Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:11:58

0001 #ifndef MACRO_FUN4ALLG4SPHENIX_C
0002 #define MACRO_FUN4ALLG4SPHENIX_C
0003 
0004 #include <ffamodules/CDBInterface.h>
0005 #include <ffamodules/FlagHandler.h>
0006 #include <ffamodules/HeadReco.h>
0007 #include <ffamodules/SyncReco.h>
0008 #include <filesystem>
0009 #include <string>
0010 
0011 #include <GlobalVariables.C>
0012 
0013 #include <G4Setup_sPHENIX.C>
0014 #include <G4_Centrality.C>
0015 #include <G4_Input.C>
0016 #include <Trkr_Clustering.C>
0017 #include <Trkr_RecoInit.C>
0018 
0019 #include <fun4all/Fun4AllDstInputManager.h>
0020 #include <fun4all/Fun4AllDstOutputManager.h>
0021 #include <fun4all/Fun4AllInputManager.h>
0022 #include <fun4all/Fun4AllOutputManager.h>
0023 #include <fun4all/Fun4AllServer.h>
0024 
0025 #include <calotrigger/MinimumBiasClassifier.h>
0026 #include <centrality/CentralityReco.h>
0027 #include <g4centrality/PHG4CentralityReco.h>
0028 #include <trackreco/PHTruthVertexing.h>
0029 
0030 #include <caloreco/CaloTowerBuilder.h>
0031 #include <caloreco/CaloTowerCalib.h>
0032 #include <calotrigger/MinimumBiasClassifier.h>
0033 #include <centrality/CentralityReco.h>
0034 #include <globalvertex/GlobalVertexReco.h>
0035 #include <mbd/MbdReco.h>
0036 #include <zdcinfo/ZdcReco.h>
0037 
0038 #include <dndetaintt/dNdEtaINTT.h>
0039 
0040 #include <phool/recoConsts.h>
0041 
0042 R__LOAD_LIBRARY(libfun4allraw.so)
0043 R__LOAD_LIBRARY(libffarawmodules.so)
0044 R__LOAD_LIBRARY(libfun4all.so)
0045 R__LOAD_LIBRARY(libffamodules.so)
0046 R__LOAD_LIBRARY(libdNdEtaINTT.so)
0047 R__LOAD_LIBRARY(libcentrality_io.so)
0048 R__LOAD_LIBRARY(libcentrality.so)
0049 R__LOAD_LIBRARY(libg4centrality.so)
0050 R__LOAD_LIBRARY(libcalotrigger.so)
0051 R__LOAD_LIBRARY(libmbd.so)
0052 R__LOAD_LIBRARY(libglobalvertex.so)
0053 // R__LOAD_LIBRARY(libcentralityvalid.so)
0054 R__LOAD_LIBRARY(libzdcinfo.so)
0055 
0056 int Fun4All_G4_sPHENIX(                           //
0057     const bool rundata = false,                   //
0058     const bool getINTTData = true,                //
0059     const int runnumber = 54280,                  //
0060     const string productionTag = "ProdA_2024",    //
0061     const string generator = "HIJING",            // only relevant for simulation
0062     const int nEvents = 10,                       //
0063     const string &outputFile = "testNtuple.root", //
0064     const int process = 0                         //
0065 )
0066 {
0067     // bool getINTTData = true;
0068     bool getCentralityData = (rundata) ? !getINTTData : true;
0069     if (rundata && getINTTData && getCentralityData)
0070     {
0071         std::cout << "We currently can't get INTT and Centrality info from the same file for real data, exiting!" << std::endl;
0072         exit(1);
0073     }
0074 
0075     int skip;
0076     if (rundata)
0077     {
0078         skip = nEvents * process;
0079     }
0080     else
0081     {
0082         skip = 0;
0083     }
0084 
0085     Fun4AllServer *se = Fun4AllServer::instance();
0086     se->Verbosity(1);
0087 
0088     Input::VERBOSITY = 10;
0089     Input::READHITS = true;
0090 
0091     string infile;
0092     if (rundata)
0093     {
0094         if (getINTTData)
0095         {
0096             // Check if the file exists. If not, just use the one that Cameron produced
0097             std::filesystem::path productiondir = std::filesystem::current_path().parent_path() / "production/";
0098             infile = productiondir.string() + "intt-" + std::string(TString::Format("%08d", runnumber).Data()) + ".root";
0099             FILE *file;
0100             file = fopen(infile.c_str(), "r");
0101             if (file == NULL)
0102             {
0103                 std::cout << "File: " << infile << " does not exist. Use the pre-generated file" << std::endl;
0104                 infile = "/sphenix/user/hjheng/sPHENIXRepo/analysis/dNdEta_Run2023/production/ProdDST-HotDead-BCO-ADC-Survey/intt-" + std::string(TString::Format("%08d", runnumber).Data()) + ".root";
0105             }
0106             else
0107             {
0108                 fclose(file);
0109             }
0110 
0111             INPUTREADHITS::filename[0] = infile;
0112         }
0113         else if (getCentralityData) // Generate MBD data list with `CreateDstList.pl --run 20869 --build ana403 --cdb 2023p011 DST_CALO_run1auau`
0114         {
0115             INPUTREADHITS::listfile[0] = "dst_calo_run1auau-000" + std::to_string(runnumber) + "-ana410_2023p014.list";
0116             // INPUTREADHITS::listfile[0] = "dst_calo-000" + std::to_string(runnumber) + ".list";
0117         }
0118     }
0119     else
0120     {
0121         if (generator == "HIJING")
0122         {
0123             // infile = "/sphenix/tg/tg01/bulk/dNdeta_INTT_run2023/data/simulation/ana.457/HIJING/fullSim/magOff/detectorAligned/dstSet_00000/dNdeta-sim-HIJING-000-" + std::string(TString::Format("%05d", process).Data()) + ".root"; // 500K events
0124             // infile = "/sphenix/tg/tg01/bulk/dNdeta_INTT_run2023/data/simulation/ana.457/HIJING/fullSim/magOff/detectorAligned/dstSet_00001/dNdeta-sim-HIJING-000-" + std::string(TString::Format("%05d", process).Data()) + ".root"; // 500K events, adding 40% of strange particles
0125             // infile = "/sphenix/tg/tg01/bulk/dNdeta_INTT_run2023/data/simulation/ana.457/HIJING/fullSim/magOff/detectorAligned/dstSet_00002/dNdeta-sim-HIJING-000-" + std::string(TString::Format("%05d", process).Data()) + ".root"; // 500K events, enable z-clustering
0126 
0127             // Official production - nominal
0128             // INPUTREADHITS::filename[0] = "/sphenix/lustre01/sphnxpro/mdc2/shijing_hepmc/fm_0_20/nopileup/trkrhit/run0026/DST_TRUTH_sHijing_0_20fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root"; // Official production, MDC2
0129             // INPUTREADHITS::filename[1] = "/sphenix/lustre01/sphnxpro/mdc2/shijing_hepmc/fm_0_20/nopileup/trkrhit/run0026/DST_TRKR_HIT_sHijing_0_20fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root"; // Official production, MDC2
0130             // INPUTREADHITS::filename[2] = "/sphenix/lustre01/sphnxpro/mdc2/shijing_hepmc/fm_0_20/nopileup/trkrcluster/run0026/DST_TRKR_CLUSTER_sHijing_0_20fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root"; // Official production, MDC2
0131             // INPUTREADHITS::filename[3] = "/sphenix/lustre01/sphnxpro/mdc2/shijing_hepmc/fm_0_20/nopileup/mbdepd/run0026/DST_MBD_EPD_sHijing_0_20fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root"; // Official production, MDC2
0132 
0133             // Official production - enhanced strangeness
0134             INPUTREADHITS::filename[0] = "/sphenix/lustre01/sphnxpro/mdc2/shijing_hepmc/fm_0_20/nopileup/trkrhit/run0027/DST_TRUTH_sHijing_0_20fm-0000000027-" + std::string(TString::Format("%06d", process).Data()) + ".root";            // Official production, MDC2
0135             INPUTREADHITS::filename[1] = "/sphenix/lustre01/sphnxpro/mdc2/shijing_hepmc/fm_0_20/nopileup/trkrhit/run0027/DST_TRKR_HIT_sHijing_0_20fm-0000000027-" + std::string(TString::Format("%06d", process).Data()) + ".root";         // Official production, MDC2
0136             INPUTREADHITS::filename[2] = "/sphenix/lustre01/sphnxpro/mdc2/shijing_hepmc/fm_0_20/nopileup/trkrcluster/run0027/DST_TRKR_CLUSTER_sHijing_0_20fm-0000000027-" + std::string(TString::Format("%06d", process).Data()) + ".root"; // Official production, MDC2
0137             INPUTREADHITS::filename[3] = "/sphenix/lustre01/sphnxpro/mdc2/shijing_hepmc/fm_0_20/nopileup/mbdepd/run0027/DST_MBD_EPD_sHijing_0_20fm-0000000027-" + std::string(TString::Format("%06d", process).Data()) + ".root";           // Official production, MDC2
0138         }
0139         else if (generator == "EPOS")
0140         {
0141             // infile = "/sphenix/tg/tg01/bulk/dNdeta_INTT_run2023/data/simulation/ana.419/EPOS/fullSim/magOff/detectorMisaligned/dstSet_00000/dNdeta-sim-EPOS-000-" + std::string(TString::Format("%05d", process).Data()) + ".root";
0142 
0143             INPUTREADHITS::filename[0] = "/sphenix/lustre01/sphnxpro/mdc2/epos/nopileup/trkrhit/run0026/DST_TRUTH_epos_0_153fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root";            // Official production, MDC2
0144             INPUTREADHITS::filename[1] = "/sphenix/lustre01/sphnxpro/mdc2/epos/nopileup/trkrhit/run0026/DST_TRKR_HIT_epos_0_153fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root";         // Official production, MDC2
0145             INPUTREADHITS::filename[2] = "/sphenix/lustre01/sphnxpro/mdc2/epos/nopileup/trkrcluster/run0026/DST_TRKR_CLUSTER_epos_0_153fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root"; // Official production, MDC2
0146             INPUTREADHITS::filename[3] = "/sphenix/lustre01/sphnxpro/mdc2/epos/nopileup/mbdepd/run0026/DST_MBD_EPD_epos_0_153fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root";           // Official production, MDC2
0147         }
0148         else if (generator == "AMPT")
0149         {
0150             // infile = "/sphenix/tg/tg01/bulk/dNdeta_INTT_run2023/data/simulation/ana.419/AMPT/fullSim/magOff/detectorMisaligned/dstSet_00000/dNdeta-sim-AMPT-000-" + std::string(TString::Format("%05d", process).Data()) + ".root";
0151 
0152             INPUTREADHITS::filename[0] = "/sphenix/lustre01/sphnxpro/mdc2/ampt/nopileup/trkrhit/run0026/DST_TRUTH_ampt_0_20fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root";            // Official production, MDC2
0153             INPUTREADHITS::filename[1] = "/sphenix/lustre01/sphnxpro/mdc2/ampt/nopileup/trkrhit/run0026/DST_TRKR_HIT_ampt_0_20fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root";         // Official production, MDC2
0154             INPUTREADHITS::filename[2] = "/sphenix/lustre01/sphnxpro/mdc2/ampt/nopileup/trkrcluster/run0026/DST_TRKR_CLUSTER_ampt_0_20fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root"; // Official production, MDC2
0155             INPUTREADHITS::filename[3] = "/sphenix/lustre01/sphnxpro/mdc2/ampt/nopileup/mbdepd/run0026/DST_MBD_EPD_ampt_0_20fm-0000000026-" + std::string(TString::Format("%06d", process).Data()) + ".root";           // Official production, MDC2
0156         }
0157         else if (generator == "SIMPLE")
0158         {
0159             infile = "/sphenix/tg/tg01/bulk/dNdeta_INTT_run2023/data/simulation/ana.474/SIMPLE/e-/fullSim/magOff/detectorAligned/dstSet_00001/dNdeta-sim-SIMPLE-e--000-" + std::string(TString::Format("%05d", process).Data()) + ".root";
0160             INPUTREADHITS::filename[0] = infile;
0161         }
0162         else
0163         {
0164             std::cout << "Generator " << generator << " is not [HIJING, EPOS, AMPT, SIMPLE]. Exit" << std::endl;
0165             return 0;
0166         }
0167     }
0168 
0169     // register all input generators with Fun4All
0170     // InputRegister();
0171 
0172     Enable::MBD = getINTTData;
0173     Enable::MBDRECO = getCentralityData || !rundata;
0174     Enable::PIPE = getINTTData;
0175     Enable::MVTX = getINTTData;
0176     Enable::INTT = getINTTData;
0177     Enable::INTT_VERBOSITY = 0;
0178     Enable::TPC = getINTTData;
0179     Enable::MICROMEGAS = getINTTData;
0180 
0181     //===============
0182     // conditions DB flags
0183     //===============
0184     recoConsts *rc = recoConsts::instance();
0185     Enable::CDB = true;
0186     Enable::VERBOSITY = 0;
0187     rc->set_StringFlag("CDB_GLOBALTAG", productionTag);
0188     rc->set_uint64Flag("TIMESTAMP", runnumber);
0189     rc->set_IntFlag("RUNNUMBER", runnumber);
0190 
0191     if (getINTTData)
0192     {
0193         G4Init();
0194         G4Setup();
0195 
0196         // Load ActsGeometry object
0197         TrackingInit();
0198         // Reco clustering
0199         // if (rundata)
0200         // Intt_Clustering();
0201     }
0202 
0203     if (getCentralityData) // when running on real data for MBD ntuples or when running on simulation
0204     {
0205         // if (!rundata)
0206         //     Mbd_Reco();
0207 
0208         MbdReco *mbdreco = new MbdReco();
0209         mbdreco->Verbosity(0);
0210         se->registerSubsystem(mbdreco);
0211 
0212         GlobalVertexReco *gblvertex = new GlobalVertexReco();
0213         gblvertex->Verbosity(INT_MAX - 1);
0214         se->registerSubsystem(gblvertex);
0215 
0216         // CaloTowerDefs::BuilderType buildertype = CaloTowerDefs::kPRDFTowerv4;
0217         // CaloTowerBuilder *caZDC = new CaloTowerBuilder("ZDCBUILDER");
0218         // caZDC->set_detector_type(CaloTowerDefs::ZDC);
0219         // caZDC->set_builder_type(buildertype);
0220         // caZDC->set_processing_type(CaloWaveformProcessing::FAST);
0221         // caZDC->set_nsamples(16);
0222         // caZDC->set_offlineflag();
0223         // se->registerSubsystem(caZDC);
0224 
0225         // std::cout << "Calibrating ZDC" << std::endl;
0226         // CaloTowerCalib *calibZDC = new CaloTowerCalib("ZDC");
0227         // calibZDC->set_detector_type(CaloTowerDefs::ZDC);
0228         // se->registerSubsystem(calibZDC); // conditions DB flags
0229 
0230         // ZDC Reconstruction--Calib Info
0231         // ZdcReco *zdcreco = new ZdcReco();
0232         // zdcreco->set_zdc1_cut(0.0);
0233         // zdcreco->set_zdc2_cut(0.0);
0234         // se->registerSubsystem(zdcreco);
0235 
0236         MinimumBiasClassifier *mb = new MinimumBiasClassifier();
0237         mb->Verbosity(INT_MAX - 1);
0238         mb->setIsSim(!rundata);
0239         mb->setOverwriteScale("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/scales/cdb_centrality_scale_1.root");
0240         mb->setOverwriteVtx("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/vertexscales/cdb_centrality_vertex_scale_1.root");
0241         se->registerSubsystem(mb);
0242 
0243         CentralityReco *cr = new CentralityReco();
0244         cr->Verbosity(INT_MAX - 1);
0245         if (generator == "HIJING")
0246         {
0247             cr->setOverwriteScale("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/scales/cdb_centrality_scale_1.root");
0248             cr->setOverwriteVtx("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/vertexscales/cdb_centrality_vertex_scale_1.root");
0249             cr->setOverwriteDivs("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/divs/cdb_centrality_1.root");
0250         }
0251         else if (generator == "EPOS")
0252         {
0253             cr->setOverwriteScale("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/divs/cdb_centrality_scale_epos_magoff.root");
0254             cr->setOverwriteVtx("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/vertexscales/cdb_centrality_vertex_scale_epos_magoff.root");
0255             cr->setOverwriteDivs("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/divs/cdb_centrality_epos_magoff.root");
0256         }
0257         else if (generator == "AMPT")
0258         {
0259             cr->setOverwriteScale("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/divs/cdb_centrality_scale_ampt_magoff.root");
0260             cr->setOverwriteVtx("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/vertexscales/cdb_centrality_vertex_scale_ampt_magoff.root");
0261             cr->setOverwriteDivs("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/divs/cdb_centrality_ampt_magoff.root");
0262         }
0263         else
0264         {
0265             std::cout << "Generator " << generator << " is not [HIJING, EPOS, AMPT]. Use HIJING as default" << std::endl;
0266             cr->setOverwriteScale("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/scales/cdb_centrality_scale_1.root");
0267             cr->setOverwriteVtx("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/vertexscales/cdb_centrality_vertex_scale_1.root");
0268             cr->setOverwriteDivs("/sphenix/user/dlis/Projects/centrality/cdb/calibrations/divs/cdb_centrality_1.root");
0269         }
0270         se->registerSubsystem(cr);
0271     }
0272 
0273     if (!rundata)
0274     {
0275         auto vtxing = new PHTruthVertexing;
0276         vtxing->associate_tracks(false);
0277         se->registerSubsystem(vtxing);
0278     }
0279 
0280     if (rundata && getCentralityData)
0281     {
0282         MinimumBiasClassifier *mb = new MinimumBiasClassifier();
0283         mb->Verbosity(0);
0284         se->registerSubsystem(mb);
0285     }
0286 
0287     dNdEtaINTT *myAnalyzer = new dNdEtaINTT("dNdEtaAnalyzer", outputFile, rundata);
0288     myAnalyzer->GetINTTdata(getINTTData || !rundata);
0289     myAnalyzer->GetRecoCluster(getINTTData || !rundata);
0290     myAnalyzer->GetTruthCluster(getINTTData || !rundata);
0291     myAnalyzer->GetInttRawHit(false);
0292     myAnalyzer->GetTrkrHit(getINTTData || !rundata); // disable for the official production, no TRKR_HITSET node
0293     myAnalyzer->GetCentrality(getCentralityData);
0294     // bool getPMTinfo = getCentralityData && false;
0295     myAnalyzer->GetPMTInfo(getCentralityData);
0296     myAnalyzer->GetPHG4(!rundata);
0297     myAnalyzer->GetAllPHG4(!rundata);
0298     if (!rundata)
0299     {
0300         if (generator == "SIMPLE")
0301             myAnalyzer->GetHEPMC(false);
0302         else
0303             myAnalyzer->GetHEPMC(true);
0304     }
0305     myAnalyzer->GetTrigger(rundata);
0306 
0307     se->registerSubsystem(myAnalyzer);
0308 
0309     //--------------
0310     // Set up Input Managers
0311     //--------------
0312     InputManagers();
0313 
0314     //-----------------
0315     // Event processing
0316     //-----------------
0317     se->skip(skip);
0318     se->run(nEvents);
0319 
0320     //-----
0321     // Exit
0322     //-----
0323     se->End();
0324     std::cout << "All done" << std::endl;
0325     delete se;
0326 
0327     gSystem->Exit(0);
0328     return 0;
0329 }
0330 #endif