CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/RecoEgamma/EgammaIsolationAlgos/src/EgammaTowerIsolation.cc

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File:      EgammaTowerIsolation.cc
00003 // ----------------------------------------------------------------------------
00004 // OrigAuth:  Matthias Mozer
00005 // Institute: IIHE-VUB
00006 //=============================================================================
00007 //*****************************************************************************
00008 //C++ includes
00009 #include <vector>
00010 #include <functional>
00011 #include <math.h>
00012 
00013 //ROOT includes
00014 #include <Math/VectorUtil.h>
00015 
00016 
00017 //CMSSW includes
00018 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
00019 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00020 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00021 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00022 #include "DataFormats/CaloTowers/interface/CaloTower.h"
00023 #include "FWCore/Utilities/interface/Exception.h"
00024 
00025 using namespace ROOT::Math::VectorUtil ;
00026 
00027 EgammaTowerIsolation::EgammaTowerIsolation (double extRadius,
00028                                       double intRadius,
00029                                       double etLow,
00030                                       signed int depth,
00031                                       const CaloTowerCollection* towercollection)   :
00032   extRadius_(extRadius),
00033   intRadius_(intRadius),
00034   etLow_(etLow),
00035   depth_(depth),
00036   towercollection_(towercollection)
00037 {
00038 }
00039 
00040 EgammaTowerIsolation::~EgammaTowerIsolation ()
00041 {
00042 }
00043 
00044 
00045 
00046 
00047 double EgammaTowerIsolation::getTowerEtSum(const reco::Candidate* photon, const std::vector<CaloTowerDetId> * detIdToExclude ) const
00048 {
00049   return getTowerEtSum( photon->get<reco::SuperClusterRef>().get(), detIdToExclude );
00050 }
00051 
00052 double EgammaTowerIsolation::getTowerEtSum(const reco::SuperCluster* sc, const std::vector<CaloTowerDetId> * detIdToExclude ) const
00053 {
00054   double candEta=sc->eta();
00055   double candPhi=sc->phi();
00056   double ptSum =0.;
00057 
00058   //loop over towers
00059   for(CaloTowerCollection::const_iterator trItr = towercollection_->begin(); trItr != towercollection_->end(); ++trItr){
00060 
00061     // skip the towers to exclude
00062     if ( detIdToExclude )
00063      {
00064       std::vector<CaloTowerDetId>::const_iterator itcheck=find(detIdToExclude->begin(),detIdToExclude->end(),trItr->id());
00065       if (itcheck != detIdToExclude->end())
00066               continue;
00067      }
00068 
00069     double this_pt=0;
00070     switch(depth_){
00071     case AllDepths: this_pt = trItr->hadEt();break;
00072     case Depth1: this_pt = trItr->ietaAbs()<18 || trItr->ietaAbs()>29 ? trItr->hadEt() : trItr->hadEnergyHeInnerLayer()*sin(trItr->p4().theta());break;
00073     case Depth2: this_pt = trItr->hadEnergyHeOuterLayer()*sin(trItr->p4().theta());break;
00074     default: throw cms::Exception("Configuration Error") << "EgammaTowerIsolation: Depth " << depth_ << " not known. "; break;
00075     }
00076 
00077     if ( this_pt < etLow_ )
00078       continue ;
00079 
00080     double towerEta=trItr->eta();
00081     double towerPhi=trItr->phi();
00082     double twoPi= 2*M_PI;
00083     if(towerPhi<0) towerPhi+=twoPi;
00084     if(candPhi<0) candPhi+=twoPi;
00085     double deltaPhi=fabs(towerPhi-candPhi);
00086     if(deltaPhi>twoPi) deltaPhi-=twoPi;
00087     if(deltaPhi>M_PI) deltaPhi=twoPi-deltaPhi;
00088     double deltaEta = towerEta - candEta;
00089 
00090     double dr = deltaEta*deltaEta + deltaPhi*deltaPhi;
00091     if( dr < extRadius_*extRadius_ &&
00092         dr >= intRadius_*intRadius_ )
00093      { ptSum += this_pt ; }
00094 
00095    }//end loop over tracks
00096 
00097   return ptSum ;
00098 
00099  }
00100 
00101 
00102 double EgammaTowerIsolation::getTowerESum(const reco::Candidate* photon, const std::vector<CaloTowerDetId> * detIdToExclude ) const
00103 {
00104   return getTowerESum( photon->get<reco::SuperClusterRef>().get(), detIdToExclude );
00105 }
00106 
00107 double EgammaTowerIsolation::getTowerESum(const reco::SuperCluster* sc, const std::vector<CaloTowerDetId> * detIdToExclude ) const
00108 {
00109   double candEta=sc->eta();
00110   double candPhi=sc->phi();
00111   double eSum =0.;
00112 
00113   //loop over towers
00114   for(CaloTowerCollection::const_iterator trItr = towercollection_->begin(); trItr != towercollection_->end(); ++trItr){
00115 
00116     // skip the towers to exclude
00117     if( detIdToExclude ) {
00118       std::vector<CaloTowerDetId>::const_iterator itcheck=find(detIdToExclude->begin(),detIdToExclude->end(),trItr->id());
00119       if (itcheck != detIdToExclude->end())
00120         continue;
00121     }
00122 
00123     double this_e=0;
00124     switch(depth_){
00125     case AllDepths: this_e = trItr->hadEnergy();break;
00126     case Depth1: this_e = trItr->ietaAbs()<18 || trItr->ietaAbs()>29 ? trItr->hadEnergy() : trItr->hadEnergyHeInnerLayer();break;
00127     case Depth2: this_e = trItr->hadEnergyHeOuterLayer();break;
00128     default: throw cms::Exception("Configuration Error") << "EgammaTowerIsolation: Depth " << depth_ << " not known. "; break;
00129     }
00130 
00131     if ( this_e*sin(trItr->p4().theta()) < etLow_ )
00132       continue ;
00133 
00134     double towerEta=trItr->eta();
00135     double towerPhi=trItr->phi();
00136     double twoPi= 2*M_PI;
00137     if(towerPhi<0) towerPhi+=twoPi;
00138     if(candPhi<0) candPhi+=twoPi;
00139     double deltaPhi=fabs(towerPhi-candPhi);
00140     if(deltaPhi>twoPi) deltaPhi-=twoPi;
00141     if(deltaPhi>M_PI) deltaPhi=twoPi-deltaPhi;
00142     double deltaEta = towerEta - candEta;
00143 
00144 
00145     double dr = deltaEta*deltaEta + deltaPhi*deltaPhi;
00146     if( dr < extRadius_*extRadius_ &&
00147         dr >= intRadius_*intRadius_ )
00148       {
00149         eSum += this_e;
00150       }
00151 
00152   }//end loop over tracks
00153 
00154   return eSum;
00155 }
00156