forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_sim.C
More file actions
144 lines (112 loc) · 4.13 KB
/
Copy pathrun_sim.C
File metadata and controls
144 lines (112 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <Rtypes.h>
#include <TSystem.h>
#include <TMath.h>
#include <TString.h>
#include <TStopwatch.h>
#include <TGeoManager.h>
#include "FairRunSim.h"
#include "FairRuntimeDb.h"
#include "FairPrimaryGenerator.h"
#include "FairBoxGenerator.h"
#include "FairParRootFileIo.h"
#include "DetectorsPassive/Cave.h"
#include "Field/MagneticField.h"
#include "ITSBase/GeometryTGeo.h"
#include "ITSMFTBase/SegmentationAlpide.h"
#include "ITSSimulation/Detector.h"
#include "ITSSimulation/Detector.h"
#include "TPCSimulation/Detector.h"
#endif
double radii2Turbo(double rMin, double rMid, double rMax, double sensW)
{
// compute turbo angle from radii and sensor width
return TMath::ASin((rMax * rMax - rMin * rMin) / (2 * rMid * sensW)) * TMath::RadToDeg();
}
void run_sim(Int_t nEvents = 2, TString mcEngine = "TGeant3")
{
TString dir = getenv("VMCWORKDIR");
TString geom_dir = dir + "/Detectors/Geometry/";
gSystem->Setenv("GEOMPATH",geom_dir.Data());
TString tut_configdir = dir + "/Detectors/gconfig";
gSystem->Setenv("CONFIG_DIR",tut_configdir.Data());
// Output file name
char fileout[100];
sprintf(fileout, "AliceO2_%s.mc_%i_event.root", mcEngine.Data(), nEvents);
TString outFile = fileout;
// Parameter file name
char filepar[100];
sprintf(filepar, "AliceO2_%s.params_%i.root", mcEngine.Data(), nEvents);
TString parFile = filepar;
// In general, the following parts need not be touched
// Debug option
gDebug = 0;
// Timer
TStopwatch timer;
timer.Start();
// CDB manager
// o2::ccdb::Manager *cdbManager = o2::ccdb::Manager::Instance();
// cdbManager->setDefaultStorage("local://$ALICEO2/tpc/dirty/o2cdb");
// cdbManager->setRun(0);
// gSystem->Load("libAliceO2Base");
// gSystem->Load("libAliceO2its");
// Create simulation run
FairRunSim* run = new FairRunSim();
run->SetName(mcEngine); // Transport engine
run->SetOutputFile(outFile); // Output file
FairRuntimeDb* rtdb = run->GetRuntimeDb();
// Create media
run->SetMaterials("media.geo"); // Materials
// Create geometry
o2::passive::Cave* cave = new o2::passive::Cave("CAVE");
cave->SetGeometryFileName("cave.geo");
run->AddModule(cave);
// FairDetector* tpc = new O2tpc("TPCV2");
// tpc->SetGeometry();
// run->AddModule(tpc);
// TGeoGlobalMagField::Instance()->SetField(new o2::field::MagneticField("Maps","Maps", -1., -1., o2::field::MagneticField::k5kG));
o2::field::MagneticField field("field","field +5kG");
run->SetField(&field);
// ===| Add ITS |============================================================
o2::its::Detector* its = new o2::its::Detector(kTRUE);
run->AddModule(its);
// ===| Add TPC |============================================================
o2::tpc::Detector* tpc = new o2::tpc::Detector(kTRUE);
//tpc->SetGeoFileName("TPCGeometry.root");
run->AddModule(tpc);
// Create PrimaryGenerator
FairPrimaryGenerator* primGen = new FairPrimaryGenerator();
FairBoxGenerator* boxGen = new FairBoxGenerator(2212, 1); /*protons*/
//boxGen->SetThetaRange(0.0, 90.0);
boxGen->SetEtaRange(-0.9,0.9);
boxGen->SetPRange(100, 100.01);
boxGen->SetPhiRange(0., 360.);
boxGen->SetDebug(kTRUE);
primGen->AddGenerator(boxGen);
run->SetGenerator(primGen);
// store track trajectories
// run->SetStoreTraj(kTRUE);
// Initialize simulation run
run->Init();
// Runtime database
Bool_t kParameterMerged = kTRUE;
FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged);
parOut->open(parFile.Data());
rtdb->setOutput(parOut);
rtdb->saveOutput();
rtdb->print();
// Start run
run->Run(nEvents);
// run->CreateGeometryFile("geofile_full.root");
// Finish
timer.Stop();
Double_t rtime = timer.RealTime();
Double_t ctime = timer.CpuTime();
std::cout << std::endl << std::endl;
std::cout << "Macro finished succesfully." << std::endl;
std::cout << "Output file is " << outFile << std::endl;
std::cout << "Parameter file is " << parFile << std::endl;
std::cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << std::endl << std::endl;
delete run;
return;
}