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 //
3 
4 #ifndef DataFormats_PatCandidates_Lepton_h
5 #define DataFormats_PatCandidates_Lepton_h
6 
24 
25 
26 namespace pat {
27 
28 
29  template <class LeptonType>
30  class Lepton : public PATObject<LeptonType> {
31 
32  public:
33 
34  Lepton();
35  Lepton(const LeptonType & aLepton);
36  Lepton(const edm::RefToBase<LeptonType> & aLeptonRef);
37  Lepton(const edm::Ptr<LeptonType> & aLeptonRef);
38  virtual ~Lepton();
39 
40  virtual Lepton<LeptonType> * clone() const { return new Lepton<LeptonType>(*this); }
41 
43 
45 
46  //============ BEGIN ISOLATION BLOCK =====
50  if (key >= 0) {
51  //if (key >= isolations_.size()) throw cms::Excepton("Missing Data")
52  //<< "Isolation corresponding to key "
53  //<< key << " was not stored for this particle.";
54  if (size_t(key) >= isolations_.size()) return -1.0;
55  return isolations_[key];
56  } else switch (key) {
57  case pat::CaloIso:
58  //if (isolations_.size() <= pat::HcalIso) throw cms::Excepton("Missing Data")
59  //<< "CaloIso Isolation was not stored for this particle.";
60  if (isolations_.size() <= pat::HcalIso) return -1.0;
62  default:
63  return -1.0;
64  //throw cms::Excepton("Missing Data") << "Isolation corresponding to key "
65  //<< key << " was not stored for this particle.";
66  }
67  }
72  float userIsolation(const std::string& key) const {
73  // remove leading namespace specifier
74  std::string prunedKey = ( key.find("pat::") == 0 ) ? std::string(key, 5) : key;
75  if ( prunedKey == "TrackIso" ) return userIsolation(pat::TrackIso);
76  if ( prunedKey == "EcalIso" ) return userIsolation(pat::EcalIso);
77  if ( prunedKey == "HcalIso" ) return userIsolation(pat::HcalIso);
78  if ( prunedKey == "PfAllParticleIso" ) return userIsolation(pat::PfAllParticleIso);
79  if ( prunedKey == "PfChargedHadronIso" ) return userIsolation(pat::PfChargedHadronIso);
80  if ( prunedKey == "PfNeutralHadronIso" ) return userIsolation(pat::PfNeutralHadronIso);
81  if ( prunedKey == "PfGammaIso" ) return userIsolation(pat::PfGammaIso);
82  if ( prunedKey == "User1Iso" ) return userIsolation(pat::User1Iso);
83  if ( prunedKey == "User2Iso" ) return userIsolation(pat::User2Iso);
84  if ( prunedKey == "User3Iso" ) return userIsolation(pat::User3Iso);
85  if ( prunedKey == "User4Iso" ) return userIsolation(pat::User4Iso);
86  if ( prunedKey == "User5Iso" ) return userIsolation(pat::User5Iso);
87  if ( prunedKey == "UserBaseIso" ) return userIsolation(pat::UserBaseIso);
88  if ( prunedKey == "CaloIso" ) return userIsolation(pat::CaloIso);
89  if ( prunedKey == "PfPUChargedHadronIso" ) return userIsolation(pat::PfPUChargedHadronIso);
90  //throw cms::Excepton("Missing Data")
91  //<< "Isolation corresponding to key "
92  //<< key << " was not stored for this particle.";
93  return -1.0;
94  }
99  if (key >= 0) {
100  if (size_t(key) >= isolations_.size()) isolations_.resize(key+1, -1.0);
101  isolations_[key] = value;
102  } else {
103  throw cms::Exception("Illegal Argument") <<
104  "The key for which you're setting isolation does not correspond " <<
105  "to an individual isolation but to the sum of more independent isolations " <<
106  "(e.g. Calo = Ecal + Hcal), so you can't SET the value, just GET it.\n" <<
107  "Please set up each component independly.\n";
108  }
109  }
110 
111  // ---- specific getters ----
116  float trackIso() const { return userIsolation(pat::TrackIso); }
121  float caloIso() const { return userIsolation(pat::CaloIso); }
126  float ecalIso() const { return userIsolation(pat::EcalIso); }
131  float hcalIso() const { return userIsolation(pat::HcalIso); }
132 
144  float photonIso() const { return userIsolation(pat::PfGammaIso); }
150  float userIso(uint8_t index=0) const { return userIsolation(IsolationKeys(UserBaseIso + index)); }
151 
152  // ---- specific setters ----
154  void setTrackIso(float trackIso) { setIsolation(pat::TrackIso, trackIso); }
156  void setEcalIso(float caloIso) { setIsolation(pat::EcalIso, caloIso); }
158  void setHcalIso(float caloIso) { setIsolation(pat::HcalIso, caloIso); }
160  void setUserIso(float value, uint8_t index=0) { setIsolation(IsolationKeys(UserBaseIso + index), value); }
161 
162 
163  //============ BEGIN ISODEPOSIT BLOCK =====
166  for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
167  it != ed; ++it)
168  {
169  if (it->first == key) return & it->second;
170  }
171  return 0;
172  }
173 
176  IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
177  for (; it != ed; ++it) {
178  if (it->first == key) { it->second = dep; return; }
179  }
180  isoDeposits_.push_back(std::make_pair(key,dep));
181  }
182 
183  // ---- specific getters ----
184  const IsoDeposit * trackIsoDeposit() const { return isoDeposit(pat::TrackIso); }
185  const IsoDeposit * ecalIsoDeposit() const { return isoDeposit(pat::EcalIso ); }
186  const IsoDeposit * hcalIsoDeposit() const { return isoDeposit(pat::HcalIso ); }
187  const IsoDeposit * userIsoDeposit(uint8_t index=0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
188 
189  // ---- specific setters ----
193  void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0) { setIsoDeposit(IsolationKeys(UserBaseIso + index), dep); }
194 
195 
196  protected:
197  // --- Isolation and IsoDeposit related datamebers ---
198  typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
200  std::vector<float> isolations_;
201  };
202 
203 
205  template <class LeptonType>
208  // no common constructor, so initialize the candidate manually
209  this->setCharge(0);
210  this->setP4(reco::Particle::LorentzVector(0, 0, 0, 0));
211  this->setVertex(reco::Particle::Point(0, 0, 0));
212  }
213 
214 
216  template <class LeptonType>
218  PATObject<LeptonType>(aLepton) {
219  }
220 
221 
223  template <class LeptonType>
225  PATObject<LeptonType>(aLeptonRef) {
226  }
227 
228 
230  template <class LeptonType>
232  PATObject<LeptonType>(aLeptonRef) {
233  }
234 
235 
237  template <class LeptonType>
239  }
240 }
241 
242 #endif
void ecalIsoDeposit(const IsoDeposit &dep)
Definition: Lepton.h:191
float ecalIso() const
Definition: Lepton.h:126
const IsoDeposit * trackIsoDeposit() const
Definition: Lepton.h:184
const reco::GenParticle * genLepton() const
Definition: Lepton.h:42
void setIsolation(IsolationKeys key, float value)
Definition: Lepton.h:98
void trackIsoDeposit(const IsoDeposit &dep)
Definition: Lepton.h:190
std::vector< std::pair< IsolationKeys, pat::IsoDeposit > > IsoDepositPairs
Definition: Lepton.h:198
Lepton()
default constructor
Definition: Lepton.h:206
const reco::GenParticle * genParticle(size_t idx=0) const
Definition: PATObject.h:236
const IsoDeposit * hcalIsoDeposit() const
Definition: Lepton.h:186
float userIso(uint8_t index=0) const
Definition: Lepton.h:150
void hcalIsoDeposit(const IsoDeposit &dep)
Definition: Lepton.h:192
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:165
void setGenParticleRef(const reco::GenParticleRef &ref, bool embed=false)
Set the generator level particle reference.
Definition: PATObject.h:654
#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:175
float particleIso() const
Definition: Lepton.h:135
float neutralHadronIso() const
Definition: Lepton.h:141
float puChargedHadronIso() const
Definition: Lepton.h:147
void setGenLepton(const reco::GenParticleRef &gl, bool embed=false)
Definition: Lepton.h:44
void setUserIso(float value, uint8_t index=0)
Sets user isolation variable #index.
Definition: Lepton.h:160
Analysis-level lepton class.
Definition: Lepton.h:30
math::XYZPoint Point
point in the space
Definition: Particle.h:25
virtual Lepton< LeptonType > * clone() const
Definition: Lepton.h:40
const IsoDeposit * ecalIsoDeposit() const
Definition: Lepton.h:185
float trackIso() const
Definition: Lepton.h:116
IsoDepositPairs isoDeposits_
Definition: Lepton.h:199
float userIsolation(const std::string &key) const
Definition: Lepton.h:72
unsigned int index
index type
Definition: Candidate.h:51
float userIsolation(IsolationKeys key) const
Definition: Lepton.h:49
std::vector< float > isolations_
Definition: Lepton.h:200
float photonIso() const
Definition: Lepton.h:144
float caloIso() const
Definition: Lepton.h:121
void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0)
Definition: Lepton.h:193
float hcalIso() const
Definition: Lepton.h:131
void setTrackIso(float trackIso)
Sets tracker isolation variable.
Definition: Lepton.h:154
virtual ~Lepton()
destructor
Definition: Lepton.h:238
Templated PAT object container.
Definition: PATObject.h:41
void setEcalIso(float caloIso)
Sets ecal isolation variable.
Definition: Lepton.h:156
void setHcalIso(float caloIso)
Sets hcal isolation variable.
Definition: Lepton.h:158
float chargedHadronIso() const
Definition: Lepton.h:138
const IsoDeposit * userIsoDeposit(uint8_t index=0) const
Definition: Lepton.h:187
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21