FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_tutorial1_mesh.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_tutorial1_mesh(Int_t nEvents = 10, TString mcEngine = "TGeant3")
9 {
10 
11  TString dir = getenv("VMCWORKDIR");
12  TString tutdir = dir + "/simulation/Tutorial1";
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  Double_t momentum = 2.;
25 
26  Double_t theta = 0.;
27 
28  TString outDir = "./";
29 
30  // Output file name
31  TString outFile = Form("%s/tutorial1_mesh%s_%s.mc_p%1.3f_t%1.0f_n%d.root",
32  outDir.Data(),
33  mcEngine.Data(),
34  partName[chosenPart].Data(),
35  momentum,
36  theta,
37  nEvents);
38 
39  // Parameter file name
40  TString parFile = Form("%s/tutorial1_mesh%s_%s.params_p%1.3f_t%1.0f_n%d.root",
41  outDir.Data(),
42  mcEngine.Data(),
43  partName[chosenPart].Data(),
44  momentum,
45  theta,
46  nEvents);
47 
48  // In general, the following parts need not be touched
49  // ========================================================================
50 
51  // ---- Debug option -------------------------------------------------
52  gDebug = 0;
53  // ------------------------------------------------------------------------
54 
55  // ----- Timer --------------------------------------------------------
56  TStopwatch timer;
57  timer.Start();
58  // ------------------------------------------------------------------------
59 
60  // ----- Create simulation run ----------------------------------------
61  FairRunSim* run = new FairRunSim();
62  run->SetName(mcEngine); // Transport engine
63  run->SetSink(new FairRootFileSink(outFile)); // Output file
64  FairRuntimeDb* rtdb = run->GetRuntimeDb();
65  // ------------------------------------------------------------------------
66 
67  // ----- Create media -------------------------------------------------
68  run->SetMaterials("media.geo"); // Materials
69  // ------------------------------------------------------------------------
70 
71  // ----- Create geometry ----------------------------------------------
72 
73  FairModule* cave = new FairCave("CAVE");
74  cave->SetGeometryFileName("cave_vacuum.geo");
75  run->AddModule(cave);
76 
77  FairDetector* tutdet = new FairTutorialDet1("TUTDET", kTRUE);
78  tutdet->SetGeometryFileName("double_sector.geo");
79  run->AddModule(tutdet);
80  // ------------------------------------------------------------------------
81 
82  // ----- Create PrimaryGenerator --------------------------------------
84  FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[chosenPart], 1);
85 
86  boxGen->SetThetaRange(theta, theta + 55.);
87  boxGen->SetPRange(momentum, momentum + 0.01);
88  boxGen->SetPhiRange(0., 360.);
89  boxGen->SetCosTheta();
90  boxGen->SetDebug(kTRUE);
91 
92  primGen->AddGenerator(boxGen);
93 
94  run->SetGenerator(primGen);
95  // ------------------------------------------------------------------------
96 
97  run->SetStoreTraj(kFALSE); // to store particle trajectories
98 
99  run->SetRadGridRegister(kTRUE); // activate RadGridManager
100 
101  // define two example meshs for dosimetry
102  FairMesh* aMesh1 = new FairMesh("test1");
103  aMesh1->SetX(-60, 60, 200);
104  aMesh1->SetY(-60, 60, 200);
105  aMesh1->SetZ(29., 31., 1);
106 
107  FairMesh* aMesh2 = new FairMesh("test2");
108  aMesh2->SetX(-20, 20, 20);
109  aMesh2->SetY(-20, 20, 20);
110  aMesh2->SetZ(-5.0, 5.0, 1);
111 
112  aMesh1->print();
113  aMesh2->print();
114 
115  run->AddMesh(aMesh1);
116  run->AddMesh(aMesh2);
117 
118  // ----- Initialize simulation run ------------------------------------
119  run->Init();
120  FairRadGridManager::Instance()->SetOutputFileName("radGridResults.root");
121  // ------------------------------------------------------------------------
122 
123  // ----- Runtime database ---------------------------------------------
124 
125  Bool_t kParameterMerged = kTRUE;
126  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
127  parOut->open(parFile.Data());
128  rtdb->setOutput(parOut);
129  rtdb->saveOutput();
130  rtdb->print();
131  // ------------------------------------------------------------------------
132 
133  // ----- Start run ----------------------------------------------------
134  run->Run(nEvents);
135  // ------------------------------------------------------------------------
136 
137  // ----- Finish -------------------------------------------------------
138 
139  cout << endl << endl;
140 
141  // Extract the maximal used memory an add is as Dart measurement
142  // This line is filtered by CTest and the value send to CDash
143  FairSystemInfo sysInfo;
144  Float_t maxMemory = sysInfo.GetMaxMemory();
145  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
146  cout << maxMemory;
147  cout << "</DartMeasurement>" << endl;
148 
149  timer.Stop();
150  Double_t rtime = timer.RealTime();
151  Double_t ctime = timer.CpuTime();
152 
153  Float_t cpuUsage = ctime / rtime;
154  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
155  cout << cpuUsage;
156  cout << "</DartMeasurement>" << endl;
157 
158  cout << endl << endl;
159  cout << "Output file is " << outFile << endl;
160  cout << "Parameter file is " << parFile << endl;
161  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
162  cout << "Macro finished successfully." << endl;
163 
164  // ------------------------------------------------------------------------
165 }
void SetDebug(Bool_t)
Bool_t kParameterMerged
virtual void SetGeometryFileName(TString fname, TString geoVer="0")
Definition: FairModule.cxx:199
void AddMesh(FairMesh *Mesh)
Definition: FairRunSim.cxx:124
list of container factories
Definition: FairRuntimeDb.h:24
static FairRadGridManager * Instance()
void print()
Definition: FairMesh.cxx:92
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 run_tutorial1_mesh(Int_t nEvents=10, TString mcEngine="TGeant3")
Float_t GetMaxMemory()
void SetY(Double_t ymin, Double_t ymax, Int_t nbin)
Definition: FairMesh.h:52
void SetX(Double_t xmin, Double_t xmax, Int_t nbin)
Definition: FairMesh.h:46
FairParRootFileIo * parOut
virtual void Init()
Definition: FairRunSim.cxx:143
void SetZ(Double_t zmin, Double_t zmax, Int_t nbin)
Definition: FairMesh.h:58
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)
void SetOutputFileName(TString tempString)
virtual void Run(Int_t NEvents=0, Int_t NotUsed=0)
Definition: FairRunSim.cxx:306
void AddModule(FairModule *Mod)
Definition: FairRunSim.cxx:118
void SetRadGridRegister(Bool_t value)
Definition: FairRunSim.h:146
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
void saveOutput(void)
void SetStoreTraj(Bool_t storeTraj=kTRUE)
Definition: FairRunSim.h:92