Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:13:20

0001 /// ---------------------------------------------------------------------------
0002 /*! \file   GEvtTools.cc
0003  *  \author Derek Anderson
0004  *  \date   03.06.2024
0005  *
0006  *  Collection of frequent event-level generator methods utilized
0007  *  in the sPHENIX Cold QCD Energy-Energy Correlator analysis.
0008  */
0009 /// ---------------------------------------------------------------------------
0010 
0011 #define SCORRELATORUTILITIES_GEVTTOOLS_CC
0012 
0013 // namespace definition
0014 #include "GEvtTools.h"
0015 
0016 // make common namespaces implicit
0017 using namespace std;
0018 
0019 
0020 
0021 // event-level generator methods ==============================================
0022 
0023 namespace SColdQcdCorrelatorAnalysis {
0024 
0025   // --------------------------------------------------------------------------
0026   //! Get total number of final state particles
0027   // --------------------------------------------------------------------------
0028   /*! A specific subset can specified by the
0029    *  subset identifier (Const::Subset).
0030    *  Optionally, a specific charge can be
0031    *  specified to get the total number of
0032    *  final state particles with that charge.
0033    */
0034   int64_t Tools::GetNumFinalStatePars(
0035     PHCompositeNode* topNode,
0036     const vector<int> evtsToGrab,
0037     const Const::Subset subset,
0038     optional<float> chargeToGrab
0039   ) {
0040 
0041     // loop over subevents
0042     int64_t nPar = 0;
0043     for (const int evtToGrab : evtsToGrab) {
0044 
0045       // loop over particles
0046       HepMC::GenEvent* genEvt = Interfaces::GetGenEvent(topNode, evtToGrab);
0047       for (
0048         HepMC::GenEvent::particle_const_iterator particle = genEvt -> particles_begin();
0049         particle != genEvt -> particles_end();
0050         ++particle
0051       ) {
0052 
0053         // check if particle is final state
0054         const bool isFinalState = Tools::IsFinalState((*particle) -> status());
0055         if (!isFinalState) continue;
0056 
0057         // if chargeToGrab is set, select only particle with charge
0058         const float charge = Tools::GetParticleCharge((*particle) -> pdg_id());
0059         if (chargeToGrab.has_value()) {
0060           if (charge == chargeToGrab.value()) {
0061             ++nPar;
0062           }
0063         } else {
0064           switch (subset) {
0065 
0066             // everything
0067             case Const::Subset::All:
0068               ++nPar;
0069               break;
0070 
0071             // all charged
0072             case Const::Subset::Charged:
0073               if (charge != 0.) {
0074                 ++nPar;
0075               }
0076               break;
0077 
0078             // only neutral
0079             case Const::Subset::Neutral:
0080               if (charge == 0.) {
0081                 ++nPar;
0082               }
0083               break;
0084 
0085             default:
0086               ++nPar;
0087               break;
0088           }
0089         }  // end if-else chargeToGrab.has_value()
0090       }  // end particle loop
0091     }  // end subevent loop
0092     return nPar;
0093 
0094   }  // end 'GetNumFinalStatePars(PHCompositeNode*, vector<int>, optional<float>, optional<float> bool)'
0095 
0096 
0097 
0098   // --------------------------------------------------------------------------
0099   //! Get sum of energy for all final state particles
0100   // --------------------------------------------------------------------------
0101   /*! A specific subset can specified by the
0102    *  subset identifier (Const::Subset).
0103    *  Optionally, a specific charge can be
0104    *  specified to get the total number of
0105    *  final state particles with that charge.
0106    */
0107   double Tools::GetSumFinalStateParEne(
0108     PHCompositeNode* topNode,
0109     const vector<int> evtsToGrab,
0110     const Const::Subset subset,
0111     optional<float> chargeToGrab
0112   ) {
0113 
0114     // loop over subevents
0115     double eSum = 0.;
0116     for (const int evtToGrab : evtsToGrab) {
0117 
0118       HepMC::GenEvent* genEvt = Interfaces::GetGenEvent(topNode, evtToGrab);
0119       for (
0120         HepMC::GenEvent::particle_const_iterator particle = genEvt -> particles_begin();
0121         particle != genEvt -> particles_end();
0122         ++particle
0123       ) {
0124 
0125         // check if particle is final state
0126         const bool isFinalState = Tools::IsFinalState((*particle) -> status());
0127         if (!isFinalState) continue;
0128 
0129         // if chargeToGrab is set, select only particle with charge
0130         const float charge = Tools::GetParticleCharge((*particle) -> pdg_id());
0131         const float energy = (*particle) -> momentum().e();
0132         if (chargeToGrab.has_value()) {
0133           if (charge == chargeToGrab.value()) {
0134             eSum += energy;
0135           }
0136         } else {
0137           switch (subset) {
0138 
0139             // everything
0140             case Const::Subset::All:
0141               eSum += energy;
0142               break;
0143 
0144             // all charged
0145             case Const::Subset::Charged:
0146               if (charge != 0.) {
0147                 eSum += energy;
0148               }
0149               break;
0150 
0151             // only neutral
0152             case Const::Subset::Neutral:
0153               if (charge == 0.) {
0154                 eSum += energy;
0155               }
0156               break;
0157 
0158             default:
0159               eSum += energy;
0160               break;
0161           }
0162         }  // end if-else chargeToGrab.has_value()
0163       }  // end particle loop
0164     }  // end subevent loop
0165     return eSum;
0166 
0167   }  // end 'GetSumFinalStateParEne(PHCompositeNode*, vector<int>, int, optional<float>)'
0168 
0169 
0170 
0171   // --------------------------------------------------------------------------
0172   //! Pull information of a parton with a specified status from a subevent
0173   // --------------------------------------------------------------------------
0174   Types::ParInfo Tools::GetPartonInfo(
0175     PHCompositeNode* topNode,
0176     const int event,
0177     const int status
0178   ) {
0179 
0180     // pick out relevant sub-sevent to grab
0181     HepMC::GenEvent* genEvt = Interfaces::GetGenEvent(topNode, event);
0182 
0183     // loop over particles
0184     Types::ParInfo parton;
0185     for (
0186       HepMC::GenEvent::particle_const_iterator particle = genEvt -> particles_begin();
0187       particle != genEvt -> particles_end();
0188       ++particle
0189     ) {
0190 
0191       // grab particle info
0192       parton.Reset();
0193       parton.SetInfo(*particle, event);
0194 
0195       // ignore all non-partons
0196       if (parton.IsParton()) continue;
0197 
0198       // exit loop with info if parton is desired status
0199       if (parton.IsHardScatterProduct()) {
0200         break;
0201       } 
0202     }  // end particle loop
0203     return parton;
0204 
0205   }  // end 'GetPartonInfo(PHCompositeNode*, int, int)'
0206 
0207 }  // end SColdQcdCorrelatorAnalysis namespace
0208 
0209 // end ------------------------------------------------------------------------