StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPrepEmbedMaker.cxx
1 
22 #include "TFile.h"
23 #include "StIOMaker/StIOMaker.h"
24 #include "StMessMgr.h"
25 #include "StPrepEmbedMaker.h"
26 #include "StEvtHddr.h"
27 #include "TTree.h"
28 #include "StGenericVertexMaker/StGenericVertexMaker.h"
29 #include "StGenericVertexMaker/StGenericVertexFinder.h"
30 
31 #include "tables/St_vertexSeed_Table.h"
32 #include "TString.h"
33 #include "TSystem.h"
34 
35 #include <unistd.h>
36 
37 ClassImp(StPrepEmbedMaker)
39  Double_t mult;
40  Int_t pid;
41  Double_t ptlow;
42  Double_t pthigh;
43  Double_t etalow;
44  Double_t etahigh;
45  Double_t philow;
46  Double_t phihigh;
47  Double_t temperature;
48  Int_t rnd1;
49  Int_t rnd2;
50  Double_t vzlow;
51  Double_t vzhigh;
52  Double_t vr;
53  Double_t vpdvz;
54  Double_t pvrank;
55  Int_t NReqTrg;
56  static const Int_t nTriggerId = 32 ;
57  Int_t ReqTrgId[nTriggerId];
58  TString mode;
59 };
60 
61 static embedSettings *mSettings = 0;
62 const Double_t StPrepEmbedMaker::mRapidityMaximumCut = 10.0 ; // Maximum rapidity range for 'spectrum' option
63 
64 //____________________________________________________________________________________________________
65 StPrepEmbedMaker::StPrepEmbedMaker(const Char_t *name) : StMaker(name)
66 {
67  mGeant3=0;
68  mTagFile = "" ;
69  mMoreTagsFile = "" ;
70  mFzFile = "temp.fz";
71  mEventCounter = 0;
72 
73  if( !mSettings ){
74  mSettings = new embedSettings();
75 
77  mSettings->vzlow = -200.0 ;
78  mSettings->vzhigh = 200.0 ;
79 
81  mSettings->mult=0.;
82 
84  mSettings->temperature=0.3; // GeV
85 
87  mSettings->NReqTrg = 0 ;
88  for(Int_t itrg=0; itrg<mSettings->nTriggerId; itrg++){
89  mSettings->ReqTrgId[itrg] = 0 ;
90  }
91 
93  mSettings->mode = "flatpt";
94  }
95  mFile = 0;
96  mMoreFile = 0 ;
97  mTree = 0;
98  mMoreTree = 0;
99  mSkipMode = kFALSE;
100  mSpreadMode = kFALSE;
101  mOpenFzFile = kFALSE;
102  mPrimeMode = kFALSE;
103  mSavePid = 0;
104  mPrimed = kFALSE;
105  mVpdVzCutMode = kFALSE;
106  mPVRankCutMode = kFALSE;
107  mRapidityMode = kTRUE;
108 }
109 //____________________________________________________________________________________________________
110 StPrepEmbedMaker::~StPrepEmbedMaker() {
111  SafeDelete(mFile);
112 }
113 
114 //____________________________________________________________________________________________________
115 Int_t StPrepEmbedMaker::Init()
116 {
117  srand((unsigned)time(0));
118  // use the SUMS_name environment variable as a flag to fix the random number
119  // generator seeds; Dev/Eval/NewTest are for library tests (e.g. nightly tests)
120  TString jobName = gSystem->Getenv("SUMS_name");
121  if (jobName.Contains("FixRandomSeeds") ||
122  jobName == "DevTest" ||
123  jobName == "EvalTest" ||
124  jobName == "NewTest") {
125  LOG_WARN << "StPrepEmbedMaker::Init Using fixed random number generator seeds!" << endm;
126  mSettings->rnd1 = 12345;
127  mSettings->rnd2 = 67890;
128  } else {
129  mSettings->rnd1 = abs(int(rand()*10000)+getpid());
130  mSettings->rnd2 = abs(int(rand()*10000)+getpid());
131  }
132 
133  if (mSettings->mode.CompareTo("strange", TString::kIgnoreCase) == 0)
134  {
135  mSpreadMode= kTRUE;
136  LOG_INFO <<"StPrepEmbedMaker::Init Setting spreader mode for embedding mode "<<mSettings->mode <<endm;
137  }
138 
139  return StMaker::Init();
140 }
141 
142 //____________________________________________________________________________________________________
143 Int_t StPrepEmbedMaker::InitRun(const int runnum)
144 {
145  //Call geant maker, set defaults
146  if (! mGeant3) {
147  mGeant3 = TGiant3::Geant3();
148  if( ! mGeant3)
149  {
150  LOG_ERROR << "StPrepEmbedMaker::InitRun Geant3 pointer not found. exiting."<<endm;
151  return kStErr;
152  }
153  }
154 
155  // Skip initialization if tags file has not been defined
156  if (mTagFile.IsWhitespace()){
157  LOG_ERROR << "StPrepEmbedMaker::InitRun TagFile has not been defined" << endm;
158  return kStErr;
159  }
160 
161  // Open Tags file
162  mFile = TFile::Open(mTagFile);
163  if (! mFile ) {
164  LOG_ERROR << "StPrepEmbedMaker::Init TagFile : " << mTagFile << " cannot be opened" << endm;
165  return kStErr;
166  }
167 
168  // Get Tag tree
169  mTree = (TTree *) mFile->Get("Tag");
170  if (! mTree ) {
171  LOG_ERROR << "StPrepEmbedMaker::Init In TagFile : " << mTagFile << " cannot find TTree \"Tag\"" << endm;
172  return kStErr;
173  }
174 
175  // Check mode type, select settings
176  if (mSpreadMode){
177  LOG_INFO << "StPrepEmbedMaker::Init Spreader mode set. Looking for MoreTags file ..."<<endm;
178  mMoreTagsFile = mTagFile;
179  const int indx1 = mMoreTagsFile.Index(".tags",0);
180  const int indx2 = mMoreTagsFile.Last('.');
181  if (indx1!=indx2) mMoreTagsFile.Remove(indx1+1,(indx2-indx1));
182  mMoreTagsFile.Insert(indx1+1,"moretags.");
183  mMoreFile = TFile::Open(mMoreTagsFile);
184 
185  if (mMoreFile ) {
186  mMoreTree = (TTree *) mMoreFile->Get("MoreTags");
187  if (! mMoreTree ) {
188  LOG_ERROR << "StPrepEmbedMaker::Init In MoreTagsFile : " << mMoreTagsFile << " cannot find TTree \"MoreTags\"" << endm;
189  return kStErr;
190  }//end if more tree
191  }
192  else {
193  LOG_INFO << "StPrepEmbedMaker::Init File moretags.root not found. If this embedding is for years 2007 through 2009, this will most likely cause the embedding to quit prematurely."<<endm;
194  return kStErr ;
195  }//end if mMoreFile
196  }//end spreadMode setup
197 
198 
199  // Obsolete methods
200 #if 0
201  if(mSettings->mode.CompareTo("Spectrum", TString::kIgnoreCase) == 0)
202  {
203  // Call the old gentx binary for this request.
204  // We need to port this code into the StPrepEmbedMaker,
205  // but the underlying functions don't exist in St_geant_Maker
206  // at this time (11-25-09).
207  // magic numbers: 1000 events, temp.fz need to be resolved
208  TString cmd;
209  cmd = Form("root4star -q \'~starofl/embedding/getVerticiesFromTags.C\(1000,\"./\",\"%s\")\'",
210  mTagFile.Data());
211  cmd = Form("~starofl/embedding/GENTX/gentx %s %s %i %i %f %f %f %i %f %f %f %i",
212  mTagFile.Data(),"temp.fz",
213  1000,mSettings->mult,mSettings->etalow, mSettings->etahigh,
214  0.0,0,mSettings->ptlow, mSettings->pthigh,mSettings->temperature,
215  mSettings->rnd1);
216  gSystem->Exec(cmd.Data());
217 
218  Do("gfile p temp.fz");
219  }//end if Spectrum
220 #endif
221 
222  if( mOpenFzFile ) {
223  // Open .fz file
224  // Name fz file with same basename as daq file
225  // If there are no daq files, use default name "temp.fz"
226  if (StIOMaker* ioMaker = (StIOMaker*)GetMakerInheritsFrom("StIOMaker")) {
227  if (const Char_t* daqfile = ioMaker->GetFile()) {
228  LOG_DEBUG << "StPrepEmbedMaker::InitRun daq file: " << daqfile << endm;
229  mFzFile = gSystem->BaseName(daqfile);
230  mFzFile.ReplaceAll(".daq",".fz");
231  }
232  }
233  LOG_INFO << "StPrepEmbedMaker::InitRun Open FZ file: " << mFzFile << endm;
234  Do("user/output o " + mFzFile);
235  }
236 #if 0 /* Please don't do this. starsim make in root4star has distroied table on virtual functions. */
237  // Common geant settings
238  Do("make gstar"); // Make user-defined particles available
239 #else
240  gSystem->Load("libgstar");
241  Do("call gstar");
242 #endif
243  Do("detp hadr_on");
244  TString cmd("rndm ");
245  cmd+=mSettings->rnd1; cmd+=" "; cmd+=mSettings->rnd2;
246  Do(cmd.Data());
247 
248  return 0;
249 }
250 
251 //____________________________________________________________________________________________________
253 {
254  mEventCounter++; // increase counter
255  StEvtHddr* EvtHddr = (StEvtHddr*) GetDataSet("EvtHddr");
256  if (! EvtHddr) {
257  LOG_ERROR << "StPrepEmbedMaker::Make EvtHddr has not been found" << endm;
258  return kStErr;
259  }
260  Int_t nFound = mTree->Draw("uncorrectedNumberOfPrimaries:primaryVertexFlag",
261  Form("mRunNumber==%i&&mEventNumber==%i",EvtHddr->GetRunNumber(),EvtHddr->GetEventNumber()),
262  "goff");
263  if (nFound != 1) {
264  LOG_ERROR << "StPrepEmbedMaker::Make Run/Event = " << EvtHddr->GetRunNumber() << "/" << EvtHddr->GetEventNumber()
265  << " has been found in tag file" << nFound << " times" << endm;
266  return kStErr;
267  }
268  LOG_INFO << "StPrepEmbedMaker::Make Run/Event = " << EvtHddr->GetRunNumber()
269  << "/" << EvtHddr->GetEventNumber()
270  << " has been found with uncorrectedNumberOfPrimaries = " << mTree->GetV1()[0]
271  << " and primaryVertexFlag = " << mTree->GetV2()[0] << endm;
272 
273  if (mTree->GetV1()[0] <= 0 || mTree->GetV2()[0] )
274  {
275  LOG_ERROR << "StPrepEmbedMaker::Make reject this event" << endm;
276  return kStErr;
277  }
278 
279  if( mMoreTree )
280  {
281  nFound = mMoreTree->Draw("nRefMult",
282  Form("RunId==%i&&EvtId==%i",EvtHddr->GetRunNumber(),EvtHddr->GetEventNumber()),
283  "goff");
284  if (nFound != 1) {
285  LOG_ERROR << "StPrepEmbedMaker::Make Run/Event = " << EvtHddr->GetRunNumber() << "/" << EvtHddr->GetEventNumber()
286  << " has been found in moretag file" << nFound << " times" << endm;
287  return kStErr;
288  }
289  LOG_INFO << "StPrepEmbedMaker::Make Run/Event = " << EvtHddr->GetRunNumber()
290  << "/" << EvtHddr->GetEventNumber()
291  << " has been found (in moretags) with uncorrectedNumberOfPrimaries = " << mMoreTree->GetV1()[0] << endm;
292 
293  if (mMoreTree->GetV1()[0] <= 0 )
294  {
295  LOG_ERROR << "StPrepEmbedMaker::Make reject this event" << endm;
296  return kStErr;
297  }
298  if ( fabs(mMoreTree->GetV1()[0]- mTree->GetV1()[0]) > 0.1 )
299  {
300  LOG_INFO << "StPrepEmbedMaker::Make Run/Event = " << EvtHddr->GetRunNumber()
301  << "/" << EvtHddr->GetEventNumber()
302  << " has different uncorrectedNumberOfPrimaries from tags and moretags" << endm;
303  }
304  }
305 
306  // Extract info for mult for this event
307  const Int_t numberOfPrimaryTracks = mMoreTree ? mMoreTree->GetV1()[0] : mTree->GetV1()[0];
308  const Int_t npart = getMultiplicity( *EvtHddr, numberOfPrimaryTracks ) ;
309 
310  nFound = (Int_t) mTree->Draw("primaryVertexX:primaryVertexY:primaryVertexZ:TriggerId",
311  Form("mRunNumber==%i&&mEventNumber==%i",
312  EvtHddr->GetRunNumber(),
313  EvtHddr->GetEventNumber()),
314  "goff");
315 
316  if ( mMoreTree )
317  {
318  nFound = (Int_t) mMoreTree->Draw("VX:VY:VZ",
319  Form("RunId==%i&&EvtId==%i",
320  EvtHddr->GetRunNumber(),
321  EvtHddr->GetEventNumber()),
322  "goff");
323  }
324 
325  Double_t xyztmp[3];
326  if ( mMoreTree )
327  {
328  xyztmp[0] = mMoreTree->GetV1()[0];
329  xyztmp[1] = mMoreTree->GetV2()[0];
330  xyztmp[2] = mMoreTree->GetV3()[0];
331  }
332  else
333  {
334  xyztmp[0] = mTree->GetV1()[0];
335  xyztmp[1] = mTree->GetV2()[0];
336  xyztmp[2] = mTree->GetV3()[0];
337  }
338 
339  const Double_t xyz[3] = {xyztmp[0],xyztmp[1],xyztmp[2]};
340 
341  // Skip event if no primary vertex - effectively if tags say it is 0,0,0
342  if (fabs(xyz[0])<1e-7 && fabs(xyz[1])<1e-7 && fabs(xyz[2])<1e-7 ){
343  LOG_INFO << "StPrepEmbedMaker::Make Event " << EvtHddr->GetEventNumber()
344  << " has tags with vertex approx at (0,0,0) - probably no PV, skipping."
345  << endm;
346  return kStSKIP;
347  }
348 
349  // Skip event
350  // 1. if vertexZ is not in the required range
351  // 2. if vr = sqrt{vx^2 + vy^2} is not in the required range
352  if (mSkipMode == kTRUE){
353  const Double_t vr = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
354  if (xyz[2]<mSettings->vzlow || xyz[2]>mSettings->vzhigh || vr>=mSettings->vr ){
355  LOG_INFO << "StPrepEmbedMaker::Make Event " << EvtHddr->GetEventNumber()
356  << " has tags with vertex at (" << xyz[0] << "," << xyz[1] << "," << xyz[2]
357  << "), vr = " << vr
358  << " - out of Vz or Vr range, skipping." << endm;
359  return kStSKIP;
360  }
361 
362  LOG_INFO << "StPrepEmbedMaker::Make Event " << EvtHddr->GetEventNumber()
363  << " has tags with vertex at (" << xyz[0] << "," << xyz[1] << "," << xyz[2]
364  << "), vr = " << vr
365  << " - within requested Vz and Vr range !" << endm;
366  }
367 
368  // more skipping. cut on trigger id.
369  if (mSkipMode == kTRUE){
370  LOG_INFO << "StPrepEmbedMaker::Event " << EvtHddr->GetEventNumber()
371  << " has Triggers: " << endm;
372  for (Int_t iTrg=0 ; iTrg<mSettings->nTriggerId ; iTrg++){
373  LOG_INFO << mTree->GetV4()[iTrg] << " ";
374  }
375  LOG_INFO << endm;
376 
377  Bool_t fired = kFALSE;
378  for (Int_t iTrg=0 ; iTrg<mSettings->nTriggerId ; iTrg++){
379  for (Int_t iReqTrg=0; iReqTrg<mSettings->NReqTrg ; iReqTrg++) {
380  if (mTree->GetV4()[iTrg] == mSettings->ReqTrgId[iReqTrg]){
381  LOG_INFO << "StPrepEmbedMaker::Requested trigger " << mSettings->ReqTrgId[iReqTrg] << " is fired!" << endm;
382  fired = kTRUE;
383  }
384  }
385  }
386 
387  if (!fired && mSettings->NReqTrg>0) {
388  LOG_INFO << "StPrepEmbedMaker::No requested triggers are fired in this event, skipping." << endm;
389  return kStSKIP;
390  }
391  }
392 
393  // more skipping. cut on VpdVz in btofheader
394  Float_t vpdvz;
395  if(mSkipMode == kTRUE && mVpdVzCutMode == kTRUE)
396  {
397  // (Run 10, 11 and 12) need an external file (moretags.root).
398  nFound=0;
399  nFound = (Int_t) mTree->Draw("VpdVz",
400  Form("mRunNumber==%i&&mEventNumber==%i",
401  EvtHddr->GetRunNumber(),
402  EvtHddr->GetEventNumber()),"goff");
403 
404  //get primary vertex errors from moretags.root
405  if(nFound == -1 && mMoreTree) {
406  nFound = (Int_t) mMoreTree->Draw("VpdVz",
407  Form("RunId==%i&&EvtId==%i",
408  EvtHddr->GetRunNumber(),
409  EvtHddr->GetEventNumber()),
410  "goff");
411 
412  LOG_INFO << "StPrepEmbedMaker::Make Use moretags file to extract VpdVz, nFound =" << nFound << endm ;
413  }
414 
415  if (nFound != 1) {
416  LOG_ERROR << "StPrepEmbedMaker::Make Run/Event = " << EvtHddr->GetRunNumber() << "/" << EvtHddr->GetEventNumber()
417  << " has been found in moretags file " << nFound << " times" << endm;
418  return kStErr;
419  }
420  vpdvz = mMoreTree->GetV1()[0];
421  LOG_INFO << vpdvz << endm;
422 
423  //cut on events
424  if( fabs(vpdvz) < 1e-7 ) {
425  LOG_INFO << "StPrepEmbedMaker::Make Event " << EvtHddr->GetEventNumber()
426  << " has tags with vertex at (" << xyz[0] << "," << xyz[1] << "," << xyz[2]
427  << "), VpdVz = " << vpdvz
428  << " - VpdVz is too small (i.e. no BTOF in this run), skipping." << endm;
429  return kStSKIP;
430  }
431  if( fabs(vpdvz) >= 100. ) {
432  LOG_INFO << "StPrepEmbedMaker::Make Event " << EvtHddr->GetEventNumber()
433  << " has tags with vertex at (" << xyz[0] << "," << xyz[1] << "," << xyz[2]
434  << "), VpdVz = " << vpdvz
435  << " - VpdVz is too large, skipping." << endm;
436  return kStSKIP;
437  }
438  if( fabs(xyz[2]-vpdvz) > mSettings->vpdvz ) {
439  LOG_INFO << "StPrepEmbedMaker::Make Event " << EvtHddr->GetEventNumber()
440  << " has tags with vertex at (" << xyz[0] << "," << xyz[1] << "," << xyz[2]
441  << "), VpdVz = " << vpdvz
442  << " - out of |Vz-VpdVz| range, skipping." << endm;
443  return kStSKIP;
444  }
445  }
446 
447 
448  // more skipping. cut on PVRank
449  Float_t pvrank;
450  if(mSkipMode == kTRUE && mPVRankCutMode == kTRUE)
451  {
452  // (Run 12, and before) need an external file (moretags.root).
453  nFound=0;
454  nFound = (Int_t) mTree->Draw("PVRank",
455  Form("mRunNumber==%i&&mEventNumber==%i",
456  EvtHddr->GetRunNumber(),
457  EvtHddr->GetEventNumber()),"goff");
458 
459  //get primary vertex errors from moretags.root
460  if(nFound == -1 && mMoreTree) {
461  nFound = (Int_t) mMoreTree->Draw("PVRank",
462  Form("RunId==%i&&EvtId==%i",
463  EvtHddr->GetRunNumber(),
464  EvtHddr->GetEventNumber()),
465  "goff");
466 
467  LOG_INFO << "StPrepEmbedMaker::Make Use moretags file to extract PVRank, nFound =" << nFound << endm ;
468  }
469 
470  if (nFound != 1) {
471  LOG_ERROR << "StPrepEmbedMaker::Make Run/Event = " << EvtHddr->GetRunNumber() << "/" << EvtHddr->GetEventNumber()
472  << " has been found in moretags file " << nFound << " times" << endm;
473  return kStErr;
474  }
475  pvrank = mMoreTree->GetV1()[0];
476  LOG_INFO << pvrank << endm;
477 
478  //cut on events
479  if( pvrank <= mSettings->pvrank ) {
480  LOG_INFO << "StPrepEmbedMaker::Make Event " << EvtHddr->GetEventNumber()
481  << " has tags with vertex at (" << xyz[0] << "," << xyz[1] << "," << xyz[2]
482  << "), PVRank = " << pvrank
483  << " - PVRank is < = " << mSettings->pvrank << ", skipping." << endm;
484  return kStSKIP;
485  }
486  }
487  //Done set up for event.
488 
489  //Setup embedded particle
490  // gkine npart ID PTLOW, PTHIGH, YLOW, YHIGH, PHILOW, PHIHIGH, ZLOW, ZHIGH
491  //make sure zlow!=zhigh in particle definition - not sure of result.
492  //Z vertex will be forced in vxyz statement.
493 
494  Double_t xyzerr[3] = {0.,0.,0.};
495 
496  //get primary vertex errors from tags.root (>= Run10)
497  if(EvtHddr->GetRunNumber()>10311000){
498  nFound=0;
499  nFound = (Int_t) mTree->Draw("sigmaPVX:sigmaPVY:sigmaPVZ",
500  Form("mRunNumber==%i&&mEventNumber==%i",
501  EvtHddr->GetRunNumber(),
502  EvtHddr->GetEventNumber()),"goff");
503  xyzerr[0] = mTree->GetV1()[0];
504  xyzerr[1] = mTree->GetV2()[0];
505  xyzerr[2] = mTree->GetV3()[0];
506  }
507 
508  //get primary vertex errors from moretags.root
509  if( mMoreTree ) {
510  nFound = (Int_t) mMoreTree->Draw("VXsigma:VYsigma:VZsigma",
511  Form("RunId==%i&&EvtId==%i",
512  EvtHddr->GetRunNumber(),
513  EvtHddr->GetEventNumber()),
514  "goff");
515 
516  LOG_INFO << "StPrepEmbedMaker::Make Use moretags file to extract vertex errors, nFound =" << nFound << endm ;
517 
518  xyzerr[0] = mMoreTree->GetV1()[0];
519  xyzerr[1] = mMoreTree->GetV2()[0];
520  xyzerr[2] = mMoreTree->GetV3()[0];
521  }
522 
523  LOG_INFO << "StPrepEmbedMaker::Make Event " << EvtHddr->GetEventNumber()
524  << " has tags with vertex errors of (" << xyzerr[0] << "," << xyzerr[1] << "," << xyzerr[2]
525  << ")" << endm;
526 
527  //Set the vertex for StEvent with StGenericVertexMaker
528  StGenericVertexMaker * vmaker = (StGenericVertexMaker*) GetMaker("GenericVertex");
529  StGenericVertexFinder * vfinder = (vmaker ? vmaker->GetGenericFinder() : 0);
530  if((vfinder) && (vfinder->IsFixed())){
531  vfinder->SetVertexPosition(xyz[0],xyz[1],xyz[2]);
532  vfinder->SetVertexError(xyzerr[0],xyzerr[1],xyzerr[2]);
533  }
534  else {
535  LOG_WARN << "StPrepEmbedMaker::Make a fixed vertex finder is not in the chain, vertex position and errors are not set!" << endm;
536  }
537 
538  if( mPrimeMode && !mPrimed ) {
539  mSavePid = mSettings->pid;
540  mSettings->pid = 45;
541  }
542 
543  // gkine is needed to set the z-vertex
544  gkine(npart, xyz[2], xyz[2]);
545 
546  // Flat (pt, y)
547  if( mRapidityMode ) phasespace(npart);
548 
549  Do(Form("gvertex %f %f %f",xyz[0],xyz[1],xyz[2]));
550  if( mSettings->mode.CompareTo("strange", TString::kIgnoreCase) == 0 )
551  {
552  // For this embedding type, we smear the start position of the particle
553  // with the vertex errors.
554  Do(Form("gspread %f %f %f", xyzerr[0],xyzerr[1],xyzerr[2]));
555  }
556  else
557  {
558  Do("vsig 0 0;");
559  }
560 
561  // Sloped momentum distribution
562  if( mSettings->mode.CompareTo("Spectrum", TString::kIgnoreCase) == 0 ){
563  // Make sure temperature > 0
564  if ( mSettings->temperature > 0.0 ){
565  // np: Number of particle type
566  // code: Particle geant id
567  // mult: Numbe of particles per event (negative multiplicity means exact input number of particles per event)
568  // slope: Inverse slope parameter (c/GeV)
569  // dy: Rapidity width, from etahigh (negative sign means flat rapidity)
570  LOG_INFO << "StPrepEmbedMaker::Make Generate sloped momentum distribution with T="
571  << mSettings->temperature << " GeV !"
572  << endm;
573 
574  Do("subevent 0");
575  Do(Form("detp mick miky.np=%d code=%d mult=%d slope=%f dy=%f",
576  1, mSettings->pid, -npart, 1.0/mSettings->temperature, -mSettings->etahigh));
577 
578  Do(Form("user/input please my.micky"));
579 // Do(Form("gfile u my.micky"));
580  }
581  else{
582  LOG_ERROR << "StPrepEmbedMaker::Make Input temperature <= 0, T=" << mSettings->temperature
583  << ", skip to generate sloped momentum distribution"
584  << endm ;
585  }
586  }
587 
588  Do("trig 1");
589 
590  if( mPrimeMode && !mPrimed ){
591  mSettings->pid = mSavePid;
592  mPrimed = kTRUE;
593  }
594 
595  return kStOK;
596 }
597 
598 //____________________________________________________________________________________________________
600 {
601  if( mOpenFzFile ) {
603  LOG_INFO << "StPrepEmbedMaker::Finish Write and close fz file: " << mFzFile << endm;
604  Do("user/output c " + mFzFile);
605  }
606  return 0;
607 }
608 
609 //____________________________________________________________________________________________________
610 void StPrepEmbedMaker::Do(const Char_t *job)
611 {
612  Int_t l=strlen(job);
613  if (l) {
614  LOG_INFO << "StPrepEmbedMaker::Do(" << job << ");" << endm;
615  mGeant3->Kuexel(job);
616  }
617 }
618 
619 //____________________________________________________________________________________________________
620 void StPrepEmbedMaker::SetPartOpt(const Int_t pid, const Double_t mult)
621 {
622  mSettings->mult=mult; mSettings->pid=pid;
623  LOG_INFO << "StPrepEmbedMaker::SetPartOpt mult = " << mSettings->mult
624  << " pid = " << mSettings->pid << endm;
625 }
626 
627 //____________________________________________________________________________________________________
628 void StPrepEmbedMaker::SetOpt(const Double_t ptlow, const Double_t pthigh,
629  const Double_t etalow, const Double_t etahigh, const Double_t philow,
630  const Double_t phihigh, const TString type)
631 {
632  mSettings->ptlow=ptlow; mSettings->pthigh=pthigh;
633  mSettings->etalow=etalow; mSettings->etahigh=etahigh;
634  mSettings->philow=philow; mSettings->phihigh=phihigh;
635  mSettings->mode=type;
636  LOG_INFO << "StPrepEmbedMaker::SetOpt ptlow = " << mSettings->ptlow << " pthigh = " << mSettings->pthigh
637  << " etalow = " << mSettings->etalow << " etahigh = " << mSettings->etahigh
638  << " philow = " << mSettings->philow << " phihigh = " << mSettings->phihigh
639  <<" Mode: "<< type.Data() << endm;
640 }
641 
642 //____________________________________________________________________________________________________
643 void StPrepEmbedMaker::SetTemp(const double t)
644 {
645  mSettings->temperature=t;
646  LOG_INFO << "StPrepEmbedMaker::SetTemp set temperature= " << mSettings->temperature << endm;
647 }
648 
649 //____________________________________________________________________________________________________
650 void StPrepEmbedMaker::SetTagFile(const Char_t *file)
651 {
652  mTagFile = file;
653  LOG_INFO << "StPrepEmbedMaker::SetTagFile set tags file= " << mTagFile << endm;
654 }
655 
656 //____________________________________________________________________________________________________
657 void StPrepEmbedMaker::SetSkipMode(const Bool_t flag)
658 {
659  LOG_INFO << "StPrepEmbedMaker::SetSkipMode set skip mode= ";
660  mSkipMode = flag;
661 
662  if( mSkipMode ){
663  LOG_INFO << " ON" << endm ;
664  }
665  else{
666  LOG_INFO << " OFF" << endm ;
667  }
668 }
669 
670 //____________________________________________________________________________________________________
671 void StPrepEmbedMaker::SetSpreadMode(const Bool_t flag)
672 {
673  mSpreadMode=flag;
674 
675  LOG_INFO << "StPrepEmbedMaker::SetSpreadMode set spread mode= ";
676 
677  if( mSpreadMode ){
678  LOG_INFO << " ON" << endm ;
679  }
680  else{
681  LOG_INFO << " OFF" << endm ;
682  }
683 }
684 
685 //____________________________________________________________________________________________________
686 void StPrepEmbedMaker::SetPrimeMode(const Bool_t flag)
687 {
688  mPrimeMode=flag;
689 
690  LOG_INFO << "StPrepEmbedMaker::SetPrimeMode set prime mode= ";
691 
692  if( mPrimeMode ){
693  LOG_INFO << " ON" << endm ;
694  }
695  else{
696  LOG_INFO << " OFF" << endm ;
697  }
698 }
699 
700 //____________________________________________________________________________________________________
701 void StPrepEmbedMaker::SetRapidityMode(const Bool_t flag)
702 {
703  mRapidityMode=flag;
704 
705  LOG_INFO << "StPrepEmbedMaker::SetRapidityMode set rapidity mode= ";
706 
707  if( mRapidityMode ){
708  LOG_INFO << " Rapidity" << endm ;
709  }
710  else{
711  LOG_INFO << " Pseudo-rapidity" << endm ;
712  }
713 }
714 
715 //____________________________________________________________________________________________________
716 void StPrepEmbedMaker::SetVpdVzCutMode(const Bool_t flag)
717 {
718 
719  mVpdVzCutMode=flag;
720 
721  LOG_INFO << "StPrepEmbedMaker::SetVpdVzCutMode set VpdVz cut mode= ";
722 
723  if( mVpdVzCutMode ){
724  LOG_INFO << " ON" << endm ;
725  }
726  else{
727  LOG_INFO << " OFF" << endm ;
728  }
729 
730  if(flag){
731  //now moretags.root needed for VpdVz
732  SetSpreadMode(flag);
733  }
734 }
735 
736 //____________________________________________________________________________________________________
737 void StPrepEmbedMaker::SetPVRankCutMode(const Bool_t flag)
738 {
739 
740  mPVRankCutMode=flag;
741 
742  LOG_INFO << "StPrepEmbedMaker::SetPVRankCutMode set PVRank cut mode= ";
743 
744  if( mPVRankCutMode ){
745  LOG_INFO << " ON" << endm ;
746  }
747  else{
748  LOG_INFO << " OFF" << endm ;
749  }
750 
751  if(flag){
752  //now moretags.root needed for PVRank
753  SetSpreadMode(flag);
754  }
755 }
756 
757 //____________________________________________________________________________________________________
758 Int_t StPrepEmbedMaker::getMultiplicity(const StEvtHddr& EvtHddr, const Int_t nprimarytracks) const
759 {
761 
762  Int_t npart = 0;
763  if(mSettings->mult < 1.)
764  {
765  npart=int(mSettings->mult * nprimarytracks);
766  if (npart < 5)
767  {
768  LOG_INFO << "StPrepEmbedMaker::Event " << EvtHddr.GetEventNumber()
769  << " has too small numberOfPrimaryTracks " << nprimarytracks << " for the mult fraction requested. Forcing npart to 5." << endm;
770  npart=5;
771  }
772 
773  }
774  else
775  {
776  npart = int (mSettings->mult);
777  }
778 
779  return npart ;
780 }
781 
782 //________________________________________________________________________________
783 void StPrepEmbedMaker::SetTrgOpt(const Int_t TrgId)
784 {
785  // Skip TrgId = 0
786  if(TrgId == 0){
787  LOG_ERROR << "StPrepEmbedMaker::SetTrgOpt Input trigger id = 0. Skip" << endm;
788  return;
789  }
790 
791  if(mSettings->NReqTrg >= mSettings->nTriggerId) {
792  LOG_ERROR << "StPrepEmbedMaker::SetTrgOpt too many triggers are requested!" <<endm;
793  return;
794  }
795 
796  mSettings->ReqTrgId[mSettings->NReqTrg] = TrgId ;
797  mSettings->NReqTrg ++ ;
798  LOG_INFO << "StPrepEmbedMaker::SetTrgOpt trigger " << mSettings->ReqTrgId[mSettings->NReqTrg-1] << " requested" << endm;
799 }
800 
801 //________________________________________________________________________________
802 void StPrepEmbedMaker::SetZVertexCut(const Double_t vzlow, const Double_t vzhigh)
803 {
804  // Make sure vzlow < vzhigh
805  if( (vzlow > vzhigh) || (vzlow == 0.0 && vzhigh == 0.0) ){
806  LOG_ERROR << "StPrepEmbedMaker::SetZVertexCut input vzlow > vzhigh or vzlow = vzhigh = 0" << endm;
807  return;
808  }
809 
810  mSettings->vzlow = vzlow ;
811  mSettings->vzhigh = vzhigh ;
812  LOG_INFO << "StPrepEmbedMaker::SetZVertexCut Cut z-vertex in " << mSettings->vzlow
813  << " < vz < "
814  << mSettings->vzhigh
815  << " (cm)" << endm;
816 }
817 
818 //________________________________________________________________________________
819 void StPrepEmbedMaker::SetVrCut(const Double_t vr)
820 {
821  // Make sure vr != 0
822  if( vr == 0.0 ){
823  LOG_ERROR << "StPrepEmbedMaker::SetVrCut input vr = 0" << endm;
824  return;
825  }
826 
827  mSettings->vr = vr ;
828  LOG_INFO << "StPrepEmbedMaker::SetVrCut Cut vr in " << mSettings->vr
829  << " (cm)" << endm;
830 }
831 
832 //________________________________________________________________________________
833 void StPrepEmbedMaker::SetVpdVzCut(const Double_t vpdvz)
834 {
835  // Make sure vpdvz > 0
836  if( vpdvz <= 0.0 ){
837  LOG_ERROR << "StPrepEmbedMaker::SetVpdVzCut input |vpdvz-vz| <= 0" << endm;
838  return;
839  }
840 
841  mSettings->vpdvz = vpdvz ;
842  LOG_INFO << "StPrepEmbedMaker::SetVpdVzCut Cut |vpdvz-vz| in " << mSettings->vpdvz
843  << " (cm)" << endm;
844 }
845 
846 //________________________________________________________________________________
847 void StPrepEmbedMaker::SetPVRankCut(const Double_t pvrank)
848 {
849  mSettings->pvrank = pvrank ;
850  LOG_INFO << "StPrepEmbedMaker::SetPVRankCut Cut P.V. ranking larger than " << mSettings->pvrank
851  << endm;
852 }
853 
854 //________________________________________________________________________________
855 void StPrepEmbedMaker::OpenFzFile()
856 {
857  // Swtich to enable writing .fz file (default is off, i.e. do not write .fz file)
858  mOpenFzFile = kTRUE ;
859  LOG_INFO << "StPrepEmbedMaker::OpenFzFile Write .fz file. File basename will be taken "
860  << "from daq file basename" << endm;
861 }
862 
863 
864 //________________________________________________________________________________
865 void StPrepEmbedMaker::phasespace(const Int_t mult)
866 {
867  Double_t rapidityMin = mSettings->etalow ;
868  Double_t rapidityMax = mSettings->etahigh ;
869 
871  if( mSettings->mode.CompareTo("Spectrum", TString::kIgnoreCase) == 0 ){
872  rapidityMin = -mRapidityMaximumCut ;
873  rapidityMax = mRapidityMaximumCut ;
874  }
875 
876  Do( Form("phasespace %i %i %f %f %f %f;",
877  mult, mSettings->pid,
878  mSettings->ptlow, mSettings->pthigh,
879  rapidityMin, rapidityMax)
880  );
881 }
882 
883 //________________________________________________________________________________
884 void StPrepEmbedMaker::gkine(const Int_t mult, const Double_t vzmin, const Double_t vzmax)
885 {
886  Double_t rapidityMin = mSettings->etalow ;
887  Double_t rapidityMax = mSettings->etahigh ;
888 
890  if( mSettings->mode.CompareTo("Spectrum", TString::kIgnoreCase) == 0 ){
891  rapidityMin = -mRapidityMaximumCut ;
892  rapidityMax = mRapidityMaximumCut ;
893  }
894 
895  Do( Form("gkine %i %i %f %f %f %f %f %f %f %f;",
896  mult, mSettings->pid,
897  mSettings->ptlow, mSettings->pthigh,
898  rapidityMin, rapidityMax,
899  mSettings->philow, mSettings->phihigh,
900  vzmin, vzmax)
901  );
902 }
903 
904 
905 /* -------------------------------------------------------------------------
906  * $Log: StPrepEmbedMaker.cxx,v $
907  * Revision 1.24 2020/09/15 05:13:29 genevb
908  * Better protection against null pointers
909  *
910  * Revision 1.23 2020/09/13 02:56:31 genevb
911  * Use IsFixed() function to determine if fixed vertex finder
912  *
913  * Revision 1.22 2020/09/10 23:32:10 starembd
914  * add dynamic_cast for vfinder
915  *
916  * Revision 1.21 2020/09/08 09:52:08 starembd
917  * fix the nightly test crash issue for year 2005-2007 data
918  *
919  * Revision 1.20 2020/09/01 09:47:27 starembd
920  * Set primary vertex errors with (more)tags.root
921  *
922  * Revision 1.19 2020/03/19 20:17:10 genevb
923  * Enabled fixed random number generator seeds
924  *
925  * Revision 1.18 2018/10/12 13:44:49 zhux
926  * updated vertex errors from moretags
927  *
928  * Revision 1.17 2018/09/29 13:22:35 zhux
929  * updated primary vertex sigma names in moretree
930  *
931  * Revision 1.16 2018/04/04 18:48:35 smirnovd
932  * After a long and fruitful discussion with DK it was decided to remove the static_cast. The world is in balance again and veprbl can sleep well at night
933  *
934  * Revision 1.15 2018/03/30 23:36:32 smirnovd
935  * Fix improper cast revealed in 64-bit build
936  *
937  * Revision 1.14 2016/10/14 07:12:26 zhux
938  * "refmult" and "vx,vy,vz" will be read from moretags.root file if it exists.
939  * The minimum number of embedded particles are now set to 5 instead of 1, when the number of embeded particles is set to be proportional to refmult.
940  *
941  * Revision 1.13 2016/06/21 16:05:18 jwebb
942  * Init all members.
943  *
944  * Revision 1.12 2013/03/26 13:38:18 fisyak
945  * restore back modififcations as not related to drop in no. of reconstructed tracks
946  *
947  * Revision 1.10 2013/02/06 22:04:24 fisyak
948  * add missing call to gstar
949  *
950  * Revision 1.9 2013/01/17 15:09:19 fisyak
951  * Remove starsim make, which destroys virtual function tables, bug #2487
952  *
953  * Revision 1.8 2012/06/03 06:34:45 zhux
954  * Added a switch to cut on the ranking of primary vertex
955  *
956  * Revision 1.7 2012/05/13 06:37:04 zhux
957  * Added switch to choose between the two kinematic variables: rapidty or pseudo-rapdity
958  *
959  * Revision 1.6 2012/04/23 23:53:23 zhux
960  * Added a switch to cut on |VpdVz-Vz|
961  *
962  * Revision 1.5 2011/12/05 15:50:49 zhux
963  * Add switch to prime the first event with deuterons (for dbar, tbar and hypertritons embedding).
964  * see ticket# 2097 for details.
965  *
966  * Revision 1.4 2010/11/30 23:32:22 hmasui
967  * Add fz file and a switch to enable writing fz file
968  *
969  * Revision 1.3 2010/11/07 23:28:36 hmasui
970  * Added transverse vertex cut
971  *
972  * Revision 1.2 2010/05/26 03:23:09 hmasui
973  * Implement spectrum option by gstar_micky
974  *
975  * Revision 1.1 2010/04/05 20:18:55 jeromel
976  * Moved from one level up
977  *
978  * Revision 1.14 2010/04/02 20:14:50 didenko
979  * StPrepEmbedMaker for Hiroshi
980  *
981  * Revision 1.13 2010/02/09 01:07:32 andrewar
982  * Changed defualt setting of mSpreadMode to kFALSE. Modified logic when looking up
983  * vertex errors; first looks at tags.root, then (if failure) attempts moretags.root.
984  * Added backward compatibility for embedding mode (default is now FlatPt).
985  *
986  * Revision 1.12 2010/02/05 23:01:04 andrewar
987  * Update with spectra embedding mode.
988  *
989  * Revision 1.11 2009/07/01 23:20:34 andrewar
990  * Updated with codes for Strangeness embedding (taken from Xianglei's code,
991  * Feb 09)
992  *
993  * Revision 1.9 2008/09/04 00:07:27 fisyak
994  * Change default from gkine to phasespace
995  *
996  * Revision 1.8 2008/08/19 23:11:27 andrewar
997  * Added initialization for RNDM seeds. Seeding now from the clock and the UNIX
998  * process ID (as suggested by Marco).
999  *
1000  * Revision 1.7 2008/08/15 15:09:37 lbarnby
1001  * Skip embedding events without primary vertex + flag for this behaviour (default is to skip)
1002  *
1003  * Revision 1.6 2008/07/30 14:11:55 lbarnby
1004  * Changed tags used to get multiplicity for calculating how many particle to embed from numberOfPrimaryTracks to uncorrectedNumberOfPrimaries because former is created by StPCollTagMaker which was not used in P08ic Au+Au 9 GeV production whereas latter is from StTagsMaker
1005  *
1006  * Revision 1.5 2008/06/17 16:08:56 fisyak
1007  * Move access to TGiant into InitRun
1008  *
1009  * Revision 1.4 2008/01/21 01:23:37 perev
1010  * WarnOff
1011  *
1012  * Revision 1.3 2007/09/18 21:53:45 fisyak
1013  * Don't use field set from GEANT
1014  *
1015  * Revision 1.2 2007/08/29 22:59:33 andrewar
1016  * Added some calls for GEANT simulation of embedded particles.
1017  *
1018  * Revision 1.1 2007/07/12 20:34:35 fisyak
1019  * Add StPrepEmbedMaker
1020  *
1021  *
1022  * -------------------------------------------------------------------------
1023  */
1024 
Prepare GEANT Maker with input from embedding settings and DAQ event.
Definition: Stypes.h:48
void phasespace(const Int_t mult)
StPrepEmbedMaker(const Char_t *name="PrepEmbed")
Definition: Stypes.h:40
void SetOpt(const Double_t ptlow, const Double_t pthigh, const Double_t etalow, const Double_t etahigh, const Double_t philow, const Double_t phihigh, const TString type="FlatPt")
Set geantid(pid) and multiplicity.
void SetPrimeMode(const Bool_t flag=kFALSE)
Switch to enable writing .fz file.
Definition: Stypes.h:44
void gkine(const Int_t mult, const Double_t vzmin, const Double_t vzmax)