FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
runMM.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 runMM(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 outDir = "./";
22 
23  // Output file name
24  TString outFile = Form("%s/prop.mc.root", outDir.Data());
25 
26  // Parameter file name
27  TString parFile = Form("%s/prop.par.root", outDir.Data());
28 
29  TString geoFile = "geofile_" + mcEngine + "_full.root";
30 
31  // In general, the following parts need not be touched
32  // ========================================================================
33 
34  // ---- Debug option -------------------------------------------------
35  gDebug = 0;
36  // ------------------------------------------------------------------------
37 
38  // ----- Timer --------------------------------------------------------
39  TStopwatch timer;
40  timer.Start();
41  // ------------------------------------------------------------------------
42 
43  // ----- Create simulation run ----------------------------------------
44  FairRunSim* run = new FairRunSim();
45  run->SetName(mcEngine); // Transport engine
46  // run->SetSimulationConfig(new FairVMCConfig());
47  run->SetIsMT(isMT); // Multi-threading mode (Geant4 only)
48  run->SetSink(new FairRootFileSink(outFile)); // Output file
49  FairRuntimeDb* rtdb = run->GetRuntimeDb();
50  // ------------------------------------------------------------------------
51 
52  // ----- Create media -------------------------------------------------
53  run->SetMaterials("media.geo"); // Materials
54  // ------------------------------------------------------------------------
55 
56  // ----- Create geometry ----------------------------------------------
57 
58  FairModule* cave = new FairCave("CAVE");
59  cave->SetGeometryFileName("cave_vacuum.geo");
60  run->AddModule(cave);
61 
62  FairTutPropDet* det = new FairTutPropDet("TutPropDetector", kTRUE);
63  det->SetGeometryFileName("tutProp.geo");
64  run->AddModule(det);
65 
66  FairTutPropDet* det2 = new FairTutPropDet("TutPropDetector", kTRUE);
67  det2->SetGeometryFileName("tutProp2.geo");
68  det2->SetPointsArrayName("FairTutPropPoint2");
69  run->AddModule(det2);
70  // ------------------------------------------------------------------------
71 
72  // ----- Create PrimaryGenerator --------------------------------------
74  FairBoxGenerator* pionBoxGen = new FairBoxGenerator(211, 2);
75 
76  pionBoxGen->SetThetaRange(0, 30);
77  pionBoxGen->SetPRange(1.,3.);
78 
79  pionBoxGen->SetPhiRange(0., 360.); // 10.,10. when looking for PCA
80  pionBoxGen->SetDebug(kTRUE);
81 
82  primGen->AddGenerator(pionBoxGen);
83 
84  FairBoxGenerator* muonBoxGen = new FairBoxGenerator(13, 2);
85 
86  muonBoxGen->SetThetaRange(0, 30);
87  muonBoxGen->SetPRange(1.,3.);
88  muonBoxGen->SetPhiRange(0., 360.); // 10.,10. when looking for PCA
89  muonBoxGen->SetDebug(kTRUE);
90 
91  primGen->AddGenerator(muonBoxGen);
92 
93  FairConstField* fMagField = new FairConstField();
94  fMagField->SetField(0., 0., 20.); // values are in kG
95  fMagField->SetFieldRegion(-150, 150, -150, 150, -250, 250); // values are in cm (xmin,xmax,ymin,ymax,zmin,zmax)
96  run->SetField(fMagField);
97 
98  run->SetGenerator(primGen);
99  // ------------------------------------------------------------------------
100 
101  // ----- Initialize simulation run ------------------------------------
102  run->Init();
103  // ------------------------------------------------------------------------
104 
105  // ----- Runtime database ---------------------------------------------
106 
107  Bool_t kParameterMerged = kTRUE;
108  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
109  parOut->open(parFile.Data());
110  rtdb->setOutput(parOut);
111  rtdb->saveOutput();
112  rtdb->print();
113  // ------------------------------------------------------------------------
114 
115  // ----- Start run ----------------------------------------------------
116  run->Run(nEvents);
117  run->CreateGeometryFile(geoFile);
118  // ------------------------------------------------------------------------
119 
120  // ----- Finish -------------------------------------------------------
121 
122  cout << endl << endl;
123 
124  // Extract the maximal used memory an add is as Dart measurement
125  // This line is filtered by CTest and the value send to CDash
126  FairSystemInfo sysInfo;
127  Float_t maxMemory = sysInfo.GetMaxMemory();
128  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
129  cout << maxMemory;
130  cout << "</DartMeasurement>" << endl;
131 
132  timer.Stop();
133  Double_t rtime = timer.RealTime();
134  Double_t ctime = timer.CpuTime();
135 
136  Float_t cpuUsage = ctime / rtime;
137  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
138  cout << cpuUsage;
139  cout << "</DartMeasurement>" << endl;
140 
141  cout << endl << endl;
142  cout << "Output file is " << outFile << endl;
143  cout << "Parameter file is " << parFile << endl;
144  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
145  cout << "Macro finished successfully." << endl;
146 
147  // ------------------------------------------------------------------------
148  return 0;
149 }
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
int runMM(Int_t nEvents=1000, TString mcEngine="TGeant4", Bool_t isMT=false)
Definition: runMM.C:8
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 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
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)
void saveOutput(void)