FairRoot/PandaRoot
PndMasterRunSim.cxx
Go to the documentation of this file.
1 #include "PndMasterRunSim.h"
2 
3 #include "PndMultiField.h"
4 #include "PndCave.h"
5 #include "PndMagnet.h"
6 #include "PndPipe.h"
7 #include "PndStt.h"
8 #include "PndMvdDetector.h"
9 #include "PndGemDetector.h"
10 #include "PndEmc.h"
11 #include "PndSciT.h"
12 #include "PndDrc.h"
13 #include "PndDsk.h"
14 #include "PndMdt.h"
15 #include "PndFts.h"
16 #include "PndFtof.h"
17 #include "PndRich.h"
18 #include "PndEmcHitProducer.h"
19 #include "PndDpmDirect.h"
20 #include "PndFtfDirect.h"
21 #include "PndFtfGenerator.h"
22 #include "PndBoxGenerator.h"
23 #include "PndEvtGenDirect.h"
24 #include "PndPiPiGenerator.h"
25 #include "PndLepLepGenerator.h"
26 #include "PndMasterSimTask.h"
27 #include "PndEventCounterTask.h"
28 #include "PndFileNameCreator.h"
30 
31 #include "FairFileSource.h"
32 #include "FairFileHeader.h"
33 #include "FairParRootFileIo.h"
34 #include "FairParAsciiFileIo.h"
35 #include "FairRuntimeDb.h"
36 #include "FairSystemInfo.h"
37 #include "FairModule.h"
38 #include "FairDetector.h"
39 #include "FairPrimaryGenerator.h"
41 #include "FairGenerator.h"
42 #include "FairLogger.h"
43 
44 #include "TLorentzVector.h"
45 #include "TDatabasePDG.h"
46 #include "TGeoManager.h"
47 #include "TROOT.h"
48 
49 #include <fstream>
50 using std::cout;
51 using std::endl;
52 
53 // ----- Default constructor -------------------------------------------
55  FairRunSim(), fInput(), fInputDir(""), fOutFile(), fParamRootFile(), fParamAsciiFile(), fOptions(), fDpmFlag(1), fFtfFlag(0), fNEvents(0), fEventCounterRate(100), fTargetMode(0), fRtdb(), fTimer()
56 {
57  fTimer.Start();
58 }
59 // ----- Default destructor -------------------------------------------
61 {
62  if (gROOT->GetVersionInt() >= 60602 && gGeoManager!=NULL) {
63  gGeoManager->GetListOfVolumes()->Delete();
64  gGeoManager->GetListOfShapes()->Delete();
65  delete gGeoManager;
66  }
67 }
68 
69 // ----- Setup ---------------------------------------------------------
71 {
72  TString inputName = outprefix;
73 
74  // If no prefix is given, we create one from fInput and force lower-case
75  if (inputName=="")
76  {
77  inputName = fInput;
78  inputName.ToLower();
79  }
80 
81  if (inputName.EndsWith(".dec")) inputName.Remove(inputName.Length()-4,4);
82  inputName.ReplaceAll(":","_");
83 
84  PndFileNameCreator creator(inputName.Data());
85  SetOutputFile(creator.GetSimFileName().data());
86  fOutFile = creator.GetSimFileName().data();
87  SetParamRootFile(creator.GetParFileName().data());
88  SetMaterials("media_pnd.geo");
89  SetGenerateRunInfo(kFALSE);
90  SetUseFairLinks(kTRUE);
91 
92  // ----- Parameter database --------------------------------------------
93  TString allDigiFile = gSystem->Getenv("VMCWORKDIR");
94  allDigiFile += "/macro/params/";
95  allDigiFile += fParamAsciiFile;
96 
97  fRtdb = this->GetRuntimeDb();
98  Bool_t kParameterMerged=kFALSE; // No use until now
99  FairParRootFileIo* parOutput = new FairParRootFileIo(kParameterMerged);
100  parOutput->open(fParamRootFile,"RECREATE");
101 
102  FairParAsciiFileIo* parIo1 = new FairParAsciiFileIo();
103  parIo1->open(allDigiFile.Data(),"in");
104 
105  fRtdb->setFirstInput(parIo1);
106  fRtdb->setOutput(parOutput);
107 
108  // ----- Create and Set the Field(s) ------------------------------------
109  PndMultiField *field= new PndMultiField("AUTO");
110  SetField(field);
111 
112  // ---- Defining PANDA particles -----------------------------------------
113  Double_t mom = GetBeamMom();
114  TLorentzVector fIni(0, 0, mom, sqrt(mom*mom+9.3827203e-01*9.3827203e-01)+9.3827203e-01);
115  TDatabasePDG::Instance()->AddParticle("ppSystem" ,"ppSystem", fIni.M(), kFALSE, 0.1, 6, "", 98888);
116  TDatabasePDG::Instance()->AddParticle("pbarpSystem" ,"pbarpSystem", fIni.M(), kFALSE, 0.1, 0, "", 88888);
117  TDatabasePDG::Instance()->AddParticle("pbarpSystem0","pbarpSystem0", fIni.M(), kFALSE, 0.1, 0, "", 88880);
118  TDatabasePDG::Instance()->AddParticle("pbarpSystem1","pbarpSystem1", fIni.M(), kFALSE, 0.1, 0, "", 88881);
119  TDatabasePDG::Instance()->AddParticle("pbarpSystem2","pbarpSystem2", fIni.M(), kFALSE, 0.1, 0, "", 88882);
120 
121  if (fOptions.Contains("day1")) fTargetMode = 1;
122  return kTRUE;
123 }
124 
125 // ----- CreateGeometry -------------------------------------------------
127 {
128  if (fOptions.Contains("phase1")) CreateGeometryPhase1();
129  else if (fOptions.Contains("day1")) CreateGeometryDay1();
130  else CreateGeometryDefault();
131 }
132 
133 // ----- CreateGeometry -------------------------------------------------
135 {
136  //------------------------- CAVE -----------------
137  FairModule *Cave= new PndCave("CAVE");
138  Cave->SetGeometryFileName("pndcave.geo");
139  AddModule(Cave);
140  //------------------------- Magnet -----------------
141  // This part is commented because the MDT geometry contains the magnet now
142  //FairModule *Magnet= new PndMagnet("MAGNET");
143  //Magnet->SetGeometryFileName("FullSolenoid_V842.root");
144  //Magnet->SetGeometryFileName("FullSuperconductingSolenoid_v831.root");
145  //AddModule(Magnet);
146  FairModule *Dipole= new PndMagnet("MAGNET");
147  Dipole->SetGeometryFileName("dipole.geo");
148  AddModule(Dipole);
149  //------------------------- Pipe -----------------
150  FairModule *Pipe= new PndPipe("PIPE");
151  Pipe->SetGeometryFileName("beampipe_201309.root");
152  AddModule(Pipe);
153  //------------------------- STT -----------------
154  FairDetector *Stt= new PndStt("STT", kTRUE);
155  Stt->SetGeometryFileName("straws_skewed_blocks_35cm_pipe.geo");
156  AddModule(Stt);
157  //------------------------- MVD -----------------
158  FairDetector *Mvd = new PndMvdDetector("MVD", kTRUE);
159  Mvd->SetGeometryFileName("Mvd-2.1_FullVersion.root");
160  AddModule(Mvd);
161  //------------------------- GEM -----------------
162  FairDetector *Gem = new PndGemDetector("GEM", kTRUE);
163  Gem->SetGeometryFileName("gem_3Stations_realistic_v2.root");
164  AddModule(Gem);
165  //------------------------- EMC -----------------
166  PndEmc *Emc = new PndEmc("EMC",kTRUE);
167  Emc->SetGeometryVersion(1);
168  Emc->SetStorageOfData(kFALSE);
169  AddModule(Emc);
170  //------------------------- SCITIL -----------------
171  FairDetector *SciT = new PndSciT("SCIT",kTRUE);
172  SciT->SetGeometryFileName("SciTil_201601.root");
173  AddModule(SciT);
174  //------------------------- DRC -----------------
175  PndDrc *Drc = new PndDrc("DIRC", kTRUE);
176  Drc->SetGeometryFileName("dirc_e3_b3_l6_m40.root");
177  Drc->SetRunCherenkov(kFALSE);
178  AddModule(Drc);
179  //------------------------- DISC -----------------
180  PndDsk* Dsk = new PndDsk("DSK", kTRUE);
181  Dsk->SetStoreCerenkovs(kFALSE);
182  Dsk->SetStoreTrackPoints(kFALSE);
183  AddModule(Dsk);
184  //------------------------- MDT -----------------
185  PndMdt *Muo = new PndMdt("MDT",kTRUE);
186  Muo->SetBarrel("fast");
187  Muo->SetEndcap("fast");
188  Muo->SetMuonFilter("fast");
189  Muo->SetForward("fast");
190  Muo->SetMdtMagnet(kTRUE);
191  Muo->SetMdtCoil(kTRUE);
192  Muo->SetMdtMFIron(kTRUE);
193  AddModule(Muo);
194  //------------------------- FTS -----------------
195  FairDetector *Fts= new PndFts("FTS", kTRUE);
196  Fts->SetGeometryFileName("fts.geo");
197  AddModule(Fts);
198  //------------------------- FTOF -----------------
199  FairDetector *FTof = new PndFtof("FTOF",kTRUE);
200  FTof->SetGeometryFileName("ftofwall.root");
201  AddModule(FTof);
202  //------------------------- RICH ----------------
203  PndRich *Rich= new PndRich("RICH",kTRUE);
204  Rich->SetGeometryFileName("rich_v313.root");
205  AddModule(Rich);
206 }
207 
208 // ----- CreateGeometry -------------------------------------------------
210 {
211  //------------------------- CAVE -----------------
212  FairModule *Cave= new PndCave("CAVE");
213  Cave->SetGeometryFileName("pndcave.geo");
214  AddModule(Cave);
215  //------------------------- Magnet -----------------
216  // This part is commented because the MDT geometry contains the magnet now
217  //FairModule *Magnet= new PndMagnet("MAGNET");
218  //Magnet->SetGeometryFileName("FullSolenoid_V842.root");
219  //Magnet->SetGeometryFileName("FullSuperconductingSolenoid_v831.root");
220  //AddModule(Magnet);
221  FairModule *Dipole= new PndMagnet("MAGNET");
222  Dipole->SetGeometryFileName("dipole.geo");
223  AddModule(Dipole);
224  //------------------------- Pipe -----------------
225  FairModule *Pipe= new PndPipe("PIPE");
226  Pipe->SetGeometryFileName("beampipe_201309.root");
227  AddModule(Pipe);
228  //------------------------- STT -----------------
229  FairDetector *Stt= new PndStt("STT", kTRUE);
230  Stt->SetGeometryFileName("straws_skewed_blocks_35cm_pipe.geo");
231  AddModule(Stt);
232  //------------------------- MVD -----------------
233  FairDetector *Mvd = new PndMvdDetector("MVD", kTRUE);
234  Mvd->SetGeometryFileName("Mvd-2.1_FullVersion.root");
235  AddModule(Mvd);
236  //------------------------- GEM -----------------
237  FairDetector *Gem = new PndGemDetector("GEM", kTRUE);
238  Gem->SetGeometryFileName("gem_3Stations_realistic_v2.root");
239  AddModule(Gem);
240  //------------------------- EMC -----------------
241  PndEmc *Emc = new PndEmc("EMC",kTRUE);
242  Emc->SetGeometryVersion(1);
243  Emc->SetStorageOfData(kFALSE);
244  AddModule(Emc);
245  //------------------------- SCITIL -----------------
246  FairDetector *SciT = new PndSciT("SCIT",kTRUE);
247  SciT->SetGeometryFileName("SciTil_201601.root");
248  AddModule(SciT);
249  //------------------------- DRC -----------------
250  PndDrc *Drc = new PndDrc("DIRC", kTRUE);
251  Drc->SetGeometryFileName("dirc_e3_b3_l6_m40.root");
252  Drc->SetRunCherenkov(kFALSE);
253  AddModule(Drc);
254  //------------------------- DISC -----------------
255  //PndDsk* Dsk = new PndDsk("DSK", kTRUE);
256  //Dsk->SetStoreCerenkovs(kFALSE);
257  //Dsk->SetStoreTrackPoints(kFALSE);
258  //AddModule(Dsk);
259  //------------------------- MDT -----------------
260  PndMdt *Muo = new PndMdt("MDT",kTRUE);
261  Muo->SetBarrel("fast");
262  Muo->SetEndcap("fast");
263  Muo->SetMuonFilter("fast");
264  Muo->SetForward("fast");
265  Muo->SetMdtMagnet(kTRUE);
266  Muo->SetMdtCoil(kTRUE);
267  Muo->SetMdtMFIron(kTRUE);
268  AddModule(Muo);
269  //------------------------- FTS -----------------
270  FairDetector *Fts= new PndFts("FTS", kTRUE);
271  Fts->SetGeometryFileName("fts.geo");
272  AddModule(Fts);
273  //------------------------- FTOF -----------------
274  FairDetector *FTof = new PndFtof("FTOF",kTRUE);
275  FTof->SetGeometryFileName("ftofwall.root");
276  AddModule(FTof);
277  //------------------------- RICH ----------------
278  //PndRich *Rich= new PndRich("RICH",kTRUE);
279  //Rich->SetGeometryFileName("rich_v313.root");
280  //AddModule(Rich);
281 }
282 
283 // ----- CreateGeometryDay1 ---------------------------------------------
285 {
286  //------------------------- CAVE -----------------
287  FairModule *Cave= new PndCave("CAVE");
288  Cave->SetGeometryFileName("pndcave.geo");
289  AddModule(Cave);
290  //------------------------- Magnet -----------------
291  // This part is commented because the MDT geometry contains the magnet now
292  //FairModule *Magnet= new PndMagnet("MAGNET");
293  //Magnet->SetGeometryFileName("FullSolenoid_V842.root");
294  //Magnet->SetGeometryFileName("FullSuperconductingSolenoid_v831.root");
295  //AddModule(Magnet);
296  FairModule *Dipole= new PndMagnet("MAGNET");
297  Dipole->SetGeometryFileName("dipole.geo");
298  AddModule(Dipole);
299  //------------------------- Pipe -----------------
300  FairModule *Pipe= new PndPipe("PIPE");
301  Pipe->SetGeometryFileName("beampipe_201309.root");
302  AddModule(Pipe);
303  //------------------------- STT -----------------
304  FairDetector *Stt= new PndStt("STT", kTRUE);
305  Stt->SetGeometryFileName("straws_skewed_blocks_35cm_pipe.geo");
306  AddModule(Stt);
307  //------------------------- MVD -----------------
308  if (fOptions.Contains("strip")||fOptions.Contains("nopixels")){
309  FairDetector *Mvd = new PndMvdDetector("MVD", kTRUE);
310  Mvd->SetGeometryFileName("Mvd-2.1-Strips.root");
311  AddModule(Mvd);
312  } else {
313  FairDetector *Mvd = new PndMvdDetector("MVD", kTRUE);
314  Mvd->SetGeometryFileName("Mvd-2.1_FullVersion.root");
315  AddModule(Mvd);
316  }
317  //------------------------- EMC -----------------
318  PndEmc *Emc = new PndEmc("EMC",kTRUE);
319  Emc->SetGeometryVersion(1);
320  Emc->SetStorageOfData(kFALSE);
321  AddModule(Emc);
322  //------------------------- SCITIL -----------------
323  FairDetector *SciT = new PndSciT("SCIT",kTRUE);
324  SciT->SetGeometryFileName("SciTil_201601.root");
325  AddModule(SciT);
326  //------------------------- DRC -----------------
327  PndDrc *Drc = new PndDrc("DIRC", kTRUE);
328  Drc->SetGeometryFileName("dirc_e3_b3_l6_m40.root");
329  Drc->SetRunCherenkov(kFALSE);
330  AddModule(Drc);
331  //------------------------- MDT -----------------
332  PndMdt *Muo = new PndMdt("MDT",kTRUE);
333  Muo->SetBarrel("fast");
334  Muo->SetEndcap("fast");
335  Muo->SetMuonFilter("fast");
336  Muo->SetForward("fast");
337  Muo->SetMdtMagnet(kTRUE);
338  Muo->SetMdtCoil(kTRUE);
339  Muo->SetMdtMFIron(kTRUE);
340  AddModule(Muo);
341  //------------------------- FTOF -----------------
342  FairDetector *FTof = new PndFtof("FTOF",kTRUE);
343  FTof->SetGeometryFileName("ftofwall.root");
344  AddModule(FTof);
345 
346  if (fOptions.Contains("nogem")||fOptions.Contains("gem0")) {
347  // do nothing
348  }
349  else if (fOptions.Contains("gem3")) // GEM 3 Stations
350  {
351  FairDetector *Gem = new PndGemDetector("GEM", kTRUE);
352  Gem->SetGeometryFileName("gem_3Stations_realistic_v2.root");
353  AddModule(Gem);
354  }
355  else //GEM 2 Stations
356  {
357  //------------------------- GEM -----------------
358  FairDetector *Gem = new PndGemDetector("GEM", kTRUE);
359  Gem->SetGeometryFileName("gem_2Stations_realistic_v2.root");
360  AddModule(Gem);
361  }
362 
363  if (fOptions.Contains("fts1256"))
364  {
365  //------------------------- FTS -----------------
366  FairDetector *Fts= new PndFts("FTS", kTRUE);
367  Fts->SetGeometryFileName("fts_1256.geo");
368  AddModule(Fts);
369  }
370  else
371  {
372  //------------------------- FTS -----------------
373  FairDetector *Fts= new PndFts("FTS", kTRUE);
374  Fts->SetGeometryFileName("fts_reduced.geo");
375  AddModule(Fts);
376  }
377 }
378 
379 // ----- AddSimTasks ---------------------------------------------------
381 {
382  // ----- Event Counter --------------------------------
383  AddTask(new PndEventCounterTask("Event Counter", fNEvents, fEventCounterRate));
384 
386  AddTask(sim);
387 
388  return;
389 }
390 
391 // ----- SetGenerator --------------------------------------------------
393 {
394  if (fOptions.Contains("pndfiltprim"))
395  fGen = new PndFilteredPrimaryGenerator();
396  else
397  fGen = new FairFilteredPrimaryGenerator();
398 
399  switch (fTargetMode)
400  {
401  case 0:
402  LOG(INFO) << "Using no Vertex smearing" << FairLogger::endl;
403  break;
404  case 1:
405  LOG(INFO) << "Using Cluster Jet Target" << FairLogger::endl;
406  // a cluster-jet beam at the interaction zone with a horizontal width
407  // of e.g. dx = 1 mm and a length in accelerator beam direction of dz = 10 mm.
408  // Target TDR, page 44
409  fGen->SetTarget(0., 1./2.355); // From FWHM to sigma
410  fGen->SmearVertexZ(kTRUE);
411  fGen->SmearGausVertexZ(kTRUE);
412  fGen->SetBeam(0., 0., 0.1, 0.1);
413  fGen->SmearVertexXY(kTRUE);
414  break;
415  case 2:
416  LOG(INFO) << "Using Pellet Target" << FairLogger::endl;
417  // At PANDA a beam diameter around 3mm is needed and one may want even
418  // smaller size when PTR is not possible.
419  // Target TDR, page 61
420  fGen->SetTarget(0., 0.3);
421  fGen->SmearVertexZ(kTRUE);
422  fGen->SmearGausVertexZ(kTRUE);
423  fGen->SetBeam(0., 0., 0.3, 0.3);
424  fGen->SmearVertexXY(kTRUE);
425  break;
426  case 3:
427  LOG(INFO) << "Using Pellet Tracking Target" << FairLogger::endl;
428  // A position resolution σ(x, y, z) < 0.2 mm in the in- teraction position
429  // is desirable for event reconstruc- tion.
430  // Target TDR, page 61
431  fGen->SetTarget(0., 0.02);
432  fGen->SmearVertexZ(kTRUE);
433  fGen->SmearGausVertexZ(kTRUE);
434  fGen->SetBeam(0., 0., 0.02, 0.02);
435  fGen->SmearVertexXY(kTRUE);
436  break;
437  default:
438  LOG(INFO) << "Unkwown target mode - Using no vertex smearing" << FairLogger::endl;
439  }
440 
441  TString input = fInput;
442  input.ToLower();
443 
444  if (input.EndsWith(".dec") || input.Contains(".dec:"))
445  {
447  }
448  else if (input.BeginsWith("dpm"))
449  {
450  UseDpmGenerator();
451  }
452  else if (input.BeginsWith("ftf"))
453  {
455  }
456  else if (input.BeginsWith("box"))
457  {
459  }
460  else if (input.BeginsWith("pipi"))
461  {
463  }
464  else
465  {
466  LOG(WARNING)<< "Generator could not be identified from input '"<<fInput.Data()<<"'!!" << FairLogger::endl;
467  }
468 
469 }
470 
472 {
473  // use BOX generator; defaults
474 
475  Double_t BoxMomMin = 0.05; // minimum momentum for box generator
476  Double_t BoxMomMax = 10.; // maximum " "
477  Double_t BoxThtMin = 0. ; // minimum theta for box generator
478  Double_t BoxThtMax = 180.; // maximum " "
479  Double_t BoxPhiMin = 0. ; // minimum phi for box generator
480  Double_t BoxPhiMax = 360.; // maximum " "
481  Bool_t BoxCosTht = false; // isotropic in cos(theta) instead theta
482  Bool_t BoxPt = false; // is pt given instead of p
483 
484  Int_t BoxType = 13; // default particle muon
485  Int_t BoxMult = 1; // default particle multiplicity
486  Double_t type=0,mult=0; // ref. parameters for range function
487 
488  BoxConfig.ToLower();
489 
490  if (BoxConfig!="box")
491  {
492  BoxConfig.ReplaceAll("box","");
493  BoxConfig.ReplaceAll(" ","");
494  BoxConfig += ":";
495 
496  while (BoxConfig.Contains(":"))
497  {
498  TString curpar = BoxConfig(0,BoxConfig.Index(":"));
499  BoxConfig = BoxConfig(BoxConfig.Index(":")+1,1000);
500  curpar.ReplaceAll("[","(");
501  curpar.ReplaceAll("]",")");
502 
503  if (curpar.BeginsWith("type(")) {GetRange(curpar,type,mult); BoxType = (Int_t)type; BoxMult = (Int_t)mult; }
504  if (curpar.BeginsWith("p(")) GetRange(curpar,BoxMomMin,BoxMomMax);
505  if (curpar.BeginsWith("pt(")) {GetRange(curpar,BoxMomMin,BoxMomMax); BoxPt = true;}
506  if (curpar.BeginsWith("tht(")) GetRange(curpar,BoxThtMin,BoxThtMax);
507  if (curpar.BeginsWith("ctht(")) {GetRange(curpar,BoxThtMin,BoxThtMax); BoxCosTht=true;}
508  if (curpar.BeginsWith("phi(")) GetRange(curpar,BoxPhiMin,BoxPhiMax);
509  }
510  }
511 
512  PndBoxGenerator* boxGen = new PndBoxGenerator(BoxType, BoxMult);
513  boxGen->SetDebug(0);
514 
515  if (BoxPt == true){
516  boxGen->SetPtRange(BoxMomMin, BoxMomMax);
517  } else {
518  boxGen->SetPRange(BoxMomMin,BoxMomMax); // GeV/c
519  }
520  boxGen->SetPhiRange(BoxPhiMin, BoxPhiMax); // Azimuth angle range [degree]
521  boxGen->SetThetaRange(BoxThtMin, BoxThtMax); // Polar angle in lab system range [degree]
522 
523  if (BoxCosTht) boxGen->SetCosTheta();
524 
525  boxGen->SetXYZ(0., 0., 0.); //cm
526 
527  LOG(INFO) << "Using PndBoxGenerator(" << GetBeamMom() <<", pdg="<<BoxType<<" mult="<<BoxMult
528  <<" ) generator with range p["<<BoxMomMin<<","<<BoxMomMax<<"] tht["<<BoxThtMin<<","<<BoxThtMax<<"]"<<(BoxCosTht?"*":"")<<" phi["<<BoxPhiMin<<","<<BoxPhiMax<<"]" << FairLogger::endl;
529 
530  // cout <<"BOX generator range: p["<<BoxMomMin<<","<<BoxMomMax<<"] tht["<<BoxThtMin<<","<<BoxThtMax<<"]"<<(BoxCosTht?"*":"")<<" phi["<<BoxPhiMin<<","<<BoxPhiMax<<"]"<<endl;
531 
532  fGen->AddGenerator(boxGen);
533 }
534 
536 {
537  // use BOX generator; defaults
538 
539  Double_t cosThetaMin = 0.0;
540  Double_t cosThetaMax = 1.0;
541 
542  pipiConfig.ToLower();
543 
544  if (pipiConfig!="pipi")
545  {
546  pipiConfig.ReplaceAll("pipi","");
547  pipiConfig.ReplaceAll(" ","");
548  pipiConfig += ":";
549 
550  while (pipiConfig.Contains(":"))
551  {
552  TString curpar = pipiConfig(0,pipiConfig.Index(":"));
553  pipiConfig = pipiConfig(pipiConfig.Index(":")+1,1000);
554  curpar.ReplaceAll("[","(");
555  curpar.ReplaceAll("]",")");
556 
557  if (curpar.BeginsWith("cosTheta(")) GetRange(curpar, cosThetaMin, cosThetaMax);
558  }
559  }
560 
561  PndPiPiGenerator* pipiGen = new PndPiPiGenerator();
562  pipiGen->SetBeamMom(GetBeamMom());
563  pipiGen->SetCosThetaMin(cosThetaMin);
564  pipiGen->SetCosThetaMax(cosThetaMax);
565 
566 
567  LOG(INFO) << "Using PndPiPiGenerator(BeamMom = " << GetBeamMom() << " GeV/c, cosThetaRange = "<< cosThetaMin << " : " << cosThetaMax << ")" << FairLogger::endl;
568 
569  // cout <<"BOX generator range: p["<<BoxMomMin<<","<<BoxMomMax<<"] tht["<<BoxThtMin<<","<<BoxThtMax<<"]"<<(BoxCosTht?"*":"")<<" phi["<<BoxPhiMin<<","<<BoxPhiMax<<"]"<<endl;
570 
571  fGen->AddGenerator(pipiGen);
572 }
573 
575 {
576  // use BOX generator; defaults
577 
578  Double_t cosThetaMin = 0.0;
579  Double_t cosThetaMax = 1.0;
580  Double_t pid = -1.0;
581  Double_t GeGmRatio = -1.0;
582  Double_t dummy = 1.0;
583 
584  leplepConfig.ToLower();
585 
586  if (leplepConfig!="")
587  {
588  leplepConfig.ReplaceAll("leplep","");
589  leplepConfig.ReplaceAll(" ","");
590  leplepConfig += ":";
591 
592  while (leplepConfig.Contains(":"))
593  {
594  TString curpar = leplepConfig(0,leplepConfig.Index(":"));
595  leplepConfig = leplepConfig(leplepConfig.Index(":")+1,1000);
596  curpar.ReplaceAll("[","(");
597  curpar.ReplaceAll("]",")");
598 
599  if (curpar.BeginsWith("pid(")) GetRange(curpar, pid, dummy);
600  if (curpar.BeginsWith("gegm(")) GetRange(curpar, GeGmRatio, dummy);
601  if (curpar.BeginsWith("cosTheta(")) GetRange(curpar, cosThetaMin, cosThetaMax);
602  }
603  }
604 
605  PndLepLepGenerator* leplepGen = new PndLepLepGenerator();
606  leplepGen->SetBeamMom(GetBeamMom());
607 
608  leplepGen->SetCosThetaMin(cosThetaMin);
609  leplepGen->SetCosThetaMax(cosThetaMax);
610 
611 
612  LOG(INFO) << "Using PndleplepGenerator(BeamMom = " << GetBeamMom() << " GeV/c, cosThetaRange = "<< cosThetaMin << " : " << cosThetaMax << ")" << FairLogger::endl;
613 
614  // cout <<"BOX generator range: p["<<BoxMomMin<<","<<BoxMomMax<<"] tht["<<BoxThtMin<<","<<BoxThtMax<<"]"<<(BoxCosTht?"*":"")<<" phi["<<BoxPhiMin<<","<<BoxPhiMax<<"]"<<endl;
615 
616  fGen->AddGenerator(leplepGen);
617 }
618 
619 // ----- SetGenerator --------------------------------------------------
621 {
622  LOG(INFO) << "Using PndBoxGenerator generator" << FairLogger::endl;
623  if (fOptions.Contains("PndFiltPrim"))
624  fGen = new PndFilteredPrimaryGenerator();
625  else
626  fGen = new FairFilteredPrimaryGenerator();
627  fGen->AddGenerator(boxGen);
628 }
629 
630 // ----- SetGenerator --------------------------------------------------
632  {
633  LOG(INFO) << "Using FairBoxGenerator generator" << FairLogger::endl;
634  if (fOptions.Contains("PndFiltPrim"))
635  fGen = new PndFilteredPrimaryGenerator();
636  else
637  fGen = new FairFilteredPrimaryGenerator();
638  fGen->AddGenerator(boxGen);
639 }
640 
641 // ----- UseDpmGenerator -----------------------------------------------
643 {
644  LOG(INFO) << "Using PndDpmDirect(" << GetBeamMom() << ", " << fDpmFlag << ") generator" << FairLogger::endl;
645  PndDpmDirect *Dpm= new PndDpmDirect(GetBeamMom(), fDpmFlag);
646  fGen->AddGenerator(Dpm);
647 }
648 
649 // ----- UseFtfGenerator -----------------------------------------------
651 {
652  //if ( strncmp(fName,"TGeant4",7 ) == 0 ) LOG(FATAL) << "FTF does not run with Geant4 !!!" << FairLogger::endl;
653  if (ftfData.Contains(".root")){
654  LOG(INFO) << "Using PndFtfGenerator with input file " << ftfData << FairLogger::endl;
655  PndFtfGenerator* Ftf = new PndFtfGenerator(ftfData);
656  fGen->AddGenerator(Ftf);
657  } else {
658  LOG(INFO) << "Using PndFtfDirect(anti_proton, G4_H, 1, ftfp, " << GetBeamMom() << ", " << gRandom->GetSeed() <<", "<<fFtfFlag<< ") generator" << FairLogger::endl;
659  PndFtfDirect *Ftf = new PndFtfDirect("anti_proton", "G4_H", 1, "ftfp", GetBeamMom(), gRandom->GetSeed(), fFtfFlag);
660  fGen->AddGenerator(Ftf);
661  }
662 }
663 
664 // ----- UseEvtGenGenerator --------------------------------------------
666 {
667 
668  TString IniRes="";
669 
670  if (EvtGenFile.Contains(":")) // is the initial resonance provide as <decfile>.dec:iniRes ?
671  {
672  IniRes = EvtGenFile(EvtGenFile.Index(":")+1,1000);
673  EvtGenFile = EvtGenFile(0,EvtGenFile.Index(":"));
674  }
675 
676  if (IniRes=="") // we need to search the decay file
677  {
678  TString fnamepath=fInputDir+EvtGenFile;
679  std::ifstream fs(fnamepath.Data());
680  char line[250];
681 
682  while (fs)
683  {
684  fs.getline(line,249);
685  TString s(line);
686  s.ReplaceAll("\r","");
687  if (IniRes=="" && s.Contains("Decay "))
688  {
689  if (s.Contains("#")) s=s(0,s.Index("#"));
690  s.ReplaceAll("Decay ","");
691  s.ReplaceAll(" ","");
692  IniRes = s;
693  }
694  }
695  fs.close();
696  }
697  /*
698  // Looping over the dec file trying to find the first string "Decay", in order to find the initai
699  // state as the following string
700  FILE *dec = fopen(fInputDir+EvtGenFile,"r");
701  if (dec==NULL) LOG(FATAL) << "The EvtGen dec file does not exist!! " << EvtGenFile << FairLogger::endl;
702 
703  char temp[6], particle[20];
704  Bool_t found = kFALSE;
705  while(fgets(temp, 6, dec) !=NULL)
706  {
707  if((strstr(temp, "Decay")) != NULL)
708  {
709  fscanf(dec, "%s",particle);
710  LOG(INFO) << "It was found a " << particle << " as initial state." << FairLogger::endl;
711  found = kTRUE;
712  break;
713  }
714  }
715  */
716  if (IniRes=="") LOG(FATAL) << "The input file is not a proper .dec!! " << FairLogger::endl;
717 
718  // TString EvtInput =gSystem->Getenv("VMCWORKDIR");
719  // EvtInput+="/macro/run/psi2s_Jpsi2pi_Jpsi_mumu.dec";
720  LOG(INFO) << "Using PndEvtGenDirect(" <<IniRes << ", " << (fInputDir+EvtGenFile).Data() << ", " << GetBeamMom() << ") generator" << FairLogger::endl;
721  PndEvtGenDirect *EvtGen = new PndEvtGenDirect(IniRes, (fInputDir+EvtGenFile).Data(), GetBeamMom());
722  EvtGen->SetStoreTree(kTRUE);
723  fGen->AddGenerator(EvtGen);
724 
725 }
726 
727 // ----- Finish ---------------------------------------------------------
729 {
730  fRtdb->saveOutput();
731 
732  cout<<"PndMasterRunAna::Finish(): Tasks that ran just now:"<<endl;
733  TFile* outfile=fRootManager->GetOutFile();
734  bool wasopen=outfile->IsOpen ();
735  if (!wasopen)
736  {
737  cout<<"file is "<< ((wasopen) ? "" : "not " ) <<"open" <<endl;
738  outfile=new TFile(outfile->GetName(),"UPDATE");
739  }
740  outfile->cd();
741 
742  // write the summary of event filter to output root file
743  if (!strcmp(fGen->ClassName(),"PndFilteredPrimaryGenerator"))
744  ((PndFilteredPrimaryGenerator*)fGen)->WriteEvtFilterStatsToRootFile(outfile);
745  else
746  ((FairFilteredPrimaryGenerator*)fGen)->WriteEvtFilterStatsToRootFile(outfile);
747 
748  FairFileHeader* outheader=(FairFileHeader*)outfile->Get("FileHeader");
749  cout<<"Task tha ran just now:"<<endl;
750  for(const auto&& os : *(outheader->GetListOfTasks()) ) cout<<" - "<<((TObjString*)os)->GetString().Data()<<endl;
751 
752  TObjString outoptions(fOptions);
753  outoptions.Write("PndOptions",kOverwrite);
754 
755  outfile->Write();
756  if(!wasopen) outfile->Close();
757 
758  cout << endl;
759  if (gROOT->GetVersionInt() >= 60602) {
760  gGeoManager->GetListOfVolumes()->Delete();
761  gGeoManager->GetListOfShapes()->Delete();
762  delete gGeoManager;
763  }
764 
765  // Extract the maximal used memory an add is as Dart measurement
766  // This line is filtered by CTest and the value send to CDash
767  FairSystemInfo sysInfo;
768  Float_t maxMemory=sysInfo.GetMaxMemory();
769  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
770  cout << maxMemory;
771  cout << "</DartMeasurement>" << endl;
772 
773  fTimer.Stop();
774  Double_t rtime = fTimer.RealTime();
775  Double_t ctime = fTimer.CpuTime();
776 
777  Float_t cpuUsage=ctime/rtime;
778  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
779  cout << cpuUsage;
780  cout << "</DartMeasurement>" << endl;
781 
782  cout << endl;
783  cout << "Output file is\t\t" << fOutFile << endl;
784  cout << "Parameter ROOT file is\t" << fParamRootFile << endl;
785  cout << "Parameter ASCII file is\t" << fParamAsciiFile << endl;
786  cout << "Real time " << rtime << " s, CPU time " << ctime
787  << "s" << endl;
788  cout << "CPU usage " << cpuUsage*100. << "%" << endl;
789  cout << "Max Memory " << maxMemory << " MB" << endl;
790 
791  cout << "Macro finished successfully." << endl;
792 
793 }
794 
795 // -----Helper function for parameter parsing ---------------------------------------------------------
796 // par = string parameter like 'varname(min,max)' of 'varname(value)'
797 
798 void PndMasterRunSim::GetRange(TString par, double &min, double &max)
799 {
800  par.ReplaceAll(" ","");
801  par = par(par.Index("(")+1, par.Length()-par.Index("(")-2);
802 
803  TString smin=par, smax=par;
804 
805  if (par.Contains(","))
806  {
807  smin = par(0,par.Index(","));
808  smax = par(par.Index(",")+1,1000);
809  }
810 
811  min = smin.Atof();
812  max = smax.Atof();
813 }
814 
PndDrc * Drc
Definition: sim_emc_apd.C:75
TString fInput
Name of the input for the simulation.
void SetForward(TString name)
Definition: PndMdt.h:34
void SetThetaRange(Double32_t thetamin=0, Double32_t thetamax=90)
FairDetector * FTof
Definition: sim_ftof.C:49
Int_t fFtfFlag
Flag for FTF event generator.
sim(Int_t nEvents=1, TString SimEngine="TGeant4", Float_t mom=6.231552)
void Finish()
Final diagnostics.
void CreateGeometryDefault()
It creates all the standard geometry volumes.
void SetBeamMom(Double_t in_P)
Bool_t kParameterMerged
Definition: sim_emc_apd.C:113
Int_t fNEvents
Number of events.
void SetBeamMom(Double_t in_P)
The default sim tasks.
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
void SetCosThetaMax(Double_t in_cos_theta_max)
TLorentzVector s
Definition: Pnd2DStar.C:50
void SetXYZ(Double32_t x=0, Double32_t y=0, Double32_t z=0)
PndEmc * Emc
Definition: sim_emc_apd.C:55
void SetMdtCoil(bool opt=false)
Definition: PndMdt.h:28
int pid()
Double_t par[3]
Bool_t Setup(TString outprefix="")
Initial setup.
FairDetector * Mvd
Definition: sim_emc_apd.C:51
void SetMdtMFIron(bool opt=false)
Definition: PndMdt.h:29
Double_t mom
Definition: plot_dirc.C:14
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
void SetStorageOfData(Bool_t val)
Definition: PndEmc.cxx:941
TGeoManager * gGeoManager
void UseEvtGenGenerator(TString EvtGenFile)
Use EvtGen as event generator.
Short_t fTargetMode
Target mode.
TString allDigiFile
Definition: hit_muo.C:36
void UseDpmGenerator()
Use DPM as event generator.
PndMdt * Muo
Definition: sim_emc_apd.C:67
Simulation of EMC.
Definition: PndEmc.h:26
TString fOptions
Options parsed to the simulation.
Int_t fEventCounterRate
After how many events the counter will print.
FairDetector * Dsk
Definition: run_DpmSim.C:66
TString parOutput
TString fOutFile
Definition: run_full.C:10
virtual ~PndMasterRunSim()
Default destructor.
void AddSimTasks()
Add simulation tasks.
FairDetector * Gem
Definition: runJohan.C:71
void SetMdtMagnet(bool opt=false)
Definition: PndMdt.h:27
Primary generator with added event filtering capabilities.
void SetStoreTrackPoints(Bool_t storeTrackPoints)
Definition: PndDsk.h:148
void SetStoreTree(Bool_t store=true)
FairDetector * Stt
Definition: sim_emc_apd.C:47
void SetParamRootFile(TString par)
Setter of the parameter root file.
A simple class which adds the corresponding file extensions to a given base class.
void SetStoreCerenkovs(Bool_t storeCerenkovs)
Definition: PndDsk.h:146
Double_t
FairModule * Dipole
Definition: sim_emc_apd.C:40
FairModule * Cave
Definition: sim_emc_apd.C:32
Definition: PndDrc.h:31
void UsePiPiGenerator(TString pipiConfig)
Use PiPiGenerator as event generator.
virtual void SetGeometryVersion(const Int_t GeoNumber)
Definition: PndEmc.cxx:966
void SetBarrel(TString name)
Definition: PndMdt.h:31
Primary generator with added event filtering capabilities.
void SetPtRange(Double32_t ptmin=0, Double32_t ptmax=10)
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
void SetCosThetaMax(Double_t in_cos_theta_max)
void CreateGeometry()
It switches between different standard geometry volumes.
void CreateGeometryDay1()
It creates the standard geometry volumes for day1 phase.
fRun AddTask(drcdigi)
void SetDebug(Bool_t debug=0)
fRun SetField(fField)
Class for the master simulation chain.
void UseFtfGenerator(TString ftfData)
Use FTF as event generator.
void SetCosThetaMin(Double_t in_cos_theta_min)
Double_t ctime
Definition: hit_dirc.C:114
FairParAsciiFileIo * parIo1
Definition: bump_emc.C:53
FairBoxGenerator * boxGen
Definition: sim_emc_apd.C:85
TString fParamRootFile
Name of the parameter root file.
fRun AddModule(Cave)
fRun SetMaterials("media_pnd.geo")
fRun SetOutputFile(outFile)
void SetEndcap(TString name)
Definition: PndMdt.h:32
void SetMuonFilter(TString name)
Definition: PndMdt.h:33
PndMvdCreateDefaultApvMap * creator
void GetRange(TString par, double &min, double &max)
PndMasterRunSim()
Default constructor.
void SetRunCherenkov(Bool_t ch)
Definition: PndDrc.h:222
void UseBoxGenerator(TString BoxConfig)
Use BoxGen as event generator.
FairRuntimeDb * fRtdb
Runtime DB.
void SetCosThetaMin(Double_t in_cos_theta_min)
Definition: PndStt.h:34
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
Definition: PndMdt.h:20
ClassImp(PndAnaContFact)
TLorentzVector fIni
Definition: full_core_ntp.C:29
TString fOutFile
Name of the output file.
FairModule * Pipe
Definition: sim_emc_apd.C:44
fRun SetUseFairLinks(kTRUE)
Double_t rtime
Definition: hit_dirc.C:113
FairDetector * Fts
Definition: sim_ftof_stof.C:58
TStopwatch fTimer
Timer.
Definition: PndDsk.h:23
void SetGenerator()
Set the event generator.
TString fInputDir
Name of the input directory for the simulation.
void CreateGeometryPhase1()
It creates the standard geometry volumes for phase1 of the experiment.
TString fParamAsciiFile
Name of the parameter ascii file.
Double_t mult
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
TString outfile
void UseLepLepGenerator(TString leplepConfig)
Use LepLepGenerator as event generator.
Definition: PndFts.h:25
Int_t fDpmFlag
Flag for DPM event generator.
Definition: PndCave.h:8