CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/PatCandidates/interface/Lepton.h

Go to the documentation of this file.
00001 //
00002 // $Id: Lepton.h,v 1.23 2010/03/02 21:01:48 rwolf Exp $
00003 //
00004 
00005 #ifndef DataFormats_PatCandidates_Lepton_h
00006 #define DataFormats_PatCandidates_Lepton_h
00007 
00023 #include "DataFormats/Candidate/interface/Particle.h"
00024 #include "DataFormats/PatCandidates/interface/PATObject.h"
00025 #include "DataFormats/PatCandidates/interface/Isolation.h"
00026 
00027 
00028 namespace pat {
00029 
00030 
00031   template <class LeptonType>
00032   class Lepton : public PATObject<LeptonType> {
00033 
00034     public:
00035 
00036       Lepton();
00037       Lepton(const LeptonType & aLepton);
00038       Lepton(const edm::RefToBase<LeptonType> & aLeptonRef);
00039       Lepton(const edm::Ptr<LeptonType> & aLeptonRef);
00040       virtual ~Lepton();
00041 
00042       virtual Lepton<LeptonType> * clone() const { return new Lepton<LeptonType>(*this); }
00043 
00044       const reco::GenParticle * genLepton() const { return PATObject<LeptonType>::genParticle(); }
00045 
00046       void setGenLepton(const reco::GenParticleRef & gl, bool embed=false) { PATObject<LeptonType>::setGenParticleRef(gl, embed); }
00047 
00048       //============ BEGIN ISOLATION BLOCK =====      
00051       float userIsolation(IsolationKeys key) const { 
00052           if (key >= 0) {
00053             //if (key >= isolations_.size()) throw cms::Excepton("Missing Data") 
00054             //<< "Isolation corresponding to key " 
00055             //<< key << " was not stored for this particle.";
00056               if (size_t(key) >= isolations_.size()) return -1.0;
00057               return isolations_[key];
00058           } else switch (key) {
00059           case pat::CaloIso:  
00060             //if (isolations_.size() <= pat::HcalIso) throw cms::Excepton("Missing Data") 
00061             //<< "CaloIso Isolation was not stored for this particle.";
00062             if (isolations_.size() <= pat::HcalIso) return -1.0; 
00063             return isolations_[pat::EcalIso] + isolations_[pat::HcalIso];
00064           default:
00065             return -1.0;
00066             //throw cms::Excepton("Missing Data") << "Isolation corresponding to key " 
00067             //<< key << " was not stored for this particle.";
00068           }
00069       }
00074       float userIsolation(const std::string& key) const {
00075         // remove leading namespace specifier
00076         std::string prunedKey = ( key.find("pat::") == 0 ) ? std::string(key, 5) : key;
00077         if ( prunedKey == "TrackIso" ) return userIsolation(pat::TrackIso);
00078         if ( prunedKey == "EcalIso" ) return userIsolation(pat::EcalIso);
00079         if ( prunedKey == "HcalIso" ) return userIsolation(pat::HcalIso);
00080         if ( prunedKey == "PfAllParticleIso" ) return userIsolation(pat::PfAllParticleIso);
00081         if ( prunedKey == "PfChargedHadronIso" ) return userIsolation(pat::PfChargedHadronIso);
00082         if ( prunedKey == "PfNeutralHadronIso" ) return userIsolation(pat::PfNeutralHadronIso);
00083         if ( prunedKey == "PfGammaIso" ) return userIsolation(pat::PfGammaIso);
00084         if ( prunedKey == "User1Iso" ) return userIsolation(pat::User1Iso);
00085         if ( prunedKey == "User2Iso" ) return userIsolation(pat::User2Iso);
00086         if ( prunedKey == "User3Iso" ) return userIsolation(pat::User3Iso);
00087         if ( prunedKey == "User4Iso" ) return userIsolation(pat::User4Iso);
00088         if ( prunedKey == "User5Iso" ) return userIsolation(pat::User5Iso);
00089         if ( prunedKey == "UserBaseIso" ) return userIsolation(pat::UserBaseIso);
00090         if ( prunedKey == "CaloIso" ) return userIsolation(pat::CaloIso);
00091         //throw cms::Excepton("Missing Data")
00092         //<< "Isolation corresponding to key " 
00093         //<< key << " was not stored for this particle.";
00094         return -1.0;
00095       }
00099       void setIsolation(IsolationKeys key, float value) {
00100           if (key >= 0) {
00101               if (size_t(key) >= isolations_.size()) isolations_.resize(key+1, -1.0);
00102               isolations_[key] = value;
00103           } else {
00104               throw cms::Exception("Illegal Argument") << 
00105                   "The key for which you're setting isolation does not correspond " <<
00106                   "to an individual isolation but to the sum of more independent isolations " <<
00107                   "(e.g. Calo = Ecal + Hcal), so you can't SET the value, just GET it.\n" <<
00108                   "Please set up each component independly.\n";
00109           }
00110       }
00111 
00112       // ---- specific getters ----
00117       float trackIso() const { return userIsolation(pat::TrackIso); }
00122       float caloIso()  const { return userIsolation(pat::CaloIso); }
00127       float ecalIso()  const { return userIsolation(pat::EcalIso); }
00132       float hcalIso()  const { return userIsolation(pat::HcalIso); }
00133 
00136       float particleIso() const { return userIsolation(pat::PfAllParticleIso); }
00139       float chargedHadronIso() const { return userIsolation(pat::PfChargedHadronIso); }
00142       float neutralHadronIso() const { return userIsolation(pat::PfNeutralHadronIso); } 
00145       float photonIso() const { return userIsolation(pat::PfGammaIso); }        
00148       float userIso(uint8_t index=0)  const { return userIsolation(IsolationKeys(UserBaseIso + index)); }
00149 
00150       // ---- specific setters ----
00152       void setTrackIso(float trackIso) { setIsolation(pat::TrackIso, trackIso); }
00154       void setEcalIso(float caloIso)   { setIsolation(pat::EcalIso, caloIso);  } 
00156       void setHcalIso(float caloIso)   { setIsolation(pat::HcalIso, caloIso);  }
00158       void setUserIso(float value, uint8_t index=0)  { setIsolation(IsolationKeys(UserBaseIso + index), value); }
00159 
00160 
00161       //============ BEGIN ISODEPOSIT BLOCK =====
00163       const IsoDeposit * isoDeposit(IsolationKeys key) const {
00164           for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end(); 
00165                   it != ed; ++it) 
00166           {
00167               if (it->first == key) return & it->second;
00168           }
00169           return 0;
00170       } 
00171 
00173       void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep) {
00174           IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
00175           for (; it != ed; ++it) {
00176               if (it->first == key) { it->second = dep; return; }
00177           }
00178           isoDeposits_.push_back(std::make_pair(key,dep));
00179       } 
00180 
00181       // ---- specific getters ----
00182       const IsoDeposit * trackIsoDeposit() const { return isoDeposit(pat::TrackIso); }
00183       const IsoDeposit * ecalIsoDeposit()  const { return isoDeposit(pat::EcalIso ); }
00184       const IsoDeposit * hcalIsoDeposit()  const { return isoDeposit(pat::HcalIso ); }
00185       const IsoDeposit * userIsoDeposit(uint8_t index=0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
00186 
00187       // ---- specific setters ----
00188       void trackIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::TrackIso,dep); }
00189       void ecalIsoDeposit(const IsoDeposit &dep)  { setIsoDeposit(pat::EcalIso, dep); }
00190       void hcalIsoDeposit(const IsoDeposit &dep)  { setIsoDeposit(pat::HcalIso, dep); }
00191       void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0) { setIsoDeposit(IsolationKeys(UserBaseIso + index), dep); }
00192 
00193 
00194     protected:
00195       // --- Isolation and IsoDeposit related datamebers ---
00196       typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
00197       IsoDepositPairs    isoDeposits_;
00198       std::vector<float> isolations_;
00199   };
00200 
00201 
00203   template <class LeptonType>
00204   Lepton<LeptonType>::Lepton() :
00205     PATObject<LeptonType>(LeptonType()) {
00206     // no common constructor, so initialize the candidate manually
00207     this->setCharge(0);
00208     this->setP4(reco::Particle::LorentzVector(0, 0, 0, 0));
00209     this->setVertex(reco::Particle::Point(0, 0, 0));
00210   }
00211 
00212 
00214   template <class LeptonType>
00215   Lepton<LeptonType>::Lepton(const LeptonType & aLepton) :
00216     PATObject<LeptonType>(aLepton) {
00217   }
00218 
00219 
00221   template <class LeptonType>
00222   Lepton<LeptonType>::Lepton(const edm::RefToBase<LeptonType> & aLeptonRef) :
00223     PATObject<LeptonType>(aLeptonRef) {
00224   }
00225 
00226 
00228   template <class LeptonType>
00229   Lepton<LeptonType>::Lepton(const edm::Ptr<LeptonType> & aLeptonRef) :
00230     PATObject<LeptonType>(aLeptonRef) {
00231   }
00232 
00233 
00235   template <class LeptonType>
00236   Lepton<LeptonType>::~Lepton() {
00237   }
00238 }
00239 
00240 #endif