CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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  
00048 {
00049   return getTowerEtSum( photon->get<reco::SuperClusterRef>().get() );
00050 }
00051 
00052 double EgammaTowerIsolation::getTowerEtSum(const reco::SuperCluster* sc) const  
00053 {
00054   math::XYZPoint theCaloPosition = sc->position();
00055   double candEta=sc->eta();
00056   double candPhi=sc->phi();
00057   double ptSum =0.;
00058 
00059   //loop over tracks
00060   for(CaloTowerCollection::const_iterator trItr = towercollection_->begin(); trItr != towercollection_->end(); ++trItr){
00061     
00062     double this_pt=0;
00063     switch(depth_){
00064     case AllDepths: this_pt = trItr->hadEt();break;
00065     case Depth1: this_pt = trItr->ietaAbs()<18 || trItr->ietaAbs()>29 ? trItr->hadEt() : trItr->hadEnergyHeInnerLayer()*sin(trItr->p4().theta());break;
00066     case Depth2: this_pt = trItr->hadEnergyHeOuterLayer()*sin(trItr->p4().theta());break;
00067     default: throw cms::Exception("Configuration Error") << "EgammaTowerIsolation: Depth " << depth_ << " not known. "; break;
00068     }
00069 
00070     if ( this_pt < etLow_ ) 
00071       continue ;  
00072     
00073     double towerEta=trItr->eta();
00074     double towerPhi=trItr->phi();
00075     double twoPi= 2*M_PI;
00076     if(towerPhi<0) towerPhi+=twoPi;
00077     if(candPhi<0) candPhi+=twoPi;
00078     double deltaPhi=fabs(towerPhi-candPhi);
00079     if(deltaPhi>twoPi) deltaPhi-=twoPi;
00080     if(deltaPhi>M_PI) deltaPhi=twoPi-deltaPhi;
00081     double deltaEta = towerEta - candEta;
00082 
00083       
00084     double dr = deltaEta*deltaEta + deltaPhi*deltaPhi;
00085     if( dr < extRadius_*extRadius_ &&
00086         dr >= intRadius_*intRadius_ )
00087       {
00088         ptSum += this_pt;
00089       }
00090     
00091   }//end loop over tracks
00092 
00093   return ptSum;
00094 }
00095 
00096 
00097 double EgammaTowerIsolation::getTowerESum(const reco::Candidate* photon) const  
00098 {
00099   return getTowerESum( photon->get<reco::SuperClusterRef>().get() );
00100 }
00101 
00102 double EgammaTowerIsolation::getTowerESum(const reco::SuperCluster* sc) const  
00103 {
00104   math::XYZPoint theCaloPosition = sc->position();
00105   double candEta=sc->eta();
00106   double candPhi=sc->phi();
00107   double eSum =0.;
00108 
00109   //loop over tracks
00110   for(CaloTowerCollection::const_iterator trItr = towercollection_->begin(); trItr != towercollection_->end(); ++trItr){
00111     
00112     double this_e=0;
00113     switch(depth_){
00114     case AllDepths: this_e = trItr->hadEnergy();break;
00115     case Depth1: this_e = trItr->ietaAbs()<18 || trItr->ietaAbs()>29 ? trItr->hadEnergy() : trItr->hadEnergyHeInnerLayer();break;
00116     case Depth2: this_e = trItr->hadEnergyHeOuterLayer();break;
00117     default: throw cms::Exception("Configuration Error") << "EgammaTowerIsolation: Depth " << depth_ << " not known. "; break;
00118     }
00119 
00120     if ( this_e*sin(trItr->p4().theta()) < etLow_ ) 
00121       continue ;  
00122     
00123     double towerEta=trItr->eta();
00124     double towerPhi=trItr->phi();
00125     double twoPi= 2*M_PI;
00126     if(towerPhi<0) towerPhi+=twoPi;
00127     if(candPhi<0) candPhi+=twoPi;
00128     double deltaPhi=fabs(towerPhi-candPhi);
00129     if(deltaPhi>twoPi) deltaPhi-=twoPi;
00130     if(deltaPhi>M_PI) deltaPhi=twoPi-deltaPhi;
00131     double deltaEta = towerEta - candEta;
00132 
00133       
00134     double dr = deltaEta*deltaEta + deltaPhi*deltaPhi;
00135     if( dr < extRadius_*extRadius_ &&
00136         dr >= intRadius_*intRadius_ )
00137       {
00138         eSum += this_e;
00139       }
00140     
00141   }//end loop over tracks
00142 
00143   return eSum;
00144 }
00145