Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_Pi0Gen_sPHENIX.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_Pi0Gen_sPHENIX.C
1 #ifndef MACRO_FUN4ALLG4SPHENIX_C
2 #define MACRO_FUN4ALLG4SPHENIX_C
3 
4 #include <../../pi0Efficiency.h>
5 #include <GlobalVariables.C>
6 
7 #include <DisplayOn.C>
8 #include <G4Setup_sPHENIX.C>
9 #include <G4_Bbc.C>
10 #include <G4_CaloTrigger.C>
11 #include <G4_Centrality.C>
12 #include <G4_DSTReader.C>
13 #include <G4_Global.C>
14 #include <G4_HIJetReco.C>
15 #include <G4_Input.C>
16 #include <G4_Jets.C>
17 #include <G4_KFParticle.C>
18 #include <G4_ParticleFlow.C>
19 #include <G4_Production.C>
20 #include <G4_TopoClusterReco.C>
21 #include <G4_Tracking.C>
22 #include <G4_User.C>
23 #include <QA.C>
24 
27 #include <fun4all/Fun4AllServer.h>
28 
29 #include <phool/PHRandomSeed.h>
30 #include <phool/recoConsts.h>
31 
32 R__LOAD_LIBRARY(libfun4all.so)
33 R__LOAD_LIBRARY(libpi0Efficiency.so)
34 // For HepMC Hijing
35 // try inputFile = /sphenix/sim/sim01/sphnxpro/sHijing_HepMC/sHijing_0-12fm.dat
36 
38  const int nEvents = 1,
39  const int pid = 111,
40  const string &outputFile = "G4sPHENIX.root",
41  const string &inputFile = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
42  const string &embed_input_file = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
43  const int skip = 0,
44  const string &outdir = ".")
45 {
47  se->Verbosity(0);
48 
49  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
51 
52  // just if we set some flags somewhere in this macro
54  // By default every random number generator uses
55  // PHRandomSeed() which reads /dev/urandom to get its seed
56  // if the RANDOMSEED flag is set its value is taken as seed
57  // You can either set this to a random value using PHRandomSeed()
58  // which will make all seeds identical (not sure what the point of
59  // this would be:
60  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
61  // or set it to a fixed value so you can debug your code
62  // rc->set_IntFlag("RANDOMSEED", 12345);
63 
64  //===============
65  // conditions DB flags
66  //===============
67  // tag
68  rc->set_StringFlag("XPLOAD_TAG","sPHENIX_ExampleGT_1");
69  // database config
70  rc->set_StringFlag("XPLOAD_CONFIG","sPHENIX_cdb");
71  // 64 bit timestamp
72  rc->set_uint64Flag("TIMESTAMP",12345678912345);
73 
74 
75  //===============
76  // Input options
77  //===============
78  // verbosity setting (applies to all input managers)
79  Input::VERBOSITY = 0;
80  // First enable the input generators
81  // Either:
82  // read previously generated g4-hits files, in this case it opens a DST and skips
83  // the simulations step completely. The G4Setup macro is only loaded to get information
84  // about the number of layers used for the cell reco code
85  // Input::READHITS = true;
86  INPUTREADHITS::filename[0] = inputFile;
87  // if you use a filelist
88  // INPUTREADHITS::listfile[0] = inputFile;
89  // Or:
90  // Use particle generator
91  // And
92  // Further choose to embed newly simulated events to a previous simulation. Not compatible with `readhits = true`
93  // In case embedding into a production output, please double check your G4Setup_sPHENIX.C and G4_*.C consistent with those in the production macro folder
94  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
95  // Input::EMBED = true;
96  INPUTEMBED::filename[0] = embed_input_file;
97  // if you use a filelist
98  //INPUTEMBED::listfile[0] = embed_input_file;
99 
100  Input::SIMPLE = true;
101  // Input::SIMPLE_NUMBER = 2; // if you need 2 of them
103 
104  // Input::PYTHIA6 = true;
105 
106  // Input::PYTHIA8 = true;
107 
108  // Input::GUN = true;
109  // Input::GUN_NUMBER = 3; // if you need 3 of them
110  // Input::GUN_VERBOSITY = 1;
111 
112  //D0 generator
113  //Input::DZERO = false;
114  //Input::DZERO_VERBOSITY = 0;
115  //Lambda_c generator //Not ready yet
116  //Input::LAMBDAC = false;
117  //Input::LAMBDAC_VERBOSITY = 0;
118  // Upsilon generator
119  //Input::UPSILON = true;
120  //Input::UPSILON_NUMBER = 3; // if you need 3 of them
121  //Input::UPSILON_VERBOSITY = 0;
122 
123  // Input::HEPMC = true;
124  INPUTHEPMC::filename = inputFile;
125 
126  // Event pile up simulation with collision rate in Hz MB collisions.
127  //Input::PILEUPRATE = 100e3;
128 
129  //-----------------
130  // Initialize the selected Input/Event generation
131  //-----------------
132  // This creates the input generator(s)
133  InputInit();
134 
135  //--------------
136  // Set generator specific options
137  //--------------
138  // can only be set after InputInit() is called
139 
140  // Simple Input generator:
141  // if you run more than one of these Input::SIMPLE_NUMBER > 1
142  // add the settings for other with [1], next with [2]...
143  if (Input::SIMPLE)
144  {
145  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles(pid, 1);
146 
147  if (Input::HEPMC || Input::EMBED)
148  {
149  INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
150  INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
151  }
152  else
153  {
154  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Gaus,
157  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
158  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0.01, 0.01, 5.);
159  }
160  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-0.3, 0.3);
161  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
162  INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(0.5, 20.);
163  }
164  // Upsilons
165  // if you run more than one of these Input::UPSILON_NUMBER > 1
166  // add the settings for other with [1], next with [2]...
167  if (Input::UPSILON)
168  {
169  INPUTGENERATOR::VectorMesonGenerator[0]->add_decay_particles("e", 0);
170  INPUTGENERATOR::VectorMesonGenerator[0]->set_rapidity_range(-1, 1);
171  INPUTGENERATOR::VectorMesonGenerator[0]->set_pt_range(0., 10.);
172  // Y species - select only one, last one wins
173  INPUTGENERATOR::VectorMesonGenerator[0]->set_upsilon_1s();
174  if (Input::HEPMC || Input::EMBED)
175  {
176  INPUTGENERATOR::VectorMesonGenerator[0]->set_reuse_existing_vertex(true);
177  INPUTGENERATOR::VectorMesonGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
178  }
179  }
180  // particle gun
181  // if you run more than one of these Input::GUN_NUMBER > 1
182  // add the settings for other with [1], next with [2]...
183  if (Input::GUN)
184  {
185  INPUTGENERATOR::Gun[0]->AddParticle("pi-", 0, 1, 0);
186  INPUTGENERATOR::Gun[0]->set_vtx(0, 0, 0);
187  }
188 
189  // pythia6
190  if (Input::PYTHIA6)
191  {
194  }
195  // pythia8
196  if (Input::PYTHIA8)
197  {
200  }
201 
202  //--------------
203  // Set Input Manager specific options
204  //--------------
205  // can only be set after InputInit() is called
206 
207  if (Input::HEPMC)
208  {
211 
212  // optional overriding beam parameters
213  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 8, 0); //optional collision smear in space, time
214  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
215  // //optional choice of vertex distribution function in space, time
216  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_function(PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus);
221  //INPUTMANAGER::HepMCInputManager->set_embedding_id(Input::EmbedID);
222  if (Input::PILEUPRATE > 0)
223  {
224  // Copy vertex settings from foreground hepmc input
226  // and then modify the ones you want to be different
227  // INPUTMANAGER::HepMCPileupInputManager->set_vertex_distribution_width(100e-4,100e-4,8,0);
228  }
229  }
230  if (Input::PILEUPRATE > 0)
231  {
234  }
235  // register all input generators with Fun4All
236  InputRegister();
237 
238  // set up production relatedstuff
239  // Enable::PRODUCTION = true;
240 
241  //======================
242  // Write the DST
243  //======================
244 
245  //Enable::DSTOUT = true;
246  Enable::DSTOUT_COMPRESS = false;
247  DstOut::OutputDir = outdir;
248  DstOut::OutputFile = outputFile;
249 
250  //Option to convert DST to human command readable TTree for quick poke around the outputs
251  // Enable::DSTREADER = true;
252 
253  // turn the display on (default off)
254  //Enable::DISPLAY = true;
255 
256  //======================
257  // What to run
258  //======================
259 
260  // QA, main switch
261  Enable::QA = false;
262 
263  // Global options (enabled for all enables subsystems - if implemented)
264  // Enable::ABSORBER = true;
265  // Enable::OVERLAPCHECK = true;
266  // Enable::VERBOSITY = 1;
267 
268  // Enable::BBC = true;
269  // Enable::BBC_SUPPORT = true; // save hist in bbc support structure
270  Enable::BBCFAKE = true; // Smeared vtx and t0, use if you don't want real BBC in simulation
271 
272  Enable::PIPE = true;
273  Enable::PIPE_ABSORBER = true;
274 
275  // central tracking
276  Enable::MVTX = false;
280  Enable::TrackingService = false;
281 
282  Enable::INTT = false;
283 // Enable::INTT_ABSORBER = true; // enables layerwise support structure readout
284 // Enable::INTT_SUPPORT = true; // enable global support structure readout
287  Enable::INTT_QA = Enable::INTT_CLUSTER && Enable::QA && true;
288 
289  Enable::TPC = false;
290  Enable::TPC_ABSORBER = true;
291  Enable::TPC_CELL = Enable::TPC && true;
293  Enable::TPC_QA = Enable::TPC_CLUSTER && Enable::QA && true;
294 
295  Enable::MICROMEGAS = false;
298  Enable::MICROMEGAS_QA = Enable::MICROMEGAS_CLUSTER && Enable::QA && true;
299 
300  Enable::TRACKING_TRACK = false;
302  Enable::TRACKING_QA = Enable::TRACKING_TRACK && Enable::QA && true;
303 
304  // cemc electronics + thin layer of W-epoxy to get albedo from cemc
305  // into the tracking, cannot run together with CEMC
306  // Enable::CEMCALBEDO = true;
307 
308  Enable::CEMC = true;
309  Enable::CEMC_ABSORBER = true;
313  Enable::CEMC_EVAL = false;//Enable::CEMC_CLUSTER && true;
314  Enable::CEMC_QA = false;//Enable::CEMC_CLUSTER && Enable::QA && true;
315 
316  Enable::HCALIN =false;
322  Enable::HCALIN_QA = Enable::HCALIN_CLUSTER && Enable::QA && true;
323 
324  Enable::MAGNET = false;
325  Enable::MAGNET_ABSORBER = false;
326 
327  Enable::HCALOUT = false;
333  Enable::HCALOUT_QA = Enable::HCALOUT_CLUSTER && Enable::QA && true;
334 
335  Enable::EPD = false;
336 
337  Enable::BEAMLINE = true;
338 // Enable::BEAMLINE_ABSORBER = true; // makes the beam line magnets sensitive volumes
339 // Enable::BEAMLINE_BLACKHOLE = true; // turns the beamline magnets into black holes
340  Enable::ZDC = false;
341 // Enable::ZDC_ABSORBER = true;
342 // Enable::ZDC_SUPPORT = true;
343  Enable::ZDC_TOWER = Enable::ZDC && true;
345 
347  //Enable::PLUGDOOR = true;
349 
350  Enable::GLOBAL_RECO = true;
351  //Enable::GLOBAL_FASTSIM = true;
352 
353  //Enable::KFPARTICLE = true;
354  //Enable::KFPARTICLE_VERBOSITY = 1;
355  //Enable::KFPARTICLE_TRUTH_MATCH = true;
356  //Enable::KFPARTICLE_SAVE_NTUPLE = true;
357 
359 
360  Enable::JETS = false;
362  Enable::JETS_QA = Enable::JETS && Enable::QA && true;
363 
364  // HI Jet Reco for p+Au / Au+Au collisions (default is false for
365  // single particle / p+p-only simulations, or for p+Au / Au+Au
366  // simulations which don't particularly care about jets)
368 
369  // 3-D topoCluster reconstruction, potentially in all calorimeter layers
371  // particle flow jet reconstruction - needs topoClusters!
373  // centrality reconstruction
374  Enable::CENTRALITY = true;
375 
376  // new settings using Enable namespace in GlobalVariables.C
377  Enable::BLACKHOLE = true;
378  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
379  //BlackHoleGeometry::visible = true;
380 
381  // run user provided code (from local G4_User.C)
382  //Enable::USER = true;
383 
384  //---------------
385  // World Settings
386  //---------------
387  // G4WORLD::PhysicsList = "FTFP_BERT"; //FTFP_BERT_HP best for calo
388  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
389 
390  //---------------
391  // Magnet Settings
392  //---------------
393 
394  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT"))+ string("/Field/Map/sphenix3dbigmapxyz.root"); // default map from the calibration database
395  // G4MAGNET::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)
396 // G4MAGNET::magfield_rescale = 1.; // make consistent with expected Babar field strength of 1.4T
397 
398  //---------------
399  // Pythia Decayer
400  //---------------
401  // list of decay types in
402  // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
403  // default is All:
404  // G4P6DECAYER::decayType = EDecayType::kAll;
405 
406  // Initialize the selected subsystems
407  G4Init();
408 
409  //---------------------
410  // GEANT4 Detector description
411  //---------------------
412  if (!Input::READHITS)
413  {
414  G4Setup();
415  }
416 
417  //------------------
418  // Detector Division
419  //------------------
420 
421  if (Enable::BBC || Enable::BBCFAKE) Bbc_Reco();
422 
427 
429 
431 
433 
434  //-----------------------------
435  // CEMC towering and clustering
436  //-----------------------------
437 
440 
441  //-----------------------------
442  // HCAL towering and clustering
443  //-----------------------------
444 
447 
448  if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
450 
451  // if enabled, do topoClustering early, upstream of any possible jet reconstruction
453 
454  //--------------
455  // SVTX tracking
456  //--------------
458  {
459  TrackingInit();
460  }
465 
467  {
468  Tracking_Reco();
469  }
470  //-----------------
471  // Global Vertexing
472  //-----------------
473 
475  {
476  cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
477  gSystem->Exit(1);
478  }
480  {
481  Global_Reco();
482  }
483  else if (Enable::GLOBAL_FASTSIM)
484  {
485  Global_FastSim();
486  }
487 
488  //-----------------
489  // Centrality Determination
490  //-----------------
491 
492  if (Enable::CENTRALITY)
493  {
494  Centrality();
495  }
496 
497  //-----------------
498  // Calo Trigger Simulation
499  //-----------------
500 
502  {
503  CaloTrigger_Sim();
504  }
505 
506  //---------
507  // Jet reco
508  //---------
509 
510  if (Enable::JETS) Jet_Reco();
511  if (Enable::HIJETS) HIJetReco();
512 
514 
515  //----------------------
516  // Simulation evaluation
517  //----------------------
518  string outputroot = outputFile;
519  string remove_this = ".root";
520  size_t pos = outputroot.find(remove_this);
521  if (pos != string::npos)
522  {
523  outputroot.erase(pos, remove_this.length());
524  }
525 
526  if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "_g4svtx_eval.root");
527 
528  if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
529 
530  if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
531 
532  if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
533 
534  if (Enable::JETS_EVAL) Jet_Eval(outputroot + "_g4jet_eval.root");
535 
536  if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
537 
539 
540 
541 
542 
543 
544  pi0Efficiency *eval = new pi0Efficiency("dummy", outputroot + "_pi0Efficiency.root");
545  se->registerSubsystem(eval);
546 
547 
548  //======================
549  // Run KFParticle on evt
550  //======================
553 
554  //----------------------
555  // Standard QAs
556  //----------------------
557 
558  if (Enable::CEMC_QA) CEMC_QA();
561 
562  if (Enable::JETS_QA) Jet_QA();
563 
564  if (Enable::MVTX_QA) Mvtx_QA();
565  if (Enable::INTT_QA) Intt_QA();
566  if (Enable::TPC_QA) TPC_QA();
569 
571 
572  //--------------
573  // Set up Input Managers
574  //--------------
575 
576  InputManagers();
577 
578  if (Enable::PRODUCTION)
579  {
581  }
582 
583  if (Enable::DSTOUT)
584  {
585  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
586  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
588  {
589  ShowerCompress();
590  DstCompress(out);
591  }
592  se->registerOutputManager(out);
593  }
594  //-----------------
595  // Event processing
596  //-----------------
597  if (Enable::DISPLAY)
598  {
599  DisplayOn();
600 
601  gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
602  gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
603 
604  cout << "-------------------------------------------------" << endl;
605  cout << "You are in event display mode. Run one event with" << endl;
606  cout << "se->run(1)" << endl;
607  cout << "Run Geant4 command with following examples" << endl;
608  gROOT->ProcessLine("displaycmd()");
609 
610  return 0;
611  }
612 
613  // if we use a negative number of events we go back to the command line here
614  if (nEvents < 0)
615  {
616  return 0;
617  }
618  // if we run the particle generator and use 0 it'll run forever
619  // for embedding it runs forever if the repeat flag is set
620  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS && INPUTEMBED::REPEAT)
621  {
622  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
623  cout << "it will run forever, so I just return without running anything" << endl;
624  return 0;
625  }
626 
627  se->skip(skip);
628  se->run(nEvents);
629 
630  //-----
631  // QA output
632  //-----
633 
634  if (Enable::QA) QA_Output(outputroot + "_qa.root");
635 
636  //-----
637  // Exit
638  //-----
639 
640  se->End();
641  std::cout << "All done" << std::endl;
642  delete se;
643  if (Enable::PRODUCTION)
644  {
646  }
647 
648  gSystem->Exit(0);
649  return 0;
650 }
651 #endif