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 
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 }
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EcalSeverityLevelAlgo
Definition: EcalSeverityLevelAlgo.h:33
EgammaRecHitIsolation::theCaloGeom_
edm::ESHandle< CaloGeometry > theCaloGeom_
Definition: EgammaRecHitIsolation.h:73
mps_fire.i
i
Definition: mps_fire.py:428
EgammaRecHitIsolation::vetoClustered_
bool vetoClustered_
Definition: EgammaRecHitIsolation.h:78
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
EgammaRecHitIsolation::caloHits_
const EcalRecHitCollection & caloHits_
Definition: EgammaRecHitIsolation.h:74
funct::false
false
Definition: Factorize.h:29
EcalSeverityLevelAlgo::severityLevel
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
Definition: EcalSeverityLevelAlgo.cc:85
CaloSubdetectorGeometry::DetIdSet
std::set< DetId > DetIdSet
Definition: CaloSubdetectorGeometry.h:27
EgammaRecHitIsolation::eLow_
double eLow_
Definition: EgammaRecHitIsolation.h:71
reco::SuperCluster
Definition: SuperCluster.h:18
EgammaRecHitIsolation::severitiesexcl_
std::vector< int > severitiesexcl_
Definition: EgammaRecHitIsolation.h:80
EgammaRecHitIsolation::intRadius_
double intRadius_
Definition: EgammaRecHitIsolation.h:68
EgammaRecHitIsolation::extRadius_
double extRadius_
Definition: EgammaRecHitIsolation.h:67
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
deltaPhi.h
BasicCluster.h
EgammaRecHitIsolation::etLow_
double etLow_
Definition: EgammaRecHitIsolation.h:70
electronEcalRecHitIsolationLcone_cfi.extRadius
extRadius
Definition: electronEcalRecHitIsolationLcone_cfi.py:16
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
edm::PtrVectorItr
Definition: PtrVector.h:51
EgammaRecHitIsolation::useNumCrystals_
bool useNumCrystals_
Definition: EgammaRecHitIsolation.h:77
edm::SortedCollection< EcalRecHit >
reco::Candidate::get
T get() const
get a component
Definition: Candidate.h:221
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
RecoCandidate.h
EcalBarrel
Definition: EcalSubdetector.h:10
BasicClusterFwd.h
EgammaRecHitIsolation::sevLevel_
const EcalSeverityLevelAlgo * sevLevel_
Definition: EgammaRecHitIsolation.h:75
edm::Ref< SuperClusterCollection >
CastorDataFrameFilter_impl::energySum
double energySum(const DataFrame &df, int fs, int ls)
Definition: CastorDataFrameFilter.cc:22
CaloGeometry
Definition: CaloGeometry.h:21
EgammaRecHitIsolation::etaSlice_
double etaSlice_
Definition: EgammaRecHitIsolation.h:69
CaloSubdetectorGeometry::getCells
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
Definition: CaloSubdetectorGeometry.cc:66
PVValHelper::eta
Definition: PVValidationHelpers.h:70
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
edm::ESHandle< CaloGeometry >
CaloClusterFwd.h
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
EcalRecHit::kGood
Definition: EcalRecHit.h:21
Point3DBase< float, GlobalTag >
EgammaRecHitIsolation::flags_
std::vector< int > flags_
Definition: EgammaRecHitIsolation.h:81
EcalSubdetector.h
EcalEndcap
Definition: EcalSubdetector.h:10
EgammaRecHitIsolation::ecalBarHits_
const EcalRecHitCollection * ecalBarHits_
Definition: EgammaRecHitIsolation.h:79
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
CaloGeometry::getGeometry
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id.
Definition: CaloGeometry.cc:60
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
reco::SuperCluster::clustersBegin
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:86
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
DetId::Detector
Detector
Definition: DetId.h:24
DetId::Ecal
Definition: DetId.h:27
reco::CaloCluster::position
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
reco::Candidate
Definition: Candidate.h:27
DDAxes::phi
edm::SortedCollection::find
iterator find(key_type k)
Definition: SortedCollection.h:240
std
Definition: JetResolutionObject.h:76
SuperClusterFwd.h
DetId.h
electronHcalTowerIsolationLcone_cfi.intRadius
intRadius
Definition: electronHcalTowerIsolationLcone_cfi.py:5
EgammaRecHitIsolation.h
SuperCluster.h
GlobalVector.h
EgammaRecHitIsolation::subdet_
const CaloSubdetectorGeometry * subdet_[2]
Definition: EgammaRecHitIsolation.h:83
EgammaRecHitIsolation::getSum_
double getSum_(const reco::Candidate *, bool returnEt) const
Definition: EgammaRecHitIsolation.cc:67
hgcalTestNeighbor_cfi.detector
detector
Definition: hgcalTestNeighbor_cfi.py:6
EgammaRecHitIsolation::EgammaRecHitIsolation
EgammaRecHitIsolation(double extRadius, double intRadius, double etaSlice, double etLow, double eLow, edm::ESHandle< CaloGeometry >, const EcalRecHitCollection &, const EcalSeverityLevelAlgo *, DetId::Detector detector)
Definition: EgammaRecHitIsolation.cc:32
reco::SuperCluster::clustersEnd
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:89
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
GlobalPoint.h
EgammaRecHitIsolation::~EgammaRecHitIsolation
~EgammaRecHitIsolation()
Definition: EgammaRecHitIsolation.cc:65
CaloCluster.h
edm::SortedCollection::empty
bool empty() const
Definition: SortedCollection.h:210