1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
//
//
#ifndef DataFormats_PatCandidates_Lepton_h
#define DataFormats_PatCandidates_Lepton_h
/**
\class pat::Lepton Lepton.h "DataFormats/PatCandidates/interface/Lepton.h"
\brief Analysis-level lepton class
Lepton implements the analysis-level charged lepton class within the 'pat'
namespace. It currently provides the link to the generated lepton and
the isolation information.
Please post comments and questions to the Physics Tools hypernews:
https://hypernews.cern.ch/HyperNews/CMS/get/physTools.html
\author Steven Lowette, Giovanni Petrucciani, Frederic Ronga
*/
#include "DataFormats/Candidate/interface/Particle.h"
#include "DataFormats/PatCandidates/interface/PATObject.h"
#include "DataFormats/PatCandidates/interface/Isolation.h"
#include "DataFormats/PatCandidates/interface/PFIsolation.h"
namespace pat {
template <class LeptonType>
class Lepton : public PATObject<LeptonType> {
public:
Lepton();
Lepton(const LeptonType &aLepton);
Lepton(const edm::RefToBase<LeptonType> &aLeptonRef);
Lepton(const edm::Ptr<LeptonType> &aLeptonRef);
~Lepton() override;
Lepton<LeptonType> *clone() const override { return new Lepton<LeptonType>(*this); }
const reco::GenParticle *genLepton() const { return PATObject<LeptonType>::genParticle(); }
void setGenLepton(const reco::GenParticleRef &gl, bool embed = false) {
PATObject<LeptonType>::setGenParticleRef(gl, embed);
}
//============ BEGIN ISOLATION BLOCK =====
/// Returns the isolation variable for a specific key (or
/// pseudo-key like CaloIso), or -1.0 if not available
float userIsolation(IsolationKeys key) const {
if (key >= 0) {
//if (key >= isolations_.size()) throw cms::Excepton("Missing Data")
//<< "Isolation corresponding to key "
//<< key << " was not stored for this particle.";
if (size_t(key) >= isolations_.size())
return -1.0;
return isolations_[key];
} else
switch (key) {
case pat::CaloIso:
//if (isolations_.size() <= pat::HcalIso) throw cms::Excepton("Missing Data")
//<< "CaloIso Isolation was not stored for this particle.";
if (isolations_.size() <= pat::HcalIso)
return -1.0;
return isolations_[pat::EcalIso] + isolations_[pat::HcalIso];
default:
return -1.0;
//throw cms::Excepton("Missing Data") << "Isolation corresponding to key "
//<< key << " was not stored for this particle.";
}
}
/// Returns the isolation variable for string type function arguments
/// (to be used with the cut-string parser);
/// the possible values of the strings are the enums defined in
/// DataFormats/PatCandidates/interface/Isolation.h
float userIsolation(const std::string &key) const {
// remove leading namespace specifier
std::string prunedKey = (key.find("pat::") == 0) ? std::string(key, 5) : key;
if (prunedKey == "TrackIso")
return userIsolation(pat::TrackIso);
if (prunedKey == "EcalIso")
return userIsolation(pat::EcalIso);
if (prunedKey == "HcalIso")
return userIsolation(pat::HcalIso);
if (prunedKey == "PfAllParticleIso")
return userIsolation(pat::PfAllParticleIso);
if (prunedKey == "PfChargedHadronIso")
return userIsolation(pat::PfChargedHadronIso);
if (prunedKey == "PfNeutralHadronIso")
return userIsolation(pat::PfNeutralHadronIso);
if (prunedKey == "PfGammaIso")
return userIsolation(pat::PfGammaIso);
if (prunedKey == "User1Iso")
return userIsolation(pat::User1Iso);
if (prunedKey == "User2Iso")
return userIsolation(pat::User2Iso);
if (prunedKey == "User3Iso")
return userIsolation(pat::User3Iso);
if (prunedKey == "User4Iso")
return userIsolation(pat::User4Iso);
if (prunedKey == "User5Iso")
return userIsolation(pat::User5Iso);
if (prunedKey == "UserBaseIso")
return userIsolation(pat::UserBaseIso);
if (prunedKey == "CaloIso")
return userIsolation(pat::CaloIso);
if (prunedKey == "PfPUChargedHadronIso")
return userIsolation(pat::PfPUChargedHadronIso);
//throw cms::Excepton("Missing Data")
//<< "Isolation corresponding to key "
//<< key << " was not stored for this particle.";
return -1.0;
}
/// Sets the userIsolation variable for a specific key.
/// Note that you can't set isolation for a pseudo-key
/// like CaloIso
void setIsolation(IsolationKeys key, float value) {
if (key >= 0) {
if (size_t(key) >= isolations_.size())
isolations_.resize(key + 1, -1.0);
isolations_[key] = value;
} else {
throw cms::Exception("Illegal Argument")
<< "The key for which you're setting isolation does not correspond "
<< "to an individual isolation but to the sum of more independent isolations "
<< "(e.g. Calo = Ecal + Hcal), so you can't SET the value, just GET it.\n"
<< "Please set up each component independly.\n";
}
}
// ---- specific getters ----
/// Returns the tracker isolation variable that was stored in this
/// object when produced, or -1.0 if there is none (overloaded if
/// specific isolation functions are available from the derived
/// objects)
float trackIso() const { return userIsolation(pat::TrackIso); }
/// Returns the sum of ecal and hcal isolation variable that were
/// stored in this object when produced, or -1.0 if at least one
/// is missing (overloaded if specific isolation functions are
/// available from the derived objects)
float caloIso() const { return userIsolation(pat::CaloIso); }
/// Returns the ecal isolation variable that was stored in this
/// object when produced, or -1.0 if there is none (overloaded
/// if specific isolation functions are available from the
/// derived objects)
float ecalIso() const { return userIsolation(pat::EcalIso); }
/// Returns the hcal isolation variable that was stored in this
/// object when produced, or -1.0 if there is none (overloaded
/// if specific isolation functions are available from the
/// derived objects)
float hcalIso() const { return userIsolation(pat::HcalIso); }
/// PARTICLE FLOW ISOLATION
/// Returns the isolation calculated with all the PFCandidates
float particleIso() const { return userIsolation(pat::PfAllParticleIso); }
/// Returns the isolation calculated with only the charged hadron
/// PFCandidates
float chargedHadronIso() const { return userIsolation(pat::PfChargedHadronIso); }
/// Returns the isolation calculated with only the neutral hadron
/// PFCandidates
float neutralHadronIso() const { return userIsolation(pat::PfNeutralHadronIso); }
/// Returns the isolation calculated with only the gamma
/// PFCandidates
float photonIso() const { return userIsolation(pat::PfGammaIso); }
/// Returns the isolation calculated with only the pile-up charged hadron
/// PFCandidates
float puChargedHadronIso() const { return userIsolation(pat::PfPUChargedHadronIso); }
/// Returns the user defined isolation variable #index that was
/// stored in this object when produced, or -1.0 if there is none
float userIso(uint8_t index = 0) const { return userIsolation(IsolationKeys(UserBaseIso + index)); }
// ---- specific setters ----
/// Sets tracker isolation variable
void setTrackIso(float trackIso) { setIsolation(pat::TrackIso, trackIso); }
/// Sets ecal isolation variable
void setEcalIso(float caloIso) { setIsolation(pat::EcalIso, caloIso); }
/// Sets hcal isolation variable
void setHcalIso(float caloIso) { setIsolation(pat::HcalIso, caloIso); }
/// Sets user isolation variable #index
void setUserIso(float value, uint8_t index = 0) { setIsolation(IsolationKeys(UserBaseIso + index), value); }
//============ BEGIN ISODEPOSIT BLOCK =====
/// Returns the IsoDeposit associated with some key, or a null pointer if it is not available
const IsoDeposit *isoDeposit(IsolationKeys key) const {
for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end(); it != ed; ++it) {
if (it->first == key)
return &it->second;
}
return nullptr;
}
/// Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep) {
IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
for (; it != ed; ++it) {
if (it->first == key) {
it->second = dep;
return;
}
}
isoDeposits_.push_back(std::make_pair(key, dep));
}
// ---- specific getters ----
const IsoDeposit *trackIsoDeposit() const { return isoDeposit(pat::TrackIso); }
const IsoDeposit *ecalIsoDeposit() const { return isoDeposit(pat::EcalIso); }
const IsoDeposit *hcalIsoDeposit() const { return isoDeposit(pat::HcalIso); }
const IsoDeposit *userIsoDeposit(uint8_t index = 0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
// ---- specific setters ----
void trackIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::TrackIso, dep); }
void ecalIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::EcalIso, dep); }
void hcalIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::HcalIso, dep); }
void userIsoDeposit(const IsoDeposit &dep, uint8_t index = 0) {
setIsoDeposit(IsolationKeys(UserBaseIso + index), dep);
}
const PFIsolation &miniPFIsolation() const { return miniPFIsolation_; }
void setMiniPFIsolation(PFIsolation const &iso) { miniPFIsolation_ = iso; }
protected:
// --- Isolation and IsoDeposit related datamebers ---
typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
IsoDepositPairs isoDeposits_;
std::vector<float> isolations_;
PFIsolation miniPFIsolation_;
};
/// default constructor
template <class LeptonType>
Lepton<LeptonType>::Lepton() : PATObject<LeptonType>(LeptonType()) {
// no common constructor, so initialize the candidate manually
this->setCharge(0);
this->setP4(reco::Particle::LorentzVector(0, 0, 0, 0));
this->setVertex(reco::Particle::Point(0, 0, 0));
this->setMiniPFIsolation(pat::PFIsolation());
}
/// constructor from LeptonType
template <class LeptonType>
Lepton<LeptonType>::Lepton(const LeptonType &aLepton) : PATObject<LeptonType>(aLepton) {
this->setMiniPFIsolation(pat::PFIsolation());
}
/// constructor from ref to LeptonType
template <class LeptonType>
Lepton<LeptonType>::Lepton(const edm::RefToBase<LeptonType> &aLeptonRef) : PATObject<LeptonType>(aLeptonRef) {
this->setMiniPFIsolation(pat::PFIsolation());
}
/// constructor from ref to LeptonType
template <class LeptonType>
Lepton<LeptonType>::Lepton(const edm::Ptr<LeptonType> &aLeptonRef) : PATObject<LeptonType>(aLeptonRef) {
this->setMiniPFIsolation(pat::PFIsolation());
}
/// destructor
template <class LeptonType>
Lepton<LeptonType>::~Lepton() {}
} // namespace pat
#endif
|