Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 /// ---------------------------------------------------------------------------
0002 /*! \file   ParInfo.cc
0003  *  \author Derek Anderson
0004  *  \date   03.04.2024
0005  *
0006  *  Utility class to hold information from
0007  *  generated particles.
0008  */
0009 /// ---------------------------------------------------------------------------
0010 
0011 #define SCORRELATORUTILITIES_PARINFO_CC
0012 
0013 // class definition
0014 #include "ParInfo.h"
0015 
0016 // make comon namespaces implicit
0017 using namespace std;
0018 
0019 
0020 
0021 namespace SColdQcdCorrelatorAnalysis {
0022 
0023   // private methods ==========================================================
0024 
0025   // --------------------------------------------------------------------------
0026   //! Set data members to absolute minima
0027   // --------------------------------------------------------------------------
0028   void Types::ParInfo::Minimize() {
0029 
0030     pid     = -1 * numeric_limits<int>::max();
0031     status  = -1 * numeric_limits<int>::max();
0032     barcode = -1 * numeric_limits<int>::max();
0033     embedID = -1 * numeric_limits<int>::max();
0034     charge  = -1. * numeric_limits<float>::max();
0035     mass    = -1. * numeric_limits<double>::max();
0036     eta     = -1. * numeric_limits<double>::max();
0037     phi     = -1. * numeric_limits<double>::max();
0038     ene     = -1. * numeric_limits<double>::max();
0039     px      = -1. * numeric_limits<double>::max();
0040     py      = -1. * numeric_limits<double>::max();
0041     pz      = -1. * numeric_limits<double>::max();
0042     pt      = -1. * numeric_limits<double>::max();
0043     vx      = -1. * numeric_limits<double>::max();
0044     vy      = -1. * numeric_limits<double>::max();
0045     vz      = -1. * numeric_limits<double>::max();
0046     vr      = -1. * numeric_limits<double>::max();
0047     return;
0048 
0049   }  // end 'Minimize()'
0050 
0051 
0052 
0053   // --------------------------------------------------------------------------
0054   //! Set data members to absolute maxima
0055   // --------------------------------------------------------------------------
0056   void Types::ParInfo::Maximize() {
0057 
0058     pid     = numeric_limits<int>::max();
0059     status  = numeric_limits<int>::max();
0060     barcode = numeric_limits<int>::max();
0061     embedID = numeric_limits<int>::max();
0062     charge  = numeric_limits<float>::max();
0063     mass    = numeric_limits<double>::max();
0064     eta     = numeric_limits<double>::max();
0065     phi     = numeric_limits<double>::max();
0066     ene     = numeric_limits<double>::max();
0067     px      = numeric_limits<double>::max();
0068     py      = numeric_limits<double>::max();
0069     pz      = numeric_limits<double>::max();
0070     pt      = numeric_limits<double>::max();
0071     vx      = numeric_limits<double>::max();
0072     vy      = numeric_limits<double>::max();
0073     vz      = numeric_limits<double>::max();
0074     vr      = numeric_limits<double>::max();
0075     return;
0076 
0077   }  // end 'Maximize()'
0078 
0079 
0080 
0081   // public methods ===========================================================
0082 
0083   // --------------------------------------------------------------------------
0084   //! Reset object by maximizing data members
0085   // --------------------------------------------------------------------------
0086   void Types::ParInfo::Reset() {
0087 
0088     Maximize();
0089     return;
0090 
0091   }  // end 'Reset()'
0092 
0093 
0094 
0095   // --------------------------------------------------------------------------
0096   //! Pull relevant information from a HepMC GenParticle
0097   // --------------------------------------------------------------------------
0098   void Types::ParInfo::SetInfo(const HepMC::GenParticle* particle, const int event) {
0099 
0100     pid     = particle -> pdg_id();
0101     status  = particle -> status();
0102     barcode = particle -> barcode();
0103     embedID = event;
0104     charge  = Const::MapPidOntoCharge()[pid];
0105     mass    = particle -> momentum().m();
0106     eta     = particle -> momentum().eta();
0107     phi     = particle -> momentum().phi();
0108     ene     = particle -> momentum().e();
0109     px      = particle -> momentum().px();
0110     py      = particle -> momentum().py();
0111     pz      = particle -> momentum().pz();
0112     pt      = particle -> momentum().perp();
0113     return;
0114 
0115   }  // end 'SetInfo(HepMC::GenParticle*, int)'
0116 
0117 
0118 
0119   // --------------------------------------------------------------------------
0120   //! Pull relevant information from a F4A PHG4Particle
0121   // --------------------------------------------------------------------------
0122   void Types::ParInfo::SetInfo(const PHG4Particle* particle, const int event) {
0123 
0124     // set basic info
0125     pid     = particle -> get_pid();
0126     status  = numeric_limits<int>::max();  // FIXME there must be a way to get the status of these particles
0127     barcode = particle -> get_barcode();
0128     embedID = event;
0129     charge  = Const::MapPidOntoCharge()[pid];
0130     mass    = numeric_limits<double>::max();  // FIXME likewise for mass
0131     ene     = particle -> get_e();
0132     px      = particle -> get_px();
0133     py      = particle -> get_py();
0134     pz      = particle -> get_pz();
0135 
0136     // get remaining kinematic info
0137     ROOT::Math::PxPyPzEVector pPar(px, py, pz, ene);
0138     eta = pPar.Eta();
0139     phi = pPar.Phi();
0140     pt  = pPar.Pt();
0141     return;
0142 
0143   }  // end 'SetInfo(PHG4Particle*, int)'
0144 
0145 
0146 
0147   // --------------------------------------------------------------------------
0148   //! Check if object is within provided bounds (explicit minimum, maximum)
0149   // --------------------------------------------------------------------------
0150   bool Types::ParInfo::IsInAcceptance(const ParInfo& minimum, const ParInfo& maximum) const {
0151 
0152     return ((*this >= minimum) && (*this <= maximum));
0153 
0154   }  // end 'IsInAcceptance(ParInfo&, ParInfo&)'
0155 
0156 
0157 
0158   // --------------------------------------------------------------------------
0159   //! Check if object is within provided bounds (set by pair)
0160   // --------------------------------------------------------------------------
0161   bool Types::ParInfo::IsInAcceptance(const pair<ParInfo, ParInfo>& range) const {
0162 
0163     return ((*this >= range.first) && (*this <= range.second));
0164 
0165   }  // end 'IsInAcceptance(ParInfo&, ParInfo&)'
0166 
0167 
0168 
0169   // --------------------------------------------------------------------------
0170   //! Check if particle is final state
0171   // --------------------------------------------------------------------------
0172   bool Types::ParInfo::IsFinalState() const {
0173 
0174     return (status == 1);
0175 
0176   }  // end 'IsFinalState()'
0177 
0178 
0179 
0180   // --------------------------------------------------------------------------
0181   //! Check if particle is a hard-scatter product
0182   // --------------------------------------------------------------------------
0183   bool Types::ParInfo::IsHardScatterProduct() const {
0184 
0185     const bool isHardScatter = (
0186       (status == Const::HardScatterStatus::First) ||
0187       (status == Const::HardScatterStatus::Second)
0188     );
0189     return isHardScatter;
0190 
0191   }  // end 'IsHardScatterProduct()'
0192 
0193 
0194 
0195   // --------------------------------------------------------------------------
0196   //! Check if particle is a parton
0197   // --------------------------------------------------------------------------
0198   bool Types::ParInfo::IsParton() const {
0199 
0200     const bool isLightQuark   = ((pid == Const::Parton::Down)    || (pid == Const::Parton::Up));
0201     const bool isStrangeQuark = ((pid == Const::Parton::Strange) || (pid == Const::Parton::Charm));
0202     const bool isHeavyQuark   = ((pid == Const::Parton::Bottom)  || (pid == Const::Parton::Top));
0203     const bool isGluon        = (pid == Const::Parton::Gluon);
0204     return (isLightQuark || isStrangeQuark || isHeavyQuark || isGluon);
0205 
0206   }  // end 'IsParton()'
0207 
0208 
0209 
0210   // --------------------------------------------------------------------------
0211   //! Check if particle is an outgoing parton from a hard scatter
0212   // --------------------------------------------------------------------------
0213   bool Types::ParInfo::IsOutgoingParton() const {
0214 
0215     return (IsHardScatterProduct() && IsParton());
0216 
0217   }  // end 'IsOutgoingParton()'
0218 
0219 
0220 
0221   // static methods ===========================================================
0222 
0223   // --------------------------------------------------------------------------
0224   //! Get list of data fields
0225   // --------------------------------------------------------------------------
0226   vector<string> Types::ParInfo::GetListOfMembers() {
0227 
0228     vector<string> members = {
0229       "pid",
0230       "status",
0231       "barcode",
0232       "embedID",
0233       "charge",
0234       "mass",
0235       "eta",
0236       "phi",
0237       "ene",
0238       "px",
0239       "py",
0240       "pz",
0241       "pt",
0242       "vx",
0243       "vy",
0244       "vz",
0245       "vr"
0246     };
0247     return members;
0248 
0249   }  // end 'GetListOfMembers()'
0250 
0251 
0252 
0253   // overloaded operators =====================================================
0254 
0255   // --------------------------------------------------------------------------
0256   //! Overloaded less-than comparison
0257   // --------------------------------------------------------------------------
0258   bool Types::operator <(const ParInfo& lhs, const ParInfo& rhs) {
0259 
0260     // note that some quantities aren't relevant for this comparison
0261     const bool isLessThan = (
0262       (lhs.eta  < rhs.eta)  &&
0263       (lhs.phi  < rhs.phi)  &&
0264       (lhs.ene  < rhs.ene)  &&
0265       (lhs.px   < rhs.px)   &&
0266       (lhs.py   < rhs.py)   &&
0267       (lhs.pz   < rhs.pz)   &&
0268       (lhs.pt   < rhs.pt)
0269     );
0270     return isLessThan;
0271 
0272   }  // end 'operator <(ParInfo&, ParInfo&)'
0273 
0274 
0275 
0276   // --------------------------------------------------------------------------
0277   //! Overloaded greater-than comparison
0278   // --------------------------------------------------------------------------
0279   bool Types::operator >(const ParInfo& lhs, const ParInfo& rhs) {
0280 
0281     // note that some quantities aren't relevant for this comparison
0282     const bool isGreaterThan = (
0283       (lhs.eta  > rhs.eta)  &&
0284       (lhs.phi  > rhs.phi)  &&
0285       (lhs.ene  > rhs.ene)  &&
0286       (lhs.px   > rhs.px)   &&
0287       (lhs.py   > rhs.py)   &&
0288       (lhs.pz   > rhs.pz)   &&
0289       (lhs.pt   > rhs.pt)
0290     );
0291     return isGreaterThan;
0292 
0293   }  // end 'operator >(ParInfo&, ParInfo&)'
0294 
0295 
0296 
0297   // --------------------------------------------------------------------------
0298   //! Overloaded less-than-or-equal-to comparison
0299   // --------------------------------------------------------------------------
0300   bool Types::operator <=(const ParInfo& lhs, const ParInfo& rhs) {
0301 
0302     // note that some quantities aren't relevant for this comparison
0303     const bool isLessThanOrEqualTo = (
0304       (lhs.eta  <= rhs.eta)  &&
0305       (lhs.phi  <= rhs.phi)  &&
0306       (lhs.ene  <= rhs.ene)  &&
0307       (lhs.px   <= rhs.px)   &&
0308       (lhs.py   <= rhs.py)   &&
0309       (lhs.pz   <= rhs.pz)   &&
0310       (lhs.pt   <= rhs.pt)
0311     );
0312     return isLessThanOrEqualTo;
0313 
0314   }  // end 'operator <=(ParInfo&, ParInfo&)'
0315 
0316 
0317 
0318   // --------------------------------------------------------------------------
0319   //! Overloaded greater-than-or-equal-to comparison
0320   // --------------------------------------------------------------------------
0321   bool Types::operator >=(const ParInfo& lhs, const ParInfo& rhs) {
0322 
0323     // note that some quantities aren't relevant for this comparison
0324     const bool isGreaterThanOrEqualTo = (
0325       (lhs.eta  >= rhs.eta)  &&
0326       (lhs.phi  >= rhs.phi)  &&
0327       (lhs.ene  >= rhs.ene)  &&
0328       (lhs.px   >= rhs.px)   &&
0329       (lhs.py   >= rhs.py)   &&
0330       (lhs.pz   >= rhs.pz)   &&
0331       (lhs.pt   >= rhs.pt)
0332     );
0333     return isGreaterThanOrEqualTo;
0334 
0335   }  // end 'operator >=(ParInfo&, ParInfo&)'
0336 
0337 
0338 
0339   // ctor/dtor ================================================================
0340 
0341   // --------------------------------------------------------------------------
0342   //! Default class constructor
0343   // --------------------------------------------------------------------------
0344   Types::ParInfo::ParInfo() {
0345 
0346     /* nothing to do */
0347 
0348   }  // end ctor()
0349 
0350 
0351 
0352   // --------------------------------------------------------------------------
0353   //! Default class destructor
0354   // --------------------------------------------------------------------------
0355   Types::ParInfo::~ParInfo() {
0356 
0357     /* nothing to do */
0358 
0359   }  // end dtor()
0360 
0361 
0362 
0363   // --------------------------------------------------------------------------
0364   //! Constructor accepting initialization option (minimize or maximize)
0365   // --------------------------------------------------------------------------
0366   Types::ParInfo::ParInfo(const Const::Init init) {
0367 
0368     switch (init) {
0369       case Const::Init::Minimize:
0370         Minimize();
0371         break;
0372       case Const::Init::Maximize:
0373         Maximize();
0374         break;
0375       default:
0376         Maximize();
0377         break;
0378     }
0379 
0380   }  // end ctor(Const::init)
0381 
0382 
0383 
0384   // --------------------------------------------------------------------------
0385   //! Constructor accepting a HepMC GenParticle
0386   // --------------------------------------------------------------------------
0387   Types::ParInfo::ParInfo(HepMC::GenParticle* particle, const int event) {
0388 
0389     SetInfo(particle, event);
0390 
0391   }  // end ctor(HepMC::GenParticle*, int)'
0392 
0393 
0394 
0395   // --------------------------------------------------------------------------
0396   //! Constructor accepting a F4A PHG4Particle
0397   // --------------------------------------------------------------------------
0398   Types::ParInfo::ParInfo(PHG4Particle* particle, const int event) {
0399 
0400     SetInfo(particle, event);
0401 
0402   }  // end ctor(PHG4Particle*, int)'
0403 
0404 }  // end SColdQcdCorrelatorAnalysis namespace
0405 
0406 // end ------------------------------------------------------------------------