Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <vector>
00010 #include <functional>
00011
00012
00013 #include <Math/VectorUtil.h>
00014
00015
00016 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaRecHitIsolation.h"
00017 #include "DataFormats/DetId/interface/DetId.h"
00018 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00019 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00020 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00021 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00022 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00023 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
00024 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
00025 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00026 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00027 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00028 #include "DataFormats/Math/interface/deltaPhi.h"
00029
00030 using namespace std;
00031
00032 EgammaRecHitIsolation::EgammaRecHitIsolation (double extRadius,
00033 double intRadius,
00034 double etaSlice,
00035 double etLow,
00036 double eLow,
00037 edm::ESHandle<CaloGeometry> theCaloGeom,
00038 CaloRecHitMetaCollectionV* caloHits,
00039 const EcalSeverityLevelAlgo* sl,
00040 DetId::Detector detector):
00041 extRadius_(extRadius),
00042 intRadius_(intRadius),
00043 etaSlice_(etaSlice),
00044 etLow_(etLow),
00045 eLow_(eLow),
00046 theCaloGeom_(theCaloGeom) ,
00047 caloHits_(caloHits),
00048 sevLevel_(sl),
00049 useNumCrystals_(false),
00050 vetoClustered_(false),
00051 ecalBarHits_(0),
00052 chStatus_(0),
00053 severityLevelCut_(-1),
00054
00055
00056
00057 v_chstatus_(0)
00058 {
00059
00060 const CaloGeometry* caloGeom = theCaloGeom_.product();
00061 subdet_[0] = caloGeom->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
00062 subdet_[1] = caloGeom->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
00063
00064 }
00065
00066 EgammaRecHitIsolation::~EgammaRecHitIsolation ()
00067 {
00068 }
00069
00070 double EgammaRecHitIsolation::getSum_(const reco::Candidate* emObject,bool returnEt) const
00071 {
00072
00073 double energySum = 0.;
00074 if (caloHits_){
00075
00076 reco::SuperClusterRef sc = emObject->get<reco::SuperClusterRef>();
00077 math::XYZPoint theCaloPosition = sc.get()->position();
00078 GlobalPoint pclu (theCaloPosition.x () ,
00079 theCaloPosition.y () ,
00080 theCaloPosition.z () );
00081 double etaclus = pclu.eta();
00082 double phiclus = pclu.phi();
00083 double r2 = intRadius_*intRadius_;
00084
00085
00086
00087 std::vector< std::pair<DetId, float> >::const_iterator rhIt;
00088
00089
00090 for(int subdetnr=0; subdetnr<=1 ; subdetnr++){
00091 CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);
00092 CaloRecHitMetaCollectionV::const_iterator j=caloHits_->end();
00093 for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin ();i!= chosen.end ();++i){
00094
00095 j=caloHits_->find(*i);
00096 if( j!=caloHits_->end()){
00097 const GlobalPoint & position = theCaloGeom_.product()->getPosition(*i);
00098 double eta = position.eta();
00099 double phi = position.phi();
00100 double etaDiff = eta - etaclus;
00101 double phiDiff= reco::deltaPhi(phi,phiclus);
00102 double energy = j->energy();
00103
00104 if(useNumCrystals_) {
00105 if( fabs(etaclus) < 1.479 ) {
00106 if ( fabs(etaDiff) < 0.0174*etaSlice_) continue;
00107 if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_) continue;
00108 } else {
00109 if ( fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_) continue;
00110 if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_) continue;
00111 }
00112 } else {
00113 if ( fabs(etaDiff) < etaSlice_) continue;
00114 if ( etaDiff*etaDiff + phiDiff*phiDiff < r2) continue;
00115 }
00116
00117
00118 if(vetoClustered_) {
00119
00120
00121 bool isClustered = false;
00122 for(reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
00123 for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
00124 if( rhIt->first == *i ) isClustered = true;
00125 if( isClustered ) break;
00126 }
00127 if( isClustered ) break;
00128 }
00129
00130 if(isClustered) continue;
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 if( severityLevelCut_!=-1 && ecalBarHits_ &&
00145 sevLevel_->severityLevel(EBDetId(j->detid()), *ecalBarHits_) >= severityLevelCut_)
00146 continue;
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 std::vector<int>::const_iterator vit = std::find( v_chstatus_.begin(), v_chstatus_.end(), ((EcalRecHit*)(&*j))->recoFlag() );
00159 if ( vit != v_chstatus_.end() ) continue;
00160
00161
00162 double et = energy*position.perp()/position.mag();
00163 if ( fabs(et) > etLow_ && fabs(energy) > eLow_){
00164 if(returnEt) energySum+=et;
00165 else energySum+=energy;
00166 }
00167
00168 }
00169 }
00170 }
00171 }
00172 return energySum;
00173 }
00174
00175
00176
00177 double EgammaRecHitIsolation::getSum_(const reco::SuperCluster* sc,bool returnEt) const
00178 {
00179
00180 double energySum = 0.;
00181 if (caloHits_){
00182
00183
00184 math::XYZPoint theCaloPosition = sc->position();
00185 GlobalPoint pclu (theCaloPosition.x () ,
00186 theCaloPosition.y () ,
00187 theCaloPosition.z () );
00188 double etaclus = pclu.eta();
00189 double phiclus = pclu.phi();
00190 double r2 = intRadius_*intRadius_;
00191
00192 std::vector< std::pair<DetId, float> >::const_iterator rhIt;
00193
00194
00195 for(int subdetnr=0; subdetnr<=1 ; subdetnr++){
00196 CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);
00197 CaloRecHitMetaCollectionV::const_iterator j=caloHits_->end();
00198 for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin ();i!= chosen.end ();++i){
00199
00200 j=caloHits_->find(*i);
00201 if( j!=caloHits_->end()){
00202 const GlobalPoint & position = theCaloGeom_.product()->getPosition(*i);
00203 double eta = position.eta();
00204 double phi = position.phi();
00205 double etaDiff = eta - etaclus;
00206 double phiDiff= reco::deltaPhi(phi,phiclus);
00207 double energy = j->energy();
00208
00209 if(useNumCrystals_) {
00210 if( fabs(etaclus) < 1.479 ) {
00211 if ( fabs(etaDiff) < 0.0174*etaSlice_) continue;
00212 if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_) continue;
00213 } else {
00214 if ( fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_) continue;
00215 if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_) continue;
00216 }
00217 } else {
00218 if ( fabs(etaDiff) < etaSlice_) continue;
00219 if ( etaDiff*etaDiff + phiDiff*phiDiff < r2) continue;
00220 }
00221
00222
00223 if(vetoClustered_) {
00224
00225
00226 bool isClustered = false;
00227 for(reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
00228 for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
00229 if( rhIt->first == *i ) isClustered = true;
00230 if( isClustered ) break;
00231 }
00232 if( isClustered ) break;
00233 }
00234
00235 if(isClustered) continue;
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 if( severityLevelCut_!=-1 && ecalBarHits_ &&
00250 sevLevel_->severityLevel(EBDetId(j->detid()), *ecalBarHits_) >= severityLevelCut_)
00251 continue;
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 std::vector<int>::const_iterator vit = std::find( v_chstatus_.begin(), v_chstatus_.end(), ((EcalRecHit*)(&*j))->recoFlag() );
00264 if ( vit != v_chstatus_.end() ) continue;
00265
00266
00267 double et = energy*position.perp()/position.mag();
00268 if ( fabs(et) > etLow_ && fabs(energy) > eLow_){
00269 if(returnEt) energySum+=et;
00270 else energySum+=energy;
00271 }
00272
00273 }
00274 }
00275 }
00276 }
00277 return energySum;
00278 }
00279