FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_tutorial4.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_tutorial4(Int_t nEvents = 10, TString mcEngine = "TGeant3", Bool_t doAlign = true, Bool_t isMT = false)
9 {
10 
11  TString dir = getenv("VMCWORKDIR");
12 
13  TString tut_configdir = dir + "/simulation/Tutorial4/gconfig";
14  gSystem->Setenv("CONFIG_DIR", tut_configdir.Data());
15 
16  TString tut_geomdir = dir + "/common/geometry";
17  gSystem->Setenv("GEOMPATH", tut_geomdir.Data());
18 
19  Double_t momentum = 2.;
20 
21  Double_t theta = 2.;
22 
23  TString outDir = "./data/";
24 
25  // Output file name
26  TString outFile{""};
27  TString geoFile{""};
28  TString parFile{""};
29  if (doAlign) {
30  outFile = "testrun_align_";
31  geoFile = "geoFile_align_";
32  parFile = "testparams_align_";
33  } else {
34  outFile = "testrun_";
35  geoFile = "geoFile";
36  parFile = "testparams_";
37  }
38  outFile = outDir + outFile + mcEngine + ".root";
39  geoFile = outDir + geoFile + mcEngine + ".root";
40  parFile = outDir + parFile + mcEngine + ".root";
41 
42  TList* parFileList = new TList();
43 
44  TString paramDir = dir + "/simulation/Tutorial4/parameters/";
45  TString paramFile = paramDir + "example.par";
46 
47  TObjString* tutDetDigiFile = new TObjString(paramFile);
48  parFileList->Add(tutDetDigiFile);
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  // Does not work with automatic loading pf libraries. The info is not in the rootmap file
63  // gLogger->SetLogScreenLevel("INFO");
64 
65  // ----- Create simulation run ----------------------------------------
66  FairRunSim* run = new FairRunSim();
67  run->SetName(mcEngine); // Transport engine
68  run->SetIsMT(isMT); // Multi-threading mode (Geant4 only)
69  run->SetSink(new FairRootFileSink(outFile)); // Output file
70  FairRuntimeDb* rtdb = run->GetRuntimeDb();
71  // ------------------------------------------------------------------------
72 
73  // ----- Create media -------------------------------------------------
74  run->SetMaterials("media.geo"); // Materials
75  // ------------------------------------------------------------------------
76 
77  // ----- Create geometry ----------------------------------------------
78  FairModule* cave = new FairCave("CAVE");
79  cave->SetGeometryFileName("cave_vacuum.geo");
80  run->AddModule(cave);
81 
82  FairTutorialDet4* tutdet = new FairTutorialDet4("TUTDET", kTRUE);
83  tutdet->SetGeometryFileName("tutorial4.root");
84  tutdet->SetModifyGeometry(doAlign);
85 
86  run->AddModule(tutdet);
87  // ------------------------------------------------------------------------
88 
89  // ----- Create PrimaryGenerator --------------------------------------
91  FairBoxGenerator* boxGen = new FairBoxGenerator(2212, 1);
92 
93  boxGen->SetThetaRange(theta, theta + 0.1);
94  // boxGen->SetThetaRange ( 0., 0.);
95  boxGen->SetPRange(momentum, momentum + 0.01);
96  boxGen->SetPhiRange(0., 360.);
97  boxGen->SetBoxXYZ(-20., -20., 20., 20., 0.);
98  // boxGen->SetBoxXYZ (0.,0.,0.,0., 0.);
99 
100  // boxGen->SetDebug(kTRUE);
101 
102  primGen->AddGenerator(boxGen);
103 
104  run->SetGenerator(primGen);
105 
106  // ----- Store information about particle trajectories ------------------
107  run->SetStoreTraj(kTRUE);
108 
109  // ----- Runtime database ---------------------------------------------
110 
111  Bool_t kParameterMerged = kTRUE;
112  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
113  FairParAsciiFileIo* parIn = new FairParAsciiFileIo();
114  parOut->open(parFile.Data());
115  parIn->open(parFileList, "in");
116  rtdb->setFirstInput(parIn);
117  rtdb->setOutput(parOut);
118  // ------------------------------------------------------------------------
119 
120  // ----- Initialize simulation run ------------------------------------
121  run->Init();
122 
123  // -Trajectories Visualization (TGeoManager Only )
124  // -----------------------------------------------
125 
126  // Set cuts for storing the trajectories
127  /* FairTrajFilter* trajFilter = FairTrajFilter::Instance();
128  trajFilter->SetStepSizeCut(0.01); // 1 cm
129  trajFilter->SetVertexCut(-2000., -2000., 4., 2000., 2000., 100.);
130  trajFilter->SetMomentumCutP(10e-3); // p_lab > 10 MeV
131  trajFilter->SetEnergyCut(0., 1.02); // 0 < Etot < 1.04 GeV
132  trajFilter->SetStorePrimaries(kTRUE);
133  trajFilter->SetStoreSecondaries(kTRUE);
134  */
135 
136  // ------------------------------------------------------------------------
137 
138  // ----- Start run ----------------------------------------------------
139  // run->CreateGeometryFile(geoFile); //misaligned geometry
140  run->Run(nEvents);
141  // run->CreateGeometryFile(geoFile); // original geometry
142  // ------------------------------------------------------------------------
143 
144  rtdb->saveOutput();
145  rtdb->print();
146 
147  delete run;
148 
149  // ----- Finish -------------------------------------------------------
150 
151  cout << endl << endl;
152 
153  // Extract the maximal used memory an add is as Dart measurement
154  // This line is filtered by CTest and the value send to CDash
155  FairSystemInfo sysInfo;
156  Float_t maxMemory = sysInfo.GetMaxMemory();
157  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
158  cout << maxMemory;
159  cout << "</DartMeasurement>" << endl;
160 
161  timer.Stop();
162  Double_t rtime = timer.RealTime();
163  Double_t ctime = timer.CpuTime();
164 
165  Float_t cpuUsage = ctime / rtime;
166  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
167  cout << cpuUsage;
168  cout << "</DartMeasurement>" << endl;
169 
170  cout << endl << endl;
171  cout << "Output file is " << outFile << endl;
172  cout << "Parameter file is " << parFile << endl;
173  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
174  cout << "Macro finished successfully." << endl;
175 
176  // ------------------------------------------------------------------------
177 }
Bool_t kParameterMerged
virtual void SetGeometryFileName(TString fname, TString geoVer="0")
Definition: FairModule.cxx:199
list of container factories
Definition: FairRuntimeDb.h:24
Bool_t open(const Text_t *fname, const Text_t *status="in")
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
void SetModifyGeometry(Bool_t val)
Float_t GetMaxMemory()
void SetIsMT(Bool_t isMT)
Definition: FairRunSim.h:184
FairParRootFileIo * parOut
void run_tutorial4(Int_t nEvents=10, TString mcEngine="TGeant3", Bool_t doAlign=true, Bool_t isMT=false)
Definition: run_tutorial4.C:8
void SetBoxXYZ(Double32_t x1=0, Double32_t y1=0, Double32_t x2=0, Double32_t y2=0, Double32_t z=0)
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)
Bool_t setFirstInput(FairParIo *)
void saveOutput(void)
void SetStoreTraj(Bool_t storeTraj=kTRUE)
Definition: FairRunSim.h:92