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 
9 void run_sim(Int_t nEvents = 10, TString mcEngine = "TGeant3", Int_t fileId = 0, Bool_t isMT = kFALSE)
10 {
11  TString dir = getenv("VMCWORKDIR");
12  TString tutdir = dir + "/MQ/pixelDetector";
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  TString outDir = "./";
25 
26  // Output file name
27  TString outFile;
28  if (fileId == 0) {
29  outFile = Form("%s/pixel_%s.mc.root", outDir.Data(), mcEngine.Data());
30  } else {
31  outFile = Form("%s/pixel_%s.mc.f%d.root", outDir.Data(), mcEngine.Data(), fileId);
32  }
33 
34  // Parameter file name
35  TString parFile = Form("%s/pixel_%s.params.root", outDir.Data(), mcEngine.Data());
36 
37  // In general, the following parts need not be touched
38  // ========================================================================
39 
40  // ---- Debug option -------------------------------------------------
41  gDebug = 0;
42  // ------------------------------------------------------------------------
43 
44  // ----- Timer --------------------------------------------------------
45  TStopwatch timer;
46  timer.Start();
47  // ------------------------------------------------------------------------
48 
49  // ----- Create simulation run ----------------------------------------
50  FairRunSim* run = new FairRunSim();
51  run->SetName(mcEngine); // Transport engine
52  run->SetIsMT(isMT); // Multi-threading mode (Geant4 only)
53  run->SetSink(new FairRootFileSink(outFile));
54  FairRuntimeDb* rtdb = run->GetRuntimeDb();
55  // ------------------------------------------------------------------------
56 
57  // ----- Create media -------------------------------------------------
58  run->SetMaterials("media.geo"); // Materials
59  // ------------------------------------------------------------------------
60 
61  // ----- Create geometry ----------------------------------------------
62 
63  FairModule* cave = new FairCave("CAVE");
64  cave->SetGeometryFileName("cave_vacuum.geo");
65  run->AddModule(cave);
66 
67  Pixel* det = new Pixel("PixelDetector", kTRUE);
68  det->SetGeometryFileName("pixel.geo");
69  // det->SetMisalignDetector(kTRUE);
70  run->AddModule(det);
71  // ------------------------------------------------------------------------
72 
73  // ----- Create PrimaryGenerator --------------------------------------
75  FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[chosenPart], 5);
76  boxGen->SetPRange(1, 2);
77  boxGen->SetThetaRange(0, 40);
78  boxGen->SetPhiRange(0, 360);
79  // boxGen->SetDebug(kTRUE);
80 
81  primGen->AddGenerator(boxGen);
82 
83  run->SetGenerator(primGen);
84  // ------------------------------------------------------------------------
85 
86  run->SetStoreTraj(kFALSE);
87 
88  // ----- Initialize simulation run ------------------------------------
89  run->Init();
90  // ------------------------------------------------------------------------
91 
92  // ----- Runtime database ---------------------------------------------
93 
94  Bool_t kParameterMerged = kTRUE;
95  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
96  parOut->open(parFile.Data());
97  rtdb->setOutput(parOut);
98  rtdb->saveOutput();
99  rtdb->print();
100  // ------------------------------------------------------------------------
101 
102  // ----- Start run ----------------------------------------------------
103  run->Run(nEvents);
104  run->CreateGeometryFile("geofile_full.root");
105  // ------------------------------------------------------------------------
106 
107  // ----- Finish -------------------------------------------------------
108 
109  cout << endl << endl;
110 
111  // Extract the maximal used memory an add is as Dart measurement
112  // This line is filtered by CTest and the value send to CDash
113  FairSystemInfo sysInfo;
114  Float_t maxMemory = sysInfo.GetMaxMemory();
115  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
116  cout << maxMemory;
117  cout << "</DartMeasurement>" << endl;
118 
119  timer.Stop();
120  Double_t rtime = timer.RealTime();
121  Double_t ctime = timer.CpuTime();
122 
123  Float_t cpuUsage = ctime / rtime;
124  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
125  cout << cpuUsage;
126  cout << "</DartMeasurement>" << endl;
127 
128  cout << endl << endl;
129  cout << "Output file is " << outFile << endl;
130  cout << "Parameter file is " << parFile << endl;
131  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
132  cout << "Macro finished successfully." << endl;
133 
134  // ------------------------------------------------------------------------
135 }
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
Definition: Pixel.h:21
FairParRootFileIo * parOut
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