FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_tutorial1_pythia6.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_pythia6(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 pythia6Config(tut_configdir + "/DecayConfig.C");
21 
22  TString partName[] = {"pions", "eplus", "proton"};
23  Int_t partPdgC[] = {211, 11, 2212};
24  Int_t chosenPart = 0;
25 
26  Double_t momentum = 2.;
27 
28  Double_t theta = 0.;
29 
30  TString outDir = "./";
31 
32  // Output file name
33  TString outFile = Form("%s/tutorial1_pythia6_%s_%s.mc_p%1.3f_t%1.0f_n%d.root",
34  outDir.Data(),
35  mcEngine.Data(),
36  partName[chosenPart].Data(),
37  momentum,
38  theta,
39  nEvents);
40 
41  // Parameter file name
42  TString parFile = Form("%s/tutorial1_pythia6_%s_%s.params_p%1.3f_t%1.0f_n%d.root",
43  outDir.Data(),
44  mcEngine.Data(),
45  partName[chosenPart].Data(),
46  momentum,
47  theta,
48  nEvents);
49 
50  TString geoFile = outDir + "geofile_pythia6_" + mcEngine + "_full.root";
51 
52  // In general, the following parts need not be touched
53  // ========================================================================
54 
55  // ---- Debug option -------------------------------------------------
56  gDebug = 0;
57  // ------------------------------------------------------------------------
58 
59  // ----- Timer --------------------------------------------------------
60  TStopwatch timer;
61  timer.Start();
62  // ------------------------------------------------------------------------
63 
64  // ----- Create simulation run ----------------------------------------
65  FairRunSim* run = new FairRunSim();
66  run->SetName(mcEngine); // Transport engine
67  run->SetSink(new FairRootFileSink(outFile)); // Output file
68  run->SetPythiaDecayer(pythia6Config); // Define Pythia6 as decayer
69 
70  FairRuntimeDb* rtdb = run->GetRuntimeDb();
71  // ------------------------------------------------------------------------
72 
73  // ----- Create media -------------------------------------------------
74  run->SetMaterials("media.geo"); // Materials
75  // ------------------------------------------------------------------------
76 
77  // ----- Create geometry ----------------------------------------------
78 
79  FairModule* cave = new FairCave("CAVE");
80  cave->SetGeometryFileName("cave_vacuum.geo");
81  run->AddModule(cave);
82 
83  FairDetector* tutdet = new FairTutorialDet1("TUTDET", kTRUE);
84  tutdet->SetGeometryFileName("double_sector.geo");
85  run->AddModule(tutdet);
86  // ------------------------------------------------------------------------
87 
88  // ----- Create PrimaryGenerator --------------------------------------
90  FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[chosenPart], 1);
91 
92  boxGen->SetThetaRange(theta, theta + 0.01);
93  boxGen->SetPRange(momentum, momentum + 0.01);
94  boxGen->SetPhiRange(0., 360.);
95  boxGen->SetDebug(kTRUE);
96 
97  primGen->AddGenerator(boxGen);
98 
99  run->SetGenerator(primGen);
100  // ------------------------------------------------------------------------
101 
102  // ----- Initialize simulation run ------------------------------------
103  run->Init();
104  // ------------------------------------------------------------------------
105 
106  // ----- Runtime database ---------------------------------------------
107 
108  Bool_t kParameterMerged = kTRUE;
109  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
110  parOut->open(parFile.Data());
111  rtdb->setOutput(parOut);
112  rtdb->saveOutput();
113  rtdb->print();
114  // ------------------------------------------------------------------------
115 
116  // ----- Start run ----------------------------------------------------
117  run->Run(nEvents);
118  run->CreateGeometryFile(geoFile);
119  // ------------------------------------------------------------------------
120 
121  // ----- Finish -------------------------------------------------------
122 
123  cout << endl << endl;
124 
125  // Extract the maximal used memory an add is as Dart measurement
126  // This line is filtered by CTest and the value send to CDash
127  FairSystemInfo sysInfo;
128  Float_t maxMemory = sysInfo.GetMaxMemory();
129  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
130  cout << maxMemory;
131  cout << "</DartMeasurement>" << endl;
132 
133  timer.Stop();
134  Double_t rtime = timer.RealTime();
135  Double_t ctime = timer.CpuTime();
136 
137  Float_t cpuUsage = ctime / rtime;
138  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
139  cout << cpuUsage;
140  cout << "</DartMeasurement>" << endl;
141 
142  cout << endl << endl;
143  cout << "Output file is " << outFile << endl;
144  cout << "Parameter file is " << parFile << endl;
145  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
146  cout << "Macro finished successfully." << endl;
147 
148  // ------------------------------------------------------------------------
149 }
void SetDebug(Bool_t)
Bool_t kParameterMerged
void run_tutorial1_pythia6(Int_t nEvents=10, TString mcEngine="TGeant3")
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()
FairParRootFileIo * parOut
void SetPythiaDecayer(Bool_t decayer)
Definition: FairRunSim.h:124
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)
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)