CMS 3D CMS Logo

GenericParticle.h
Go to the documentation of this file.
1 //
2 //
3 
4 #ifndef DataFormats_PatCandidates_GenericParticle_h
5 #define DataFormats_PatCandidates_GenericParticle_h
6 
26 
27 // Define typedefs for convenience
28 namespace pat {
30  typedef std::vector<GenericParticle> GenericParticleCollection;
33 } // namespace pat
34 
35 // Class definition
36 namespace pat {
37 
38  class GenericParticle : public PATObject<reco::RecoCandidate> {
39  public:
43  GenericParticle(const reco::Candidate &aGenericParticle);
45  GenericParticle(const edm::RefToBase<reco::Candidate> &aGenericParticleRef);
47  GenericParticle(const edm::Ptr<reco::Candidate> &aGenericParticleRef);
49  ~GenericParticle() override;
50 
52  GenericParticle *clone() const override { return new GenericParticle(*this); }
53 
58  bool overlap(const Candidate &) const override;
59 
62  reco::TrackRef track() const override { return track_.empty() ? trackRef_ : reco::TrackRef(&track_, 0); }
65  reco::TrackRef track(size_t idx) const override {
66  if (idx >= numberOfTracks())
67  throw cms::Exception("Index out of bounds")
68  << "Requested track " << idx << " out of " << numberOfTracks() << ".\n";
69  return (tracks_.empty() ? trackRefs_[idx] : reco::TrackRef(&tracks_, idx));
70  }
72  size_t numberOfTracks() const override { return tracks_.empty() ? trackRefs_.size() : tracks_.size(); }
75  reco::GsfTrackRef gsfTrack() const override {
76  return (gsfTrack_.empty() ? gsfTrackRef_ : reco::GsfTrackRef(&gsfTrack_, 0));
77  }
80  reco::TrackRef standAloneMuon() const override {
82  }
85  reco::TrackRef combinedMuon() const override {
87  }
92  }
95  CaloTowerRef caloTower() const override {
97  }
98 
100  virtual void setTrack(const reco::TrackRef &ref, bool embed = false);
102  virtual void setTracks(const reco::TrackRefVector &refs, bool embed = false);
104  virtual void setStandAloneMuon(const reco::TrackRef &ref, bool embed = false);
106  virtual void setCombinedMuon(const reco::TrackRef &ref, bool embed = false);
108  virtual void setGsfTrack(const reco::GsfTrackRef &ref, bool embed = false);
110  virtual void setSuperCluster(const reco::SuperClusterRef &ref, bool embed = false);
112  virtual void setCaloTower(const CaloTowerRef &ref, bool embed = false);
113 
115  void embedTrack();
117  void embedTracks();
119  void embedStandalone();
121  void embedCombined();
123  void embedGsfTrack();
125  void embedSuperCluster();
127  void embedCaloTower();
128 
130  float quality() { return quality_; }
132  void setQuality(float quality) { quality_ = quality; }
133 
134  //============ BEGIN ISOLATION BLOCK =====
138  if (key >= 0) {
139  //if (key >= isolations_.size()) throw cms::Excepton("Missing Data")
140  //<< "Isolation corresponding to key "
141  //<< key << " was not stored for this particle.";
142  if (size_t(key) >= isolations_.size())
143  return -1.0;
144  return isolations_[key];
145  } else
146  switch (key) {
147  case pat::CaloIso:
148  //if (isolations_.size() <= pat::HcalIso) throw cms::Excepton("Missing Data")
149  //<< "CalIsoo Isolation was not stored for this particle.";
150  if (isolations_.size() <= pat::HcalIso)
151  return -1.0;
153  default:
154  return -1.0;
155  //throw cms::Excepton("Missing Data") << "Isolation corresponding to key "
156  //<< key << " was not stored for this particle.";
157  }
158  }
163  float userIsolation(const std::string &key) const {
164  // remove leading namespace specifier
165  std::string prunedKey = (key.find("pat::") == 0) ? std::string(key, 5) : key;
166  if (prunedKey == "TrackIso")
168  if (prunedKey == "EcalIso")
169  return userIsolation(pat::EcalIso);
170  if (prunedKey == "HcalIso")
171  return userIsolation(pat::HcalIso);
172  if (prunedKey == "PfAllParticleIso")
174  if (prunedKey == "PfChargedHadronIso")
176  if (prunedKey == "PfNeutralHadronIso")
178  if (prunedKey == "PfGammaIso")
180  if (prunedKey == "User1Iso")
182  if (prunedKey == "User2Iso")
184  if (prunedKey == "User3Iso")
186  if (prunedKey == "User4Iso")
188  if (prunedKey == "User5Iso")
190  if (prunedKey == "UserBaseIso")
192  if (prunedKey == "CaloIso")
193  return userIsolation(pat::CaloIso);
194  //throw cms::Excepton("Missing Data")
195  //<< "Isolation corresponding to key "
196  //<< key << " was not stored for this particle.";
197  return -1.0;
198  }
202  if (key >= 0) {
203  if (size_t(key) >= isolations_.size())
204  isolations_.resize(key + 1, -1.0);
205  isolations_[key] = value;
206  } else {
207  throw cms::Exception("Illegal Argument")
208  << "The key for which you're setting isolation does not correspond "
209  << "to an individual isolation but to the sum of more independent isolations "
210  << "(e.g. Calo = Ecal + Hcal), so you can't SET the value, just GET it.\n"
211  << "Please set up each component independly.\n";
212  }
213  }
214 
215  // ---- specific getters ----
218  float trackIso() const { return userIsolation(pat::TrackIso); }
222  float caloIso() const { return userIsolation(pat::CaloIso); }
225  float ecalIso() const { return userIsolation(pat::EcalIso); }
228  float hcalIso() const { return userIsolation(pat::HcalIso); }
229 
230  // ---- specific setters ----
239 
240  //============ BEGIN ISODEPOSIT BLOCK =====
243  for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end(); it != ed; ++it) {
244  if (it->first == key)
245  return &it->second;
246  }
247  return nullptr;
248  }
249 
252  IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
253  for (; it != ed; ++it) {
254  if (it->first == key) {
255  it->second = dep;
256  return;
257  }
258  }
259  isoDeposits_.push_back(std::make_pair(key, dep));
260  }
261 
262  // ---- specific getters ----
264  const IsoDeposit *ecalIsoDeposit() const { return isoDeposit(pat::EcalIso); }
265  const IsoDeposit *hcalIsoDeposit() const { return isoDeposit(pat::HcalIso); }
266  const IsoDeposit *userIsoDeposit(uint8_t index = 0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
267 
268  // ---- specific setters ----
272  void userIsoDeposit(const IsoDeposit &dep, uint8_t index = 0) {
274  }
275 
277  const pat::VertexAssociation *vertexAssociation(size_t index = 0) const {
278  return vtxAss_.size() > index ? &vtxAss_[index] : nullptr;
279  }
281  const std::vector<pat::VertexAssociation> &vertexAssociations() const { return vtxAss_; }
284  vtxAss_ = std::vector<pat::VertexAssociation>(1, assoc);
285  }
287  void setVertexAssociations(const std::vector<pat::VertexAssociation> &assocs) { vtxAss_ = assocs; }
288 
289  protected:
290  // Any sort of single tracks
293 
294  // GsfTrack
297 
298  // CaloTower
301 
302  // SuperCluster
305 
306  // Multiple tracks
309 
310  // information originally in external branches
311  // some quality variable
312  float quality_;
313 
314  // --- Isolation and IsoDeposit related datamebers ---
315  typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
317  std::vector<float> isolations_;
318 
319  // --- Vertexing information
320  std::vector<pat::VertexAssociation> vtxAss_;
321 
322  void fillInFrom(const reco::Candidate &cand);
323  };
324 
325 } // namespace pat
326 
327 #endif
edm::Ref< GsfTrackCollection > GsfTrackRef
persistent reference to a GsfTrack
Definition: GsfTrackFwd.h:13
IsoDepositPairs isoDeposits_
reco::TrackRef track() const override
const IsoDeposit * trackIsoDeposit() const
CaloTowerCollection caloTower_
reco::TrackRef standaloneTrackRef_
void setIsolation(IsolationKeys key, float value)
void ecalIsoDeposit(const IsoDeposit &dep)
reco::TrackCollection combinedTrack_
reco::TrackCollection track_
void fillInFrom(const reco::Candidate &cand)
edm::Ref< GenericParticleCollection > GenericParticleRef
const IsoDeposit * ecalIsoDeposit() const
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:14
~GenericParticle() override
destructor
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_
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
const IsoDeposit * hcalIsoDeposit() const
reco::TrackRef standAloneMuon() const override
void setHcalIso(float caloIso)
Sets hcal isolation variable.
edm::Ref< SuperClusterCollection > SuperClusterRef
reference to an object in a collection of SuperCluster objects
size_t numberOfTracks() const override
number of multiple tracks (not including the master one)
GenericParticle()
default constructor
virtual void setCombinedMuon(const reco::TrackRef &ref, bool embed=false)
sets combined muon 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...
#define embed
Definition: AMPTWrapper.h:188
void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0)
Definition: HeavyIon.h:7
float trackIso() const
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
reco::TrackCollection standaloneTrack_
float userIsolation(IsolationKeys key) const
void embedStandalone()
embeds the stand-alone track instead of keeping a reference to it
bool overlap(const Candidate &) const override
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
reco::GsfTrackRef gsfTrackRef_
reco::SuperClusterRef superClusterRef_
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
GenericParticle * clone() const override
required reimplementation of the Candidate&#39;s clone method
const IsoDeposit * userIsoDeposit(uint8_t index=0) const
void setTrackIso(float trackIso)
Sets tracker isolation variable.
virtual void setGsfTrack(const reco::GsfTrackRef &ref, bool embed=false)
sets gsf track reference (or even embed it into the object)
Definition: value.py:1
CaloTowerRef caloTower() const override
reco::TrackRef combinedMuon() const override
reco::TrackRef track(size_t idx) const override
unsigned int index
Definition: LeafCandidate.h:31
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...
reco::GsfTrackRef gsfTrack() const override
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
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:50
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
reco::TrackCollection tracks_
void embedTracks()
embeds the other tracks instead of keeping references
reco::GsfTrackCollection gsfTrack_
Candidate()
default constructor
Definition: Candidate.h:53
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
reco::TrackRefVector trackRefs_
std::vector< pat::VertexAssociation > vtxAss_
float userIsolation(const std::string &key) const
CaloTowerRef caloTowerRef_
reco::SuperClusterRef superCluster() const override
reco::TrackRef combinedTrackRef_
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
Analysis-level structure for vertex-related information.
Definition: Vertexing.h:25
Templated PAT object container.
Definition: PATObject.h:43
void embedCaloTower()
embeds the calotower instead of keeping a reference to it
void setEcalIso(float caloIso)
Sets ecal isolation variable.
edm::Ref< CaloTowerCollection > CaloTowerRef
Definition: CaloTowerDefs.h:17
void setQuality(float quality)
sets a user defined quality value
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)
const std::vector< pat::VertexAssociation > & vertexAssociations() const
Vertex associations. Can be empty if it was not enabled in the config file.
void setVertexAssociation(const pat::VertexAssociation &assoc)
Set a single vertex association.
const IsoDeposit * isoDeposit(IsolationKeys key) const
Returns the IsoDeposit associated with some key, or a null pointer if it is not available.
virtual void setSuperCluster(const reco::SuperClusterRef &ref, bool embed=false)
sets supercluster reference (or even embed it into the object)