FairRoot/PandaRoot
tools/RadMapTool/sim_radmap.C
Go to the documentation of this file.
1 
2 #ifndef __CINT__
3 #include <iostream>
4 #include <fstream>
5 
6 #include <stdio.h>
7 #include <getopt.h>
8 
9 #include <TStopwatch.h>
10 #include <TString.h>
11 #include <TRandom.h>
12 
13 #include <FairRunSim.h>
14 #include <FairRuntimeDb.h>
15 #include <FairParAsciiFileIo.h>
16 #include <FairParRootFileIo.h>
17 #include <FairModule.h>
18 
19 #include <PndCave.h>
20 #include <PndMagnet.h>
21 #include <PndPipe.h>
22 #include <PndStt.h>
23 #include <PndMvdDetector.h>
24 #include <PndEmc.h>
25 #include <PndMdt.h>
26 #include <PndGemDetector.h>
27 #include <PndDsk.h>
28 #include <PndDrc.h>
29 #include <PndFts.h>
30 #include <PndSciT.h>
31 #include <PndFtof.h>
32 #include <PndRich.h>
33 
34 #include <FairEvtGenGenerator.h>
35 #include <PndDpmDirect.h>
36 #include <FairPrimaryGenerator.h>
37 #include <FairBoxGenerator.h>
38 #include <PndEvtGenDirect.h>
39 #include <PndDpmDirect.h>
40 
41 
42 #include <PndMultiField.h>
43 #include <PndMultiFieldPar.h>
44 
45 #include <PndEmcHitProducer.h>
46 
47 #include <TMemStat.h>
48 
49 
50 #endif
51 
52 #include <sys/types.h>
53 #include <sys/stat.h>
54 #include <fcntl.h>
55 #include <unistd.h>
56 
57 
58 #define DEVURANDOM "/dev/urandom"
59 
60 
61 void ReadFiles(string geomfile,
62  std::vector<std::string>& geometryfiles);
63 
64 
65 
66 const char * help_str(){
67  return "Usage: [executable] [parameters]\n\n"
68  "\033[0;31m -o\t--output [name]\t\tName of the [o]utput file\033[0m\n"
69  "\033[0;31m -n\t--number [#]\t\tnumber of events to simulate\033[0m\n"
70  "\033[0;31m -t\t--tracker [tracker]\t\tWhich tracker will be used [Geant3, Geant4]\033[0m\n"
71  "\033[0;31m -g\t--geofile [geofile]\t\tFile that store the name of the geometry files of the detectors\033[0m\n"
72  // "\n-----------------------------------------------------------------\n"
73  ;
74 }
75 
76 //void sim(TString output="/tmp/test.root",
77 void sim(TString output,
78  // TString input,
79  Int_t nEvents,
80  const char* TransportModel,
81  std::vector<std::string> geometryfiles,
82  UInt_t seed);
83 
84 unsigned int GetRandomSeed(){
85  unsigned int rnum = 0;
86  int fd = open(DEVURANDOM, 0);
87  if (fd != -1){
88  (void) read(fd, (void *)&rnum, sizeof(int));
89  (void) close(fd);
90  }
91  return rnum;
92 }
93 
94 int main(int argc, char ** argv){
95 
96  int c;
97  unsigned nevt = 2;
98  string out = "RadMap_Out_Sim.root";
99  string tra = "TGeant4";
100  string geofile = "/lustre/nyx/panda/carsten/fairsoft_nov15/pandaroot/tools/RadMapTool/detectors.dat";
101  // std::vector<std::pair<std::string, std::string> > geometryfiles;
102  std::vector<std::string> geometryfiles;
103  while ((c = getopt(argc, argv, "n:o:t:g:h")) != -1)
104  switch (c) {
105  case 'n':
106  nevt = atoi(optarg);
107  break;
108 
109  case 'o':
110  out = optarg;
111  break;
112 
113  case 't':
114  tra = optarg;
115  break;
116 
117  case 'g':
118  geofile = optarg;
119  break;
120 
121  case 'h':
122  printf("%s\n", help_str());
123  break;
124 
125  default:
126  printf("%s\n", help_str());
127  abort ();
128  }
129 
130  std::cout<<" using detectors from "<<geofile.c_str()<<std::endl;
131 
132  ReadFiles(geofile, geometryfiles);
133 
134  int RandN = GetRandomSeed();
135  std::cout << "***************************\n";
136  std::cout << "sim: " << RandN << std::endl;
137  std::cout << "***************************\n";
138 
139  sim(TString(out.c_str()), nevt, tra.c_str(), geometryfiles, RandN);
140 }
141 
143  Int_t nEvents,
144  const char* TransportModel,
145  std::vector<std::string> geometryfiles,
146  UInt_t seed){
147  // activate TMemStat info file (ROOT >=5.28)
148  // TMemStat mm("gnubuiltin");
149 
150  gRandom->SetSeed(seed);
151  TStopwatch timer;
152  timer.Start();
153  gDebug=0;
154 
155  unsigned int RandN = 0;
156 
157 
158  FairRunSim *fRun = new FairRunSim();
159 
160  fRun->SetName(TransportModel);
161  fRun->SetOutputFile(output);
162 
163  fRun->SetMaterials(geometryfiles.at(0).c_str());
164 
165 
166  // Create and add detectors
167  //-------------------------
168  FairModule *Cave= new PndCave("CAVE");
169  Cave->SetGeometryFileName(geometryfiles.at(1).c_str());
170  fRun->AddModule(Cave);
171 
172  FairModule *Magnet= new PndMagnet("MAGNET");
173  Magnet->SetGeometryFileName(geometryfiles.at(2).c_str());
174  fRun->AddModule(Magnet);
175 
176  FairModule *Dipole= new PndMagnet("MAGNET");
177  Dipole->SetGeometryFileName(geometryfiles.at(3).c_str());
178  fRun->AddModule(Dipole);
179 
180  FairModule *Pipe= new PndPipe("PIPE");
181  Pipe->SetGeometryFileName(geometryfiles.at(4).c_str());
182  fRun->AddModule(Pipe);
183 
184  FairDetector *Stt= new PndStt("STT", kFALSE);
185  Stt->SetGeometryFileName(geometryfiles.at(5).c_str());
186  fRun->AddModule(Stt);
187 
188  FairDetector *Mvd = new PndMvdDetector("MVD", kFALSE);
189  Mvd->SetGeometryFileName(geometryfiles.at(6).c_str());
190  fRun->AddModule(Mvd);
191 
192  FairDetector *Gem = new PndGemDetector("GEM", kFALSE);
193  Gem->SetGeometryFileName(geometryfiles.at(7).c_str());
194  fRun->AddModule(Gem);
195 
196 
197  PndEmc *Emc = new PndEmc("EMC",kFALSE);
198  Emc->SetGeometryVersion(1);
199  Emc->SetStorageOfData(kFALSE);
200  fRun->AddModule(Emc);
201 
202  PndDrc *Drc = new PndDrc("DIRC", kFALSE);
203  Drc->SetGeometryFileName(geometryfiles.at(9).c_str());
204  Drc->SetRunCherenkov(kFALSE); // for fast sim Cherenkov -> kFALSE
205  fRun->AddModule(Drc);
206 
207  PndDsk* Dsk = new PndDsk("DSK", kFALSE);
208  Dsk->SetStoreCerenkovs(kFALSE);
209  Dsk->SetStoreTrackPoints(kFALSE);
210  fRun->AddModule(Dsk);
211 
212  PndMdt *Muo = new PndMdt("MDT",kFALSE);
213  Muo->SetBarrel("fast");
214  Muo->SetEndcap("fast");
215  Muo->SetMuonFilter("fast");
216  Muo->SetForward("fast");
217  Muo->SetMdtMagnet(kTRUE);
218  Muo->SetMdtCoil(kTRUE);
219  Muo->SetMdtMFIron(kTRUE);
220  fRun->AddModule(Muo);
221 
222  //------------------------- FTS -----------------
223  FairDetector *Fts= new PndFts("FTS", kFALSE);
224  Fts->SetGeometryFileName(geometryfiles.at(14).c_str());
225  fRun->AddModule(Fts);
226 
227  //--------------------------- FTOF -----------------
228  FairDetector *FTof = new PndFtof("FTOF",kFALSE);
229  FTof->SetGeometryFileName(geometryfiles.at(15).c_str()); // not default
230  fRun->AddModule(FTof);
231 
232 
233  FairModule* Rich= new PndRich("RICH",kFALSE);
234  Rich->SetGeometryFileName(geometryfiles.at(16).c_str());
235  fRun->AddModule(Rich);
236  // Create and Set Event Generator
237  //-------------------------------
238 
239  FairPrimaryGenerator* primGen = new FairPrimaryGenerator();
240  fRun->SetGenerator(primGen);
241 
242  Double_t P = 15.0;
243  RandN = GetRandomSeed();
244  std::cout << "***************************\n";
245  std::cout << "Dpm: " << RandN << std::endl;
246  std::cout << "***************************\n";
248  primGen->AddGenerator(dpmGen);
249 
250 
251  fRun->GetListOfModules()->Print();
252  fRun->SetStoreTraj(kFALSE); // to store particle trajectories
253  fRun->SetRadMapRegister(kTRUE); // radiation map manager
254  fRun->SetBeamMom(P);
255  PndMultiField *fField= new PndMultiField("FULL");
256  fRun->SetField(fField);
257 
258  timer.Stop();
259 
260  Double_t preinitrtime = timer.RealTime();
261 
262  timer.Continue();
263 
264  fRun->Init();
265 
266  timer.Stop();
267 
268  Double_t postinitrtime = timer.RealTime();
269 
270  timer.Continue();
271 
272  printf("************* Running %i events ******************\n", nEvents);
273  fRun->Run(nEvents);
274 
275  timer.Stop();
276 
277  Double_t rtime = timer.RealTime();
278  Double_t ctime = timer.CpuTime();
279  printf("Preinit: %f seconds, Postinit: %f seconds; RealTime=%f seconds, CpuTime=%f seconds\n", preinitrtime, postinitrtime, rtime, ctime);
280 }
281 
282 void ReadFiles(string geomfile,
283  std::vector<std::string>& geometryfiles){
284  // enum _files {MEDIA ,
285  // CAVE , SOLENOID , DIPOLE , PIPE , STT ,
286  // MVD , GEM , SciTile , DRC , DSK ,
287  // MUONBAR , MOUNENDC , MOUNFOR , MUONFILT , FTS ,
288  // FTOF , RICH};
289 
290  for(int i = 0; i < 18; i++) geometryfiles.push_back(std::string(""));
291 
292  TObjArray *tokens;
293  std::ifstream ifile(geomfile.c_str());
294 
295 
296  if(ifile.is_open()){
297  TString Line, help0, help1;
298  std::string line;
299  while (1) {
300  getline (ifile,line);
301  if(!ifile.good()) break;
302  Line = TString(line);
303  if(Line[0] != '#'){
304  tokens = Line.Tokenize(":");
305  if(tokens->GetEntries() == 2){
306  help0 = ((TObjString*)(tokens->At(0)))->GetString();
307  help0.Remove(TString::kBoth, ' ');
308  help1 = ((TObjString*)(tokens->At(1)))->GetString();
309  help1.Remove(TString::kBoth, ' ');
310  cout << "\"" << ((TObjString*)(tokens->At(1)))->GetString() << "\" -> \"" << help1 << "\"" << endl;
311  help0.ToUpper();
312  if(help0.Contains("MEDIA")){
313  geometryfiles.at(0) = help1;
314  }
315  if(help0.Contains("CAVE")){
316  geometryfiles.at(1) = help1;
317  }
318  if(help0.Contains("SOLENOID")){
319  geometryfiles.at(2) = help1;
320  }
321  if(help0.Contains("DIPOLE")){
322  geometryfiles.at(3) = help1;
323  }
324  if(help0.Contains("PIPE")){
325  geometryfiles.at(4) = help1;
326  }
327 
328  if(help0.Contains("STT")){
329  geometryfiles.at(5) = help1;
330  }
331  if(help0.Contains("MVD")){
332  geometryfiles.at(6) = help1;
333  }
334  if(help0.Contains("GEM")){
335  geometryfiles.at(7) = help1;
336  }
337  if(help0.Contains("SCITILE")){
338  geometryfiles.at(8) = help1;
339  }
340  if(help0.Contains("DRC")){
341  geometryfiles.at(9) = help1;
342  }
343 
344 
345  if(help0.Contains("DSK")){
346  geometryfiles.at(10) = help1;
347  }
348  if(help0.Contains("MUONBAR")){
349  geometryfiles.at(11) = help1;
350  }
351  if(help0.Contains("MUONENDC")){
352  geometryfiles.at(12) = help1;
353  }
354  if(help0.Contains("MUONFOR")){
355  geometryfiles.at(13) = help1;
356  }
357  if(help0.Contains("MUONFILT")){
358  geometryfiles.at(14) = help1;
359  }
360 
361  if(help0.Contains("FTS")){
362  geometryfiles.at(15) = help1;
363  }
364  if(help0.Contains("FTOF")){
365  geometryfiles.at(16) = help1;
366  }
367  if(help0.Contains("RICH")){
368  geometryfiles.at(17) = help1;
369  }
370  }
371  }
372  }
373  }
374 }
375 
PndDrc * Drc
Definition: sim_emc_apd.C:75
PndMultiField * fField
Definition: sim_emc_apd.C:97
void SetForward(TString name)
Definition: PndMdt.h:34
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
FairDetector * FTof
Definition: sim_ftof.C:49
void ReadFiles(string geomfile, std::vector< std::string > &geometryfiles)
Int_t i
Definition: run_full.C:25
PndDpmGenerator * dpmGen
void sim(TString output, Int_t nEvents, const char *TransportModel, std::vector< std::string > geometryfiles, UInt_t seed)
PndEmc * Emc
Definition: sim_emc_apd.C:55
void SetMdtCoil(bool opt=false)
Definition: PndMdt.h:28
FairDetector * Mvd
Definition: sim_emc_apd.C:51
void SetMdtMFIron(bool opt=false)
Definition: PndMdt.h:29
void SetStorageOfData(Bool_t val)
Definition: PndEmc.cxx:941
#define DEVURANDOM
FairParRootFileIo * output
Definition: sim_emc_apd.C:120
PndMdt * Muo
Definition: sim_emc_apd.C:67
Simulation of EMC.
Definition: PndEmc.h:26
FairPrimaryGenerator * primGen
Definition: sim_emc_apd.C:81
FairDetector * Dsk
Definition: run_DpmSim.C:66
FairRunAna * fRun
Definition: hit_dirc.C:58
FairDetector * Gem
Definition: runJohan.C:71
void SetMdtMagnet(bool opt=false)
Definition: PndMdt.h:27
void SetStoreTrackPoints(Bool_t storeTrackPoints)
Definition: PndDsk.h:148
FairDetector * Stt
Definition: sim_emc_apd.C:47
Double_t
void SetStoreCerenkovs(Bool_t storeCerenkovs)
Definition: PndDsk.h:146
FairModule * Dipole
Definition: sim_emc_apd.C:40
FairModule * Cave
Definition: sim_emc_apd.C:32
Definition: PndDrc.h:31
Int_t nEvents
Definition: hit_dirc.C:11
unsigned int seed
TStopwatch timer
Definition: hit_dirc.C:51
int main(int argc, char **argv)
virtual void SetGeometryVersion(const Int_t GeoNumber)
Definition: PndEmc.cxx:966
void SetBarrel(TString name)
Definition: PndMdt.h:31
gDebug
Definition: sim_emc_apd.C:6
const char * help_str()
TFile * out
Definition: reco_muo.C:20
Double_t ctime
Definition: hit_dirc.C:114
parInput1 open(parFile.Data())
out close()
void SetEndcap(TString name)
Definition: PndMdt.h:32
void SetMuonFilter(TString name)
Definition: PndMdt.h:33
GeV c P
void SetRunCherenkov(Bool_t ch)
Definition: PndDrc.h:222
Definition: PndStt.h:34
Definition: PndMdt.h:20
FairModule * Pipe
Definition: sim_emc_apd.C:44
Double_t rtime
Definition: hit_dirc.C:113
FairDetector * Fts
Definition: sim_ftof_stof.C:58
Definition: PndDsk.h:23
unsigned int GetRandomSeed()
FairModule * Magnet
Definition: sim_emc_apd.C:36
Definition: PndFts.h:25
Definition: PndCave.h:8