CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
heppy::IsolationComputer Class Reference

#include <IsolationComputer.h>

Public Types

enum  SelfVetoPolicy { selfVetoNone =0, selfVetoAll =1, selfVetoFirst =2 }
 Self-veto policy. More...
 

Public Member Functions

void addVetos (const reco::Candidate &cand)
 veto footprint from this candidate, for the isolation of all candidates and also for calculation of neutral weights (if used) More...
 
float chargedAbsIso (const reco::Candidate &cand, float dR, float innerR=0, float threshold=0, SelfVetoPolicy selfVeto=selfVetoAll) const
 Isolation from charged from the PV. More...
 
void clearVetos ()
 clear all vetos More...
 
 IsolationComputer (float weightCone=-1)
 Create the calculator; optionally specify a cone for computing deltaBeta weights. More...
 
float neutralAbsIsoRaw (const reco::Candidate &cand, float dR, float innerR=0, float threshold=0, SelfVetoPolicy selfVeto=selfVetoAll) const
 Isolation from all neutrals (uncorrected) More...
 
float neutralAbsIsoWeighted (const reco::Candidate &cand, float dR, float innerR=0, float threshold=0, SelfVetoPolicy selfVeto=selfVetoAll) const
 Isolation from all neutrals (with weights) More...
 
float neutralHadAbsIsoRaw (const reco::Candidate &cand, float dR, float innerR=0, float threshold=0, SelfVetoPolicy selfVeto=selfVetoAll) const
 Isolation from neutral hadrons (uncorrected) More...
 
float neutralHadAbsIsoWeighted (const reco::Candidate &cand, float dR, float innerR=0, float threshold=0, SelfVetoPolicy selfVeto=selfVetoAll) const
 Isolation from neutral hadrons (with weights) More...
 
float photonAbsIsoRaw (const reco::Candidate &cand, float dR, float innerR=0, float threshold=0, SelfVetoPolicy selfVeto=selfVetoAll) const
 Isolation from photons (uncorrected) More...
 
float photonAbsIsoWeighted (const reco::Candidate &cand, float dR, float innerR=0, float threshold=0, SelfVetoPolicy selfVeto=selfVetoAll) const
 Isolation from photons (with weights) More...
 
float puAbsIso (const reco::Candidate &cand, float dR, float innerR=0, float threshold=0, SelfVetoPolicy selfVeto=selfVetoAll) const
 Isolation from charged from PU. More...
 
void setPackedCandidates (const std::vector< pat::PackedCandidate > &all, int fromPV_thresh=1, float dz_thresh=9999., float dxy_thresh=9999., bool also_leptons=false)
 Initialize with the list of packed candidates (note: clears also all vetos) More...
 

Protected Member Functions

float isoSumNeutralsWeighted (const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
 
float isoSumRaw (const std::vector< const pat::PackedCandidate * > &cands, const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
 

Protected Attributes

const std::vector< pat::PackedCandidate > * allcands_
 
std::vector< const pat::PackedCandidate * > charged_
 
std::vector< const pat::PackedCandidate * > neutral_
 
std::vector< const pat::PackedCandidate * > pileup_
 
std::vector< const reco::Candidate * > vetos_
 
float weightCone_
 
std::vector< float > weights_
 

Detailed Description

Definition at line 8 of file IsolationComputer.h.

Member Enumeration Documentation

Self-veto policy.

Enumerator
selfVetoNone 
selfVetoAll 
selfVetoFirst 

Definition at line 14 of file IsolationComputer.h.

Constructor & Destructor Documentation

heppy::IsolationComputer::IsolationComputer ( float  weightCone = -1)
inline

Create the calculator; optionally specify a cone for computing deltaBeta weights.

Definition at line 11 of file IsolationComputer.h.

11 : weightCone_(weightCone) {}

Member Function Documentation

void heppy::IsolationComputer::addVetos ( const reco::Candidate cand)

veto footprint from this candidate, for the isolation of all candidates and also for calculation of neutral weights (if used)

veto footprint from this candidate

Definition at line 49 of file IsolationComputer.cc.

References SimDataFormats::CaloAnalysis::cp, mps_fire::i, edm::Ptr< T >::isAvailable(), edm::Ptr< T >::isNonnull(), gen::n, reco::Candidate::numberOfSourceCandidatePtrs(), and reco::Candidate::sourceCandidatePtr().

49  {
50  for (unsigned int i = 0, n = cand.numberOfSourceCandidatePtrs(); i < n; ++i) {
52  if (cp.isNonnull() && cp.isAvailable()) vetos_.push_back(&*cp);
53  }
54 }
virtual CandidatePtr sourceCandidatePtr(size_type i) const
Definition: Candidate.h:170
bool isAvailable() const
Definition: Ptr.h:258
virtual size_t numberOfSourceCandidatePtrs() const =0
std::vector< const reco::Candidate * > vetos_
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
float heppy::IsolationComputer::chargedAbsIso ( const reco::Candidate cand,
float  dR,
float  innerR = 0,
float  threshold = 0,
SelfVetoPolicy  selfVeto = selfVetoAll 
) const

Isolation from charged from the PV.

Definition at line 62 of file IsolationComputer.cc.

62  {
63  return isoSumRaw(charged_, cand, dR, innerR, threshold, selfVeto);
64 }
float isoSumRaw(const std::vector< const pat::PackedCandidate * > &cands, const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
std::vector< const pat::PackedCandidate * > charged_
void heppy::IsolationComputer::clearVetos ( )

clear all vetos

Definition at line 57 of file IsolationComputer.cc.

57  {
58  vetos_.clear();
59 }
std::vector< const reco::Candidate * > vetos_
float heppy::IsolationComputer::isoSumNeutralsWeighted ( const reco::Candidate cand,
float  dR,
float  innerR,
float  threshold,
SelfVetoPolicy  selfVeto,
int  pdgId = -1 
) const
protected

Definition at line 132 of file IsolationComputer.cc.

References funct::abs(), SimDataFormats::CaloAnalysis::cp, reco::deltaR2(), reco::Candidate::eta(), Exception, f, spr::find(), mps_fire::i, edm::Ptr< T >::isAvailable(), edm::Ptr< T >::isNonnull(), cmsBatch::log, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, gen::n, reco::Candidate::numberOfSourceCandidatePtrs(), reco::Candidate::sourceCandidatePtr(), mathSSE::sqrt(), electronIdCutBased_cfi::threshold, pfDeepBoostedJetPreprocessParams_cfi::upper_bound, boostedElectronIsolation_cff::vetos, and w.

133 {
134  if (weightCone_ <= 0) throw cms::Exception("LogicError", "you must set a valid weight cone to use this method");
135  float dR2 = dR*dR, innerR2 = innerR*innerR, weightCone2 = weightCone_*weightCone_;
136 
137  std::vector<const reco::Candidate *> vetos(vetos_);
138  for (unsigned int i = 0, n = cand.numberOfSourceCandidatePtrs(); i < n; ++i) {
139  if (selfVeto == selfVetoNone) break;
140  const reco::CandidatePtr &cp = cand.sourceCandidatePtr(i);
141  if (cp.isNonnull() && cp.isAvailable()) {
142  vetos.push_back(&*cp);
143  if (selfVeto == selfVetoFirst) break;
144  }
145  }
146 
147  typedef std::vector<const pat::PackedCandidate *>::const_iterator IT;
148  IT charged_begin = std::lower_bound(charged_.begin(), charged_.end(), cand.eta() - dR - weightCone_, ByEta());
149  IT charged_end = std::upper_bound(charged_begin, charged_.end(), cand.eta() + dR + weightCone_, ByEta());
150  IT pileup_begin = std::lower_bound(pileup_.begin(), pileup_.end(), cand.eta() - dR - weightCone_, ByEta());
151  IT pileup_end = std::upper_bound(pileup_begin, pileup_.end(), cand.eta() + dR + weightCone_, ByEta());
152  IT neutral_begin = std::lower_bound(neutral_.begin(), neutral_.end(), cand.eta() - dR, ByEta());
153  IT neutral_end = std::upper_bound(neutral_begin, neutral_.end(), cand.eta() + dR, ByEta());
154 
155  double isosum = 0.0;
156  for (IT ineutral = neutral_begin; ineutral < neutral_end; ++ineutral) {
157  // pdgId
158  if (pdgId > 0 && abs((*ineutral)->pdgId()) != pdgId) continue;
159  // threshold
160  if (threshold > 0 && (*ineutral)->pt() < threshold) continue;
161  // cone
162  float mydr2 = reco::deltaR2(**ineutral, cand);
163  if (mydr2 >= dR2 || mydr2 < innerR2) continue;
164  // veto
165  if (std::find(vetos.begin(), vetos.end(), *ineutral) != vetos.end()) {
166  continue;
167  }
168  // weight
169  float &w = weights_[ineutral-neutral_.begin()];
170  if (w == -1.f) {
171  double sumc = 0, sump = 0.0;
172  for (IT icharged = charged_begin; icharged < charged_end; ++icharged) {
173  float hisdr2 = std::max<float>(reco::deltaR2(**icharged, **ineutral), 0.01f);
174  if (hisdr2 > weightCone2) continue;
175  if (std::find(vetos_.begin(), vetos_.end(), *icharged) != vetos_.end()) {
176  continue;
177  }
178  sumc += std::log( (*icharged)->pt() / std::sqrt(hisdr2) );
179  }
180  for (IT ipileup = pileup_begin; ipileup < pileup_end; ++ipileup) {
181  float hisdr2 = std::max<float>(reco::deltaR2(**ipileup, **ineutral), 0.01f);
182  if (hisdr2 > weightCone2) continue;
183  if (std::find(vetos_.begin(), vetos_.end(), *ipileup) != vetos_.end()) {
184  continue;
185  }
186  sumc += std::log( (*ipileup)->pt() / std::sqrt(hisdr2) );
187  }
188  w = (sump == 0 ? 1 : sumc/(sump+sumc));
189  }
190  // add to sum
191  isosum += w * (*ineutral)->pt();
192  }
193  return isosum;
194 }
const double w
Definition: UKUtility.cc:23
std::vector< const pat::PackedCandidate * > neutral_
virtual CandidatePtr sourceCandidatePtr(size_type i) const
Definition: Candidate.h:170
bool isAvailable() const
Definition: Ptr.h:258
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
virtual size_t numberOfSourceCandidatePtrs() const =0
std::vector< const reco::Candidate * > vetos_
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
std::vector< const pat::PackedCandidate * > charged_
std::vector< LinkConnSpec >::const_iterator IT
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
std::vector< const pat::PackedCandidate * > pileup_
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
virtual double eta() const =0
momentum pseudorapidity
std::vector< float > weights_
float heppy::IsolationComputer::isoSumRaw ( const std::vector< const pat::PackedCandidate * > &  cands,
const reco::Candidate cand,
float  dR,
float  innerR,
float  threshold,
SelfVetoPolicy  selfVeto,
int  pdgId = -1 
) const
protected

Definition at line 95 of file IsolationComputer.cc.

References funct::abs(), SimDataFormats::CaloAnalysis::cp, reco::deltaR2(), reco::Candidate::eta(), spr::find(), mps_fire::i, edm::Ptr< T >::isAvailable(), edm::Ptr< T >::isNonnull(), pfDeepBoostedJetPreprocessParams_cfi::lower_bound, gen::n, reco::Candidate::numberOfSourceCandidatePtrs(), reco::Candidate::sourceCandidatePtr(), electronIdCutBased_cfi::threshold, pfDeepBoostedJetPreprocessParams_cfi::upper_bound, and boostedElectronIsolation_cff::vetos.

96 {
97  float dR2 = dR*dR, innerR2 = innerR*innerR;
98 
99  std::vector<const reco::Candidate *> vetos(vetos_);
100  for (unsigned int i = 0, n = cand.numberOfSourceCandidatePtrs(); i < n; ++i) {
101  if (selfVeto == selfVetoNone) break;
102  const reco::CandidatePtr &cp = cand.sourceCandidatePtr(i);
103  if (cp.isNonnull() && cp.isAvailable()) {
104  vetos.push_back(&*cp);
105  if (selfVeto == selfVetoFirst) break;
106  }
107  }
108 
109  typedef std::vector<const pat::PackedCandidate *>::const_iterator IT;
110  IT candsbegin = std::lower_bound(cands.begin(), cands.end(), cand.eta() - dR, ByEta());
111  IT candsend = std::upper_bound(candsbegin, cands.end(), cand.eta() + dR, ByEta());
112 
113  double isosum = 0;
114  for (IT icharged = candsbegin; icharged < candsend; ++icharged) {
115  // pdgId
116  if (pdgId > 0 && abs((*icharged)->pdgId()) != pdgId) continue;
117  // threshold
118  if (threshold > 0 && (*icharged)->pt() < threshold) continue;
119  // cone
120  float mydr2 = reco::deltaR2(**icharged, cand);
121  if (mydr2 >= dR2 || mydr2 < innerR2) continue;
122  // veto
123  if (std::find(vetos.begin(), vetos.end(), *icharged) != vetos.end()) {
124  continue;
125  }
126  // add to sum
127  isosum += (*icharged)->pt();
128  }
129  return isosum;
130 }
virtual CandidatePtr sourceCandidatePtr(size_type i) const
Definition: Candidate.h:170
bool isAvailable() const
Definition: Ptr.h:258
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
virtual size_t numberOfSourceCandidatePtrs() const =0
std::vector< const reco::Candidate * > vetos_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< LinkConnSpec >::const_iterator IT
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
virtual double eta() const =0
momentum pseudorapidity
float heppy::IsolationComputer::neutralAbsIsoRaw ( const reco::Candidate cand,
float  dR,
float  innerR = 0,
float  threshold = 0,
SelfVetoPolicy  selfVeto = selfVetoAll 
) const

Isolation from all neutrals (uncorrected)

Definition at line 71 of file IsolationComputer.cc.

71  {
72  return isoSumRaw(neutral_, cand, dR, innerR, threshold, selfVeto);
73 }
std::vector< const pat::PackedCandidate * > neutral_
float isoSumRaw(const std::vector< const pat::PackedCandidate * > &cands, const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
float heppy::IsolationComputer::neutralAbsIsoWeighted ( const reco::Candidate cand,
float  dR,
float  innerR = 0,
float  threshold = 0,
SelfVetoPolicy  selfVeto = selfVetoAll 
) const

Isolation from all neutrals (with weights)

Definition at line 75 of file IsolationComputer.cc.

75  {
76  return isoSumNeutralsWeighted(cand, dR, innerR, threshold, selfVeto);
77 }
float isoSumNeutralsWeighted(const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
float heppy::IsolationComputer::neutralHadAbsIsoRaw ( const reco::Candidate cand,
float  dR,
float  innerR = 0,
float  threshold = 0,
SelfVetoPolicy  selfVeto = selfVetoAll 
) const

Isolation from neutral hadrons (uncorrected)

Definition at line 79 of file IsolationComputer.cc.

79  {
80  return isoSumRaw(neutral_, cand, dR, innerR, threshold, selfVeto, 130);
81 }
std::vector< const pat::PackedCandidate * > neutral_
float isoSumRaw(const std::vector< const pat::PackedCandidate * > &cands, const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
float heppy::IsolationComputer::neutralHadAbsIsoWeighted ( const reco::Candidate cand,
float  dR,
float  innerR = 0,
float  threshold = 0,
SelfVetoPolicy  selfVeto = selfVetoAll 
) const

Isolation from neutral hadrons (with weights)

Definition at line 83 of file IsolationComputer.cc.

83  {
84  return isoSumNeutralsWeighted(cand, dR, innerR, threshold, selfVeto, 130);
85 }
float isoSumNeutralsWeighted(const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
float heppy::IsolationComputer::photonAbsIsoRaw ( const reco::Candidate cand,
float  dR,
float  innerR = 0,
float  threshold = 0,
SelfVetoPolicy  selfVeto = selfVetoAll 
) const

Isolation from photons (uncorrected)

Definition at line 87 of file IsolationComputer.cc.

87  {
88  return isoSumRaw(neutral_, cand, dR, innerR, threshold, selfVeto, 22);
89 }
std::vector< const pat::PackedCandidate * > neutral_
float isoSumRaw(const std::vector< const pat::PackedCandidate * > &cands, const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
float heppy::IsolationComputer::photonAbsIsoWeighted ( const reco::Candidate cand,
float  dR,
float  innerR = 0,
float  threshold = 0,
SelfVetoPolicy  selfVeto = selfVetoAll 
) const

Isolation from photons (with weights)

Definition at line 91 of file IsolationComputer.cc.

91  {
92  return isoSumNeutralsWeighted(cand, dR, innerR, threshold, selfVeto, 22);
93 }
float isoSumNeutralsWeighted(const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
float heppy::IsolationComputer::puAbsIso ( const reco::Candidate cand,
float  dR,
float  innerR = 0,
float  threshold = 0,
SelfVetoPolicy  selfVeto = selfVetoAll 
) const

Isolation from charged from PU.

Definition at line 67 of file IsolationComputer.cc.

67  {
68  return isoSumRaw(pileup_, cand, dR, innerR, threshold, selfVeto);
69 }
float isoSumRaw(const std::vector< const pat::PackedCandidate * > &cands, const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
std::vector< const pat::PackedCandidate * > pileup_
void heppy::IsolationComputer::setPackedCandidates ( const std::vector< pat::PackedCandidate > &  all,
int  fromPV_thresh = 1,
float  dz_thresh = 9999.,
float  dxy_thresh = 9999.,
bool  also_leptons = false 
)

Initialize with the list of packed candidates (note: clears also all vetos)

Definition at line 18 of file IsolationComputer.cc.

References funct::abs(), Vispa.Plugins.EdmBrowser.EdmDataAccessor::all(), lumiContext::fill, and AlCaHLTBitMon_ParallelJobs::p.

19 {
20  allcands_ = &all;
21  charged_.clear(); neutral_.clear(); pileup_.clear();
22 
23  for (const pat::PackedCandidate &p : all) {
24  if (p.charge() == 0) {
25  neutral_.push_back(&p);
26  } else {
27 
28  if ( (abs(p.pdgId()) == 211 ) || ( also_leptons && ((abs(p.pdgId()) == 11 ) || (abs(p.pdgId()) == 13 )) ) ) {
29 
30  if (p.fromPV() > fromPV_thresh && fabs(p.dz()) < dz_thresh && fabs(p.dxy()) < dxy_thresh ) {
31  charged_.push_back(&p);
32  } else {
33  pileup_.push_back(&p);
34  }
35 
36  }
37 
38  }
39  }
40  if (weightCone_ > 0) weights_.resize(neutral_.size());
41  std::fill(weights_.begin(), weights_.end(), -1.f);
42  std::sort(charged_.begin(), charged_.end(), ByEta());
43  std::sort(neutral_.begin(), neutral_.end(), ByEta());
44  std::sort(pileup_.begin(), pileup_.end(), ByEta());
45  clearVetos();
46 }
std::vector< const pat::PackedCandidate * > neutral_
void clearVetos()
clear all vetos
const std::vector< pat::PackedCandidate > * allcands_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< const pat::PackedCandidate * > charged_
std::vector< const pat::PackedCandidate * > pileup_
std::vector< float > weights_

Member Data Documentation

const std::vector<pat::PackedCandidate>* heppy::IsolationComputer::allcands_
protected

Definition at line 51 of file IsolationComputer.h.

std::vector<const pat::PackedCandidate *> heppy::IsolationComputer::charged_
protected

Definition at line 54 of file IsolationComputer.h.

std::vector<const pat::PackedCandidate *> heppy::IsolationComputer::neutral_
protected

Definition at line 54 of file IsolationComputer.h.

std::vector<const pat::PackedCandidate *> heppy::IsolationComputer::pileup_
protected

Definition at line 54 of file IsolationComputer.h.

std::vector<const reco::Candidate *> heppy::IsolationComputer::vetos_
protected

Definition at line 56 of file IsolationComputer.h.

float heppy::IsolationComputer::weightCone_
protected

Definition at line 52 of file IsolationComputer.h.

std::vector<float> heppy::IsolationComputer::weights_
mutableprotected

Definition at line 55 of file IsolationComputer.h.