CMS 3D CMS Logo

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,
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 
68  bool returnEt,
69  const EcalPFRecHitThresholds* thresholds) const {
70  double energySum = 0.;
71  if (!caloHits_.empty()) {
72  //Take the SC position
74  math::XYZPoint const& theCaloPosition = sc.get()->position();
75  GlobalPoint pclu(theCaloPosition.x(), theCaloPosition.y(), theCaloPosition.z());
76  float etaclus = pclu.eta();
77  float phiclus = pclu.phi();
78  float r2 = intRadius_ * intRadius_;
79 
80  std::vector<std::pair<DetId, float> >::const_iterator rhIt;
81 
82  for (int subdetnr = 0; subdetnr <= 1; subdetnr++) { // look in barrel and endcap
83  if (nullptr == subdet_[subdetnr])
84  continue;
85 
87  subdet_[subdetnr]->getCells(pclu, extRadius_); // select cells around cluster
89 
90  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin(); i != chosen.end();
91  ++i) { //loop selected cells
92  j = caloHits_.find(*i); // find selected cell among rechits
93  if (j != caloHits_.end()) { // add rechit only if available
94  auto cell = theCaloGeom_->getGeometry(*i);
95  float eta = cell->etaPos();
96  float phi = cell->phiPos();
97  float etaDiff = eta - etaclus;
98  float phiDiff = reco::deltaPhi(phi, phiclus);
99  float energy = j->energy();
100 
101  float rhThres = (thresholds != nullptr) ? (*thresholds)[j->detid()] : 0.f;
102  if (energy <= rhThres)
103  continue;
104 
105  if (useNumCrystals_) {
106  if (fabs(etaclus) < 1.479) { // Barrel num crystals, crystal width = 0.0174
107  if (fabs(etaDiff) < 0.0174 * etaSlice_)
108  continue;
109  //if (sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_)
110  //continue;
111  if ((etaDiff * etaDiff + phiDiff * phiDiff) < 0.00030276 * r2)
112  continue;
113  } else { // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
114  if (fabs(etaDiff) < 0.00864 * fabs(sinh(eta)) * etaSlice_)
115  continue;
116  //if (sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_)
117  // continue;
118  if ((etaDiff * etaDiff + phiDiff * phiDiff) < (0.000037325 * (cosh(2 * eta) - 1) * r2))
119  continue;
120  }
121  } else {
122  if (fabs(etaDiff) < etaSlice_)
123  continue; // jurassic strip cut
124  if (etaDiff * etaDiff + phiDiff * phiDiff < r2)
125  continue; // jurassic exclusion cone cut
126  }
127  //Check if RecHit is in SC
128  if (vetoClustered_) {
129  //Loop over basic clusters:
130  bool isClustered = false;
131  for (reco::CaloCluster_iterator bcIt = sc->clustersBegin(); bcIt != sc->clustersEnd(); ++bcIt) {
132  for (rhIt = (*bcIt)->hitsAndFractions().begin(); rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
133  if (rhIt->first == *i)
134  isClustered = true;
135  if (isClustered)
136  break;
137  }
138 
139  if (isClustered)
140  break;
141  } //end loop over basic clusters
142 
143  if (isClustered)
144  continue;
145  } //end if removeClustered
146 
147  //std::cout << "detid " << j->detid() << std::endl;
148  int severityFlag = ecalBarHits_ == nullptr ? -1 : sevLevel_->severityLevel(j->detid(), *ecalBarHits_);
149  std::vector<int>::const_iterator sit =
150  std::find(severitiesexcl_.begin(), severitiesexcl_.end(), severityFlag);
151 
152  if (sit != severitiesexcl_.end())
153  continue;
154 
155  // new rechit flag checks
156  //std::vector<int>::const_iterator vit = std::find(flags_.begin(),
157  // flags_.end(),
158  // j->recoFlag());
159  //if (vit != flags_.end())
160  // continue;
161  if (!j->checkFlag(EcalRecHit::kGood)) {
162  if (j->checkFlags(flags_)) {
163  continue;
164  }
165  }
166 
167  float et = energy * std::sqrt(cell->getPosition().perp2() / cell->getPosition().mag2());
168  if (et > etLow_ && energy > eLow_) { //Changed energy --> fabs(energy) - now changed back to energy
169  if (returnEt)
170  energySum += et;
171  else
172  energySum += energy;
173  }
174 
175  } //End if not end of list
176  } //End loop over rechits
177  } //End loop over barrel/endcap
178  } //End if caloHits_
179 
180  return energySum;
181 }
182 
184  bool returnEt,
185  const EcalPFRecHitThresholds* thresholds) const {
186  double energySum = 0.;
187  if (!caloHits_.empty()) {
188  //Take the SC position
189 
190  const math::XYZPoint& theCaloPosition = sc->position();
191  GlobalPoint pclu(theCaloPosition.x(), theCaloPosition.y(), theCaloPosition.z());
192  double etaclus = pclu.eta();
193  double phiclus = pclu.phi();
194  double r2 = intRadius_ * intRadius_;
195 
196  std::vector<std::pair<DetId, float> >::const_iterator rhIt;
197 
198  for (int subdetnr = 0; subdetnr <= 1; subdetnr++) { // look in barrel and endcap
199  if (nullptr == subdet_[subdetnr])
200  continue;
202  subdet_[subdetnr]->getCells(pclu, extRadius_); // select cells around cluster
204  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin(); i != chosen.end();
205  ++i) { //loop selected cells
206 
207  j = caloHits_.find(*i); // find selected cell among rechits
208  if (j != caloHits_.end()) { // add rechit only if available
209  const GlobalPoint& position = (theCaloGeom_.product())->getPosition(*i);
210  double eta = position.eta();
211  double phi = position.phi();
212  double etaDiff = eta - etaclus;
213  double phiDiff = reco::deltaPhi(phi, phiclus);
214  double energy = j->energy();
215 
216  float rhThres = (thresholds != nullptr) ? (*thresholds)[j->detid()] : 0.f;
217  if (energy <= rhThres)
218  continue;
219 
220  if (useNumCrystals_) {
221  if (fabs(etaclus) < 1.479) { // Barrel num crystals, crystal width = 0.0174
222  if (fabs(etaDiff) < 0.0174 * etaSlice_)
223  continue;
224  // if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_) continue;
225  if ((etaDiff * etaDiff + phiDiff * phiDiff) < 0.00030276 * r2)
226  continue;
227  } else { // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
228  if (fabs(etaDiff) < 0.00864 * fabs(sinh(eta)) * etaSlice_)
229  continue;
230  // if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_) continue;
231  if ((etaDiff * etaDiff + phiDiff * phiDiff) < (0.000037325 * (cosh(2 * eta) - 1) * r2))
232  continue;
233  }
234  } else {
235  if (fabs(etaDiff) < etaSlice_)
236  continue; // jurassic strip cut
237  if (etaDiff * etaDiff + phiDiff * phiDiff < r2)
238  continue; // jurassic exclusion cone cut
239  }
240 
241  //Check if RecHit is in SC
242  if (vetoClustered_) {
243  //Loop over basic clusters:
244  bool isClustered = false;
245  for (reco::CaloCluster_iterator bcIt = sc->clustersBegin(); bcIt != sc->clustersEnd(); ++bcIt) {
246  for (rhIt = (*bcIt)->hitsAndFractions().begin(); rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
247  if (rhIt->first == *i)
248  isClustered = true;
249  if (isClustered)
250  break;
251  }
252  if (isClustered)
253  break;
254  } //end loop over basic clusters
255 
256  if (isClustered)
257  continue;
258  } //end if removeClustered
259 
260  int severityFlag = sevLevel_->severityLevel(j->detid(), *ecalBarHits_);
261  std::vector<int>::const_iterator sit =
262  std::find(severitiesexcl_.begin(), severitiesexcl_.end(), severityFlag);
263 
264  if (sit != severitiesexcl_.end())
265  continue;
266 
267  // new rechit flag checks
268  //std::vector<int>::const_iterator vit = std::find(flags_.begin(),
269  // flags_.end(),
270  // j->recoFlag());
271  //if (vit != flags_.end())
272  // continue;
273  if (!j->checkFlag(EcalRecHit::kGood)) {
274  if (j->checkFlags(flags_)) {
275  continue;
276  }
277  }
278 
279  double et = energy * position.perp() / position.mag();
280  if (et > etLow_ && energy > eLow_) { //Changed energy --> fabs(energy) -- then changed into energy
281  if (returnEt)
282  energySum += et;
283  else
284  energySum += energy;
285  }
286 
287  } //End if not end of list
288  } //End loop over rechits
289  } //End loop over barrel/endcap
290  } //End if caloHits_
291 
292  return energySum;
293 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
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 get() const
get a component
Definition: Candidate.h:221
T eta() const
Definition: PV3DBase.h:73
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:88
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
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:91
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
T const * product() const
Definition: ESHandle.h:86
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
T sqrt(T t)
Definition: SSEVec.h:23
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id.
Definition: CaloGeometry.cc:60
EgammaRecHitIsolation(double extRadius, double intRadius, double etaSlice, double etLow, double eLow, edm::ESHandle< CaloGeometry >, const EcalRecHitCollection &, const EcalSeverityLevelAlgo *, DetId::Detector detector)
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
iterator find(key_type k)
static int position[264][3]
Definition: ReadPGInfo.cc:289
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
const EcalSeverityLevelAlgo * sevLevel_
double energySum(const DataFrame &df, int fs, int ls)
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
double getSum_(const reco::Candidate *, bool returnEt, const EcalPFRecHitThresholds *thresholds) const
const EcalRecHitCollection & caloHits_