CMS 3D CMS Logo

GenericParticle.h

Go to the documentation of this file.
00001 //
00002 // $Id: GenericParticle.h,v 1.5 2008/10/08 11:44:31 fronga Exp $
00003 //
00004 
00005 #ifndef DataFormats_PatCandidates_GenericParticle_h
00006 #define DataFormats_PatCandidates_GenericParticle_h
00007 
00019 #include "DataFormats/PatCandidates/interface/PATObject.h"
00020 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00021 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00022 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00023 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
00024 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00025 #include "DataFormats/PatCandidates/interface/Isolation.h"
00026 #include "DataFormats/PatCandidates/interface/Vertexing.h"
00027 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00028 
00029 // Define typedefs for convenience
00030 namespace pat {
00031   class GenericParticle;
00032   typedef std::vector<GenericParticle>              GenericParticleCollection; 
00033   typedef edm::Ref<GenericParticleCollection>       GenericParticleRef; 
00034   typedef edm::RefVector<GenericParticleCollection> GenericParticleRefVector; 
00035 }
00036 
00037 
00038 // Class definition
00039 namespace pat {
00040 
00041 
00042   class GenericParticle : public PATObject<reco::RecoCandidate> {
00043 
00044     public:
00045 
00047       GenericParticle();
00049       GenericParticle(const reco::Candidate & aGenericParticle);
00051       GenericParticle(const edm::RefToBase<reco::Candidate> & aGenericParticleRef);
00053       GenericParticle(const edm::Ptr<reco::Candidate> & aGenericParticleRef);
00055       virtual ~GenericParticle();
00056 
00057       virtual GenericParticle * clone() const { return new GenericParticle(*this); }
00058 
00063       virtual bool overlap( const Candidate & ) const ;
00064 
00067       virtual reco::TrackRef track() const    { return track_.empty() ? trackRef_ : reco::TrackRef(&track_, 0); }
00070       virtual reco::TrackRef track( size_t idx ) const {  
00071             if (idx >= numberOfTracks()) throw cms::Exception("Index out of bounds") << "Requested track " << idx << " out of " << numberOfTracks() << ".\n";
00072             return (tracks_.empty() ? trackRefs_[idx] : reco::TrackRef(&tracks_, idx) );
00073       }
00075       virtual size_t numberOfTracks() const { return tracks_.empty() ? trackRefs_.size() : tracks_.size(); }
00078       virtual reco::GsfTrackRef gsfTrack() const    { return (gsfTrack_.empty() ? gsfTrackRef_ : reco::GsfTrackRef(&gsfTrack_, 0)); }
00081       virtual reco::TrackRef standAloneMuon() const { return (standaloneTrack_.empty() ? standaloneTrackRef_ : reco::TrackRef(&standaloneTrack_, 0)); }
00084       virtual reco::TrackRef combinedMuon()   const { return (combinedTrack_.empty() ? combinedTrackRef_ : reco::TrackRef(&combinedTrack_, 0)); }
00087       virtual reco::SuperClusterRef superCluster() const { return superCluster_.empty() ? superClusterRef_ : reco::SuperClusterRef(&superCluster_, 0); }
00090       virtual CaloTowerRef caloTower() const { return caloTower_.empty() ? caloTowerRef_ : CaloTowerRef(&caloTower_, 0); }
00091 
00093       virtual void setTrack(const reco::TrackRef &ref, bool embed=false) ;
00095       virtual void setTracks(const reco::TrackRefVector &refs, bool embed=false) ;
00097       virtual void setStandAloneMuon(const reco::TrackRef &ref, bool embed=false) ;
00099       virtual void setCombinedMuon(const reco::TrackRef &ref, bool embed=false) ;
00101       virtual void setGsfTrack(const reco::GsfTrackRef &ref, bool embed=false) ;
00103       virtual void setSuperCluster(const reco::SuperClusterRef &ref, bool embed=false) ;
00105       virtual void setCaloTower(const CaloTowerRef &ref, bool embed=false) ;
00106 
00108       void embedTrack() ; 
00110       void embedTracks() ; 
00112       void embedStandalone() ; 
00114       void embedCombined() ; 
00116       void embedGsfTrack() ; 
00118       void embedSuperCluster() ; 
00120       void embedCaloTower() ; 
00121 
00123       float quality() { return quality_; }
00125       void setQuality(float quality) { quality_ = quality; }
00126       
00127       //============ BEGIN ISOLATION BLOCK =====
00129       float isolation(IsolationKeys key) const { 
00130           if (key >= 0) {
00131               //if (key >= isolations_.size()) throw cms::Excepton("Missing Data") << "Isolation corresponding to key " << key << " was not stored for this particle.";
00132               if (size_t(key) >= isolations_.size()) return -1.0;
00133               return isolations_[key];
00134           } else switch (key) {
00135               case CaloIso:  
00136                   //if (isolations_.size() <= HCalIso) throw cms::Excepton("Missing Data") << "CalIsoo Isolation was not stored for this particle.";
00137                   if (isolations_.size() <= HCalIso) return -1.0; 
00138                   return isolations_[ECalIso] + isolations_[HCalIso];
00139               default:
00140                   return -1.0;
00141                   //throw cms::Excepton("Missing Data") << "Isolation corresponding to key " << key << " was not stored for this particle.";
00142           }
00143       }
00144 
00147       void setIsolation(IsolationKeys key, float value) {
00148           if (key >= 0) {
00149               if (size_t(key) >= isolations_.size()) isolations_.resize(key+1, -1.0);
00150               isolations_[key] = value;
00151           } else {
00152               throw cms::Exception("Illegal Argument") << 
00153                   "The key for which you're setting isolation does not correspond " <<
00154                   "to an individual isolation but to the sum of more independent isolations " <<
00155                   "(e.g. Calo = ECal + HCal), so you can't SET the value, just GET it.\n" <<
00156                   "Please set up each component independly.\n";
00157           }
00158       }
00159 
00160       // ---- specific getters ----
00162       float trackIso() const { return isolation(TrackerIso); }
00164       float caloIso()  const { return isolation(CaloIso); }
00166       float ecalIso()  const { return isolation(ECalIso); }
00168       float hcalIso()  const { return isolation(HCalIso); }
00170       float userIso(uint8_t index=0)  const { return isolation(IsolationKeys(UserBaseIso + index)); }
00171 
00172       // ---- specific setters ----
00174       void setTrackIso(float trackIso) { setIsolation(TrackerIso, trackIso); }
00176       void setECalIso(float caloIso)   { setIsolation(ECalIso, caloIso);  } 
00178       void setHCalIso(float caloIso)   { setIsolation(HCalIso, caloIso);  }
00180       void setUserIso(float value, uint8_t index=0)  { setIsolation(IsolationKeys(UserBaseIso + index), value); }
00181 
00182 
00183       //============ BEGIN ISODEPOSIT BLOCK =====
00185       const IsoDeposit * isoDeposit(IsolationKeys key) const {
00186           for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end(); 
00187                   it != ed; ++it) 
00188           {
00189               if (it->first == key) return & it->second;
00190           }
00191           return 0;
00192       } 
00193 
00195       void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep) {
00196           IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
00197           for (; it != ed; ++it) {
00198               if (it->first == key) { it->second = dep; return; }
00199           }
00200           isoDeposits_.push_back(std::make_pair(key,dep));
00201       } 
00202 
00203       // ---- specific getters ----
00204       const IsoDeposit * trackerIsoDeposit() const { return isoDeposit(TrackerIso); }
00205       const IsoDeposit * ecalIsoDeposit()    const { return isoDeposit(ECalIso); }
00206       const IsoDeposit * hcalIsoDeposit()    const { return isoDeposit(HCalIso); }
00207       const IsoDeposit * userIsoDeposit(uint8_t index=0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
00208 
00209       // ---- specific setters ----
00210       void trackerIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(TrackerIso, dep); }
00211       void ecalIsoDeposit(const IsoDeposit &dep)    { setIsoDeposit(ECalIso, dep); }
00212       void hcalIsoDeposit(const IsoDeposit &dep)    { setIsoDeposit(HCalIso, dep); }
00213       void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0) { setIsoDeposit(IsolationKeys(UserBaseIso + index), dep); }
00214 
00216       const pat::VertexAssociation              * vertexAssociation(size_t index=0) const { return vtxAss_.size() > index ? & vtxAss_[index] : 0; }
00218       const std::vector<pat::VertexAssociation> & vertexAssociations()              const { return vtxAss_; }
00220       void  setVertexAssociation(const pat::VertexAssociation &assoc)  { vtxAss_ = std::vector<pat::VertexAssociation>(1, assoc); }
00222       void  setVertexAssociations(const std::vector<pat::VertexAssociation> &assocs) { vtxAss_ = assocs; }
00223     protected:
00224       // Any sort of single tracks
00225       reco::TrackRef           trackRef_, standaloneTrackRef_, combinedTrackRef_; // ref
00226       reco::TrackCollection    track_,    standaloneTrack_,    combinedTrack_;    // embedded
00227 
00228       // GsfTrack
00229       reco::GsfTrackRef        gsfTrackRef_; // normal
00230       reco::GsfTrackCollection gsfTrack_;    // embedded
00231 
00232       // CaloTower
00233       CaloTowerRef           caloTowerRef_;    // ref
00234       CaloTowerCollection    caloTower_;       // embedded
00235 
00236       // SuperCluster
00237       reco::SuperClusterRef        superClusterRef_; // ref
00238       reco::SuperClusterCollection superCluster_;    // embedded
00239 
00240       // Multiple tracks
00241       reco::TrackRefVector  trackRefs_; // by ref
00242       reco::TrackCollection tracks_;    // embedded
00243 
00244       // information originally in external branches
00245       // some quality variable
00246       float quality_;
00247 
00248       // --- Isolation and IsoDeposit related datamebers ---
00249       typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
00250       IsoDepositPairs    isoDeposits_;
00251       std::vector<float> isolations_;
00252 
00253       // --- Vertexing information
00254       std::vector<pat::VertexAssociation> vtxAss_;
00255 
00256       void fillInFrom(const reco::Candidate &cand); 
00257     
00258   };
00259 
00260 
00261 }
00262 
00263 #endif

Generated on Tue Jun 9 17:31:24 2009 for CMSSW by  doxygen 1.5.4