File indexing completed on 2024-04-06 12:04:54
0001
0002
0003
0004 #ifndef DataFormats_PatCandidates_Lepton_h
0005 #define DataFormats_PatCandidates_Lepton_h
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "DataFormats/Candidate/interface/Particle.h"
0022 #include "DataFormats/PatCandidates/interface/PATObject.h"
0023 #include "DataFormats/PatCandidates/interface/Isolation.h"
0024 #include "DataFormats/PatCandidates/interface/PFIsolation.h"
0025
0026 namespace pat {
0027
0028 template <class LeptonType>
0029 class Lepton : public PATObject<LeptonType> {
0030 public:
0031 Lepton();
0032 Lepton(const LeptonType &aLepton);
0033 Lepton(const edm::RefToBase<LeptonType> &aLeptonRef);
0034 Lepton(const edm::Ptr<LeptonType> &aLeptonRef);
0035 ~Lepton() override;
0036
0037 Lepton<LeptonType> *clone() const override { return new Lepton<LeptonType>(*this); }
0038
0039 const reco::GenParticle *genLepton() const { return PATObject<LeptonType>::genParticle(); }
0040
0041 void setGenLepton(const reco::GenParticleRef &gl, bool embed = false) {
0042 PATObject<LeptonType>::setGenParticleRef(gl, embed);
0043 }
0044
0045
0046
0047
0048 float userIsolation(IsolationKeys key) const {
0049 if (key >= 0) {
0050
0051
0052
0053 if (size_t(key) >= isolations_.size())
0054 return -1.0;
0055 return isolations_[key];
0056 } else
0057 switch (key) {
0058 case pat::CaloIso:
0059
0060
0061 if (isolations_.size() <= pat::HcalIso)
0062 return -1.0;
0063 return isolations_[pat::EcalIso] + isolations_[pat::HcalIso];
0064 default:
0065 return -1.0;
0066
0067
0068 }
0069 }
0070
0071
0072
0073
0074 float userIsolation(const std::string &key) const {
0075
0076 std::string prunedKey = (key.find("pat::") == 0) ? std::string(key, 5) : key;
0077 if (prunedKey == "TrackIso")
0078 return userIsolation(pat::TrackIso);
0079 if (prunedKey == "EcalIso")
0080 return userIsolation(pat::EcalIso);
0081 if (prunedKey == "HcalIso")
0082 return userIsolation(pat::HcalIso);
0083 if (prunedKey == "PfAllParticleIso")
0084 return userIsolation(pat::PfAllParticleIso);
0085 if (prunedKey == "PfChargedHadronIso")
0086 return userIsolation(pat::PfChargedHadronIso);
0087 if (prunedKey == "PfNeutralHadronIso")
0088 return userIsolation(pat::PfNeutralHadronIso);
0089 if (prunedKey == "PfGammaIso")
0090 return userIsolation(pat::PfGammaIso);
0091 if (prunedKey == "User1Iso")
0092 return userIsolation(pat::User1Iso);
0093 if (prunedKey == "User2Iso")
0094 return userIsolation(pat::User2Iso);
0095 if (prunedKey == "User3Iso")
0096 return userIsolation(pat::User3Iso);
0097 if (prunedKey == "User4Iso")
0098 return userIsolation(pat::User4Iso);
0099 if (prunedKey == "User5Iso")
0100 return userIsolation(pat::User5Iso);
0101 if (prunedKey == "UserBaseIso")
0102 return userIsolation(pat::UserBaseIso);
0103 if (prunedKey == "CaloIso")
0104 return userIsolation(pat::CaloIso);
0105 if (prunedKey == "PfPUChargedHadronIso")
0106 return userIsolation(pat::PfPUChargedHadronIso);
0107
0108
0109
0110 return -1.0;
0111 }
0112
0113
0114
0115 void setIsolation(IsolationKeys key, float value) {
0116 if (key >= 0) {
0117 if (size_t(key) >= isolations_.size())
0118 isolations_.resize(key + 1, -1.0);
0119 isolations_[key] = value;
0120 } else {
0121 throw cms::Exception("Illegal Argument")
0122 << "The key for which you're setting isolation does not correspond "
0123 << "to an individual isolation but to the sum of more independent isolations "
0124 << "(e.g. Calo = Ecal + Hcal), so you can't SET the value, just GET it.\n"
0125 << "Please set up each component independly.\n";
0126 }
0127 }
0128
0129
0130
0131
0132
0133
0134 float trackIso() const { return userIsolation(pat::TrackIso); }
0135
0136
0137
0138
0139 float caloIso() const { return userIsolation(pat::CaloIso); }
0140
0141
0142
0143
0144 float ecalIso() const { return userIsolation(pat::EcalIso); }
0145
0146
0147
0148
0149 float hcalIso() const { return userIsolation(pat::HcalIso); }
0150
0151
0152
0153 float particleIso() const { return userIsolation(pat::PfAllParticleIso); }
0154
0155
0156 float chargedHadronIso() const { return userIsolation(pat::PfChargedHadronIso); }
0157
0158
0159 float neutralHadronIso() const { return userIsolation(pat::PfNeutralHadronIso); }
0160
0161
0162 float photonIso() const { return userIsolation(pat::PfGammaIso); }
0163
0164
0165 float puChargedHadronIso() const { return userIsolation(pat::PfPUChargedHadronIso); }
0166
0167
0168 float userIso(uint8_t index = 0) const { return userIsolation(IsolationKeys(UserBaseIso + index)); }
0169
0170
0171
0172 void setTrackIso(float trackIso) { setIsolation(pat::TrackIso, trackIso); }
0173
0174 void setEcalIso(float caloIso) { setIsolation(pat::EcalIso, caloIso); }
0175
0176 void setHcalIso(float caloIso) { setIsolation(pat::HcalIso, caloIso); }
0177
0178 void setUserIso(float value, uint8_t index = 0) { setIsolation(IsolationKeys(UserBaseIso + index), value); }
0179
0180
0181
0182 const IsoDeposit *isoDeposit(IsolationKeys key) const {
0183 for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end(); it != ed; ++it) {
0184 if (it->first == key)
0185 return &it->second;
0186 }
0187 return nullptr;
0188 }
0189
0190
0191 void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep) {
0192 IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
0193 for (; it != ed; ++it) {
0194 if (it->first == key) {
0195 it->second = dep;
0196 return;
0197 }
0198 }
0199 isoDeposits_.push_back(std::make_pair(key, dep));
0200 }
0201
0202
0203 const IsoDeposit *trackIsoDeposit() const { return isoDeposit(pat::TrackIso); }
0204 const IsoDeposit *ecalIsoDeposit() const { return isoDeposit(pat::EcalIso); }
0205 const IsoDeposit *hcalIsoDeposit() const { return isoDeposit(pat::HcalIso); }
0206 const IsoDeposit *userIsoDeposit(uint8_t index = 0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
0207
0208
0209 void trackIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::TrackIso, dep); }
0210 void ecalIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::EcalIso, dep); }
0211 void hcalIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::HcalIso, dep); }
0212 void userIsoDeposit(const IsoDeposit &dep, uint8_t index = 0) {
0213 setIsoDeposit(IsolationKeys(UserBaseIso + index), dep);
0214 }
0215
0216 const PFIsolation &miniPFIsolation() const { return miniPFIsolation_; }
0217 void setMiniPFIsolation(PFIsolation const &iso) { miniPFIsolation_ = iso; }
0218
0219 protected:
0220
0221 typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
0222 IsoDepositPairs isoDeposits_;
0223 std::vector<float> isolations_;
0224
0225 PFIsolation miniPFIsolation_;
0226 };
0227
0228
0229 template <class LeptonType>
0230 Lepton<LeptonType>::Lepton() : PATObject<LeptonType>(LeptonType()) {
0231
0232 this->setCharge(0);
0233 this->setP4(reco::Particle::LorentzVector(0, 0, 0, 0));
0234 this->setVertex(reco::Particle::Point(0, 0, 0));
0235 this->setMiniPFIsolation(pat::PFIsolation());
0236 }
0237
0238
0239 template <class LeptonType>
0240 Lepton<LeptonType>::Lepton(const LeptonType &aLepton) : PATObject<LeptonType>(aLepton) {
0241 this->setMiniPFIsolation(pat::PFIsolation());
0242 }
0243
0244
0245 template <class LeptonType>
0246 Lepton<LeptonType>::Lepton(const edm::RefToBase<LeptonType> &aLeptonRef) : PATObject<LeptonType>(aLeptonRef) {
0247 this->setMiniPFIsolation(pat::PFIsolation());
0248 }
0249
0250
0251 template <class LeptonType>
0252 Lepton<LeptonType>::Lepton(const edm::Ptr<LeptonType> &aLeptonRef) : PATObject<LeptonType>(aLeptonRef) {
0253 this->setMiniPFIsolation(pat::PFIsolation());
0254 }
0255
0256
0257 template <class LeptonType>
0258 Lepton<LeptonType>::~Lepton() {}
0259 }
0260
0261 #endif