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