CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Lepton.h
Go to the documentation of this file.
1 //
2 // $Id: Lepton.h,v 1.22 2010/02/22 11:10:00 veelken Exp $
3 //
4 
5 #ifndef DataFormats_PatCandidates_Lepton_h
6 #define DataFormats_PatCandidates_Lepton_h
7 
26 
27 
28 namespace pat {
29 
30 
31  template <class LeptonType>
32  class Lepton : public PATObject<LeptonType> {
33 
34  public:
35 
36  Lepton();
37  Lepton(const LeptonType & aLepton);
38  Lepton(const edm::RefToBase<LeptonType> & aLeptonRef);
39  Lepton(const edm::Ptr<LeptonType> & aLeptonRef);
40  virtual ~Lepton();
41 
42  virtual Lepton<LeptonType> * clone() const { return new Lepton<LeptonType>(*this); }
43 
45 
47 
48  //============ BEGIN ISOLATION BLOCK =====
52  if (key >= 0) {
53  //if (key >= isolations_.size()) throw cms::Excepton("Missing Data")
54  //<< "Isolation corresponding to key "
55  //<< key << " was not stored for this particle.";
56  if (size_t(key) >= isolations_.size()) return -1.0;
57  return isolations_[key];
58  } else switch (key) {
59  case pat::CaloIso:
60  //if (isolations_.size() <= pat::HcalIso) throw cms::Excepton("Missing Data")
61  //<< "CaloIso Isolation was not stored for this particle.";
62  if (isolations_.size() <= pat::HcalIso) return -1.0;
64  default:
65  return -1.0;
66  //throw cms::Excepton("Missing Data") << "Isolation corresponding to key "
67  //<< key << " was not stored for this particle.";
68  }
69  }
74  float userIsolation(const std::string& key) const {
75  // remove leading namespace specifier
76  std::string prunedKey = ( key.find("pat::") == 0 ) ? std::string(key, 5) : key;
77  if ( prunedKey == "TrackIso" ) return userIsolation(pat::TrackIso);
78  if ( prunedKey == "EcalIso" ) return userIsolation(pat::EcalIso);
79  if ( prunedKey == "HcalIso" ) return userIsolation(pat::HcalIso);
80  if ( prunedKey == "PfAllParticleIso" ) return userIsolation(pat::PfAllParticleIso);
81  if ( prunedKey == "PfChargedHadronIso" ) return userIsolation(pat::PfChargedHadronIso);
82  if ( prunedKey == "PfNeutralHadronIso" ) return userIsolation(pat::PfNeutralHadronIso);
83  if ( prunedKey == "PfGammaIso" ) return userIsolation(pat::PfGammaIso);
84  if ( prunedKey == "User1Iso" ) return userIsolation(pat::User1Iso);
85  if ( prunedKey == "User2Iso" ) return userIsolation(pat::User2Iso);
86  if ( prunedKey == "User3Iso" ) return userIsolation(pat::User3Iso);
87  if ( prunedKey == "User4Iso" ) return userIsolation(pat::User4Iso);
88  if ( prunedKey == "User5Iso" ) return userIsolation(pat::User5Iso);
89  if ( prunedKey == "UserBaseIso" ) return userIsolation(pat::UserBaseIso);
90  if ( prunedKey == "CaloIso" ) return userIsolation(pat::CaloIso);
91  //throw cms::Excepton("Missing Data")
92  //<< "Isolation corresponding to key "
93  //<< key << " was not stored for this particle.";
94  return -1.0;
95  }
100  if (key >= 0) {
101  if (size_t(key) >= isolations_.size()) isolations_.resize(key+1, -1.0);
102  isolations_[key] = value;
103  } else {
104  throw cms::Exception("Illegal Argument") <<
105  "The key for which you're setting isolation does not correspond " <<
106  "to an individual isolation but to the sum of more independent isolations " <<
107  "(e.g. Calo = Ecal + Hcal), so you can't SET the value, just GET it.\n" <<
108  "Please set up each component independly.\n";
109  }
110  }
111 
112  // ---- specific getters ----
117  float trackIso() const { return userIsolation(pat::TrackIso); }
122  float caloIso() const { return userIsolation(pat::CaloIso); }
127  float ecalIso() const { return userIsolation(pat::EcalIso); }
132  float hcalIso() const { return userIsolation(pat::HcalIso); }
133 
145  float photonIso() const { return userIsolation(pat::PfGammaIso); }
148  float userIso(uint8_t index=0) const { return userIsolation(IsolationKeys(UserBaseIso + index)); }
149 
150  // ---- specific setters ----
152  void setTrackIso(float trackIso) { setIsolation(pat::TrackIso, trackIso); }
154  void setEcalIso(float caloIso) { setIsolation(pat::EcalIso, caloIso); }
156  void setHcalIso(float caloIso) { setIsolation(pat::HcalIso, caloIso); }
158  void setUserIso(float value, uint8_t index=0) { setIsolation(IsolationKeys(UserBaseIso + index), value); }
159 
160 
161  //============ BEGIN ISODEPOSIT BLOCK =====
164  for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
165  it != ed; ++it)
166  {
167  if (it->first == key) return & it->second;
168  }
169  return 0;
170  }
171 
174  IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
175  for (; it != ed; ++it) {
176  if (it->first == key) { it->second = dep; return; }
177  }
178  isoDeposits_.push_back(std::make_pair(key,dep));
179  }
180 
181  // ---- specific getters ----
182  const IsoDeposit * trackIsoDeposit() const { return isoDeposit(pat::TrackIso); }
183  const IsoDeposit * ecalIsoDeposit() const { return isoDeposit(pat::EcalIso ); }
184  const IsoDeposit * hcalIsoDeposit() const { return isoDeposit(pat::HcalIso ); }
185  const IsoDeposit * userIsoDeposit(uint8_t index=0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
186 
187  // ---- specific setters ----
191  void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0) { setIsoDeposit(IsolationKeys(UserBaseIso + index), dep); }
192 
193 
194  protected:
195  // --- Isolation and IsoDeposit related datamebers ---
196  typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
198  std::vector<float> isolations_;
199  };
200 
201 
203  template <class LeptonType>
206  // no common constructor, so initialize the candidate manually
207  this->setCharge(0);
208  this->setP4(reco::Particle::LorentzVector(0, 0, 0, 0));
209  this->setVertex(reco::Particle::Point(0, 0, 0));
210  }
211 
212 
214  template <class LeptonType>
216  PATObject<LeptonType>(aLepton) {
217  }
218 
219 
221  template <class LeptonType>
223  PATObject<LeptonType>(aLeptonRef) {
224  }
225 
226 
228  template <class LeptonType>
230  PATObject<LeptonType>(aLeptonRef) {
231  }
232 
233 
235  template <class LeptonType>
237  }
238 }
239 
240 #endif
void ecalIsoDeposit(const IsoDeposit &dep)
Definition: Lepton.h:189
float ecalIso() const
Definition: Lepton.h:127
const IsoDeposit * trackIsoDeposit() const
Definition: Lepton.h:182
const reco::GenParticle * genLepton() const
Definition: Lepton.h:44
void setIsolation(IsolationKeys key, float value)
Definition: Lepton.h:99
void trackIsoDeposit(const IsoDeposit &dep)
Definition: Lepton.h:188
std::vector< std::pair< IsolationKeys, pat::IsoDeposit > > IsoDepositPairs
Definition: Lepton.h:196
const reco::GenParticle * genParticle(size_t idx=0) const
Definition: PATObject.h:234
const IsoDeposit * hcalIsoDeposit() const
Definition: Lepton.h:184
float userIso(uint8_t index=0) const
Definition: Lepton.h:148
void hcalIsoDeposit(const IsoDeposit &dep)
Definition: Lepton.h:190
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
const IsoDeposit * isoDeposit(IsolationKeys key) const
Returns the IsoDeposit associated with some key, or a null pointer if it is not available.
Definition: Lepton.h:163
void setGenParticleRef(const reco::GenParticleRef &ref, bool embed=false)
Set the generator level particle reference.
Definition: PATObject.h:646
#define embed
Definition: AMPTWrapper.h:178
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
Definition: Lepton.h:173
float particleIso() const
Definition: Lepton.h:136
float neutralHadronIso() const
Definition: Lepton.h:142
Lepton()
default constructor
Definition: Lepton.h:204
void setGenLepton(const reco::GenParticleRef &gl, bool embed=false)
Definition: Lepton.h:46
void setUserIso(float value, uint8_t index=0)
Sets user isolation variable #index.
Definition: Lepton.h:158
Analysis-level lepton class.
Definition: Lepton.h:32
math::XYZPoint Point
point in the space
Definition: Particle.h:30
virtual Lepton< LeptonType > * clone() const
Definition: Lepton.h:42
virtual ~Lepton()
destructor
Definition: Lepton.h:236
const IsoDeposit * ecalIsoDeposit() const
Definition: Lepton.h:183
float trackIso() const
Definition: Lepton.h:117
IsoDepositPairs isoDeposits_
Definition: Lepton.h:197
float userIsolation(const std::string &key) const
Definition: Lepton.h:74
unsigned int index
index type
Definition: Candidate.h:53
float userIsolation(IsolationKeys key) const
Definition: Lepton.h:51
std::vector< float > isolations_
Definition: Lepton.h:198
float photonIso() const
Definition: Lepton.h:145
float caloIso() const
Definition: Lepton.h:122
list key
Definition: combine.py:13
void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0)
Definition: Lepton.h:191
float hcalIso() const
Definition: Lepton.h:132
void setTrackIso(float trackIso)
Sets tracker isolation variable.
Definition: Lepton.h:152
Templated PAT object container.
Definition: PATObject.h:43
void setEcalIso(float caloIso)
Sets ecal isolation variable.
Definition: Lepton.h:154
void setHcalIso(float caloIso)
Sets hcal isolation variable.
Definition: Lepton.h:156
float chargedHadronIso() const
Definition: Lepton.h:139
const IsoDeposit * userIsoDeposit(uint8_t index=0) const
Definition: Lepton.h:185
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:26