CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenericParticle.h
Go to the documentation of this file.
1 //
2 // $Id: GenericParticle.h,v 1.9 2010/03/02 21:02:46 rwolf Exp $
3 //
4 
5 #ifndef DataFormats_PatCandidates_GenericParticle_h
6 #define DataFormats_PatCandidates_GenericParticle_h
7 
28 
29 // Define typedefs for convenience
30 namespace pat {
32  typedef std::vector<GenericParticle> GenericParticleCollection;
35 }
36 
37 
38 // Class definition
39 namespace pat {
40 
41 
42  class GenericParticle : public PATObject<reco::RecoCandidate> {
43 
44  public:
45 
49  GenericParticle(const reco::Candidate & aGenericParticle);
51  GenericParticle(const edm::RefToBase<reco::Candidate> & aGenericParticleRef);
53  GenericParticle(const edm::Ptr<reco::Candidate> & aGenericParticleRef);
55  virtual ~GenericParticle();
56 
58  virtual GenericParticle * clone() const { return new GenericParticle(*this); }
59 
64  virtual bool overlap( const Candidate & ) const ;
65 
68  virtual reco::TrackRef track() const { return track_.empty() ? trackRef_ : reco::TrackRef(&track_, 0); }
71  virtual reco::TrackRef track( size_t idx ) const {
72  if (idx >= numberOfTracks()) throw cms::Exception("Index out of bounds") << "Requested track " << idx << " out of " << numberOfTracks() << ".\n";
73  return (tracks_.empty() ? trackRefs_[idx] : reco::TrackRef(&tracks_, idx) );
74  }
76  virtual size_t numberOfTracks() const { return tracks_.empty() ? trackRefs_.size() : tracks_.size(); }
79  virtual reco::GsfTrackRef gsfTrack() const { return (gsfTrack_.empty() ? gsfTrackRef_ : reco::GsfTrackRef(&gsfTrack_, 0)); }
92 
94  virtual void setTrack(const reco::TrackRef &ref, bool embed=false) ;
96  virtual void setTracks(const reco::TrackRefVector &refs, bool embed=false) ;
98  virtual void setStandAloneMuon(const reco::TrackRef &ref, bool embed=false) ;
100  virtual void setCombinedMuon(const reco::TrackRef &ref, bool embed=false) ;
102  virtual void setGsfTrack(const reco::GsfTrackRef &ref, bool embed=false) ;
104  virtual void setSuperCluster(const reco::SuperClusterRef &ref, bool embed=false) ;
106  virtual void setCaloTower(const CaloTowerRef &ref, bool embed=false) ;
107 
109  void embedTrack() ;
111  void embedTracks() ;
113  void embedStandalone() ;
115  void embedCombined() ;
117  void embedGsfTrack() ;
119  void embedSuperCluster() ;
121  void embedCaloTower() ;
122 
124  float quality() { return quality_; }
126  void setQuality(float quality) { quality_ = quality; }
127 
128  //============ BEGIN ISOLATION BLOCK =====
132  if (key >= 0) {
133  //if (key >= isolations_.size()) throw cms::Excepton("Missing Data")
134  //<< "Isolation corresponding to key "
135  //<< key << " was not stored for this particle.";
136  if (size_t(key) >= isolations_.size()) return -1.0;
137  return isolations_[key];
138  } else switch (key) {
139  case pat::CaloIso:
140  //if (isolations_.size() <= pat::HcalIso) throw cms::Excepton("Missing Data")
141  //<< "CalIsoo Isolation was not stored for this particle.";
142  if (isolations_.size() <= pat::HcalIso) return -1.0;
144  default:
145  return -1.0;
146  //throw cms::Excepton("Missing Data") << "Isolation corresponding to key "
147  //<< key << " was not stored for this particle.";
148  }
149  }
154  float userIsolation(const std::string& key) const {
155  // remove leading namespace specifier
156  std::string prunedKey = ( key.find("pat::") == 0 ) ? std::string(key, 5) : key;
157  if ( prunedKey == "TrackIso" ) return userIsolation(pat::TrackIso);
158  if ( prunedKey == "EcalIso" ) return userIsolation(pat::EcalIso);
159  if ( prunedKey == "HcalIso" ) return userIsolation(pat::HcalIso);
160  if ( prunedKey == "PfAllParticleIso" ) return userIsolation(pat::PfAllParticleIso);
161  if ( prunedKey == "PfChargedHadronIso" ) return userIsolation(pat::PfChargedHadronIso);
162  if ( prunedKey == "PfNeutralHadronIso" ) return userIsolation(pat::PfNeutralHadronIso);
163  if ( prunedKey == "PfGammaIso" ) return userIsolation(pat::PfGammaIso);
164  if ( prunedKey == "User1Iso" ) return userIsolation(pat::User1Iso);
165  if ( prunedKey == "User2Iso" ) return userIsolation(pat::User2Iso);
166  if ( prunedKey == "User3Iso" ) return userIsolation(pat::User3Iso);
167  if ( prunedKey == "User4Iso" ) return userIsolation(pat::User4Iso);
168  if ( prunedKey == "User5Iso" ) return userIsolation(pat::User5Iso);
169  if ( prunedKey == "UserBaseIso" ) return userIsolation(pat::UserBaseIso);
170  if ( prunedKey == "CaloIso" ) return userIsolation(pat::CaloIso);
171  //throw cms::Excepton("Missing Data")
172  //<< "Isolation corresponding to key "
173  //<< key << " was not stored for this particle.";
174  return -1.0;
175  }
179  if (key >= 0) {
180  if (size_t(key) >= isolations_.size()) isolations_.resize(key+1, -1.0);
181  isolations_[key] = value;
182  } else {
183  throw cms::Exception("Illegal Argument") <<
184  "The key for which you're setting isolation does not correspond " <<
185  "to an individual isolation but to the sum of more independent isolations " <<
186  "(e.g. Calo = Ecal + Hcal), so you can't SET the value, just GET it.\n" <<
187  "Please set up each component independly.\n";
188  }
189  }
190 
191  // ---- specific getters ----
194  float trackIso() const { return userIsolation(pat::TrackIso); }
198  float caloIso() const { return userIsolation(pat::CaloIso); }
201  float ecalIso() const { return userIsolation(pat::EcalIso); }
204  float hcalIso() const { return userIsolation(pat::HcalIso); }
205 
206  // ---- specific setters ----
208  void setTrackIso(float trackIso) { setIsolation(pat::TrackIso, trackIso); }
210  void setEcalIso(float caloIso) { setIsolation(pat::EcalIso, caloIso); }
212  void setHcalIso(float caloIso) { setIsolation(pat::HcalIso, caloIso); }
214  void setUserIso(float value, uint8_t index=0) { setIsolation(IsolationKeys(UserBaseIso + index), value); }
215 
216 
217  //============ BEGIN ISODEPOSIT BLOCK =====
220  for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
221  it != ed; ++it)
222  {
223  if (it->first == key) return & it->second;
224  }
225  return 0;
226  }
227 
230  IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
231  for (; it != ed; ++it) {
232  if (it->first == key) { it->second = dep; return; }
233  }
234  isoDeposits_.push_back(std::make_pair(key,dep));
235  }
236 
237  // ---- specific getters ----
238  const IsoDeposit * trackIsoDeposit() const { return isoDeposit(pat::TrackIso); }
239  const IsoDeposit * ecalIsoDeposit() const { return isoDeposit(pat::EcalIso ); }
240  const IsoDeposit * hcalIsoDeposit() const { return isoDeposit(pat::HcalIso ); }
241  const IsoDeposit * userIsoDeposit(uint8_t index=0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
242 
243  // ---- specific setters ----
247  void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0) { setIsoDeposit(IsolationKeys(UserBaseIso + index), dep); }
248 
250  const pat::VertexAssociation * vertexAssociation(size_t index=0) const { return vtxAss_.size() > index ? & vtxAss_[index] : 0; }
252  const std::vector<pat::VertexAssociation> & vertexAssociations() const { return vtxAss_; }
254  void setVertexAssociation(const pat::VertexAssociation &assoc) { vtxAss_ = std::vector<pat::VertexAssociation>(1, assoc); }
256  void setVertexAssociations(const std::vector<pat::VertexAssociation> &assocs) { vtxAss_ = assocs; }
257  protected:
258  // Any sort of single tracks
261 
262  // GsfTrack
265 
266  // CaloTower
269 
270  // SuperCluster
273 
274  // Multiple tracks
277 
278  // information originally in external branches
279  // some quality variable
280  float quality_;
281 
282  // --- Isolation and IsoDeposit related datamebers ---
283  typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
285  std::vector<float> isolations_;
286 
287  // --- Vertexing information
288  std::vector<pat::VertexAssociation> vtxAss_;
289 
290  void fillInFrom(const reco::Candidate &cand);
291 
292  };
293 
294 
295 }
296 
297 #endif
edm::Ref< GsfTrackCollection > GsfTrackRef
persistent reference to a GsfTrack
Definition: GsfTrackFwd.h:13
IsoDepositPairs isoDeposits_
CaloTowerCollection caloTower_
reco::TrackRef standaloneTrackRef_
virtual reco::TrackRef combinedMuon() const
void setIsolation(IsolationKeys key, float value)
virtual bool overlap(const Candidate &) const
void ecalIsoDeposit(const IsoDeposit &dep)
reco::TrackCollection combinedTrack_
reco::TrackCollection track_
void fillInFrom(const reco::Candidate &cand)
edm::Ref< GenericParticleCollection > GenericParticleRef
std::vector< GenericParticle > GenericParticleCollection
void trackIsoDeposit(const IsoDeposit &dep)
void setUserIso(float value, uint8_t index=0)
Sets user isolation variable index.
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
std::vector< float > isolations_
void embedTrack()
embeds the master track instead of keeping a reference to it
void hcalIsoDeposit(const IsoDeposit &dep)
reco::TrackRef trackRef_
const IsoDeposit * isoDeposit(IsolationKeys key) const
Returns the IsoDeposit associated with some key, or a null pointer if it is not available.
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
void setHcalIso(float caloIso)
Sets hcal isolation variable.
edm::Ref< SuperClusterCollection > SuperClusterRef
reference to an object in a collection of SuperCluster objects
GenericParticle()
default constructor
float trackIso() const
virtual void setCombinedMuon(const reco::TrackRef &ref, bool embed=false)
sets combined muon track reference (or even embed it into the object)
#define embed
Definition: AMPTWrapper.h:178
void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0)
float hcalIso() const
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
reco::TrackCollection standaloneTrack_
void embedStandalone()
embeds the stand-alone track instead of keeping a reference to it
reco::SuperClusterCollection superCluster_
float quality()
returns a user defined quality value, if set by the user to some meaningful value ...
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
virtual reco::TrackRef standAloneMuon() const
const IsoDeposit * trackIsoDeposit() const
reco::GsfTrackRef gsfTrackRef_
reco::SuperClusterRef superClusterRef_
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
virtual CaloTowerRef caloTower() const
virtual reco::TrackRef track(size_t idx) const
void setTrackIso(float trackIso)
Sets tracker isolation variable.
virtual reco::TrackRef track() const
virtual void setGsfTrack(const reco::GsfTrackRef &ref, bool embed=false)
sets gsf track reference (or even embed it into the object)
const pat::VertexAssociation * vertexAssociation(size_t index=0) const
Vertex association (or associations, if any). Return null pointer if none has been set...
unsigned int index
Definition: LeafCandidate.h:33
virtual void setCaloTower(const CaloTowerRef &ref, bool embed=false)
sets calotower reference (or even embed it into the object)
edm::RefVector< GenericParticleCollection > GenericParticleRefVector
virtual void setTracks(const reco::TrackRefVector &refs, bool embed=false)
sets multiple track references (or even embed the tracks into the object - whatch out for disk size i...
std::vector< std::pair< IsolationKeys, pat::IsoDeposit > > IsoDepositPairs
void embedGsfTrack()
embeds the gsf track instead of keeping a reference to it
void embedSuperCluster()
embeds the supercluster instead of keeping a reference to it
float caloIso() const
virtual void setStandAloneMuon(const reco::TrackRef &ref, bool embed=false)
sets stand-alone muon track reference (or even embed it into the object)
unsigned int index
index type
Definition: Candidate.h:52
virtual size_t numberOfTracks() const
number of multiple tracks (not including the master one)
const IsoDeposit * ecalIsoDeposit() const
const IsoDeposit * userIsoDeposit(uint8_t index=0) const
reco::TrackCollection tracks_
void embedTracks()
embeds the other tracks instead of keeping references
reco::GsfTrackCollection gsfTrack_
Candidate()
default constructor
Definition: Candidate.h:55
virtual ~GenericParticle()
destructor
virtual reco::GsfTrackRef gsfTrack() const
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
reco::TrackRefVector trackRefs_
const IsoDeposit * hcalIsoDeposit() const
float userIsolation(IsolationKeys key) const
std::vector< pat::VertexAssociation > vtxAss_
virtual GenericParticle * clone() const
required reimplementation of the Candidate&#39;s clone method
CaloTowerRef caloTowerRef_
reco::TrackRef combinedTrackRef_
list key
Definition: combine.py:13
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
Analysis-level structure for vertex-related information.
Definition: Vertexing.h:27
Templated PAT object container.
Definition: PATObject.h:43
void embedCaloTower()
embeds the calotower instead of keeping a reference to it
virtual reco::SuperClusterRef superCluster() const
const std::vector< pat::VertexAssociation > & vertexAssociations() const
Vertex associations. Can be empty if it was not enabled in the config file.
float ecalIso() const
void setEcalIso(float caloIso)
Sets ecal isolation variable.
void setQuality(float quality)
sets a user defined quality value
edm::Ref< CaloTowerCollection > CaloTowerRef
Definition: CaloTowerFwd.h:16
void setVertexAssociations(const std::vector< pat::VertexAssociation > &assocs)
Set multiple vertex associations.
void embedCombined()
embeds the combined track instead of keeping a reference to it
virtual void setTrack(const reco::TrackRef &ref, bool embed=false)
sets master track reference (or even embed it into the object)
void setVertexAssociation(const pat::VertexAssociation &assoc)
Set a single vertex association.
virtual void setSuperCluster(const reco::SuperClusterRef &ref, bool embed=false)
sets supercluster reference (or even embed it into the object)
float userIsolation(const std::string &key) const