Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_pi0tbt_SIMPLE_EMBED.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_pi0tbt_SIMPLE_EMBED.C
1 #ifndef MACRO_FUN4ALLG4SPHENIX_C
2 #define MACRO_FUN4ALLG4SPHENIX_C
3 
4 #include <GlobalVariables.C>
5 
6 #include <DisplayOn.C>
7 #include <G4Setup_sPHENIX.C>
8 #include <G4_Mbd.C>
9 #include <G4_CaloTrigger.C>
10 #include <G4_Centrality.C>
11 #include <G4_DSTReader.C>
12 #include <G4_Global.C>
13 #include <G4_HIJetReco.C>
14 #include <G4_Input.C>
15 #include <G4_Jets.C>
16 #include <G4_KFParticle.C>
17 #include <G4_ParticleFlow.C>
18 #include <G4_Production.C>
19 #include <G4_TopoClusterReco.C>
20 #include <G4_Tracking.C>
21 #include <G4_User.C>
22 #include <QA.C>
23 
26 #include <fun4all/Fun4AllServer.h>
27 
28 #include <phool/PHRandomSeed.h>
29 #include <phool/recoConsts.h>
30 
31 #include <calib_emc_pi0/CaloCalibEmc_Pi0.h>
32 
33 R__LOAD_LIBRARY(libfun4all.so)
34 R__LOAD_LIBRARY(libcaloCalibDBFile.so)
35 R__LOAD_LIBRARY(libcalibCaloEmc_pi0.so)
36 
37 // For HepMC Hijing
38 // try inputFile = /sphenix/sim/sim01/sphnxpro/sHijing_HepMC/sHijing_0-12fm.dat
39 
41  const int nEvents = 3,
42  const int mdc2_4_file_num = 1,
43  const string &outputFile = "out_jan23.root",
44  const int skip = 0,
45  const string &outdir = ".")
46 {
48  se->Verbosity(0);
49 
50  string inputFile0 = "DST_CALO_G4HIT_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000062-";
51  string inputFile1 = "DST_VERTEX_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000062-";
52  string inputFile2 = "DST_TRUTH_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000062-";
53 
54 
55  int ynum_int = 100000+ mdc2_4_file_num;
56  TString yn_tstr = "";
57  yn_tstr += ynum_int;
58  yn_tstr.Remove(0,1);
59  inputFile0 += yn_tstr.Data();
60  inputFile1 += yn_tstr.Data();
61  inputFile2 += yn_tstr.Data();
62 
63  inputFile0 += ".root";
64  inputFile1 += ".root";
65  inputFile2 += ".root";
66 
67  cout << "running over these files" << endl;
68  cout << inputFile0 << endl;
69  cout << inputFile1 << endl;
70 
71  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
73 
74  // just if we set some flags somewhere in this macro
76 
77  //===============
78  // Input options
79  //===============
80  // verbosity setting (applies to all input managers)
81  Input::VERBOSITY = 1;
82 
83  Input::READHITS = false; // true;
84  //INPUTREADHITS::filename[0] = inputFile0;
85  //INPUTREADHITS::filename[1] = inputFile1;
86 
87  Input::EMBED = true;
88  INPUTEMBED::filename[0] = inputFile0; //0;
89  INPUTEMBED::filename[1] = inputFile1;
90  INPUTEMBED::filename[2] = inputFile2;
91 
92  Input::SIMPLE = true;
94 
95  InputInit();
96 
97  //--------------
98  // Set generator specific options
99  //--------------
100  // can only be set after InputInit() is called
101 
102  // Simple Input generator:
103  // if you run more than one of these Input::SIMPLE_NUMBER > 1
104  // add the settings for other with [1], next with [2]...
105  if (Input::SIMPLE)
106  {
107  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi0",10);
108  if (Input::HEPMC || Input::EMBED)
109  {
110  //INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_global_vertex(true);
111  INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
112  INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
113  }
114  else
115  {
116  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Gaus,
119  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
120  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0.01, 0.01, 5.);
121  }
122  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-1.1, 1.1);
123  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
124  INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(1.6, 5.);
125  INPUTGENERATOR::SimpleEventGenerator[0]->set_power_law_n(-6.5);
126  }
127 
128 
129  if (Input::PILEUPRATE > 0)
130  {
133  }
134  // register all input generators with Fun4All
135  InputRegister();
136 
137  // set up production relatedstuff
138  Enable::PRODUCTION = true;
139 
140  //======================
141  // Write the DST
142  //======================
143 
144  Enable::DSTOUT = false;
145  Enable::DSTOUT_COMPRESS = false;
146  DstOut::OutputDir = outdir;
147  DstOut::OutputFile = outputFile;
148 
149  //Option to convert DST to human command readable TTree for quick poke around the outputs
150  // Enable::DSTREADER = true;
151 
152  // turn the display on (default off)
153  Enable::DISPLAY = false;
154 
155  //======================
156  // What to run
157  //======================
158 
159  // QA, main switch
160  Enable::QA = false;
161 
162  // Global options (enabled for all enables subsystems - if implemented)
163  // Enable::ABSORBER = true;
164  // Enable::OVERLAPCHECK = true;
165  // Enable::VERBOSITY = 1;
166 
167  // Enable::MBD = true;
168  // Enable::MBD_SUPPORT = true; // save hist in MBD/BBC support structure
169  //Enable::MBDFAKE = true; // Smeared vtx and t0, use if you don't want real MBD/BBC in simulation
170 
171  //Enable::PIPE = true;
172  //Enable::PIPE_ABSORBER = true;
173  //Enable::INTT = false;
174 // Enable::INTT_ABSORBER = true; // enables layerwise support structure readout
175 // Enable::INTT_SUPPORT = true; // enable global support structure readout
179 
180  Enable::TPC = false;
181  Enable::TPC_ABSORBER = true;
182  Enable::TPC_CELL = Enable::TPC && true;
184  Enable::TPC_QA = Enable::TPC_CLUSTER && Enable::QA && true;
185 
186  Enable::MICROMEGAS = false;
189  Enable::MICROMEGAS_QA = Enable::MICROMEGAS_CLUSTER && Enable::QA && true;
190 
191  Enable::TRACKING_TRACK = false;
193  Enable::TRACKING_QA = Enable::TRACKING_TRACK && Enable::QA && true;
194 
195  // cemc electronics + thin layer of W-epoxy to get albedo from cemc
196  // into the tracking, cannot run together with CEMC
197  // Enable::CEMCALBEDO = true;
198 
199  Enable::CEMC = true;
200  // Enable::CEMC_ABSORBER = true;
204  //Enable::CEMC_EVAL = false;//Enable::CEMC_CLUSTER && true;
205  //Enable::CEMC_QA = false;//Enable::CEMC_CLUSTER && Enable::QA && true;
206 
207  Enable::HCALIN =false;
213  Enable::HCALIN_QA = Enable::HCALIN_CLUSTER && Enable::QA && true;
214 
215  Enable::MAGNET = false;
216  Enable::MAGNET_ABSORBER = false;
217 
218  Enable::HCALOUT = false;
224  Enable::HCALOUT_QA = Enable::HCALOUT_CLUSTER && Enable::QA && true;
225 
226  Enable::EPD = false;
227 
228  Enable::BEAMLINE = true;
229 // Enable::BEAMLINE_ABSORBER = true; // makes the beam line magnets sensitive volumes
230 // Enable::BEAMLINE_BLACKHOLE = true; // turns the beamline magnets into black holes
231  Enable::ZDC = false;
232 // Enable::ZDC_ABSORBER = true;
233 // Enable::ZDC_SUPPORT = true;
234  Enable::ZDC_TOWER = Enable::ZDC && true;
236 
238  //Enable::PLUGDOOR = true;
239  //Enable::PLUGDOOR_ABSORBER = true;
240 
241  //Enable::GLOBAL_RECO = true;
242  //Enable::GLOBAL_FASTSIM = true;
243 
244  //Enable::KFPARTICLE = true;
245  //Enable::KFPARTICLE_VERBOSITY = 1;
246  //Enable::KFPARTICLE_TRUTH_MATCH = true;
247  //Enable::KFPARTICLE_SAVE_NTUPLE = true;
248 
250 
251  Enable::JETS = false;
253  Enable::JETS_QA = Enable::JETS && Enable::QA && true;
254 
255  // HI Jet Reco for p+Au / Au+Au collisions (default is false for
256  // single particle / p+p-only simulations, or for p+Au / Au+Au
257  // simulations which don't particularly care about jets)
259 
260  // 3-D topoCluster reconstruction, potentially in all calorimeter layers
262  // particle flow jet reconstruction - needs topoClusters!
263  //Enable::PARTICLEFLOW = true && Enable::TOPOCLUSTER;
264  // centrality reconstruction
265  //Enable::CENTRALITY = true;
266 
267  // new settings using Enable namespace in GlobalVariables.C
268  //Enable::BLACKHOLE = true;
269  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
270  //BlackHoleGeometry::visible = true;
271 
272  // Initialize the selected subsystems
273  G4Init();
274 
275  //---------------------
276  // GEANT4 Detector description
277  //---------------------
278 
279 
280  if (!Input::READHITS)
281  {
282  G4Setup();
283  }
284 
285 
286  //------------------
287  // Detector Division
288  //------------------
289 
291 
296 
298 
300 
302 
303  //-----------------------------
304  // CEMC towering and clustering
305  //-----------------------------
306 
309 
310  //-----------------------------
311  // HCAL towering and clustering
312  //-----------------------------
313 
316 
317  if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
319 
320  // if enabled, do topoClustering early, upstream of any possible jet reconstruction
322 
323  //--------------
324  // SVTX tracking
325  //--------------
327  {
328  TrackingInit();
329  }
334 
336  {
337  Tracking_Reco();
338  }
339  //-----------------
340  // Global Vertexing
341  //-----------------
342  /*
343  if (Enable::GLOBAL_RECO && Enable::GLOBAL_FASTSIM)
344  {
345  cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
346  gSystem->Exit(1);
347  }
348  if (Enable::GLOBAL_RECO)
349  {
350  Global_Reco();
351  }
352  else if (Enable::GLOBAL_FASTSIM)
353  {
354  Global_FastSim();
355  }
356 */
357 
358  //-----------------
359  // Centrality Determination
360  //-----------------
361 
362  if (Enable::CENTRALITY)
363  {
364  Centrality();
365  }
366 
367  //-----------------
368  // Calo Trigger Simulation
369  //-----------------
370 
372  {
373  CaloTrigger_Sim();
374  }
375 
376  //---------
377  // Jet reco
378  //---------
379 
380  if (Enable::JETS) Jet_Reco();
381  if (Enable::HIJETS) HIJetReco();
382 
384 
385  //----------------------
386  // Simulation evaluation
387  //----------------------
388  string outputroot = outputFile;
389  string remove_this = ".root";
390  size_t pos = outputroot.find(remove_this);
391  if (pos != string::npos)
392  {
393  outputroot.erase(pos, remove_this.length());
394  }
395 
396  if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "_g4svtx_eval.root");
397 
398  if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
399 
400  if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
401 
402  if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
403 
404  if (Enable::JETS_EVAL) Jet_Eval(outputroot + "_g4jet_eval.root");
405 
406  if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
407 
409 
410 
411 
412 
413  //======================
414  // Run KFParticle on evt
415  //======================
418 
419  //----------------------
420  // Standard QAs
421  //----------------------
422 
423  if (Enable::CEMC_QA) CEMC_QA();
426 
427  if (Enable::JETS_QA) Jet_QA();
428 
429  if (Enable::MVTX_QA) Mvtx_QA();
430  if (Enable::INTT_QA) Intt_QA();
431  if (Enable::TPC_QA) TPC_QA();
434 
436 
437  //--------------
438  // Set up Input Managers
439  //--------------
440 
441  InputManagers();
442 
443  if (Enable::PRODUCTION)
444  {
446  }
447 
448  if (Enable::DSTOUT)
449  {
450  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
451  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
453  {
454  ShowerCompress();
455  DstCompress(out);
456  }
457  se->registerOutputManager(out);
458  }
459  //-----------------
460  // Event processing
461  //-----------------
462  if (Enable::DISPLAY)
463  {
464  DisplayOn();
465 
466  gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
467  gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
468 
469  cout << "-------------------------------------------------" << endl;
470  cout << "You are in event display mode. Run one event with" << endl;
471  cout << "se->run(1)" << endl;
472  cout << "Run Geant4 command with following examples" << endl;
473  gROOT->ProcessLine("displaycmd()");
474 
475  return 0;
476  }
477 
478  CaloCalibEmc_Pi0 *eval_pi2 = new CaloCalibEmc_Pi0("dummy", outputroot+"_piemc.root");
479  // this call is needed for embedding
480  eval_pi2->set_centrality_nclusters_cut(350); // which uses more central events
481  // than we will for data to enhance Bkg
482  // to match the enhanced signal from embed
483  se->registerSubsystem(eval_pi2);
484  cout << "successful registration of pi0 " << endl;
485 
486 
487  // if we use a negative number of events we go back to the command line here
488  if (nEvents < 0)
489  {
490  return 0;
491  }
492  // if we run the particle generator and use 0 it'll run forever
493  // for embedding it runs forever if the repeat flag is set
494  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS && INPUTEMBED::REPEAT)
495  {
496  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
497  cout << "it will run forever, so I just return without running anything" << endl;
498  return 0;
499  }
500 
501  se->skip(skip);
502  se->run(nEvents);
503 
504  //-----
505  // QA output
506  //-----
507 
508  if (Enable::QA) QA_Output(outputroot + "_qa.root");
509 
510  //-----
511  // Exit
512  //-----
513 
514  se->End();
515  std::cout << "All done" << std::endl;
516  delete se;
517  /*
518  if (Enable::PRODUCTION)
519  {
520  Production_MoveOutput();
521  }
522  */
523  gSystem->Exit(0);
524  return 0;
525 }
526 #endif