Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-02 23:59:42

0001 #ifndef DATAFORMATS_CALOTOWERS_CALOTOWER_H
0002 #define DATAFORMATS_CALOTOWERS_CALOTOWER_H 1
0003 
0004 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
0007 #include "DataFormats/Math/interface/Vector3D.h"
0008 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0009 #include "Rtypes.h"
0010 #include <vector>
0011 #include <cmath>
0012 
0013 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0014 
0015 /** \class CaloTower
0016     
0017 \author J. Mans - Minnesota
0018 */
0019 
0020 // Original author: J. Mans - Minnesota
0021 //
0022 // Modified: Anton Anastassov (Northwestern)
0023 //    Make CaloTower inherit from LeafCandidate,
0024 //    add new members and accessors.
0025 
0026 class CaloTower : public reco::LeafCandidate {
0027 public:
0028   typedef CaloTowerDetId key_type;  // for SortedCollection
0029 
0030   // Default constructor
0031   CaloTower();
0032 
0033   // Constructors from values
0034 
0035   CaloTower(const CaloTowerDetId& id,
0036             double emE,
0037             double hadE,
0038             double outerE,
0039             int ecal_tp,
0040             int hcal_tp,
0041             const PolarLorentzVector& p4,
0042             const GlobalPoint& emPosition,
0043             const GlobalPoint& hadPosition);
0044 
0045   CaloTower(const CaloTowerDetId& id,
0046             double emE,
0047             double hadE,
0048             double outerE,
0049             int ecal_tp,
0050             int hcal_tp,
0051             const LorentzVector& p4,
0052             const GlobalPoint& emPosition,
0053             const GlobalPoint& hadPosition);
0054 
0055   CaloTower(CaloTowerDetId id,
0056             float emE,
0057             float hadE,
0058             float outerE,
0059             int ecal_tp,
0060             int hcal_tp,
0061             GlobalVector p3,
0062             float iEnergy,
0063             bool massless,
0064             GlobalPoint emPosition,
0065             GlobalPoint hadPosition);
0066 
0067   CaloTower(CaloTowerDetId id,
0068             float emE,
0069             float hadE,
0070             float outerE,
0071             int ecal_tp,
0072             int hcal_tp,
0073             GlobalVector p3,
0074             float iEnergy,
0075             float imass,
0076             GlobalPoint emPosition,
0077             GlobalPoint hadPosition);
0078 
0079   // setters
0080   void addConstituent(DetId id) { constituents_.push_back(id); }
0081   void addConstituents(const std::vector<DetId>& ids);
0082   void setConstituents(std::vector<DetId>&& ids) { constituents_ = std::move(ids); }
0083   void setEcalTime(int t) { ecalTime_ = t; };
0084   void setHcalTime(int t) { hcalTime_ = t; };
0085   void setHcalSubdet(int lastHB, int lastHE, int lastHF, int lastHO) {
0086     int ct_ieta = ietaAbs();
0087     if (ct_ieta <= lastHB)
0088       subdet_ = HcalBarrel;
0089     else if (ct_ieta <= lastHE)
0090       subdet_ = HcalEndcap;
0091     else if (ct_ieta <= lastHF)
0092       subdet_ = HcalForward;
0093 
0094     //account for HO separately
0095     if (ct_ieta <= lastHO)
0096       inHO_ = true;
0097     else
0098       inHO_ = false;
0099 
0100     //account for gap/crossover tower separately
0101     if (ct_ieta == lastHB)
0102       inHBHEgap_ = true;
0103     else
0104       inHBHEgap_ = false;
0105   }
0106 
0107   // set CaloTower status based on the number of
0108   // bad/recovered/problematic cells in ECAL and HCAL
0109 
0110   void setCaloTowerStatus(unsigned int numBadHcalChan,
0111                           unsigned int numBadEcalChan,
0112                           unsigned int numRecHcalChan,
0113                           unsigned int numRecEcalChan,
0114                           unsigned int numProbHcalChan,
0115                           unsigned int numProbEcalChan);
0116 
0117   void setCaloTowerStatus(uint32_t s) { twrStatusWord_ = s; }
0118 
0119   // set the hottest cell energy in the tower
0120   void setHottestCellE(double e) { hottestCellE_ = e; }
0121 
0122   // getters
0123   CaloTowerDetId id() const { return id_; }
0124   const std::vector<DetId>& constituents() const { return constituents_; }
0125   size_t constituentsSize() const { return constituents_.size(); }
0126   DetId constituent(size_t i) const { return constituents_[i]; }
0127 
0128   // energy contributions from different detectors
0129   // energy in HO ("outerEnergy")is not included in "hadEnergy"
0130   double emEnergy() const { return emE_; }
0131   double hadEnergy() const { return hadE_; }
0132   double outerEnergy() const { return (inHO_) ? outerE_ : 0.0; }
0133 
0134   // transverse energies wrt to vtx (0,0,0)
0135   double emEt() const { return emE_ * sin(theta()); }
0136   double hadEt() const { return hadE_ * sin(theta()); }
0137   double outerEt() const { return (inHO_) ? outerE_ * sin(theta()) : 0.0; }
0138 
0139   // preserve the inherited default accessors where applicable
0140   // (user gets default p4 wrt to vtx (0,0,0) using p4(), etc.
0141 
0142   using LeafCandidate::et;
0143   using LeafCandidate::p;
0144   using LeafCandidate::p4;
0145 
0146   // recalculated wrt user provided vertex Z position;
0147 
0148   math::PtEtaPhiMLorentzVector p4(double vtxZ) const;
0149   double p(double vtxZ) const { return p4(vtxZ).P(); }
0150   double et(double vtxZ) const { return p4(vtxZ).Et(); }
0151 
0152   double emEt(double vtxZ) const { return emE_ * sin(p4(vtxZ).theta()); }
0153   double hadEt(double vtxZ) const { return hadE_ * sin(p4(vtxZ).theta()); }
0154   double outerEt(double vtxZ) const { return (inHO_) ? outerE_ * sin(p4(vtxZ).theta()) : 0.0; }
0155 
0156   // recalculated wrt vertex provided as 3D point
0157 
0158   math::PtEtaPhiMLorentzVector p4(const Point& v) const;
0159   double p(const Point& v) const { return p4(v).P(); }
0160   double et(const Point& v) const { return p4(v).Et(); }
0161 
0162   double emEt(const Point& v) const { return emE_ * sin(p4(v).theta()); }
0163   double hadEt(const Point& v) const { return hadE_ * sin(p4(v).theta()); }
0164   double outerEt(const Point& v) const { return (inHO_) ? outerE_ * sin(p4(v).theta()) : 0.0; }
0165 
0166   double hottestCellE() const { return hottestCellE_; }
0167 
0168   // Access to p4 comming from HO alone: requested by JetMET to add/subtract HO contributions
0169   // to the tower for cases when the tower collection was created without/with HO
0170 
0171   math::PtEtaPhiMLorentzVector p4_HO() const;
0172   math::PtEtaPhiMLorentzVector p4_HO(double vtxZ) const;
0173   math::PtEtaPhiMLorentzVector p4_HO(const Point& v) const;
0174 
0175   // the reference poins in ECAL and HCAL for direction determination
0176   // algorithm and parameters for selecting these points are set in the CaloTowersCreator
0177   const GlobalPoint& emPosition() const { return emPosition_; }
0178   const GlobalPoint& hadPosition() const { return hadPosition_; }
0179 
0180   int emLvl1() const { return emLvl1_; }
0181   int hadLv11() const { return hadLvl1_; }
0182 
0183   // energy contained in depths>1 in the HE for 18<|iEta|<29
0184   double hadEnergyHeOuterLayer() const { return (subdet_ == HcalEndcap) ? outerE_ : 0; }
0185   double hadEnergyHeInnerLayer() const { return (subdet_ == HcalEndcap) ? hadE_ - outerE_ : 0; }
0186 
0187   // energy in the tower by HCAL subdetector
0188   // This is trivial except for tower 16
0189   // needed by JetMET cleanup in AOD.
0190   double energyInHB() const;  // { return (id_.ietaAbs()<16)? outerE_ : 0.0; }
0191   double energyInHE() const;
0192   double energyInHF() const;
0193   double energyInHO() const;
0194 
0195   // time (ns) in ECAL/HCAL components of the tower based on weigted sum of the times in the contributing RecHits
0196   float ecalTime() const { return float(ecalTime_) * 0.01; }
0197   float hcalTime() const { return float(hcalTime_) * 0.01; }
0198 
0199   // position information on the tower
0200   int ieta() const { return id_.ieta(); }
0201   int ietaAbs() const { return id_.ietaAbs(); }
0202   int iphi() const { return id_.iphi(); }
0203   int zside() const { return id_.zside(); }
0204 
0205   int numCrystals() const;
0206 
0207   // methods to retrieve status information from the CaloTower:
0208   // number of bad/recovered/problematic cells in the tower
0209   // separately for ECAL and HCAL
0210 
0211   unsigned int numBadEcalCells() const { return (twrStatusWord_ & 0x1F); }
0212   unsigned int numRecoveredEcalCells() const { return ((twrStatusWord_ >> 5) & 0x1F); }
0213   unsigned int numProblematicEcalCells() const { return ((twrStatusWord_ >> 10) & 0x1F); }
0214 
0215   unsigned int numBadHcalCells() const { return ((twrStatusWord_ >> 15) & 0x7); }
0216   unsigned int numRecoveredHcalCells() const { return ((twrStatusWord_ >> 18) & 0x7); }
0217   unsigned int numProblematicHcalCells() const { return ((twrStatusWord_ >> 21) & 0x7); }
0218 
0219   // the status word itself
0220   uint32_t towerStatusWord() const { return twrStatusWord_; }
0221 
0222 private:
0223   CaloTowerDetId id_;
0224 
0225   uint32_t twrStatusWord_;
0226 
0227   // positions of assumed EM and HAD shower positions
0228   GlobalPoint emPosition_;
0229   GlobalPoint hadPosition_;
0230 
0231   //hcal subdetector info
0232   HcalSubdetector subdet_{HcalEmpty};
0233   bool inHO_{false}, inHBHEgap_{false};
0234 
0235   // time
0236   int ecalTime_;
0237   int hcalTime_;
0238 
0239   float emE_, hadE_, outerE_;
0240   // for Jet ID use: hottest cell (ECAl or HCAL)
0241   float hottestCellE_;
0242 
0243   int emLvl1_, hadLvl1_;
0244   std::vector<DetId> constituents_;
0245 
0246   // vertex correction of EM and HAD momentum components:
0247   // internally used in the transformation of the CaloTower p4
0248 
0249   // for 3D vertex
0250   math::PtEtaPhiMLorentzVector hadP4(const Point& v) const;
0251   math::PtEtaPhiMLorentzVector emP4(const Point& v) const;
0252 
0253   // taking only z-component
0254   math::PtEtaPhiMLorentzVector hadP4(double vtxZ) const;
0255   math::PtEtaPhiMLorentzVector emP4(double vtxZ) const;
0256 };
0257 
0258 std::ostream& operator<<(std::ostream& s, const CaloTower& ct);
0259 
0260 inline bool operator==(const CaloTower& t1, const CaloTower& t2) { return t1.id() == t2.id(); }
0261 
0262 #endif