CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/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     severitiesexcl_(0),
00054     //severityRecHitThreshold_(0),
00055     //spId_(EcalSeverityLevelAlgo::kSwissCross),
00056     //spIdThreshold_(0),
00057     flags_(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 double EgammaRecHitIsolation::getSum_(const reco::Candidate* emObject,bool returnEt) const {
00070   
00071   double energySum = 0.;
00072   if (caloHits_){
00073     //Take the SC position
00074     reco::SuperClusterRef sc = emObject->get<reco::SuperClusterRef>();
00075     math::XYZPoint theCaloPosition = sc.get()->position();
00076     GlobalPoint pclu (theCaloPosition.x () ,
00077                       theCaloPosition.y () ,
00078                       theCaloPosition.z () );
00079     double etaclus = pclu.eta();
00080     double phiclus = pclu.phi();
00081     double r2 = intRadius_*intRadius_;
00082     
00083     std::vector< std::pair<DetId, float> >::const_iterator rhIt;
00084     
00085     for(int subdetnr=0; subdetnr<=1 ; subdetnr++){  // look in barrel and endcap
00086       CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);// select cells around cluster
00087       CaloRecHitMetaCollectionV::const_iterator j = caloHits_->end();
00088       for (CaloSubdetectorGeometry::DetIdSet::const_iterator  i = chosen.begin ();i != chosen.end (); ++i){ //loop selected cells
00089         j = caloHits_->find(*i); // find selected cell among rechits
00090         if(j != caloHits_->end()) { // add rechit only if available 
00091           const  GlobalPoint & position = theCaloGeom_.product()->getPosition(*i);
00092           double eta = position.eta();
00093           double phi = position.phi();
00094           double etaDiff = eta - etaclus;
00095           double phiDiff= reco::deltaPhi(phi,phiclus);
00096           double energy = j->energy();
00097 
00098           if(useNumCrystals_) {
00099             if(fabs(etaclus) < 1.479) {  // Barrel num crystals, crystal width = 0.0174
00100               if (fabs(etaDiff) < 0.0174*etaSlice_) 
00101                 continue;  
00102               if (sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_) 
00103                 continue; 
00104             } else {                       // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
00105               if (fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_) 
00106                 continue;  
00107               if (sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_) 
00108                 continue; 
00109             }
00110           } else {
00111             if (fabs(etaDiff) < etaSlice_) 
00112               continue;  // jurassic strip cut
00113             if (etaDiff*etaDiff + phiDiff*phiDiff < r2) 
00114               continue; // jurassic exclusion cone cut
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)
00124                   isClustered = true;
00125                 if(isClustered) 
00126                   break;
00127               }
00128               
00129               if(isClustered) 
00130                 break;
00131             } //end loop over basic clusters
00132             
00133             if(isClustered) 
00134               continue;
00135           }  //end if removeClustered
00136           
00137           
00138           
00139           
00140           //std::cout << "detid " << ((EcalRecHit*)(&*j))->detid() << std::endl;
00141           int severityFlag = ecalBarHits_ == 0 ? -1 : sevLevel_->severityLevel(((EcalRecHit*)(&*j))->detid(), *ecalBarHits_);
00142           std::vector<int>::const_iterator sit = std::find(severitiesexcl_.begin(), 
00143                                                            severitiesexcl_.end(), 
00144                                                            severityFlag);
00145 
00146           if (sit!= severitiesexcl_.end())
00147             continue;
00148           
00149           std::vector<int>::const_iterator vit = std::find(flags_.begin(), 
00150                                                            flags_.end(),
00151                                                            ((EcalRecHit*)(&*j))->recoFlag());
00152           if (vit != flags_.end()) 
00153             continue;
00154           
00155           
00156           
00157           
00158           
00159           
00160           
00161           
00162           
00163           double et = energy*position.perp()/position.mag();
00164           if ( et > etLow_ && energy > eLow_) { //Changed energy --> fabs(energy) - now changed back to energy
00165             if(returnEt) 
00166               energySum += et;
00167             else 
00168               energySum += energy;
00169           }
00170           
00171         }                //End if not end of list
00172       }                  //End loop over rechits
00173     }                    //End loop over barrel/endcap
00174   }                        //End if caloHits_
00175   
00176   return energySum;
00177 }
00178 
00179 
00180 
00181 double EgammaRecHitIsolation::getSum_(const reco::SuperCluster* sc, bool returnEt) const {
00182 
00183   double energySum = 0.;
00184   if (caloHits_){
00185     //Take the SC position
00186  
00187     math::XYZPoint theCaloPosition = sc->position();
00188     GlobalPoint pclu (theCaloPosition.x () ,
00189                       theCaloPosition.y () ,
00190                       theCaloPosition.z () );
00191     double etaclus = pclu.eta();
00192     double phiclus = pclu.phi();
00193     double r2 = intRadius_*intRadius_;
00194     
00195     std::vector< std::pair<DetId, float> >::const_iterator rhIt;
00196     
00197     
00198     for(int subdetnr=0; subdetnr<=1 ; subdetnr++){  // look in barrel and endcap
00199       CaloSubdetectorGeometry::DetIdSet chosen = subdet_[subdetnr]->getCells(pclu,extRadius_);// select cells around cluster
00200       CaloRecHitMetaCollectionV::const_iterator j=caloHits_->end();
00201       for (CaloSubdetectorGeometry::DetIdSet::const_iterator  i = chosen.begin ();i!= chosen.end ();++i){//loop selected cells
00202         
00203         j=caloHits_->find(*i); // find selected cell among rechits
00204         if( j!=caloHits_->end()){ // add rechit only if available 
00205           const  GlobalPoint & position = theCaloGeom_.product()->getPosition(*i);
00206           double eta = position.eta();
00207           double phi = position.phi();
00208           double etaDiff = eta - etaclus;
00209           double phiDiff= reco::deltaPhi(phi,phiclus);
00210           double energy = j->energy();
00211           
00212           if(useNumCrystals_) {
00213             if( fabs(etaclus) < 1.479 ) {  // Barrel num crystals, crystal width = 0.0174
00214               if ( fabs(etaDiff) < 0.0174*etaSlice_) continue;  
00215               if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.0174*intRadius_) continue; 
00216             } else {                       // Endcap num crystals, crystal width = 0.00864*fabs(sinh(eta))
00217               if ( fabs(etaDiff) < 0.00864*fabs(sinh(eta))*etaSlice_) continue;  
00218               if ( sqrt(etaDiff*etaDiff + phiDiff*phiDiff) < 0.00864*fabs(sinh(eta))*intRadius_) continue; 
00219             }
00220           } else {
00221             if ( fabs(etaDiff) < etaSlice_) continue;  // jurassic strip cut
00222             if ( etaDiff*etaDiff + phiDiff*phiDiff < r2) continue; // jurassic exclusion cone cut
00223           }
00224           
00225           //Check if RecHit is in SC
00226           if(vetoClustered_) {
00227             
00228             //Loop over basic clusters:
00229             bool isClustered = false;
00230             for(reco::CaloCluster_iterator bcIt = sc->clustersBegin();bcIt != sc->clustersEnd(); ++bcIt) {
00231               for(rhIt = (*bcIt)->hitsAndFractions().begin();rhIt != (*bcIt)->hitsAndFractions().end(); ++rhIt) {
00232                 if( rhIt->first == *i ) isClustered = true;
00233                 if( isClustered ) break;
00234               }
00235               if( isClustered ) break;
00236             } //end loop over basic clusters
00237             
00238             if(isClustered) continue;
00239           }  //end if removeClustered
00240           
00241           
00242           int severityFlag = sevLevel_->severityLevel(((EcalRecHit*)(&*j))->detid(), *ecalBarHits_);
00243           std::vector<int>::const_iterator sit = std::find(severitiesexcl_.begin(), 
00244                                                            severitiesexcl_.end(), 
00245                                                            severityFlag);
00246           
00247           if (sit!= severitiesexcl_.end())
00248             continue;
00249           
00250           
00251           
00252           //if( severitiesexcl_!=-1 && ecalBarHits_ && 
00253           //    sevLevel_->severityLevel(EBDetId(j->detid()), *ecalBarHits_) >= severitiesexcl_) 
00254           //  continue;                    
00255           
00256           std::vector<int>::const_iterator vit = std::find(flags_.begin(), 
00257                                                            flags_.end(),
00258                                                            ((EcalRecHit*)(&*j))->recoFlag());
00259           if (vit != flags_.end()) 
00260             continue;
00261           
00262           
00263           
00264           double et = energy*position.perp()/position.mag();
00265           if ( et > etLow_ && energy > eLow_){ //Changed energy --> fabs(energy) -- then changed into energy
00266             if(returnEt) energySum+=et;
00267             else energySum+=energy;
00268           }
00269           
00270         }                //End if not end of list
00271       }                  //End loop over rechits
00272     }                    //End loop over barrel/endcap
00273   }                      //End if caloHits_
00274 
00275   return energySum;
00276 }
00277