FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_tutorial1.C
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 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 void run_tutorial1(Int_t nEvents = 10,
9  TString mcEngine = "TGeant3",
10  Bool_t isMT = true,
11  Bool_t loadPostInitConfig = false)
12 {
13 
14  TString dir = getenv("VMCWORKDIR");
15  TString tutdir = dir + "/simulation/Tutorial1";
16 
17  TString tut_geomdir = dir + "/common/geometry";
18  gSystem->Setenv("GEOMPATH", tut_geomdir.Data());
19 
20  TString tut_configdir = dir + "/common/gconfig";
21  gSystem->Setenv("CONFIG_DIR", tut_configdir.Data());
22 
23  TString partName[] = {"pions", "eplus", "proton"};
24  Int_t partPdgC[] = {211, 11, 2212};
25  Int_t chosenPart = 0;
26 
27  Double_t momentum = 2.;
28 
29  Double_t theta = 0.;
30 
31  TString outDir = "./";
32 
33  // Output file name
34  TString outFile = Form("%s/tutorial1_%s_%s.mc_p%1.3f_t%1.0f_n%d.root",
35  outDir.Data(),
36  mcEngine.Data(),
37  partName[chosenPart].Data(),
38  momentum,
39  theta,
40  nEvents);
41 
42  // Parameter file name
43  TString parFile = Form("%s/tutorial1_%s_%s.params_p%1.3f_t%1.0f_n%d.root",
44  outDir.Data(),
45  mcEngine.Data(),
46  partName[chosenPart].Data(),
47  momentum,
48  theta,
49  nEvents);
50 
51  TString geoFile = "geofile_" + mcEngine + "_full.root";
52 
53  // In general, the following parts need not be touched
54  // ========================================================================
55 
56  // ---- Debug option -------------------------------------------------
57  gDebug = 0;
58  // ------------------------------------------------------------------------
59 
60  // ----- Timer --------------------------------------------------------
61  TStopwatch timer;
62  timer.Start();
63  // ------------------------------------------------------------------------
64 
65  // ----- Create simulation run ----------------------------------------
66  FairRunSim* run = new FairRunSim();
67  run->SetName(mcEngine); // Transport engine
69  if (loadPostInitConfig)
70  config->UsePostInitConfig();
71  run->SetSimulationConfig(config);
72  run->SetIsMT(isMT); // Multi-threading mode (Geant4 only)
73  run->SetSink(new FairRootFileSink(outFile)); // Output file
74  FairRuntimeDb* rtdb = run->GetRuntimeDb();
75  // ------------------------------------------------------------------------
76 
77  // ----- Create media -------------------------------------------------
78  run->SetMaterials("media.geo"); // Materials
79  // ------------------------------------------------------------------------
80 
81  // ----- Create geometry ----------------------------------------------
82 
83  FairModule* cave = new FairCave("CAVE");
84  cave->SetGeometryFileName("cave_vacuum.geo");
85  run->AddModule(cave);
86 
87  FairDetector* tutdet = new FairTutorialDet1("TUTDET", kTRUE);
88  tutdet->SetGeometryFileName("double_sector.geo");
89  run->AddModule(tutdet);
90  // ------------------------------------------------------------------------
91 
92  // ----- Create PrimaryGenerator --------------------------------------
94  FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[chosenPart], 1);
95 
96  boxGen->SetThetaRange(theta, theta + 0.01);
97  boxGen->SetPRange(momentum, momentum + 0.01);
98  boxGen->SetPhiRange(0., 360.);
99  boxGen->SetDebug(kTRUE);
100 
101  primGen->AddGenerator(boxGen);
102 
103  run->SetGenerator(primGen);
104  // ------------------------------------------------------------------------
105 
106  // ----- Initialize simulation run ------------------------------------
107  UInt_t randomSeed = 123456;
108  TRandom3 random(randomSeed);
109  gRandom = &random;
110 
111  run->Init();
112  // ------------------------------------------------------------------------
113 
114  // ----- Runtime database ---------------------------------------------
115 
116  Bool_t kParameterMerged = kTRUE;
117  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
118  parOut->open(parFile.Data());
119  rtdb->setOutput(parOut);
120  rtdb->saveOutput();
121  rtdb->print();
122  // ------------------------------------------------------------------------
123 
124  // ----- Start run ----------------------------------------------------
125  run->Run(nEvents);
126  run->CreateGeometryFile(geoFile);
127  // ------------------------------------------------------------------------
128 
129  // ----- Finish -------------------------------------------------------
130 
131  cout << endl << endl;
132 
133  // Extract the maximal used memory an add is as Dart measurement
134  // This line is filtered by CTest and the value send to CDash
135  FairSystemInfo sysInfo;
136  Float_t maxMemory = sysInfo.GetMaxMemory();
137  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
138  cout << maxMemory;
139  cout << "</DartMeasurement>" << endl;
140 
141  timer.Stop();
142  Double_t rtime = timer.RealTime();
143  Double_t ctime = timer.CpuTime();
144 
145  Float_t cpuUsage = ctime / rtime;
146  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
147  cout << cpuUsage;
148  cout << "</DartMeasurement>" << endl;
149 
150  cout << endl << endl;
151  cout << "Output file is " << outFile << endl;
152  cout << "Parameter file is " << parFile << endl;
153  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
154  cout << "Macro finished successfully." << endl;
155 
156  // ------------------------------------------------------------------------
157 }
void run_tutorial1(Int_t nEvents=10, TString mcEngine="TGeant3", Bool_t isMT=true, Bool_t loadPostInitConfig=false)
Definition: run_tutorial1.C:8
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 SetPRange(Double32_t pmin=0, Double32_t pmax=10)
void AddGenerator(FairGenerator *generator)
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
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 UsePostInitConfig(bool useC=true, const char *stringC="g4ConfigPostInit.C")
virtual void Run(Int_t NEvents=0, Int_t NotUsed=0)
Definition: FairRunSim.cxx:306
void AddModule(FairModule *Mod)
Definition: FairRunSim.cxx:118
void SetSimulationConfig(FairGenericVMCConfig *tconf)
Definition: FairRunSim.h:181
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
void saveOutput(void)