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

◆ SelfVetoPolicy

Self-veto policy.

Enumerator
selfVetoNone 
selfVetoAll 
selfVetoFirst 

Definition at line 14 of file IsolationComputer.h.

14 { selfVetoNone = 0, selfVetoAll = 1, selfVetoFirst = 2 };

Constructor & Destructor Documentation

◆ IsolationComputer()

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

◆ addVetos()

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 47 of file IsolationComputer.cc.

47  {
48  for (unsigned int i = 0, n = cand.numberOfSourceCandidatePtrs(); i < n; ++i) {
49  const reco::CandidatePtr &cp = cand.sourceCandidatePtr(i);
50  if (cp.isNonnull() && cp.isAvailable())
51  vetos_.push_back(&*cp);
52  }
53 }

References CommonMethods::cp(), mps_fire::i, and dqmiodumpmetadata::n.

◆ chargedAbsIso()

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 59 of file IsolationComputer.cc.

60  {
61  return isoSumRaw(charged_, cand, dR, innerR, threshold, selfVeto);
62 }

References HGC3DClusterGenMatchSelector_cfi::dR, and remoteMonitoring_LED_IterMethod_cfg::threshold.

◆ clearVetos()

void heppy::IsolationComputer::clearVetos ( )

clear all vetos

Definition at line 56 of file IsolationComputer.cc.

56 { vetos_.clear(); }

Referenced by setPackedCandidates().

◆ isoSumNeutralsWeighted()

float heppy::IsolationComputer::isoSumNeutralsWeighted ( const reco::Candidate cand,
float  dR,
float  innerR,
float  threshold,
SelfVetoPolicy  selfVeto,
int  pdgId = -1 
) const
protected

Definition at line 147 of file IsolationComputer.cc.

148  {
149  if (weightCone_ <= 0)
150  throw cms::Exception("LogicError", "you must set a valid weight cone to use this method");
151  float dR2 = dR * dR, innerR2 = innerR * innerR, weightCone2 = weightCone_ * weightCone_;
152 
153  std::vector<const reco::Candidate *> vetos(vetos_);
154  for (unsigned int i = 0, n = cand.numberOfSourceCandidatePtrs(); i < n; ++i) {
155  if (selfVeto == selfVetoNone)
156  break;
157  const reco::CandidatePtr &cp = cand.sourceCandidatePtr(i);
158  if (cp.isNonnull() && cp.isAvailable()) {
159  vetos.push_back(&*cp);
160  if (selfVeto == selfVetoFirst)
161  break;
162  }
163  }
164 
165  typedef std::vector<const pat::PackedCandidate *>::const_iterator IT;
166  IT charged_begin = std::lower_bound(charged_.begin(), charged_.end(), cand.eta() - dR - weightCone_, ByEta());
167  IT charged_end = std::upper_bound(charged_begin, charged_.end(), cand.eta() + dR + weightCone_, ByEta());
168  IT pileup_begin = std::lower_bound(pileup_.begin(), pileup_.end(), cand.eta() - dR - weightCone_, ByEta());
169  IT pileup_end = std::upper_bound(pileup_begin, pileup_.end(), cand.eta() + dR + weightCone_, ByEta());
170  IT neutral_begin = std::lower_bound(neutral_.begin(), neutral_.end(), cand.eta() - dR, ByEta());
171  IT neutral_end = std::upper_bound(neutral_begin, neutral_.end(), cand.eta() + dR, ByEta());
172 
173  double isosum = 0.0;
174  for (IT ineutral = neutral_begin; ineutral < neutral_end; ++ineutral) {
175  // pdgId
176  if (pdgId > 0 && abs((*ineutral)->pdgId()) != pdgId)
177  continue;
178  // threshold
179  if (threshold > 0 && (*ineutral)->pt() < threshold)
180  continue;
181  // cone
182  float mydr2 = reco::deltaR2(**ineutral, cand);
183  if (mydr2 >= dR2 || mydr2 < innerR2)
184  continue;
185  // veto
186  if (std::find(vetos.begin(), vetos.end(), *ineutral) != vetos.end()) {
187  continue;
188  }
189  // weight
190  float &w = weights_[ineutral - neutral_.begin()];
191  if (w == -1.f) {
192  double sumc = 0, sump = 0.0;
193  for (IT icharged = charged_begin; icharged < charged_end; ++icharged) {
194  float hisdr2 = std::max<float>(reco::deltaR2(**icharged, **ineutral), 0.01f);
195  if (hisdr2 > weightCone2)
196  continue;
197  if (std::find(vetos_.begin(), vetos_.end(), *icharged) != vetos_.end()) {
198  continue;
199  }
200  sumc += std::log((*icharged)->pt() / std::sqrt(hisdr2));
201  }
202  for (IT ipileup = pileup_begin; ipileup < pileup_end; ++ipileup) {
203  float hisdr2 = std::max<float>(reco::deltaR2(**ipileup, **ineutral), 0.01f);
204  if (hisdr2 > weightCone2)
205  continue;
206  if (std::find(vetos_.begin(), vetos_.end(), *ipileup) != vetos_.end()) {
207  continue;
208  }
209  sumc += std::log((*ipileup)->pt() / std::sqrt(hisdr2));
210  }
211  w = (sump == 0 ? 1 : sumc / (sump + sumc));
212  }
213  // add to sum
214  isosum += w * (*ineutral)->pt();
215  }
216  return isosum;
217 }

References funct::abs(), CommonMethods::cp(), reco::deltaR2(), HGC3DClusterGenMatchSelector_cfi::dR, Exception, f, spr::find(), mps_fire::i, dqm-mbProfile::log, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, dqmiodumpmetadata::n, EgammaValidation_cff::pdgId, mathSSE::sqrt(), remoteMonitoring_LED_IterMethod_cfg::threshold, pfDeepBoostedJetPreprocessParams_cfi::upper_bound, boostedElectronIsolation_cff::vetos, and w.

◆ isoSumRaw()

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 100 of file IsolationComputer.cc.

106  {
107  float dR2 = dR * dR, innerR2 = innerR * innerR;
108 
109  std::vector<const reco::Candidate *> vetos(vetos_);
110  for (unsigned int i = 0, n = cand.numberOfSourceCandidatePtrs(); i < n; ++i) {
111  if (selfVeto == selfVetoNone)
112  break;
113  const reco::CandidatePtr &cp = cand.sourceCandidatePtr(i);
114  if (cp.isNonnull() && cp.isAvailable()) {
115  vetos.push_back(&*cp);
116  if (selfVeto == selfVetoFirst)
117  break;
118  }
119  }
120 
121  typedef std::vector<const pat::PackedCandidate *>::const_iterator IT;
122  IT candsbegin = std::lower_bound(cands.begin(), cands.end(), cand.eta() - dR, ByEta());
123  IT candsend = std::upper_bound(candsbegin, cands.end(), cand.eta() + dR, ByEta());
124 
125  double isosum = 0;
126  for (IT icharged = candsbegin; icharged < candsend; ++icharged) {
127  // pdgId
128  if (pdgId > 0 && abs((*icharged)->pdgId()) != pdgId)
129  continue;
130  // threshold
131  if (threshold > 0 && (*icharged)->pt() < threshold)
132  continue;
133  // cone
134  float mydr2 = reco::deltaR2(**icharged, cand);
135  if (mydr2 >= dR2 || mydr2 < innerR2)
136  continue;
137  // veto
138  if (std::find(vetos.begin(), vetos.end(), *icharged) != vetos.end()) {
139  continue;
140  }
141  // add to sum
142  isosum += (*icharged)->pt();
143  }
144  return isosum;
145 }

References funct::abs(), HLT_FULL_cff::cands, CommonMethods::cp(), reco::deltaR2(), HGC3DClusterGenMatchSelector_cfi::dR, spr::find(), mps_fire::i, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, dqmiodumpmetadata::n, EgammaValidation_cff::pdgId, remoteMonitoring_LED_IterMethod_cfg::threshold, pfDeepBoostedJetPreprocessParams_cfi::upper_bound, and boostedElectronIsolation_cff::vetos.

◆ neutralAbsIsoRaw()

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 70 of file IsolationComputer.cc.

71  {
72  return isoSumRaw(neutral_, cand, dR, innerR, threshold, selfVeto);
73 }

References HGC3DClusterGenMatchSelector_cfi::dR, and remoteMonitoring_LED_IterMethod_cfg::threshold.

◆ neutralAbsIsoWeighted()

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.

76  {
77  return isoSumNeutralsWeighted(cand, dR, innerR, threshold, selfVeto);
78 }

References HGC3DClusterGenMatchSelector_cfi::dR, and remoteMonitoring_LED_IterMethod_cfg::threshold.

◆ neutralHadAbsIsoRaw()

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 80 of file IsolationComputer.cc.

81  {
82  return isoSumRaw(neutral_, cand, dR, innerR, threshold, selfVeto, 130);
83 }

References HGC3DClusterGenMatchSelector_cfi::dR, and remoteMonitoring_LED_IterMethod_cfg::threshold.

◆ neutralHadAbsIsoWeighted()

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 85 of file IsolationComputer.cc.

86  {
87  return isoSumNeutralsWeighted(cand, dR, innerR, threshold, selfVeto, 130);
88 }

References HGC3DClusterGenMatchSelector_cfi::dR, and remoteMonitoring_LED_IterMethod_cfg::threshold.

◆ photonAbsIsoRaw()

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 90 of file IsolationComputer.cc.

91  {
92  return isoSumRaw(neutral_, cand, dR, innerR, threshold, selfVeto, 22);
93 }

References HGC3DClusterGenMatchSelector_cfi::dR, and remoteMonitoring_LED_IterMethod_cfg::threshold.

◆ photonAbsIsoWeighted()

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 95 of file IsolationComputer.cc.

96  {
97  return isoSumNeutralsWeighted(cand, dR, innerR, threshold, selfVeto, 22);
98 }

References HGC3DClusterGenMatchSelector_cfi::dR, and remoteMonitoring_LED_IterMethod_cfg::threshold.

◆ puAbsIso()

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 65 of file IsolationComputer.cc.

66  {
67  return isoSumRaw(pileup_, cand, dR, innerR, threshold, selfVeto);
68 }

References HGC3DClusterGenMatchSelector_cfi::dR, and remoteMonitoring_LED_IterMethod_cfg::threshold.

◆ setPackedCandidates()

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 14 of file IsolationComputer.cc.

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

References funct::abs(), python.cmstools::all(), allcands_, charged_, clearVetos(), ntuplemaker::fill, neutral_, AlCaHLTBitMon_ParallelJobs::p, pileup_, weightCone_, and weights_.

Member Data Documentation

◆ allcands_

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

Definition at line 85 of file IsolationComputer.h.

Referenced by setPackedCandidates().

◆ charged_

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

Definition at line 88 of file IsolationComputer.h.

Referenced by setPackedCandidates().

◆ neutral_

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

Definition at line 88 of file IsolationComputer.h.

Referenced by setPackedCandidates().

◆ pileup_

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

Definition at line 88 of file IsolationComputer.h.

Referenced by setPackedCandidates().

◆ vetos_

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

Definition at line 90 of file IsolationComputer.h.

◆ weightCone_

float heppy::IsolationComputer::weightCone_
protected

Definition at line 86 of file IsolationComputer.h.

Referenced by setPackedCandidates().

◆ weights_

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

Definition at line 89 of file IsolationComputer.h.

Referenced by setPackedCandidates().

heppy::IsolationComputer::allcands_
const std::vector< pat::PackedCandidate > * allcands_
Definition: IsolationComputer.h:85
heppy::IsolationComputer::pileup_
std::vector< const pat::PackedCandidate * > pileup_
Definition: IsolationComputer.h:88
heppy::IsolationComputer::selfVetoNone
Definition: IsolationComputer.h:14
pfDeepBoostedJetPreprocessParams_cfi.upper_bound
upper_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:16
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
heppy::IsolationComputer::selfVetoFirst
Definition: IsolationComputer.h:14
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
heppy::IsolationComputer::selfVetoAll
Definition: IsolationComputer.h:14
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
python.cmstools.all
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:26
heppy::IsolationComputer::neutral_
std::vector< const pat::PackedCandidate * > neutral_
Definition: IsolationComputer.h:88
heppy::IsolationComputer::vetos_
std::vector< const reco::Candidate * > vetos_
Definition: IsolationComputer.h:90
heppy::IsolationComputer::isoSumNeutralsWeighted
float isoSumNeutralsWeighted(const reco::Candidate &cand, float dR, float innerR, float threshold, SelfVetoPolicy selfVeto, int pdgId=-1) const
Definition: IsolationComputer.cc:147
heppy::IsolationComputer::charged_
std::vector< const pat::PackedCandidate * > charged_
Definition: IsolationComputer.h:88
w
const double w
Definition: UKUtility.cc:23
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
heppy::IsolationComputer::clearVetos
void clearVetos()
clear all vetos
Definition: IsolationComputer.cc:56
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15142
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
pat::PackedCandidate
Definition: PackedCandidate.h:22
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
cand
Definition: decayParser.h:32
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
IT
std::vector< LinkConnSpec >::const_iterator IT
Definition: TriggerBoardSpec.cc:5
heppy::IsolationComputer::weights_
std::vector< float > weights_
Definition: IsolationComputer.h:89
edm::Ptr< Candidate >
heppy::IsolationComputer::weightCone_
float weightCone_
Definition: IsolationComputer.h:86
Exception
Definition: hltDiff.cc:246
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:426
CommonMethods.cp
def cp(fromDir, toDir, listOfFiles, overwrite=False, smallList=False)
Definition: CommonMethods.py:192
boostedElectronIsolation_cff.vetos
vetos
Definition: boostedElectronIsolation_cff.py:79
heppy::IsolationComputer::isoSumRaw
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
Definition: IsolationComputer.cc:100