CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DataFormats/CaloTowers/interface/CaloTower.h

Go to the documentation of this file.
00001 #ifndef DATAFORMATS_CALOTOWERS_CALOTOWER_H
00002 #define DATAFORMATS_CALOTOWERS_CALOTOWER_H 1
00003 
00004 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00005 #include "DataFormats/DetId/interface/DetId.h"
00006 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
00007 #include "DataFormats/Math/interface/Vector3D.h"
00008 #include "Rtypes.h" 
00009 #include <vector>
00010 #include <cmath>
00011 
00012 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00013 
00021 // Original author: J. Mans - Minnesota
00022 //
00023 // Modified: Anton Anastassov (Northwestern)
00024 //    Make CaloTower inherit from LeafCandidate,
00025 //    add new members and accessors.
00026 
00027 
00028 class CaloTower : public reco::LeafCandidate {
00029 public:
00030   typedef CaloTowerDetId key_type; // for SortedCollection
00031 
00032   // Default constructor
00033   CaloTower();
00034 
00035   // Constructors from values
00036 
00037   CaloTower(const CaloTowerDetId& id, 
00038             double emE, double hadE, double outerE,
00039             int ecal_tp, int hcal_tp,
00040             const PolarLorentzVector p4,
00041       GlobalPoint emPosition, GlobalPoint hadPosition);
00042 
00043   CaloTower(const CaloTowerDetId& id, 
00044             double emE, double hadE, double outerE,
00045             int ecal_tp, int hcal_tp,
00046             const LorentzVector p4,
00047       GlobalPoint emPosition, GlobalPoint hadPosition);
00048 
00049 
00050    // setters
00051   void addConstituent( DetId id ) { constituents_.push_back( id ); }
00052   void addConstituents( const std::vector<DetId>& ids );
00053   void setEcalTime(int t) { ecalTime_ = t; };
00054   void setHcalTime(int t) { hcalTime_ = t; };
00055 
00056   // set CaloTower status based on the number of
00057   // bad/recovered/problematic cells in ECAL and HCAL
00058 
00059   void setCaloTowerStatus(unsigned int numBadHcalChan,unsigned int numBadEcalChan, 
00060                           unsigned int numRecHcalChan,unsigned int numRecEcalChan,
00061                           unsigned int numProbHcalChan,unsigned int numProbEcalChan);
00062 
00063   void setCaloTowerStatus(uint32_t s) { twrStatusWord_ = s; }
00064 
00065   // set the hottest cell energy in the tower
00066   void setHottestCellE(double e) { hottestCellE_ = e; }
00067 
00068 
00069 
00070 
00071   // getters
00072   CaloTowerDetId id() const { return id_; }
00073   const std::vector<DetId>& constituents() const { return constituents_; }
00074   size_t constituentsSize() const { return constituents_.size(); }
00075   DetId constituent( size_t i ) const { return constituents_[ i ]; }
00076 
00077   // energy contributions from different detectors
00078   // energy in HO ("outerEnergy")is not included in "hadEnergy"
00079   double emEnergy() const { return emE_ ; }
00080   double hadEnergy() const { return hadE_ ; }
00081   double outerEnergy() const { return (id_.ietaAbs()<16)? outerE_ : 0.0; }
00082 
00083   // transverse energies wrt to vtx (0,0,0)
00084   double emEt() const { return emE_ * sin( theta() ); }
00085   double hadEt() const { return hadE_ * sin( theta() ); }
00086   double outerEt() const { return (id_.ietaAbs()<16)? outerE_ * sin( theta() ) : 0.0; }
00087 
00088 
00089   // preserve the inherited default accessors where applicable
00090   // (user gets default p4 wrt to vtx (0,0,0) using p4(), etc.
00091 
00092   using LeafCandidate::p4;
00093   using LeafCandidate::p;
00094   using LeafCandidate::et; 
00095 
00096 
00097   // recalculated wrt user provided vertex Z position;
00098 
00099   math::PtEtaPhiMLorentzVector p4(double vtxZ) const;
00100   double p (double vtxZ) const { return p4(vtxZ).P(); }
00101   double et(double vtxZ) const { return p4(vtxZ).Et(); }
00102 
00103   double emEt(double vtxZ)  const { return  emE_ * sin(p4(vtxZ).theta()); }
00104   double hadEt(double vtxZ) const { return  hadE_ * sin(p4(vtxZ).theta()); }
00105   double outerEt(double vtxZ) const { return (id_.ietaAbs()<16)? outerE_ * sin(p4(vtxZ).theta()) : 0.0; }
00106 
00107   // recalculated wrt vertex provided as 3D point
00108 
00109   math::PtEtaPhiMLorentzVector p4(Point v) const;
00110   double p (Point v) const { return p4(v).P(); }
00111   double et(Point v) const { return p4(v).Et(); }
00112 
00113   double emEt(Point v)  const { return  emE_ * sin(p4(v).theta()); }
00114   double hadEt(Point v) const { return  hadE_ * sin(p4(v).theta()); }
00115   double outerEt(Point v) const { return (id_.ietaAbs()<16)? outerE_ * sin(p4(v).theta()) : 0.0; }
00116 
00117   double hottestCellE() const { return hottestCellE_; }
00118 
00119   // Access to p4 comming from HO alone: requested by JetMET to add/subtract HO contributions
00120   // to the tower for cases when the tower collection was created without/with HO   
00121 
00122   math::PtEtaPhiMLorentzVector p4_HO() const;  
00123   math::PtEtaPhiMLorentzVector p4_HO(double vtxZ) const;
00124   math::PtEtaPhiMLorentzVector p4_HO(Point v) const;
00125 
00126 
00127   // the reference poins in ECAL and HCAL for direction determination
00128   // algorithm and parameters for selecting these points are set in the CaloTowersCreator
00129   const GlobalPoint& emPosition()  const { return emPosition_ ; }
00130   const GlobalPoint& hadPosition() const { return hadPosition_ ; }
00131 
00132   int emLvl1() const { return emLvl1_; }
00133   int hadLv11() const { return hadLvl1_; }
00134 
00135   // energy contained in depths>1 in the HE for 18<|iEta|<29
00136   double hadEnergyHeOuterLayer() const { return (id_.ietaAbs()<18 || id_.ietaAbs()>29)? 0 : outerE_; }
00137   double hadEnergyHeInnerLayer() const { return (id_.ietaAbs()<18 || id_.ietaAbs()>29)? 0 : hadE_ - outerE_; }
00138 
00139   // energy in the tower by HCAL subdetector
00140   // This is trivial except for tower 16
00141   // needed by JetMET cleanup in AOD.
00142   double energyInHB() const; // { return (id_.ietaAbs()<16)? outerE_ : 0.0; }
00143   double energyInHE() const;
00144   double energyInHF() const;
00145   double energyInHO() const;
00146 
00147 
00148 
00149   // time (ns) in ECAL/HCAL components of the tower based on weigted sum of the times in the contributing RecHits
00150   float ecalTime() const { return float(ecalTime_) * 0.01; }
00151   float hcalTime() const { return float(hcalTime_) * 0.01; }
00152 
00153   // position information on the tower
00154   int ieta() const { return id_.ieta(); }
00155   int ietaAbs() const { return id_.ietaAbs(); }
00156   int iphi() const { return id_.iphi(); }
00157   int zside() const { return id_.zside(); }
00158 
00159   int numCrystals() const; 
00160 
00161   // methods to retrieve status information from the CaloTower:
00162   // number of bad/recovered/problematic cells in the tower
00163   // separately for ECAL and HCAL
00164 
00165   unsigned int numBadEcalCells() const { return (twrStatusWord_ & 0x1F); }
00166   unsigned int numRecoveredEcalCells() const { return ((twrStatusWord_ >> 5) & 0x1F); }
00167   unsigned int numProblematicEcalCells() const { return ((twrStatusWord_ >> 10) & 0x1F); }
00168 
00169   unsigned int numBadHcalCells() const { return ( (twrStatusWord_ >> 15)& 0x7); }
00170   unsigned int numRecoveredHcalCells() const { return ((twrStatusWord_ >> 18) & 0x7); }
00171   unsigned int numProblematicHcalCells() const { return ((twrStatusWord_ >> 21) & 0x7); }
00172 
00173   // the status word itself
00174   uint32_t towerStatusWord() const { return twrStatusWord_; }
00175 
00176 
00177 private:
00178   CaloTowerDetId id_;
00179  
00180   uint32_t twrStatusWord_;
00181 
00182    // positions of assumed EM and HAD shower positions
00183    GlobalPoint emPosition_;
00184    GlobalPoint hadPosition_;
00185 
00186    // time
00187    int ecalTime_;
00188    int hcalTime_;
00189 
00190   float emE_, hadE_, outerE_;
00191   // for Jet ID use: hottest cell (ECAl or HCAL)
00192   float hottestCellE_;
00193 
00194   int emLvl1_,hadLvl1_;
00195   std::vector<DetId> constituents_;
00196 
00197   // vertex correction of EM and HAD momentum components:
00198   // internally used in the transformation of the CaloTower p4
00199 
00200   // for 3D vertex
00201   math::PtEtaPhiMLorentzVector hadP4(Point v) const;
00202   math::PtEtaPhiMLorentzVector emP4(Point v) const;
00203 
00204   // taking only z-component
00205   math::PtEtaPhiMLorentzVector hadP4(double vtxZ) const;
00206   math::PtEtaPhiMLorentzVector emP4(double vtxZ) const;
00207 };
00208 
00209 std::ostream& operator<<(std::ostream& s, const CaloTower& ct);
00210 
00211 inline bool operator==( const CaloTower & t1, const CaloTower & t2 ) {
00212   return t1.id() == t2.id();
00213 } 
00214 
00215 #endif