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
00053 severitiesexcl_(0),
00054
00055
00056
00057 flags_(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 double EgammaRecHitIsolation::getSum_(const reco::Candidate* emObject,bool returnEt) const {
00070
00071 double energySum = 0.;
00072 if (caloHits_){
00073
00074 reco::SuperClusterRef sc = emObject->get<reco::SuperClusterRef>();
00075 math::XYZPoint const & theCaloPosition = sc.get()->position();
00076 GlobalPoint pclu (theCaloPosition.x () ,
00077 theCaloPosition.y () ,
00078 theCaloPosition.z () );
00079 float etaclus = pclu.eta();
00080 float phiclus = pclu.phi();
00081 float r2 = intRadius_*intRadius_;
00082
00083 std::vector< std::pair<DetId, float> >::const_iterator rhIt;
00084
00085 for(int subdetnr=0; subdetnr<=1 ; subdetnr++){
00086 CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);
00087 CaloRecHitMetaCollectionV::const_iterator j = caloHits_->end();
00088 for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin ();i != chosen.end (); ++i){
00089 j = caloHits_->find(*i);
00090 if(j != caloHits_->end()) {
00091 auto const cell = theCaloGeom_.product()->getGeometry(*i);
00092 float eta = cell->etaPos();
00093 float phi = cell->phiPos();
00094 float etaDiff = eta - etaclus;
00095 float phiDiff= reco::deltaPhi(phi,phiclus);
00096 float energy = j->energy();
00097
00098 if(useNumCrystals_) {
00099 if(fabs(etaclus) < 1.479) {
00100 if (fabs(etaDiff) < 0.0174*etaSlice_)
00101 continue;
00102
00103
00104 if ((etaDiff*etaDiff + phiDiff*phiDiff) < 0.00030276*r2)
00105 continue;
00106 } else {
00107 if (fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_)
00108 continue;
00109
00110
00111 if ((etaDiff*etaDiff + phiDiff*phiDiff) < (0.000037325*(cosh(2*eta)-1)*r2))
00112 continue;
00113 }
00114 } else {
00115 if (fabs(etaDiff) < etaSlice_)
00116 continue;
00117 if (etaDiff*etaDiff + phiDiff*phiDiff < r2)
00118 continue;
00119 }
00120
00121 if(vetoClustered_) {
00122
00123
00124 bool isClustered = false;
00125 for(reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
00126 for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
00127 if(rhIt->first == *i)
00128 isClustered = true;
00129 if(isClustered)
00130 break;
00131 }
00132
00133 if(isClustered)
00134 break;
00135 }
00136
00137 if(isClustered)
00138 continue;
00139 }
00140
00141
00142
00143
00144
00145 int severityFlag = ecalBarHits_ == 0 ? -1 : sevLevel_->severityLevel(((const EcalRecHit*)(&*j))->detid(), *ecalBarHits_);
00146 std::vector<int>::const_iterator sit = std::find(severitiesexcl_.begin(),
00147 severitiesexcl_.end(),
00148 severityFlag);
00149
00150 if (sit!= severitiesexcl_.end())
00151 continue;
00152
00153
00154
00155
00156
00157
00158
00159 if (!((EcalRecHit*)(&*j))->checkFlag(EcalRecHit::kGood)) {
00160 if (((EcalRecHit*)(&*j))->checkFlags(flags_)) {
00161 continue;
00162 }
00163 }
00164
00165 float et = energy*std::sqrt(cell->getPosition().perp2()/cell->getPosition().mag2());
00166 if ( et > etLow_ && energy > eLow_) {
00167 if(returnEt)
00168 energySum += et;
00169 else
00170 energySum += energy;
00171 }
00172
00173 }
00174 }
00175 }
00176 }
00177
00178 return energySum;
00179 }
00180
00181
00182
00183 double EgammaRecHitIsolation::getSum_(const reco::SuperCluster* sc, bool returnEt) const {
00184
00185 double energySum = 0.;
00186 if (caloHits_){
00187
00188
00189 math::XYZPoint theCaloPosition = sc->position();
00190 GlobalPoint pclu (theCaloPosition.x () ,
00191 theCaloPosition.y () ,
00192 theCaloPosition.z () );
00193 double etaclus = pclu.eta();
00194 double phiclus = pclu.phi();
00195 double r2 = intRadius_*intRadius_;
00196
00197 std::vector< std::pair<DetId, float> >::const_iterator rhIt;
00198
00199
00200 for(int subdetnr=0; subdetnr<=1 ; subdetnr++){
00201 CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);
00202 CaloRecHitMetaCollectionV::const_iterator j=caloHits_->end();
00203 for (CaloSubdetectorGeometry::DetIdSet::const_iterator i = chosen.begin ();i!= chosen.end ();++i){
00204
00205 j=caloHits_->find(*i);
00206 if( j!=caloHits_->end()){
00207 const GlobalPoint & position = theCaloGeom_.product()->getPosition(*i);
00208 double eta = position.eta();
00209 double phi = position.phi();
00210 double etaDiff = eta - etaclus;
00211 double phiDiff= reco::deltaPhi(phi,phiclus);
00212 double energy = j->energy();
00213
00214 if(useNumCrystals_) {
00215 if( fabs(etaclus) < 1.479 ) {
00216 if ( fabs(etaDiff) < 0.0174*etaSlice_) continue;
00217
00218 if ((etaDiff*etaDiff + phiDiff*phiDiff) < 0.00030276*r2) continue;
00219 } else {
00220 if ( fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_) continue;
00221
00222 if ((etaDiff*etaDiff + phiDiff*phiDiff) < (0.000037325*(cosh(2*eta)-1)*r2)) continue;
00223 }
00224 } else {
00225 if ( fabs(etaDiff) < etaSlice_) continue;
00226 if ( etaDiff*etaDiff + phiDiff*phiDiff < r2) continue;
00227 }
00228
00229
00230 if(vetoClustered_) {
00231
00232
00233 bool isClustered = false;
00234 for(reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
00235 for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
00236 if( rhIt->first == *i ) isClustered = true;
00237 if( isClustered ) break;
00238 }
00239 if( isClustered ) break;
00240 }
00241
00242 if(isClustered) continue;
00243 }
00244
00245
00246 int severityFlag = sevLevel_->severityLevel(j->detid(), *ecalBarHits_);
00247 std::vector<int>::const_iterator sit = std::find(severitiesexcl_.begin(),
00248 severitiesexcl_.end(),
00249 severityFlag);
00250
00251 if (sit!= severitiesexcl_.end())
00252 continue;
00253
00254
00255
00256
00257
00258
00259
00260 if (!((EcalRecHit*)(&*j))->checkFlag(EcalRecHit::kGood)) {
00261 if (((EcalRecHit*)(&*j))->checkFlags(flags_)) {
00262 continue;
00263 }
00264 }
00265
00266
00267 double et = energy*position.perp()/position.mag();
00268 if ( et > etLow_ && energy > eLow_){
00269 if(returnEt) energySum+=et;
00270 else energySum+=energy;
00271 }
00272
00273 }
00274 }
00275 }
00276 }
00277
00278 return energySum;
00279 }
00280