ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_EICDetector_AnaTutorial.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_EICDetector_AnaTutorial.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 <anatutorialecce/AnaTutorialECCE.h>
17 
18 #include <TROOT.h>
21 #include <fun4all/Fun4AllServer.h>
22 
23 #include <phool/recoConsts.h>
24 
25 #include <RooUnblindPrecision.h>
26 
27 R__LOAD_LIBRARY(libfun4all.so)
28 R__LOAD_LIBRARY(libanatutorialecce.so)
29 
31  const int nEvents = 1,
32  const string &inputFile = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
33  const string &outputFile = "G4EICDetector.root",
34  const string &embed_input_file = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
35  const int skip = 0,
36  const string &outdir = ".")
37 {
38  //---------------
39  // Fun4All server
40  //---------------
42  se->Verbosity(0);
43  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
44  //PHRandomSeed::Verbosity(1);
45 
46  // just if we set some flags somewhere in this macro
48  // By default every random number generator uses
49  // PHRandomSeed() which reads /dev/urandom to get its seed
50  // if the RANDOMSEED flag is set its value is taken as initial seed
51  // which will produce identical results so you can debug your code
52  // rc->set_IntFlag("RANDOMSEED", 12345);
53 
54  bool generate_seed = false;
55 
56  if (generate_seed)
57  {
58  size_t findSlash = inputFile.find_last_of("/");
59  string inputFileName = inputFile.substr(findSlash + 1, inputFile.size());
60 
61  RooRealVar dummyVal("dummy", "", 0);
62  RooUnblindPrecision blindVal("blindVal", "blindVal", inputFileName.c_str(), nEvents, skip + 1, dummyVal, kFALSE);
63  rc->set_IntFlag("RANDOMSEED", abs(ceil(blindVal.getVal() * 1e2)));
64  }
65 
66  //===============
67  // Input options
68  //===============
69 
70  // switching IPs by comment/uncommenting the following lines
71  // used for both beamline setting and for the event generator crossing boost
72  Enable::IP6 = true;
73  // Enable::IP8 = true;
74 
75  // Setting proton beam pipe energy. If you don't know what to set here, leave it at 275
77 
78  // Either:
79  // read previously generated g4-hits files, in this case it opens a DST and skips
80  // the simulations step completely. The G4Setup macro is only loaded to get information
81  // about the number of layers used for the cell reco code
82  //
83  //Input::READHITS = true;
84  INPUTREADHITS::filename[0] = inputFile;
85  // if you use a filelist
86  // INPUTREADHITS::listfile[0] = inputFile;
87 
88  // Or:
89  // Use one or more particle generators
90  // It is run if Input::<generator> is set to true
91  // all other options only play a role if it is active
92  // 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
93  // Input::EMBED = true;
94  INPUTEMBED::filename[0] = embed_input_file;
95  // if you use a filelist
96  //INPUTEMBED::listfile[0] = embed_input_file;
97 
98  // Use Pythia 8
99  // Input::PYTHIA8 = true;
100 
101  // Use Pythia 6
102  // Input::PYTHIA6 = true;
103 
104  // Use Sartre
105  // Input::SARTRE = true;
106 
107  // Simple multi particle generator in eta/phi/pt ranges
108  Input::SIMPLE = true;
109  // Input::SIMPLE_NUMBER = 2; // if you need 2 of them
110  // Input::SIMPLE_VERBOSITY = 1;
111 
112  // Particle gun (same particles in always the same direction)
113  // Input::GUN = true;
114  // Input::GUN_NUMBER = 3; // if you need 3 of them
115  // Input::GUN_VERBOSITY = 0;
116 
117  // Upsilon generator
118  // Input::UPSILON = true;
119  // Input::UPSILON_NUMBER = 3; // if you need 3 of them
120  // Input::UPSILON_VERBOSITY = 0;
121 
122  // And/Or read generated particles from file
123 
124  // eic-smear output
125  // Input::READEIC = true;
126  INPUTREADEIC::filename = inputFile;
127 
128  // HepMC2 files
129  // Input::HEPMC = true;
130  Input::VERBOSITY = 0;
131  INPUTHEPMC::filename = inputFile;
132 
133  //-----------------
134  // Initialize the selected Input/Event generation
135  //-----------------
136  InputInit();
137  //--------------
138  // Set generator specific options
139  //--------------
140  // can only be set after InputInit() is called
141 
142  // Simple Input generator:
143  // if you run more than one of these Input::SIMPLE_NUMBER > 1
144  // add the settings for other with [1], next with [2]...
145  if (Input::SIMPLE)
146  {
147  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi-", 5);
148  if (Input::HEPMC || Input::EMBED)
149  {
150  INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
151  INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
152  }
153  else
154  {
155  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Uniform,
158  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
159  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0., 0., 5.);
160  }
161  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-3, 3);
162  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
163  INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(0.1, 20.);
164  }
165  // Upsilons
166  // if you run more than one of these Input::UPSILON_NUMBER > 1
167  // add the settings for other with [1], next with [2]...
168  if (Input::UPSILON)
169  {
170  INPUTGENERATOR::VectorMesonGenerator[0]->add_decay_particles("mu", 0);
171  INPUTGENERATOR::VectorMesonGenerator[0]->set_rapidity_range(-1, 1);
172  INPUTGENERATOR::VectorMesonGenerator[0]->set_pt_range(0., 10.);
173  // Y species - select only one, last one wins
174  INPUTGENERATOR::VectorMesonGenerator[0]->set_upsilon_1s();
175  if (Input::HEPMC || Input::EMBED)
176  {
177  INPUTGENERATOR::VectorMesonGenerator[0]->set_reuse_existing_vertex(true);
178  INPUTGENERATOR::VectorMesonGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
179  }
180  }
181  // particle gun
182  // if you run more than one of these Input::GUN_NUMBER > 1
183  // add the settings for other with [1], next with [2]...
184  if (Input::GUN)
185  {
186  INPUTGENERATOR::Gun[0]->AddParticle("pi-", 0, 1, 0);
187  INPUTGENERATOR::Gun[0]->set_vtx(0, 0, 0);
188  }
189  // pythia6
190  if (Input::PYTHIA6)
191  {
192  INPUTGENERATOR::Pythia6->set_config_file(string(getenv("CALIBRATIONROOT")) + "/Generators/phpythia6_ep.cfg");
195  }
196  // pythia8
197  if (Input::PYTHIA8)
198  {
201  }
202  // Sartre
203  if (Input::SARTRE)
204  {
207  }
208 
209  //--------------
210  // Set Input Manager specific options
211  //--------------
212  // can only be set after InputInit() is called
213 
214  if (Input::HEPMC)
215  {
218  // optional overriding beam parameters
219  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 30, 0); //optional collision smear in space, time
220  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
221  // //optional choice of vertex distribution function in space, time
222  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_function(PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus);
227  //INPUTMANAGER::HepMCInputManager->set_embedding_id(2);
228  }
229 
230  // register all input generators with Fun4All
231  InputRegister();
232 
233  // Reads event generators in EIC smear files, which is registered in InputRegister
234  if (Input::READEIC)
235  {
239  }
240 
241  // set up production relatedstuff
242  // Enable::PRODUCTION = true;
243 
244  //======================
245  // Write the DST
246  //======================
247 
248  // Enable::DSTOUT = true;
249  DstOut::OutputDir = outdir;
250  DstOut::OutputFile = outputFile;
251  Enable::DSTOUT_COMPRESS = true; // Compress DST files
252 
253  //Option to convert DST to human command readable TTree for quick poke around the outputs
254  // Enable::DSTREADER = true;
255 
256  // turn the display on (default off)
257  // Enable::DISPLAY = true;
258 
259  //======================
260  // What to run
261  //======================
262  // Global options (enabled for all subsystems - if implemented)
263  // Enable::ABSORBER = true;
264  // Enable::OVERLAPCHECK = true;
265  // Enable::VERBOSITY = 1;
266 
267  // whether to simulate the Be section of the beam pipe
268  Enable::PIPE = true;
269  // If need to disable EIC beam pipe extension beyond the Be-section:
271  //EIC hadron far forward magnets and detectors. IP6 and IP8 are incompatible (pick either or);
274 
277 
278  // gems
279  Enable::EGEM = true;
280  Enable::FGEM = true;
281  // Enable::BGEM = true; // not yet defined in this model
282  Enable::RWELL = true;
283  // barrel tracker
285  // Enable::TrackingService_VERBOSITY = INT_MAX - 10;
286  Enable::BARREL = true;
287  // fst
288  Enable::FST = true;
289 
290  // TOFs
291  Enable::FTTL = true;
292  Enable::ETTL = true;
293  Enable::CTTL = true;
296 
297  Enable::TRACKING = true;
299  G4TRACKING::DISPLACED_VERTEX = true; // this option exclude vertex in the track fitting and use RAVE to reconstruct primary and 2ndary vertexes
300  // projections to calorimeters
309 
310  Enable::BECAL = true;
315 
316  Enable::HCALIN = true;
317  // Enable::HCALIN_ABSORBER = true;
322 
323  Enable::MAGNET = true;
324 
325  Enable::HCALOUT = true;
326  // Enable::HCALOUT_ABSORBER = true;
331 
332  // EICDetector geometry - barrel
333  Enable::DIRC = true;
335  // Enable::DIRC_VERBOSITY = 2;
336 
337  // EICDetector geometry - 'hadron' direction
338  Enable::RICH = true;
340  // Enable::RICH_VERBOSITY = 2;
341 
342  // EICDetector geometry - 'electron' direction
343  Enable::mRICH = true;
345  // Enable::mRICH_VERBOSITY = 2;
346 
347  Enable::FEMC = true;
348  // Enable::FEMC_ABSORBER = true;
352 
353  //Enable::DRCALO = false;
359 
360  Enable::LFHCAL = true;
361  Enable::LFHCAL_ABSORBER = false;
366 
367  // EICDetector geometry - 'electron' direction
368  Enable::EEMCH = true;
373 
374  Enable::EHCAL = true;
379 
381 
382  Enable::PLUGDOOR = false;
383 
384  // Other options
385  Enable::GLOBAL_RECO = G4TRACKING::DISPLACED_VERTEX; // use reco vertex for global event vertex
386  Enable::GLOBAL_FASTSIM = true;
387 
388  // jet reconstruction
389  Enable::FWDJETS = true;
391 
392  // new settings using Enable namespace in GlobalVariables.C
393  Enable::BLACKHOLE = true;
394  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
395  //BlackHoleGeometry::visible = true;
396 
397  // ZDC
398  // Enable::ZDC = true;
399  // Enable::ZDC_DISABLE_BLACKHOLE = true;
400 
401  // B0
402  // Enable::B0_DISABLE_HITPLANE = true;
403  // Enable::B0_FULLHITPLANE = true;
404 
405  // Enabling the event evaluator?
406  Enable::EVENT_EVAL = true;
407  // EVENT_EVALUATOR::Verbosity = 1;
408  // EVENT_EVALUATOR::EnergyThreshold = 0.05; // GeV
409 
410  //Enable::USER = true;
411 
412  //---------------
413  // World Settings
414  //---------------
415  // G4WORLD::PhysicsList = "FTFP_BERT"; //FTFP_BERT_HP best for calo
416  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
417 
418  //---------------
419  // Magnet Settings
420  //---------------
421 
422  // 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)
423  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sPHENIX.2d.root"); // default map from the calibration database
424  G4MAGNET::magfield_rescale = -1.4 / 1.5; // make consistent with expected Babar field strength of 1.4T
425 
426  //---------------
427  // Pythia Decayer
428  //---------------
429  // list of decay types in
430  // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
431  // default is All:
432  // G4P6DECAYER::decayType = EDecayType::kAll;
433 
434  // Initialize the selected subsystems
435  G4Init();
436 
437  //---------------------
438  // GEANT4 Detector description
439  //---------------------
440 
441  // 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
442  if (!Input::READHITS)
443  {
444  G4Setup();
445  }
446 
447  //------------------
448  // Detector Division
449  //------------------
451 
453 
455 
456  //-----------------------------
457  // CEMC towering and clustering
458  //-----------------------------
459 
462 
463  //-----------------------------
464  // HCAL towering and clustering
465  //-----------------------------
466 
469 
472 
473  //-----------------------------
474  // e, h direction Calorimeter towering and clustering
475  //-----------------------------
476 
479 
482 
485 
488 
491 
494 
497 
500 
502 
503  //--------------
504  // Tracking and PID
505  //--------------
506 
508 
510 
512 
514 
515  //-----------------
516  // Global Vertexing
517  //-----------------
518 
520  {
521  Global_Reco();
522  }
523  else if (Enable::GLOBAL_FASTSIM)
524  {
525  Global_FastSim();
526  }
527 
528  //---------
529  // Jet reco
530  //---------
531 
533 
534  string outputroot = outputFile;
535  string remove_this = ".root";
536  size_t pos = outputroot.find(remove_this);
537  if (pos != string::npos)
538  {
539  outputroot.erase(pos, remove_this.length());
540  }
541 
542  if (Enable::DSTREADER) G4DSTreader_EICDetector(outputroot + "_DSTReader.root");
543 
544  //----------------------
545  // Simulation evaluation
546  //----------------------
547 
548  if (Enable::EVENT_EVAL) Event_Eval(outputroot + "_eventtree.root");
549 
550  if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "_g4tracking_eval.root");
551 
552  if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
553 
554  if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
555 
556  if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
557 
558  if (Enable::FEMC_EVAL) FEMC_Eval(outputroot + "_g4femc_eval.root");
559 
560  if (Enable::FHCAL_EVAL) FHCAL_Eval(outputroot + "_g4fhcal_eval.root");
561 
562  if (Enable::EEMC_EVAL) EEMC_Eval(outputroot + "_g4eemc_eval.root");
563 
564  if (Enable::FFR_EVAL) FFR_Eval(outputroot + "_g4ffr_eval.root");
565 
567 
569 
570  AnaTutorialECCE *anaTutorial = new AnaTutorialECCE("anaTutorial", outputroot + "_anaTutorial.root");
571  anaTutorial->setMinJetPt(3.);
572  anaTutorial->Verbosity(0);
573  anaTutorial->analyzeTracks(true);
574  anaTutorial->analyzeClusters(true);
575  anaTutorial->analyzeJets(true);
576  anaTutorial->analyzeTruth(false);
577  se->registerSubsystem(anaTutorial);
578 
579  //--------------
580  // Set up Input Managers
581  //--------------
582 
583  InputManagers();
584 
585  //--------------
586  // Set up Output Manager
587  //--------------
588  if (Enable::PRODUCTION)
589  {
591  }
592 
593  if (Enable::DSTOUT)
594  {
595  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
596  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
598  se->registerOutputManager(out);
599  }
600 
601  //-----------------
602  // Event processing
603  //-----------------
604  if (Enable::DISPLAY)
605  {
606  DisplayOn();
607 
608  gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
609  gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
610 
611  cout << "-------------------------------------------------" << endl;
612  cout << "You are in event display mode. Run one event with" << endl;
613  cout << "se->run(1)" << endl;
614  cout << "Run Geant4 command with following examples" << endl;
615  gROOT->ProcessLine("displaycmd()");
616 
617  return 0;
618  }
619  // if we use a negative number of events we go back to the command line here
620  if (nEvents < 0)
621  {
622  return 0;
623  }
624  // if we run any of the particle generators and use 0 it'll run forever
625  if (nEvents == 0 && !Input::READHITS && !Input::HEPMC && !Input::READEIC)
626  {
627  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
628  cout << "it will run forever, so I just return without running anything" << endl;
629  return 0;
630  }
631 
632  se->skip(skip);
633  se->run(nEvents);
634 
635  //-----
636  // Exit
637  //-----
638 
639  se->End();
640  std::cout << "All done" << std::endl;
641  delete se;
642  if (Enable::PRODUCTION)
643  {
645  }
646  gSystem->Exit(0);
647  return 0;
648 }
649 #endif