CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenericParticle.cc
Go to the documentation of this file.
1 //
2 // $Id: GenericParticle.cc,v 1.3 2008/07/08 20:56:48 gpetrucc Exp $
3 //
4 
6 
7 
9 
10 
12 GenericParticle::GenericParticle() :
13  PATObject<reco::RecoCandidate>()
14 {
15 }
16 
17 
20  PATObject<reco::RecoCandidate>()
21 {
22  fillInFrom(cand);
23 }
24 
25 
28  PATObject<reco::RecoCandidate>()
29 {
30  fillInFrom(*cand);
31  refToOrig_ = edm::Ptr<reco::Candidate>(cand.id(), cand.get(), cand.key()); // correct RefToBase=>Ptr conversion
32 }
33 
36  PATObject<reco::RecoCandidate>()
37 {
38  fillInFrom(*cand);
39  refToOrig_ = cand;
40 }
41 
42 
43 
46 }
47 
48 // ====== SETTERS =====
51  trackRef_ = ref;
52  if (embed) embedTrack(); else track_.clear();
53 }
54 
57  trackRefs_ = refs;
58  if (embed) embedTracks(); else tracks_.clear();
59 }
60 
63  standaloneTrackRef_ = ref;
64  if (embed) embedStandalone(); else standaloneTrack_.clear();
65 }
66 
69  combinedTrackRef_ = ref;
70  if (embed) embedCombined(); else combinedTrack_.clear();
71 }
72 
75  gsfTrackRef_ = ref;
76  if (embed) embedGsfTrack(); else gsfTrack_.clear();
77 }
78 
81  superClusterRef_ = ref;
82  if (embed) embedSuperCluster(); else superCluster_.clear();
83 }
84 
87  caloTowerRef_ = ref;
88  if (embed) {
89  embedCaloTower();
90  } else if (!caloTower_.empty()) {
92  }
93 }
94 
95 
96 // ========== EMBEDDER METHODS
99  track_.clear();
100  if (trackRef_.isNonnull()) track_.push_back(*trackRef_); // import
101  trackRef_ = reco::TrackRef(); // clear, to save space (zeroes compress better)
102 }
105  tracks_.clear();
106  tracks_.reserve(trackRefs_.size());
108  if (it->isNonnull()) tracks_.push_back(**it); // embed track
109  }
110  trackRefs_ = reco::TrackRefVector(); // clear, to save space
111 }
114  standaloneTrack_.clear();
116  standaloneTrackRef_ = reco::TrackRef(); // clear, to save space (zeroes compress better)
117 }
120  combinedTrack_.clear();
121  if (combinedTrackRef_.isNonnull()) combinedTrack_.push_back(*combinedTrackRef_); // import
122  combinedTrackRef_ = reco::TrackRef(); // clear, to save space (zeroes compress better)
123 }
126  gsfTrack_.clear();
127  if (gsfTrackRef_.isNonnull()) gsfTrack_.push_back(*gsfTrackRef_); // import
128  gsfTrackRef_ = reco::GsfTrackRef(); // clear, to save space (zeroes compress better)
129 }
130 
133  superCluster_.clear();
134  if (superClusterRef_.isNonnull()) superCluster_.push_back(*superClusterRef_); // import
135  superClusterRef_ = reco::SuperClusterRef(); // clear, to save space (zeroes compress better)
136 }
141  caloTowerRef_ = CaloTowerRef(); // clear, to save space (zeroes compress better)
142 }
143 
144 
146  // first, kinematics & status
147  setCharge(cand.charge());
148  setP4(cand.polarP4());
149  setVertex(cand.vertex());
150  setPdgId(cand.pdgId());
151  setStatus(cand.status());
152  // then RECO part, if available
153  const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&cand);
154  if (rc != 0) {
155  setTrack(rc->track());
156  setGsfTrack(rc->gsfTrack());
157  setStandAloneMuon(rc->standAloneMuon());
158  setCombinedMuon(rc->combinedMuon());
159  setSuperCluster(rc->superCluster());
160  setCaloTower(rc->caloTower());
161  size_t ntracks = rc->numberOfTracks();
162  if (ntracks > 0) {
164  for (size_t i = 0; i < ntracks; ++i) {
165  tracks.push_back(rc->track(i));
166  }
167  setTracks(tracks);
168  }
169  }
170 }
171 
172 bool GenericParticle::overlap( const reco::Candidate &cand ) const {
173  const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&cand);
174  if (rc != 0) {
175  if (rc->track().isNonnull() && (track() == rc->track())) return true;
176  if (rc->gsfTrack().isNonnull() && (gsfTrack() == rc->gsfTrack())) return true;
177  if (rc->standAloneMuon().isNonnull() && (standAloneMuon() == rc->standAloneMuon())) return true;
178  if (rc->combinedMuon().isNonnull() && (combinedMuon() == rc->combinedMuon())) return true;
179  if (rc->superCluster().isNonnull() && (superCluster() == rc->superCluster())) return true;
180  if (rc->caloTower().isNonnull() && (caloTower() == rc->caloTower())) return true;
181  }
182  const GenericParticle *rc2 = dynamic_cast<const GenericParticle *>(&cand);
183  if (rc2 != 0) {
184  if (rc2->track().isNonnull() && (track() == rc2->track())) return true;
185  if (rc2->gsfTrack().isNonnull() && (gsfTrack() == rc2->gsfTrack())) return true;
186  if (rc2->standAloneMuon().isNonnull() && (standAloneMuon() == rc2->standAloneMuon())) return true;
187  if (rc2->combinedMuon().isNonnull() && (combinedMuon() == rc2->combinedMuon())) return true;
188  if (rc2->superCluster().isNonnull() && (superCluster() == rc2->superCluster())) return true;
189  if (rc2->caloTower().isNonnull() && (caloTower() == rc2->caloTower())) return true;
190  }
191  return false;
192 }
edm::Ref< GsfTrackCollection > GsfTrackRef
persistent reference to a GsfTrack
Definition: GsfTrackFwd.h:13
virtual reco::GsfTrackRef gsfTrack() const
reference to a GsfTrack
int i
Definition: DBlmapReader.cc:9
CaloTowerCollection caloTower_
reco::TrackRef standaloneTrackRef_
virtual reco::TrackRef combinedMuon() const
virtual bool overlap(const Candidate &) const
reco::TrackCollection combinedTrack_
reco::TrackCollection track_
virtual void setCharge(Charge q)
set electric charge
void fillInFrom(const reco::Candidate &cand)
virtual void setStatus(int status)
set status word
virtual int status() const =0
status word
void swap(SortedCollection &other)
void push_back(T const &t)
virtual void setP4(const LorentzVector &p4)
set 4-momentum
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
ProductID id() const
Definition: RefToBase.h:215
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:242
edm::RefVector< TrackCollection > TrackRefVector
vector of reference to Track in the same collection
Definition: TrackFwd.h:18
virtual const PolarLorentzVector & polarP4() const =0
four-momentum Lorentz vector
edm::Ref< SuperClusterCollection > SuperClusterRef
reference to an object in a collection of SuperCluster objects
GenericParticle()
default constructor
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:237
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
virtual reco::TrackRef track() const
reference to a Track
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:248
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_
virtual reco::TrackRef standAloneMuon() const
virtual CaloTowerRef caloTower() const
reference to a CaloTower
reco::GsfTrackRef gsfTrackRef_
reco::SuperClusterRef superClusterRef_
virtual CaloTowerRef caloTower() const
virtual const Point & vertex() const =0
vertex position
virtual int charge() const =0
electric charge
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)
size_t key() const
Definition: RefToBase.h:223
virtual void setVertex(const Point &vertex)
set vertex
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...
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 int pdgId() const =0
PDG identifier.
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_
virtual ~GenericParticle()
destructor
tuple tracks
Definition: testEve_cfg.py:39
virtual reco::GsfTrackRef gsfTrack() const
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
reco::TrackRefVector trackRefs_
CaloTowerRef caloTowerRef_
reco::TrackRef combinedTrackRef_
edm::SortedCollection< CaloTower > CaloTowerCollection
Definition: CaloTowerFwd.h:15
virtual void setPdgId(int pdgId)
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:61
size_type size() const
Size of the RefVector.
Definition: RefVector.h:85
Templated PAT object container.
Definition: PATObject.h:42
void embedCaloTower()
embeds the calotower instead of keeping a reference to it
virtual reco::SuperClusterRef superCluster() const
edm::Ref< CaloTowerCollection > CaloTowerRef
Definition: CaloTowerFwd.h:16
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)
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:394
value_type const * get() const
Definition: RefToBase.h:207
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