FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
run_sim_sep.C
Go to the documentation of this file.
1 void run_sim_sep(Int_t fileId, Int_t nEvents = 1000, TString mcEngine = "TGeant3")
2 {
3  gRandom->SetSeed(1111 * fileId);
4 
5  TStopwatch timer;
6  timer.Start();
7  gDebug = 0;
8 
9  // Use non default gconfig and geometry directories
10  TString dir = getenv("VMCWORKDIR");
11  TString tutdir = dir + "/";
12 
13  TString tut_geomdir = tutdir + "/common/geometry";
14  gSystem->Setenv("GEOMPATH", tut_geomdir.Data());
15 
16  TString tut_configdir = tutdir + "/common/gconfig";
17  gSystem->Setenv("CONFIG_DIR", tut_configdir.Data());
18 
19  // create Instance of Run Manager class
20  FairRunSim *fRun = new FairRunSim();
21 
22  // set the MC version used
23  // ------------------------
24 
25  fRun->SetName(mcEngine);
26 
27  TString outfile = Form("data/testrun_%s_f%d.root", mcEngine.Data(), fileId);
28  TString outparam = Form("data/testpar_%s_f%d.root", mcEngine.Data(), fileId);
29 
30  fRun->SetSink(new FairRootFileSink(outfile));
31 
32  // ----- Magnetic field -------------------------------------------
33  // Constant Field
34  FairConstField *fMagField = new FairConstField();
35  fMagField->SetField(0., 10., 0.); // values are in kG
36  fMagField->SetFieldRegion(-50, 50, -50, 50, 350, 450); // values are in cm (xmin,xmax,ymin,ymax,zmin,zmax)
37  fRun->SetField(fMagField);
38  // --------------------------------------------------------------------
39 
40  // Set Material file Name
41  //-----------------------
42  fRun->SetMaterials("media.geo");
43 
44  // Create and add detectors
45  //-------------------------
46  FairModule *Cave = new FairCave("CAVE");
47  Cave->SetGeometryFileName("cave.geo");
48  fRun->AddModule(Cave);
49 
50  FairModule *Magnet = new FairMagnet("MAGNET");
51  Magnet->SetGeometryFileName("magnet.geo");
52  fRun->AddModule(Magnet);
53 
54  FairDetector *Torino = new FairTestDetector("TORINO", kTRUE);
55  Torino->SetGeometryFileName("torino.geo");
56  fRun->AddModule(Torino);
57 
58  // Create and Set Event Generator
59  //-------------------------------
60 
62  fRun->SetGenerator(primGen);
63 
64  // Box Generator
65  FairBoxGenerator *boxGen = new FairBoxGenerator(13, 10); // 13 = muon; 1 = multipl.
66  boxGen->SetPRange(2., 2.); // GeV/c //setPRange vs setPtRange
67  boxGen->SetPhiRange(0, 360); // Azimuth angle range [degree]
68  boxGen->SetThetaRange(3, 10); // Polar angle in lab system range [degree]
69  boxGen->SetCosTheta(); // uniform generation on all the solid angle(default)
70 
71  // boxGen->SetXYZ(0., 0.37, 0.);
72  primGen->AddGenerator(boxGen);
73 
74  fRun->SetStoreTraj(kTRUE);
75 
76  fRun->Init();
77 
78  // -Trajectories Visualization (TGeoManager Only )
79  // -----------------------------------------------
80 
81  // Set cuts for storing the trajectpries
82  /* FairTrajFilter* trajFilter = FairTrajFilter::Instance();
83  trajFilter->SetStepSizeCut(0.01); // 1 cm
84  trajFilter->SetVertexCut(-2000., -2000., 4., 2000., 2000., 100.);
85  trajFilter->SetMomentumCutP(10e-3); // p_lab > 10 MeV
86  trajFilter->SetEnergyCut(0., 1.02); // 0 < Etot < 1.04 GeV
87  trajFilter->SetStorePrimaries(kTRUE);
88  trajFilter->SetStoreSecondaries(kTRUE);
89  */
90 
91  // Fill the Parameter containers for this run
92  //-------------------------------------------
93 
94  FairRuntimeDb *rtdb = fRun->GetRuntimeDb();
95  Bool_t kParameterMerged = kTRUE;
96  FairParRootFileIo *output = new FairParRootFileIo(kParameterMerged);
97  output->open(outparam);
98  rtdb->setOutput(output);
99 
100  rtdb->saveOutput();
101  rtdb->print();
102 
103  // Transport nEvents
104  // -----------------
105 
106  // Int_t nEvents = 1;
107  fRun->Run(nEvents);
108 
109  fRun->CreateGeometryFile("data/geofile_full.root");
110 
111  // ----- Finish -------------------------------------------------------
112 
113  cout << endl << endl;
114 
115  // Extract the maximal used memory an add is as Dart measurement
116  // This line is filtered by CTest and the value send to CDash
117  FairSystemInfo sysInfo;
118  Float_t maxMemory = sysInfo.GetMaxMemory();
119  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
120  cout << maxMemory;
121  cout << "</DartMeasurement>" << endl;
122 
123  timer.Stop();
124  Double_t rtime = timer.RealTime();
125  Double_t ctime = timer.CpuTime();
126 
127  Float_t cpuUsage = ctime / rtime;
128  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
129  cout << cpuUsage;
130  cout << "</DartMeasurement>" << endl;
131 
132  cout << endl << endl;
133  cout << "Output file is " << outfile << endl;
134  cout << "Parameter file is " << outparam << endl;
135  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
136  cout << "Macro finished successfully." << endl;
137 
138  // ------------------------------------------------------------------------
139 }
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 SetField(FairField *field)
Definition: FairRunSim.cxx:308
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
void AddGenerator(FairGenerator *generator)
void SetField(Double_t bX, Double_t bY, Double_t bZ)
void SetGenerator(FairPrimaryGenerator *Gen)
Definition: FairRunSim.cxx:310
void print(void)
void SetSink(FairSink *tempSink)
Definition: FairRun.h:84
Float_t GetMaxMemory()
void SetFieldRegion(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax)
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)
void run_sim_sep(Int_t fileId, Int_t nEvents=1000, TString mcEngine="TGeant3")
Definition: run_sim_sep.C:1
void SetStoreTraj(Bool_t storeTraj=kTRUE)
Definition: FairRunSim.h:92