CMS 3D CMS Logo

GenericParticle.cc
Go to the documentation of this file.
1 //
2 //
3 
5 
6 
8 
9 
11 GenericParticle::GenericParticle() :
12  PATObject<reco::RecoCandidate>()
13 {
14 }
15 
16 
20 {
22 }
23 
24 
28 {
29  fillInFrom(*cand);
30  refToOrig_ = edm::Ptr<reco::Candidate>(cand.id(), cand.get(), cand.key()); // correct RefToBase=>Ptr conversion
31 }
32 
36 {
37  fillInFrom(*cand);
38  refToOrig_ = cand;
39 }
40 
41 
42 
45 }
46 
47 // ====== SETTERS =====
50  trackRef_ = ref;
51  if (embed) embedTrack(); else track_.clear();
52 }
53 
56  trackRefs_ = refs;
57  if (embed) embedTracks(); else tracks_.clear();
58 }
59 
62  standaloneTrackRef_ = ref;
63  if (embed) embedStandalone(); else standaloneTrack_.clear();
64 }
65 
68  combinedTrackRef_ = ref;
69  if (embed) embedCombined(); else combinedTrack_.clear();
70 }
71 
74  gsfTrackRef_ = ref;
75  if (embed) embedGsfTrack(); else gsfTrack_.clear();
76 }
77 
80  superClusterRef_ = ref;
81  if (embed) embedSuperCluster(); else superCluster_.clear();
82 }
83 
86  caloTowerRef_ = ref;
87  if (embed) {
88  embedCaloTower();
89  } else if (!caloTower_.empty()) {
91  }
92 }
93 
94 
95 // ========== EMBEDDER METHODS
98  track_.clear();
99  if (trackRef_.isNonnull()) track_.push_back(*trackRef_); // import
100  trackRef_ = reco::TrackRef(); // clear, to save space (zeroes compress better)
101 }
104  tracks_.clear();
105  tracks_.reserve(trackRefs_.size());
107  if (it->isNonnull()) tracks_.push_back(**it); // embed track
108  }
109  trackRefs_ = reco::TrackRefVector(); // clear, to save space
110 }
113  standaloneTrack_.clear();
115  standaloneTrackRef_ = reco::TrackRef(); // clear, to save space (zeroes compress better)
116 }
119  combinedTrack_.clear();
120  if (combinedTrackRef_.isNonnull()) combinedTrack_.push_back(*combinedTrackRef_); // import
121  combinedTrackRef_ = reco::TrackRef(); // clear, to save space (zeroes compress better)
122 }
125  gsfTrack_.clear();
126  if (gsfTrackRef_.isNonnull()) gsfTrack_.push_back(*gsfTrackRef_); // import
127  gsfTrackRef_ = reco::GsfTrackRef(); // clear, to save space (zeroes compress better)
128 }
129 
132  superCluster_.clear();
133  if (superClusterRef_.isNonnull()) superCluster_.push_back(*superClusterRef_); // import
134  superClusterRef_ = reco::SuperClusterRef(); // clear, to save space (zeroes compress better)
135 }
140  caloTowerRef_ = CaloTowerRef(); // clear, to save space (zeroes compress better)
141 }
142 
143 
145  // first, kinematics & status
146  setCharge(cand.charge());
147  setP4(cand.polarP4());
148  setVertex(cand.vertex());
149  setPdgId(cand.pdgId());
150  setStatus(cand.status());
151  // then RECO part, if available
152  const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&cand);
153  if (rc != nullptr) {
154  setTrack(rc->track());
155  setGsfTrack(rc->gsfTrack());
156  setStandAloneMuon(rc->standAloneMuon());
157  setCombinedMuon(rc->combinedMuon());
158  setSuperCluster(rc->superCluster());
159  setCaloTower(rc->caloTower());
160  size_t ntracks = rc->numberOfTracks();
161  if (ntracks > 0) {
163  for (size_t i = 0; i < ntracks; ++i) {
164  tracks.push_back(rc->track(i));
165  }
166  setTracks(tracks);
167  }
168  }
169 }
170 
171 bool GenericParticle::overlap( const reco::Candidate &cand ) const {
172  const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&cand);
173  if (rc != nullptr) {
174  if (rc->track().isNonnull() && (track() == rc->track())) return true;
175  if (rc->gsfTrack().isNonnull() && (gsfTrack() == rc->gsfTrack())) return true;
176  if (rc->standAloneMuon().isNonnull() && (standAloneMuon() == rc->standAloneMuon())) return true;
177  if (rc->combinedMuon().isNonnull() && (combinedMuon() == rc->combinedMuon())) return true;
178  if (rc->superCluster().isNonnull() && (superCluster() == rc->superCluster())) return true;
179  if (rc->caloTower().isNonnull() && (caloTower() == rc->caloTower())) return true;
180  }
181  const GenericParticle *rc2 = dynamic_cast<const GenericParticle *>(&cand);
182  if (rc2 != nullptr) {
183  if (rc2->track().isNonnull() && (track() == rc2->track())) return true;
184  if (rc2->gsfTrack().isNonnull() && (gsfTrack() == rc2->gsfTrack())) return true;
185  if (rc2->standAloneMuon().isNonnull() && (standAloneMuon() == rc2->standAloneMuon())) return true;
186  if (rc2->combinedMuon().isNonnull() && (combinedMuon() == rc2->combinedMuon())) return true;
187  if (rc2->superCluster().isNonnull() && (superCluster() == rc2->superCluster())) return true;
188  if (rc2->caloTower().isNonnull() && (caloTower() == rc2->caloTower())) return true;
189  }
190  return false;
191 }
edm::Ref< GsfTrackCollection > GsfTrackRef
persistent reference to a GsfTrack
Definition: GsfTrackFwd.h:13
virtual reco::GsfTrackRef gsfTrack() const
reference to a GsfTrack
value_type const * get() const
Definition: RefToBase.h:234
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
CaloTowerCollection caloTower_
reco::TrackRef standaloneTrackRef_
reco::TrackCollection combinedTrack_
virtual const PolarLorentzVector & polarP4() const =0
four-momentum Lorentz vector
reco::TrackCollection track_
void fillInFrom(const reco::Candidate &cand)
void swap(SortedCollection &other)
void push_back(T const &t)
~GenericParticle() override
destructor
void embedTrack()
embeds the master track instead of keeping a reference to it
reco::TrackRef trackRef_
virtual reco::TrackRef standAloneMuon() const
reference to a stand-alone muon Track
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:253
edm::RefVector< TrackCollection > TrackRefVector
vector of reference to Track in the same collection
Definition: TrackFwd.h:30
edm::Ref< SuperClusterCollection > SuperClusterRef
reference to an object in a collection of SuperCluster objects
ProductID id() const
Definition: RefToBase.h:242
GenericParticle()
default constructor
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:248
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 setVertex(const Point &vertex) override
set vertex
virtual reco::TrackRef track() const
reference to a Track
void setCharge(Charge q) final
set electric charge
Definition: LeafCandidate.h:93
virtual int status() const =0
status word
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_
size_t key() const
Definition: RefToBase.h:250
virtual int pdgId() const =0
PDG identifier.
virtual CaloTowerRef caloTower() const
reference to a CaloTower
reco::GsfTrackRef gsfTrackRef_
reco::SuperClusterRef superClusterRef_
edm::SortedCollection< CaloTower > CaloTowerCollection
Definition: CaloTowerDefs.h:16
virtual void setGsfTrack(const reco::GsfTrackRef &ref, bool embed=false)
sets gsf track reference (or even embed it into the object)
reco::TrackRef combinedMuon() const override
reco::TrackRef standAloneMuon() const override
virtual void setCaloTower(const CaloTowerRef &ref, bool embed=false)
sets calotower reference (or even embed it into the object)
CaloTowerRef caloTower() const override
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...
bool overlap(const Candidate &) const override
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)
reco::TrackCollection tracks_
void embedTracks()
embeds the other tracks instead of keeping references
reco::GsfTrackCollection gsfTrack_
Candidate()
default constructor
Definition: Candidate.h:54
reco::TrackRef track() const override
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:21
reco::TrackRefVector trackRefs_
virtual int charge() const =0
electric charge
CaloTowerRef caloTowerRef_
fixed size matrix
reco::TrackRef combinedTrackRef_
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:69
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
Templated PAT object container.
Definition: PATObject.h:49
void embedCaloTower()
embeds the calotower instead of keeping a reference to it
virtual const Point & vertex() const =0
vertex position
reco::GsfTrackRef gsfTrack() const override
reco::SuperClusterRef superCluster() const override
edm::Ref< CaloTowerCollection > CaloTowerRef
Definition: CaloTowerDefs.h:17
void setStatus(int status) final
set status word
void embedCombined()
embeds the combined track instead of keeping a reference to it
void setPdgId(int pdgId) final
virtual void setTrack(const reco::TrackRef &ref, bool embed=false)
sets master track reference (or even embed it into the object)
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:421
void setP4(const LorentzVector &p4) final
set 4-momentum
virtual reco::SuperClusterRef superCluster() const
reference to a SuperCluster
virtual void setSuperCluster(const reco::SuperClusterRef &ref, bool embed=false)
sets supercluster reference (or even embed it into the object)
virtual reco::TrackRef combinedMuon() const
reference to a stand-alone muon Track