Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:13

0001 //
0002 //
0003 
0004 #include "PhysicsTools/PatUtils/interface/CaloIsolationEnergy.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/Utilities/interface/Exception.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "DataFormats/CaloTowers/interface/CaloTower.h"
0009 #include "DataFormats/PatCandidates/interface/Electron.h"
0010 #include "DataFormats/PatCandidates/interface/Muon.h"
0011 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0012 #include <vector>
0013 
0014 using namespace pat;
0015 
0016 /// constructor
0017 CaloIsolationEnergy::CaloIsolationEnergy() {}
0018 
0019 /// destructor
0020 CaloIsolationEnergy::~CaloIsolationEnergy() {}
0021 
0022 /// calculate the CalIsoE from the lepton object
0023 float CaloIsolationEnergy::calculate(const Electron& theElectron,
0024                                      const std::vector<CaloTower>& theTowers,
0025                                      float isoConeElectron) const {
0026   float isoE = this->calculate(*theElectron.gsfTrack(), theElectron.energy(), theTowers, isoConeElectron);
0027   return isoE - theElectron.caloEnergy();
0028 }
0029 float CaloIsolationEnergy::calculate(const Muon& theMuon,
0030                                      const std::vector<CaloTower>& theTowers,
0031                                      float isoConeMuon) const {
0032   return this->calculate(*theMuon.track(), theMuon.energy(), theTowers, isoConeMuon);
0033 }
0034 
0035 /// calculate the CalIsoE from the lepton's track
0036 float CaloIsolationEnergy::calculate(const reco::Track& theTrack,
0037                                      const float leptonEnergy,
0038                                      const std::vector<CaloTower>& theTowers,
0039                                      float isoCone) const {
0040   float isoELepton = 0;
0041   // calculate iso energy
0042   //const CaloTower * closestTower = 0;
0043   float closestDR = 10000;
0044   for (std::vector<CaloTower>::const_iterator itTower = theTowers.begin(); itTower != theTowers.end(); itTower++) {
0045     // calculate dPhi with correct sign
0046     float dPhi = theTrack.phi() - itTower->phi();
0047     if (dPhi > M_PI)
0048       dPhi = -2 * M_PI + dPhi;
0049     if (dPhi < -M_PI)
0050       dPhi = 2 * M_PI + dPhi;
0051     // calculate dR
0052     float dR = sqrt(std::pow(theTrack.eta() - itTower->eta(), 2) + std::pow(dPhi, 2));
0053     // calculate energy in cone around direction at vertex of the track
0054     if (dR < isoCone) {
0055       isoELepton += itTower->energy();
0056       if (dR < closestDR) {
0057         closestDR = dR;
0058         //closestTower = &(*itTower);
0059       }
0060     }
0061   }
0062   // subtract track deposits from total energy in cone
0063   //  if (closestTower) isoELepton -= closestTower->energy();
0064   // return the iso energy
0065   return isoELepton;
0066 }