FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_tutorial4_createGeometryFile.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_createGeometryFile(Int_t nEvents = 1, TString mcEngine = "TGeant3", 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 = "makeGeo_";
27  outFile = outDir + outFile + mcEngine + ".root";
28 
29  TString geoFile = "makeGeoFile_";
30  geoFile = outDir + geoFile + mcEngine + "_full.root";
31 
32  TString parFile = "makeGeoParams_";
33  parFile = outDir + parFile + mcEngine + ".root";
34 
35  TList* parFileList = new TList();
36 
37  /*
38  TString paramDir = dir + "/simulation/Tutorial4/parameters/";
39  TString paramFile = paramDir + "example.par";
40 
41  TObjString* tutDetDigiFile = new TObjString(paramFile);
42  parFileList->Add(tutDetDigiFile);
43 */
44 
45  // In general, the following parts need not be touched
46  // ========================================================================
47 
48  // ---- Debug option -------------------------------------------------
49  gDebug = 0;
50  // ------------------------------------------------------------------------
51 
52  // ----- Timer --------------------------------------------------------
53  TStopwatch timer;
54  timer.Start();
55  // ------------------------------------------------------------------------
56 
57  // Does not work with automatic loading pf libraries. The info is not in the rootmap file
58  // gLogger->SetLogScreenLevel("INFO");
59 
60  // ----- Create simulation run ----------------------------------------
61  FairRunSim* run = new FairRunSim();
62  run->SetName(mcEngine); // Transport engine
63  run->SetIsMT(isMT); // Multi-threading mode (Geant4 only)
64  run->SetSink(new FairRootFileSink(outFile)); // Output file
65  FairRuntimeDb* rtdb = run->GetRuntimeDb();
66  // ------------------------------------------------------------------------
67 
68  // ----- Create media -------------------------------------------------
69  run->SetMaterials("media.geo"); // Materials
70  // ------------------------------------------------------------------------
71 
72  // ----- Create geometry ----------------------------------------------
73  FairModule* cave = new FairCave("CAVE");
74  cave->SetGeometryFileName("cave_vacuum.geo");
75  run->AddModule(cave);
76 
77  FairTutorialDet4* tutdet = new FairTutorialDet4("TUTDET", kTRUE);
78  tutdet->SetGeometryFileName("tutorial4.root");
79 
80  run->AddModule(tutdet);
81  // ------------------------------------------------------------------------
82 
83  // ----- Create PrimaryGenerator --------------------------------------
85  FairBoxGenerator* boxGen = new FairBoxGenerator(2212, 1);
86 
87  boxGen->SetThetaRange(theta, theta + 0.1);
88  // boxGen->SetThetaRange ( 0., 0.);
89  boxGen->SetPRange(momentum, momentum + 0.01);
90  boxGen->SetPhiRange(0., 360.);
91  boxGen->SetBoxXYZ(-20., -20., 20., 20., 0.);
92  // boxGen->SetBoxXYZ (0.,0.,0.,0., 0.);
93 
94  // boxGen->SetDebug(kTRUE);
95 
96  primGen->AddGenerator(boxGen);
97 
98  run->SetGenerator(primGen);
99  // ------------------------------------------------------------------------
100 
101  // ----- Runtime database ---------------------------------------------
102 
103  Bool_t kParameterMerged = kTRUE;
104  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
105  FairParAsciiFileIo* parIn = new FairParAsciiFileIo();
106  parOut->open(parFile.Data());
107  parIn->open(parFileList, "in");
108  rtdb->setFirstInput(parIn);
109  rtdb->setOutput(parOut);
110  // ------------------------------------------------------------------------
111 
112  run->Init();
113 
114  // ------------------------------------------------------------------------
115 
116  // ----- Start run ----------------------------------------------------
117  run->Run(nEvents);
118  run->CreateGeometryFile(geoFile);
119  // ------------------------------------------------------------------------
120 
121  rtdb->saveOutput();
122  rtdb->print();
123 
124  delete run;
125 
126  // ----- Finish -------------------------------------------------------
127 
128  cout << endl << endl;
129 
130  // Extract the maximal used memory an add is as Dart measurement
131  // This line is filtered by CTest and the value send to CDash
132  FairSystemInfo sysInfo;
133  Float_t maxMemory = sysInfo.GetMaxMemory();
134  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
135  cout << maxMemory;
136  cout << "</DartMeasurement>" << endl;
137 
138  timer.Stop();
139  Double_t rtime = timer.RealTime();
140  Double_t ctime = timer.CpuTime();
141 
142  Float_t cpuUsage = ctime / rtime;
143  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
144  cout << cpuUsage;
145  cout << "</DartMeasurement>" << endl;
146 
147  cout << endl << endl;
148  cout << "Output file is " << outFile << endl;
149  cout << "Parameter file is " << parFile << endl;
150  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
151  cout << "Macro finished successfully." << endl;
152 
153  // ------------------------------------------------------------------------
154 }
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
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
Float_t GetMaxMemory()
void SetIsMT(Bool_t isMT)
Definition: FairRunSim.h:184
FairParRootFileIo * parOut
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 run_tutorial4_createGeometryFile(Int_t nEvents=1, TString mcEngine="TGeant3", Bool_t isMT=false)
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)