test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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): // not used anymore, kept for compatibility
41  extRadius_(extRadius),
42  intRadius_(intRadius),
43  etaSlice_(etaSlice),
44  etLow_(etLow),
45  eLow_(eLow),
46  theCaloGeom_(theCaloGeom) ,
47  caloHits_(caloHits),
48  sevLevel_(sl),
49  useNumCrystals_(false),
50  vetoClustered_(false),
51  ecalBarHits_(0),
52  //chStatus_(0),
53  severitiesexcl_(0),
54  //severityRecHitThreshold_(0),
55  //spId_(EcalSeverityLevelAlgo::kSwissCross),
56  //spIdThreshold_(0),
57  flags_(0)
58 {
59  //set up the geometry and selector
60  const CaloGeometry* caloGeom = theCaloGeom_.product();
63 
64 }
65 
67 {}
68 
69 double EgammaRecHitIsolation::getSum_(const reco::Candidate* emObject,bool returnEt) const {
70 
71  double energySum = 0.;
72  if (! caloHits_.empty()) {
73  //Take the SC position
75  math::XYZPoint const & theCaloPosition = sc.get()->position();
76  GlobalPoint pclu (theCaloPosition.x () ,
77  theCaloPosition.y () ,
78  theCaloPosition.z () );
79  float etaclus = pclu.eta();
80  float phiclus = pclu.phi();
81  float r2 = intRadius_*intRadius_;
82 
83  std::vector< std::pair<DetId, float> >::const_iterator rhIt;
84 
85  for(int subdetnr=0; subdetnr<=1 ; subdetnr++){ // look in barrel and endcap
86  CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);// select cells around cluster
88 
89  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin ();i != chosen.end (); ++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 const cell = theCaloGeom_.product()->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 
124  //Loop over basic clusters:
125  bool isClustered = false;
126  for(reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
127  for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
128  if(rhIt->first == *i)
129  isClustered = true;
130  if(isClustered)
131  break;
132  }
133 
134  if(isClustered)
135  break;
136  } //end loop over basic clusters
137 
138  if(isClustered)
139  continue;
140  } //end if removeClustered
141 
142 
143 
144 
145  //std::cout << "detid " << ((EcalRecHit*)(&*j))->detid() << std::endl;
146  int severityFlag = ecalBarHits_ == 0 ? -1 : sevLevel_->severityLevel(((const EcalRecHit*)(&*j))->detid(), *ecalBarHits_);
147  std::vector<int>::const_iterator sit = std::find(severitiesexcl_.begin(),
148  severitiesexcl_.end(),
149  severityFlag);
150 
151  if (sit!= severitiesexcl_.end())
152  continue;
153 
154  // new rechit flag checks
155  //std::vector<int>::const_iterator vit = std::find(flags_.begin(),
156  // flags_.end(),
157  // ((const EcalRecHit*)(&*j))->recoFlag());
158  //if (vit != flags_.end())
159  // continue;
160  if (!((EcalRecHit*)(&*j))->checkFlag(EcalRecHit::kGood)) {
161  if (((EcalRecHit*)(&*j))->checkFlags(flags_)) {
162  continue;
163  }
164  }
165 
166  float et = energy*std::sqrt(cell->getPosition().perp2()/cell->getPosition().mag2());
167  if ( et > etLow_ && energy > eLow_) { //Changed energy --> fabs(energy) - now changed back to energy
168  if(returnEt)
169  energySum += et;
170  else
171  energySum += energy;
172  }
173 
174  } //End if not end of list
175  } //End loop over rechits
176  } //End loop over barrel/endcap
177  } //End if caloHits_
178 
179  return energySum;
180 }
181 
182 
183 
184 double EgammaRecHitIsolation::getSum_(const reco::SuperCluster* sc, bool returnEt) const {
185 
186  double energySum = 0.;
187  if (! caloHits_.empty()){
188  //Take the SC position
189 
190  math::XYZPoint theCaloPosition = sc->position();
191  GlobalPoint pclu (theCaloPosition.x () ,
192  theCaloPosition.y () ,
193  theCaloPosition.z () );
194  double etaclus = pclu.eta();
195  double phiclus = pclu.phi();
196  double r2 = intRadius_*intRadius_;
197 
198  std::vector< std::pair<DetId, float> >::const_iterator rhIt;
199 
200 
201  for(int subdetnr=0; subdetnr<=1 ; subdetnr++){ // look in barrel and endcap
202  CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);// select cells around cluster
204  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin ();i!= chosen.end ();++i){//loop selected cells
205 
206  j=caloHits_.find(*i); // find selected cell among rechits
207  if( j!=caloHits_.end()){ // add rechit only if available
208  const GlobalPoint & position = theCaloGeom_.product()->getPosition(*i);
209  double eta = position.eta();
210  double phi = position.phi();
211  double etaDiff = eta - etaclus;
212  double phiDiff= reco::deltaPhi(phi,phiclus);
213  double energy = j->energy();
214 
215  if(useNumCrystals_) {
216  if( fabs(etaclus) < 1.479 ) { // Barrel num crystals, crystal width = 0.0174
217  if ( fabs(etaDiff) < 0.0174*etaSlice_) continue;
218  // if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_) continue;
219  if ((etaDiff*etaDiff + phiDiff*phiDiff) < 0.00030276*r2) continue;
220  } else { // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
221  if ( fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_) continue;
222  // if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_) continue;
223  if ((etaDiff*etaDiff + phiDiff*phiDiff) < (0.000037325*(cosh(2*eta)-1)*r2)) continue;
224  }
225  } else {
226  if ( fabs(etaDiff) < etaSlice_) continue; // jurassic strip cut
227  if ( etaDiff*etaDiff + phiDiff*phiDiff < r2) continue; // jurassic exclusion cone cut
228  }
229 
230  //Check if RecHit is in SC
231  if(vetoClustered_) {
232 
233  //Loop over basic clusters:
234  bool isClustered = false;
235  for(reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
236  for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
237  if( rhIt->first == *i ) isClustered = true;
238  if( isClustered ) break;
239  }
240  if( isClustered ) break;
241  } //end loop over basic clusters
242 
243  if(isClustered) continue;
244  } //end if removeClustered
245 
246 
247  int severityFlag = sevLevel_->severityLevel(j->detid(), *ecalBarHits_);
248  std::vector<int>::const_iterator sit = std::find(severitiesexcl_.begin(),
249  severitiesexcl_.end(),
250  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  // ((EcalRecHit*)(&*j))->recoFlag());
259  //if (vit != flags_.end())
260  // continue;
261  if (!((EcalRecHit*)(&*j))->checkFlag(EcalRecHit::kGood)) {
262  if (((EcalRecHit*)(&*j))->checkFlags(flags_)) {
263  continue;
264  }
265  }
266 
267 
268  double et = energy*position.perp()/position.mag();
269  if ( et > etLow_ && energy > eLow_){ //Changed energy --> fabs(energy) -- then changed into energy
270  if(returnEt) energySum+=et;
271  else energySum+=energy;
272  }
273 
274  } //End if not end of list
275  } //End loop over rechits
276  } //End loop over barrel/endcap
277  } //End if caloHits_
278 
279  return energySum;
280 }
281 
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:43
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:126
int i
Definition: DBlmapReader.cc:9
const CaloSubdetectorGeometry * subdet_[2]
edm::ESHandle< CaloGeometry > theCaloGeom_
std::vector< int > flags_
T perp() const
Definition: PV3DBase.h:72
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
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:7
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:67
T sqrt(T t)
Definition: SSEVec.h:18
int j
Definition: DBlmapReader.cc:9
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:244
const EcalRecHitCollection * ecalBarHits_
const_iterator end() const
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
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:76
iterator find(key_type k)
static int position[264][3]
Definition: ReadPGInfo.cc:509
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:75
T get() const
get a component
Definition: Candidate.h:217
const EcalSeverityLevelAlgo * sevLevel_
volatile std::atomic< bool > shutdown_flag false
double energySum(const DataFrame &df, int fs, int ls)
const EcalRecHitCollection & caloHits_
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:78