CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/PhysicsTools/PatUtils/src/CaloIsolationEnergy.cc

Go to the documentation of this file.
00001 //
00002 // $Id: CaloIsolationEnergy.cc,v 1.3 2010/10/15 22:44:33 wmtan Exp $
00003 //
00004 
00005 #include "PhysicsTools/PatUtils/interface/CaloIsolationEnergy.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "DataFormats/CaloTowers/interface/CaloTower.h"
00010 #include "DataFormats/PatCandidates/interface/Electron.h"
00011 #include "DataFormats/PatCandidates/interface/Muon.h"
00012 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00013 #include <vector>
00014 
00015 using namespace pat;
00016 
00018 CaloIsolationEnergy::CaloIsolationEnergy() {
00019 }
00020 
00022 CaloIsolationEnergy::~CaloIsolationEnergy() {
00023 }
00024 
00026 float CaloIsolationEnergy::calculate(const Electron & theElectron, const std::vector<CaloTower> & theTowers, float isoConeElectron) const {
00027   float isoE = this->calculate(*theElectron.gsfTrack(), theElectron.energy(), theTowers, isoConeElectron);
00028   return isoE - theElectron.caloEnergy();
00029 }
00030 float CaloIsolationEnergy::calculate(const Muon & theMuon, const std::vector<CaloTower> & theTowers, float isoConeMuon) const {
00031   return this->calculate(*theMuon.track(), theMuon.energy(), theTowers, isoConeMuon);
00032 }
00033 
00034 
00036 float CaloIsolationEnergy::calculate(const reco::Track & theTrack, const float leptonEnergy, const std::vector<CaloTower> & theTowers, float isoCone) const {
00037   float isoELepton = 0;
00038   // calculate iso energy
00039   const CaloTower * closestTower = 0;
00040   float closestDR = 10000;
00041   for (std::vector<CaloTower>::const_iterator itTower = theTowers.begin(); itTower != theTowers.end(); itTower++) {
00042     // calculate dPhi with correct sign
00043     float dPhi = theTrack.phi() - itTower->phi();
00044     if (dPhi > M_PI)  dPhi = -2*M_PI + dPhi;
00045     if (dPhi < -M_PI) dPhi =  2*M_PI + dPhi;
00046     // calculate dR
00047     float dR = sqrt(std::pow(theTrack.eta()-itTower->eta(), 2) + std::pow(dPhi, 2));
00048     // calculate energy in cone around direction at vertex of the track
00049     if (dR < isoCone) {
00050       isoELepton += itTower->energy();
00051       if (dR < closestDR) {
00052         closestDR = dR;
00053         closestTower = &(*itTower);
00054       }
00055     }
00056   }
00057   // subtract track deposits from total energy in cone
00058 //  if (closestTower) isoELepton -= closestTower->energy();
00059   // return the iso energy
00060   return isoELepton;
00061 }