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"
44 #include "TLorentzVector.h"
45 #include "TDatabasePDG.h"
46 #include "TGeoManager.h"
55 FairRunSim(), fInput(), fInputDir(
""),
fOutFile(), fParamRootFile(), fParamAsciiFile(), fOptions(), fDpmFlag(1), fFtfFlag(0), fNEvents(0), fEventCounterRate(100), fTargetMode(0), fRtdb(), fTimer()
62 if (gROOT->GetVersionInt() >= 60602 &&
gGeoManager!=NULL) {
81 if (inputName.EndsWith(
".dec")) inputName.Remove(inputName.Length()-4,4);
82 inputName.ReplaceAll(
":",
"_");
89 SetGenerateRunInfo(kFALSE);
94 allDigiFile +=
"/macro/params/";
97 fRtdb = this->GetRuntimeDb();
99 FairParRootFileIo*
parOutput =
new FairParRootFileIo(kParameterMerged);
102 FairParAsciiFileIo*
parIo1 =
new FairParAsciiFileIo();
103 parIo1->open(allDigiFile.Data(),
"in");
105 fRtdb->setFirstInput(parIo1);
106 fRtdb->setOutput(parOutput);
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);
137 Cave->SetGeometryFileName(
"pndcave.geo");
146 Dipole->SetGeometryFileName(
"dipole.geo");
150 Pipe->SetGeometryFileName(
"beampipe_201309.root");
153 FairDetector *
Stt=
new PndStt(
"STT", kTRUE);
154 Stt->SetGeometryFileName(
"straws_skewed_blocks_35cm_pipe.geo");
158 Mvd->SetGeometryFileName(
"Mvd-2.1_FullVersion.root");
162 Gem->SetGeometryFileName(
"gem_3Stations_realistic_v2.root");
170 FairDetector *SciT =
new PndSciT(
"SCIT",kTRUE);
171 SciT->SetGeometryFileName(
"SciTil_201601.root");
175 Drc->SetGeometryFileName(
"dirc_e3_b3_l6_m40.root");
194 FairDetector *
Fts=
new PndFts(
"FTS", kTRUE);
195 Fts->SetGeometryFileName(
"fts.geo");
199 FTof->SetGeometryFileName(
"ftofwall.root");
203 Rich->SetGeometryFileName(
"rich_v313.root");
212 Cave->SetGeometryFileName(
"pndcave.geo");
221 Dipole->SetGeometryFileName(
"dipole.geo");
225 Pipe->SetGeometryFileName(
"beampipe_201309.root");
228 FairDetector *
Stt=
new PndStt(
"STT", kTRUE);
229 Stt->SetGeometryFileName(
"straws_skewed_blocks_35cm_pipe.geo");
233 Mvd->SetGeometryFileName(
"Mvd-2.1_FullVersion.root");
237 Gem->SetGeometryFileName(
"gem_3Stations_realistic_v2.root");
245 FairDetector *SciT =
new PndSciT(
"SCIT",kTRUE);
246 SciT->SetGeometryFileName(
"SciTil_201601.root");
250 Drc->SetGeometryFileName(
"dirc_e3_b3_l6_m40.root");
269 FairDetector *
Fts=
new PndFts(
"FTS", kTRUE);
270 Fts->SetGeometryFileName(
"fts.geo");
274 FTof->SetGeometryFileName(
"ftofwall.root");
287 Cave->SetGeometryFileName(
"pndcave.geo");
296 Dipole->SetGeometryFileName(
"dipole.geo");
300 Pipe->SetGeometryFileName(
"beampipe_201309.root");
303 FairDetector *
Stt=
new PndStt(
"STT", kTRUE);
304 Stt->SetGeometryFileName(
"straws_skewed_blocks_35cm_pipe.geo");
309 Mvd->SetGeometryFileName(
"Mvd-2.1-Strips.root");
313 Mvd->SetGeometryFileName(
"Mvd-2.1_FullVersion.root");
322 FairDetector *SciT =
new PndSciT(
"SCIT",kTRUE);
323 SciT->SetGeometryFileName(
"SciTil_201601.root");
327 Drc->SetGeometryFileName(
"dirc_e3_b3_l6_m40.root");
342 FTof->SetGeometryFileName(
"ftofwall.root");
351 Gem->SetGeometryFileName(
"gem_3Stations_realistic_v2.root");
358 Gem->SetGeometryFileName(
"gem_2Stations_realistic_v2.root");
365 FairDetector *
Fts=
new PndFts(
"FTS", kTRUE);
366 Fts->SetGeometryFileName(
"fts_1256.geo");
372 FairDetector *
Fts=
new PndFts(
"FTS", kTRUE);
373 Fts->SetGeometryFileName(
"fts_reduced.geo");
393 if (
fOptions.Contains(
"pndfiltprim"))
401 LOG(INFO) <<
"Using no Vertex smearing" << FairLogger::endl;
404 LOG(INFO) <<
"Using Cluster Jet Target" << FairLogger::endl;
408 fGen->SetTarget(0., 1./2.355);
409 fGen->SmearVertexZ(kTRUE);
410 fGen->SmearGausVertexZ(kTRUE);
411 fGen->SetBeam(0., 0., 0.1, 0.1);
412 fGen->SmearVertexXY(kTRUE);
415 LOG(INFO) <<
"Using Pellet Target" << FairLogger::endl;
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);
426 LOG(INFO) <<
"Using Pellet Tracking Target" << FairLogger::endl;
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);
437 LOG(INFO) <<
"Unkwown target mode - Using no vertex smearing" << FairLogger::endl;
443 if (input.EndsWith(
".dec") || input.Contains(
".dec:"))
447 else if (input.BeginsWith(
"dpm"))
451 else if (input.BeginsWith(
"ftf"))
455 else if (input.BeginsWith(
"box"))
459 else if (input.BeginsWith(
"pipi"))
465 LOG(FATAL)<<
"Generator could not be identified from input '"<<
fInput.Data()<<
"'!!" << FairLogger::endl;
489 if (BoxConfig!=
"box")
491 BoxConfig.ReplaceAll(
"box",
"");
492 BoxConfig.ReplaceAll(
" ",
"");
495 while (BoxConfig.Contains(
":"))
497 TString curpar = BoxConfig(0,BoxConfig.Index(
":"));
498 BoxConfig = BoxConfig(BoxConfig.Index(
":")+1,1000);
499 curpar.ReplaceAll(
"[",
"(");
500 curpar.ReplaceAll(
"]",
")");
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);
524 boxGen->
SetXYZ(0., 0., 0.);
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;
531 fGen->AddGenerator(boxGen);
541 pipiConfig.ToLower();
543 if (pipiConfig!=
"pipi")
545 pipiConfig.ReplaceAll(
"pipi",
"");
546 pipiConfig.ReplaceAll(
" ",
"");
549 while (pipiConfig.Contains(
":"))
551 TString curpar = pipiConfig(0,pipiConfig.Index(
":"));
552 pipiConfig = pipiConfig(pipiConfig.Index(
":")+1,1000);
553 curpar.ReplaceAll(
"[",
"(");
554 curpar.ReplaceAll(
"]",
")");
556 if (curpar.BeginsWith(
"cosTheta("))
GetRange(curpar, cosThetaMin, cosThetaMax);
566 LOG(INFO) <<
"Using PndPiPiGenerator(BeamMom = " << GetBeamMom() <<
" GeV/c, cosThetaRange = "<< cosThetaMin <<
" : " << cosThetaMax <<
")" << FairLogger::endl;
570 fGen->AddGenerator(pipiGen);
583 leplepConfig.ToLower();
585 if (leplepConfig!=
"")
587 leplepConfig.ReplaceAll(
"leplep",
"");
588 leplepConfig.ReplaceAll(
" ",
"");
591 while (leplepConfig.Contains(
":"))
593 TString curpar = leplepConfig(0,leplepConfig.Index(
":"));
594 leplepConfig = leplepConfig(leplepConfig.Index(
":")+1,1000);
595 curpar.ReplaceAll(
"[",
"(");
596 curpar.ReplaceAll(
"]",
")");
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);
611 LOG(INFO) <<
"Using PndleplepGenerator(BeamMom = " << GetBeamMom() <<
" GeV/c, cosThetaRange = "<< cosThetaMin <<
" : " << cosThetaMax <<
")" << FairLogger::endl;
615 fGen->AddGenerator(leplepGen);
621 LOG(INFO) <<
"Using PndBoxGenerator generator" << FairLogger::endl;
622 if (
fOptions.Contains(
"PndFiltPrim"))
626 fGen->AddGenerator(boxGen);
632 LOG(INFO) <<
"Using FairBoxGenerator generator" << FairLogger::endl;
633 if (
fOptions.Contains(
"PndFiltPrim"))
637 fGen->AddGenerator(boxGen);
643 LOG(INFO) <<
"Using PndDpmDirect(" << GetBeamMom() <<
", " <<
fDpmFlag <<
") generator" << FairLogger::endl;
645 fGen->AddGenerator(Dpm);
652 if (ftfData.Contains(
".root")){
653 LOG(INFO) <<
"Using PndFtfGenerator with input file " << ftfData << FairLogger::endl;
655 fGen->AddGenerator(Ftf);
657 LOG(INFO) <<
"Using PndFtfDirect(anti_proton, G4_H, 1, ftfp, " << GetBeamMom() <<
", " << gRandom->GetSeed() <<
", "<<
fFtfFlag<<
") generator" << FairLogger::endl;
659 fGen->AddGenerator(Ftf);
669 if (EvtGenFile.Contains(
":"))
671 IniRes = EvtGenFile(EvtGenFile.Index(
":")+1,1000);
672 EvtGenFile = EvtGenFile(0,EvtGenFile.Index(
":"));
678 std::ifstream fs(fnamepath.Data());
683 fs.getline(line,249);
685 s.ReplaceAll(
"\r",
"");
686 if (IniRes==
"" && s.Contains(
"Decay "))
688 if (s.Contains(
"#")) s=
s(0,s.Index(
"#"));
689 s.ReplaceAll(
"Decay ",
"");
690 s.ReplaceAll(
" ",
"");
715 if (IniRes==
"") LOG(FATAL) <<
"The input file is not a proper .dec!! " << FairLogger::endl;
719 LOG(INFO) <<
"Using PndEvtGenDirect(" <<IniRes <<
", " << (
fInputDir+EvtGenFile).Data() <<
", " << GetBeamMom() <<
") generator" << FairLogger::endl;
722 fGen->AddGenerator(EvtGen);
731 cout<<
"PndMasterRunAna::Finish(): Tasks that ran just now:"<<endl;
732 TFile*
outfile=fRootManager->GetOutFile();
733 bool wasopen=outfile->IsOpen ();
736 cout<<
"file is "<< ((wasopen) ?
"" :
"not " ) <<
"open" <<endl;
737 outfile=
new TFile(outfile->GetName(),
"UPDATE");
742 if (!strcmp(fGen->ClassName(),
"PndFilteredPrimaryGenerator"))
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;
752 outoptions.Write(
"PndOptions",kOverwrite);
755 if(!wasopen) outfile->Close();
758 if (gROOT->GetVersionInt() >= 60602) {
766 FairSystemInfo sysInfo;
767 Float_t maxMemory=sysInfo.GetMaxMemory();
768 cout <<
"<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
770 cout <<
"</DartMeasurement>" << endl;
776 Float_t cpuUsage=ctime/
rtime;
777 cout <<
"<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
779 cout <<
"</DartMeasurement>" << endl;
782 cout <<
"Output file is\t\t" <<
fOutFile << endl;
785 cout <<
"Real time " << rtime <<
" s, CPU time " << ctime
787 cout <<
"CPU usage " << cpuUsage*100. <<
"%" << endl;
788 cout <<
"Max Memory " << maxMemory <<
" MB" << endl;
790 cout <<
"Macro finished successfully." << endl;
799 par.ReplaceAll(
" ",
"");
800 par =
par(par.Index(
"(")+1, par.Length()-par.Index(
"(")-2);
804 if (par.Contains(
","))
806 smin =
par(0,par.Index(
","));
807 smax =
par(par.Index(
",")+1,1000);
TString fInput
Name of the input for the simulation.
void SetForward(TString name)
void SetThetaRange(Double32_t thetamin=0, Double32_t thetamax=90)
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)
Int_t fNEvents
Number of events.
void SetBeamMom(Double_t in_P)
friend F32vec4 sqrt(const F32vec4 &a)
void SetCosThetaMax(Double_t in_cos_theta_max)
void SetXYZ(Double32_t x=0, Double32_t y=0, Double32_t z=0)
void SetMdtCoil(bool opt=false)
Bool_t Setup(TString outprefix="")
Initial setup.
void SetMdtMFIron(bool opt=false)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
void SetStorageOfData(Bool_t val)
TGeoManager * gGeoManager
void UseEvtGenGenerator(TString EvtGenFile)
Use EvtGen as event generator.
Short_t fTargetMode
Target mode.
void UseDpmGenerator()
Use DPM as event generator.
TString fOptions
Options parsed to the simulation.
Int_t fEventCounterRate
After how many events the counter will print.
virtual ~PndMasterRunSim()
Default destructor.
void AddSimTasks()
Add simulation tasks.
void SetMdtMagnet(bool opt=false)
Primary generator with added event filtering capabilities.
void SetStoreTrackPoints(Bool_t storeTrackPoints)
void SetStoreTree(Bool_t store=true)
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)
void UsePiPiGenerator(TString pipiConfig)
Use PiPiGenerator as event generator.
virtual void SetGeometryVersion(const Int_t GeoNumber)
void SetBarrel(TString name)
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)
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.
void SetDebug(Bool_t debug=0)
Class for the master simulation chain.
void UseFtfGenerator(TString ftfData)
Use FTF as event generator.
void SetCosThetaMin(Double_t in_cos_theta_min)
FairParAsciiFileIo * parIo1
FairBoxGenerator * boxGen
TString fParamRootFile
Name of the parameter root file.
fRun SetMaterials("media_pnd.geo")
fRun SetOutputFile(outFile)
void SetEndcap(TString name)
void SetMuonFilter(TString name)
PndMvdCreateDefaultApvMap * creator
void GetRange(TString par, double &min, double &max)
PndMasterRunSim()
Default constructor.
void SetRunCherenkov(Bool_t ch)
void UseBoxGenerator(TString BoxConfig)
Use BoxGen as event generator.
FairRuntimeDb * fRtdb
Runtime DB.
void SetCosThetaMin(Double_t in_cos_theta_min)
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
TString fOutFile
Name of the output file.
fRun SetUseFairLinks(kTRUE)
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.
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
void UseLepLepGenerator(TString leplepConfig)
Use LepLepGenerator as event generator.
Int_t fDpmFlag
Flag for DPM event generator.