Go to the documentation of this file.00001
00002
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
00039
00040 float closestDR = 10000;
00041 for (std::vector<CaloTower>::const_iterator itTower = theTowers.begin(); itTower != theTowers.end(); itTower++) {
00042
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
00047 float dR = sqrt(std::pow(theTrack.eta()-itTower->eta(), 2) + std::pow(dPhi, 2));
00048
00049 if (dR < isoCone) {
00050 isoELepton += itTower->energy();
00051 if (dR < closestDR) {
00052 closestDR = dR;
00053
00054 }
00055 }
00056 }
00057
00058
00059
00060 return isoELepton;
00061 }