CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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 "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHadTower.h"
00006 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.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),hadTower_(0)
00013  {}
00014 
00015 void ElectronHcalHelper::checkSetup( const edm::EventSetup & es )
00016  {
00017 
00018   if (cfg_.hOverEConeSize==0)
00019    { return ; }
00020 
00021   if (cfg_.useTowers)
00022    {
00023     delete hadTower_ ;
00024     hadTower_ = new EgammaHadTower(es) ;
00025    }
00026   else
00027    {
00028     unsigned long long newCaloGeomCacheId_
00029      = es.get<CaloGeometryRecord>().cacheIdentifier() ;
00030     if (caloGeomCacheId_!=newCaloGeomCacheId_)
00031      {
00032       caloGeomCacheId_ = newCaloGeomCacheId_ ;
00033       es.get<CaloGeometryRecord>().get(caloGeom_) ;
00034      }
00035    }
00036  }
00037 
00038 void ElectronHcalHelper::readEvent( edm::Event & evt )
00039  {
00040   if (cfg_.hOverEConeSize==0)
00041    { return ; }
00042 
00043   if (cfg_.useTowers)
00044    {
00045     delete towerIso1_ ; towerIso1_ = 0 ;
00046     delete towerIso2_ ; towerIso2_ = 0 ;
00047     delete towersH_ ; towersH_ = 0 ;
00048 
00049     towersH_ = new edm::Handle<CaloTowerCollection>() ;
00050     if (!evt.getByLabel(cfg_.hcalTowers,*towersH_))
00051      { edm::LogError("ElectronHcalHelper::readEvent")<<"failed to get the hcal towers of label "<<cfg_.hcalTowers ; }
00052     hadTower_->setTowerCollection(towersH_->product());
00053     towerIso1_ = new EgammaTowerIsolation(cfg_.hOverEConeSize,0.,cfg_.hOverEPtMin,1,towersH_->product()) ;
00054     towerIso2_ = new EgammaTowerIsolation(cfg_.hOverEConeSize,0.,cfg_.hOverEPtMin,2,towersH_->product()) ;
00055    }
00056   else
00057    {
00058     delete hcalIso_ ; hcalIso_ = 0 ;
00059     delete mhbhe_ ; mhbhe_ = 0 ;
00060     delete hbhe_ ; hbhe_ = 0 ;
00061 
00062     hbhe_=  new edm::Handle<HBHERecHitCollection>() ;
00063     if (!evt.getByLabel(cfg_.hcalRecHits,*hbhe_))
00064      { edm::LogError("ElectronHcalHelper::readEvent")<<"failed to get the rechits of label "<<cfg_.hcalRecHits ; }
00065     mhbhe_=  new HBHERecHitMetaCollection(**hbhe_) ;
00066     hcalIso_ = new EgammaHcalIsolation(cfg_.hOverEConeSize,0.,cfg_.hOverEHBMinE,cfg_.hOverEHFMinE,0.,0.,caloGeom_,mhbhe_) ;
00067    }
00068  }
00069 
00070 std::vector<CaloTowerDetId> ElectronHcalHelper::hcalTowersBehindClusters( const reco::SuperCluster & sc )
00071  { return hadTower_->towersOf(sc) ; }
00072 
00073 double ElectronHcalHelper::hcalESumDepth1BehindClusters( const std::vector<CaloTowerDetId> & towers )
00074  { return hadTower_->getDepth1HcalESum(towers) ; }
00075 
00076 double ElectronHcalHelper::hcalESumDepth2BehindClusters( const std::vector<CaloTowerDetId> & towers )
00077  { return hadTower_->getDepth2HcalESum(towers) ; }
00078 
00079 double ElectronHcalHelper::hcalESum( const SuperCluster & sc, const std::vector<CaloTowerDetId > * excludeTowers )
00080  {
00081   if (cfg_.hOverEConeSize==0)
00082    { return 0 ; }
00083   if (cfg_.useTowers)
00084     { return(hcalESumDepth1(sc,excludeTowers)+hcalESumDepth2(sc,excludeTowers)) ; }
00085   else
00086    { return hcalIso_->getHcalESum(&sc) ; }
00087  }
00088 
00089 double ElectronHcalHelper::hcalESumDepth1( const SuperCluster & sc ,const std::vector<CaloTowerDetId > * excludeTowers )
00090  {
00091   if (cfg_.hOverEConeSize==0)
00092    { return 0 ; }
00093   if (cfg_.useTowers)
00094     { return towerIso1_->getTowerESum(&sc, excludeTowers) ; }
00095   else
00096    { return hcalIso_->getHcalESumDepth1(&sc) ; }
00097  }
00098 
00099 double ElectronHcalHelper::hcalESumDepth2( const SuperCluster & sc ,const std::vector<CaloTowerDetId > * excludeTowers  )
00100  {
00101   if (cfg_.hOverEConeSize==0)
00102    { return 0 ; }
00103   if (cfg_.useTowers)
00104     { return towerIso2_->getTowerESum(&sc, excludeTowers) ; }
00105   else
00106    { return hcalIso_->getHcalESumDepth2(&sc) ; }
00107  }
00108 
00109 ElectronHcalHelper::~ElectronHcalHelper()
00110  {
00111   if (cfg_.hOverEConeSize==0)
00112    { return ; }
00113   if (cfg_.useTowers)
00114    {
00115     delete towerIso1_ ;
00116     delete towerIso2_ ;
00117     delete towersH_ ;
00118     delete hadTower_;
00119    }
00120   else
00121    {
00122     delete hcalIso_ ;
00123     delete mhbhe_ ;
00124     delete hbhe_ ;
00125    }
00126  }
00127 
00128