FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
runMC.C
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 int runMC(Int_t nEvents = 1000, TString mcEngine = "TGeant4", Bool_t isMT = false)
9 {
10  UInt_t randomSeed = 123456;
11  gRandom->SetSeed(randomSeed);
12 
13  TString dir = getenv("VMCWORKDIR");
14 
15  TString tut_geomdir = dir + "/common/geometry";
16  gSystem->Setenv("GEOMPATH", tut_geomdir.Data());
17 
18  TString tut_configdir = dir + "/common/gconfig";
19  gSystem->Setenv("CONFIG_DIR", tut_configdir.Data());
20 
21  // TString partName[] = {"pions","eplus","proton"};
22  Int_t partPdgC[] = {211, 11, 2212};
23 
24  Double_t momentum = 2.;
25 
26  Double_t theta = 10.;
27 
28  TString outDir = "./";
29 
30  // Output file name
31  TString outFile = Form("%s/prop.mc.root", outDir.Data());
32 
33  // Parameter file name
34  TString parFile = Form("%s/prop.par.root", outDir.Data());
35 
36  TString geoFile = "geofile_" + mcEngine + "_full.root";
37 
38  // In general, the following parts need not be touched
39  // ========================================================================
40 
41  // ---- Debug option -------------------------------------------------
42  gDebug = 0;
43  // ------------------------------------------------------------------------
44 
45  // ----- Timer --------------------------------------------------------
46  TStopwatch timer;
47  timer.Start();
48  // ------------------------------------------------------------------------
49 
50  // ----- Create simulation run ----------------------------------------
51  FairRunSim* run = new FairRunSim();
52  run->SetName(mcEngine); // Transport engine
53  // run->SetSimulationConfig(new FairVMCConfig());
54  run->SetIsMT(isMT); // Multi-threading mode (Geant4 only)
55  run->SetSink(new FairRootFileSink(outFile)); // Output file
56  FairRuntimeDb* rtdb = run->GetRuntimeDb();
57  // ------------------------------------------------------------------------
58 
59  // ----- Create media -------------------------------------------------
60  run->SetMaterials("media.geo"); // Materials
61  // ------------------------------------------------------------------------
62 
63  // ----- Create geometry ----------------------------------------------
64 
65  FairModule* cave = new FairCave("CAVE");
66  cave->SetGeometryFileName("cave_vacuum.geo");
67  run->AddModule(cave);
68 
69  FairTutPropDet* det = new FairTutPropDet("TutPropDetector", kTRUE);
70  det->SetGeometryFileName("tutProp.geo");
71  run->AddModule(det);
72 
73  FairTutPropDet* det2 = new FairTutPropDet("TutPropDetector", kTRUE);
74  det2->SetGeometryFileName("tutProp2.geo");
75  det2->SetPointsArrayName("FairTutPropPoint2");
76  run->AddModule(det2);
77  // ------------------------------------------------------------------------
78 
79  // ----- Create PrimaryGenerator --------------------------------------
81  for (int iPart = 0; iPart < 3; iPart++) {
82 
83  FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[iPart], 3);
84 
85  boxGen->SetThetaRange(theta, theta + 0.01);
86  boxGen->SetPRange(momentum, momentum + 0.01);
87  boxGen->SetPhiRange(0., 360.); // 10.,10. when looking for PCA
88  boxGen->SetDebug(kTRUE);
89 
90  primGen->AddGenerator(boxGen);
91  }
92  FairConstField* fMagField = new FairConstField();
93  fMagField->SetField(0., 0., 20.); // values are in kG
94  fMagField->SetFieldRegion(-150, 150, -150, 150, -250, 250); // values are in cm (xmin,xmax,ymin,ymax,zmin,zmax)
95  run->SetField(fMagField);
96 
97  run->SetGenerator(primGen);
98  // ------------------------------------------------------------------------
99  run->SetStoreTraj(kTRUE);
100  // ----- Initialize simulation run ------------------------------------
101  run->Init();
102  // ------------------------------------------------------------------------
104  trajFilter->SetStepSizeCut(0.01); // 1 cm
105  // trajFilter->SetVertexCut(-2000., -2000., 4., 2000., 2000., 100.);
106  trajFilter->SetMomentumCutP(.50); // p_lab > 500 MeV
107  // trajFilter->SetEnergyCut(.2, 3.02); // 0 < Etot < 1.04 GeV
108 
109  trajFilter->SetStorePrimaries(kTRUE);
110 
111  // ----- Runtime database ---------------------------------------------
112 
113  Bool_t kParameterMerged = kTRUE;
114  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
115  parOut->open(parFile.Data());
116  rtdb->setOutput(parOut);
117  rtdb->saveOutput();
118  rtdb->print();
119  // ------------------------------------------------------------------------
120 
121  // ----- Start run ----------------------------------------------------
122  run->Run(nEvents);
123  run->CreateGeometryFile(geoFile);
124  // ------------------------------------------------------------------------
125 
126  // ----- Finish -------------------------------------------------------
127 
128  cout << endl << endl;
129 
130  // Extract the maximal used memory an add is as Dart measurement
131  // This line is filtered by CTest and the value send to CDash
132  FairSystemInfo sysInfo;
133  Float_t maxMemory = sysInfo.GetMaxMemory();
134  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
135  cout << maxMemory;
136  cout << "</DartMeasurement>" << endl;
137 
138  timer.Stop();
139  Double_t rtime = timer.RealTime();
140  Double_t ctime = timer.CpuTime();
141 
142  Float_t cpuUsage = ctime / rtime;
143  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
144  cout << cpuUsage;
145  cout << "</DartMeasurement>" << endl;
146 
147  cout << endl << endl;
148  cout << "Output file is " << outFile << endl;
149  cout << "Parameter file is " << parFile << endl;
150  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
151  cout << "Macro finished successfully." << endl;
152 
153  // ------------------------------------------------------------------------
154  return 0;
155 }
void SetDebug(Bool_t)
Bool_t kParameterMerged
virtual void SetGeometryFileName(TString fname, TString geoVer="0")
Definition: FairModule.cxx:199
void CreateGeometryFile(const char *geofile)
Definition: FairRun.cxx:103
list of container factories
Definition: FairRuntimeDb.h:24
void SetStepSizeCut(Double_t stepSizeMin=0.)
void SetField(FairField *field)
Definition: FairRunSim.cxx:308
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
void AddGenerator(FairGenerator *generator)
void SetField(Double_t bX, Double_t bY, Double_t bZ)
void SetMomentumCutP(Double_t pMin=0., Double_t thetaMin=0., Double_t phiMin=0., Double_t pMax=1e10, Double_t thetaMax=TMath::Pi(), Double_t phiMax=TMath::TwoPi())
void SetPointsArrayName(const std::string &tempName)
void SetGenerator(FairPrimaryGenerator *Gen)
Definition: FairRunSim.cxx:310
void print(void)
void SetSink(FairSink *tempSink)
Definition: FairRun.h:84
Float_t GetMaxMemory()
void SetIsMT(Bool_t isMT)
Definition: FairRunSim.h:184
void SetFieldRegion(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax)
FairParRootFileIo * parOut
static FairTrajFilter * Instance()
void SetStorePrimaries(Bool_t storePrim=kTRUE)
virtual void Init()
Definition: FairRunSim.cxx:143
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
void SetThetaRange(Double32_t thetamin=0, Double32_t thetamax=90)
void SetMaterials(const char *MatFileName)
Definition: FairRunSim.cxx:312
Bool_t setOutput(FairParIo *)
Bool_t open(const Text_t *fname, Option_t *option="READ", const Text_t *ftitle="", Int_t compress=1)
virtual void Run(Int_t NEvents=0, Int_t NotUsed=0)
Definition: FairRunSim.cxx:306
void AddModule(FairModule *Mod)
Definition: FairRunSim.cxx:118
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
int runMC(Int_t nEvents=1000, TString mcEngine="TGeant4", Bool_t isMT=false)
Definition: runMC.C:8
void saveOutput(void)
void SetStoreTraj(Bool_t storeTraj=kTRUE)
Definition: FairRunSim.h:92