Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef MACRO_NOBKGDSUBJETRECO_C
0002 #define MACRO_NOBKGDSUBJETRECO_C
0003 
0004 #include <GlobalVariables.C>
0005 
0006 #include <g4jets/TruthJetInput.h>
0007 
0008 #include <globalvertex/GlobalVertex.h>
0009 
0010 #include <jetbackground/FastJetAlgoSub.h>
0011 #include <jetbackground/RetowerCEMC.h>
0012 
0013 #include <jetbase/FastJetOptions.h>
0014 #include <jetbase/JetReco.h>
0015 #include <jetbase/TowerJetInput.h>
0016 #include <jetbase/TrackJetInput.h>
0017 
0018 #include <particleflowreco/ParticleFlowJetInput.h>
0019 
0020 #include <fun4all/Fun4AllServer.h>
0021 
0022 #include <Rtypes.h>  // resolves R__LOAD_LIBRARY for clang-tidy
0023 
0024 R__LOAD_LIBRARY(libg4jets.so)
0025 R__LOAD_LIBRARY(libjetbackground.so)
0026 R__LOAD_LIBRARY(libjetbase.so)
0027 R__LOAD_LIBRARY(libparticleflow.so)
0028 
0029 // ----------------------------------------------------------------------------
0030 //! General options for no subtraction (NS) jet reconstruction
0031 // ----------------------------------------------------------------------------
0032 namespace Enable
0033 {
0034   int NSJETS_VERBOSITY = 0;   ///< verbosity
0035   bool NSJETS = false;        ///< do no-subtraction jet reco
0036   bool NSJETS_MC = false;     ///< is simulation
0037   bool NSJETS_TRUTH = false;  ///< make truth jets
0038   bool NSJETS_TOWER = false;  ///< make tower jets
0039   bool NSJETS_TRACK = true;   ///< make track jets
0040   bool NSJETS_PFLOW = false;  ///< make particle flow jets
0041 }  // end namespace Enable
0042 
0043 // ----------------------------------------------------------------------------
0044 //! Options specific to no subtraction jet reconstruction
0045 // ----------------------------------------------------------------------------
0046 namespace NSJETS
0047 {
0048   ///! turn on/off functionality only relevant for
0049   ///! nucleon collisions
0050   bool is_pp = false;
0051 
0052   ///! sets prefix of nodes to use as tower jet
0053   ///! input
0054   std::string tower_prefix = "TOWERINFO_CALIB";
0055 
0056   ///! if true, sets vertex type to type specified
0057   ///! by vertex_type
0058   bool do_vertex_type = true;
0059 
0060   ///! specifies type of vertex to use
0061   GlobalVertex::VTXTYPE vertex_type = GlobalVertex::MBD;
0062 
0063   ///! Base fastjet options to use. Note that the
0064   ///! resolution parameter will be overwritten
0065   ///! to R = 0.2, 0.3, 0.4, and 0.5
0066   FastJetOptions fj_opts({Jet::ANTIKT, JET_R, 0.4, VERBOSITY, static_cast<float>(Enable::NSJETS_VERBOSITY)});
0067 
0068   ///! sets jet node name
0069   std::string jet_node = "ANTIKT";
0070 
0071   ///! sets prefix of nodes to store jets
0072   std::string algo_prefix = "AntiKt";
0073 
0074   ///! enumerates reconstructed resolution
0075   ///! parameters
0076   enum Res
0077   {
0078     R02 = 0,
0079     R03 = 1,
0080     R04 = 2,
0081     R05 = 3
0082   };
0083 
0084   // --------------------------------------------------------------------------
0085   //! Helper method to generate releveant FastJet algorithms
0086   // --------------------------------------------------------------------------
0087   FastJetAlgoSub* GetFJAlgo(const float reso)
0088   {
0089     // grab current options & update
0090     // reso parameter
0091     FastJetOptions opts = fj_opts;
0092     opts.jet_R = reso;
0093 
0094     // create new algorithm
0095     return new FastJetAlgoSub(opts);
0096 
0097   }  // end 'GetFJAlgo()'
0098 }  // end namespace NSJETS
0099 
0100 // ----------------------------------------------------------------------------
0101 //! Make jets out of appropriate truth particles
0102 // ----------------------------------------------------------------------------
0103 void MakeNSTruthJets()
0104 {
0105   // set verbosity
0106   int verbosity = std::max(Enable::VERBOSITY, Enable::NSJETS_VERBOSITY);
0107 
0108   //---------------
0109   // Fun4All server
0110   //---------------
0111   Fun4AllServer* se = Fun4AllServer::instance();
0112 
0113   // if making track jets, make truth jets out of only charged particles
0114   if (Enable::NSJETS_TRACK)
0115   {
0116     // book jet reconstruction on charged FS particles
0117     JetReco* chrgTruthJets = new JetReco();
0118     chrgTruthJets->add_input(new TruthJetInput(Jet::SRC::CHARGED_PARTICLE));
0119     chrgTruthJets->add_algo(NSJETS::GetFJAlgo(0.2), NSJETS::algo_prefix + "_ChargedTruth_r02");
0120     chrgTruthJets->add_algo(NSJETS::GetFJAlgo(0.3), NSJETS::algo_prefix + "_ChargedTruth_r03");
0121     chrgTruthJets->add_algo(NSJETS::GetFJAlgo(0.4), NSJETS::algo_prefix + "_ChargedTruth_r04");
0122     chrgTruthJets->add_algo(NSJETS::GetFJAlgo(0.5), NSJETS::algo_prefix + "_ChargedTruth_r05");
0123     chrgTruthJets->set_algo_node(NSJETS::jet_node);
0124     chrgTruthJets->set_input_node("TRUTH");
0125     chrgTruthJets->Verbosity(verbosity);
0126     se->registerSubsystem(chrgTruthJets);
0127   }
0128 
0129   // if making tower or pflow jets, make truth jets out of all particles
0130   if (Enable::NSJETS_TOWER || Enable::NSJETS_PFLOW)
0131   {
0132     // book jet reconstruction on all particles
0133     JetReco* fullTruthJets = new JetReco();
0134     fullTruthJets->add_input(new TruthJetInput(Jet::PARTICLE));
0135     fullTruthJets->add_algo(NSJETS::GetFJAlgo(0.2), NSJETS::algo_prefix + "_Truth_r02");
0136     fullTruthJets->add_algo(NSJETS::GetFJAlgo(0.3), NSJETS::algo_prefix + "_Truth_r03");
0137     fullTruthJets->add_algo(NSJETS::GetFJAlgo(0.4), NSJETS::algo_prefix + "_Truth_r04");
0138     fullTruthJets->add_algo(NSJETS::GetFJAlgo(0.5), NSJETS::algo_prefix + "_Truth_r05");
0139     fullTruthJets->set_algo_node(NSJETS::jet_node);
0140     fullTruthJets->set_input_node("TRUTH");
0141     fullTruthJets->Verbosity(verbosity);
0142     se->registerSubsystem(fullTruthJets);
0143   }
0144 
0145   // exit back to NoBkdSubJetReco()
0146   return;
0147 
0148 }  // end 'MakeNSTruthJets()'
0149 
0150 // ----------------------------------------------------------------------------
0151 //! Make jets out of unsubtracted towers
0152 // ----------------------------------------------------------------------------
0153 void MakeNSTowerJets()
0154 {
0155   // set verbosity
0156   int verbosity = std::max(Enable::VERBOSITY, Enable::NSJETS_VERBOSITY);
0157 
0158   //---------------
0159   // Fun4All server
0160   //---------------
0161   Fun4AllServer* se = Fun4AllServer::instance();
0162 
0163   // retower the emcal to match I/OHCal granularity
0164   RetowerCEMC* rcemc = new RetowerCEMC();
0165   rcemc->Verbosity(verbosity);
0166   rcemc->set_towerinfo(true);
0167   rcemc->set_frac_cut(0.5);  // fraction of retower that must be masked to mask the full retower
0168   rcemc->set_towerNodePrefix(NSJETS::tower_prefix);
0169   se->registerSubsystem(rcemc);
0170 
0171   // create tower jet input and set vertex type
0172   TowerJetInput* emTwrInput = new TowerJetInput(Jet::CEMC_TOWERINFO_RETOWER, NSJETS::tower_prefix);
0173   TowerJetInput* ihTwrInput = new TowerJetInput(Jet::HCALIN_TOWERINFO, NSJETS::tower_prefix);
0174   TowerJetInput* ohTwrInput = new TowerJetInput(Jet::HCALOUT_TOWERINFO, NSJETS::tower_prefix);
0175   if (NSJETS::do_vertex_type)
0176   {
0177     emTwrInput->set_GlobalVertexType(NSJETS::vertex_type);
0178     ihTwrInput->set_GlobalVertexType(NSJETS::vertex_type);
0179     ohTwrInput->set_GlobalVertexType(NSJETS::vertex_type);
0180   }
0181 
0182   // book jet reconstruction on towers
0183   JetReco* twrRecoJets = new JetReco();
0184   twrRecoJets->add_input(emTwrInput);
0185   twrRecoJets->add_input(ihTwrInput);
0186   twrRecoJets->add_input(ohTwrInput);
0187   twrRecoJets->add_algo(NSJETS::GetFJAlgo(0.2), NSJETS::algo_prefix + "_Tower_r02");
0188   twrRecoJets->add_algo(NSJETS::GetFJAlgo(0.3), NSJETS::algo_prefix + "_Tower_r03");
0189   twrRecoJets->add_algo(NSJETS::GetFJAlgo(0.4), NSJETS::algo_prefix + "_Tower_r04");
0190   twrRecoJets->add_algo(NSJETS::GetFJAlgo(0.5), NSJETS::algo_prefix + "_Tower_r05");
0191   twrRecoJets->set_algo_node(NSJETS::jet_node);
0192   twrRecoJets->set_input_node("TOWER");
0193   twrRecoJets->Verbosity(verbosity);
0194   se->registerSubsystem(twrRecoJets);
0195 
0196   // exit back to NoBkgdSubJetReco()
0197   return;
0198 
0199 }  // end 'MakeNSTowerJets()'
0200 
0201 // ----------------------------------------------------------------------------
0202 //! Make jets out of tracks without background subtraction
0203 // ----------------------------------------------------------------------------
0204 void MakeNSTrackJets()
0205 {
0206   // set verbosity
0207   int verbosity = std::max(Enable::VERBOSITY, Enable::NSJETS_VERBOSITY);
0208 
0209   //---------------
0210   // Fun4All server
0211   //---------------
0212   Fun4AllServer* se = Fun4AllServer::instance();
0213 
0214   // book jet reconstruction routines on tracks
0215   JetReco* trkRecoJets = new JetReco();
0216   trkRecoJets->add_input(new TrackJetInput(Jet::SRC::TRACK));
0217   trkRecoJets->add_algo(NSJETS::GetFJAlgo(0.2), NSJETS::algo_prefix + "_Track_r02");
0218   trkRecoJets->add_algo(NSJETS::GetFJAlgo(0.3), NSJETS::algo_prefix + "_Track_r03");
0219   trkRecoJets->add_algo(NSJETS::GetFJAlgo(0.4), NSJETS::algo_prefix + "_Track_r04");
0220   trkRecoJets->add_algo(NSJETS::GetFJAlgo(0.5), NSJETS::algo_prefix + "_Track_r05");
0221   trkRecoJets->set_algo_node(NSJETS::jet_node);
0222   trkRecoJets->set_input_node("TRACK");
0223   trkRecoJets->Verbosity(verbosity);
0224   se->registerSubsystem(trkRecoJets);
0225 
0226   // exit back to NoBkgdSubJetReco()
0227   return;
0228 
0229 }  // end 'MakeNSTrackJets()'
0230 
0231 // ----------------------------------------------------------------------------
0232 //! Make jets out of particle-flow elements without background subtraction
0233 // ----------------------------------------------------------------------------
0234 void MakeNSPFlowJets()
0235 {
0236   // set verbosity
0237   int verbosity = std::max(Enable::VERBOSITY, Enable::NSJETS_VERBOSITY);
0238 
0239   //---------------
0240   // Fun4All server
0241   //---------------
0242   Fun4AllServer* se = Fun4AllServer::instance();
0243 
0244   // book jet reconstruction routines on pflow elements
0245   JetReco* pfRecoJets = new JetReco();
0246   pfRecoJets->add_input(new ParticleFlowJetInput());
0247   pfRecoJets->add_algo(NSJETS::GetFJAlgo(0.2), NSJETS::algo_prefix + "_ParticleFlow_r02");
0248   pfRecoJets->add_algo(NSJETS::GetFJAlgo(0.3), NSJETS::algo_prefix + "_ParticleFlow_r03");
0249   pfRecoJets->add_algo(NSJETS::GetFJAlgo(0.4), NSJETS::algo_prefix + "_ParticleFlow_r04");
0250   pfRecoJets->add_algo(NSJETS::GetFJAlgo(0.5), NSJETS::algo_prefix + "_ParticleFlow_r05");
0251   pfRecoJets->set_algo_node(NSJETS::jet_node);
0252   pfRecoJets->set_input_node("ELEMENT");
0253   pfRecoJets->Verbosity(verbosity);
0254   se->registerSubsystem(pfRecoJets);
0255 
0256   // exit back to NoBkgdSubJetReco()
0257   return;
0258 
0259 }  // end 'MakeNSPFlowJets()'
0260 
0261 // ----------------------------------------------------------------------------
0262 //! Run jet reconstruction without background subtraction
0263 // ----------------------------------------------------------------------------
0264 void NoBkgdSubJetReco()
0265 {
0266   // if simulation, make appropriate truth jets
0267   if (Enable::NSJETS_MC && Enable::NSJETS_TRUTH)
0268   {
0269     MakeNSTruthJets();
0270   }
0271 
0272   // run approriate jet reconstruction routines
0273   if (Enable::NSJETS_TOWER)
0274   {
0275     MakeNSTowerJets();
0276   }
0277   if (Enable::NSJETS_TRACK)
0278   {
0279     MakeNSTrackJets();
0280   }
0281   if (Enable::NSJETS_PFLOW)
0282   {
0283     MakeNSPFlowJets();
0284   }
0285 
0286 }  // end 'NoBkgdSubJetReco()'
0287 
0288 #endif