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("pbarpSystem" ,"pbarpSystem", fIni.M(), kFALSE, 0.1, 0, "", 88888);
116  TDatabasePDG::Instance()->AddParticle("pbarpSystem0","pbarpSystem0", fIni.M(), kFALSE, 0.1, 0, "", 88880);
117  TDatabasePDG::Instance()->AddParticle("pbarpSystem1","pbarpSystem1", fIni.M(), kFALSE, 0.1, 0, "", 88881);
118  TDatabasePDG::Instance()->AddParticle("pbarpSystem2","pbarpSystem2", fIni.M(), kFALSE, 0.1, 0, "", 88882);
119 
120  if (fOptions.Contains("day1")) fTargetMode = 1;
121  return kTRUE;
122 }
123 
124 // ----- CreateGeometry -------------------------------------------------
126 {
127  if (fOptions.Contains("phase1")) CreateGeometryPhase1();
128  else if (fOptions.Contains("day1")) CreateGeometryDay1();
129  else CreateGeometryDefault();
130 }
131 
132 // ----- CreateGeometry -------------------------------------------------
134 {
135  //------------------------- CAVE -----------------
136  FairModule *Cave= new PndCave("CAVE");
137  Cave->SetGeometryFileName("pndcave.geo");
138  AddModule(Cave);
139  //------------------------- Magnet -----------------
140  // This part is commented because the MDT geometry contains the magnet now
141  //FairModule *Magnet= new PndMagnet("MAGNET");
142  //Magnet->SetGeometryFileName("FullSolenoid_V842.root");
143  //Magnet->SetGeometryFileName("FullSuperconductingSolenoid_v831.root");
144  //AddModule(Magnet);
145  FairModule *Dipole= new PndMagnet("MAGNET");
146  Dipole->SetGeometryFileName("dipole.geo");
147  AddModule(Dipole);
148  //------------------------- Pipe -----------------
149  FairModule *Pipe= new PndPipe("PIPE");
150  Pipe->SetGeometryFileName("beampipe_201309.root");
151  AddModule(Pipe);
152  //------------------------- STT -----------------
153  FairDetector *Stt= new PndStt("STT", kTRUE);
154  Stt->SetGeometryFileName("straws_skewed_blocks_35cm_pipe.geo");
155  AddModule(Stt);
156  //------------------------- MVD -----------------
157  FairDetector *Mvd = new PndMvdDetector("MVD", kTRUE);
158  Mvd->SetGeometryFileName("Mvd-2.1_FullVersion.root");
159  AddModule(Mvd);
160  //------------------------- GEM -----------------
161  FairDetector *Gem = new PndGemDetector("GEM", kTRUE);
162  Gem->SetGeometryFileName("gem_3Stations_realistic_v2.root");
163  AddModule(Gem);
164  //------------------------- EMC -----------------
165  PndEmc *Emc = new PndEmc("EMC",kTRUE);
166  Emc->SetGeometryVersion(1);
167  Emc->SetStorageOfData(kFALSE);
168  AddModule(Emc);
169  //------------------------- SCITIL -----------------
170  FairDetector *SciT = new PndSciT("SCIT",kTRUE);
171  SciT->SetGeometryFileName("SciTil_201601.root");
172  AddModule(SciT);
173  //------------------------- DRC -----------------
174  PndDrc *Drc = new PndDrc("DIRC", kTRUE);
175  Drc->SetGeometryFileName("dirc_e3_b3_l6_m40.root");
176  Drc->SetRunCherenkov(kFALSE);
177  AddModule(Drc);
178  //------------------------- DISC -----------------
179  PndDsk* Dsk = new PndDsk("DSK", kTRUE);
180  Dsk->SetStoreCerenkovs(kFALSE);
181  Dsk->SetStoreTrackPoints(kFALSE);
182  AddModule(Dsk);
183  //------------------------- MDT -----------------
184  PndMdt *Muo = new PndMdt("MDT",kTRUE);
185  Muo->SetBarrel("fast");
186  Muo->SetEndcap("fast");
187  Muo->SetMuonFilter("fast");
188  Muo->SetForward("fast");
189  Muo->SetMdtMagnet(kTRUE);
190  Muo->SetMdtCoil(kTRUE);
191  Muo->SetMdtMFIron(kTRUE);
192  AddModule(Muo);
193  //------------------------- FTS -----------------
194  FairDetector *Fts= new PndFts("FTS", kTRUE);
195  Fts->SetGeometryFileName("fts.geo");
196  AddModule(Fts);
197  //------------------------- FTOF -----------------
198  FairDetector *FTof = new PndFtof("FTOF",kTRUE);
199  FTof->SetGeometryFileName("ftofwall.root");
200  AddModule(FTof);
201  //------------------------- RICH ----------------
202  PndRich *Rich= new PndRich("RICH",kTRUE);
203  Rich->SetGeometryFileName("rich_v313.root");
204  AddModule(Rich);
205 }
206 
207 // ----- CreateGeometry -------------------------------------------------
209 {
210  //------------------------- CAVE -----------------
211  FairModule *Cave= new PndCave("CAVE");
212  Cave->SetGeometryFileName("pndcave.geo");
213  AddModule(Cave);
214  //------------------------- Magnet -----------------
215  // This part is commented because the MDT geometry contains the magnet now
216  //FairModule *Magnet= new PndMagnet("MAGNET");
217  //Magnet->SetGeometryFileName("FullSolenoid_V842.root");
218  //Magnet->SetGeometryFileName("FullSuperconductingSolenoid_v831.root");
219  //AddModule(Magnet);
220  FairModule *Dipole= new PndMagnet("MAGNET");
221  Dipole->SetGeometryFileName("dipole.geo");
222  AddModule(Dipole);
223  //------------------------- Pipe -----------------
224  FairModule *Pipe= new PndPipe("PIPE");
225  Pipe->SetGeometryFileName("beampipe_201309.root");
226  AddModule(Pipe);
227  //------------------------- STT -----------------
228  FairDetector *Stt= new PndStt("STT", kTRUE);
229  Stt->SetGeometryFileName("straws_skewed_blocks_35cm_pipe.geo");
230  AddModule(Stt);
231  //------------------------- MVD -----------------
232  FairDetector *Mvd = new PndMvdDetector("MVD", kTRUE);
233  Mvd->SetGeometryFileName("Mvd-2.1_FullVersion.root");
234  AddModule(Mvd);
235  //------------------------- GEM -----------------
236  FairDetector *Gem = new PndGemDetector("GEM", kTRUE);
237  Gem->SetGeometryFileName("gem_3Stations_realistic_v2.root");
238  AddModule(Gem);
239  //------------------------- EMC -----------------
240  PndEmc *Emc = new PndEmc("EMC",kTRUE);
241  Emc->SetGeometryVersion(1);
242  Emc->SetStorageOfData(kFALSE);
243  AddModule(Emc);
244  //------------------------- SCITIL -----------------
245  FairDetector *SciT = new PndSciT("SCIT",kTRUE);
246  SciT->SetGeometryFileName("SciTil_201601.root");
247  AddModule(SciT);
248  //------------------------- DRC -----------------
249  PndDrc *Drc = new PndDrc("DIRC", kTRUE);
250  Drc->SetGeometryFileName("dirc_e3_b3_l6_m40.root");
251  Drc->SetRunCherenkov(kFALSE);
252  AddModule(Drc);
253  //------------------------- DISC -----------------
254  //PndDsk* Dsk = new PndDsk("DSK", kTRUE);
255  //Dsk->SetStoreCerenkovs(kFALSE);
256  //Dsk->SetStoreTrackPoints(kFALSE);
257  //AddModule(Dsk);
258  //------------------------- MDT -----------------
259  PndMdt *Muo = new PndMdt("MDT",kTRUE);
260  Muo->SetBarrel("fast");
261  Muo->SetEndcap("fast");
262  Muo->SetMuonFilter("fast");
263  Muo->SetForward("fast");
264  Muo->SetMdtMagnet(kTRUE);
265  Muo->SetMdtCoil(kTRUE);
266  Muo->SetMdtMFIron(kTRUE);
267  AddModule(Muo);
268  //------------------------- FTS -----------------
269  FairDetector *Fts= new PndFts("FTS", kTRUE);
270  Fts->SetGeometryFileName("fts.geo");
271  AddModule(Fts);
272  //------------------------- FTOF -----------------
273  FairDetector *FTof = new PndFtof("FTOF",kTRUE);
274  FTof->SetGeometryFileName("ftofwall.root");
275  AddModule(FTof);
276  //------------------------- RICH ----------------
277  //PndRich *Rich= new PndRich("RICH",kTRUE);
278  //Rich->SetGeometryFileName("rich_v313.root");
279  //AddModule(Rich);
280 }
281 
282 // ----- CreateGeometryDay1 ---------------------------------------------
284 {
285  //------------------------- CAVE -----------------
286  FairModule *Cave= new PndCave("CAVE");
287  Cave->SetGeometryFileName("pndcave.geo");
288  AddModule(Cave);
289  //------------------------- Magnet -----------------
290  // This part is commented because the MDT geometry contains the magnet now
291  //FairModule *Magnet= new PndMagnet("MAGNET");
292  //Magnet->SetGeometryFileName("FullSolenoid_V842.root");
293  //Magnet->SetGeometryFileName("FullSuperconductingSolenoid_v831.root");
294  //AddModule(Magnet);
295  FairModule *Dipole= new PndMagnet("MAGNET");
296  Dipole->SetGeometryFileName("dipole.geo");
297  AddModule(Dipole);
298  //------------------------- Pipe -----------------
299  FairModule *Pipe= new PndPipe("PIPE");
300  Pipe->SetGeometryFileName("beampipe_201309.root");
301  AddModule(Pipe);
302  //------------------------- STT -----------------
303  FairDetector *Stt= new PndStt("STT", kTRUE);
304  Stt->SetGeometryFileName("straws_skewed_blocks_35cm_pipe.geo");
305  AddModule(Stt);
306  //------------------------- MVD -----------------
307  if (fOptions.Contains("strip")||fOptions.Contains("nopixels")){
308  FairDetector *Mvd = new PndMvdDetector("MVD", kTRUE);
309  Mvd->SetGeometryFileName("Mvd-2.1-Strips.root");
310  AddModule(Mvd);
311  } else {
312  FairDetector *Mvd = new PndMvdDetector("MVD", kTRUE);
313  Mvd->SetGeometryFileName("Mvd-2.1_FullVersion.root");
314  AddModule(Mvd);
315  }
316  //------------------------- EMC -----------------
317  PndEmc *Emc = new PndEmc("EMC",kTRUE);
318  Emc->SetGeometryVersion(1);
319  Emc->SetStorageOfData(kFALSE);
320  AddModule(Emc);
321  //------------------------- SCITIL -----------------
322  FairDetector *SciT = new PndSciT("SCIT",kTRUE);
323  SciT->SetGeometryFileName("SciTil_201601.root");
324  AddModule(SciT);
325  //------------------------- DRC -----------------
326  PndDrc *Drc = new PndDrc("DIRC", kTRUE);
327  Drc->SetGeometryFileName("dirc_e3_b3_l6_m40.root");
328  Drc->SetRunCherenkov(kFALSE);
329  AddModule(Drc);
330  //------------------------- MDT -----------------
331  PndMdt *Muo = new PndMdt("MDT",kTRUE);
332  Muo->SetBarrel("fast");
333  Muo->SetEndcap("fast");
334  Muo->SetMuonFilter("fast");
335  Muo->SetForward("fast");
336  Muo->SetMdtMagnet(kTRUE);
337  Muo->SetMdtCoil(kTRUE);
338  Muo->SetMdtMFIron(kTRUE);
339  AddModule(Muo);
340  //------------------------- FTOF -----------------
341  FairDetector *FTof = new PndFtof("FTOF",kTRUE);
342  FTof->SetGeometryFileName("ftofwall.root");
343  AddModule(FTof);
344 
345  if (fOptions.Contains("nogem")||fOptions.Contains("gem0")) {
346  // do nothing
347  }
348  else if (fOptions.Contains("gem3")) // GEM 3 Stations
349  {
350  FairDetector *Gem = new PndGemDetector("GEM", kTRUE);
351  Gem->SetGeometryFileName("gem_3Stations_realistic_v2.root");
352  AddModule(Gem);
353  }
354  else //GEM 2 Stations
355  {
356  //------------------------- GEM -----------------
357  FairDetector *Gem = new PndGemDetector("GEM", kTRUE);
358  Gem->SetGeometryFileName("gem_2Stations_realistic_v2.root");
359  AddModule(Gem);
360  }
361 
362  if (fOptions.Contains("fts1256"))
363  {
364  //------------------------- FTS -----------------
365  FairDetector *Fts= new PndFts("FTS", kTRUE);
366  Fts->SetGeometryFileName("fts_1256.geo");
367  AddModule(Fts);
368  }
369  else
370  {
371  //------------------------- FTS -----------------
372  FairDetector *Fts= new PndFts("FTS", kTRUE);
373  Fts->SetGeometryFileName("fts_reduced.geo");
374  AddModule(Fts);
375  }
376 }
377 
378 // ----- AddSimTasks ---------------------------------------------------
380 {
381  // ----- Event Counter --------------------------------
382  AddTask(new PndEventCounterTask("Event Counter", fNEvents, fEventCounterRate));
383 
385  AddTask(sim);
386 
387  return;
388 }
389 
390 // ----- SetGenerator --------------------------------------------------
392 {
393  if (fOptions.Contains("pndfiltprim"))
394  fGen = new PndFilteredPrimaryGenerator();
395  else
396  fGen = new FairFilteredPrimaryGenerator();
397 
398  switch (fTargetMode)
399  {
400  case 0:
401  LOG(INFO) << "Using no Vertex smearing" << FairLogger::endl;
402  break;
403  case 1:
404  LOG(INFO) << "Using Cluster Jet Target" << FairLogger::endl;
405  // a cluster-jet beam at the interaction zone with a horizontal width
406  // of e.g. dx = 1 mm and a length in accelerator beam direction of dz = 10 mm.
407  // Target TDR, page 44
408  fGen->SetTarget(0., 1./2.355); // From FWHM to sigma
409  fGen->SmearVertexZ(kTRUE);
410  fGen->SmearGausVertexZ(kTRUE);
411  fGen->SetBeam(0., 0., 0.1, 0.1);
412  fGen->SmearVertexXY(kTRUE);
413  break;
414  case 2:
415  LOG(INFO) << "Using Pellet Target" << FairLogger::endl;
416  // At PANDA a beam diameter around 3mm is needed and one may want even
417  // smaller size when PTR is not possible.
418  // Target TDR, page 61
419  fGen->SetTarget(0., 0.3);
420  fGen->SmearVertexZ(kTRUE);
421  fGen->SmearGausVertexZ(kTRUE);
422  fGen->SetBeam(0., 0., 0.3, 0.3);
423  fGen->SmearVertexXY(kTRUE);
424  break;
425  case 3:
426  LOG(INFO) << "Using Pellet Tracking Target" << FairLogger::endl;
427  // A position resolution σ(x, y, z) < 0.2 mm in the in- teraction position
428  // is desirable for event reconstruc- tion.
429  // Target TDR, page 61
430  fGen->SetTarget(0., 0.02);
431  fGen->SmearVertexZ(kTRUE);
432  fGen->SmearGausVertexZ(kTRUE);
433  fGen->SetBeam(0., 0., 0.02, 0.02);
434  fGen->SmearVertexXY(kTRUE);
435  break;
436  default:
437  LOG(INFO) << "Unkwown target mode - Using no vertex smearing" << FairLogger::endl;
438  }
439 
440  TString input = fInput;
441  input.ToLower();
442 
443  if (input.EndsWith(".dec") || input.Contains(".dec:"))
444  {
446  }
447  else if (input.BeginsWith("dpm"))
448  {
449  UseDpmGenerator();
450  }
451  else if (input.BeginsWith("ftf"))
452  {
454  }
455  else if (input.BeginsWith("box"))
456  {
458  }
459  else if (input.BeginsWith("pipi"))
460  {
462  }
463  else
464  {
465  LOG(FATAL)<< "Generator could not be identified from input '"<<fInput.Data()<<"'!!" << FairLogger::endl;
466  }
467 
468 }
469 
471 {
472  // use BOX generator; defaults
473 
474  Double_t BoxMomMin = 0.05; // minimum momentum for box generator
475  Double_t BoxMomMax = 10.; // maximum " "
476  Double_t BoxThtMin = 0. ; // minimum theta for box generator
477  Double_t BoxThtMax = 180.; // maximum " "
478  Double_t BoxPhiMin = 0. ; // minimum phi for box generator
479  Double_t BoxPhiMax = 360.; // maximum " "
480  Bool_t BoxCosTht = false; // isotropic in cos(theta) instead theta
481  Bool_t BoxPt = false; // is pt given instead of p
482 
483  Int_t BoxType = 13; // default particle muon
484  Int_t BoxMult = 1; // default particle multiplicity
485  Double_t type=0,mult=0; // ref. parameters for range function
486 
487  BoxConfig.ToLower();
488 
489  if (BoxConfig!="box")
490  {
491  BoxConfig.ReplaceAll("box","");
492  BoxConfig.ReplaceAll(" ","");
493  BoxConfig += ":";
494 
495  while (BoxConfig.Contains(":"))
496  {
497  TString curpar = BoxConfig(0,BoxConfig.Index(":"));
498  BoxConfig = BoxConfig(BoxConfig.Index(":")+1,1000);
499  curpar.ReplaceAll("[","(");
500  curpar.ReplaceAll("]",")");
501 
502  if (curpar.BeginsWith("type(")) {GetRange(curpar,type,mult); BoxType = (Int_t)type; BoxMult = (Int_t)mult; }
503  if (curpar.BeginsWith("p(")) GetRange(curpar,BoxMomMin,BoxMomMax);
504  if (curpar.BeginsWith("pt(")) {GetRange(curpar,BoxMomMin,BoxMomMax); BoxPt = true;}
505  if (curpar.BeginsWith("tht(")) GetRange(curpar,BoxThtMin,BoxThtMax);
506  if (curpar.BeginsWith("ctht(")) {GetRange(curpar,BoxThtMin,BoxThtMax); BoxCosTht=true;}
507  if (curpar.BeginsWith("phi(")) GetRange(curpar,BoxPhiMin,BoxPhiMax);
508  }
509  }
510 
511  PndBoxGenerator* boxGen = new PndBoxGenerator(BoxType, BoxMult);
512  boxGen->SetDebug(0);
513 
514  if (BoxPt == true){
515  boxGen->SetPtRange(BoxMomMin, BoxMomMax);
516  } else {
517  boxGen->SetPRange(BoxMomMin,BoxMomMax); // GeV/c
518  }
519  boxGen->SetPhiRange(BoxPhiMin, BoxPhiMax); // Azimuth angle range [degree]
520  boxGen->SetThetaRange(BoxThtMin, BoxThtMax); // Polar angle in lab system range [degree]
521 
522  if (BoxCosTht) boxGen->SetCosTheta();
523 
524  boxGen->SetXYZ(0., 0., 0.); //cm
525 
526  LOG(INFO) << "Using PndBoxGenerator(" << GetBeamMom() <<", pdg="<<BoxType<<" mult="<<BoxMult
527  <<" ) generator with range p["<<BoxMomMin<<","<<BoxMomMax<<"] tht["<<BoxThtMin<<","<<BoxThtMax<<"]"<<(BoxCosTht?"*":"")<<" phi["<<BoxPhiMin<<","<<BoxPhiMax<<"]" << FairLogger::endl;
528 
529  // cout <<"BOX generator range: p["<<BoxMomMin<<","<<BoxMomMax<<"] tht["<<BoxThtMin<<","<<BoxThtMax<<"]"<<(BoxCosTht?"*":"")<<" phi["<<BoxPhiMin<<","<<BoxPhiMax<<"]"<<endl;
530 
531  fGen->AddGenerator(boxGen);
532 }
533 
535 {
536  // use BOX generator; defaults
537 
538  Double_t cosThetaMin = 0.0;
539  Double_t cosThetaMax = 1.0;
540 
541  pipiConfig.ToLower();
542 
543  if (pipiConfig!="pipi")
544  {
545  pipiConfig.ReplaceAll("pipi","");
546  pipiConfig.ReplaceAll(" ","");
547  pipiConfig += ":";
548 
549  while (pipiConfig.Contains(":"))
550  {
551  TString curpar = pipiConfig(0,pipiConfig.Index(":"));
552  pipiConfig = pipiConfig(pipiConfig.Index(":")+1,1000);
553  curpar.ReplaceAll("[","(");
554  curpar.ReplaceAll("]",")");
555 
556  if (curpar.BeginsWith("cosTheta(")) GetRange(curpar, cosThetaMin, cosThetaMax);
557  }
558  }
559 
560  PndPiPiGenerator* pipiGen = new PndPiPiGenerator();
561  pipiGen->SetBeamMom(GetBeamMom());
562  pipiGen->SetCosThetaMin(cosThetaMin);
563  pipiGen->SetCosThetaMax(cosThetaMax);
564 
565 
566  LOG(INFO) << "Using PndPiPiGenerator(BeamMom = " << GetBeamMom() << " GeV/c, cosThetaRange = "<< cosThetaMin << " : " << cosThetaMax << ")" << FairLogger::endl;
567 
568  // cout <<"BOX generator range: p["<<BoxMomMin<<","<<BoxMomMax<<"] tht["<<BoxThtMin<<","<<BoxThtMax<<"]"<<(BoxCosTht?"*":"")<<" phi["<<BoxPhiMin<<","<<BoxPhiMax<<"]"<<endl;
569 
570  fGen->AddGenerator(pipiGen);
571 }
572 
574 {
575  // use BOX generator; defaults
576 
577  Double_t cosThetaMin = 0.0;
578  Double_t cosThetaMax = 1.0;
579  Double_t pid = -1.0;
580  Double_t GeGmRatio = -1.0;
581  Double_t dummy = 1.0;
582 
583  leplepConfig.ToLower();
584 
585  if (leplepConfig!="")
586  {
587  leplepConfig.ReplaceAll("leplep","");
588  leplepConfig.ReplaceAll(" ","");
589  leplepConfig += ":";
590 
591  while (leplepConfig.Contains(":"))
592  {
593  TString curpar = leplepConfig(0,leplepConfig.Index(":"));
594  leplepConfig = leplepConfig(leplepConfig.Index(":")+1,1000);
595  curpar.ReplaceAll("[","(");
596  curpar.ReplaceAll("]",")");
597 
598  if (curpar.BeginsWith("pid(")) GetRange(curpar, pid, dummy);
599  if (curpar.BeginsWith("gegm(")) GetRange(curpar, GeGmRatio, dummy);
600  if (curpar.BeginsWith("cosTheta(")) GetRange(curpar, cosThetaMin, cosThetaMax);
601  }
602  }
603 
604  PndLepLepGenerator* leplepGen = new PndLepLepGenerator();
605  leplepGen->SetBeamMom(GetBeamMom());
606 
607  leplepGen->SetCosThetaMin(cosThetaMin);
608  leplepGen->SetCosThetaMax(cosThetaMax);
609 
610 
611  LOG(INFO) << "Using PndleplepGenerator(BeamMom = " << GetBeamMom() << " GeV/c, cosThetaRange = "<< cosThetaMin << " : " << cosThetaMax << ")" << FairLogger::endl;
612 
613  // cout <<"BOX generator range: p["<<BoxMomMin<<","<<BoxMomMax<<"] tht["<<BoxThtMin<<","<<BoxThtMax<<"]"<<(BoxCosTht?"*":"")<<" phi["<<BoxPhiMin<<","<<BoxPhiMax<<"]"<<endl;
614 
615  fGen->AddGenerator(leplepGen);
616 }
617 
618 // ----- SetGenerator --------------------------------------------------
620 {
621  LOG(INFO) << "Using PndBoxGenerator generator" << FairLogger::endl;
622  if (fOptions.Contains("PndFiltPrim"))
623  fGen = new PndFilteredPrimaryGenerator();
624  else
625  fGen = new FairFilteredPrimaryGenerator();
626  fGen->AddGenerator(boxGen);
627 }
628 
629 // ----- SetGenerator --------------------------------------------------
631  {
632  LOG(INFO) << "Using FairBoxGenerator generator" << FairLogger::endl;
633  if (fOptions.Contains("PndFiltPrim"))
634  fGen = new PndFilteredPrimaryGenerator();
635  else
636  fGen = new FairFilteredPrimaryGenerator();
637  fGen->AddGenerator(boxGen);
638 }
639 
640 // ----- UseDpmGenerator -----------------------------------------------
642 {
643  LOG(INFO) << "Using PndDpmDirect(" << GetBeamMom() << ", " << fDpmFlag << ") generator" << FairLogger::endl;
644  PndDpmDirect *Dpm= new PndDpmDirect(GetBeamMom(), fDpmFlag);
645  fGen->AddGenerator(Dpm);
646 }
647 
648 // ----- UseFtfGenerator -----------------------------------------------
650 {
651  //if ( strncmp(fName,"TGeant4",7 ) == 0 ) LOG(FATAL) << "FTF does not run with Geant4 !!!" << FairLogger::endl;
652  if (ftfData.Contains(".root")){
653  LOG(INFO) << "Using PndFtfGenerator with input file " << ftfData << FairLogger::endl;
654  PndFtfGenerator* Ftf = new PndFtfGenerator(ftfData);
655  fGen->AddGenerator(Ftf);
656  } else {
657  LOG(INFO) << "Using PndFtfDirect(anti_proton, G4_H, 1, ftfp, " << GetBeamMom() << ", " << gRandom->GetSeed() <<", "<<fFtfFlag<< ") generator" << FairLogger::endl;
658  PndFtfDirect *Ftf = new PndFtfDirect("anti_proton", "G4_H", 1, "ftfp", GetBeamMom(), gRandom->GetSeed(), fFtfFlag);
659  fGen->AddGenerator(Ftf);
660  }
661 }
662 
663 // ----- UseEvtGenGenerator --------------------------------------------
665 {
666 
667  TString IniRes="";
668 
669  if (EvtGenFile.Contains(":")) // is the initial resonance provide as <decfile>.dec:iniRes ?
670  {
671  IniRes = EvtGenFile(EvtGenFile.Index(":")+1,1000);
672  EvtGenFile = EvtGenFile(0,EvtGenFile.Index(":"));
673  }
674 
675  if (IniRes=="") // we need to search the decay file
676  {
677  TString fnamepath=fInputDir+EvtGenFile;
678  std::ifstream fs(fnamepath.Data());
679  char line[250];
680 
681  while (fs)
682  {
683  fs.getline(line,249);
684  TString s(line);
685  s.ReplaceAll("\r","");
686  if (IniRes=="" && s.Contains("Decay "))
687  {
688  if (s.Contains("#")) s=s(0,s.Index("#"));
689  s.ReplaceAll("Decay ","");
690  s.ReplaceAll(" ","");
691  IniRes = s;
692  }
693  }
694  fs.close();
695  }
696  /*
697  // Looping over the dec file trying to find the first string "Decay", in order to find the initai
698  // state as the following string
699  FILE *dec = fopen(fInputDir+EvtGenFile,"r");
700  if (dec==NULL) LOG(FATAL) << "The EvtGen dec file does not exist!! " << EvtGenFile << FairLogger::endl;
701 
702  char temp[6], particle[20];
703  Bool_t found = kFALSE;
704  while(fgets(temp, 6, dec) !=NULL)
705  {
706  if((strstr(temp, "Decay")) != NULL)
707  {
708  fscanf(dec, "%s",particle);
709  LOG(INFO) << "It was found a " << particle << " as initial state." << FairLogger::endl;
710  found = kTRUE;
711  break;
712  }
713  }
714  */
715  if (IniRes=="") LOG(FATAL) << "The input file is not a proper .dec!! " << FairLogger::endl;
716 
717  // TString EvtInput =gSystem->Getenv("VMCWORKDIR");
718  // EvtInput+="/macro/run/psi2s_Jpsi2pi_Jpsi_mumu.dec";
719  LOG(INFO) << "Using PndEvtGenDirect(" <<IniRes << ", " << (fInputDir+EvtGenFile).Data() << ", " << GetBeamMom() << ") generator" << FairLogger::endl;
720  PndEvtGenDirect *EvtGen = new PndEvtGenDirect(IniRes, (fInputDir+EvtGenFile).Data(), GetBeamMom());
721  EvtGen->SetStoreTree(kTRUE);
722  fGen->AddGenerator(EvtGen);
723 
724 }
725 
726 // ----- Finish ---------------------------------------------------------
728 {
729  fRtdb->saveOutput();
730 
731  cout<<"PndMasterRunAna::Finish(): Tasks that ran just now:"<<endl;
732  TFile* outfile=fRootManager->GetOutFile();
733  bool wasopen=outfile->IsOpen ();
734  if (!wasopen)
735  {
736  cout<<"file is "<< ((wasopen) ? "" : "not " ) <<"open" <<endl;
737  outfile=new TFile(outfile->GetName(),"UPDATE");
738  }
739  outfile->cd();
740 
741  // write the summary of event filter to output root file
742  if (!strcmp(fGen->ClassName(),"PndFilteredPrimaryGenerator"))
743  ((PndFilteredPrimaryGenerator*)fGen)->WriteEvtFilterStatsToRootFile(outfile);
744  else
745  ((FairFilteredPrimaryGenerator*)fGen)->WriteEvtFilterStatsToRootFile(outfile);
746 
747  FairFileHeader* outheader=(FairFileHeader*)outfile->Get("FileHeader");
748  cout<<"Task tha ran just now:"<<endl;
749  for(const auto&& os : *(outheader->GetListOfTasks()) ) cout<<" - "<<((TObjString*)os)->GetString().Data()<<endl;
750 
751  TObjString outoptions(fOptions);
752  outoptions.Write("PndOptions",kOverwrite);
753 
754  outfile->Write();
755  if(!wasopen) outfile->Close();
756 
757  cout << endl;
758  if (gROOT->GetVersionInt() >= 60602) {
759  gGeoManager->GetListOfVolumes()->Delete();
760  gGeoManager->GetListOfShapes()->Delete();
761  delete gGeoManager;
762  }
763 
764  // Extract the maximal used memory an add is as Dart measurement
765  // This line is filtered by CTest and the value send to CDash
766  FairSystemInfo sysInfo;
767  Float_t maxMemory=sysInfo.GetMaxMemory();
768  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
769  cout << maxMemory;
770  cout << "</DartMeasurement>" << endl;
771 
772  fTimer.Stop();
773  Double_t rtime = fTimer.RealTime();
774  Double_t ctime = fTimer.CpuTime();
775 
776  Float_t cpuUsage=ctime/rtime;
777  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
778  cout << cpuUsage;
779  cout << "</DartMeasurement>" << endl;
780 
781  cout << endl;
782  cout << "Output file is\t\t" << fOutFile << endl;
783  cout << "Parameter ROOT file is\t" << fParamRootFile << endl;
784  cout << "Parameter ASCII file is\t" << fParamAsciiFile << endl;
785  cout << "Real time " << rtime << " s, CPU time " << ctime
786  << "s" << endl;
787  cout << "CPU usage " << cpuUsage*100. << "%" << endl;
788  cout << "Max Memory " << maxMemory << " MB" << endl;
789 
790  cout << "Macro finished successfully." << endl;
791 
792 }
793 
794 // -----Helper function for parameter parsing ---------------------------------------------------------
795 // par = string parameter like 'varname(min,max)' of 'varname(value)'
796 
797 void PndMasterRunSim::GetRange(TString par, double &min, double &max)
798 {
799  par.ReplaceAll(" ","");
800  par = par(par.Index("(")+1, par.Length()-par.Index("(")-2);
801 
802  TString smin=par, smax=par;
803 
804  if (par.Contains(","))
805  {
806  smin = par(0,par.Index(","));
807  smax = par(par.Index(",")+1,1000);
808  }
809 
810  min = smin.Atof();
811  max = smax.Atof();
812 }
813 
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