Back to home page

sPhenix code displayed by LXR

 
 

    


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

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 #include <G4_Tracking.C>
0021 #include <G4_User.C>
0022 #include <QA.C>
0023 
0024 #include <fun4all/Fun4AllDstOutputManager.h>
0025 #include <fun4all/Fun4AllOutputManager.h>
0026 #include <fun4all/Fun4AllServer.h>
0027 
0028 #include <phool/PHRandomSeed.h>
0029 #include <phool/recoConsts.h>
0030 
0031 #include <calib_emc_pi0/CaloCalibEmc_Pi0.h>
0032 
0033 R__LOAD_LIBRARY(libfun4all.so)
0034 R__LOAD_LIBRARY(libcaloCalibDBFile.so)
0035 R__LOAD_LIBRARY(libcalibCaloEmc_pi0.so)
0036 
0037 // For HepMC Hijing
0038 // try inputFile = /sphenix/sim/sim01/sphnxpro/sHijing_HepMC/sHijing_0-12fm.dat
0039 
0040 int Fun4All_pi0tbt_SIMPLE_EMBED(
0041     const int nEvents = 3,
0042         const int mdc2_4_file_num = 1,
0043     const string &outputFile = "out_jan23.root",
0044     const int skip = 0,
0045     const string &outdir = ".")
0046 {
0047   Fun4AllServer *se = Fun4AllServer::instance();
0048   se->Verbosity(0);
0049 
0050     string inputFile0 = "DST_CALO_G4HIT_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000062-";
0051   string inputFile1 = "DST_VERTEX_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000062-";
0052     string inputFile2 = "DST_TRUTH_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000062-";
0053 
0054 
0055     int ynum_int = 100000+ mdc2_4_file_num;
0056   TString yn_tstr = "";
0057   yn_tstr += ynum_int;
0058   yn_tstr.Remove(0,1);
0059   inputFile0 += yn_tstr.Data();
0060   inputFile1 += yn_tstr.Data();
0061     inputFile2 += yn_tstr.Data();
0062 
0063   inputFile0 += ".root";
0064   inputFile1 += ".root";
0065     inputFile2 += ".root";
0066    
0067   cout << "running over these files" << endl;
0068   cout << inputFile0 << endl;
0069   cout << inputFile1 << endl;
0070 
0071   //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
0072   PHRandomSeed::Verbosity(1);
0073 
0074   // just if we set some flags somewhere in this macro
0075   recoConsts *rc = recoConsts::instance();
0076 
0077   //===============
0078   // Input options
0079   //===============
0080   // verbosity setting (applies to all input managers)
0081   Input::VERBOSITY = 1;
0082 
0083     Input::READHITS = false; // true;
0084     //INPUTREADHITS::filename[0] = inputFile0;
0085     //INPUTREADHITS::filename[1] = inputFile1;
0086 
0087   Input::EMBED = true;
0088     INPUTEMBED::filename[0] = inputFile0;  //0;
0089     INPUTEMBED::filename[1] = inputFile1;
0090     INPUTEMBED::filename[2] = inputFile2;
0091 
0092   Input::SIMPLE = true;
0093   Input::SIMPLE_VERBOSITY = 0;
0094 
0095   InputInit();
0096 
0097   //--------------
0098   // Set generator specific options
0099   //--------------
0100   // can only be set after InputInit() is called
0101 
0102   // Simple Input generator:
0103   // if you run more than one of these Input::SIMPLE_NUMBER > 1
0104   // add the settings for other with [1], next with [2]...
0105   if (Input::SIMPLE)
0106   {
0107     INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi0",10);     
0108     if (Input::HEPMC || Input::EMBED)
0109     {
0110             //INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_global_vertex(true);
0111       INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
0112       INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
0113     }
0114     else
0115     {
0116       INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Gaus,
0117                                                                                 PHG4SimpleEventGenerator::Gaus,
0118                                                                                 PHG4SimpleEventGenerator::Gaus);
0119       INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
0120       INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0.01, 0.01, 5.);
0121     }
0122     INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-1.1, 1.1);
0123     INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
0124     INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(1.6, 5.);
0125     INPUTGENERATOR::SimpleEventGenerator[0]->set_power_law_n(-6.5);
0126   }
0127 
0128 
0129   if (Input::PILEUPRATE > 0)
0130   {
0131     //! apply sPHENIX nominal beam parameter with 2mrad crossing as defined in sPH-TRG-2020-001
0132     Input::ApplysPHENIXBeamParameter(INPUTMANAGER::HepMCPileupInputManager);
0133   }
0134   // register all input generators with Fun4All
0135   InputRegister();
0136 
0137   // set up production relatedstuff
0138   Enable::PRODUCTION = true;
0139 
0140   //======================
0141   // Write the DST
0142   //======================
0143 
0144   Enable::DSTOUT = false;
0145   Enable::DSTOUT_COMPRESS = false;
0146   DstOut::OutputDir = outdir;
0147   DstOut::OutputFile = outputFile;
0148 
0149   //Option to convert DST to human command readable TTree for quick poke around the outputs
0150   //  Enable::DSTREADER = true;
0151 
0152   // turn the display on (default off)
0153   Enable::DISPLAY = false;
0154 
0155   //======================
0156   // What to run
0157   //======================
0158 
0159   // QA, main switch
0160   Enable::QA = false;
0161 
0162   // Global options (enabled for all enables subsystems - if implemented)
0163   //  Enable::ABSORBER = true;
0164   //  Enable::OVERLAPCHECK = true;
0165   //  Enable::VERBOSITY = 1;
0166 
0167   // Enable::MBD = true;
0168   // Enable::MBD_SUPPORT = true; // save hist in MBD/BBC support structure
0169   //Enable::MBDFAKE = true;  // Smeared vtx and t0, use if you don't want real MBD/BBC in simulation
0170 
0171   //Enable::PIPE = true;
0172   //Enable::PIPE_ABSORBER = true;
0173   //Enable::INTT = false;
0174 //  Enable::INTT_ABSORBER = true; // enables layerwise support structure readout
0175 //  Enable::INTT_SUPPORT = true; // enable global support structure readout
0176   Enable::INTT_CELL = Enable::INTT && true;
0177   Enable::INTT_CLUSTER = Enable::INTT_CELL && true;
0178   Enable::INTT_QA = Enable::INTT_CLUSTER && Enable::QA && true;
0179 
0180   Enable::TPC = false;
0181   Enable::TPC_ABSORBER = true;
0182   Enable::TPC_CELL = Enable::TPC && true;
0183   Enable::TPC_CLUSTER = Enable::TPC_CELL && true;
0184   Enable::TPC_QA = Enable::TPC_CLUSTER && Enable::QA && true;
0185 
0186   Enable::MICROMEGAS = false;
0187   Enable::MICROMEGAS_CELL = Enable::MICROMEGAS && true;
0188   Enable::MICROMEGAS_CLUSTER = Enable::MICROMEGAS_CELL && true;
0189   Enable::MICROMEGAS_QA = Enable::MICROMEGAS_CLUSTER && Enable::QA && true;
0190 
0191   Enable::TRACKING_TRACK = false;
0192   Enable::TRACKING_EVAL = Enable::TRACKING_TRACK && true;
0193   Enable::TRACKING_QA = Enable::TRACKING_TRACK && Enable::QA && true;
0194 
0195   //  cemc electronics + thin layer of W-epoxy to get albedo from cemc
0196   //  into the tracking, cannot run together with CEMC
0197   //  Enable::CEMCALBEDO = true;
0198 
0199   Enable::CEMC = true;
0200  // Enable::CEMC_ABSORBER = true;
0201   Enable::CEMC_CELL = Enable::CEMC && true;
0202   Enable::CEMC_TOWER = Enable::CEMC_CELL && true;
0203   Enable::CEMC_CLUSTER = Enable::CEMC_TOWER && true;
0204   //Enable::CEMC_EVAL = false;//Enable::CEMC_CLUSTER && true;
0205   //Enable::CEMC_QA = false;//Enable::CEMC_CLUSTER && Enable::QA && true;
0206 
0207   Enable::HCALIN =false;
0208   Enable::HCALIN_ABSORBER = true;
0209   Enable::HCALIN_CELL = Enable::HCALIN && true;
0210   Enable::HCALIN_TOWER = Enable::HCALIN_CELL && true;
0211   Enable::HCALIN_CLUSTER = Enable::HCALIN_TOWER && true;
0212   Enable::HCALIN_EVAL = Enable::HCALIN_CLUSTER && true;
0213   Enable::HCALIN_QA = Enable::HCALIN_CLUSTER && Enable::QA && true;
0214 
0215   Enable::MAGNET = false;
0216   Enable::MAGNET_ABSORBER = false;
0217 
0218   Enable::HCALOUT = false;
0219   Enable::HCALOUT_ABSORBER = true;
0220   Enable::HCALOUT_CELL = Enable::HCALOUT && true;
0221   Enable::HCALOUT_TOWER = Enable::HCALOUT_CELL && true;
0222   Enable::HCALOUT_CLUSTER = Enable::HCALOUT_TOWER && true;
0223   Enable::HCALOUT_EVAL = Enable::HCALOUT_CLUSTER && true;
0224   Enable::HCALOUT_QA = Enable::HCALOUT_CLUSTER && Enable::QA && true;
0225 
0226   Enable::EPD = false;
0227 
0228   Enable::BEAMLINE = true;
0229 //  Enable::BEAMLINE_ABSORBER = true;  // makes the beam line magnets sensitive volumes
0230 //  Enable::BEAMLINE_BLACKHOLE = true; // turns the beamline magnets into black holes
0231   Enable::ZDC = false;
0232 //  Enable::ZDC_ABSORBER = true;
0233 //  Enable::ZDC_SUPPORT = true;
0234   Enable::ZDC_TOWER = Enable::ZDC && true;
0235   Enable::ZDC_EVAL = Enable::ZDC_TOWER && true;
0236 
0237   //! forward flux return plug door. Out of acceptance and off by default.
0238   //Enable::PLUGDOOR = true;
0239   //Enable::PLUGDOOR_ABSORBER = true;
0240 
0241     //Enable::GLOBAL_RECO = true;
0242   //Enable::GLOBAL_FASTSIM = true;
0243 
0244   //Enable::KFPARTICLE = true;
0245   //Enable::KFPARTICLE_VERBOSITY = 1;
0246   //Enable::KFPARTICLE_TRUTH_MATCH = true;
0247   //Enable::KFPARTICLE_SAVE_NTUPLE = true;
0248 
0249   Enable::CALOTRIGGER = Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
0250 
0251   Enable::JETS = false;
0252   Enable::JETS_EVAL = Enable::JETS && true;
0253   Enable::JETS_QA = Enable::JETS && Enable::QA && true;
0254 
0255   // HI Jet Reco for p+Au / Au+Au collisions (default is false for
0256   // single particle / p+p-only simulations, or for p+Au / Au+Au
0257   // simulations which don't particularly care about jets)
0258   Enable::HIJETS = false && Enable::JETS && Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER;
0259 
0260   // 3-D topoCluster reconstruction, potentially in all calorimeter layers
0261   Enable::TOPOCLUSTER = false && Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER;
0262   // particle flow jet reconstruction - needs topoClusters!
0263   //Enable::PARTICLEFLOW = true && Enable::TOPOCLUSTER;
0264   // centrality reconstruction
0265   //Enable::CENTRALITY = true;
0266 
0267   // new settings using Enable namespace in GlobalVariables.C
0268   //Enable::BLACKHOLE = true;
0269   //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
0270   //BlackHoleGeometry::visible = true;
0271 
0272   // Initialize the selected subsystems
0273   G4Init();
0274 
0275   //---------------------
0276   // GEANT4 Detector description
0277   //---------------------
0278 
0279         
0280   if (!Input::READHITS)
0281   {
0282     G4Setup();
0283   }
0284         
0285 
0286   //------------------
0287   // Detector Division
0288   //------------------
0289 
0290   if (Enable::MBD || Enable::MBDFAKE) Mbd_Reco();
0291 
0292   if (Enable::MVTX_CELL) Mvtx_Cells();
0293   if (Enable::INTT_CELL) Intt_Cells();
0294   if (Enable::TPC_CELL) TPC_Cells();
0295   if (Enable::MICROMEGAS_CELL) Micromegas_Cells();
0296 
0297   if (Enable::CEMC_CELL) CEMC_Cells();
0298 
0299   if (Enable::HCALIN_CELL) HCALInner_Cells();
0300 
0301   if (Enable::HCALOUT_CELL) HCALOuter_Cells();
0302 
0303   //-----------------------------
0304   // CEMC towering and clustering
0305   //-----------------------------
0306 
0307   if (Enable::CEMC_TOWER) CEMC_Towers();
0308   if (Enable::CEMC_CLUSTER) CEMC_Clusters();
0309 
0310   //-----------------------------
0311   // HCAL towering and clustering
0312   //-----------------------------
0313 
0314   if (Enable::HCALIN_TOWER) HCALInner_Towers();
0315   if (Enable::HCALIN_CLUSTER) HCALInner_Clusters();
0316 
0317   if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
0318   if (Enable::HCALOUT_CLUSTER) HCALOuter_Clusters();
0319 
0320   // if enabled, do topoClustering early, upstream of any possible jet reconstruction
0321   if (Enable::TOPOCLUSTER) TopoClusterReco();
0322 
0323   //--------------
0324   // SVTX tracking
0325   //--------------
0326   if(Enable::TRACKING_TRACK)
0327     {
0328       TrackingInit();
0329     }
0330   if (Enable::MVTX_CLUSTER) Mvtx_Clustering();
0331   if (Enable::INTT_CLUSTER) Intt_Clustering();
0332   if (Enable::TPC_CLUSTER) TPC_Clustering();
0333   if (Enable::MICROMEGAS_CLUSTER) Micromegas_Clustering();
0334 
0335   if (Enable::TRACKING_TRACK)
0336   {
0337     Tracking_Reco();
0338   }
0339   //-----------------
0340   // Global Vertexing
0341   //-----------------
0342     /*
0343   if (Enable::GLOBAL_RECO && Enable::GLOBAL_FASTSIM)
0344   {
0345     cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
0346     gSystem->Exit(1);
0347   }
0348   if (Enable::GLOBAL_RECO)
0349   {
0350     Global_Reco();
0351   }
0352   else if (Enable::GLOBAL_FASTSIM)
0353   {
0354     Global_FastSim();
0355   }
0356 */  
0357 
0358   //-----------------
0359   // Centrality Determination
0360   //-----------------
0361 
0362   if (Enable::CENTRALITY)
0363   {
0364       Centrality();
0365   }
0366 
0367   //-----------------
0368   // Calo Trigger Simulation
0369   //-----------------
0370 
0371   if (Enable::CALOTRIGGER)
0372   {
0373     CaloTrigger_Sim();
0374   }
0375 
0376   //---------
0377   // Jet reco
0378   //---------
0379 
0380   if (Enable::JETS) Jet_Reco();
0381   if (Enable::HIJETS) HIJetReco();
0382 
0383   if (Enable::PARTICLEFLOW) ParticleFlow();
0384 
0385   //----------------------
0386   // Simulation evaluation
0387   //----------------------
0388   string outputroot = outputFile;
0389   string remove_this = ".root";
0390   size_t pos = outputroot.find(remove_this);
0391   if (pos != string::npos)
0392   {
0393     outputroot.erase(pos, remove_this.length());
0394   }
0395 
0396   if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "_g4svtx_eval.root");
0397 
0398   if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
0399   
0400   if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
0401 
0402   if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
0403 
0404   if (Enable::JETS_EVAL) Jet_Eval(outputroot + "_g4jet_eval.root");
0405 
0406   if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
0407 
0408   if (Enable::USER) UserAnalysisInit();
0409 
0410 
0411   
0412 
0413   //======================
0414   // Run KFParticle on evt
0415   //======================
0416   if (Enable::KFPARTICLE && Input::UPSILON) KFParticle_Upsilon_Reco();
0417   if (Enable::KFPARTICLE && Input::DZERO) KFParticle_D0_Reco();
0418 
0419   //----------------------
0420   // Standard QAs
0421   //----------------------
0422 
0423   if (Enable::CEMC_QA) CEMC_QA();
0424   if (Enable::HCALIN_QA) HCALInner_QA();
0425   if (Enable::HCALOUT_QA) HCALOuter_QA();
0426 
0427   if (Enable::JETS_QA) Jet_QA();
0428 
0429   if (Enable::MVTX_QA) Mvtx_QA();
0430   if (Enable::INTT_QA) Intt_QA();
0431   if (Enable::TPC_QA) TPC_QA();
0432   if (Enable::MICROMEGAS_QA) Micromegas_QA();
0433   if (Enable::TRACKING_QA) Tracking_QA();
0434 
0435   if (Enable::TRACKING_QA && Enable::CEMC_QA && Enable::HCALIN_QA && Enable::HCALOUT_QA) QA_G4CaloTracking();
0436 
0437   //--------------
0438   // Set up Input Managers
0439   //--------------
0440 
0441   InputManagers();
0442 
0443   if (Enable::PRODUCTION)
0444   {
0445     Production_CreateOutputDir();
0446   }
0447 
0448   if (Enable::DSTOUT)
0449   {
0450     string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
0451     Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
0452     if (Enable::DSTOUT_COMPRESS)
0453     {
0454       ShowerCompress();
0455       DstCompress(out);
0456     }
0457     se->registerOutputManager(out);
0458   }
0459   //-----------------
0460   // Event processing
0461   //-----------------
0462   if (Enable::DISPLAY)
0463   {
0464     DisplayOn();
0465 
0466     gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
0467     gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
0468 
0469     cout << "-------------------------------------------------" << endl;
0470     cout << "You are in event display mode. Run one event with" << endl;
0471     cout << "se->run(1)" << endl;
0472     cout << "Run Geant4 command with following examples" << endl;
0473     gROOT->ProcessLine("displaycmd()");
0474 
0475     return 0;
0476   }
0477 
0478   CaloCalibEmc_Pi0 *eval_pi2 = new CaloCalibEmc_Pi0("dummy", outputroot+"_piemc.root");
0479                                                 // this call is needed for embedding
0480   eval_pi2->set_centrality_nclusters_cut(350);  // which uses more central events
0481                                                 // than we will for data to enhance Bkg
0482                                                 // to match the enhanced signal from embed
0483   se->registerSubsystem(eval_pi2);
0484   cout << "successful registration of pi0 " << endl;
0485 
0486 
0487   // if we use a negative number of events we go back to the command line here
0488   if (nEvents < 0)
0489   {
0490     return 0;
0491   }
0492   // if we run the particle generator and use 0 it'll run forever
0493   // for embedding it runs forever if the repeat flag is set
0494   if (nEvents == 0 && !Input::HEPMC && !Input::READHITS && INPUTEMBED::REPEAT)
0495   {
0496     cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
0497     cout << "it will run forever, so I just return without running anything" << endl;
0498     return 0;
0499   }
0500 
0501   se->skip(skip);
0502   se->run(nEvents);
0503 
0504   //-----
0505   // QA output
0506   //-----
0507 
0508   if (Enable::QA) QA_Output(outputroot + "_qa.root");
0509 
0510   //-----
0511   // Exit
0512   //-----
0513 
0514   se->End();
0515   std::cout << "All done" << std::endl;
0516   delete se;
0517     /*
0518   if (Enable::PRODUCTION)
0519   {
0520     Production_MoveOutput();
0521   }
0522     */
0523   gSystem->Exit(0);
0524   return 0;
0525 }
0526 #endif