Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:51

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