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.24 2011/09/29 05:19:08 cbern 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  if ( prunedKey == "PfPUChargedHadronIso" ) return userIsolation(pat::PfPUChargedHadronIso);
92  //throw cms::Excepton("Missing Data")
93  //<< "Isolation corresponding to key "
94  //<< key << " was not stored for this particle.";
95  return -1.0;
96  }
101  if (key >= 0) {
102  if (size_t(key) >= isolations_.size()) isolations_.resize(key+1, -1.0);
103  isolations_[key] = value;
104  } else {
105  throw cms::Exception("Illegal Argument") <<
106  "The key for which you're setting isolation does not correspond " <<
107  "to an individual isolation but to the sum of more independent isolations " <<
108  "(e.g. Calo = Ecal + Hcal), so you can't SET the value, just GET it.\n" <<
109  "Please set up each component independly.\n";
110  }
111  }
112 
113  // ---- specific getters ----
118  float trackIso() const { return userIsolation(pat::TrackIso); }
123  float caloIso() const { return userIsolation(pat::CaloIso); }
128  float ecalIso() const { return userIsolation(pat::EcalIso); }
133  float hcalIso() const { return userIsolation(pat::HcalIso); }
134 
146  float photonIso() const { return userIsolation(pat::PfGammaIso); }
152  float userIso(uint8_t index=0) const { return userIsolation(IsolationKeys(UserBaseIso + index)); }
153 
154  // ---- specific setters ----
156  void setTrackIso(float trackIso) { setIsolation(pat::TrackIso, trackIso); }
158  void setEcalIso(float caloIso) { setIsolation(pat::EcalIso, caloIso); }
160  void setHcalIso(float caloIso) { setIsolation(pat::HcalIso, caloIso); }
162  void setUserIso(float value, uint8_t index=0) { setIsolation(IsolationKeys(UserBaseIso + index), value); }
163 
164 
165  //============ BEGIN ISODEPOSIT BLOCK =====
168  for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
169  it != ed; ++it)
170  {
171  if (it->first == key) return & it->second;
172  }
173  return 0;
174  }
175 
178  IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
179  for (; it != ed; ++it) {
180  if (it->first == key) { it->second = dep; return; }
181  }
182  isoDeposits_.push_back(std::make_pair(key,dep));
183  }
184 
185  // ---- specific getters ----
186  const IsoDeposit * trackIsoDeposit() const { return isoDeposit(pat::TrackIso); }
187  const IsoDeposit * ecalIsoDeposit() const { return isoDeposit(pat::EcalIso ); }
188  const IsoDeposit * hcalIsoDeposit() const { return isoDeposit(pat::HcalIso ); }
189  const IsoDeposit * userIsoDeposit(uint8_t index=0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
190 
191  // ---- specific setters ----
195  void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0) { setIsoDeposit(IsolationKeys(UserBaseIso + index), dep); }
196 
197 
198  protected:
199  // --- Isolation and IsoDeposit related datamebers ---
200  typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
202  std::vector<float> isolations_;
203  };
204 
205 
207  template <class LeptonType>
210  // no common constructor, so initialize the candidate manually
211  this->setCharge(0);
212  this->setP4(reco::Particle::LorentzVector(0, 0, 0, 0));
213  this->setVertex(reco::Particle::Point(0, 0, 0));
214  }
215 
216 
218  template <class LeptonType>
220  PATObject<LeptonType>(aLepton) {
221  }
222 
223 
225  template <class LeptonType>
227  PATObject<LeptonType>(aLeptonRef) {
228  }
229 
230 
232  template <class LeptonType>
234  PATObject<LeptonType>(aLeptonRef) {
235  }
236 
237 
239  template <class LeptonType>
241  }
242 }
243 
244 #endif
void ecalIsoDeposit(const IsoDeposit &dep)
Definition: Lepton.h:193
float ecalIso() const
Definition: Lepton.h:128
const IsoDeposit * trackIsoDeposit() const
Definition: Lepton.h:186
const reco::GenParticle * genLepton() const
Definition: Lepton.h:44
void setIsolation(IsolationKeys key, float value)
Definition: Lepton.h:100
void trackIsoDeposit(const IsoDeposit &dep)
Definition: Lepton.h:192
std::vector< std::pair< IsolationKeys, pat::IsoDeposit > > IsoDepositPairs
Definition: Lepton.h:200
const reco::GenParticle * genParticle(size_t idx=0) const
Definition: PATObject.h:234
const IsoDeposit * hcalIsoDeposit() const
Definition: Lepton.h:188
float userIso(uint8_t index=0) const
Definition: Lepton.h:152
void hcalIsoDeposit(const IsoDeposit &dep)
Definition: Lepton.h:194
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:167
void setGenParticleRef(const reco::GenParticleRef &ref, bool embed=false)
Set the generator level particle reference.
Definition: PATObject.h:652
#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:177
float particleIso() const
Definition: Lepton.h:137
float neutralHadronIso() const
Definition: Lepton.h:143
Lepton()
default constructor
Definition: Lepton.h:208
float puChargedHadronIso() const
Definition: Lepton.h:149
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:162
Analysis-level lepton class.
Definition: Lepton.h:32
math::XYZPoint Point
point in the space
Definition: Particle.h:29
virtual Lepton< LeptonType > * clone() const
Definition: Lepton.h:42
virtual ~Lepton()
destructor
Definition: Lepton.h:240
const IsoDeposit * ecalIsoDeposit() const
Definition: Lepton.h:187
float trackIso() const
Definition: Lepton.h:118
IsoDepositPairs isoDeposits_
Definition: Lepton.h:201
float userIsolation(const std::string &key) const
Definition: Lepton.h:74
unsigned int index
index type
Definition: Candidate.h:55
float userIsolation(IsolationKeys key) const
Definition: Lepton.h:51
std::vector< float > isolations_
Definition: Lepton.h:202
float photonIso() const
Definition: Lepton.h:146
float caloIso() const
Definition: Lepton.h:123
list key
Definition: combine.py:13
void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0)
Definition: Lepton.h:195
float hcalIso() const
Definition: Lepton.h:133
void setTrackIso(float trackIso)
Sets tracker isolation variable.
Definition: Lepton.h:156
Templated PAT object container.
Definition: PATObject.h:43
void setEcalIso(float caloIso)
Sets ecal isolation variable.
Definition: Lepton.h:158
void setHcalIso(float caloIso)
Sets hcal isolation variable.
Definition: Lepton.h:160
float chargedHadronIso() const
Definition: Lepton.h:140
const IsoDeposit * userIsoDeposit(uint8_t index=0) const
Definition: Lepton.h:189
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25