FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_sim.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_sim(Int_t nEvents = 100, TString mcEngine = "TGeant3")
9 {
10  TStopwatch timer;
11  timer.Start();
12  gDebug = 0;
13 
14  // Use non default gconfig and geometry directories
15  TString dir = getenv("VMCWORKDIR");
16  TString tutdir = dir + "/";
17 
18  TString tut_geomdir = tutdir + "/common/geometry";
19  gSystem->Setenv("GEOMPATH", tut_geomdir.Data());
20 
21  TString tut_configdir = tutdir + "/common/gconfig";
22  gSystem->Setenv("CONFIG_DIR", tut_configdir.Data());
23 
24  // create Instance of Run Manager class
25  FairRunSim *fRun = new FairRunSim();
26  fRun->SetUseFairLinks(kTRUE);
27  // FairLinkManager::Instance()->AddIncludeType(0);
28  // set the MC version used
29  // ------------------------
30 
31  fRun->SetName(mcEngine);
32 
33  TString outFile = "data/testrun_";
34  outFile = outFile + mcEngine + ".root";
35 
36  TString geoFile = "data/geofile_";
37  geoFile = geoFile + mcEngine + "_full.root";
38 
39  TString parFile = "data/testparams_";
40  parFile = parFile + mcEngine + ".root";
41 
42  fRun->SetSink(new FairRootFileSink(outFile));
43  fRun->SetGenerateRunInfo(kTRUE); // Create FairRunInfo file
44 
45  // ----- Magnetic field -------------------------------------------
46  // Constant Field
47  FairConstField *fMagField = new FairConstField();
48  fMagField->SetField(0., 10., 0.); // values are in kG
49  fMagField->SetFieldRegion(-50, 50, -50, 50, 350, 450); // values are in cm (xmin,xmax,ymin,ymax,zmin,zmax)
50  fRun->SetField(fMagField);
51  // --------------------------------------------------------------------
52 
53  // Set Material file Name
54  //-----------------------
55  fRun->SetMaterials("media.geo");
56 
57  // Create and add detectors
58  //-------------------------
59  FairModule *Cave = new FairCave("CAVE");
60  Cave->SetGeometryFileName("cave.geo");
61  fRun->AddModule(Cave);
62 
63  FairModule *Magnet = new FairMagnet("MAGNET");
64  Magnet->SetGeometryFileName("magnet.geo");
65  fRun->AddModule(Magnet);
66 
67  FairDetector *Torino = new FairTestDetector("TORINO", kTRUE);
68  Torino->SetGeometryFileName("torino.geo");
69  fRun->AddModule(Torino);
70 
71  // Create and Set Event Generator
72  //-------------------------------
73 
75  fRun->SetGenerator(primGen);
76 
77  // Box Generator
78  FairBoxGenerator *boxGen = new FairBoxGenerator(2212, 10); // 13 = muon; 1 = multipl.
79  boxGen->SetPRange(2., 2.); // GeV/c //setPRange vs setPtRange
80  boxGen->SetPhiRange(0, 360); // Azimuth angle range [degree]
81  boxGen->SetThetaRange(3, 10); // Polar angle in lab system range [degree]
82  boxGen->SetCosTheta(); // uniform generation on all the solid angle(default)
83 
84  // boxGen->SetXYZ(0., 0.37, 0.);
85  primGen->AddGenerator(boxGen);
86 
87  fRun->SetStoreTraj(kTRUE);
88 
89  fRun->Init();
90 
91  // -Trajectories Visualization (TGeoManager Only )
92  // -----------------------------------------------
93 
94  // Set cuts for storing the trajectpries
95  /* FairTrajFilter* trajFilter = FairTrajFilter::Instance();
96  trajFilter->SetStepSizeCut(0.01); // 1 cm
97  trajFilter->SetVertexCut(-2000., -2000., 4., 2000., 2000., 100.);
98  trajFilter->SetMomentumCutP(10e-3); // p_lab > 10 MeV
99  trajFilter->SetEnergyCut(0., 1.02); // 0 < Etot < 1.04 GeV
100  trajFilter->SetStorePrimaries(kTRUE);
101  trajFilter->SetStoreSecondaries(kTRUE);
102  */
103 
104  // Fill the Parameter containers for this run
105  //-------------------------------------------
106 
107  FairRuntimeDb *rtdb = fRun->GetRuntimeDb();
108  Bool_t kParameterMerged = kTRUE;
109  FairParRootFileIo *output = new FairParRootFileIo(kParameterMerged);
110  output->open(parFile);
111  rtdb->setOutput(output);
112 
113  rtdb->saveOutput();
114  rtdb->print();
115 
116  // Transport nEvents
117  // -----------------
118 
119  // Int_t nEvents = 1;
120  fRun->Run(nEvents);
121 
122  fRun->CreateGeometryFile(geoFile);
123 
124  // ----- Finish -------------------------------------------------------
125 
126  cout << endl << endl;
127 
128  // Extract the maximal used memory an add is as Dart measurement
129  // This line is filtered by CTest and the value send to CDash
130  FairSystemInfo sysInfo;
131  Float_t maxMemory = sysInfo.GetMaxMemory();
132  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
133  cout << maxMemory;
134  cout << "</DartMeasurement>" << endl;
135 
136  timer.Stop();
137  Double_t rtime = timer.RealTime();
138  Double_t ctime = timer.CpuTime();
139 
140  Float_t cpuUsage = ctime / rtime;
141  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
142  cout << cpuUsage;
143  cout << "</DartMeasurement>" << endl;
144 
145  cout << endl << endl;
146  cout << "Output file is " << outFile << endl;
147  cout << "Parameter file is " << parFile << endl;
148  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
149  cout << "Macro finished successfully." << endl;
150 
151  // ------------------------------------------------------------------------
152 }
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 SetField(FairField *field)
Definition: FairRunSim.cxx:308
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
void AddGenerator(FairGenerator *generator)
void SetField(Double_t bX, Double_t bY, Double_t bZ)
void SetGenerator(FairPrimaryGenerator *Gen)
Definition: FairRunSim.cxx:310
void print(void)
void SetGenerateRunInfo(Bool_t write)
Definition: FairRun.h:131
void SetSink(FairSink *tempSink)
Definition: FairRun.h:84
Float_t GetMaxMemory()
void SetUseFairLinks(Bool_t val)
Definition: FairRun.cxx:120
void SetFieldRegion(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax)
virtual void Init()
Definition: FairRunSim.cxx:143
void run_sim(Int_t nEvents=100, TString mcEngine="TGeant3")
Definition: run_sim.C:8
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