EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_EICDetector.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_EICDetector.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>
8 #include <G4_Bbc.C>
9 #include <G4_CaloTrigger.C>
11 #include <G4_FwdJets.C>
12 #include <G4_Global.C>
13 #include <G4_HIJetReco.C>
14 #include <G4_Input.C>
15 #include <G4_Jets.C>
16 #include <G4_Production.C>
17 #include <G4_User.C>
18 
19 #include <TROOT.h>
22 #include <fun4all/Fun4AllServer.h>
23 
24 #include <phool/recoConsts.h>
25 
26 R__LOAD_LIBRARY(libfun4all.so)
27 
29  const int nEvents = 1,
30  const string &inputFile = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
31  const string &outputFile = "G4EICDetector.root",
32  const string &embed_input_file = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
33  const int skip = 0,
34  const string &outdir = ".")
35 {
36  //---------------
37  // Fun4All server
38  //---------------
40  se->Verbosity(0);
41  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
42  //PHRandomSeed::Verbosity(1);
43 
44  // just if we set some flags somewhere in this macro
46  // By default every random number generator uses
47  // PHRandomSeed() which reads /dev/urandom to get its seed
48  // if the RANDOMSEED flag is set its value is taken as initial seed
49  // which will produce identical results so you can debug your code
50  // rc->set_IntFlag("RANDOMSEED", 12345);
51 
52  //===============
53  // Input options
54  //===============
55 
56  // Either:
57  // read previously generated g4-hits files, in this case it opens a DST and skips
58  // the simulations step completely. The G4Setup macro is only loaded to get information
59  // about the number of layers used for the cell reco code
60  //
61  //Input::READHITS = true;
62  INPUTREADHITS::filename[0] = inputFile;
63  // if you use a filelist
64  // INPUTREADHITS::listfile[0] = inputFile;
65 
66  // Or:
67  // Use one or more particle generators
68  // It is run if Input::<generator> is set to true
69  // all other options only play a role if it is active
70  // 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
71  // Input::EMBED = true;
72  INPUTEMBED::filename[0] = embed_input_file;
73  // if you use a filelist
74  //INPUTEMBED::listfile[0] = embed_input_file;
75 
76  // Use Pythia 8
77  // Input::PYTHIA8 = true;
78 
79  // Use Pythia 6
80  Input::PYTHIA6 = false;
81 
82  // Use Sartre
83  // Input::SARTRE = true;
84 
85  // Simple multi particle generator in eta/phi/pt ranges
86  Input::SIMPLE = true;
87  // Input::SIMPLE_NUMBER = 2; // if you need 2 of them
88  // Input::SIMPLE_VERBOSITY = 1;
89 
90  // Particle gun (same particles in always the same direction)
91  // Input::GUN = true;
92  // Input::GUN_NUMBER = 3; // if you need 3 of them
93  // Input::GUN_VERBOSITY = 0;
94 
95  // Upsilon generator
96  // Input::UPSILON = true;
97  // Input::UPSILON_NUMBER = 3; // if you need 3 of them
98  // Input::UPSILON_VERBOSITY = 0;
99 
100  // And/Or read generated particles from file
101 
102  // eic-smear output
103  // Input::READEIC = true;
104  INPUTREADEIC::filename = inputFile;
105 
106  // HepMC2 files
107  // Input::HEPMC = true;
108  Input::VERBOSITY = 0;
109  INPUTHEPMC::filename = inputFile;
110 
111  //-----------------
112  // Initialize the selected Input/Event generation
113  //-----------------
114  InputInit();
115  //--------------
116  // Set generator specific options
117  //--------------
118  // can only be set after InputInit() is called
119 
120  // Simple Input generator:
121  // if you run more than one of these Input::SIMPLE_NUMBER > 1
122  // add the settings for other with [1], next with [2]...
123  if (Input::SIMPLE)
124  {
125  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("e-", 1);
126  if (Input::HEPMC || Input::EMBED)
127  {
128  INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
129  INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
130  }
131  else
132  {
133  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Uniform,
136  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
137  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0., 0., 5.);
138  }
139  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-0.2, 0.2);
140  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
141  INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(10, 10.);
142  }
143  // Upsilons
144  // if you run more than one of these Input::UPSILON_NUMBER > 1
145  // add the settings for other with [1], next with [2]...
146  if (Input::UPSILON)
147  {
148  INPUTGENERATOR::VectorMesonGenerator[0]->add_decay_particles("mu", 0);
149  INPUTGENERATOR::VectorMesonGenerator[0]->set_rapidity_range(-1, 1);
150  INPUTGENERATOR::VectorMesonGenerator[0]->set_pt_range(0., 10.);
151  // Y species - select only one, last one wins
152  INPUTGENERATOR::VectorMesonGenerator[0]->set_upsilon_1s();
153  if (Input::HEPMC || Input::EMBED)
154  {
155  INPUTGENERATOR::VectorMesonGenerator[0]->set_reuse_existing_vertex(true);
156  INPUTGENERATOR::VectorMesonGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
157  }
158  }
159  // particle gun
160  // if you run more than one of these Input::GUN_NUMBER > 1
161  // add the settings for other with [1], next with [2]...
162  if (Input::GUN)
163  {
164  INPUTGENERATOR::Gun[0]->AddParticle("pi-", 0, 1, 0);
165  INPUTGENERATOR::Gun[0]->set_vtx(0, 0, 0);
166  }
167  // pythia6
168  if (Input::PYTHIA6)
169  {
170  INPUTGENERATOR::Pythia6->set_config_file(string(getenv("CALIBRATIONROOT")) + "/Generators/phpythia6_ep.cfg");
173  }
174  // pythia8
175  if (Input::PYTHIA8)
176  {
179  }
180  // Sartre
181  if (Input::SARTRE)
182  {
185  }
186 
187  //--------------
188  // Set Input Manager specific options
189  //--------------
190  // can only be set after InputInit() is called
191 
192  if (Input::HEPMC)
193  {
196  // optional overriding beam parameters
197  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 30, 0); //optional collision smear in space, time
198  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
199  // //optional choice of vertex distribution function in space, time
200  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_function(PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus);
205  //INPUTMANAGER::HepMCInputManager->set_embedding_id(2);
206  }
207 
208  // register all input generators with Fun4All
209  InputRegister();
210 
211  // Reads event generators in EIC smear files, which is registered in InputRegister
212  if (Input::READEIC)
213  {
216  }
217 
218  // set up production relatedstuff
219  // Enable::PRODUCTION = true;
220 
221  //======================
222  // Write the DST
223  //======================
224 
225  Enable::DSTOUT = false;
226  DstOut::OutputDir = outdir;
227  DstOut::OutputFile = outputFile;
228  Enable::DSTOUT_COMPRESS = false; // Compress DST files
229 
230  //Option to convert DST to human command readable TTree for quick poke around the outputs
231  // Enable::DSTREADER = true;
232 
233  // turn the display on (default off)
234  Enable::DISPLAY = false;
235 
236  //======================
237  // What to run
238  //======================
239  // Global options (enabled for all subsystems - if implemented)
240  // Enable::ABSORBER = true;
241  // Enable::OVERLAPCHECK = true;
242  // Enable::VERBOSITY = 1;
243 
244  // Enable::BBC = true;
245  Enable::BBCFAKE = true; // Smeared vtx and t0, use if you don't want real BBC in simulation
246 
247  // whether to simulate the Be section of the beam pipe
248  Enable::PIPE = true;
249  // EIC beam pipe extension beyond the Be-section:
251  //EIC hadron far forward magnets and detectors. IP6 and IP8 are incompatible (pick either or);
256 
257  // gems
258  Enable::EGEM = true;
259  Enable::FGEM = true;
260  Enable::FGEM_ORIG = false; //5 forward gems; cannot be used with FST
261  // barrel tracker
262  Enable::BARREL = false;
263  //G4BARREL::SETTING::BARRELV6=true;
264  // fst
265  Enable::FST = true;
267  // mvtx/tpc tracker
268  Enable::MVTX = true;
269  Enable::TPC = true;
270  // Enable::TPC_ENDCAP = true;
271 
272  Enable::TRACKING = true;
274  G4TRACKING::DISPLACED_VERTEX = true; // this option exclude vertex in the track fitting and use RAVE to reconstruct primary and 2ndary vertexes
275  // projections to calorimeters
280 
281  Enable::CEMC = true;
282  // Enable::CEMC_ABSORBER = true;
287 
288  Enable::BECAL = false;
291 
292  Enable::HCALIN = true;
293  // Enable::HCALIN_ABSORBER = true;
298 
299  Enable::MAGNET = true;
300 
301  Enable::HCALOUT = true;
302  // Enable::HCALOUT_ABSORBER = true;
307 
308  // EICDetector geometry - barrel
309  Enable::DIRC = true;
310 
311  // EICDetector geometry - 'hadron' direction
312  Enable::RICH = true;
313  Enable::AEROGEL = true;
314 
315  Enable::FEMC = true;
316  // Enable::FEMC_ABSORBER = true;
320 
321  Enable::FHCAL = true;
322  // Enable::FHCAL_ABSORBER = true; // make absorber active volume
323  // Enable::FHCAL_SUPPORT = true; // make support active volume
327 
328  // EICDetector geometry - 'electron' direction
329  Enable::EEMC = true;
333 
334  Enable::PLUGDOOR = false;
335 
336  // Other options
337  Enable::GLOBAL_RECO = true;
338  Enable::GLOBAL_FASTSIM = true;
339 
341 
342  // Select only one jet reconstruction- they currently use the same
343  // output collections on the node tree!
344  Enable::JETS = false;
346 
347  Enable::FWDJETS = false;
349 
350  // HI Jet Reco for jet simulations in Au+Au (default is false for
351  // single particle / p+p simulations, or for Au+Au simulations which
352  // don't care about jets)
354 
355  // new settings using Enable namespace in GlobalVariables.C
356  Enable::BLACKHOLE = true;
357  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
358  //BlackHoleGeometry::visible = true;
359 
360  //Enable::USER = true;
361 
362  //---------------
363  // World Settings
364  //---------------
365  // G4WORLD::PhysicsList = "FTFP_BERT"; //FTFP_BERT_HP best for calo
366  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
367 
368  //---------------
369  // Magnet Settings
370  //---------------
371 
372  // const string magfield = "1.4"; // 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)
373  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sphenix3dbigmapxyz.root"); // default map from the calibration database
374  G4MAGNET::magfield_rescale = 1.; // in case you want to play with field
375 
376  //---------------
377  // Pythia Decayer
378  //---------------
379  // list of decay types in
380  // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
381  // default is All:
382  // G4P6DECAYER::decayType = EDecayType::kAll;
383 
384  // Initialize the selected subsystems
385  G4Init();
386 
387  //---------------------
388  // GEANT4 Detector description
389  //---------------------
390 
391  // 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
392  if (!Input::READHITS)
393  {
394  G4Setup();
395  }
396 
397  //------------------
398  // Detector Division
399  //------------------
400 
402 
404 
406 
408 
409  //-----------------------------
410  // CEMC towering and clustering
411  //-----------------------------
412 
415 
416  //-----------------------------
417  // BECAL towering and clustering
418  //-----------------------------
419 
422 
423  //-----------------------------
424  // HCAL towering and clustering
425  //-----------------------------
426 
429 
430  if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
432 
433  //-----------------------------
434  // e, h direction Calorimeter towering and clustering
435  //-----------------------------
436 
439 
442 
445 
447 
448  //--------------
449  // SVTX tracking
450  //--------------
451 
453 
454  //-----------------
455  // Global Vertexing
456  //-----------------
457 
459  {
460  Global_Reco();
461  }
462  else if (Enable::GLOBAL_FASTSIM)
463  {
464  Global_FastSim();
465  }
466 
467  //-----------------
468  // Calo Trigger Simulation
469  //-----------------
470 
472 
473  //---------
474  // Jet reco
475  //---------
476 
477  if (Enable::JETS) Jet_Reco();
478 
479  if (Enable::HIJETS) HIJetReco();
480 
482 
483  string outputroot = outputFile;
484  string remove_this = ".root";
485  size_t pos = outputroot.find(remove_this);
486  if (pos != string::npos)
487  {
488  outputroot.erase(pos, remove_this.length());
489  }
490 
491  if (Enable::DSTREADER) G4DSTreader_EICDetector(outputroot + "_DSTReader.root");
492 
493  //----------------------
494  // Simulation evaluation
495  //----------------------
496  if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "_g4tracking_eval.root");
497 
498  if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
499 
500  if (Enable::BECAL_EVAL) BECAL_Eval(outputroot + "_g4becal_eval.root");
501 
502  if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
503 
504  if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
505 
506  if (Enable::FEMC_EVAL) FEMC_Eval(outputroot + "_g4femc_eval.root");
507 
508  if (Enable::FHCAL_EVAL) FHCAL_Eval(outputroot + "_g4fhcal_eval.root");
509 
510  if (Enable::EEMC_EVAL) EEMC_Eval(outputroot + "_g4eemc_eval.root");
511 
512  if (Enable::JETS_EVAL) Jet_Eval(outputroot + "_g4jet_eval.root");
513 
514  if (Enable::FWDJETS_EVAL) Jet_FwdEval(outputroot + "_g4fwdjet_eval.root");
515 
517 
518  //--------------
519  // Set up Input Managers
520  //--------------
521 
522  InputManagers();
523 
524  //--------------
525  // Set up Output Manager
526  //--------------
527  if (Enable::PRODUCTION)
528  {
530  }
531 
532  if (Enable::DSTOUT)
533  {
534  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
535  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
537  se->registerOutputManager(out);
538  }
539 
540  //-----------------
541  // Event processing
542  //-----------------
543  if (Enable::DISPLAY)
544  {
545  DisplayOn();
546 
547  gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
548  gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
549 
550  cout << "-------------------------------------------------" << endl;
551  cout << "You are in event display mode. Run one event with" << endl;
552  cout << "se->run(1)" << endl;
553  cout << "Run Geant4 command with following examples" << endl;
554  gROOT->ProcessLine("displaycmd()");
555 
556  return 0;
557  }
558  // if we use a negative number of events we go back to the command line here
559  if (nEvents < 0)
560  {
561  return 0;
562  }
563  // if we run any of the particle generators and use 0 it'll run forever
564  if (nEvents == 0 && !Input::READHITS && !Input::HEPMC && !Input::READEIC)
565  {
566  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
567  cout << "it will run forever, so I just return without running anything" << endl;
568  return 0;
569  }
570 
571  se->skip(skip);
572  se->run(nEvents);
573 
574  //-----
575  // Exit
576  //-----
577 
578  se->End();
579  std::cout << "All done" << std::endl;
580  delete se;
581  if (Enable::PRODUCTION)
582  {
584  }
585  gSystem->Exit(0);
586  return 0;
587 }
588 #endif