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