CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/RecoEgamma/EgammaIsolationAlgos/src/EgammaHadTower.cc

Go to the documentation of this file.
00001 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHadTower.h"
00002 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00005 
00006 #include <algorithm>
00007 #include <iostream>
00008 
00009 EgammaHadTower::EgammaHadTower(const edm::EventSetup &es,HoeMode mode):mode_(mode) {
00010   edm::ESHandle<CaloTowerConstituentsMap> ctmaph;
00011   es.get<IdealGeometryRecord>().get(ctmaph);
00012   towerMap_ = &(*ctmaph);
00013   NMaxClusters_ = 4;
00014 }
00015 
00016 CaloTowerDetId  EgammaHadTower::towerOf(const reco::CaloCluster& cluster) const {
00017   DetId detid = cluster.seed();
00018   if(detid.det() != DetId::Ecal) {
00019     CaloTowerDetId tower;
00020     return tower;
00021   }
00022   CaloTowerDetId id(towerMap_->towerOf(detid));
00023   return id;
00024 }
00025 
00026 std::vector<CaloTowerDetId>  EgammaHadTower::towersOf(const reco::SuperCluster& sc) const {
00027   std::vector<CaloTowerDetId> towers;
00028   std::vector<reco::CaloClusterPtr>  orderedClusters;
00029 
00030   // in this mode, check only the tower behind the seed
00031   if ( mode_ == SingleTower ) {
00032     towers.push_back(towerOf(sc));
00033   }
00034 
00035   // in this mode check the towers behind each basic cluster
00036   if ( mode_ == TowersBehindCluster ) {
00037     // Loop on the basic clusters
00038     reco::CaloCluster_iterator it = sc.clustersBegin();
00039     reco::CaloCluster_iterator itend = sc.clustersEnd();
00040 
00041     for ( ; it !=itend; ++it) {
00042       orderedClusters.push_back(*it);
00043     }
00044     std::sort(orderedClusters.begin(),orderedClusters.end(),ClusterGreaterThan);
00045     unsigned nclusters=orderedClusters.size();
00046     for ( unsigned iclus =0 ; iclus <nclusters && iclus < NMaxClusters_; ++iclus) {
00047       // Get the tower
00048       CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
00049       std::vector<CaloTowerDetId>::const_iterator itcheck=find(towers.begin(),towers.end(),id);
00050       if( itcheck == towers.end() ) {
00051         towers.push_back(id);
00052       }
00053     }
00054   }
00055 //  if(towers.size() > 4) {
00056 //    std::cout << " NTOWERS " << towers.size() << " ";
00057 //    for(unsigned i=0; i<towers.size() ; ++i) {
00058 //      std::cout << towers[i] << " ";
00059 //    }
00060 //    std::cout <<  std::endl;
00061 //    for ( unsigned iclus=0 ; iclus < orderedClusters.size(); ++iclus) {
00062 //      // Get the tower
00063 //      CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
00064 //      std::cout << " Pos " << orderedClusters[iclus]->position() << " " << orderedClusters[iclus]->energy() << " " << id ;
00065 //    }
00066 //    std::cout << std::endl;
00067 //  }
00068   return towers;
00069 }
00070 
00071 double EgammaHadTower::getDepth1HcalESum(const std::vector<CaloTowerDetId> & towers) const {
00072   double esum=0.;
00073   CaloTowerCollection::const_iterator trItr = towerCollection_->begin();
00074   CaloTowerCollection::const_iterator trItrEnd = towerCollection_->end();
00075   for( ;  trItr != trItrEnd ; ++trItr){
00076     std::vector<CaloTowerDetId>::const_iterator itcheck = find(towers.begin(), towers.end(), trItr->id());
00077     if( itcheck != towers.end() ) {
00078       esum += trItr->ietaAbs()<18 || trItr->ietaAbs()>29 ? trItr->hadEnergy() : trItr->hadEnergyHeInnerLayer() ;
00079     }
00080   }
00081   return esum;
00082 }
00083 
00084 double EgammaHadTower::getDepth2HcalESum(const std::vector<CaloTowerDetId> & towers) const {
00085   double esum=0.;
00086   CaloTowerCollection::const_iterator trItr = towerCollection_->begin();
00087   CaloTowerCollection::const_iterator trItrEnd = towerCollection_->end();
00088   for( ;  trItr != trItrEnd ; ++trItr){
00089     std::vector<CaloTowerDetId>::const_iterator itcheck = find(towers.begin(), towers.end(), trItr->id());
00090     if( itcheck != towers.end() ) {
00091       esum += trItr->hadEnergyHeOuterLayer();
00092     }
00093   }
00094   return esum;
00095 }
00096 
00097 double EgammaHadTower::getDepth1HcalESum( const reco::SuperCluster& sc ) const {
00098   return getDepth1HcalESum(towersOf(sc)) ;
00099 }
00100 
00101 double EgammaHadTower::getDepth2HcalESum( const reco::SuperCluster& sc ) const {
00102   return getDepth2HcalESum(towersOf(sc)) ;
00103 }
00104 
00105 void EgammaHadTower::setTowerCollection(const CaloTowerCollection* towerCollection) {
00106   towerCollection_ = towerCollection;
00107 }
00108 
00109 bool ClusterGreaterThan(const reco::CaloClusterPtr& c1, const reco::CaloClusterPtr& c2)  {
00110   return (*c1 > *c2);
00111 }