Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 /// ---------------------------------------------------------------------------
0002 /*! \file   TwrTools.cc
0003  *  \author Derek Anderson
0004  *  \date   08.04.2024
0005  *
0006  *  Collection of frequent tower-related methods utilized in
0007  *  the sPHENIX Cold QCD Energy-Energy Correlator analysis.
0008  */
0009 /// ---------------------------------------------------------------------------
0010 
0011 #define SCORRELATORUTILITIES_TWRTOOLS_CC
0012 
0013 // namespace definition
0014 #include "TwrTools.h"
0015 
0016 // make common namespaces implicit
0017 using namespace std;
0018 
0019 
0020 
0021 // tower methods ==============================================================
0022 
0023 namespace SColdQcdCorrelatorAnalysis {
0024 
0025   // --------------------------------------------------------------------------
0026   //! Get tower status
0027   // --------------------------------------------------------------------------
0028   /*! NOTE: only applies to TowerInfo objects.
0029    */
0030   int Tools::GetTowerStatus(const TowerInfo* tower) {
0031 
0032     int status = Const::TowerStatus::Unknown;
0033     if (tower -> get_isHot()) {
0034       status = Const::TowerStatus::Hot;
0035     } else if (tower -> get_isBadTime()) {
0036       status = Const::TowerStatus::BadTime;
0037     } else if (tower -> get_isBadChi2()) {
0038       status = Const::TowerStatus::BadChi;
0039     } else if (tower -> get_isNotInstr()) {
0040       status = Const::TowerStatus::NotInstr;
0041     } else if (tower -> get_isNoCalib()) {
0042       status = Const::TowerStatus::NoCalib;
0043     } else {
0044       status = Const::TowerStatus::Good;
0045     }
0046     return status;
0047 
0048   }  // end 'GetTowerStatus(TowerInfo*)' 
0049 
0050 
0051 
0052   // --------------------------------------------------------------------------
0053   //! Get Calorimeter ID from a RawTower
0054   // --------------------------------------------------------------------------
0055   int Tools::GetCaloIDFromRawTower(RawTower* tower) {
0056 
0057     auto rawKey = tower -> get_id();
0058     return RawTowerDefs::decode_caloid(rawKey);
0059 
0060   }  // end 'GetCaloIDFromRawTower(RawTower*)'
0061 
0062 
0063 
0064   // --------------------------------------------------------------------------
0065   //! Get raw tower key based on tower indices
0066   // --------------------------------------------------------------------------
0067   int Tools::GetRawTowerKey(const int idGeo, const tuple<int, int, int> indices) {
0068 
0069     const int key = (int) RawTowerDefs::encode_towerid(
0070       (RawTowerDefs::CalorimeterId) idGeo,
0071       get<1>(indices),
0072       get<2>(indices)
0073     );
0074     return key;
0075 
0076   }  // end 'GetRawTowerKey(int, tuple<int, int, int>)'
0077 
0078 
0079 
0080   // --------------------------------------------------------------------------
0081   //! Get key and eta-phi indices for a TowerInfo object
0082   // --------------------------------------------------------------------------
0083   tuple<int, int, int> Tools::GetTowerIndices(
0084     const int channel,
0085     const int subsys,
0086     PHCompositeNode* topNode
0087   ) {
0088 
0089     // grab container & key
0090     TowerInfoContainer* towers = Interfaces::GetTowerInfoStore(
0091       topNode,
0092       Const::MapIndexOntoTowerInfo()[ subsys ]
0093     );
0094     const uint32_t key = towers -> encode_key(channel);
0095 
0096     // grab indices
0097     const int iEta = towers -> getTowerEtaBin(key);
0098     const int iPhi = towers -> getTowerPhiBin(key);
0099     return make_tuple((int) key, iEta, iPhi);
0100 
0101   }  // end 'GetTowerIndices(int, int, PHCompositeNode*)'
0102 
0103 
0104 
0105   // --------------------------------------------------------------------------
0106   //! Get tower coordinates in (x, y, z)
0107   // --------------------------------------------------------------------------
0108   ROOT::Math::XYZVector Tools::GetTowerPositionXYZ(const int rawKey, const int subsys, PHCompositeNode* topNode) {
0109 
0110     // get corresponding geometry
0111     RawTowerGeom* geometry = Interfaces::GetTowerGeometry(topNode, subsys, rawKey);
0112 
0113     // grab (x, y, z) coordinates
0114     ROOT::Math::XYZVector position(
0115       geometry -> get_center_x(),
0116       geometry -> get_center_y(),
0117       geometry -> get_center_z()
0118     );
0119     return position;
0120 
0121   }  // end 'GetTowerPositionXYZ(int, int, PHCompositeNode*)'
0122 
0123 
0124 
0125   // --------------------------------------------------------------------------
0126   //! Get tower coordinates in (r, eta, phi)
0127   // --------------------------------------------------------------------------
0128   ROOT::Math::RhoEtaPhiVector Tools::GetTowerPositionRhoEtaPhi(
0129     const int rawKey,
0130     const int subsys,
0131     const float zVtx,
0132     PHCompositeNode* topNode
0133   ) {
0134 
0135     // get corresponding geometry
0136     RawTowerGeom* geometry = Interfaces::GetTowerGeometry(topNode, subsys, rawKey);
0137 
0138     // calculate variables
0139     const float zShift = (geometry -> get_center_z()) - zVtx;
0140     const float radius = geometry -> get_center_radius();
0141     const float eta    = asinh(zShift / radius);
0142     const float phi    = atan2(geometry -> get_center_y(), geometry -> get_center_x());
0143 
0144     // grab (rho, eta, phi) coordinates
0145     ROOT::Math::RhoEtaPhiVector position(
0146       radius,
0147       eta,
0148       phi
0149     );
0150     return position;
0151 
0152   }  // end 'GetTowerPositionRhoEtaPhi(int, int, float, PHCompositeNode*)'
0153 
0154 
0155 
0156   // --------------------------------------------------------------------------
0157   //! Get 4-momentum for a tower
0158   // --------------------------------------------------------------------------
0159   ROOT::Math::PxPyPzEVector Tools::GetTowerMomentum(const double energy, const ROOT::Math::RhoEtaPhiVector pos) {
0160 
0161     // grab eta, phi, and pt
0162     const double hTwr  = pos.Eta();
0163     const double fTwr  = pos.Phi();
0164     const double ptTwr = energy / cosh(hTwr);
0165 
0166     // fill in 4-vector
0167     ROOT::Math::PxPyPzEVector mom(
0168       ptTwr * cos(fTwr),
0169       ptTwr * sin(fTwr),
0170       ptTwr * sinh(hTwr),
0171       energy
0172     );
0173     return mom;
0174 
0175   }  // end 'GetTowerMomentum(double, ROOT::Math::XYZVector, ROOT::Math::XYZVector)'
0176 
0177 }  // end SColdQcdCorrelatorAnalysis namespace
0178 
0179 // end ------------------------------------------------------------------------