CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/RecoEgamma/EgammaElectronAlgos/src/ElectronHcalHelper.cc

Go to the documentation of this file.
00001 
00002 #include "RecoEgamma/EgammaElectronAlgos/interface/ElectronHcalHelper.h"
00003 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHcalIsolation.h"
00004 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
00005 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00008 
00009 using namespace reco ;
00010 
00011 ElectronHcalHelper::ElectronHcalHelper( const Configuration & cfg  )
00012  : cfg_(cfg), caloGeomCacheId_(0), hbhe_(0), mhbhe_(0), hcalIso_(0), towersH_(0), towerIso1_(0), towerIso2_(0)
00013  {}
00014 
00015 void ElectronHcalHelper::checkSetup( const edm::EventSetup & es )
00016  {
00017   if (cfg_.hOverEConeSize==0)
00018    { return ; }
00019 
00020   if (!cfg_.useTowers)
00021    {
00022     unsigned long long newCaloGeomCacheId_
00023      = es.get<CaloGeometryRecord>().cacheIdentifier() ;
00024     if (caloGeomCacheId_!=newCaloGeomCacheId_)
00025      {
00026       caloGeomCacheId_ = newCaloGeomCacheId_ ;
00027       es.get<CaloGeometryRecord>().get(caloGeom_) ;
00028      }
00029    }
00030  }
00031 
00032 void ElectronHcalHelper::readEvent( edm::Event & evt )
00033  {
00034   if (cfg_.hOverEConeSize==0)
00035    { return ; }
00036 
00037   if (cfg_.useTowers)
00038    {
00039     delete towerIso1_ ; towerIso1_ = 0 ;
00040     delete towerIso2_ ; towerIso2_ = 0 ;
00041     delete towersH_ ; towersH_ = 0 ;
00042 
00043     towersH_ = new edm::Handle<CaloTowerCollection>() ;
00044     if (!evt.getByLabel(cfg_.hcalTowers,*towersH_))
00045      { edm::LogError("ElectronHcalHelper::readEvent")<<"failed to get the hcal towers of label "<<cfg_.hcalTowers ; }
00046     towerIso1_ = new EgammaTowerIsolation(cfg_.hOverEConeSize,0.,cfg_.hOverEPtMin,1,towersH_->product()) ;
00047     towerIso2_ = new EgammaTowerIsolation(cfg_.hOverEConeSize,0.,cfg_.hOverEPtMin,2,towersH_->product()) ;
00048    }
00049   else
00050    {
00051     delete hcalIso_ ; hcalIso_ = 0 ;
00052     delete mhbhe_ ; mhbhe_ = 0 ;
00053     delete hbhe_ ; hbhe_ = 0 ;
00054 
00055     hbhe_=  new edm::Handle<HBHERecHitCollection>() ;
00056     if (!evt.getByLabel(cfg_.hcalRecHits,*hbhe_))
00057      { edm::LogError("ElectronHcalHelper::readEvent")<<"failed to get the rechits of label "<<cfg_.hcalRecHits ; }
00058     mhbhe_=  new HBHERecHitMetaCollection(**hbhe_) ;
00059     hcalIso_ = new EgammaHcalIsolation(cfg_.hOverEConeSize,0.,cfg_.hOverEHBMinE,cfg_.hOverEHFMinE,0.,0.,caloGeom_,mhbhe_) ;
00060    }
00061  }
00062 
00063 double ElectronHcalHelper::hcalESum( const SuperCluster & sc )
00064  {
00065   if (cfg_.hOverEConeSize==0)
00066    { return 0 ; }
00067   if (cfg_.useTowers)
00068    { return(hcalESumDepth1(sc)+hcalESumDepth2(sc)) ; }
00069   else
00070    { return hcalIso_->getHcalESum(&sc) ; }
00071  }
00072 
00073 double ElectronHcalHelper::hcalESumDepth1( const SuperCluster & sc )
00074  {
00075   if (cfg_.hOverEConeSize==0)
00076    { return 0 ; }
00077   if (cfg_.useTowers)
00078    { return towerIso1_->getTowerESum(&sc) ; }
00079   else
00080    { return hcalIso_->getHcalESumDepth1(&sc) ; }
00081  }
00082 
00083 double ElectronHcalHelper::hcalESumDepth2( const SuperCluster & sc )
00084  {
00085   if (cfg_.hOverEConeSize==0)
00086    { return 0 ; }
00087   if (cfg_.useTowers)
00088    { return towerIso2_->getTowerESum(&sc) ; }
00089   else
00090    { return hcalIso_->getHcalESumDepth2(&sc) ; }
00091  }
00092 
00093 ElectronHcalHelper::~ElectronHcalHelper()
00094  {
00095   if (cfg_.hOverEConeSize==0)
00096    { return ; }
00097   if (cfg_.useTowers)
00098    {
00099     delete towerIso1_ ;
00100     delete towerIso2_ ;
00101     delete towersH_ ;
00102    }
00103   else
00104    {
00105     delete hcalIso_ ;
00106     delete mhbhe_ ;
00107     delete hbhe_ ;
00108    }
00109  }
00110 
00111