Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:24:06

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