ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_ECCEModular.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_ECCEModular.C
1 #ifndef MACRO_FUN4ALLG4EICDETECTOR_C
2 #define MACRO_FUN4ALLG4EICDETECTOR_C
3 
4 #include <GlobalVariables.C>
5 
6 #include <DisplayOn.C>
7 #include <G4Setup_EICDetector.C>
9 #include <G4_EventEvaluator.C>
10 #include <G4_FwdJets.C>
11 #include <G4_Global.C>
12 #include <G4_Input.C>
13 #include <G4_Production.C>
14 #include <G4_User.C>
15 
16 #include <TROOT.h>
19 #include <fun4all/Fun4AllServer.h>
20 
21 #include <phool/recoConsts.h>
22 
23 #include <RooUnblindPrecision.h>
24 
25 R__LOAD_LIBRARY(libfun4all.so)
26 
28  const int nEvents = 1,
29  const double particlemomMin = -1,
30  const double particlemomMax = -1,
31  const string detectorSettings = "TTLGEO_5",
32  const TString generatorSettings = "PYTHIA8",
33  const string &inputFile = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
34  const string &outputFile = "G4EICDetector.root",
35  const string &embed_input_file = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
36  const int skip = 0,
37  const string &outdir = ".")
38 {
39  //---------------
40  // Fun4All server
41  //---------------
43  se->Verbosity(0);
44  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
45  //PHRandomSeed::Verbosity(1);
46 
47  // just if we set some flags somewhere in this macro
49  // By default every random number generator uses
50  // PHRandomSeed() which reads /dev/urandom to get its seed
51  // if the RANDOMSEED flag is set its value is taken as initial seed
52  // which will produce identical results so you can debug your code
53  // rc->set_IntFlag("RANDOMSEED", 12345);
54 
55  bool generate_seed = false;
56 
57  if (generate_seed)
58  {
59  size_t findSlash = inputFile.find_last_of("/");
60  string inputFileName = inputFile.substr(findSlash + 1, inputFile.size());
61 
62  RooRealVar dummyVal("dummy", "", 0);
63  RooUnblindPrecision blindVal("blindVal", "blindVal", inputFileName.c_str(), nEvents, skip + 1, dummyVal, kFALSE);
64  rc->set_IntFlag("RANDOMSEED", abs(ceil(blindVal.getVal() * 1e2)));
65  }
66 
67  //===============
68  // Input options
69  //===============
70 
71  // switching IPs by comment/uncommenting the following lines
72  // used for both beamline setting and for the event generator crossing boost
73  Enable::IP6 = true;
74  // Enable::IP8 = true;
75 
76  // Setting proton beam pipe energy. If you don't know what to set here, leave it at 275
78 
79  // Either:
80  // read previously generated g4-hits files, in this case it opens a DST and skips
81  // the simulations step completely. The G4Setup macro is only loaded to get information
82  // about the number of layers used for the cell reco code
83  //
84  //Input::READHITS = true;
85  INPUTREADHITS::filename[0] = inputFile;
86  // if you use a filelist
87  // INPUTREADHITS::listfile[0] = inputFile;
88 
89  // Or:
90  // Use one or more particle generators
91  // It is run if Input::<generator> is set to true
92  // all other options only play a role if it is active
93  // In case embedding into a production output, please double check your G4Setup_EICDetector.C and G4_*.C consistent with those in the production macro folder
94  // Input::EMBED = true;
95  INPUTEMBED::filename[0] = embed_input_file;
96  // if you use a filelist
97  //INPUTEMBED::listfile[0] = embed_input_file;
98 
99  if(particlemomMin==-1 && particlemomMax==-1){
100  if (generatorSettings.Contains("PYTHIA6")) {
101  Input::PYTHIA6 = true;
102  } else if (generatorSettings.Contains("PYTHIA8")) {
103  Input::PYTHIA8 = true;
104  } else if (generatorSettings.Contains("SATRE")) {
105  Input::SARTRE = true;
106  } else if (generatorSettings.Contains("READEIC")) {
107  Input::READEIC = true;
108  } else if (generatorSettings.Contains("HEPMCINPUT")) {
109  Input::HEPMC = true;
110  INPUTHEPMC::filename = inputFile;
111  }
112  }
113  // Simple multi particle generator in eta/phi/pt ranges
114  Input::SIMPLE = false;
115  if (particlemomMin>-1 && particlemomMax>-1){
116  Input::SIMPLE = true;
118  if (generatorSettings.Contains("Multi"))
119  Input::SIMPLE_NUMBER = 3; // if you need 2 of them
120  }
121 
122  Input::VERBOSITY = 0;
123 
124  //-----------------
125  // Initialize the selected Input/Event generation
126  //-----------------
127  InputInit();
128  //--------------
129  // Set generator specific options
130  //--------------
131  // can only be set after InputInit() is called
132 
133  // Simple Input generator:
134  // if you run more than one of these Input::SIMPLE_NUMBER > 1
135  // add the settings for other with [1], next with [2]...
136  if (Input::SIMPLE){
137  if (generatorSettings.Contains("Multi")){
138  for(int igen=0;igen<Input::SIMPLE_NUMBER;igen++){
139  if (generatorSettings.Contains("PiPrEl")){
140  if(igen==0)INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("pi-", 1);
141  else if(igen==1)INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("e-", 1);
142  else if(igen==2)INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("proton", 1);
143  }else if (generatorSettings.Contains("Pion"))
144  INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("pi-", 1);
145  else if (generatorSettings.Contains("Kaon"))
146  INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("kaon-", 1);
147  else if (generatorSettings.Contains("Proton"))
148  INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("proton", 1);
149  else if (generatorSettings.Contains("Muon"))
150  INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("mu-", 1);
151  else if (generatorSettings.Contains("Photon"))
152  INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("gamma", 1);
153  else if (generatorSettings.Contains("Neutron"))
154  INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("neutron", 1);
155  else if (generatorSettings.Contains("Lambda"))
156  INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("lambda", 1);
157  else if (generatorSettings.Contains("K0S"))
158  INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("kaon0S", 1);
159  else if (generatorSettings.Contains("Electron"))
160  INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("e-", 1);
161  else if (generatorSettings.Contains("PiZero"))
162  INPUTGENERATOR::SimpleEventGenerator[igen]->add_particles("pi0", 1);
163  else {
164  std::cout << "You didn't specify which particle you wanted to generate, exiting" << std::endl;
165  return 0;
166  }
167  INPUTGENERATOR::SimpleEventGenerator[igen]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Uniform,
170  INPUTGENERATOR::SimpleEventGenerator[igen]->set_vertex_distribution_mean(0., 0., 0.);
171  INPUTGENERATOR::SimpleEventGenerator[igen]->set_vertex_distribution_width(0., 0., 0.);
172 
173  bool strictrange = false;
174  if(generatorSettings.Contains("strict")) strictrange = true;
175  if (igen==0){
176  if(strictrange)
177  INPUTGENERATOR::SimpleEventGenerator[igen]->set_eta_range(-0.7, 0.7);
178  else
179  INPUTGENERATOR::SimpleEventGenerator[igen]->set_eta_range(-1.7, 1.2);
180  } else if (igen==1) {
181  if(strictrange)
182  INPUTGENERATOR::SimpleEventGenerator[igen]->set_eta_range(-3.0, -2.5);
183  else
184  INPUTGENERATOR::SimpleEventGenerator[igen]->set_eta_range(-4, -1.7);
185  } else if (igen==2) {
186  if(strictrange)
187  INPUTGENERATOR::SimpleEventGenerator[igen]->set_eta_range(2.5, 3.0);
188  else
189  INPUTGENERATOR::SimpleEventGenerator[igen]->set_eta_range(1.2, 4.0);
190  } else {
191  INPUTGENERATOR::SimpleEventGenerator[igen]->set_eta_range(-4.0, 4.0);
192  }
193  INPUTGENERATOR::SimpleEventGenerator[igen]->set_phi_range(-M_PI, M_PI);
194  INPUTGENERATOR::SimpleEventGenerator[igen]->set_p_range(particlemomMin, particlemomMax);
195  }
196  } else {
197  if (generatorSettings.Contains("SimplePion"))
198  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi-", 1);
199  else if (generatorSettings.Contains("SimpleKaon"))
200  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("kaon-", 1);
201  else if (generatorSettings.Contains("SimpleProton"))
202  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("proton", 1);
203  else if (generatorSettings.Contains("SimplePhoton"))
204  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("gamma", 1);
205  else if (generatorSettings.Contains("SimpleNeutron"))
206  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("neutron", 1);
207  else if (generatorSettings.Contains("SimpleMuon"))
208  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("mu-", 1);
209  else if (generatorSettings.Contains("SimpleLambda"))
210  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("lambda", 1);
211  else if (generatorSettings.Contains("SimpleK0S"))
212  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("kaon0S", 1);
213  else if (generatorSettings.Contains("SimpleElectron"))
214  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("e-", 1);
215  else if (generatorSettings.Contains("SimplePiZero"))
216  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi0", 1);
217  else {
218  std::cout << "You didn't specify which particle you wanted to generate, exiting" << std::endl;
219  return 0;
220  }
221  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Uniform,
224  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
225  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0., 0., 0.);
226  if (generatorSettings.Contains("central"))
227  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-1.8, 1.2);
228  else if (generatorSettings.Contains("bck"))
229  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-4, -1.7);
230  else if (generatorSettings.Contains("fwd"))
231  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(1.2, 4.0);
232  else
233  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-4.0, 4.0);
234  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
235  INPUTGENERATOR::SimpleEventGenerator[0]->set_p_range(particlemomMin, particlemomMax);
236  }
237  }
238  if(particlemomMin>-1 && particlemomMax == -1){
239  PHG4ParticleGenerator *gen = new PHG4ParticleGenerator("PGENERATOR");
240  gen->set_name("pi-");
241  // gen->set_name("pi0");
242  gen->set_vtx(0, 0, 0);
243  gen->set_eta_range(-4.0, 4.0); // around midrapidity
244  if(particlemomMin > -1) {
245  gen->set_mom_range(particlemomMin, particlemomMin); // fixed 4 GeV/c
246  }
247  else {
248  gen->set_mom_range(1, 60); // fixed 4 GeV/c
249  }
250  gen->set_phi_range(0., 2* M_PI); // 0-90 deg
251  // gen->Verbosity(1); // 0-90 deg
252  se->registerSubsystem(gen);
253  }
254  // pythia6
255  if (Input::PYTHIA6)
256  {
257  //INPUTGENERATOR::Pythia6->set_config_file(string(getenv("CALIBRATIONROOT")) + "/Generators/phpythia6_ep.cfg");
261  }
262  // pythia8
263  if (Input::PYTHIA8)
264  {
265  // Configuration file
266  PYTHIA8::config_file = inputFile;
269  }
270  // Sartre
271  if (Input::SARTRE)
272  {
275  }
276 
277  //--------------
278  // Set Input Manager specific options
279  //--------------
280  // can only be set after InputInit() is called
281 
282  if (Input::HEPMC)
283  {
286  // optional overriding beam parameters
287  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 30, 0); //optional collision smear in space, time
288  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
289  // //optional choice of vertex distribution function in space, time
290  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_function(PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus);
295  //INPUTMANAGER::HepMCInputManager->set_embedding_id(2);
296  }
297 
298  // register all input generators with Fun4All
299  InputRegister();
300 
301  // Reads event generators in EIC smear files, which is registered in InputRegister
302  if (Input::READEIC)
303  {
304  INPUTREADEIC::filename = inputFile;
308  }
309 
310  // set up production relatedstuff
311  // Enable::PRODUCTION = true;
312 
313  //======================
314  // Write the DST
315  //======================
316 
317  Enable::DSTOUT = false;
318  DstOut::OutputDir = outdir;
319  DstOut::OutputFile = outputFile;
320  Enable::DSTOUT_COMPRESS = false; // Compress DST files
321 
322  //Option to convert DST to human command readable TTree for quick poke around the outputs
323  // Enable::DSTREADER = true;
324 
325  // turn the display on (default off)
326  if (detectorSettings.find("display") != std::string::npos) {
327  Enable::DISPLAY = true;
328  }
329  //======================
330  // What to run
331  //======================
332  // Global options (enabled for all subsystems - if implemented)
333  // Enable::ABSORBER = true;
334  // Enable::OVERLAPCHECK = true;
335  // Enable::VERBOSITY = 1;
336 
337  // whether to simulate the Be section of the beam pipe
338  Enable::PIPE = true;
339  // If need to disable EIC beam pipe extension beyond the Be-section:
341  //EIC hadron far forward magnets and detectors. IP6 and IP8 are incompatible (pick either or);
342  // Enable::HFARFWD_MAGNETS = true;
343  // Enable::HFARFWD_VIRTUAL_DETECTORS = true;
344 
345  // Enable::HFARBWD_MAGNETS = true;
346  // Enable::HFARBWD_VIRTUAL_DETECTORS = true;
347 
348  //***********************************************
349  // barrel trackers
350  //***********************************************
351  Enable::RWELL = true;
352  // barrel tracker
354  // Enable::TrackingService_VERBOSITY = INT_MAX - 10;
355  Enable::BARREL = true;
356  // fst
357  Enable::FST = true;
358 
359  //***********************************************
360  // TOFs
361  //***********************************************
362  Enable::FTTL = true;
363  Enable::ETTL = true;
364  Enable::CTTL = true;
366  std::string ttlSettingToFind = "TTLGEO_";
367  if (detectorSettings.find(ttlSettingToFind) != std::string::npos) {
368  auto pos = detectorSettings.find(ttlSettingToFind);
369  G4TTL::SETTING::optionGeo = std::stoi(detectorSettings.substr(pos + ttlSettingToFind.size(), pos + ttlSettingToFind.size() + 1));
370  } else {
372  }
373 
374  //***********************************************
375  // gems fwd & bwd
376  //***********************************************
377  Enable::EGEM = false;
378  Enable::FGEM = false;
379 
380  //***********************************************
381  // tracking macro settings
382  //***********************************************
383  Enable::TRACKING = true;
385  G4TRACKING::DISPLACED_VERTEX = true; // this option exclude vertex in the track fitting and use RAVE to reconstruct primary and 2ndary vertexes
386  // projections to calorimeters
396 
397  //***********************************************
398  // barrel calos & magnet
399  //***********************************************
400  Enable::BECAL = true;
401  Enable::HCALIN = true;
402  Enable::MAGNET = true;
403  Enable::HCALOUT = true;
404 
405  //***********************************************
406  // cherenkov's
407  //***********************************************
408  Enable::DIRC = true;
409  Enable::RICH = true;
410  Enable::mRICH = true;
411 
412  //***********************************************
413  // fwd calos
414  //***********************************************
415  Enable::FEMC = true;
416  Enable::DRCALO = false;
418  Enable::LFHCAL = true;
419 
420  //***********************************************
421  // bwd calos
422  //***********************************************
423  Enable::EEMCH = true;
424  if (detectorSettings.find("EEMAPNC") != std::string::npos) {
426  }
427  if (detectorSettings.find("EEMAP30CM") != std::string::npos) {
429  }
430  if (detectorSettings.find("EEMAPCARBON") != std::string::npos) {
432  }
433  if (detectorSettings.find("EEMAPUPDATE") != std::string::npos) {
435  }
436  Enable::EHCAL = false;
437  Enable::PLUGDOOR = true;
438 
439  // Other options
440  Enable::GLOBAL_RECO = G4TRACKING::DISPLACED_VERTEX; // use reco vertex for global event vertex
441  Enable::GLOBAL_FASTSIM = true;
442 
443  // jet reconstruction
444  Enable::FWDJETS = false;
446 
447  // new settings using Enable namespace in GlobalVariables.C
448  Enable::BLACKHOLE = true;
449  bool BLACKHOLE_SAVEHITS = false;
450  if(detectorSettings.find("BHH")!= std::string::npos ){
451  Enable::BLACKHOLE_SAVEHITS = true; // turn off saving of bh hits
452  Enable::EVENT_EVAL_DO_HITS_BLACKHOLE = true; // turn off saving of bh hits
453  }
454  // BlackHoleGeometry::visible = true;
455 
456  // ZDC
457  // Enable::ZDC = true;
458  // Enable::ZDC_DISABLE_BLACKHOLE = true;
459 
460  // B0
461  // Enable::B0_DISABLE_HITPLANE = true;
462  // Enable::B0_FULLHITPLANE = true;
463 
464  // Enable::B0ECALTOWERS = true; //To Construct Towers of B0ECal instead of one single volume
465  // Enable::B0ECAL = Enable::B0_DISABLE_HITPLANE && true;
466  // Enable::B0ECAL_CELL = Enable::B0ECAL && true;
467  // Enable::B0ECAL_TOWER = Enable::B0ECAL_CELL && true;
468  // Enable::B0ECAL_CLUSTER = Enable::B0ECAL_TOWER && true;
469  // Enable::B0ECAL_EVAL = Enable::B0ECAL_CLUSTER && true;
470 
471  // RP
472  // Enable::RP_DISABLE_HITPLANE = true;
473  // Enable::RP_FULLHITPLANE = true;
474 
475  // RP after 2nd focus for IP8 only
476  // Enable::RP2nd_DISABLE_HITPLANE = true;
477  // Enable::RP2nd_FULLHITPLANE = true;
478 
479  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
480  // special settings for Calo standalone studies
481  // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
482  // deactivate all respective detector systems for standalone studies
483  if(detectorSettings.find("STANDALONE")!= std::string::npos){
484  Enable::PIPE = false;
486  Enable::HFARFWD_MAGNETS = false;
488  // Enable::TPC_ENDCAP = false;
489  // G4TRACKING::PROJECTION_CEMC = false;
490  // G4TRACKING::PROJECTION_FEMC = false;
491  // G4TRACKING::PROJECTION_FHCAL = false;
492  // G4TRACKING::PROJECTION_EHCAL = false;
493  // G4TRACKING::PROJECTION_DRCALO = false;
494  // G4TRACKING::PROJECTION_EEMC = false;
495  Enable::MAGNET = false;
496  Enable::DIRC = false;
497  Enable::RICH = false;
498  Enable::mRICH = false;
499  // Enable::AEROGEL = false;
500  Enable::CEMC = false;
501  Enable::HCALOUT = false;
502  Enable::HCALIN = false;
503  Enable::EHCAL = false;
504  Enable::EEMC = false;
505  Enable::EEMCH = false;
506  Enable::FEMC = false;
507  Enable::FHCAL = false;
508  Enable::LFHCAL = false;
509  Enable::BECAL = false;
510  Enable::FTTL = false;
511  Enable::CTTL = false;
512  Enable::ETTL = false;
513  Enable::EEMCH = false;
514  Enable::RWELL = false;
515  Enable::TrackingService = false;
516  Enable::BARREL = false;
517  Enable::FST = false;
518  Enable::EGEM = false;
519  Enable::FGEM = false;
520  if(detectorSettings.find("PIPE")!= std::string::npos ){
521  Enable::PIPE = true;
523  }
524  if(detectorSettings.find("Magnet")!= std::string::npos )
525  Enable::MAGNET = true;
526  if(detectorSettings.find("dRICH")!= std::string::npos )
527  Enable::RICH = true;
528  // if(detectorSettings.find("ALLSILICON")!= std::string::npos )
529  // Enable::ALLSILICON = true;
530  if(detectorSettings.find("CEMC")!= std::string::npos )
531  Enable::CEMC = true;
532  if(detectorSettings.find("HCALOUT")!= std::string::npos ){
533  Enable::HCALOUT = true;
534  }
535  if(detectorSettings.find("HCALIN")!= std::string::npos ){
536  Enable::HCALIN = true;
537  }
538  if(detectorSettings.find("HCALINOUT")!= std::string::npos ){
539  Enable::HCALOUT = true;
540  Enable::HCALIN = true;
541  }
542  if(detectorSettings.find("DR")!= std::string::npos )
543  Enable::DRCALO = true;
544  if(detectorSettings.find("FEMC")!= std::string::npos )
545  Enable::FEMC = true;
546  if(detectorSettings.find("FGEM")!= std::string::npos )
547  Enable::FGEM = true;
548  if((detectorSettings.find("FHCAL")!= std::string::npos) && !(detectorSettings.find("LFHCAL")!= std::string::npos) )
549  Enable::FHCAL = true;
550  if(detectorSettings.find("LFHCAL")!= std::string::npos )
551  Enable::LFHCAL = true;
552  if(detectorSettings.find("BECAL")!= std::string::npos )
553  Enable::BECAL = true;
554  if(detectorSettings.find("EHCAL")!= std::string::npos )
555  Enable::EHCAL = true;
556  if(detectorSettings.find("EEMCH")!= std::string::npos )
557  Enable::EEMCH = true;
558  if(detectorSettings.find("RWELL")!= std::string::npos )
559  Enable::RWELL = true;
560  if(detectorSettings.find("CHCAL")!= std::string::npos ){
561  Enable::HCALIN = true;
562  Enable::HCALOUT = true;
563  }
564  if(detectorSettings.find("DIRC")!= std::string::npos )
565  Enable::DIRC = true;
566  if(detectorSettings.find("SUPPORT")!= std::string::npos ){
569  }
570  if(detectorSettings.find("FWDCALO")!= std::string::npos ){
571  Enable::FEMC = true;
572  Enable::FHCAL = true;
573  }
574  if(detectorSettings.find("FWDLCALO")!= std::string::npos ){
575  Enable::FEMC = true;
576  Enable::LFHCAL = true;
577  }
578  if(detectorSettings.find("BARCALO")!= std::string::npos ){
579  Enable::BECAL = true;
580  Enable::HCALIN = true;
581  Enable::HCALOUT = true;
582  Enable::MAGNET = true;
583  }
584  if(detectorSettings.find("BCKCALO")!= std::string::npos ){
585  Enable::EHCAL = true;
586  Enable::EEMCH = true;
587  }
588  if(detectorSettings.find("TTL")!= std::string::npos ){
589  // Enable::PIPE = true;
590  // G4PIPE::use_forward_pipes = true;
591  // LGAD layers
592  if(detectorSettings.find("FTTL")!= std::string::npos )
593  Enable::FTTL = true;
594  if(detectorSettings.find("ETTL")!= std::string::npos ){
595  Enable::ETTL = true;
596  // G4DIRC::SETTING::USECEMCGeo = false;
598  }
599  if(detectorSettings.find("CTTL")!= std::string::npos ){
600  Enable::CTTL = true;
601  // Enable::DIRC = true;
602  // Enable::CEMC = true;
603  // Enable::BECAL = true;
604  // Enable::ALLSILICON = true;
605  // G4DIRC::SETTING::USECEMCGeo = false;
607  }
608  }
609  }
610 
611  //************************************************************
612  // details for calos: cells, towers, clusters
613  //************************************************************
618 
623 
628 
632 
636 
641 
642  Enable::LFHCAL_ABSORBER = false;
647 
652 
657 
659 
660  // Enabling the event evaluator?
661  Enable::EVENT_EVAL = true;
662  if (detectorSettings.find("HITS") != std::string::npos) {
664  if (detectorSettings.find("HITSABS") != std::string::npos) {
666  }
667  if (detectorSettings.find("HITSC") != std::string::npos) {
669  }
670  }
673  // EVENT_EVALUATOR::Verbosity = 1;
674 
675  //Enable::USER = true;
676 
677  //---------------
678  // World Settings
679  //---------------
680  // G4WORLD::PhysicsList = "FTFP_BERT"; //FTFP_BERT_HP best for calo
681  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
682  // G4WORLD::WorldMaterial = "G4_Galactic"; // set to G4_GALACTIC for material scans
683  // ---------------
684  // Magnet Settings
685  //---------------
686  if (detectorSettings.find("NOFIELD") != std::string::npos) {
687  const string magfield = "0.0"; // alternatively to specify a constant magnetic field, give a float number, which will be translated to solenoidal field in T, if string use as fieldmap name (including path)
689  G4WORLD::WorldMaterial = "G4_Galactic"; // set to G4_GALACTIC for material scans
690  } else {
691  // const string magfield = "1.5"; // alternatively to specify a constant magnetic field, give a float number, which will be translated to solenoidal field in T, if string use as fieldmap name (including path)
692  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sPHENIX.2d.root"); // default map from the calibration database
693  G4MAGNET::magfield_rescale = -1.4 / 1.5; // make consistent with expected Babar field strength of 1.4T
694  }
695  //---------------
696  // Pythia Decayer
697  //---------------
698  // list of decay types in
699  // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
700  // default is All:
701  // G4P6DECAYER::decayType = EDecayType::kAll;
702 
703  // Initialize the selected subsystems
704  G4Init();
705 
706  //---------------------
707  // GEANT4 Detector description
708  //---------------------
709 
710  // If "readhepMC" is also set, the Upsilons will be embedded in Hijing events, if 'particles" is set, the Upsilons will be embedded in whatever particles are thrown
711  if (!Input::READHITS)
712  {
713  G4Setup();
714  }
715 
716  //------------------
717  // Detector Division
718  //------------------
722 
723  //-----------------------------
724  // CEMC towering and clustering
725  //-----------------------------
726 
729 
730  //-----------------------------
731  // HCAL towering and clustering
732  //-----------------------------
733 
736 
739 
740  //-----------------------------
741  // e, h direction Calorimeter towering and clustering
742  //-----------------------------
743 
746 
749 
752 
755 
758 
761 
764 
767 
769 
770  //--------------
771  // Tracking and PID
772  //--------------
773 
775 
777 
779 
781 
782  //-----------------
783  // Global Vertexing
784  //-----------------
785 
787  {
788  Global_Reco();
789  }
790  else if (Enable::GLOBAL_FASTSIM)
791  {
792  Global_FastSim();
793  }
794 
795  //---------
796  // Jet reco
797  //---------
798 
800 
801  string outputroot = outdir + "/" + outputFile;
802  string remove_this = ".root";
803  size_t pos = outputroot.find(remove_this);
804  if (pos != string::npos)
805  {
806  outputroot.erase(pos, remove_this.length());
807  }
808 
809  if (Enable::DSTREADER) G4DSTreader_EICDetector(outputroot + "_DSTReader.root");
810 
811  //----------------------
812  // Simulation evaluation
813  //----------------------
814 
815  if (Enable::EVENT_EVAL) Event_Eval(outputroot + "_eventtree.root");
816 
817  if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "_g4tracking_eval.root");
818 
819  if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
820 
821  if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
822 
823  if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
824 
825  if (Enable::FEMC_EVAL) FEMC_Eval(outputroot + "_g4femc_eval.root");
826 
827  if (Enable::FHCAL_EVAL) FHCAL_Eval(outputroot + "_g4fhcal_eval.root");
828 
829  if (Enable::EEMC_EVAL) EEMC_Eval(outputroot + "_g4eemc_eval.root");
830 
831  if (Enable::FFR_EVAL) FFR_Eval(outputroot + "_g4ffr_eval.root");
832 
833  if (Enable::FWDJETS_EVAL) Jet_FwdEval(outputroot);
834 
836 
837 
838  //--------------
839  // Set up Input Managers
840  //--------------
841 
842  InputManagers();
843 
844  //--------------
845  // Set up Output Manager
846  //--------------
847  if (Enable::PRODUCTION)
848  {
850  }
851 
852  if (Enable::DSTOUT)
853  {
854  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
855  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
857  se->registerOutputManager(out);
858  }
859 
860  //-----------------
861  // Event processing
862  //-----------------
863  if (Enable::DISPLAY)
864  {
865  if (detectorSettings.find("viewer") != std::string::npos){
866  gROOT->ProcessLine("PHG4Reco *g4 = QTGui();"); // alternative to DisplayOn
867  } else {
868  DisplayOn();
869  gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
870  gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
871  }
872  cout << "-------------------------------------------------" << endl;
873  cout << "You are in event display mode. Run one event with" << endl;
874  cout << "se->run(1)" << endl;
875  cout << "Run Geant4 command with following examples" << endl;
876  gROOT->ProcessLine("displaycmd()");
877 
878  return 0;
879  }
880  // if we use a negative number of events we go back to the command line here
881  if (nEvents < 0)
882  {
883  return 0;
884  }
885  // if we run any of the particle generators and use 0 it'll run forever
886  if (nEvents == 0 && !Input::READHITS && !Input::HEPMC && !Input::READEIC)
887  {
888  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
889  cout << "it will run forever, so I just return without running anything" << endl;
890  return 0;
891  }
892 
893  se->skip(skip);
894  se->run(nEvents);
895 
896  //-----
897  // Exit
898  //-----
899 
900  se->End();
901  std::cout << "All done" << std::endl;
902  delete se;
903  if (Enable::PRODUCTION)
904  {
906  }
907  gSystem->Exit(0);
908  return 0;
909 }
910 #endif