CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaTowerIsolation.cc
Go to the documentation of this file.
1 //*****************************************************************************
2 // File: EgammaTowerIsolation.cc
3 // ----------------------------------------------------------------------------
4 // OrigAuth: Matthias Mozer
5 // Institute: IIHE-VUB
6 //=============================================================================
7 //*****************************************************************************
8 //C++ includes
9 #include <vector>
10 #include <functional>
11 #include <math.h>
12 
13 //ROOT includes
14 #include <Math/VectorUtil.h>
15 
16 
17 //CMSSW includes
24 
25 using namespace ROOT::Math::VectorUtil ;
26 
28  double intRadius,
29  double etLow,
30  signed int depth,
31  const CaloTowerCollection* towercollection) :
32  extRadius_(extRadius),
33  intRadius_(intRadius),
34  etLow_(etLow),
35  depth_(depth),
36  towercollection_(towercollection)
37 {
38 }
39 
41 {
42 }
43 
44 
45 
46 
47 double EgammaTowerIsolation::getTowerEtSum(const reco::Candidate* photon, const std::vector<CaloTowerDetId> * detIdToExclude ) const
48 {
49  return getTowerEtSum( photon->get<reco::SuperClusterRef>().get(), detIdToExclude );
50 }
51 
52 double EgammaTowerIsolation::getTowerEtSum(const reco::SuperCluster* sc, const std::vector<CaloTowerDetId> * detIdToExclude ) const
53 {
54  double candEta=sc->eta();
55  double candPhi=sc->phi();
56  double ptSum =0.;
57 
58  //loop over towers
60 
61  // skip the towers to exclude
62  if ( detIdToExclude )
63  {
64  std::vector<CaloTowerDetId>::const_iterator itcheck=find(detIdToExclude->begin(),detIdToExclude->end(),trItr->id());
65  if (itcheck != detIdToExclude->end())
66  continue;
67  }
68 
69  double this_pt=0;
70  switch(depth_){
71  case AllDepths: this_pt = trItr->hadEt();break;
72  case Depth1: this_pt = trItr->ietaAbs()<18 || trItr->ietaAbs()>29 ? trItr->hadEt() : trItr->hadEnergyHeInnerLayer()*sin(trItr->p4().theta());break;
73  case Depth2: this_pt = trItr->hadEnergyHeOuterLayer()*sin(trItr->p4().theta());break;
74  default: throw cms::Exception("Configuration Error") << "EgammaTowerIsolation: Depth " << depth_ << " not known. "; break;
75  }
76 
77  if ( this_pt < etLow_ )
78  continue ;
79 
80  double towerEta=trItr->eta();
81  double towerPhi=trItr->phi();
82  double twoPi= 2*M_PI;
83  if(towerPhi<0) towerPhi+=twoPi;
84  if(candPhi<0) candPhi+=twoPi;
85  double deltaPhi=fabs(towerPhi-candPhi);
86  if(deltaPhi>twoPi) deltaPhi-=twoPi;
87  if(deltaPhi>M_PI) deltaPhi=twoPi-deltaPhi;
88  double deltaEta = towerEta - candEta;
89 
90  double dr = deltaEta*deltaEta + deltaPhi*deltaPhi;
91  if( dr < extRadius_*extRadius_ &&
92  dr >= intRadius_*intRadius_ )
93  { ptSum += this_pt ; }
94 
95  }//end loop over tracks
96 
97  return ptSum ;
98 
99  }
100 
101 
102 double EgammaTowerIsolation::getTowerESum(const reco::Candidate* photon, const std::vector<CaloTowerDetId> * detIdToExclude ) const
103 {
104  return getTowerESum( photon->get<reco::SuperClusterRef>().get(), detIdToExclude );
105 }
106 
107 double EgammaTowerIsolation::getTowerESum(const reco::SuperCluster* sc, const std::vector<CaloTowerDetId> * detIdToExclude ) const
108 {
109  double candEta=sc->eta();
110  double candPhi=sc->phi();
111  double eSum =0.;
112 
113  //loop over towers
114  for(CaloTowerCollection::const_iterator trItr = towercollection_->begin(); trItr != towercollection_->end(); ++trItr){
115 
116  // skip the towers to exclude
117  if( detIdToExclude ) {
118  std::vector<CaloTowerDetId>::const_iterator itcheck=find(detIdToExclude->begin(),detIdToExclude->end(),trItr->id());
119  if (itcheck != detIdToExclude->end())
120  continue;
121  }
122 
123  double this_e=0;
124  switch(depth_){
125  case AllDepths: this_e = trItr->hadEnergy();break;
126  case Depth1: this_e = trItr->ietaAbs()<18 || trItr->ietaAbs()>29 ? trItr->hadEnergy() : trItr->hadEnergyHeInnerLayer();break;
127  case Depth2: this_e = trItr->hadEnergyHeOuterLayer();break;
128  default: throw cms::Exception("Configuration Error") << "EgammaTowerIsolation: Depth " << depth_ << " not known. "; break;
129  }
130 
131  if ( this_e*sin(trItr->p4().theta()) < etLow_ )
132  continue ;
133 
134  double towerEta=trItr->eta();
135  double towerPhi=trItr->phi();
136  double twoPi= 2*M_PI;
137  if(towerPhi<0) towerPhi+=twoPi;
138  if(candPhi<0) candPhi+=twoPi;
139  double deltaPhi=fabs(towerPhi-candPhi);
140  if(deltaPhi>twoPi) deltaPhi-=twoPi;
141  if(deltaPhi>M_PI) deltaPhi=twoPi-deltaPhi;
142  double deltaEta = towerEta - candEta;
143 
144 
145  double dr = deltaEta*deltaEta + deltaPhi*deltaPhi;
146  if( dr < extRadius_*extRadius_ &&
147  dr >= intRadius_*intRadius_ )
148  {
149  eSum += this_e;
150  }
151 
152  }//end loop over tracks
153 
154  return eSum;
155 }
156 
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< CaloTower >::const_iterator const_iterator
EgammaTowerIsolation(double extRadius, double intRadius, double etLow, signed int depth, const CaloTowerCollection *)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:160
double getTowerEtSum(const reco::Candidate *, const std::vector< CaloTowerDetId > *detIdToExclude=0) const
const_iterator end() const
double getTowerESum(const reco::Candidate *, const std::vector< CaloTowerDetId > *detIdToExclude=0) const
#define M_PI
Definition: BFit3D.cc:3
const CaloTowerCollection * towercollection_
double twoPi()
Definition: Pi.h:32
T get() const
get a component
Definition: Candidate.h:216
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:163
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
const_iterator begin() const