CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEgamma/EgammaIsolationAlgos/src/EgammaRecHitIsolation.cc

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File:      EgammaRecHitIsolation.cc
00003 // ----------------------------------------------------------------------------
00004 // OrigAuth:  Matthias Mozer, hacked by Sam Harper (ie the ugly stuff is mine)
00005 // Institute: IIHE-VUB, RAL
00006 //=============================================================================
00007 //*****************************************************************************
00008 //C++ includes
00009 #include <vector>
00010 #include <functional>
00011 
00012 //ROOT includes
00013 #include <Math/VectorUtil.h>
00014 
00015 //CMSSW includes
00016 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaRecHitIsolation.h"
00017 #include "DataFormats/DetId/interface/DetId.h"
00018 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00019 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00020 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00021 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00022 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00023 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
00024 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
00025 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00026 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00027 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00028 #include "DataFormats/Math/interface/deltaPhi.h"
00029 
00030 using namespace std;
00031 
00032 EgammaRecHitIsolation::EgammaRecHitIsolation (double extRadius,
00033                                               double intRadius,
00034                                               double etaSlice,
00035                                               double etLow,
00036                                               double eLow,
00037                                               edm::ESHandle<CaloGeometry> theCaloGeom,
00038                                               CaloRecHitMetaCollectionV* caloHits,
00039                                               const EcalSeverityLevelAlgo* sl,
00040                                               DetId::Detector detector):  // not used anymore, kept for compatibility
00041     extRadius_(extRadius),
00042     intRadius_(intRadius),
00043     etaSlice_(etaSlice),
00044     etLow_(etLow),
00045     eLow_(eLow),
00046     theCaloGeom_(theCaloGeom) ,  
00047     caloHits_(caloHits),
00048     sevLevel_(sl),
00049     useNumCrystals_(false),
00050     vetoClustered_(false),
00051     ecalBarHits_(0),
00052     chStatus_(0),
00053     severityLevelCut_(-1),
00054     //severityRecHitThreshold_(0),
00055     //spId_(EcalSeverityLevelAlgo::kSwissCross),
00056     //spIdThreshold_(0),
00057     v_chstatus_(0)
00058 {
00059     //set up the geometry and selector
00060     const CaloGeometry* caloGeom = theCaloGeom_.product();
00061     subdet_[0] = caloGeom->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
00062     subdet_[1] = caloGeom->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
00063 
00064 }
00065 
00066 EgammaRecHitIsolation::~EgammaRecHitIsolation ()
00067 {
00068 }
00069 
00070 double EgammaRecHitIsolation::getSum_(const reco::Candidate* emObject,bool returnEt) const
00071 {
00072 
00073     double energySum = 0.;
00074     if (caloHits_){
00075         //Take the SC position
00076         reco::SuperClusterRef sc = emObject->get<reco::SuperClusterRef>();
00077         math::XYZPoint theCaloPosition = sc.get()->position();
00078         GlobalPoint pclu (theCaloPosition.x () ,
00079                 theCaloPosition.y () ,
00080                 theCaloPosition.z () );
00081         double etaclus = pclu.eta();
00082         double phiclus = pclu.phi();
00083         double r2 = intRadius_*intRadius_;
00084 
00085         
00086         std::vector< std::pair<DetId, float> >::const_iterator rhIt;
00087 
00088 
00089         for(int subdetnr=0; subdetnr<=1 ; subdetnr++){  // look in barrel and endcap
00090             CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);// select cells around cluster
00091             CaloRecHitMetaCollectionV::const_iterator j=caloHits_->end();
00092             for (CaloSubdetectorGeometry::DetIdSet::const_iterator  i = chosen.begin ();i!= chosen.end ();++i){//loop selected cells
00093 
00094                 j=caloHits_->find(*i); // find selected cell among rechits
00095                 if( j!=caloHits_->end()){ // add rechit only if available 
00096                     const  GlobalPoint & position = theCaloGeom_.product()->getPosition(*i);
00097                     double eta = position.eta();
00098                     double phi = position.phi();
00099                     double etaDiff = eta - etaclus;
00100                     double phiDiff= reco::deltaPhi(phi,phiclus);
00101                     double energy = j->energy();
00102 
00103                     if(useNumCrystals_) {
00104                         if( fabs(etaclus) < 1.479 ) {  // Barrel num crystals, crystal width = 0.0174
00105                             if ( fabs(etaDiff) < 0.0174*etaSlice_) continue;  
00106                             if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_) continue; 
00107                         } else {                       // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
00108                             if ( fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_) continue;  
00109                             if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_) continue; 
00110                         }
00111                     } else {
00112                         if ( fabs(etaDiff) < etaSlice_) continue;  // jurassic strip cut
00113                         if ( etaDiff*etaDiff + phiDiff*phiDiff < r2) continue; // jurassic exclusion cone cut
00114                     }
00115 
00116                     //Check if RecHit is in SC
00117                     if(vetoClustered_) {
00118 
00119                         //Loop over basic clusters:
00120                         bool isClustered = false;
00121                         for(reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
00122                             for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
00123                                 if( rhIt->first == *i ) isClustered = true;
00124                                 if( isClustered ) break;
00125                             }
00126                             if( isClustered ) break;
00127                         } //end loop over basic clusters
00128 
00129                         if(isClustered) continue;
00130                     }  //end if removeClustered
00131 
00132                     //Severity level check
00133                     //make sure we have a barrel rechit                                     
00134                     //call the severity level method                                        
00135                     //passing the EBDetId                                                   
00136                     //the rechit collection in order to calculate the swiss crss            
00137                     //and the EcalChannelRecHitRcd                                          
00138                     //only consider rechits with ET >                                       
00139                     //the SpikeId method (currently kE1OverE9 or kSwissCross)               
00140                     //cut value for above                                                   
00141                     //then if the severity level is too high, we continue to the next rechit
00142 
00143                     if( severityLevelCut_!=-1 && ecalBarHits_ && 
00144                         sevLevel_->severityLevel(EBDetId(j->detid()), *ecalBarHits_) >= severityLevelCut_) 
00145                       continue;                    
00146                     //                            *chStatus_,                           
00147                     //        severityRecHitThreshold_,             
00148                     //        spId_,                                
00149                     //        spIdThreshold_                        
00150                     //    ) >= severityLevelCut_) continue;         
00151 
00152 
00153 
00154 
00155                     //Check based on flags to protect from recovered channels from non-read towers
00156                     //Assumption is that v_chstatus_ is empty unless doFlagChecks() has been called
00157                     std::vector<int>::const_iterator vit = std::find( v_chstatus_.begin(), v_chstatus_.end(),  ((EcalRecHit*)(&*j))->recoFlag() );
00158                     if ( vit != v_chstatus_.end() ) continue; // the recHit has to be excluded from the iso sum
00159 
00160 
00161                     double et = energy*position.perp()/position.mag();
00162                     if ( fabs(et) > etLow_ && fabs(energy) > eLow_){ //Changed energy --> fabs(energy)
00163                         if(returnEt) energySum+=et;
00164                         else energySum+=energy;
00165                     }
00166 
00167                 }                //End if not end of list
00168             }                    //End loop over rechits
00169         }                        //End loop over barrel/endcap
00170     }                            //End if caloHits_
00171     return energySum;
00172 }
00173