1 |
dgele |
1.1 |
//
|
2 |
|
|
// $Id: CaloIsolationEnergy.cc,v 1.2 2008/02/28 14:54:25 llista Exp $
|
3 |
|
|
//
|
4 |
|
|
|
5 |
|
|
#include "PhysicsTools/PatUtils/interface/CaloIsolationEnergy.h"
|
6 |
|
|
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
7 |
|
|
#include "FWCore/Utilities/interface/Exception.h"
|
8 |
|
|
#include "FWCore/Framework/interface/ESHandle.h"
|
9 |
|
|
#include "DataFormats/CaloTowers/interface/CaloTower.h"
|
10 |
|
|
#include "DataFormats/PatCandidates/interface/Electron.h"
|
11 |
|
|
#include "DataFormats/PatCandidates/interface/Muon.h"
|
12 |
|
|
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
|
13 |
|
|
#include <vector>
|
14 |
|
|
|
15 |
|
|
using namespace pat;
|
16 |
|
|
|
17 |
|
|
/// constructor
|
18 |
|
|
CaloIsolationEnergy::CaloIsolationEnergy() {
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
/// destructor
|
22 |
|
|
CaloIsolationEnergy::~CaloIsolationEnergy() {
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
/// calculate the CalIsoE from the lepton object
|
26 |
|
|
float CaloIsolationEnergy::calculate(const Electron & theElectron, const std::vector<CaloTower> & theTowers, float isoConeElectron) const {
|
27 |
|
|
float isoE = this->calculate(*theElectron.gsfTrack(), theElectron.energy(), theTowers, isoConeElectron);
|
28 |
|
|
return isoE - theElectron.caloEnergy();
|
29 |
|
|
}
|
30 |
|
|
float CaloIsolationEnergy::calculate(const Muon & theMuon, const std::vector<CaloTower> & theTowers, float isoConeMuon) const {
|
31 |
|
|
return this->calculate(*theMuon.track(), theMuon.energy(), theTowers, isoConeMuon);
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
/// calculate the CalIsoE from the lepton's track
|
36 |
|
|
float CaloIsolationEnergy::calculate(const reco::Track & theTrack, const float leptonEnergy, const std::vector<CaloTower> & theTowers, float isoCone) const {
|
37 |
|
|
float isoELepton = 0;
|
38 |
|
|
// calculate iso energy
|
39 |
|
|
const CaloTower * closestTower = 0;
|
40 |
|
|
float closestDR = 10000;
|
41 |
|
|
for (std::vector<CaloTower>::const_iterator itTower = theTowers.begin(); itTower != theTowers.end(); itTower++) {
|
42 |
|
|
// calculate dPhi with correct sign
|
43 |
|
|
float dPhi = theTrack.phi() - itTower->phi();
|
44 |
|
|
if (dPhi > M_PI) dPhi = -2*M_PI + dPhi;
|
45 |
|
|
if (dPhi < -M_PI) dPhi = 2*M_PI + dPhi;
|
46 |
|
|
// calculate dR
|
47 |
|
|
float dR = sqrt(pow(theTrack.eta()-itTower->eta(), 2) + pow(dPhi, 2));
|
48 |
|
|
// calculate energy in cone around direction at vertex of the track
|
49 |
|
|
if (dR < isoCone) {
|
50 |
|
|
isoELepton += itTower->energy();
|
51 |
|
|
if (dR < closestDR) {
|
52 |
|
|
closestDR = dR;
|
53 |
|
|
closestTower = &(*itTower);
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
// subtract track deposits from total energy in cone
|
58 |
|
|
// if (closestTower) isoELepton -= closestTower->energy();
|
59 |
|
|
// return the iso energy
|
60 |
|
|
return isoELepton;
|
61 |
|
|
}
|