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  CaloRecHitMetaCollectionV* 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_){
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  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin ();i != chosen.end (); ++i){ //loop selected cells
89  j = caloHits_->find(*i); // find selected cell among rechits
90  if(j != caloHits_->end()) { // add rechit only if available
91  auto const cell = theCaloGeom_.product()->getGeometry(*i);
92  float eta = cell->etaPos();
93  float phi = cell->phiPos();
94  float etaDiff = eta - etaclus;
95  float phiDiff= reco::deltaPhi(phi,phiclus);
96  float energy = j->energy();
97 
98  if(useNumCrystals_) {
99  if(fabs(etaclus) < 1.479) { // Barrel num crystals, crystal width = 0.0174
100  if (fabs(etaDiff) < 0.0174*etaSlice_)
101  continue;
102  //if (sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_)
103  //continue;
104  if ((etaDiff*etaDiff + phiDiff*phiDiff) < 0.00030276*r2)
105  continue;
106  } else { // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
107  if (fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_)
108  continue;
109  //if (sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_)
110  // continue;
111  if ((etaDiff*etaDiff + phiDiff*phiDiff) < (0.000037325*(cosh(2*eta)-1)*r2))
112  continue;
113  }
114  } else {
115  if (fabs(etaDiff) < etaSlice_)
116  continue; // jurassic strip cut
117  if (etaDiff*etaDiff + phiDiff*phiDiff < r2)
118  continue; // jurassic exclusion cone cut
119  }
120  //Check if RecHit is in SC
121  if(vetoClustered_) {
122 
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 
142 
143 
144  //std::cout << "detid " << ((EcalRecHit*)(&*j))->detid() << std::endl;
145  int severityFlag = ecalBarHits_ == 0 ? -1 : sevLevel_->severityLevel(((const EcalRecHit*)(&*j))->detid(), *ecalBarHits_);
146  std::vector<int>::const_iterator sit = std::find(severitiesexcl_.begin(),
147  severitiesexcl_.end(),
148  severityFlag);
149 
150  if (sit!= severitiesexcl_.end())
151  continue;
152 
153  // new rechit flag checks
154  //std::vector<int>::const_iterator vit = std::find(flags_.begin(),
155  // flags_.end(),
156  // ((const EcalRecHit*)(&*j))->recoFlag());
157  //if (vit != flags_.end())
158  // continue;
159  if (!((EcalRecHit*)(&*j))->checkFlag(EcalRecHit::kGood)) {
160  if (((EcalRecHit*)(&*j))->checkFlags(flags_)) {
161  continue;
162  }
163  }
164 
165  float et = energy*std::sqrt(cell->getPosition().perp2()/cell->getPosition().mag2());
166  if ( et > etLow_ && energy > eLow_) { //Changed energy --> fabs(energy) - now changed back to energy
167  if(returnEt)
168  energySum += et;
169  else
170  energySum += energy;
171  }
172 
173  } //End if not end of list
174  } //End loop over rechits
175  } //End loop over barrel/endcap
176  } //End if caloHits_
177 
178  return energySum;
179 }
180 
181 
182 
183 double EgammaRecHitIsolation::getSum_(const reco::SuperCluster* sc, bool returnEt) const {
184 
185  double energySum = 0.;
186  if (caloHits_){
187  //Take the SC position
188 
189  math::XYZPoint theCaloPosition = sc->position();
190  GlobalPoint pclu (theCaloPosition.x () ,
191  theCaloPosition.y () ,
192  theCaloPosition.z () );
193  double etaclus = pclu.eta();
194  double phiclus = pclu.phi();
195  double r2 = intRadius_*intRadius_;
196 
197  std::vector< std::pair<DetId, float> >::const_iterator rhIt;
198 
199 
200  for(int subdetnr=0; subdetnr<=1 ; subdetnr++){ // look in barrel and endcap
201  CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);// select cells around cluster
203  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin ();i!= chosen.end ();++i){//loop selected cells
204 
205  j=caloHits_->find(*i); // find selected cell among rechits
206  if( j!=caloHits_->end()){ // add rechit only if available
207  const GlobalPoint & position = theCaloGeom_.product()->getPosition(*i);
208  double eta = position.eta();
209  double phi = position.phi();
210  double etaDiff = eta - etaclus;
211  double phiDiff= reco::deltaPhi(phi,phiclus);
212  double energy = j->energy();
213 
214  if(useNumCrystals_) {
215  if( fabs(etaclus) < 1.479 ) { // Barrel num crystals, crystal width = 0.0174
216  if ( fabs(etaDiff) < 0.0174*etaSlice_) continue;
217  // if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_) continue;
218  if ((etaDiff*etaDiff + phiDiff*phiDiff) < 0.00030276*r2) continue;
219  } else { // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
220  if ( fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_) continue;
221  // if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_) continue;
222  if ((etaDiff*etaDiff + phiDiff*phiDiff) < (0.000037325*(cosh(2*eta)-1)*r2)) continue;
223  }
224  } else {
225  if ( fabs(etaDiff) < etaSlice_) continue; // jurassic strip cut
226  if ( etaDiff*etaDiff + phiDiff*phiDiff < r2) continue; // jurassic exclusion cone cut
227  }
228 
229  //Check if RecHit is in SC
230  if(vetoClustered_) {
231 
232  //Loop over basic clusters:
233  bool isClustered = false;
234  for(reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
235  for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
236  if( rhIt->first == *i ) isClustered = true;
237  if( isClustered ) break;
238  }
239  if( isClustered ) break;
240  } //end loop over basic clusters
241 
242  if(isClustered) continue;
243  } //end if removeClustered
244 
245 
246  int severityFlag = sevLevel_->severityLevel(j->detid(), *ecalBarHits_);
247  std::vector<int>::const_iterator sit = std::find(severitiesexcl_.begin(),
248  severitiesexcl_.end(),
249  severityFlag);
250 
251  if (sit!= severitiesexcl_.end())
252  continue;
253 
254  // new rechit flag checks
255  //std::vector<int>::const_iterator vit = std::find(flags_.begin(),
256  // flags_.end(),
257  // ((EcalRecHit*)(&*j))->recoFlag());
258  //if (vit != flags_.end())
259  // continue;
260  if (!((EcalRecHit*)(&*j))->checkFlag(EcalRecHit::kGood)) {
261  if (((EcalRecHit*)(&*j))->checkFlags(flags_)) {
262  continue;
263  }
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) energySum+=et;
270  else energySum+=energy;
271  }
272 
273  } //End if not end of list
274  } //End loop over rechits
275  } //End loop over barrel/endcap
276  } //End if caloHits_
277 
278  return energySum;
279 }
280 
virtual const_iterator find(const DetId &id) const
find by id (default version is very slow unsorted find)
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:124
int i
Definition: DBlmapReader.cc:9
const CaloSubdetectorGeometry * subdet_[2]
edm::ESHandle< CaloGeometry > theCaloGeom_
std::vector< int > flags_
CaloRecHitMetaCollectionV * caloHits_
T perp() const
Definition: PV3DBase.h:72
const DetId & detid() const
Definition: CaloRecHit.h:20
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< int > severitiesexcl_
T eta() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
double getSum_(const reco::Candidate *, bool returnEt) const
const_iterator end() const
get the ending iterator
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
float energy() const
Definition: CaloRecHit.h:17
T sqrt(T t)
Definition: SSEVec.h:48
int j
Definition: DBlmapReader.cc:9
EgammaRecHitIsolation(double extRadius, double intRadius, double etaSlice, double etLow, double eLow, edm::ESHandle< CaloGeometry >, CaloRecHitMetaCollectionV *, const EcalSeverityLevelAlgo *, DetId::Detector detector)
const EcalRecHitCollection * ecalBarHits_
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:12
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:62
T eta() const
Definition: PV3DBase.h:76
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:75
T get() const
get a component
Definition: Candidate.h:219
const EcalSeverityLevelAlgo * sevLevel_
volatile std::atomic< bool > shutdown_flag false
double energySum(const DataFrame &df, int fs, int ls)
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id, const EcalRecHitCollection &rhs) const
Evaluate status from id.
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:78
Definition: DDAxes.h:10