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