Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 /// ---------------------------------------------------------------------------
0002 /*! \file   TwrInfo.cc
0003  *  \author Derek Anderson
0004  *  \date   08.04.2024
0005  *
0006  *  Utility class to hold information from
0007  *  calorimeter clusters.
0008  */
0009 /// ---------------------------------------------------------------------------
0010 
0011 #define SCORRELATORUTILITIES_TWRINFO_CC
0012 
0013 // class definition
0014 #include "TwrInfo.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::TwrInfo::Minimize() {
0029 
0030     system  = -1 * numeric_limits<int>::max();
0031     status  = -1 * numeric_limits<int>::max();
0032     channel = -1 * numeric_limits<int>::max();
0033     id      = -1 * numeric_limits<int>::max();
0034     ene     = -1. * numeric_limits<double>::max();
0035     rho     = -1. * numeric_limits<double>::max();
0036     eta     = -1. * numeric_limits<double>::max();
0037     phi     = -1. * numeric_limits<double>::max();
0038     px      = -1. * numeric_limits<double>::max();
0039     py      = -1. * numeric_limits<double>::max();
0040     pz      = -1. * numeric_limits<double>::max();
0041     rx      = -1. * numeric_limits<double>::max();
0042     ry      = -1. * numeric_limits<double>::max();
0043     rz      = -1. * numeric_limits<double>::max();
0044     return;
0045 
0046   }  // end 'Minimize()'
0047 
0048 
0049 
0050   // --------------------------------------------------------------------------
0051   //! Set data members to absolute maxima
0052   // --------------------------------------------------------------------------
0053   void Types::TwrInfo::Maximize() {
0054 
0055     system  = numeric_limits<int>::max();
0056     status  = numeric_limits<int>::max();
0057     channel = numeric_limits<int>::max();
0058     id      = numeric_limits<int>::max();
0059     ene     = numeric_limits<double>::max();
0060     rho     = numeric_limits<double>::max();
0061     eta     = numeric_limits<double>::max();
0062     phi     = numeric_limits<double>::max();
0063     px      = numeric_limits<double>::max();
0064     py      = numeric_limits<double>::max();
0065     pz      = numeric_limits<double>::max();
0066     rx      = numeric_limits<double>::max();
0067     ry      = numeric_limits<double>::max();
0068     rz      = numeric_limits<double>::max();
0069     return;
0070 
0071   }  // end 'Maximize()'
0072 
0073 
0074 
0075   // public methods ===========================================================
0076 
0077   // --------------------------------------------------------------------------
0078   //! Reset object by maximizing data members
0079   // --------------------------------------------------------------------------
0080   void Types::TwrInfo::Reset() {
0081 
0082     Maximize();
0083     return;
0084 
0085   }  // end 'Reset()'
0086 
0087 
0088 
0089   // --------------------------------------------------------------------------
0090   //! Pull relevant information from a F4A RawTower
0091   // --------------------------------------------------------------------------
0092   void Types::TwrInfo::SetInfo(
0093     const int sys,
0094     const RawTower* tower,
0095     PHCompositeNode* topNode,
0096     optional<ROOT::Math::XYZVector> vtx
0097   ) {
0098 
0099     // if no vertex provided, use origin
0100     ROOT::Math::XYZVector vtxToUse(0., 0., 0.);
0101     if (vtx.has_value()) {
0102       vtxToUse = vtx.value();
0103     }
0104 
0105     // grab raw key for geometry
0106     const int rawKey = tower -> get_key();
0107 
0108     // grab position in (x, y, z)
0109     ROOT::Math::XYZVector xyzPos = Tools::GetTowerPositionXYZ(
0110       rawKey,
0111       sys,
0112       topNode
0113     );
0114 
0115     // grab position in (rho, eta, phi)
0116     ROOT::Math::RhoEtaPhiVector rhfPos = Tools::GetTowerPositionRhoEtaPhi(
0117       rawKey,
0118       sys,
0119       vtxToUse.z(),
0120       topNode
0121     );
0122 
0123     // grab momentum
0124     ROOT::Math::PxPyPzEVector momentum = Tools::GetTowerMomentum(
0125       tower -> get_energy(),
0126       rhfPos
0127     );
0128 
0129     // set remaining members
0130     system  = sys;
0131     status  = Const::TowerStatus::NA;
0132     id      = rawKey;
0133     ene     = tower -> get_energy();
0134     rho     = rhfPos.Rho();
0135     eta     = rhfPos.Eta();
0136     phi     = rhfPos.Phi();
0137     px      = momentum.Px();
0138     py      = momentum.Py();
0139     pz      = momentum.Pz();
0140     rx      = xyzPos.x();
0141     ry      = xyzPos.y();
0142     rz      = xyzPos.z();
0143     return;
0144 
0145   }  // end 'SetInfo(int, RawTower*, PHCompositeNode*, optional<ROOT::Math::XYZVector>)'
0146 
0147 
0148 
0149   // --------------------------------------------------------------------------
0150   //! Pull relevant information from a F4A TowerInfo
0151   // --------------------------------------------------------------------------
0152   void Types::TwrInfo::SetInfo(
0153     const int sys,
0154     const int chan,
0155     TowerInfo* tower,
0156     PHCompositeNode* topNode, 
0157     optional<ROOT::Math::XYZVector> vtx
0158   ) {
0159 
0160     // if no vertex provided, use origin
0161     ROOT::Math::XYZVector vtxToUse(0., 0., 0.);
0162     if (vtx.has_value()) {
0163       vtxToUse = vtx.value();
0164     }
0165 
0166     // get raw tower key 
0167     const auto indices = Tools::GetTowerIndices(chan, sys, topNode);
0168     const int  rawKey  = Tools::GetRawTowerKey(Const::MapIndexOntoID()[ sys ], indices);
0169 
0170     // grab position in (x, y, z)
0171     ROOT::Math::XYZVector xyzPos = Tools::GetTowerPositionXYZ(
0172       rawKey,
0173       sys,
0174       topNode
0175     );
0176 
0177     // grab position in (rho, eta, phi)
0178     ROOT::Math::RhoEtaPhiVector rhfPos = Tools::GetTowerPositionRhoEtaPhi(
0179       rawKey,
0180       sys,
0181       vtxToUse.z(),
0182       topNode
0183     );
0184 
0185     // grab momentum
0186     ROOT::Math::PxPyPzEVector momentum = Tools::GetTowerMomentum(
0187       tower -> get_energy(),
0188       rhfPos
0189     );
0190 
0191     // set remaining members
0192     system  = sys;
0193     status  = Tools::GetTowerStatus(tower);
0194     channel = chan;
0195     id      = get<0>(indices);
0196     ene     = tower -> get_energy();
0197     rho     = rhfPos.Rho();
0198     eta     = rhfPos.Eta();
0199     phi     = rhfPos.Phi();
0200     px      = momentum.Px();
0201     py      = momentum.Py();
0202     pz      = momentum.Pz();
0203     rx      = xyzPos.x();
0204     ry      = xyzPos.y();
0205     rz      = xyzPos.z();
0206     return;
0207 
0208   }  // end 'SetInfo(int, int, TowerInfo*, PHCompositeNode*, optional<ROOT::Math::XYZVector>)'
0209 
0210 
0211 
0212   // --------------------------------------------------------------------------
0213   //! Check if object is within provided bounds (explicit minimum, maximum)
0214   // --------------------------------------------------------------------------
0215   bool Types::TwrInfo::IsInAcceptance(const TwrInfo& minimum, const TwrInfo& maximum) const {
0216 
0217     return ((*this >= minimum) && (*this <= maximum));
0218 
0219   }  // end 'IsInAcceptance(TwrInfo&, TwrInfo&)'
0220 
0221 
0222 
0223   // --------------------------------------------------------------------------
0224   //! Check if object is within provided bounds (set by pair)
0225   // --------------------------------------------------------------------------
0226   bool Types::TwrInfo::IsInAcceptance(const pair<TwrInfo, TwrInfo>& range) const {
0227 
0228     return ((*this >= range.first) && (*this <= range.second));
0229 
0230   }  // end 'IsInAcceptance(pair<TwrInfo, TwrInfo>&)'
0231 
0232 
0233 
0234   // --------------------------------------------------------------------------
0235   //! Check if tower is good
0236   // --------------------------------------------------------------------------
0237   bool Types::TwrInfo::IsGood() const {
0238 
0239     return (
0240       (status == Const::TowerStatus::Good) ||
0241       (status == Const::TowerStatus::NA)
0242     );
0243 
0244   }  // end 'IsGood()'
0245 
0246 
0247 
0248   // static methods ===========================================================
0249 
0250   // --------------------------------------------------------------------------
0251   //! Get list of data fields
0252   // --------------------------------------------------------------------------
0253   vector<string> Types::TwrInfo::GetListOfMembers() {
0254 
0255     vector<string> members = {
0256       "system",
0257       "status",
0258       "channel",
0259       "id",
0260       "ene",
0261       "rho",
0262       "eta",
0263       "phi",
0264       "px",
0265       "py",
0266       "pz",
0267       "rx",
0268       "ry",
0269       "rz"
0270     };
0271     return members;
0272 
0273   }  // end 'GetListOfMembers()'
0274 
0275 
0276 
0277   // overloaded operators =====================================================
0278 
0279   // --------------------------------------------------------------------------
0280   //! Overloaded less-than comparison
0281   // --------------------------------------------------------------------------
0282   bool Types::operator <(const TwrInfo& lhs, const TwrInfo& rhs) {
0283 
0284     // note that some quantities aren't relevant for this comparison
0285     const bool isLessThan = (
0286       (lhs.ene  < rhs.ene)  &&
0287       (lhs.rho  < rhs.rho)  &&
0288       (lhs.eta  < rhs.eta)  &&
0289       (lhs.phi  < rhs.phi)  &&
0290       (lhs.px   < rhs.px)   &&
0291       (lhs.py   < rhs.py)   &&
0292       (lhs.pz   < rhs.pz)   &&
0293       (lhs.rx   < rhs.rx)   &&
0294       (lhs.ry   < rhs.ry)   &&
0295       (lhs.rz   < rhs.rz)
0296     );
0297     return isLessThan;
0298 
0299   }  // end 'operator <(TwrInfo&, TwrInfo&) const'
0300 
0301 
0302 
0303   // --------------------------------------------------------------------------
0304   //! Overloaded greater-than comparison
0305   // --------------------------------------------------------------------------
0306   bool Types::operator >(const TwrInfo& lhs, const TwrInfo& rhs) {
0307 
0308     // note that some quantities aren't relevant for this comparison
0309     const bool isGreaterThan = (
0310       (lhs.ene  > rhs.ene)  &&
0311       (lhs.rho  > rhs.rho)  &&
0312       (lhs.eta  > rhs.eta)  &&
0313       (lhs.phi  > rhs.phi)  &&
0314       (lhs.px   > rhs.px)   &&
0315       (lhs.py   > rhs.py)   &&
0316       (lhs.pz   > rhs.pz)   &&
0317       (lhs.rx   > rhs.rx)   &&
0318       (lhs.ry   > rhs.ry)   &&
0319       (lhs.rz   > rhs.rz)
0320     );
0321     return isGreaterThan;
0322 
0323   }  // end 'operator >(TwrInfo&, TwrInfo&)'
0324 
0325 
0326 
0327   // --------------------------------------------------------------------------
0328   //! Overloaded less-than-or-equal-to comparison
0329   // --------------------------------------------------------------------------
0330   bool Types::operator <=(const TwrInfo& lhs, const TwrInfo& rhs) {
0331 
0332     // note that some quantities aren't relevant for this comparison
0333     const bool isLessThanOrEqualTo = (
0334       (lhs.ene  <= rhs.ene)  &&
0335       (lhs.rho  <= rhs.rho)  &&
0336       (lhs.eta  <= rhs.eta)  &&
0337       (lhs.phi  <= rhs.phi)  &&
0338       (lhs.px   <= rhs.px)   &&
0339       (lhs.py   <= rhs.py)   &&
0340       (lhs.pz   <= rhs.pz)   &&
0341       (lhs.rx   <= rhs.rx)   &&
0342       (lhs.ry   <= rhs.ry)   &&
0343       (lhs.rz   <= rhs.rz)
0344     );
0345     return isLessThanOrEqualTo;
0346 
0347   }  // end 'operator <=(TwrInfo&, TwrInfo&) const'
0348 
0349 
0350 
0351   // --------------------------------------------------------------------------
0352   //! Overloaded greater-than-or-equal-to comparison
0353   // --------------------------------------------------------------------------
0354   bool Types::operator >=(const TwrInfo& lhs, const TwrInfo& rhs) {
0355 
0356     // note that some quantities aren't relevant for this comparison
0357     const bool isGreaterThanOrEqualTo = (
0358       (lhs.ene  >= rhs.ene)  &&
0359       (lhs.rho  >= rhs.rho)  &&
0360       (lhs.eta  >= rhs.eta)  &&
0361       (lhs.phi  >= rhs.phi)  &&
0362       (lhs.px   >= rhs.px)   &&
0363       (lhs.py   >= rhs.py)   &&
0364       (lhs.pz   >= rhs.pz)   &&
0365       (lhs.rx   >= rhs.rx)   &&
0366       (lhs.ry   >= rhs.ry)   &&
0367       (lhs.rz   >= rhs.rz)
0368     );
0369     return isGreaterThanOrEqualTo;
0370 
0371   }  // end 'operator >=(TwrInfo&, TwrInfo&)'
0372 
0373 
0374 
0375   // ctor/dtor ================================================================
0376 
0377   // --------------------------------------------------------------------------
0378   //! Default class constructor
0379   // --------------------------------------------------------------------------
0380   Types::TwrInfo::TwrInfo() {
0381 
0382      /* nothing to do */
0383 
0384   }  // end ctor()
0385 
0386 
0387 
0388   // --------------------------------------------------------------------------
0389   //! Default class destructor
0390   // --------------------------------------------------------------------------
0391   Types::TwrInfo::~TwrInfo() {
0392 
0393     /* nothing to do */
0394 
0395   }  // end dtor()
0396 
0397 
0398 
0399   // --------------------------------------------------------------------------
0400   //! Constructor accepting initialization option (minimize or maximize)
0401   // --------------------------------------------------------------------------
0402   Types::TwrInfo::TwrInfo(const Const::Init init) {
0403 
0404     switch (init) {
0405       case Const::Init::Minimize:
0406         Minimize();
0407         break;
0408       case Const::Init::Maximize:
0409         Maximize();
0410         break;
0411       default:
0412         Maximize();
0413         break;
0414     }
0415 
0416   }  // end ctor(Const::Init)
0417 
0418 
0419 
0420   // --------------------------------------------------------------------------
0421   //! Constructor accepting a F4A RawTower
0422   // --------------------------------------------------------------------------
0423   Types::TwrInfo::TwrInfo(
0424     const int sys,
0425     const RawTower* tower,
0426     PHCompositeNode* topNode,
0427     optional<ROOT::Math::XYZVector> vtx
0428   ) {
0429 
0430     SetInfo(sys, tower, topNode, vtx);
0431 
0432   }  // end ctor(int, RawTower*, PHCompositeNode*, optional<ROOT::Math::XYZVector>)'
0433 
0434 
0435 
0436   // --------------------------------------------------------------------------
0437   //! Constructor accepting a F4A TowerInfo
0438   // --------------------------------------------------------------------------
0439   Types::TwrInfo::TwrInfo(
0440     const int sys,
0441     const int chan,
0442     TowerInfo* tower,
0443     PHCompositeNode* topNode,
0444     optional<ROOT::Math::XYZVector> vtx
0445   ) {
0446 
0447     SetInfo(sys, chan, tower, topNode, vtx);
0448 
0449   }  // end ctor(int, int, TowerInfo*, PHCompositeNode*, optional<ROOT::Math::XYZVector>)'
0450 
0451 }  // end SColdQcdCorrelatorAnalysis namespace
0452 
0453 // end ------------------------------------------------------------------------