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  severityLevelCut_(-1),
54  //severityRecHitThreshold_(0),
55  //spId_(EcalSeverityLevelAlgo::kSwissCross),
56  //spIdThreshold_(0),
57  v_chstatus_(0)
58 {
59  //set up the geometry and selector
60  const CaloGeometry* caloGeom = theCaloGeom_.product();
63 
64 }
65 
67 {
68 }
69 
70 double EgammaRecHitIsolation::getSum_(const reco::Candidate* emObject,bool returnEt) const
71 {
72 
73  double energySum = 0.;
74  if (caloHits_){
75  //Take the SC position
77  math::XYZPoint theCaloPosition = sc.get()->position();
78  GlobalPoint pclu (theCaloPosition.x () ,
79  theCaloPosition.y () ,
80  theCaloPosition.z () );
81  double etaclus = pclu.eta();
82  double phiclus = pclu.phi();
83  double r2 = intRadius_*intRadius_;
84 
85 
86  std::vector< std::pair<DetId, float> >::const_iterator rhIt;
87 
88 
89  for(int subdetnr=0; subdetnr<=1 ; subdetnr++){ // look in barrel and endcap
90  CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);// select cells around cluster
92  for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin ();i!= chosen.end ();++i){//loop selected cells
93 
94  j=caloHits_->find(*i); // find selected cell among rechits
95  if( j!=caloHits_->end()){ // add rechit only if available
96  const GlobalPoint & position = theCaloGeom_.product()->getPosition(*i);
97  double eta = position.eta();
98  double phi = position.phi();
99  double etaDiff = eta - etaclus;
100  double phiDiff= reco::deltaPhi(phi,phiclus);
101  double energy = j->energy();
102 
103  if(useNumCrystals_) {
104  if( fabs(etaclus) < 1.479 ) { // Barrel num crystals, crystal width = 0.0174
105  if ( fabs(etaDiff) < 0.0174*etaSlice_) continue;
106  if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_) continue;
107  } else { // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
108  if ( fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_) continue;
109  if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_) continue;
110  }
111  } else {
112  if ( fabs(etaDiff) < etaSlice_) continue; // jurassic strip cut
113  if ( etaDiff*etaDiff + phiDiff*phiDiff < r2) continue; // jurassic exclusion cone cut
114  }
115 
116  //Check if RecHit is in SC
117  if(vetoClustered_) {
118 
119  //Loop over basic clusters:
120  bool isClustered = false;
121  for(reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
122  for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
123  if( rhIt->first == *i ) isClustered = true;
124  if( isClustered ) break;
125  }
126  if( isClustered ) break;
127  } //end loop over basic clusters
128 
129  if(isClustered) continue;
130  } //end if removeClustered
131 
132  //Severity level check
133  //make sure we have a barrel rechit
134  //call the severity level method
135  //passing the EBDetId
136  //the rechit collection in order to calculate the swiss crss
137  //and the EcalChannelRecHitRcd
138  //only consider rechits with ET >
139  //the SpikeId method (currently kE1OverE9 or kSwissCross)
140  //cut value for above
141  //then if the severity level is too high, we continue to the next rechit
142 
143  if( severityLevelCut_!=-1 && ecalBarHits_ &&
145  continue;
146  // *chStatus_,
147  // severityRecHitThreshold_,
148  // spId_,
149  // spIdThreshold_
150  // ) >= severityLevelCut_) continue;
151 
152 
153 
154 
155  //Check based on flags to protect from recovered channels from non-read towers
156  //Assumption is that v_chstatus_ is empty unless doFlagChecks() has been called
157  std::vector<int>::const_iterator vit = std::find( v_chstatus_.begin(), v_chstatus_.end(), ((EcalRecHit*)(&*j))->recoFlag() );
158  if ( vit != v_chstatus_.end() ) continue; // the recHit has to be excluded from the iso sum
159 
160 
161  double et = energy*position.perp()/position.mag();
162  if ( fabs(et) > etLow_ && fabs(energy) > eLow_){ //Changed energy --> fabs(energy)
163  if(returnEt) energySum+=et;
164  else energySum+=energy;
165  }
166 
167  } //End if not end of list
168  } //End loop over rechits
169  } //End loop over barrel/endcap
170  } //End if caloHits_
171  return energySum;
172 }
173 
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
int i
Definition: DBlmapReader.cc:9
const CaloSubdetectorGeometry * subdet_[2]
edm::ESHandle< CaloGeometry > theCaloGeom_
CaloRecHitMetaCollectionV * caloHits_
T perp() const
Definition: PV3DBase.h:66
const DetId & detid() const
Definition: CaloRecHit.h:21
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
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
EcalSeverityLevel severityLevel(const DetId &id, const EcalRecHitCollection &rhs) const
Evaluate status from id.
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:61
float energy() const
Definition: CaloRecHit.h:19
T sqrt(T t)
Definition: SSEVec.h:28
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:13
std::vector< int > v_chstatus_
Detector
Definition: DetId.h:26
T const * product() const
Definition: ESHandle.h:62
T eta() const
Definition: PV3DBase.h:70
T get() const
get a component
Definition: Candidate.h:217
const EcalSeverityLevelAlgo * sevLevel_
double energySum(const DataFrame &df, int fs, int ls)
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:241
Definition: DDAxes.h:10