Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:24:05

0001 #ifndef FUN4ALL_JETPRODUCTIONYEAR2_C
0002 #define FUN4ALL_JETPRODUCTIONYEAR2_C
0003 
0004 #include <GlobalVariables.C>
0005 
0006 #include <G4_ActsGeom.C>
0007 #include <G4_Centrality.C>
0008 #include <G4_Global.C>
0009 #include <G4_Magnet.C>
0010 #include <HIJetReco.C>  // n.b. needed for rho calculation
0011 #include <NoBkgdSubJetReco.C>
0012 #include <Jet_QA.C>
0013 #include <QA.C>
0014 #include <Trkr_Reco.C>
0015 #include <Trkr_RecoInit.C>
0016 #include <Trkr_TpcReadoutInit.C>
0017 
0018 #include <g4centrality/PHG4CentralityReco.h>
0019 
0020 #include <globalvertex/GlobalVertexReco.h>
0021 
0022 #include <jetbackground/BeamBackgroundFilterAndQA.h>
0023 
0024 #include <mbd/MbdReco.h>
0025 
0026 #include <zdcinfo/ZdcReco.h>
0027 
0028 #include <qautils/QAHistManagerDef.h>
0029 
0030 #include <ffamodules/CDBInterface.h>
0031 #include <ffamodules/FlagHandler.h>
0032 
0033 #include <fun4all/Fun4AllDstInputManager.h>
0034 #include <fun4all/Fun4AllDstOutputManager.h>
0035 #include <fun4all/Fun4AllInputManager.h>
0036 #include <fun4all/Fun4AllRunNodeInputManager.h>
0037 #include <fun4all/Fun4AllServer.h>
0038 #include <fun4all/Fun4AllUtils.h>
0039 
0040 #include <phool/recoConsts.h>
0041 
0042 #include <fstream>
0043 #include <iostream>
0044 #include <optional>
0045 #include <string>
0046 #include <utility>
0047 #include <vector>
0048 
0049 // load libraries
0050 R__LOAD_LIBRARY(libcentrality.so)
0051 R__LOAD_LIBRARY(libg4centrality.so)
0052 R__LOAD_LIBRARY(libglobalvertex.so)
0053 R__LOAD_LIBRARY(libfun4all.so)
0054 R__LOAD_LIBRARY(libffamodules.so)
0055 R__LOAD_LIBRARY(libjetbackground.so)
0056 R__LOAD_LIBRARY(libjetqa.so)
0057 R__LOAD_LIBRARY(libmbd.so)
0058 R__LOAD_LIBRARY(libqautils.so)
0059 R__LOAD_LIBRARY(libzdcinfo.so)
0060 
0061 
0062 
0063 // ============================================================================
0064 //! Jet production macro for year 2 (pp)
0065 // ============================================================================
0066 /*! Jet production macro for pp-running in year 2. Currently used for
0067  *  producing for QA. Can be adapted for production of JET DSTs in the
0068  *  future.
0069  *
0070  *  Necessary inputs:
0071  *    - For calo jets:
0072  *      - DST_CALO
0073  *    - For track jets:
0074  *      - DST_CALO (for beam background filter)
0075  *      - DST_TRKR_TRACKS
0076  *      - DST_TRKR_CLUSTER (for tracks-in-jets QA)
0077  */
0078 void Fun4All_JetProductionYear2(
0079   const int nEvents = 0,
0080   const bool useTwrs = true,
0081   const bool useTrks = false,
0082   const bool useFlow = false,
0083   const std::vector<std::string>& inlists = {
0084     "./input/dsts_calo_run2pp-00053877.goldenTrkCaloRun_allSeg.list",
0085     "./input/dsts_clust_run2pp-00053877.goldenTrkCaloRun_allSeg.list",
0086     "./input/dsts_track_run2pp-00053877.goldenTrkCaloRun_allSeg.list"
0087   },
0088   const std::string& outfile = "DST_JET-00053877-0000.root",
0089   const std::string& outfile_hist = "HIST_JETQA-00053877-0000.year2_trackandcalotest.root",
0090   const std::string& dbtag = "ProdA_2024"
0091 ) {
0092 
0093   // set options --------------------------------------------------------------
0094 
0095   // turn on/off DST output and/or QA
0096   Enable::DSTOUT           = false;
0097   Enable::QA               = true;
0098   Enable::NSJETS_VERBOSITY = 0;
0099   Enable::JETQA_VERBOSITY  = std::max(Enable::VERBOSITY, Enable::NSJETS_VERBOSITY);
0100 
0101   // jet reco options
0102   Enable::NSJETS         = true;
0103   Enable::NSJETS_TOWER   = useTwrs;
0104   Enable::NSJETS_TRACK   = useTrks;
0105   Enable::NSJETS_PFLOW   = useFlow;
0106   NSJETS::is_pp          = true;
0107   NSJETS::do_vertex_type = true;
0108   NSJETS::vertex_type    = Enable::NSJETS_TRACK ? GlobalVertex::SVTX : GlobalVertex::MBD;
0109 
0110   // make sure HIJetReco inputs are the same
0111   // for rho calculation
0112   Enable::HIJETS_TOWER = Enable::NSJETS_TOWER;
0113   Enable::HIJETS_TRACK = Enable::NSJETS_TRACK;
0114   Enable::HIJETS_PFLOW = Enable::NSJETS_PFLOW;
0115 
0116   // qa options
0117   JetQA::DoInclusive      = true;
0118   JetQA::DoTriggered      = true;
0119   JetQA::DoPP             = NSJETS::is_pp;
0120   JetQA::UseBkgdSub       = false;
0121   JetQA::RestrictPtToTrig = false;
0122   JetQA::RestrictEtaByR   = true;
0123   JetQA::HasTracks        = Enable::NSJETS_TRACK || Enable::NSJETS_PFLOW;
0124   JetQA::HasCalos         = Enable::NSJETS_TOWER || Enable::NSJETS_PFLOW;
0125 
0126   // tracking options
0127   G4TPC::ENABLE_MODULE_EDGE_CORRECTIONS = true;
0128   Enable::MVTX_APPLYMISALIGNMENT        = true;
0129   ACTSGEOM::mvtx_applymisalignment      = Enable::MVTX_APPLYMISALIGNMENT;
0130   TRACKING::pp_mode                     = NSJETS::is_pp;
0131 
0132   // initialize interfaces, register inputs -----------------------------------
0133 
0134   // initialize F4A server
0135   Fun4AllServer* se = Fun4AllServer::instance();
0136   se->Verbosity(1);
0137 
0138   // grab 1st file from input lists
0139   std::ifstream files(inlists.front());
0140   std::string first;
0141   std::getline(files, first);
0142 
0143   // grab run and segment no.s
0144   std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(first);
0145   int runnumber = runseg.first;
0146 
0147   // set up reconstruction constants, DB tag, timestamp
0148   recoConsts* rc = recoConsts::instance();
0149   rc->set_StringFlag("CDB_GLOBALTAG", dbtag);
0150   rc->set_uint64Flag("TIMESTAMP", runnumber);
0151 
0152   // connect to conditions database
0153   CDBInterface* cdb = CDBInterface::instance();
0154   cdb->Verbosity(1);
0155 
0156   // set up flag handler
0157   FlagHandler* flag = new FlagHandler();
0158   se->registerSubsystem(flag);
0159 
0160   // read in input
0161   for (std::size_t iin = 0; iin < inlists.size(); ++iin)
0162   {
0163     Fun4AllInputManager* indst = new Fun4AllDstInputManager("indst" + std::to_string(iin));
0164     indst->AddListFile(inlists[iin]);
0165     se->registerInputManager(indst);
0166   }
0167 
0168   // set up tracking
0169   if (JetQA::HasTracks)
0170   {
0171     // register tracking geometry
0172     Fun4AllRunNodeInputManager* ingeom = new Fun4AllRunNodeInputManager("ingeom");
0173     ingeom->AddFile(cdb->getUrl("Tracking_Geometry"));
0174     se->registerInputManager(ingeom);
0175 
0176     // initialize tracking
0177     TpcReadoutInit(runnumber);
0178     TrackingInit();
0179   }
0180 
0181   // register reconstruction modules ------------------------------------------
0182 
0183   // do vertex & centrality reconstruction
0184   Global_Reco();
0185   if (!NSJETS::is_pp)
0186   {
0187     Centrality();
0188   }
0189 
0190   // filter out beam-background events (use default parameters for
0191   // streak-sideband filter)
0192   BeamBackgroundFilterAndQA* filter = new BeamBackgroundFilterAndQA("BeamBackgroundFilterAndQA");
0193   filter->Verbosity(std::max(Enable::QA_VERBOSITY, Enable::JETQA_VERBOSITY));
0194   filter->SetConfig(
0195     {
0196       .debug          = false,
0197       .doQA           = Enable::QA,
0198       .doEvtAbort     = false,
0199       .filtersToApply = {"StreakSideband"}
0200     }
0201   );
0202   se->registerSubsystem(filter);
0203 
0204   // do jet reconstruction
0205   NoBkgdSubJetReco();
0206 
0207   // register modules necessary for QA
0208   if (Enable::QA)
0209   {
0210     DoRhoCalculation();
0211     Jet_QA();
0212   }
0213 
0214   // if needed, save DST output
0215   if (Enable::DSTOUT)
0216   {
0217     Fun4AllDstOutputManager* out = new Fun4AllDstOutputManager("DSTOUT", outfile);
0218     out->StripNode("CEMCPackets");
0219     out->StripNode("HCALPackets");
0220     out->StripNode("ZDCPackets");
0221     out->StripNode("SEPDPackets");
0222     out->StripNode("MBDPackets");
0223     se->registerOutputManager(out);
0224   }
0225 
0226   // run & exit ---------------------------------------------------------------
0227 
0228   // run4all
0229   se->run(nEvents);
0230   se->End();
0231 
0232   // if needed, save QA output
0233   if (Enable::QA)
0234   {
0235     QAHistManagerDef::saveQARootFile(outfile_hist);
0236   }
0237 
0238   // print used DB files, time elapsed and delete server
0239   cdb->Print();
0240   se->PrintTimer();
0241   delete se;
0242 
0243   // announce end and exit
0244   std::cout << "Jets are done!" << std::endl;
0245   gSystem->Exit(0);
0246 
0247 }
0248 
0249 #endif
0250 
0251 // end ------------------------------------------------------------------------