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