Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_RunNewTruthMatcher.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_RunNewTruthMatcher.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 
21 #include <Trkr_RecoInit.C>
22 #include <Trkr_Clustering.C>
23 #include <Trkr_LaserClustering.C>
24 #include <Trkr_Reco.C>
25 #include <Trkr_Eval.C>
26 #include <Trkr_QA.C>
27 
28 #include <Trkr_Diagnostics.C>
29 #include <G4_User.C>
30 #include <QA.C>
31 
32 #include <ffamodules/FlagHandler.h>
33 #include <ffamodules/HeadReco.h>
34 #include <ffamodules/SyncReco.h>
36 
39 #include <fun4all/Fun4AllServer.h>
40 
41 #include <phool/PHRandomSeed.h>
42 #include <phool/recoConsts.h>
43 
44 R__LOAD_LIBRARY(libfun4all.so)
45 R__LOAD_LIBRARY(libffamodules.so)
46 
47 // For HepMC Hijing
48 // try inputFile = /sphenix/sim/sim01/sphnxpro/sHijing_HepMC/sHijing_0-12fm.dat
49 
51  const int nEvents = 1,
52  const int skip = 0,
53  const string &outputFile = "G4sPHENIX.root",
54  const string &inputFile = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
55  const string &embed_input_file = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
56  const string &outdir = ".")
57 {
59  se->Verbosity(0);
60 
61  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
63 
64  // just if we set some flags somewhere in this macro
66  // By default every random number generator uses
67  // PHRandomSeed() which reads /dev/urandom to get its seed
68  // if the RANDOMSEED flag is set its value is taken as seed
69  // You can either set this to a random value using PHRandomSeed()
70  // which will make all seeds identical (not sure what the point of
71  // this would be:
72  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
73  // or set it to a fixed value so you can debug your code
74  // rc->set_IntFlag("RANDOMSEED", 12345);
75 
76 
77  //===============
78  // Input options
79  //===============
80  // verbosity setting (applies to all input managers)
81  Input::VERBOSITY = 0;
82  // First enable the input generators
83  // Either:
84  // read previously generated g4-hits files, in this case it opens a DST and skips
85  // the simulations step completely. The G4Setup macro is only loaded to get information
86  // about the number of layers used for the cell reco code
87  // Input::READHITS = true;
88  INPUTREADHITS::filename[0] = inputFile;
89  // if you use a filelist
90  // INPUTREADHITS::listfile[0] = inputFile;
91  // Or:
92  // Use particle generator
93  // And
94  // Further choose to embed newly simulated events to a previous simulation. Not compatible with `readhits = true`
95  // 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
96  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
97  // Input::EMBED = true;
98  INPUTEMBED::filename[0] = embed_input_file;
99  // if you use a filelist
100  //INPUTEMBED::listfile[0] = embed_input_file;
101 
102  Input::SIMPLE = true;
103  // Input::SIMPLE_NUMBER = 2; // if you need 2 of them
104  // Input::SIMPLE_VERBOSITY = 1;
105 
106  // Enable this is emulating the nominal pp/pA/AA collision vertex distribution
107  // Input::BEAM_CONFIGURATION = Input::AA_COLLISION; // Input::AA_COLLISION (default), Input::pA_COLLISION, Input::pp_COLLISION
108 
109  // Input::PYTHIA6 = true;
110 
111  // Input::PYTHIA8 = true;
112 
113  // Input::GUN = true;
114  // Input::GUN_NUMBER = 3; // if you need 3 of them
115  // Input::GUN_VERBOSITY = 1;
116 
117  // Input::COSMIC = true;
118 
119  //D0 generator
120  //Input::DZERO = false;
121  //Input::DZERO_VERBOSITY = 0;
122  //Lambda_c generator //Not ready yet
123  //Input::LAMBDAC = false;
124  //Input::LAMBDAC_VERBOSITY = 0;
125  // Upsilon generator
126  //Input::UPSILON = true;
127  //Input::UPSILON_NUMBER = 3; // if you need 3 of them
128  //Input::UPSILON_VERBOSITY = 0;
129 
130  // Input::HEPMC = true;
131  INPUTHEPMC::filename = inputFile;
132  //-----------------
133  // Hijing options (symmetrize hijing, add flow, add fermi motion)
134  //-----------------
135  // INPUTHEPMC::HIJINGFLIP = true;
136  // INPUTHEPMC::FLOW = true;
137  // INPUTHEPMC::FLOW_VERBOSITY = 3;
138  // INPUTHEPMC::FERMIMOTION = true;
139 
140 
141  // Event pile up simulation with collision rate in Hz MB collisions.
142  //Input::PILEUPRATE = 50e3; // 50 kHz for AuAu
143  //Input::PILEUPRATE = 3e6; // 3MHz for pp
144 
145  // Enable this is emulating the nominal pp/pA/AA collision vertex distribution
146  // for HepMC records (hijing, pythia8)
147  // Input::BEAM_CONFIGURATION = Input::AA_COLLISION; // for 2023 sims we want the AA geometry for no pileup sims
148  // Input::BEAM_CONFIGURATION = Input::pp_COLLISION; // for 2024 sims we want the pp geometry for no pileup sims
149  // Input::BEAM_CONFIGURATION = Input::pA_COLLISION; // for pAu sims we want the pA geometry for no pileup sims
150 
151  //-----------------
152  // Initialize the selected Input/Event generation
153  //-----------------
154  // This creates the input generator(s)
155  InputInit();
156 
157  //--------------
158  // Set generator specific options
159  //--------------
160  // can only be set after InputInit() is called
161 
162  // Simple Input generator:
163  // if you run more than one of these Input::SIMPLE_NUMBER > 1
164  // add the settings for other with [1], next with [2]...
165 
166  // TEST [Derek, 09.05.2023]
167  const UInt_t nPerEvt(1);
168  const TString sParticle("pi-");
169  const Double_t ptParMin(10.);
170  const Double_t ptParMax(10.);
171 
172  // TEST [Derek, 02.06.2024]
173  const Bool_t doGausVertex(false);
174  const Double_t meanVtxXG(0.);
175  const Double_t meanVtxYG(0.);
176  const Double_t meanVtxZG(0.);
177  const Double_t meanVtxXU(0.);
178  const Double_t meanVtxYU(0.);
179  const Double_t meanVtxZU(0.);
180  const Double_t widthVtxXG(0.01);
181  const Double_t widthVtxYG(0.01);
182  const Double_t widthVtxZG(5.);
183  const Double_t widthVtxXU(0.);
184  const Double_t widthVtxYU(0.);
185  const Double_t widthVtxZU(0.);
186 
187  if (Input::SIMPLE)
188  {
189  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles(sParticle.Data(), nPerEvt);
190  if (Input::HEPMC || Input::EMBED)
191  {
192  INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
193  INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
194  }
195  else
196  {
197  if (doGausVertex) {
198  INPUTGENERATOR::SimpleEventGenerator[0] -> set_vertex_distribution_function(
202  );
203  INPUTGENERATOR::SimpleEventGenerator[0] -> set_vertex_distribution_mean(meanVtxXG, meanVtxYG, meanVtxZG);
204  INPUTGENERATOR::SimpleEventGenerator[0] -> set_vertex_distribution_width(widthVtxXG, widthVtxYG, widthVtxZG);
205  } else {
206  INPUTGENERATOR::SimpleEventGenerator[0] -> set_vertex_distribution_function(
210  );
211  INPUTGENERATOR::SimpleEventGenerator[0] -> set_vertex_distribution_mean(meanVtxXU, meanVtxYU, meanVtxZU);
212  INPUTGENERATOR::SimpleEventGenerator[0] -> set_vertex_distribution_width(widthVtxXU, widthVtxYU, widthVtxZU);
213  }
214  }
215  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-1, 1);
216  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
217  INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(ptParMin, ptParMax);
218  }
219  // Upsilons
220  // if you run more than one of these Input::UPSILON_NUMBER > 1
221  // add the settings for other with [1], next with [2]...
222  if (Input::UPSILON)
223  {
224  INPUTGENERATOR::VectorMesonGenerator[0]->add_decay_particles("e", 0);
225  INPUTGENERATOR::VectorMesonGenerator[0]->set_rapidity_range(-1, 1);
226  INPUTGENERATOR::VectorMesonGenerator[0]->set_pt_range(0., 10.);
227  // Y species - select only one, last one wins
228  INPUTGENERATOR::VectorMesonGenerator[0]->set_upsilon_1s();
229  if (Input::HEPMC || Input::EMBED)
230  {
231  INPUTGENERATOR::VectorMesonGenerator[0]->set_reuse_existing_vertex(true);
232  INPUTGENERATOR::VectorMesonGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
233  }
234  }
235  // particle gun
236  // if you run more than one of these Input::GUN_NUMBER > 1
237  // add the settings for other with [1], next with [2]...
238  if (Input::GUN)
239  {
240  INPUTGENERATOR::Gun[0]->AddParticle("pi-", 0, 1, 0);
241  INPUTGENERATOR::Gun[0]->set_vtx(0, 0, 0);
242  }
243 
244  // pythia6
245  if (Input::PYTHIA6)
246  {
249  }
250  // pythia8
251  if (Input::PYTHIA8)
252  {
255  }
256 
257  //--------------
258  // Set Input Manager specific options
259  //--------------
260  // can only be set after InputInit() is called
261 
262  if (Input::HEPMC)
263  {
266 
267  // optional overriding beam parameters
268  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 8, 0); //optional collision smear in space, time
269  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
270  // //optional choice of vertex distribution function in space, time
271  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_function(PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus);
276  //INPUTMANAGER::HepMCInputManager->set_embedding_id(Input::EmbedID);
277  if (Input::PILEUPRATE > 0)
278  {
279  // Copy vertex settings from foreground hepmc input
281  // and then modify the ones you want to be different
282  // INPUTMANAGER::HepMCPileupInputManager->set_vertex_distribution_width(100e-4,100e-4,8,0);
283  }
284  }
285  if (Input::PILEUPRATE > 0)
286  {
289  }
290  // register all input generators with Fun4All
291  InputRegister();
292 
293  if (! Input::READHITS)
294  {
295  rc->set_IntFlag("RUNNUMBER",1);
296 
297  SyncReco *sync = new SyncReco();
298  se->registerSubsystem(sync);
299 
300  HeadReco *head = new HeadReco();
301  se->registerSubsystem(head);
302  }
303 // Flag Handler is always needed to read flags from input (if used)
304 // and update our rc flags with them. At the end it saves all flags
305 // again on the DST in the Flags node under the RUN node
306  FlagHandler *flag = new FlagHandler();
307  se->registerSubsystem(flag);
308 
309  // set up production relatedstuff
310  // Enable::PRODUCTION = true;
311 
312  //======================
313  // Write the DST
314  //======================
315 
316  //Enable::DSTOUT = true;
317  Enable::DSTOUT_COMPRESS = false;
318  DstOut::OutputDir = outdir;
319  DstOut::OutputFile = outputFile;
320 
321  //Option to convert DST to human command readable TTree for quick poke around the outputs
322  // Enable::DSTREADER = true;
323 
324  // turn the display on (default off)
325  //Enable::DISPLAY = true;
326 
327  //======================
328  // What to run
329  //======================
330 
331  // QA, main switch
332  Enable::QA = false;
333 
334  // Global options (enabled for all enables subsystems - if implemented)
335  // Enable::ABSORBER = true;
336  // Enable::OVERLAPCHECK = true;
337  // Enable::VERBOSITY = 1;
338 
339  // Enable::MBD = true;
340  // Enable::MBD_SUPPORT = true; // save hist in MBD/BBC support structure
341  // Enable::MBDRECO = Enable::MBD && true;
342  Enable::MBDFAKE = true; // Smeared vtx and t0, use if you don't want real MBD/BBC in simulation
343 
344  Enable::PIPE = true;
345  Enable::PIPE_ABSORBER = true;
346 
347  // central tracking
348  Enable::MVTX = true;
352 
353  Enable::INTT = true;
354 // Enable::INTT_ABSORBER = true; // enables layerwise support structure readout
355 // Enable::INTT_SUPPORT = true; // enable global support structure readout
358  Enable::INTT_QA = Enable::INTT_CLUSTER && Enable::QA && true;
359 
360  Enable::TPC = true;
361  Enable::TPC_ABSORBER = true;
362  Enable::TPC_CELL = Enable::TPC && true;
364  Enable::TPC_QA = Enable::TPC_CLUSTER && Enable::QA && true;
365 
366  Enable::MICROMEGAS = true;
369  Enable::MICROMEGAS_QA = Enable::MICROMEGAS_CLUSTER && Enable::QA && true;
370 
373  Enable::TRACKING_QA = Enable::TRACKING_TRACK && Enable::QA && true;
374 
375  // only do track matching if TRACKINGTRACK is also used
379 
380  //Additional tracking tools
381  //Enable::TRACKING_DIAGNOSTICS = Enable::TRACKING_TRACK && true;
382  //G4TRACKING::filter_conversion_electrons = true;
383 
384 
385  // cemc electronics + thin layer of W-epoxy to get albedo from cemc
386  // into the tracking, cannot run together with CEMC
387  // Enable::CEMCALBEDO = true;
388 
389  Enable::CEMC = true;
390  Enable::CEMC_ABSORBER = true;
395  Enable::CEMC_QA = Enable::CEMC_CLUSTER && Enable::QA && false;
396 
397  Enable::HCALIN = true;
403  Enable::HCALIN_QA = Enable::HCALIN_CLUSTER && Enable::QA && false;
404 
405  Enable::MAGNET = true;
407 
408  Enable::HCALOUT = true;
414  Enable::HCALOUT_QA = Enable::HCALOUT_CLUSTER && Enable::QA && false;
415 
416  Enable::EPD = true;
417  Enable::EPD_TILE = Enable::EPD && true;
418 
419  Enable::BEAMLINE = true;
420 // Enable::BEAMLINE_ABSORBER = true; // makes the beam line magnets sensitive volumes
421 // Enable::BEAMLINE_BLACKHOLE = true; // turns the beamline magnets into black holes
422  Enable::ZDC = true;
423 // Enable::ZDC_ABSORBER = true;
424 // Enable::ZDC_SUPPORT = true;
425  Enable::ZDC_TOWER = Enable::ZDC && true;
427 
429  //Enable::PLUGDOOR = true;
431 
432  Enable::GLOBAL_RECO = (Enable::MBDFAKE || Enable::TRACKING_TRACK) && true;
433  //Enable::GLOBAL_FASTSIM = true;
434 
435  //Enable::KFPARTICLE = true;
436  //Enable::KFPARTICLE_VERBOSITY = 1;
437  //Enable::KFPARTICLE_TRUTH_MATCH = true;
438  //Enable::KFPARTICLE_SAVE_NTUPLE = true;
439 
441 
442  Enable::JETS = (Enable::GLOBAL_RECO || Enable::GLOBAL_FASTSIM) && false;
443  Enable::JETS_EVAL = Enable::JETS && false;
444  Enable::JETS_QA = Enable::JETS && Enable::QA && false;
445 
446  // HI Jet Reco for p+Au / Au+Au collisions (default is false for
447  // single particle / p+p-only simulations, or for p+Au / Au+Au
448  // simulations which don't particularly care about jets)
449  Enable::HIJETS = Enable::JETS && Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
450 
451  // 3-D topoCluster reconstruction, potentially in all calorimeter layers
452  Enable::TOPOCLUSTER = Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
453  // particle flow jet reconstruction - needs topoClusters!
455  // centrality reconstruction
456  Enable::CENTRALITY = true;
457 
458  // new settings using Enable namespace in GlobalVariables.C
459  Enable::BLACKHOLE = true;
460  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
461  //Enable::BLACKHOLE_FORWARD_SAVEHITS = false; // disable forward/backward hits
462  //BlackHoleGeometry::visible = true;
463 
464  // run user provided code (from local G4_User.C)
465  //Enable::USER = true;
466 
467  //===============
468  // conditions DB flags
469  //===============
470  Enable::CDB = true;
471  // global tag
472  rc->set_StringFlag("CDB_GLOBALTAG",CDB::global_tag);
473  // 64 bit timestamp
474  rc->set_uint64Flag("TIMESTAMP",CDB::timestamp);
475  //---------------
476  // World Settings
477  //---------------
478  // G4WORLD::PhysicsList = "FTFP_BERT"; //FTFP_BERT_HP best for calo
479  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
480 
481  //---------------
482  // Magnet Settings
483  //---------------
484 
485  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT"))+ string("/Field/Map/sphenix3dbigmapxyz.root"); // default map from the calibration database
486  // 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)
487 // G4MAGNET::magfield_rescale = 1.; // make consistent with expected Babar field strength of 1.4T
488 
489  //---------------
490  // Pythia Decayer
491  //---------------
492  // list of decay types in
493  // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
494  // default is All:
495  // G4P6DECAYER::decayType = EDecayType::kAll;
496 
497  // Initialize the selected subsystems
498  G4Init();
499 
500  //---------------------
501  // GEANT4 Detector description
502  //---------------------
503  if (!Input::READHITS)
504  {
505  G4Setup();
506  }
507 
508  //------------------
509  // Detector Division
510  //------------------
511 
513 
518 
520 
522 
524 
525  //-----------------------------
526  // CEMC towering and clustering
527  //-----------------------------
528 
530  if (Enable::CEMC_CLUSTER) CEMC_Clusters();
531 
532  //--------------
533  // EPD tile reconstruction
534  //--------------
535 
537 
538  //-----------------------------
539  // HCAL towering and clustering
540  //-----------------------------
541 
543  if (Enable::HCALIN_CLUSTER) HCALInner_Clusters();
544 
545  if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
546  if (Enable::HCALOUT_CLUSTER) HCALOuter_Clusters();
547 
548  // if enabled, do topoClustering early, upstream of any possible jet reconstruction
550 
551  //--------------
552  // SVTX tracking
553  //--------------
555  {
556  TrackingInit();
557  }
561  {
563  {
565  }
566  else
567  {
568  TPC_Clustering();
569  }
570  }
572 
574  {
575  Tracking_Reco();
576  }
577 
578 
579 
581  {
582  const std::string kshortFile = "./kshort_" + outputFile;
583  const std::string residualsFile = "./residuals_" + outputFile;
584 
585  G4KshortReconstruction(kshortFile);
586  seedResiduals(residualsFile);
587  }
588 
589 
590  //-----------------
591  // Global Vertexing
592  //-----------------
593 
594  if (Enable::GLOBAL_RECO && Enable::GLOBAL_FASTSIM)
595  {
596  cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
597  gSystem->Exit(1);
598  }
599  if (Enable::GLOBAL_RECO)
600  {
601  Global_Reco();
602  }
603  else if (Enable::GLOBAL_FASTSIM)
604  {
605  Global_FastSim();
606  }
607 
608  //-----------------
609  // Centrality Determination
610  //-----------------
611 
612  if (Enable::CENTRALITY)
613  {
614  Centrality();
615  }
616 
617  //-----------------
618  // Calo Trigger Simulation
619  //-----------------
620 
622  {
623  CaloTrigger_Sim();
624  }
625 
626  //---------
627  // Jet reco
628  //---------
629 
630  if (Enable::JETS) Jet_Reco();
631  if (Enable::HIJETS) HIJetReco();
632 
634 
635  //----------------------
636  // Simulation evaluation
637  //----------------------
638  string outputroot = outputFile;
639  string remove_this = ".root";
640  size_t pos = outputroot.find(remove_this);
641  if (pos != string::npos)
642  {
643  outputroot.erase(pos, remove_this.length());
644  }
645 
646  //if (Enable::TRACKING_EVAL) {
647  if (true) {
648 
650 
651  std::cout << "CHECK I am inside the svtx evaluator block!" << std::endl;
652 
653  SvtxEvaluator* eval = new SvtxEvaluator(
654  "SVTXEVALUATOR",
655  outputroot + "_g4svtx_eval.root",
656  "SvtxTrackMap",
661  );
662  eval->do_cluster_eval(true);
663  eval->do_g4hit_eval(false);
664  eval->do_hit_eval(false); // enable to see the hits that includes the chamber physics...
665  eval->do_gpoint_eval(true);
666  eval->do_vtx_eval_light(true);
667  eval->do_eval_light(true);
668  eval->do_track_eval(true);
669  eval->do_gtrack_eval(true);
670  eval->do_track_match(true);
672 
673  bool embed_scan = true;
674  if(TRACKING::pp_mode) {
675  embed_scan = false;
676  }
677  eval->scan_for_embedded(embed_scan); // take all tracks if false - take only embedded tracks if true
678  eval->scan_for_primaries(embed_scan); // defaults to only thrown particles for ntp_gtrack
679  std::cout << "SvtxEvaluator: pp_mode set to " << TRACKING::pp_mode << " and scan_for_embedded set to " << embed_scan << std::endl;
681  se->registerSubsystem(eval);
682  } // end if (Enable::TRACKING_EVAL)
683 
684  if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
685 
686  if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
687 
688  if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
689 
690  if (Enable::JETS_EVAL) Jet_Eval(outputroot + "_g4jet_eval.root");
691 
692  if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
693 
694 
695 
697 
698  // Writes electrons from conversions to a new track map on the node tree
699  // the ntuple file is for diagnostics, it is produced only if the flag is set in G4_Tracking.C
700  if(G4TRACKING::filter_conversion_electrons) Filter_Conversion_Electrons(outputroot + "_secvert_ntuple.root");
701 
702 
703  //======================
704  // Run KFParticle on evt
705  //======================
708 
709  //----------------------
710  // Standard QAs
711  //----------------------
712 
713  if (Enable::CEMC_QA) CEMC_QA();
716 
717  if (Enable::JETS_QA) Jet_QA();
718 
719  if (Enable::MVTX_QA) Mvtx_QA();
720  if (Enable::INTT_QA) Intt_QA();
721  if (Enable::TPC_QA) TPC_QA();
724 
726 
727  //if (Enable::TRACK_MATCHING) {
728  if (true) {
729 
730  // initialize track matcher
731  TrkrClusterIsMatcher* ismatcher = new TrkrClusterIsMatcher();
732 
733  // These are the default values -- uncomment and change as desired
734  //ismatcher->single_pixel_phi_MVTX = false ; // default to pitch*max(N_pixels_M,N_pixels_T)*tol_MVTX
735  //ismatcher->single_pixel_phi_INTT = false ; // ... same as for MVTX
736  //ismatcher->single_bin_phi_TPC = true ; // default to pitch*tol_phi_TPC
737  //ismatcher->single_pixel_z_MVTX = false ; // default to pitch*max(N_pixels_M,N_pixels_T)*tol_z_MVTX
738  //ismatcher->single_pixel_z_INTT = false ; // ... same as for MVTX
739  //ismatcher->single_bin_t_TPC = true ; // default to pitch*tol_t_TPC
740  //ismatcher-> tol_phi_MVTX = 0.5;
741  //ismatcher-> tol_phi_INTT = 0.5;
742  //ismatcher-> tol_phi_TPC = 1.0;
743  //ismatcher-> tol_z_MVTX = 0.5;
744  //ismatcher-> tol_t_TPC = 1.0;
745 
746  auto trackmatcher = new TruthRecoTrackMatching(ismatcher);
747  trackmatcher->set_min_cl_match (5); // minimum number of matched clusters to make a matched track
748  trackmatcher->set_min_cl_ratio (0.1); // at least 10% of truth clusters must be matched
749  trackmatcher->set_cutoff_deta (0.3); // won't compare tracks with |Δeta|>0.3 away
750  trackmatcher->set_cutoff_dphi (0.3); // won't compare tracks with |Δphi|>0.3 away
751  trackmatcher->set_smallsearch_deta (0.05); // will first compare tracks within this |Δphi|
752  trackmatcher->set_smallsearch_dphi (0.05); // will first compare tracks within this |Δeta|
753  //trackmatcher->set_max_nreco_per_truth (4); // maximum reco tracks matched for any truth track
754  //trackmatcher->set_max_ntruth_per_reco (4); // maximum truth tracks matched for any reco track
755  trackmatcher->set_max_nreco_per_truth (1); // maximum reco tracks matched for any truth track // TEST [Derek, 10.13.2023]
756  trackmatcher->set_max_ntruth_per_reco (1); // maximum truth tracks matched for any reco track // TEST [Derek, 10.13.2023]
757 
758  // set verbosity
760  trackmatcher->Verbosity(verbosity);
761  se->registerSubsystem(trackmatcher);
762 
764  auto treefiller = new FillClusMatchTree(ismatcher, outputroot + "_g4trackmatching.root");//, true, true, true, outputFile);
765  treefiller->Verbosity(verbosity);
767  treefiller->m_fill_clusters = true;
768  treefiller->m_fill_SvUnmatched = true;
769  } else {
770  treefiller->m_fill_clusters = false;
771  treefiller->m_fill_SvUnmatched = false;
772  }
773  treefiller->m_fill_clusverbose = false;
774  se->registerSubsystem(treefiller);
775  }
776  } // end if (ENABLE::TRACK_MATCHING)
777 
778  //--------------
779  // Set up Input Managers
780  //--------------
781 
782  InputManagers();
783 
784  if (Enable::PRODUCTION)
785  {
787  }
788 
789  if (Enable::DSTOUT)
790  {
791  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
792  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
794  {
795  ShowerCompress();
796  DstCompress(out);
797  }
798  se->registerOutputManager(out);
799  }
800  //-----------------
801  // Event processing
802  //-----------------
803  if (Enable::DISPLAY)
804  {
805  DisplayOn();
806 
807  gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
808  gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
809 
810  cout << "-------------------------------------------------" << endl;
811  cout << "You are in event display mode. Run one event with" << endl;
812  cout << "se->run(1)" << endl;
813  cout << "Run Geant4 command with following examples" << endl;
814  gROOT->ProcessLine("displaycmd()");
815 
816  return 0;
817  }
818 
819  // if we use a negative number of events we go back to the command line here
820  if (nEvents < 0)
821  {
822  return 0;
823  }
824  // if we run the particle generator and use 0 it'll run forever
825  // for embedding it runs forever if the repeat flag is set
826  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS && INPUTEMBED::REPEAT)
827  {
828  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
829  cout << "it will run forever, so I just return without running anything" << endl;
830  return 0;
831  }
832 
833  se->skip(skip);
834  se->run(nEvents);
835 
836  //-----
837  // QA output
838  //-----
839 
840  if (Enable::QA) QA_Output(outputroot + "_qa.root");
841 
842  //-----
843  // Exit
844  //-----
845 
846 // CDBInterface::instance()->Print(); // print used DB files
847  se->End();
848  std::cout << "All done" << std::endl;
849  delete se;
850  if (Enable::PRODUCTION)
851  {
853  }
854 
855  gSystem->Exit(0);
856  return 0;
857 }
858 #endif