FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_background.C
Go to the documentation of this file.
1 void run_background(Int_t nEvents = 130)
2 {
3  TString dir = getenv("VMCWORKDIR");
4  TString tutdir = dir + "/simulation/Tutorial2";
5 
6  TString tut_geomdir = dir + "/common/geometry";
7  gSystem->Setenv("GEOMPATH", tut_geomdir.Data());
8 
9  TString tut_configdir = dir + "/common/gconfig";
10  gSystem->Setenv("CONFIG_DIR", tut_configdir.Data());
11 
12  TString partName[] = {"pions", "eplus", "proton"};
13  Int_t partPdgC[] = {211, 11, 2212};
14  Int_t chosenPart = 0;
15 
16  Double_t momentum = 2.;
17 
18  Double_t theta = 0.;
19 
20  TString outDir = "./";
21 
22  // Output file name
23  TString outFile = Form("%s/tutorial2_%s.mc_p%1.3f_t%1.0f_n%d.bg.root",
24  outDir.Data(),
25  partName[chosenPart].Data(),
26  momentum,
27  theta,
28  nEvents);
29 
30  // Parameter file name
31  TString parFile = Form("%s/tutorial2_%s.params_p%1.3f_t%1.0f_n%d.bg.root",
32  outDir.Data(),
33  partName[chosenPart].Data(),
34  momentum,
35  theta,
36  nEvents);
37 
38  // In general, the following parts need not be touched
39  // ========================================================================
40 
41  // ---- Debug option -------------------------------------------------
42  gDebug = 0;
43  // ------------------------------------------------------------------------
44 
45  // ----- Timer --------------------------------------------------------
46  TStopwatch timer;
47  timer.Start();
48  // ------------------------------------------------------------------------
49 
50  // ----- Create simulation run ----------------------------------------
51  FairRunSim* run = new FairRunSim();
52  run->SetName("TGeant3"); // Transport engine
53  run->SetSink(new FairRootFileSink(outFile)); // Output file
54  FairRuntimeDb* rtdb = run->GetRuntimeDb();
55  // ------------------------------------------------------------------------
56 
57  // ----- Create media -------------------------------------------------
58  run->SetMaterials("media.geo"); // Materials
59  // ------------------------------------------------------------------------
60 
61  // ----- Create geometry ----------------------------------------------
62  FairModule* cave = new FairCave("CAVE");
63  cave->SetGeometryFileName("cave_vacuum.geo");
64  run->AddModule(cave);
65 
66  FairDetector* tutdet = new FairTutorialDet2("TUTDET", kTRUE);
67  tutdet->SetGeometryFileName("double_sector.geo");
68  run->AddModule(tutdet);
69  // ------------------------------------------------------------------------
70 
71  // ----- Create PrimaryGenerator --------------------------------------
73  FairBoxGenerator* boxGen = new FairBoxGenerator(partPdgC[chosenPart], 1);
74 
75  boxGen->SetThetaRange(theta, theta + 0.01);
76  boxGen->SetPRange(momentum, momentum + 0.01);
77  boxGen->SetPhiRange(0., 360.);
78 
79  primGen->AddGenerator(boxGen);
80 
81  run->SetGenerator(primGen);
82  // ------------------------------------------------------------------------
83 
84  // ----- Initialize simulation run ------------------------------------
85  run->Init();
86  // ------------------------------------------------------------------------
87 
88  // ----- Runtime database ---------------------------------------------
89  Bool_t kParameterMerged = kTRUE;
90  FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
91  parOut->open(parFile.Data());
92  rtdb->setOutput(parOut);
93  rtdb->saveOutput();
94  rtdb->print();
95  // ------------------------------------------------------------------------
96 
97  // ----- Start run ----------------------------------------------------
98  run->Run(nEvents);
99  // ------------------------------------------------------------------------
100 
101  // ----- Finish -------------------------------------------------------
102 
103  cout << endl << endl;
104 
105  // Extract the maximal used memory an add is as Dart measurement
106  // This line is filtered by CTest and the value send to CDash
107  FairSystemInfo sysInfo;
108  Float_t maxMemory = sysInfo.GetMaxMemory();
109  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
110  cout << maxMemory;
111  cout << "</DartMeasurement>" << endl;
112 
113  timer.Stop();
114  Double_t rtime = timer.RealTime();
115  Double_t ctime = timer.CpuTime();
116 
117  Float_t cpuUsage = ctime / rtime;
118  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
119  cout << cpuUsage;
120  cout << "</DartMeasurement>" << endl;
121 
122  cout << endl << endl;
123  cout << "Output file is " << outFile << endl;
124  cout << "Parameter file is " << parFile << endl;
125  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
126  cout << "Macro finished successfully." << endl;
127 
128  // ------------------------------------------------------------------------
129 }
Bool_t kParameterMerged
virtual void SetGeometryFileName(TString fname, TString geoVer="0")
Definition: FairModule.cxx:199
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
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 run_background(Int_t nEvents=130)
Definition: run_background.C:1
void saveOutput(void)