FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_tutorial1_fastsim.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_fastsim(Int_t nEvents = 10, TString mcEngine = "TGeant3", Bool_t isMT = false)
9 {
10 
11  TString dir = getenv("VMCWORKDIR");
12  TString tutdir = dir + "/simulation/Tutorial1";
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/tutorial1_%s_%s.mc_p%1.3f_t%1.0f_n%d.root",
32  outDir.Data(),
33  mcEngine.Data(),
34  partName[chosenPart].Data(),
35  momentum,
36  theta,
37  nEvents);
38 
39  // Parameter file name
40  TString parFile = Form("%s/tutorial1_%s_%s.params_p%1.3f_t%1.0f_n%d.root",
41  outDir.Data(),
42  mcEngine.Data(),
43  partName[chosenPart].Data(),
44  momentum,
45  theta,
46  nEvents);
47 
48  TString geoFile = "geofile_" + mcEngine + "_full.root";
49 
50  // In general, the following parts need not be touched
51  // ========================================================================
52 
53  // ---- Debug option -------------------------------------------------
54  gDebug = 0;
55  // ------------------------------------------------------------------------
56 
57  // ----- Timer --------------------------------------------------------
58  TStopwatch timer;
59  timer.Start();
60  // ------------------------------------------------------------------------
61 
62  // ----- Create simulation run ----------------------------------------
63  FairRunSim* run = new FairRunSim();
64  run->SetName(mcEngine); // Transport engine
65  run->SetIsMT(isMT); // Multi-threading mode (Geant4 only)
66  run->SetSink(new FairRootFileSink(outFile)); // Output file
67  FairRuntimeDb* rtdb = run->GetRuntimeDb();
68  // ------------------------------------------------------------------------
69 
70  // ----- Create media -------------------------------------------------
71  run->SetMaterials("media.geo"); // Materials
72  // ------------------------------------------------------------------------
73 
74  // ----- Create geometry ----------------------------------------------
75 
76  FairModule* cave = new FairCave("CAVE");
77  cave->SetGeometryFileName("cave_vacuum.geo");
78  run->AddModule(cave);
79 
80  FairDetector* fastsim = new FairFastSimExample("FastSim");
81  run->AddModule(fastsim);
82 
83  FairDetector* fastsim2 = new FairFastSimExample2("FastSim2");
84  run->AddModule(fastsim2);
85 
86  FairDetector* tutdet = new FairTutorialDet1("TUTDET", kTRUE);
87  tutdet->SetGeometryFileName("double_sector.geo");
88  run->AddModule(tutdet);
89  // ------------------------------------------------------------------------
90 
91  // ----- Create PrimaryGenerator --------------------------------------
93  FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[chosenPart], 1);
94 
95  boxGen->SetThetaRange(theta, theta + 0.01);
96  boxGen->SetPRange(momentum, momentum + 0.01);
97  boxGen->SetPhiRange(0., 360.);
98  boxGen->SetDebug(kTRUE);
99 
100  primGen->AddGenerator(boxGen);
101 
102  run->SetGenerator(primGen);
103  // ------------------------------------------------------------------------
104 
105  // ----- Initialize simulation run ------------------------------------
106  UInt_t randomSeed = 123456;
107  TRandom3 random(randomSeed);
108  gRandom = &random;
109 
110  run->SetStoreTraj(kTRUE);
111 
112  gLogger->SetLogScreenLevel("info");
113 
114  run->Init();
115  // ------------------------------------------------------------------------
116 
117  // ----- Runtime database ---------------------------------------------
118 
119  Bool_t kParameterMerged = kTRUE;
120  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
121  parOut->open(parFile.Data());
122  rtdb->setOutput(parOut);
123  rtdb->saveOutput();
124  rtdb->print();
125  // ------------------------------------------------------------------------
126 
127  // ----- Start run ----------------------------------------------------
128  run->Run(nEvents);
129  run->CreateGeometryFile(geoFile);
130  // ------------------------------------------------------------------------
131 
132  // ----- Finish -------------------------------------------------------
133 
134  cout << endl << endl;
135 
136  // Extract the maximal used memory an add is as Dart measurement
137  // This line is filtered by CTest and the value send to CDash
138  FairSystemInfo sysInfo;
139  Float_t maxMemory = sysInfo.GetMaxMemory();
140  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
141  cout << maxMemory;
142  cout << "</DartMeasurement>" << endl;
143 
144  timer.Stop();
145  Double_t rtime = timer.RealTime();
146  Double_t ctime = timer.CpuTime();
147 
148  Float_t cpuUsage = ctime / rtime;
149  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
150  cout << cpuUsage;
151  cout << "</DartMeasurement>" << endl;
152 
153  cout << endl << endl;
154  cout << "Output file is " << outFile << endl;
155  cout << "Parameter file is " << parFile << endl;
156  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
157  cout << "Macro finished successfully." << endl;
158 
159  // ------------------------------------------------------------------------
160 }
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
#define gLogger
Definition: FairLogger.h:156
FairParRootFileIo * parOut
virtual void Init()
Definition: FairRunSim.cxx:143
void run_tutorial1_fastsim(Int_t nEvents=10, TString mcEngine="TGeant3", Bool_t isMT=false)
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)
void SetStoreTraj(Bool_t storeTraj=kTRUE)
Definition: FairRunSim.h:92