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(
"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);
138 Cave->SetGeometryFileName(
"pndcave.geo");
147 Dipole->SetGeometryFileName(
"dipole.geo");
151 Pipe->SetGeometryFileName(
"beampipe_201309.root");
154 FairDetector *
Stt=
new PndStt(
"STT", kTRUE);
155 Stt->SetGeometryFileName(
"straws_skewed_blocks_35cm_pipe.geo");
159 Mvd->SetGeometryFileName(
"Mvd-2.1_FullVersion.root");
163 Gem->SetGeometryFileName(
"gem_3Stations_realistic_v2.root");
171 FairDetector *SciT =
new PndSciT(
"SCIT",kTRUE);
172 SciT->SetGeometryFileName(
"SciTil_201601.root");
176 Drc->SetGeometryFileName(
"dirc_e3_b3_l6_m40.root");
195 FairDetector *
Fts=
new PndFts(
"FTS", kTRUE);
196 Fts->SetGeometryFileName(
"fts.geo");
200 FTof->SetGeometryFileName(
"ftofwall.root");
204 Rich->SetGeometryFileName(
"rich_v313.root");
213 Cave->SetGeometryFileName(
"pndcave.geo");
222 Dipole->SetGeometryFileName(
"dipole.geo");
226 Pipe->SetGeometryFileName(
"beampipe_201309.root");
229 FairDetector *
Stt=
new PndStt(
"STT", kTRUE);
230 Stt->SetGeometryFileName(
"straws_skewed_blocks_35cm_pipe.geo");
234 Mvd->SetGeometryFileName(
"Mvd-2.1_FullVersion.root");
238 Gem->SetGeometryFileName(
"gem_3Stations_realistic_v2.root");
246 FairDetector *SciT =
new PndSciT(
"SCIT",kTRUE);
247 SciT->SetGeometryFileName(
"SciTil_201601.root");
251 Drc->SetGeometryFileName(
"dirc_e3_b3_l6_m40.root");
270 FairDetector *
Fts=
new PndFts(
"FTS", kTRUE);
271 Fts->SetGeometryFileName(
"fts.geo");
275 FTof->SetGeometryFileName(
"ftofwall.root");
288 Cave->SetGeometryFileName(
"pndcave.geo");
297 Dipole->SetGeometryFileName(
"dipole.geo");
301 Pipe->SetGeometryFileName(
"beampipe_201309.root");
304 FairDetector *
Stt=
new PndStt(
"STT", kTRUE);
305 Stt->SetGeometryFileName(
"straws_skewed_blocks_35cm_pipe.geo");
310 Mvd->SetGeometryFileName(
"Mvd-2.1-Strips.root");
314 Mvd->SetGeometryFileName(
"Mvd-2.1_FullVersion.root");
323 FairDetector *SciT =
new PndSciT(
"SCIT",kTRUE);
324 SciT->SetGeometryFileName(
"SciTil_201601.root");
328 Drc->SetGeometryFileName(
"dirc_e3_b3_l6_m40.root");
343 FTof->SetGeometryFileName(
"ftofwall.root");
352 Gem->SetGeometryFileName(
"gem_3Stations_realistic_v2.root");
359 Gem->SetGeometryFileName(
"gem_2Stations_realistic_v2.root");
366 FairDetector *
Fts=
new PndFts(
"FTS", kTRUE);
367 Fts->SetGeometryFileName(
"fts_1256.geo");
373 FairDetector *
Fts=
new PndFts(
"FTS", kTRUE);
374 Fts->SetGeometryFileName(
"fts_reduced.geo");
394 if (
fOptions.Contains(
"pndfiltprim"))
402 LOG(INFO) <<
"Using no Vertex smearing" << FairLogger::endl;
405 LOG(INFO) <<
"Using Cluster Jet Target" << FairLogger::endl;
409 fGen->SetTarget(0., 1./2.355);
410 fGen->SmearVertexZ(kTRUE);
411 fGen->SmearGausVertexZ(kTRUE);
412 fGen->SetBeam(0., 0., 0.1, 0.1);
413 fGen->SmearVertexXY(kTRUE);
416 LOG(INFO) <<
"Using Pellet Target" << FairLogger::endl;
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);
427 LOG(INFO) <<
"Using Pellet Tracking Target" << FairLogger::endl;
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);
438 LOG(INFO) <<
"Unkwown target mode - Using no vertex smearing" << FairLogger::endl;
444 if (input.EndsWith(
".dec") || input.Contains(
".dec:"))
448 else if (input.BeginsWith(
"dpm"))
452 else if (input.BeginsWith(
"ftf"))
456 else if (input.BeginsWith(
"box"))
460 else if (input.BeginsWith(
"pipi"))
466 LOG(WARNING)<<
"Generator could not be identified from input '"<<
fInput.Data()<<
"'!!" << FairLogger::endl;
490 if (BoxConfig!=
"box")
492 BoxConfig.ReplaceAll(
"box",
"");
493 BoxConfig.ReplaceAll(
" ",
"");
496 while (BoxConfig.Contains(
":"))
498 TString curpar = BoxConfig(0,BoxConfig.Index(
":"));
499 BoxConfig = BoxConfig(BoxConfig.Index(
":")+1,1000);
500 curpar.ReplaceAll(
"[",
"(");
501 curpar.ReplaceAll(
"]",
")");
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);
525 boxGen->
SetXYZ(0., 0., 0.);
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;
532 fGen->AddGenerator(boxGen);
542 pipiConfig.ToLower();
544 if (pipiConfig!=
"pipi")
546 pipiConfig.ReplaceAll(
"pipi",
"");
547 pipiConfig.ReplaceAll(
" ",
"");
550 while (pipiConfig.Contains(
":"))
552 TString curpar = pipiConfig(0,pipiConfig.Index(
":"));
553 pipiConfig = pipiConfig(pipiConfig.Index(
":")+1,1000);
554 curpar.ReplaceAll(
"[",
"(");
555 curpar.ReplaceAll(
"]",
")");
557 if (curpar.BeginsWith(
"cosTheta("))
GetRange(curpar, cosThetaMin, cosThetaMax);
567 LOG(INFO) <<
"Using PndPiPiGenerator(BeamMom = " << GetBeamMom() <<
" GeV/c, cosThetaRange = "<< cosThetaMin <<
" : " << cosThetaMax <<
")" << FairLogger::endl;
571 fGen->AddGenerator(pipiGen);
584 leplepConfig.ToLower();
586 if (leplepConfig!=
"")
588 leplepConfig.ReplaceAll(
"leplep",
"");
589 leplepConfig.ReplaceAll(
" ",
"");
592 while (leplepConfig.Contains(
":"))
594 TString curpar = leplepConfig(0,leplepConfig.Index(
":"));
595 leplepConfig = leplepConfig(leplepConfig.Index(
":")+1,1000);
596 curpar.ReplaceAll(
"[",
"(");
597 curpar.ReplaceAll(
"]",
")");
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);
612 LOG(INFO) <<
"Using PndleplepGenerator(BeamMom = " << GetBeamMom() <<
" GeV/c, cosThetaRange = "<< cosThetaMin <<
" : " << cosThetaMax <<
")" << FairLogger::endl;
616 fGen->AddGenerator(leplepGen);
622 LOG(INFO) <<
"Using PndBoxGenerator generator" << FairLogger::endl;
623 if (
fOptions.Contains(
"PndFiltPrim"))
627 fGen->AddGenerator(boxGen);
633 LOG(INFO) <<
"Using FairBoxGenerator generator" << FairLogger::endl;
634 if (
fOptions.Contains(
"PndFiltPrim"))
638 fGen->AddGenerator(boxGen);
644 LOG(INFO) <<
"Using PndDpmDirect(" << GetBeamMom() <<
", " <<
fDpmFlag <<
") generator" << FairLogger::endl;
646 fGen->AddGenerator(Dpm);
653 if (ftfData.Contains(
".root")){
654 LOG(INFO) <<
"Using PndFtfGenerator with input file " << ftfData << FairLogger::endl;
656 fGen->AddGenerator(Ftf);
658 LOG(INFO) <<
"Using PndFtfDirect(anti_proton, G4_H, 1, ftfp, " << GetBeamMom() <<
", " << gRandom->GetSeed() <<
", "<<
fFtfFlag<<
") generator" << FairLogger::endl;
660 fGen->AddGenerator(Ftf);
670 if (EvtGenFile.Contains(
":"))
672 IniRes = EvtGenFile(EvtGenFile.Index(
":")+1,1000);
673 EvtGenFile = EvtGenFile(0,EvtGenFile.Index(
":"));
679 std::ifstream fs(fnamepath.Data());
684 fs.getline(line,249);
686 s.ReplaceAll(
"\r",
"");
687 if (IniRes==
"" && s.Contains(
"Decay "))
689 if (s.Contains(
"#")) s=
s(0,s.Index(
"#"));
690 s.ReplaceAll(
"Decay ",
"");
691 s.ReplaceAll(
" ",
"");
716 if (IniRes==
"") LOG(FATAL) <<
"The input file is not a proper .dec!! " << FairLogger::endl;
720 LOG(INFO) <<
"Using PndEvtGenDirect(" <<IniRes <<
", " << (
fInputDir+EvtGenFile).Data() <<
", " << GetBeamMom() <<
") generator" << FairLogger::endl;
723 fGen->AddGenerator(EvtGen);
732 cout<<
"PndMasterRunAna::Finish(): Tasks that ran just now:"<<endl;
733 TFile*
outfile=fRootManager->GetOutFile();
734 bool wasopen=outfile->IsOpen ();
737 cout<<
"file is "<< ((wasopen) ?
"" :
"not " ) <<
"open" <<endl;
738 outfile=
new TFile(outfile->GetName(),
"UPDATE");
743 if (!strcmp(fGen->ClassName(),
"PndFilteredPrimaryGenerator"))
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;
753 outoptions.Write(
"PndOptions",kOverwrite);
756 if(!wasopen) outfile->Close();
759 if (gROOT->GetVersionInt() >= 60602) {
767 FairSystemInfo sysInfo;
768 Float_t maxMemory=sysInfo.GetMaxMemory();
769 cout <<
"<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
771 cout <<
"</DartMeasurement>" << endl;
777 Float_t cpuUsage=ctime/
rtime;
778 cout <<
"<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
780 cout <<
"</DartMeasurement>" << endl;
783 cout <<
"Output file is\t\t" <<
fOutFile << endl;
786 cout <<
"Real time " << rtime <<
" s, CPU time " << ctime
788 cout <<
"CPU usage " << cpuUsage*100. <<
"%" << endl;
789 cout <<
"Max Memory " << maxMemory <<
" MB" << endl;
791 cout <<
"Macro finished successfully." << endl;
800 par.ReplaceAll(
" ",
"");
801 par =
par(par.Index(
"(")+1, par.Length()-par.Index(
"(")-2);
805 if (par.Contains(
","))
807 smin =
par(0,par.Index(
","));
808 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.