CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoEgamma/EgammaTools/src/HoECalculator.cc

Go to the documentation of this file.
00001 #include "RecoEgamma/EgammaTools/interface/HoECalculator.h"
00002 
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00005 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00006 #include "RecoCaloTools/MetaCollections/interface/CaloRecHitMetaCollection.h"
00007 
00008 HoECalculator::HoECalculator () :
00009                theCaloGeom_(0)
00010 {
00011 } 
00012 HoECalculator::HoECalculator (const edm::ESHandle<CaloGeometry>  &caloGeom) :
00013                theCaloGeom_(caloGeom)
00014 {
00015 } 
00016 
00017 double HoECalculator::operator() ( const reco::BasicCluster* clus , const edm::Event& e , const edm::EventSetup& c) 
00018 {
00019   return getHoE(GlobalPoint(clus->x(),clus->y(),clus->z()), clus->energy(), e,c);
00020 }
00021 
00022 double HoECalculator::operator() ( const reco::SuperCluster* clus , const edm::Event& e , const edm::EventSetup& c) 
00023 {
00024   return getHoE(GlobalPoint(clus->x(),clus->y(),clus->z()), clus->energy(), e,c);
00025 }
00026 
00027 double HoECalculator::operator() ( const reco::SuperCluster* clus, 
00028                                    HBHERecHitMetaCollection *mhbhe, int ialgo) {
00029   double HoE=0.;
00030   switch (ialgo) {
00031     case 1:
00032       for (reco::CaloCluster_iterator bc=clus->clustersBegin(); bc!=clus->clustersEnd(); bc++) {
00033         double HoEi = getHoE(GlobalPoint((*bc)->x(),(*bc)->y(),(*bc)->z()),clus->energy(), mhbhe);
00034         if (HoEi > HoE) HoE = HoEi;
00035       }
00036       break;
00037     case 2:
00038       HoE = getHoE(GlobalPoint(clus->x(),clus->y(),clus->z()), clus->energy(), mhbhe);
00039       break;
00040     default:
00041       std::cout << "!!! algo for HoE should be 1 or 2 " << std::endl;
00042   } 
00043   return HoE;   
00044 }
00045 
00046 
00047 double HoECalculator::operator() ( const reco::BasicCluster* clus, 
00048                              HBHERecHitMetaCollection *mhbhe) {
00049   return getHoE(GlobalPoint(clus->x(),clus->y(),clus->z()), clus->energy(), mhbhe);
00050 }
00051 
00052 double HoECalculator::getHoE(GlobalPoint pclu, float ecalEnergy, const edm::Event& e , const edm::EventSetup& c )
00053 {
00054   if ( !theCaloGeom_.isValid() )
00055     c.get<CaloGeometryRecord>().get(theCaloGeom_) ;
00056 
00057   //product the geometry
00058   theCaloGeom_.product() ;
00059 
00060   //Create a CaloRecHitMetaCollection
00061   edm::Handle< HBHERecHitCollection > hbhe ;
00062   e.getByLabel("hbhereco","",hbhe);
00063   const HBHERecHitCollection* hithbhe_ = hbhe.product();
00064 
00065   double HoE=0.;
00066   const CaloGeometry& geometry = *theCaloGeom_ ;
00067   const CaloSubdetectorGeometry *geometry_p ; 
00068   geometry_p = geometry.getSubdetectorGeometry (DetId::Hcal,4) ;
00069   DetId hcalDetId ;
00070   hcalDetId = geometry_p->getClosestCell(pclu) ;
00071   double hcalEnergy = 0 ;
00072   CaloRecHitMetaCollection f;
00073   f.add(hithbhe_);
00074   CaloRecHitMetaCollection::const_iterator iterRecHit ; 
00075   iterRecHit = f.find(hcalDetId) ;
00076   if (iterRecHit!=f.end()) {
00077     hcalEnergy = iterRecHit->energy() ;
00078     HoE = hcalEnergy/ecalEnergy ;
00079   }
00080 
00081   return HoE ;
00082 }
00083 
00084 double HoECalculator::getHoE(GlobalPoint pos, float energy,
00085                              HBHERecHitMetaCollection *mhbhe) {
00086   
00087   double HoE=0.;
00088   
00089   if (mhbhe) {
00090     const CaloSubdetectorGeometry *geometry_p ; 
00091     geometry_p =  theCaloGeom_->getSubdetectorGeometry (DetId::Hcal,4) ;
00092     HcalDetId dB= geometry_p->getClosestCell(pos);
00093     CaloRecHitMetaCollectionV::const_iterator i=mhbhe->find(dB);
00094     if (i!=mhbhe->end()) {
00095       HoE =  i->energy()/energy;
00096     }
00097   }
00098   return HoE ;
00099 
00100 }