Go to the documentation of this file.00001
00002
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
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
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
00058 virtual GenericParticle * clone() const { return new GenericParticle(*this); }
00059
00064 virtual bool overlap( const Candidate & ) const ;
00065
00068 virtual reco::TrackRef track() const { return track_.empty() ? trackRef_ : reco::TrackRef(&track_, 0); }
00071 virtual reco::TrackRef track( size_t idx ) const {
00072 if (idx >= numberOfTracks()) throw cms::Exception("Index out of bounds") << "Requested track " << idx << " out of " << numberOfTracks() << ".\n";
00073 return (tracks_.empty() ? trackRefs_[idx] : reco::TrackRef(&tracks_, idx) );
00074 }
00076 virtual size_t numberOfTracks() const { return tracks_.empty() ? trackRefs_.size() : tracks_.size(); }
00079 virtual reco::GsfTrackRef gsfTrack() const { return (gsfTrack_.empty() ? gsfTrackRef_ : reco::GsfTrackRef(&gsfTrack_, 0)); }
00082 virtual reco::TrackRef standAloneMuon() const { return (standaloneTrack_.empty() ? standaloneTrackRef_ : reco::TrackRef(&standaloneTrack_, 0)); }
00085 virtual reco::TrackRef combinedMuon() const { return (combinedTrack_.empty() ? combinedTrackRef_ : reco::TrackRef(&combinedTrack_, 0)); }
00088 virtual reco::SuperClusterRef superCluster() const { return superCluster_.empty() ? superClusterRef_ : reco::SuperClusterRef(&superCluster_, 0); }
00091 virtual CaloTowerRef caloTower() const { return caloTower_.empty() ? caloTowerRef_ : CaloTowerRef(&caloTower_, 0); }
00092
00094 virtual void setTrack(const reco::TrackRef &ref, bool embed=false) ;
00096 virtual void setTracks(const reco::TrackRefVector &refs, bool embed=false) ;
00098 virtual void setStandAloneMuon(const reco::TrackRef &ref, bool embed=false) ;
00100 virtual void setCombinedMuon(const reco::TrackRef &ref, bool embed=false) ;
00102 virtual void setGsfTrack(const reco::GsfTrackRef &ref, bool embed=false) ;
00104 virtual void setSuperCluster(const reco::SuperClusterRef &ref, bool embed=false) ;
00106 virtual void setCaloTower(const CaloTowerRef &ref, bool embed=false) ;
00107
00109 void embedTrack() ;
00111 void embedTracks() ;
00113 void embedStandalone() ;
00115 void embedCombined() ;
00117 void embedGsfTrack() ;
00119 void embedSuperCluster() ;
00121 void embedCaloTower() ;
00122
00124 float quality() { return quality_; }
00126 void setQuality(float quality) { quality_ = quality; }
00127
00128
00131 float userIsolation(IsolationKeys key) const {
00132 if (key >= 0) {
00133
00134
00135
00136 if (size_t(key) >= isolations_.size()) return -1.0;
00137 return isolations_[key];
00138 } else switch (key) {
00139 case pat::CaloIso:
00140
00141
00142 if (isolations_.size() <= pat::HcalIso) return -1.0;
00143 return isolations_[pat::EcalIso] + isolations_[pat::HcalIso];
00144 default:
00145 return -1.0;
00146
00147
00148 }
00149 }
00154 float userIsolation(const std::string& key) const {
00155
00156 std::string prunedKey = ( key.find("pat::") == 0 ) ? std::string(key, 5) : key;
00157 if ( prunedKey == "TrackIso" ) return userIsolation(pat::TrackIso);
00158 if ( prunedKey == "EcalIso" ) return userIsolation(pat::EcalIso);
00159 if ( prunedKey == "HcalIso" ) return userIsolation(pat::HcalIso);
00160 if ( prunedKey == "PfAllParticleIso" ) return userIsolation(pat::PfAllParticleIso);
00161 if ( prunedKey == "PfChargedHadronIso" ) return userIsolation(pat::PfChargedHadronIso);
00162 if ( prunedKey == "PfNeutralHadronIso" ) return userIsolation(pat::PfNeutralHadronIso);
00163 if ( prunedKey == "PfGammaIso" ) return userIsolation(pat::PfGammaIso);
00164 if ( prunedKey == "User1Iso" ) return userIsolation(pat::User1Iso);
00165 if ( prunedKey == "User2Iso" ) return userIsolation(pat::User2Iso);
00166 if ( prunedKey == "User3Iso" ) return userIsolation(pat::User3Iso);
00167 if ( prunedKey == "User4Iso" ) return userIsolation(pat::User4Iso);
00168 if ( prunedKey == "User5Iso" ) return userIsolation(pat::User5Iso);
00169 if ( prunedKey == "UserBaseIso" ) return userIsolation(pat::UserBaseIso);
00170 if ( prunedKey == "CaloIso" ) return userIsolation(pat::CaloIso);
00171
00172
00173
00174 return -1.0;
00175 }
00178 void setIsolation(IsolationKeys key, float value) {
00179 if (key >= 0) {
00180 if (size_t(key) >= isolations_.size()) isolations_.resize(key+1, -1.0);
00181 isolations_[key] = value;
00182 } else {
00183 throw cms::Exception("Illegal Argument") <<
00184 "The key for which you're setting isolation does not correspond " <<
00185 "to an individual isolation but to the sum of more independent isolations " <<
00186 "(e.g. Calo = Ecal + Hcal), so you can't SET the value, just GET it.\n" <<
00187 "Please set up each component independly.\n";
00188 }
00189 }
00190
00191
00194 float trackIso() const { return userIsolation(pat::TrackIso); }
00198 float caloIso() const { return userIsolation(pat::CaloIso); }
00201 float ecalIso() const { return userIsolation(pat::EcalIso); }
00204 float hcalIso() const { return userIsolation(pat::HcalIso); }
00205
00206
00208 void setTrackIso(float trackIso) { setIsolation(pat::TrackIso, trackIso); }
00210 void setEcalIso(float caloIso) { setIsolation(pat::EcalIso, caloIso); }
00212 void setHcalIso(float caloIso) { setIsolation(pat::HcalIso, caloIso); }
00214 void setUserIso(float value, uint8_t index=0) { setIsolation(IsolationKeys(UserBaseIso + index), value); }
00215
00216
00217
00219 const IsoDeposit * isoDeposit(IsolationKeys key) const {
00220 for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
00221 it != ed; ++it)
00222 {
00223 if (it->first == key) return & it->second;
00224 }
00225 return 0;
00226 }
00227
00229 void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep) {
00230 IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
00231 for (; it != ed; ++it) {
00232 if (it->first == key) { it->second = dep; return; }
00233 }
00234 isoDeposits_.push_back(std::make_pair(key,dep));
00235 }
00236
00237
00238 const IsoDeposit * trackIsoDeposit() const { return isoDeposit(pat::TrackIso); }
00239 const IsoDeposit * ecalIsoDeposit() const { return isoDeposit(pat::EcalIso ); }
00240 const IsoDeposit * hcalIsoDeposit() const { return isoDeposit(pat::HcalIso ); }
00241 const IsoDeposit * userIsoDeposit(uint8_t index=0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
00242
00243
00244 void trackIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::TrackIso, dep); }
00245 void ecalIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::EcalIso, dep); }
00246 void hcalIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::HcalIso, dep); }
00247 void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0) { setIsoDeposit(IsolationKeys(UserBaseIso + index), dep); }
00248
00250 const pat::VertexAssociation * vertexAssociation(size_t index=0) const { return vtxAss_.size() > index ? & vtxAss_[index] : 0; }
00252 const std::vector<pat::VertexAssociation> & vertexAssociations() const { return vtxAss_; }
00254 void setVertexAssociation(const pat::VertexAssociation &assoc) { vtxAss_ = std::vector<pat::VertexAssociation>(1, assoc); }
00256 void setVertexAssociations(const std::vector<pat::VertexAssociation> &assocs) { vtxAss_ = assocs; }
00257 protected:
00258
00259 reco::TrackRef trackRef_, standaloneTrackRef_, combinedTrackRef_;
00260 reco::TrackCollection track_, standaloneTrack_, combinedTrack_;
00261
00262
00263 reco::GsfTrackRef gsfTrackRef_;
00264 reco::GsfTrackCollection gsfTrack_;
00265
00266
00267 CaloTowerRef caloTowerRef_;
00268 CaloTowerCollection caloTower_;
00269
00270
00271 reco::SuperClusterRef superClusterRef_;
00272 reco::SuperClusterCollection superCluster_;
00273
00274
00275 reco::TrackRefVector trackRefs_;
00276 reco::TrackCollection tracks_;
00277
00278
00279
00280 float quality_;
00281
00282
00283 typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
00284 IsoDepositPairs isoDeposits_;
00285 std::vector<float> isolations_;
00286
00287
00288 std::vector<pat::VertexAssociation> vtxAss_;
00289
00290 void fillInFrom(const reco::Candidate &cand);
00291
00292 };
00293
00294
00295 }
00296
00297 #endif