Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:14:31

0001 #ifndef MACRO_FUN4ALLG4SPHENIX_C
0002 #define MACRO_FUN4ALLG4SPHENIX_C
0003 
0004 #include <../src/pi0ClusterAna.h>
0005 #include <GlobalVariables.C>
0006 
0007 #include <DisplayOn.C>
0008 #include <G4Setup_sPHENIX.C>
0009 #include <G4_Bbc.C>
0010 #include <G4_CaloTrigger.C>
0011 #include <G4_Centrality.C>
0012 #include <G4_DSTReader.C>
0013 #include <G4_Global.C>
0014 #include <G4_HIJetReco.C>
0015 #include <G4_Input.C>
0016 #include <G4_Jets.C>
0017 #include <G4_KFParticle.C>
0018 #include <G4_ParticleFlow.C>
0019 #include <G4_Production.C>
0020 #include <G4_TopoClusterReco.C>
0021 #include <G4_Tracking.C>
0022 #include <G4_User.C>
0023 #include <QA.C>
0024 
0025 #include <fun4all/Fun4AllDstOutputManager.h>
0026 #include <fun4all/Fun4AllOutputManager.h>
0027 #include <fun4all/Fun4AllServer.h>
0028 
0029 #include <phool/PHRandomSeed.h>
0030 #include <phool/recoConsts.h>
0031 
0032 R__LOAD_LIBRARY(libfun4all.so)
0033 R__LOAD_LIBRARY(libpi0ClusterAna.so)
0034 // For HepMC Hijing
0035 // try inputFile = /sphenix/sim/sim01/sphnxpro/sHijing_HepMC/sHijing_0-12fm.dat
0036 
0037 int Fun4All_SinglePi0Gen_sPHENIX(
0038     const int nEvents = 1,
0039     const int pid = 111,
0040     const string &outputFile = "G4sPHENIX.root",
0041     const string &inputFile = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
0042     const string &embed_input_file = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
0043     const int skip = 0,
0044     const string &outdir = ".")
0045 {
0046   Fun4AllServer *se = Fun4AllServer::instance();
0047   se->Verbosity(0);
0048 
0049   //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
0050   PHRandomSeed::Verbosity(0);
0051 
0052   // just if we set some flags somewhere in this macro
0053   recoConsts *rc = recoConsts::instance();
0054   // By default every random number generator uses
0055   // PHRandomSeed() which reads /dev/urandom to get its seed
0056   // if the RANDOMSEED flag is set its value is taken as seed
0057   // You can either set this to a random value using PHRandomSeed()
0058   // which will make all seeds identical (not sure what the point of
0059   // this would be:
0060   //  rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
0061   // or set it to a fixed value so you can debug your code
0062   //  rc->set_IntFlag("RANDOMSEED", 12345);
0063 
0064   //===============
0065   // conditions DB flags
0066   //===============
0067   // tag
0068   rc->set_StringFlag("XPLOAD_TAG","sPHENIX_ExampleGT_1");
0069   // database config
0070   rc->set_StringFlag("XPLOAD_CONFIG","sPHENIX_cdb");
0071   // 64 bit timestamp
0072   rc->set_uint64Flag("TIMESTAMP",12345678912345);
0073 
0074 
0075   //===============
0076   // Input options
0077   //===============
0078   // verbosity setting (applies to all input managers)
0079   Input::VERBOSITY = 0;
0080   // First enable the input generators
0081   // Either:
0082   // read previously generated g4-hits files, in this case it opens a DST and skips
0083   // the simulations step completely. The G4Setup macro is only loaded to get information
0084   // about the number of layers used for the cell reco code
0085   //  Input::READHITS = true;
0086   INPUTREADHITS::filename[0] = inputFile;
0087   // if you use a filelist
0088   // INPUTREADHITS::listfile[0] = inputFile;
0089   // Or:
0090   // Use particle generator
0091   // And
0092   // Further choose to embed newly simulated events to a previous simulation. Not compatible with `readhits = true`
0093   // 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
0094   // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
0095   //  Input::EMBED = true;
0096   INPUTEMBED::filename[0] = embed_input_file;
0097   // if you use a filelist
0098   //INPUTEMBED::listfile[0] = embed_input_file;
0099 
0100   Input::SIMPLE = true;
0101   // Input::SIMPLE_NUMBER = 2; // if you need 2 of them
0102   Input::SIMPLE_VERBOSITY = 0;
0103 
0104   //  Input::PYTHIA6 = true;
0105 
0106   // Input::PYTHIA8 = true;
0107 
0108   //  Input::GUN = true;
0109   //  Input::GUN_NUMBER = 3; // if you need 3 of them
0110   // Input::GUN_VERBOSITY = 1;
0111 
0112   //D0 generator
0113   //Input::DZERO = false;
0114   //Input::DZERO_VERBOSITY = 0;
0115   //Lambda_c generator //Not ready yet
0116   //Input::LAMBDAC = false;
0117   //Input::LAMBDAC_VERBOSITY = 0;
0118   // Upsilon generator
0119   //Input::UPSILON = true;
0120   //Input::UPSILON_NUMBER = 3; // if you need 3 of them
0121   //Input::UPSILON_VERBOSITY = 0;
0122 
0123   //  Input::HEPMC = true;
0124   INPUTHEPMC::filename = inputFile;
0125 
0126   // Event pile up simulation with collision rate in Hz MB collisions.
0127   //Input::PILEUPRATE = 100e3;
0128 
0129   //-----------------
0130   // Initialize the selected Input/Event generation
0131   //-----------------
0132   // This creates the input generator(s)
0133   InputInit();
0134 
0135   //--------------
0136   // Set generator specific options
0137   //--------------
0138   // can only be set after InputInit() is called
0139 
0140   // Simple Input generator:
0141   // if you run more than one of these Input::SIMPLE_NUMBER > 1
0142   // add the settings for other with [1], next with [2]...
0143   if (Input::SIMPLE)
0144   {
0145     INPUTGENERATOR::SimpleEventGenerator[0]->add_particles(pid, 1);
0146     
0147     if (Input::HEPMC || Input::EMBED)
0148     {
0149       INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
0150       INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
0151     }
0152     else
0153     {
0154       INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Gaus,
0155                                                                                 PHG4SimpleEventGenerator::Gaus,
0156                                                                                 PHG4SimpleEventGenerator::Gaus);
0157       INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
0158       /* INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0., 0., 0.); */
0159       INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0.01, 0.01, 5.);
0160     }
0161     INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-1.2, 1.2);
0162     INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
0163     INPUTGENERATOR::SimpleEventGenerator[0]->set_p_range(8.0, 8.0);
0164   }
0165   // Upsilons
0166   // if you run more than one of these Input::UPSILON_NUMBER > 1
0167   // add the settings for other with [1], next with [2]...
0168   if (Input::UPSILON)
0169   {
0170     INPUTGENERATOR::VectorMesonGenerator[0]->add_decay_particles("e", 0);
0171     INPUTGENERATOR::VectorMesonGenerator[0]->set_rapidity_range(-1, 1);
0172     INPUTGENERATOR::VectorMesonGenerator[0]->set_pt_range(0., 10.);
0173     // Y species - select only one, last one wins
0174     INPUTGENERATOR::VectorMesonGenerator[0]->set_upsilon_1s();
0175     if (Input::HEPMC || Input::EMBED)
0176     {
0177       INPUTGENERATOR::VectorMesonGenerator[0]->set_reuse_existing_vertex(true);
0178       INPUTGENERATOR::VectorMesonGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
0179     }
0180   }
0181   // particle gun
0182   // if you run more than one of these Input::GUN_NUMBER > 1
0183   // add the settings for other with [1], next with [2]...
0184   if (Input::GUN)
0185   {
0186     INPUTGENERATOR::Gun[0]->AddParticle("pi-", 0, 1, 0);
0187     INPUTGENERATOR::Gun[0]->set_vtx(0, 0, 0);
0188   }
0189 
0190   // pythia6
0191   if (Input::PYTHIA6)
0192   {
0193     //! apply sPHENIX nominal beam parameter with 2mrad crossing as defined in sPH-TRG-2020-001
0194     Input::ApplysPHENIXBeamParameter(INPUTGENERATOR::Pythia6);
0195   }
0196   // pythia8
0197   if (Input::PYTHIA8)
0198   {
0199     //! apply sPHENIX nominal beam parameter with 2mrad crossing as defined in sPH-TRG-2020-001
0200     Input::ApplysPHENIXBeamParameter(INPUTGENERATOR::Pythia8);
0201   }
0202 
0203   //--------------
0204   // Set Input Manager specific options
0205   //--------------
0206   // can only be set after InputInit() is called
0207 
0208   if (Input::HEPMC)
0209   {
0210     //! apply sPHENIX nominal beam parameter with 2mrad crossing as defined in sPH-TRG-2020-001
0211     Input::ApplysPHENIXBeamParameter(INPUTMANAGER::HepMCInputManager);
0212 
0213     // optional overriding beam parameters
0214     //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 8, 0);  //optional collision smear in space, time
0215     //    INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
0216     // //optional choice of vertex distribution function in space, time
0217     //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_function(PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus);
0218     //! embedding ID for the event
0219     //! positive ID is the embedded event of interest, e.g. jetty event from pythia
0220     //! negative IDs are backgrounds, .e.g out of time pile up collisions
0221     //! Usually, ID = 0 means the primary Au+Au collision background
0222     //INPUTMANAGER::HepMCInputManager->set_embedding_id(Input::EmbedID);
0223     if (Input::PILEUPRATE > 0)
0224     {
0225       // Copy vertex settings from foreground hepmc input
0226       INPUTMANAGER::HepMCPileupInputManager->CopyHelperSettings(INPUTMANAGER::HepMCInputManager);
0227       // and then modify the ones you want to be different
0228       // INPUTMANAGER::HepMCPileupInputManager->set_vertex_distribution_width(100e-4,100e-4,8,0);
0229     }
0230   }
0231   if (Input::PILEUPRATE > 0)
0232   {
0233     //! apply sPHENIX nominal beam parameter with 2mrad crossing as defined in sPH-TRG-2020-001
0234     Input::ApplysPHENIXBeamParameter(INPUTMANAGER::HepMCPileupInputManager);
0235   }
0236   // register all input generators with Fun4All
0237   InputRegister();
0238 
0239   // set up production relatedstuff
0240   //   Enable::PRODUCTION = true;
0241 
0242   //======================
0243   // Write the DST
0244   //======================
0245 
0246   //Enable::DSTOUT = true;
0247   Enable::DSTOUT_COMPRESS = false;
0248   DstOut::OutputDir = outdir;
0249   DstOut::OutputFile = outputFile;
0250 
0251   //Option to convert DST to human command readable TTree for quick poke around the outputs
0252   //  Enable::DSTREADER = true;
0253 
0254   // turn the display on (default off)
0255    //Enable::DISPLAY = true;
0256 
0257   //======================
0258   // What to run
0259   //======================
0260 
0261   // QA, main switch
0262   Enable::QA = false;
0263 
0264   // Global options (enabled for all enables subsystems - if implemented)
0265   //  Enable::ABSORBER = true;
0266   //  Enable::OVERLAPCHECK = true;
0267   //  Enable::VERBOSITY = 1;
0268 
0269   // Enable::BBC = true;
0270   // Enable::BBC_SUPPORT = true; // save hist in bbc support structure
0271    Enable::BBCFAKE = true;  // Smeared vtx and t0, use if you don't want real BBC in simulation
0272 
0273   Enable::PIPE = true;
0274   //Enable::PIPE_ABSORBER = true;
0275 
0276   // central tracking
0277   Enable::MVTX = true;
0278   //Enable::MVTX_CELL = Enable::MVTX && true;
0279   Enable::MVTX_CLUSTER = Enable::MVTX_CELL && true;
0280   Enable::MVTX_QA = Enable::MVTX_CLUSTER && Enable::QA && true;
0281   /* Enable::TrackingService = false; */
0282 
0283   Enable::INTT = true;
0284 //  Enable::INTT_ABSORBER = true; // enables layerwise support structure readout
0285 //  Enable::INTT_SUPPORT = true; // enable global support structure readout
0286   //  Enable::INTT_CELL = Enable::INTT && true;
0287   Enable::INTT_CLUSTER = Enable::INTT_CELL && true;
0288   Enable::INTT_QA = Enable::INTT_CLUSTER && Enable::QA && true;
0289 
0290   Enable::TPC = true;
0291   // Enable::TPC_ABSORBER = true;
0292   // Enable::TPC_CELL = Enable::TPC && true;
0293   Enable::TPC_CLUSTER = Enable::TPC_CELL && true;
0294   Enable::TPC_QA = Enable::TPC_CLUSTER && Enable::QA && true;
0295 
0296   Enable::MICROMEGAS = true;
0297   //Enable::MICROMEGAS_CELL = fasle;// = Enable::MICROMEGAS && true;
0298   Enable::MICROMEGAS_CLUSTER = Enable::MICROMEGAS_CELL && true;
0299   Enable::MICROMEGAS_QA = Enable::MICROMEGAS_CLUSTER && Enable::QA && true;
0300 
0301   //Enable::TRACKING_TRACK = true;
0302   Enable::TRACKING_EVAL = false;//= Enable::TRACKING_TRACK && true;
0303   Enable::TRACKING_QA = false;//xs= Enable::TRACKING_TRACK && Enable::QA && true;
0304 
0305   //  cemc electronics + thin layer of W-epoxy to get albedo from cemc
0306   //  into the tracking, cannot run together with CEMC
0307   //  Enable::CEMCALBEDO = true;
0308 
0309   Enable::CEMC = true;
0310   Enable::CEMC_ABSORBER = true;
0311   Enable::CEMC_CELL = Enable::CEMC && true;
0312   Enable::CEMC_TOWER = Enable::CEMC_CELL && true;
0313   Enable::CEMC_CLUSTER = Enable::CEMC_TOWER && true;
0314   Enable::CEMC_EVAL = false;//Enable::CEMC_CLUSTER && true;
0315   Enable::CEMC_QA = false;//Enable::CEMC_CLUSTER && Enable::QA && true;
0316 
0317   Enable::HCALIN =false;
0318   Enable::HCALIN_ABSORBER = true;
0319   Enable::HCALIN_CELL = Enable::HCALIN && true;
0320   Enable::HCALIN_TOWER = Enable::HCALIN_CELL && true;
0321   Enable::HCALIN_CLUSTER = Enable::HCALIN_TOWER && true;
0322   Enable::HCALIN_EVAL = Enable::HCALIN_CLUSTER && true;
0323   Enable::HCALIN_QA = Enable::HCALIN_CLUSTER && Enable::QA && true;
0324 
0325   Enable::MAGNET = false;
0326   Enable::MAGNET_ABSORBER = false;
0327 
0328   Enable::HCALOUT = false;
0329   Enable::HCALOUT_ABSORBER = true;
0330   Enable::HCALOUT_CELL = Enable::HCALOUT && true;
0331   Enable::HCALOUT_TOWER = Enable::HCALOUT_CELL && true;
0332   Enable::HCALOUT_CLUSTER = Enable::HCALOUT_TOWER && true;
0333   Enable::HCALOUT_EVAL = Enable::HCALOUT_CLUSTER && true;
0334   Enable::HCALOUT_QA = Enable::HCALOUT_CLUSTER && Enable::QA && true;
0335 
0336   Enable::EPD = false;
0337 
0338   //Enable::BEAMLINE = true;
0339 //  Enable::BEAMLINE_ABSORBER = true;  // makes the beam line magnets sensitive volumes
0340 //  Enable::BEAMLINE_BLACKHOLE = true; // turns the beamline magnets into black holes
0341   G4BEAMLINE::skin_thickness = 0.5;
0342 
0343   Enable::ZDC = false;
0344 //  Enable::ZDC_ABSORBER = true;
0345 //  Enable::ZDC_SUPPORT = true;
0346   Enable::ZDC_TOWER = Enable::ZDC && true;
0347   Enable::ZDC_EVAL = Enable::ZDC_TOWER && true;
0348 
0349   //! forward flux return plug door. Out of acceptance and off by default.
0350   //Enable::PLUGDOOR = true;
0351   //Enable::PLUGDOOR_ABSORBER = true;
0352   Enable::PLUGDOOR_BLACKHOLE = true;
0353 
0354   Enable::GLOBAL_RECO = true;
0355   //Enable::GLOBAL_FASTSIM = true;
0356 
0357   //Enable::KFPARTICLE = true;
0358   //Enable::KFPARTICLE_VERBOSITY = 1;
0359   //Enable::KFPARTICLE_TRUTH_MATCH = true;
0360   //Enable::KFPARTICLE_SAVE_NTUPLE = true;
0361 
0362   Enable::CALOTRIGGER = Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
0363 
0364   Enable::JETS = false;
0365   Enable::JETS_EVAL = Enable::JETS && true;
0366   Enable::JETS_QA = Enable::JETS && Enable::QA && true;
0367 
0368   // HI Jet Reco for p+Au / Au+Au collisions (default is false for
0369   // single particle / p+p-only simulations, or for p+Au / Au+Au
0370   // simulations which don't particularly care about jets)
0371   Enable::HIJETS = false && Enable::JETS && Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER;
0372 
0373   // 3-D topoCluster reconstruction, potentially in all calorimeter layers
0374   Enable::TOPOCLUSTER = false && Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER;
0375   // particle flow jet reconstruction - needs topoClusters!
0376   Enable::PARTICLEFLOW = true && Enable::TOPOCLUSTER;
0377   // centrality reconstruction
0378   Enable::CENTRALITY = true;
0379 
0380   // new settings using Enable namespace in GlobalVariables.C
0381   Enable::BLACKHOLE = true;
0382   //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
0383   //BlackHoleGeometry::visible = true;
0384 
0385   // run user provided code (from local G4_User.C)
0386   //Enable::USER = true;
0387 
0388   //---------------
0389   // World Settings
0390   //---------------
0391   //  G4WORLD::PhysicsList = "FTFP_BERT"; //FTFP_BERT_HP best for calo
0392   //  G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
0393 
0394   //---------------
0395   // Magnet Settings
0396   //---------------
0397 
0398   //  G4MAGNET::magfield =  string(getenv("CALIBRATIONROOT"))+ string("/Field/Map/sphenix3dbigmapxyz.root");  // default map from the calibration database
0399   //  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)
0400 //  G4MAGNET::magfield_rescale = 1.;  // make consistent with expected Babar field strength of 1.4T
0401 
0402   //---------------
0403   // Pythia Decayer
0404   //---------------
0405   // list of decay types in
0406   // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
0407   // default is All:
0408   // G4P6DECAYER::decayType = EDecayType::kAll;
0409 
0410   // Initialize the selected subsystems
0411   G4Init();
0412 
0413   //---------------------
0414   // GEANT4 Detector description
0415   //---------------------
0416   if (!Input::READHITS)
0417   {
0418     G4Setup();
0419   }
0420 
0421   //------------------
0422   // Detector Division
0423   //------------------
0424 
0425   if (Enable::BBC || Enable::BBCFAKE) Bbc_Reco();
0426 
0427   if (Enable::MVTX_CELL) Mvtx_Cells();
0428   if (Enable::INTT_CELL) Intt_Cells();
0429   if (Enable::TPC_CELL) TPC_Cells();
0430   if (Enable::MICROMEGAS_CELL) Micromegas_Cells();
0431 
0432   if (Enable::CEMC_CELL) CEMC_Cells();
0433 
0434   if (Enable::HCALIN_CELL) HCALInner_Cells();
0435 
0436   if (Enable::HCALOUT_CELL) HCALOuter_Cells();
0437 
0438   //-----------------------------
0439   // CEMC towering and clustering
0440   //-----------------------------
0441 
0442   if (Enable::CEMC_TOWER) CEMC_Towers();
0443   if (Enable::CEMC_CLUSTER) CEMC_Clusters();
0444 
0445   //-----------------------------
0446   // HCAL towering and clustering
0447   //-----------------------------
0448 
0449   if (Enable::HCALIN_TOWER) HCALInner_Towers();
0450   if (Enable::HCALIN_CLUSTER) HCALInner_Clusters();
0451 
0452   if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
0453   if (Enable::HCALOUT_CLUSTER) HCALOuter_Clusters();
0454 
0455   // if enabled, do topoClustering early, upstream of any possible jet reconstruction
0456   if (Enable::TOPOCLUSTER) TopoClusterReco();
0457 
0458   //--------------
0459   // SVTX tracking
0460   //--------------
0461   if(Enable::TRACKING_TRACK)
0462     {
0463       TrackingInit();
0464     }
0465   if (Enable::MVTX_CLUSTER) Mvtx_Clustering();
0466   if (Enable::INTT_CLUSTER) Intt_Clustering();
0467   if (Enable::TPC_CLUSTER) TPC_Clustering();
0468   if (Enable::MICROMEGAS_CLUSTER) Micromegas_Clustering();
0469 
0470   if (Enable::TRACKING_TRACK)
0471   {
0472     Tracking_Reco();
0473   }
0474   //-----------------
0475   // Global Vertexing
0476   //-----------------
0477 
0478   if (Enable::GLOBAL_RECO && Enable::GLOBAL_FASTSIM)
0479   {
0480     cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
0481     gSystem->Exit(1);
0482   }
0483   if (Enable::GLOBAL_RECO)
0484   {
0485     Global_Reco();
0486   }
0487   else if (Enable::GLOBAL_FASTSIM)
0488   {
0489     Global_FastSim();
0490   }
0491 
0492   //-----------------
0493   // Centrality Determination
0494   //-----------------
0495 
0496   if (Enable::CENTRALITY)
0497   {
0498       Centrality();
0499   }
0500 
0501   //-----------------
0502   // Calo Trigger Simulation
0503   //-----------------
0504 
0505   if (Enable::CALOTRIGGER)
0506   {
0507     CaloTrigger_Sim();
0508   }
0509 
0510   //---------
0511   // Jet reco
0512   //---------
0513 
0514   if (Enable::JETS) Jet_Reco();
0515   if (Enable::HIJETS) HIJetReco();
0516 
0517   if (Enable::PARTICLEFLOW) ParticleFlow();
0518 
0519   //----------------------
0520   // Simulation evaluation
0521   //----------------------
0522   string outputroot = outputFile;
0523   string remove_this = ".root";
0524   size_t pos = outputroot.find(remove_this);
0525   if (pos != string::npos)
0526   {
0527     outputroot.erase(pos, remove_this.length());
0528   }
0529 
0530   if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "_g4svtx_eval.root");
0531 
0532   if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
0533   
0534   if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
0535 
0536   if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
0537 
0538   if (Enable::JETS_EVAL) Jet_Eval(outputroot + "_g4jet_eval.root");
0539 
0540   if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
0541 
0542   if (Enable::USER) UserAnalysisInit();
0543 
0544 
0545 
0546   
0547 
0548   pi0ClusterAna *eval = new pi0ClusterAna("dummy", outputroot + "_pi0ClusterAna.root");
0549   se->registerSubsystem(eval);
0550 
0551 
0552   //======================
0553   // Run KFParticle on evt
0554   //======================
0555   if (Enable::KFPARTICLE && Input::UPSILON) KFParticle_Upsilon_Reco();
0556   if (Enable::KFPARTICLE && Input::DZERO) KFParticle_D0_Reco();
0557 
0558   //----------------------
0559   // Standard QAs
0560   //----------------------
0561 
0562   if (Enable::CEMC_QA) CEMC_QA();
0563   if (Enable::HCALIN_QA) HCALInner_QA();
0564   if (Enable::HCALOUT_QA) HCALOuter_QA();
0565 
0566   if (Enable::JETS_QA) Jet_QA();
0567 
0568   if (Enable::MVTX_QA) Mvtx_QA();
0569   if (Enable::INTT_QA) Intt_QA();
0570   if (Enable::TPC_QA) TPC_QA();
0571   if (Enable::MICROMEGAS_QA) Micromegas_QA();
0572   if (Enable::TRACKING_QA) Tracking_QA();
0573 
0574   if (Enable::TRACKING_QA && Enable::CEMC_QA && Enable::HCALIN_QA && Enable::HCALOUT_QA) QA_G4CaloTracking();
0575 
0576   //--------------
0577   // Set up Input Managers
0578   //--------------
0579 
0580   InputManagers();
0581 
0582   if (Enable::PRODUCTION)
0583   {
0584     Production_CreateOutputDir();
0585   }
0586 
0587   if (Enable::DSTOUT)
0588   {
0589     string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
0590     Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
0591     if (Enable::DSTOUT_COMPRESS)
0592     {
0593       ShowerCompress();
0594       DstCompress(out);
0595     }
0596     se->registerOutputManager(out);
0597   }
0598   //-----------------
0599   // Event processing
0600   //-----------------
0601   if (Enable::DISPLAY)
0602   {
0603     DisplayOn();
0604 
0605     gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
0606     gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
0607 
0608     cout << "-------------------------------------------------" << endl;
0609     cout << "You are in event display mode. Run one event with" << endl;
0610     cout << "se->run(1)" << endl;
0611     cout << "Run Geant4 command with following examples" << endl;
0612     gROOT->ProcessLine("displaycmd()");
0613 
0614     return 0;
0615   }
0616 
0617   // if we use a negative number of events we go back to the command line here
0618   if (nEvents < 0)
0619   {
0620     return 0;
0621   }
0622   // if we run the particle generator and use 0 it'll run forever
0623   // for embedding it runs forever if the repeat flag is set
0624   if (nEvents == 0 && !Input::HEPMC && !Input::READHITS && INPUTEMBED::REPEAT)
0625   {
0626     cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
0627     cout << "it will run forever, so I just return without running anything" << endl;
0628     return 0;
0629   }
0630 
0631   se->skip(skip);
0632   se->run(nEvents);
0633 
0634   //-----
0635   // QA output
0636   //-----
0637 
0638   if (Enable::QA) QA_Output(outputroot + "_qa.root");
0639 
0640   //-----
0641   // Exit
0642   //-----
0643 
0644   se->End();
0645   std::cout << "All done" << std::endl;
0646   delete se;
0647   if (Enable::PRODUCTION)
0648   {
0649     Production_MoveOutput();
0650   }
0651 
0652   gSystem->Exit(0);
0653   return 0;
0654 }
0655 #endif