Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:26

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