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