CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/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     // Basic clusters of hybrid super-cluster do not have the seed set; take the first DetId instead 
00020     // Should be checked . The single Tower Mode should be favoured until fixed
00021     detid = cluster.hitsAndFractions()[0].first;
00022     if(detid.det() != DetId::Ecal) {
00023       CaloTowerDetId tower;
00024       return tower;
00025     }
00026   }
00027   CaloTowerDetId id(towerMap_->towerOf(detid));
00028   return id;
00029 }
00030 
00031 std::vector<CaloTowerDetId>  EgammaHadTower::towersOf(const reco::SuperCluster& sc) const {
00032   std::vector<CaloTowerDetId> towers;
00033   std::vector<reco::CaloClusterPtr>  orderedClusters;
00034 
00035   // in this mode, check only the tower behind the seed
00036   if ( mode_ == SingleTower ) {
00037     towers.push_back(towerOf(*sc.seed()));
00038   }
00039 
00040   // in this mode check the towers behind each basic cluster
00041   if ( mode_ == TowersBehindCluster ) {
00042     // Loop on the basic clusters
00043     reco::CaloCluster_iterator it = sc.clustersBegin();
00044     reco::CaloCluster_iterator itend = sc.clustersEnd();
00045 
00046     for ( ; it !=itend; ++it) {
00047       orderedClusters.push_back(*it);
00048     }
00049     std::sort(orderedClusters.begin(),orderedClusters.end(),ClusterGreaterThan);
00050     unsigned nclusters=orderedClusters.size();
00051     for ( unsigned iclus =0 ; iclus <nclusters && iclus < NMaxClusters_; ++iclus) {
00052       // Get the tower
00053       CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
00054       std::vector<CaloTowerDetId>::const_iterator itcheck=find(towers.begin(),towers.end(),id);
00055       if( itcheck == towers.end() ) {
00056         towers.push_back(id);
00057       }
00058     }
00059   }
00060 //  if(towers.size() > 4) {
00061 //    std::cout << " NTOWERS " << towers.size() << " ";
00062 //    for(unsigned i=0; i<towers.size() ; ++i) {
00063 //      std::cout << towers[i] << " ";
00064 //    }
00065 //    std::cout <<  std::endl;
00066 //    for ( unsigned iclus=0 ; iclus < orderedClusters.size(); ++iclus) {
00067 //      // Get the tower
00068 //      CaloTowerDetId id = towerOf(*(orderedClusters[iclus]));
00069 //      std::cout << " Pos " << orderedClusters[iclus]->position() << " " << orderedClusters[iclus]->energy() << " " << id ;
00070 //    }
00071 //    std::cout << std::endl;
00072 //  }
00073   return towers;
00074 }
00075 
00076 double EgammaHadTower::getDepth1HcalESum(const std::vector<CaloTowerDetId> & towers) const {
00077   double esum=0.;
00078   CaloTowerCollection::const_iterator trItr = towerCollection_->begin();
00079   CaloTowerCollection::const_iterator trItrEnd = towerCollection_->end();
00080   for( ;  trItr != trItrEnd ; ++trItr){
00081     std::vector<CaloTowerDetId>::const_iterator itcheck = find(towers.begin(), towers.end(), trItr->id());
00082     if( itcheck != towers.end() ) {
00083       esum += trItr->ietaAbs()<18 || trItr->ietaAbs()>29 ? trItr->hadEnergy() : trItr->hadEnergyHeInnerLayer() ;
00084     }
00085   }
00086   return esum;
00087 }
00088 
00089 double EgammaHadTower::getDepth2HcalESum(const std::vector<CaloTowerDetId> & towers) const {
00090   double esum=0.;
00091   CaloTowerCollection::const_iterator trItr = towerCollection_->begin();
00092   CaloTowerCollection::const_iterator trItrEnd = towerCollection_->end();
00093   for( ;  trItr != trItrEnd ; ++trItr){
00094     std::vector<CaloTowerDetId>::const_iterator itcheck = find(towers.begin(), towers.end(), trItr->id());
00095     if( itcheck != towers.end() ) {
00096       esum += trItr->hadEnergyHeOuterLayer();
00097     }
00098   }
00099   return esum;
00100 }
00101 
00102 double EgammaHadTower::getDepth1HcalESum( const reco::SuperCluster& sc ) const {
00103   return getDepth1HcalESum(towersOf(sc)) ;
00104 }
00105 
00106 double EgammaHadTower::getDepth2HcalESum( const reco::SuperCluster& sc ) const {
00107   return getDepth2HcalESum(towersOf(sc)) ;
00108 }
00109 
00110 void EgammaHadTower::setTowerCollection(const CaloTowerCollection* towerCollection) {
00111   towerCollection_ = towerCollection;
00112 }
00113 
00114 bool ClusterGreaterThan(const reco::CaloClusterPtr& c1, const reco::CaloClusterPtr& c2)  {
00115   return (*c1 > *c2);
00116 }