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
pat::GenericParticle::ecalIsoDeposit
const IsoDeposit * ecalIsoDeposit() const
Definition: GenericParticle.h:264
pat::User3Iso
Definition: Isolation.h:19
pat::GenericParticle::trackIsoDeposit
void trackIsoDeposit(const IsoDeposit &dep)
Definition: GenericParticle.h:269
reco::GsfTrackRef
edm::Ref< GsfTrackCollection > GsfTrackRef
persistent reference to a GsfTrack
Definition: GsfTrackFwd.h:13
embed
#define embed
Definition: AMPTWrapper.h:188
pat::GenericParticle::hcalIsoDeposit
void hcalIsoDeposit(const IsoDeposit &dep)
Definition: GenericParticle.h:271
pat::GenericParticle::userIsolation
float userIsolation(const std::string &key) const
Definition: GenericParticle.h:163
pat::EcalIso
Definition: Isolation.h:11
pat::GenericParticle::combinedTrack_
reco::TrackCollection combinedTrack_
Definition: GenericParticle.h:292
pat::GenericParticle::numberOfTracks
size_t numberOfTracks() const override
number of multiple tracks (not including the master one)
Definition: GenericParticle.h:72
pat::GenericParticle::setTrack
virtual void setTrack(const reco::TrackRef &ref, bool embed=false)
sets master track reference (or even embed it into the object)
Definition: GenericParticle.cc:31
pat::GenericParticle::track_
reco::TrackCollection track_
Definition: GenericParticle.h:292
pat::GenericParticle::standAloneMuon
reco::TrackRef standAloneMuon() const override
Definition: GenericParticle.h:80
pat::GenericParticleRefVector
edm::RefVector< GenericParticleCollection > GenericParticleRefVector
Definition: GenericParticle.h:32
pat::GenericParticle::setUserIso
void setUserIso(float value, uint8_t index=0)
Sets user isolation variable index.
Definition: GenericParticle.h:238
reco::LeafCandidate::index
unsigned int index
Definition: LeafCandidate.h:31
pat::GenericParticle::standaloneTrackRef_
reco::TrackRef standaloneTrackRef_
Definition: GenericParticle.h:291
pat::GenericParticle::superClusterRef_
reco::SuperClusterRef superClusterRef_
Definition: GenericParticle.h:303
pat::GenericParticle::caloTowerRef_
CaloTowerRef caloTowerRef_
Definition: GenericParticle.h:299
pat::GenericParticle::caloIso
float caloIso() const
Definition: GenericParticle.h:222
pat::GenericParticle::vertexAssociation
const pat::VertexAssociation * vertexAssociation(size_t index=0) const
Vertex association (or associations, if any). Return null pointer if none has been set.
Definition: GenericParticle.h:277
pat::GenericParticle::embedSuperCluster
void embedSuperCluster()
embeds the supercluster instead of keeping a reference to it
Definition: GenericParticle.cc:135
pat::GenericParticle::gsfTrack
reco::GsfTrackRef gsfTrack() const override
Definition: GenericParticle.h:75
pat::GenericParticle::superCluster_
reco::SuperClusterCollection superCluster_
Definition: GenericParticle.h:304
pat::GenericParticle::trackIso
float trackIso() const
Definition: GenericParticle.h:218
edm::SortedCollection< CaloTower >
pat::PfAllParticleIso
Definition: Isolation.h:13
pat::GenericParticle::clone
GenericParticle * clone() const override
required reimplementation of the Candidate's clone method
Definition: GenericParticle.h:52
pat::GenericParticle::quality
float quality()
returns a user defined quality value, if set by the user to some meaningful value
Definition: GenericParticle.h:130
pat::GenericParticle::setEcalIso
void setEcalIso(float caloIso)
Sets ecal isolation variable.
Definition: GenericParticle.h:234
pat::User5Iso
Definition: Isolation.h:21
edm::RefVector
Definition: EDProductfwd.h:27
pat::GenericParticle::ecalIso
float ecalIso() const
Definition: GenericParticle.h:225
pat::GenericParticle::setCombinedMuon
virtual void setCombinedMuon(const reco::TrackRef &ref, bool embed=false)
sets combined muon track reference (or even embed it into the object)
Definition: GenericParticle.cc:58
RecoCandidate.h
pat::GenericParticle::embedGsfTrack
void embedGsfTrack()
embeds the gsf track instead of keeping a reference to it
Definition: GenericParticle.cc:127
pat::GenericParticle::combinedMuon
reco::TrackRef combinedMuon() const override
Definition: GenericParticle.h:85
edm::Ref
Definition: AssociativeIterator.h:58
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
GenParticle.h
trackingPlots.assoc
assoc
Definition: trackingPlots.py:183
reco::SuperClusterCollection
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
Definition: SuperClusterFwd.h:9
pat::User4Iso
Definition: Isolation.h:20
pat::GenericParticle::hcalIsoDeposit
const IsoDeposit * hcalIsoDeposit() const
Definition: GenericParticle.h:265
pat::User1Iso
Definition: Isolation.h:17
pat::GenericParticle::setIsolation
void setIsolation(IsolationKeys key, float value)
Definition: GenericParticle.h:201
pat::GenericParticle::vertexAssociations
const std::vector< pat::VertexAssociation > & vertexAssociations() const
Vertex associations. Can be empty if it was not enabled in the config file.
Definition: GenericParticle.h:281
pat::PfChargedHadronIso
Definition: Isolation.h:14
pat::GenericParticle::userIsoDeposit
void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0)
Definition: GenericParticle.h:272
pat::PATObject
Templated PAT object container.
Definition: PATObject.h:43
reco::SuperClusterRef
edm::Ref< SuperClusterCollection > SuperClusterRef
reference to an object in a collection of SuperCluster objects
Definition: SuperClusterFwd.h:15
pat::GenericParticle::setSuperCluster
virtual void setSuperCluster(const reco::SuperClusterRef &ref, bool embed=false)
sets supercluster reference (or even embed it into the object)
Definition: GenericParticle.cc:76
pat::GenericParticle::hcalIso
float hcalIso() const
Definition: GenericParticle.h:228
pat::GenericParticle::setQuality
void setQuality(float quality)
sets a user defined quality value
Definition: GenericParticle.h:132
pat::GenericParticle::gsfTrack_
reco::GsfTrackCollection gsfTrack_
Definition: GenericParticle.h:296
Isolation.h
pat::GenericParticle::setVertexAssociations
void setVertexAssociations(const std::vector< pat::VertexAssociation > &assocs)
Set multiple vertex associations.
Definition: GenericParticle.h:287
pat::GenericParticle::userIsolation
float userIsolation(IsolationKeys key) const
Definition: GenericParticle.h:137
pat::GenericParticle::track
reco::TrackRef track(size_t idx) const override
Definition: GenericParticle.h:65
pat::GenericParticle::embedStandalone
void embedStandalone()
embeds the stand-alone track instead of keeping a reference to it
Definition: GenericParticle.cc:113
pat::GenericParticle::caloTower
CaloTowerRef caloTower() const override
Definition: GenericParticle.h:95
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
pat::GenericParticle::isolations_
std::vector< float > isolations_
Definition: GenericParticle.h:317
pat::GenericParticle::embedCaloTower
void embedCaloTower()
embeds the calotower instead of keeping a reference to it
Definition: GenericParticle.cc:142
pat::User2Iso
Definition: Isolation.h:18
pat::GenericParticle
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed)
Definition: GenericParticle.h:38
pat::GenericParticle::overlap
bool overlap(const Candidate &) const override
Definition: GenericParticle.cc:177
pat::GenericParticle::setHcalIso
void setHcalIso(float caloIso)
Sets hcal isolation variable.
Definition: GenericParticle.h:236
pat::PfGammaIso
Definition: Isolation.h:16
pat::GenericParticle::setGsfTrack
virtual void setGsfTrack(const reco::GsfTrackRef &ref, bool embed=false)
sets gsf track reference (or even embed it into the object)
Definition: GenericParticle.cc:67
pat::UserBaseIso
Definition: Isolation.h:22
cand
Definition: decayParser.h:32
pat::TrackIso
Definition: Isolation.h:10
pat::GenericParticle::fillInFrom
void fillInFrom(const reco::Candidate &cand)
Definition: GenericParticle.cc:150
pat::GenericParticle::isoDeposit
const IsoDeposit * isoDeposit(IsolationKeys key) const
Returns the IsoDeposit associated with some key, or a null pointer if it is not available.
Definition: GenericParticle.h:242
pat::GenericParticle::trackRef_
reco::TrackRef trackRef_
Definition: GenericParticle.h:291
pat::GenericParticle::userIsoDeposit
const IsoDeposit * userIsoDeposit(uint8_t index=0) const
Definition: GenericParticle.h:266
pat::HcalIso
Definition: Isolation.h:12
pat::GenericParticle::setVertexAssociation
void setVertexAssociation(const pat::VertexAssociation &assoc)
Set a single vertex association.
Definition: GenericParticle.h:283
value
Definition: value.py:1
GsfTrack.h
pat::PfNeutralHadronIso
Definition: Isolation.h:15
pat
Definition: HeavyIon.h:7
Vertexing.h
pat::GenericParticle::~GenericParticle
~GenericParticle() override
destructor
Definition: GenericParticle.cc:27
pat::GenericParticleCollection
std::vector< GenericParticle > GenericParticleCollection
Definition: GenericParticle.h:29
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pat::VertexAssociation
Analysis-level structure for vertex-related information.
Definition: Vertexing.h:25
pat::GenericParticle::trackIsoDeposit
const IsoDeposit * trackIsoDeposit() const
Definition: GenericParticle.h:263
edm::Ptr< reco::Candidate >
reco::Candidate
Definition: Candidate.h:27
pat::GenericParticle::IsoDepositPairs
std::vector< std::pair< IsolationKeys, pat::IsoDeposit > > IsoDepositPairs
Definition: GenericParticle.h:315
pat::GenericParticle::tracks_
reco::TrackCollection tracks_
Definition: GenericParticle.h:308
pat::GenericParticle::setTracks
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...
Definition: GenericParticle.cc:40
reco::GsfTrackCollection
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
pat::GenericParticle::standaloneTrack_
reco::TrackCollection standaloneTrack_
Definition: GenericParticle.h:292
pat::GenericParticle::embedCombined
void embedCombined()
embeds the combined track instead of keeping a reference to it
Definition: GenericParticle.cc:120
GsfTrackFwd.h
pat::IsolationKeys
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
SuperClusterFwd.h
relativeConstraints.value
value
Definition: relativeConstraints.py:53
SuperCluster.h
Exception
Definition: hltDiff.cc:245
pat::GenericParticle::setCaloTower
virtual void setCaloTower(const CaloTowerRef &ref, bool embed=false)
sets calotower reference (or even embed it into the object)
Definition: GenericParticle.cc:85
reco::Candidate::index
unsigned int index
index type
Definition: Candidate.h:50
pat::GenericParticle::isoDeposits_
IsoDepositPairs isoDeposits_
Definition: GenericParticle.h:316
pat::GenericParticle::gsfTrackRef_
reco::GsfTrackRef gsfTrackRef_
Definition: GenericParticle.h:295
pat::GenericParticle::combinedTrackRef_
reco::TrackRef combinedTrackRef_
Definition: GenericParticle.h:291
reco::IsoDeposit
Definition: IsoDeposit.h:49
pat::GenericParticle::track
reco::TrackRef track() const override
Definition: GenericParticle.h:62
edm::RefToBase
Definition: AssociativeIterator.h:54
CaloTowerRef
edm::Ref< CaloTowerCollection > CaloTowerRef
Definition: CaloTowerDefs.h:17
reco::Candidate::Candidate
Candidate()
default constructor
Definition: Candidate.h:53
pat::GenericParticleRef
edm::Ref< GenericParticleCollection > GenericParticleRef
Definition: GenericParticle.h:31
pat::GenericParticle::embedTracks
void embedTracks()
embeds the other tracks instead of keeping references
Definition: GenericParticle.cc:103
pat::CaloIso
Definition: Isolation.h:23
pat::GenericParticle::setIsoDeposit
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
Definition: GenericParticle.h:251
pat::GenericParticle::setStandAloneMuon
virtual void setStandAloneMuon(const reco::TrackRef &ref, bool embed=false)
sets stand-alone muon track reference (or even embed it into the object)
Definition: GenericParticle.cc:49
pat::GenericParticle::setTrackIso
void setTrackIso(float trackIso)
Sets tracker isolation variable.
Definition: GenericParticle.h:232
pat::GenericParticle::superCluster
reco::SuperClusterRef superCluster() const override
Definition: GenericParticle.h:90
pat::GenericParticle::caloTower_
CaloTowerCollection caloTower_
Definition: GenericParticle.h:300
edm::RefVector::size
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
crabWrapper.key
key
Definition: crabWrapper.py:19
pat::GenericParticle::quality_
float quality_
Definition: GenericParticle.h:312
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
pat::GenericParticle::GenericParticle
GenericParticle()
default constructor
Definition: GenericParticle.cc:9
pat::GenericParticle::ecalIsoDeposit
void ecalIsoDeposit(const IsoDeposit &dep)
Definition: GenericParticle.h:270
pat::GenericParticle::embedTrack
void embedTrack()
embeds the master track instead of keeping a reference to it
Definition: GenericParticle.cc:96
edm::SortedCollection::empty
bool empty() const
Definition: SortedCollection.h:210
pat::GenericParticle::vtxAss_
std::vector< pat::VertexAssociation > vtxAss_
Definition: GenericParticle.h:320
PATObject.h
pat::GenericParticle::trackRefs_
reco::TrackRefVector trackRefs_
Definition: GenericParticle.h:307