CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EgammaRecHitIsolation.cc
Go to the documentation of this file.
1 //*****************************************************************************
2 // File: EgammaRecHitIsolation.cc
3 // ----------------------------------------------------------------------------
4 // OrigAuth: Matthias Mozer, hacked by Sam Harper (ie the ugly stuff is mine)
5 // Institute: IIHE-VUB, RAL
6 //=============================================================================
7 //*****************************************************************************
8 //C++ includes
9 #include <vector>
10 #include <functional>
11 
12 //ROOT includes
13 #include <Math/VectorUtil.h>
14 
15 //CMSSW includes
29 
30 using namespace std;
31 
33  double intRadius,
34  double etaSlice,
35  double etLow,
36  double eLow,
37  edm::ESHandle<CaloGeometry> theCaloGeom,
38  const EcalRecHitCollection& caloHits,
39  const EcalSeverityLevelAlgo* sl,
40  DetId::Detector detector)
41  : // not used anymore, kept for compatibility
42  extRadius_(extRadius),
43  intRadius_(intRadius),
44  etaSlice_(etaSlice),
45  etLow_(etLow),
46  eLow_(eLow),
47  theCaloGeom_(theCaloGeom),
48  caloHits_(caloHits),
49  sevLevel_(sl),
50  useNumCrystals_(false),
51  vetoClustered_(false),
52  ecalBarHits_(nullptr),
53  //chStatus_(0),
54  severitiesexcl_(0),
55  //severityRecHitThreshold_(0),
56  //spId_(EcalSeverityLevelAlgo::kSwissCross),
57  //spIdThreshold_(0),
58  flags_(0) {
59  //set up the geometry and selector
60  const CaloGeometry* caloGeom = theCaloGeom_.product();
63 }
64 
66 
67 double EgammaRecHitIsolation::getSum_(const reco::Candidate* emObject, bool returnEt) const {
68  double energySum = 0.;
69  if (!caloHits_.empty()) {
70  //Take the SC position
72  math::XYZPoint const& theCaloPosition = sc.get()->position();
73  GlobalPoint pclu(theCaloPosition.x(), theCaloPosition.y(), theCaloPosition.z());
74  float etaclus = pclu.eta();
75  float phiclus = pclu.phi();
76  float r2 = intRadius_ * intRadius_;
77 
78  std::vector<std::pair<DetId, float> >::const_iterator rhIt;
79 
80  for (int subdetnr = 0; subdetnr <= 1; subdetnr++) { // look in barrel and endcap
81  if (nullptr == subdet_[subdetnr])
82  continue;
83 
85  subdet_[subdetnr]->getCells(pclu, extRadius_); // select cells around cluster
87 
88  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin(); i != chosen.end();
89  ++i) { //loop selected cells
90  j = caloHits_.find(*i); // find selected cell among rechits
91  if (j != caloHits_.end()) { // add rechit only if available
92  auto cell = theCaloGeom_->getGeometry(*i);
93  float eta = cell->etaPos();
94  float phi = cell->phiPos();
95  float etaDiff = eta - etaclus;
96  float phiDiff = reco::deltaPhi(phi, phiclus);
97  float energy = j->energy();
98 
99  if (useNumCrystals_) {
100  if (fabs(etaclus) < 1.479) { // Barrel num crystals, crystal width = 0.0174
101  if (fabs(etaDiff) < 0.0174 * etaSlice_)
102  continue;
103  //if (sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_)
104  //continue;
105  if ((etaDiff * etaDiff + phiDiff * phiDiff) < 0.00030276 * r2)
106  continue;
107  } else { // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
108  if (fabs(etaDiff) < 0.00864 * fabs(sinh(eta)) * etaSlice_)
109  continue;
110  //if (sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_)
111  // continue;
112  if ((etaDiff * etaDiff + phiDiff * phiDiff) < (0.000037325 * (cosh(2 * eta) - 1) * r2))
113  continue;
114  }
115  } else {
116  if (fabs(etaDiff) < etaSlice_)
117  continue; // jurassic strip cut
118  if (etaDiff * etaDiff + phiDiff * phiDiff < r2)
119  continue; // jurassic exclusion cone cut
120  }
121  //Check if RecHit is in SC
122  if (vetoClustered_) {
123  //Loop over basic clusters:
124  bool isClustered = false;
125  for (reco::CaloCluster_iterator bcIt = sc->clustersBegin(); bcIt != sc->clustersEnd(); ++bcIt) {
126  for (rhIt = (*bcIt)->hitsAndFractions().begin(); rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
127  if (rhIt->first == *i)
128  isClustered = true;
129  if (isClustered)
130  break;
131  }
132 
133  if (isClustered)
134  break;
135  } //end loop over basic clusters
136 
137  if (isClustered)
138  continue;
139  } //end if removeClustered
140 
141  //std::cout << "detid " << j->detid() << std::endl;
142  int severityFlag = ecalBarHits_ == nullptr ? -1 : sevLevel_->severityLevel(j->detid(), *ecalBarHits_);
143  std::vector<int>::const_iterator sit =
144  std::find(severitiesexcl_.begin(), severitiesexcl_.end(), severityFlag);
145 
146  if (sit != severitiesexcl_.end())
147  continue;
148 
149  // new rechit flag checks
150  //std::vector<int>::const_iterator vit = std::find(flags_.begin(),
151  // flags_.end(),
152  // j->recoFlag());
153  //if (vit != flags_.end())
154  // continue;
155  if (!j->checkFlag(EcalRecHit::kGood)) {
156  if (j->checkFlags(flags_)) {
157  continue;
158  }
159  }
160 
161  float et = energy * std::sqrt(cell->getPosition().perp2() / cell->getPosition().mag2());
162  if (et > etLow_ && energy > eLow_) { //Changed energy --> fabs(energy) - now changed back to energy
163  if (returnEt)
164  energySum += et;
165  else
166  energySum += energy;
167  }
168 
169  } //End if not end of list
170  } //End loop over rechits
171  } //End loop over barrel/endcap
172  } //End if caloHits_
173 
174  return energySum;
175 }
176 
177 double EgammaRecHitIsolation::getSum_(const reco::SuperCluster* sc, bool returnEt) const {
178  double energySum = 0.;
179  if (!caloHits_.empty()) {
180  //Take the SC position
181 
182  const math::XYZPoint& theCaloPosition = sc->position();
183  GlobalPoint pclu(theCaloPosition.x(), theCaloPosition.y(), theCaloPosition.z());
184  double etaclus = pclu.eta();
185  double phiclus = pclu.phi();
186  double r2 = intRadius_ * intRadius_;
187 
188  std::vector<std::pair<DetId, float> >::const_iterator rhIt;
189 
190  for (int subdetnr = 0; subdetnr <= 1; subdetnr++) { // look in barrel and endcap
191  if (nullptr == subdet_[subdetnr])
192  continue;
194  subdet_[subdetnr]->getCells(pclu, extRadius_); // select cells around cluster
196  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin(); i != chosen.end();
197  ++i) { //loop selected cells
198 
199  j = caloHits_.find(*i); // find selected cell among rechits
200  if (j != caloHits_.end()) { // add rechit only if available
201  const GlobalPoint& position = (theCaloGeom_.product())->getPosition(*i);
202  double eta = position.eta();
203  double phi = position.phi();
204  double etaDiff = eta - etaclus;
205  double phiDiff = reco::deltaPhi(phi, phiclus);
206  double energy = j->energy();
207 
208  if (useNumCrystals_) {
209  if (fabs(etaclus) < 1.479) { // Barrel num crystals, crystal width = 0.0174
210  if (fabs(etaDiff) < 0.0174 * etaSlice_)
211  continue;
212  // if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_) continue;
213  if ((etaDiff * etaDiff + phiDiff * phiDiff) < 0.00030276 * r2)
214  continue;
215  } else { // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
216  if (fabs(etaDiff) < 0.00864 * fabs(sinh(eta)) * etaSlice_)
217  continue;
218  // if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_) continue;
219  if ((etaDiff * etaDiff + phiDiff * phiDiff) < (0.000037325 * (cosh(2 * eta) - 1) * r2))
220  continue;
221  }
222  } else {
223  if (fabs(etaDiff) < etaSlice_)
224  continue; // jurassic strip cut
225  if (etaDiff * etaDiff + phiDiff * phiDiff < r2)
226  continue; // jurassic exclusion cone cut
227  }
228 
229  //Check if RecHit is in SC
230  if (vetoClustered_) {
231  //Loop over basic clusters:
232  bool isClustered = false;
233  for (reco::CaloCluster_iterator bcIt = sc->clustersBegin(); bcIt != sc->clustersEnd(); ++bcIt) {
234  for (rhIt = (*bcIt)->hitsAndFractions().begin(); rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
235  if (rhIt->first == *i)
236  isClustered = true;
237  if (isClustered)
238  break;
239  }
240  if (isClustered)
241  break;
242  } //end loop over basic clusters
243 
244  if (isClustered)
245  continue;
246  } //end if removeClustered
247 
248  int severityFlag = sevLevel_->severityLevel(j->detid(), *ecalBarHits_);
249  std::vector<int>::const_iterator sit =
250  std::find(severitiesexcl_.begin(), severitiesexcl_.end(), severityFlag);
251 
252  if (sit != severitiesexcl_.end())
253  continue;
254 
255  // new rechit flag checks
256  //std::vector<int>::const_iterator vit = std::find(flags_.begin(),
257  // flags_.end(),
258  // j->recoFlag());
259  //if (vit != flags_.end())
260  // continue;
261  if (!j->checkFlag(EcalRecHit::kGood)) {
262  if (j->checkFlags(flags_)) {
263  continue;
264  }
265  }
266 
267  double et = energy * position.perp() / position.mag();
268  if (et > etLow_ && energy > eLow_) { //Changed energy --> fabs(energy) -- then changed into energy
269  if (returnEt)
270  energySum += et;
271  else
272  energySum += energy;
273  }
274 
275  } //End if not end of list
276  } //End loop over rechits
277  } //End loop over barrel/endcap
278  } //End if caloHits_
279 
280  return energySum;
281 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
const CaloSubdetectorGeometry * subdet_[2]
edm::ESHandle< CaloGeometry > theCaloGeom_
std::vector< int > flags_
T perp() const
Definition: PV3DBase.h:69
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
std::vector< EcalRecHit >::const_iterator const_iterator
std::vector< int > severitiesexcl_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
double getSum_(const reco::Candidate *, bool returnEt) const
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
T mag() const
Definition: PV3DBase.h:64
T sqrt(T t)
Definition: SSEVec.h:19
EgammaRecHitIsolation(double extRadius, double intRadius, double etaSlice, double etLow, double eLow, edm::ESHandle< CaloGeometry >, const EcalRecHitCollection &, const EcalSeverityLevelAlgo *, DetId::Detector detector)
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
const EcalRecHitCollection * ecalBarHits_
const_iterator end() const
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Detector
Definition: DetId.h:24
T const * product() const
Definition: ESHandle.h:86
T eta() const
Definition: PV3DBase.h:73
iterator find(key_type k)
static int position[264][3]
Definition: ReadPGInfo.cc:289
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:86
T get() const
get a component
Definition: Candidate.h:221
const EcalSeverityLevelAlgo * sevLevel_
double energySum(const DataFrame &df, int fs, int ls)
const EcalRecHitCollection & caloHits_
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:89