CMS 3D CMS Logo

GenericParticle.cc
Go to the documentation of this file.
1 //
2 //
3 
5 
7 
9 GenericParticle::GenericParticle() : PATObject<reco::RecoCandidate>() {}
10 
13 
15 GenericParticle::GenericParticle(const edm::RefToBase<Candidate> &cand) : PATObject<reco::RecoCandidate>() {
16  fillInFrom(*cand);
17  refToOrig_ = edm::Ptr<reco::Candidate>(cand.id(), cand.get(), cand.key()); // correct RefToBase=>Ptr conversion
18 }
19 
21 GenericParticle::GenericParticle(const edm::Ptr<Candidate> &cand) : PATObject<reco::RecoCandidate>() {
22  fillInFrom(*cand);
23  refToOrig_ = cand;
24 }
25 
28 
29 // ====== SETTERS =====
32  trackRef_ = ref;
33  if (embed)
34  embedTrack();
35  else
36  track_.clear();
37 }
38 
41  trackRefs_ = refs;
42  if (embed)
43  embedTracks();
44  else
45  tracks_.clear();
46 }
47 
50  standaloneTrackRef_ = ref;
51  if (embed)
53  else
54  standaloneTrack_.clear();
55 }
56 
59  combinedTrackRef_ = ref;
60  if (embed)
61  embedCombined();
62  else
63  combinedTrack_.clear();
64 }
65 
68  gsfTrackRef_ = ref;
69  if (embed)
70  embedGsfTrack();
71  else
72  gsfTrack_.clear();
73 }
74 
77  superClusterRef_ = ref;
78  if (embed)
80  else
81  superCluster_.clear();
82 }
83 
86  caloTowerRef_ = ref;
87  if (embed) {
89  } else if (!caloTower_.empty()) {
91  }
92 }
93 
94 // ========== EMBEDDER METHODS
97  track_.clear();
98  if (trackRef_.isNonnull())
99  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())
108  tracks_.push_back(**it); // embed track
109  }
110  trackRefs_ = reco::TrackRefVector(); // clear, to save space
111 }
114  standaloneTrack_.clear();
116  standaloneTrack_.push_back(*standaloneTrackRef_); // import
117  standaloneTrackRef_ = reco::TrackRef(); // clear, to save space (zeroes compress better)
118 }
121  combinedTrack_.clear();
123  combinedTrack_.push_back(*combinedTrackRef_); // import
124  combinedTrackRef_ = reco::TrackRef(); // clear, to save space (zeroes compress better)
125 }
128  gsfTrack_.clear();
129  if (gsfTrackRef_.isNonnull())
130  gsfTrack_.push_back(*gsfTrackRef_); // import
131  gsfTrackRef_ = reco::GsfTrackRef(); // clear, to save space (zeroes compress better)
132 }
133 
136  superCluster_.clear();
138  superCluster_.push_back(*superClusterRef_); // import
139  superClusterRef_ = reco::SuperClusterRef(); // clear, to save space (zeroes compress better)
140 }
143  if (!caloTower_.empty())
145  if (caloTowerRef_.isNonnull())
146  caloTower_.push_back(*caloTowerRef_); // import
147  caloTowerRef_ = CaloTowerRef(); // clear, to save space (zeroes compress better)
148 }
149 
151  // first, kinematics & status
152  setCharge(cand.charge());
153  setP4(cand.polarP4());
154  setVertex(cand.vertex());
155  setPdgId(cand.pdgId());
156  setStatus(cand.status());
157  // then RECO part, if available
158  const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&cand);
159  if (rc != nullptr) {
160  setTrack(rc->track());
161  setGsfTrack(rc->gsfTrack());
162  setStandAloneMuon(rc->standAloneMuon());
163  setCombinedMuon(rc->combinedMuon());
164  setSuperCluster(rc->superCluster());
165  setCaloTower(rc->caloTower());
166  size_t ntracks = rc->numberOfTracks();
167  if (ntracks > 0) {
169  for (size_t i = 0; i < ntracks; ++i) {
170  tracks.push_back(rc->track(i));
171  }
172  setTracks(tracks);
173  }
174  }
175 }
176 
178  const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&cand);
179  if (rc != nullptr) {
180  if (rc->track().isNonnull() && (track() == rc->track()))
181  return true;
182  if (rc->gsfTrack().isNonnull() && (gsfTrack() == rc->gsfTrack()))
183  return true;
184  if (rc->standAloneMuon().isNonnull() && (standAloneMuon() == rc->standAloneMuon()))
185  return true;
186  if (rc->combinedMuon().isNonnull() && (combinedMuon() == rc->combinedMuon()))
187  return true;
188  if (rc->superCluster().isNonnull() && (superCluster() == rc->superCluster()))
189  return true;
190  if (rc->caloTower().isNonnull() && (caloTower() == rc->caloTower()))
191  return true;
192  }
193  const GenericParticle *rc2 = dynamic_cast<const GenericParticle *>(&cand);
194  if (rc2 != nullptr) {
195  if (rc2->track().isNonnull() && (track() == rc2->track()))
196  return true;
197  if (rc2->gsfTrack().isNonnull() && (gsfTrack() == rc2->gsfTrack()))
198  return true;
199  if (rc2->standAloneMuon().isNonnull() && (standAloneMuon() == rc2->standAloneMuon()))
200  return true;
201  if (rc2->combinedMuon().isNonnull() && (combinedMuon() == rc2->combinedMuon()))
202  return true;
203  if (rc2->superCluster().isNonnull() && (superCluster() == rc2->superCluster()))
204  return true;
205  if (rc2->caloTower().isNonnull() && (caloTower() == rc2->caloTower()))
206  return true;
207  }
208  return false;
209 }
edm::Ref< GsfTrackCollection > GsfTrackRef
persistent reference to a GsfTrack
Definition: GsfTrackFwd.h:13
reco::TrackRef track() const override
CaloTowerCollection caloTower_
reco::TrackRef standaloneTrackRef_
virtual reco::GsfTrackRef gsfTrack() const
reference to a GsfTrack
reco::TrackCollection combinedTrack_
reco::TrackCollection track_
void fillInFrom(const reco::Candidate &cand)
void swap(SortedCollection &other)
void push_back(T const &t)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
~GenericParticle() override
destructor
void embedTrack()
embeds the master track instead of keeping a reference to it
reco::TrackRef trackRef_
reco::TrackRef standAloneMuon() const override
edm::RefVector< TrackCollection > TrackRefVector
vector of reference to Track in the same collection
Definition: TrackFwd.h:29
edm::Ref< SuperClusterCollection > SuperClusterRef
reference to an object in a collection of SuperCluster objects
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)
#define embed
Definition: AMPTWrapper.h:188
void setVertex(const Point &vertex) override
set vertex
void setCharge(Charge q) final
set electric charge
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
virtual CaloTowerRef caloTower() const
reference to a CaloTower
reco::TrackCollection standaloneTrack_
void embedStandalone()
embeds the stand-alone track instead of keeping a reference to it
bool overlap(const Candidate &) const override
reco::SuperClusterCollection superCluster_
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)
CaloTowerRef caloTower() const override
reco::TrackRef combinedMuon() const override
virtual void setCaloTower(const CaloTowerRef &ref, bool embed=false)
sets calotower reference (or even embed it into the object)
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
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)
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
auto const & tracks
cannot be loose
reco::TrackCollection tracks_
void embedTracks()
embeds the other tracks instead of keeping references
reco::GsfTrackCollection gsfTrack_
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
reco::TrackRefVector trackRefs_
virtual reco::SuperClusterRef superCluster() const
reference to a SuperCluster
CaloTowerRef caloTowerRef_
fixed size matrix
reco::SuperClusterRef superCluster() const override
reco::TrackRef combinedTrackRef_
virtual reco::TrackRef track() const
reference to a Track
virtual reco::TrackRef combinedMuon() const
reference to a stand-alone muon Track
Templated PAT object container.
Definition: PATObject.h:43
void embedCaloTower()
embeds the calotower instead of keeping a reference to it
edm::Ref< CaloTowerCollection > CaloTowerRef
Definition: CaloTowerDefs.h:17
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
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:458
void setP4(const LorentzVector &p4) final
set 4-momentum
virtual void setSuperCluster(const reco::SuperClusterRef &ref, bool embed=false)
sets supercluster reference (or even embed it into the object)
virtual reco::TrackRef standAloneMuon() const
reference to a stand-alone muon Track