CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PackedCandidate.h
Go to the documentation of this file.
1 #ifndef __DataFormats_PatCandidates_PackedCandidate_h__
2 #define __DataFormats_PatCandidates_PackedCandidate_h__
3 
12 /* #include "DataFormats/Math/interface/PtEtaPhiMass.h" */
13 
14 namespace pat {
16  public:
27 
28  typedef unsigned int index;
29 
33  explicit PackedCandidate( const reco::Candidate & c, const reco::VertexRef &pv)
35 
36  explicit PackedCandidate( const PolarLorentzVector &p4, const Point &vtx, float phiAtVtx, int pdgId, const reco::VertexRef &pv)
38 
39  explicit PackedCandidate( const LorentzVector &p4, const Point &vtx, float phiAtVtx, int pdgId, const reco::VertexRef &pv)
40  : p4_(p4.Pt(), p4.Eta(), p4.Phi(), p4.M()), p4c_(p4), vertex_(vtx), dphi_(reco::deltaPhi(phiAtVtx,p4_.phi())), pdgId_(pdgId), qualityFlags_(0), pvRef_(pv), unpacked_(true), unpackedVtx_(true), unpackedTrk_(false),dxydxy_(0),dzdz_(0),dxydz_(0),dlambdadz_(0),dphidxy_(0),packedHits_(0),normalizedChi2_(0) { packBoth(); }
41 
42 
43 
44 
46  virtual ~PackedCandidate();
48  virtual const_iterator begin() const;
50  virtual const_iterator end() const;
52  virtual iterator begin();
54  virtual iterator end();
56  virtual size_t numberOfDaughters() const;
58  virtual const reco::Candidate * daughter( size_type ) const;
60  virtual size_t numberOfMothers() const;
62  virtual const reco::Candidate * mother( size_type ) const;
64  virtual reco::Candidate * daughter( size_type );
66  virtual reco::Candidate * daughter(const std::string& s );
68  virtual const reco::Candidate * daughter(const std::string& s ) const;
71  virtual size_t numberOfSourceCandidatePtrs() const {return 0;}
75  return reco::CandidatePtr();
76  }
77 
79  virtual int charge() const {
80  switch (abs(pdgId_)) {
81  case 211: return (pdgId_>0)-(pdgId_<0);
82  case 11: return (-1)*(pdgId_>0)-(pdgId_<0); //e
83  case 13: return (-1)*(pdgId_>0)-(pdgId_<0); //mu
84  case 15: return (-1)*(pdgId_>0)-(pdgId_<0); //tau
85  case 24: return (-1)*(pdgId_>0)-(pdgId_<0); //W
86  default: return 0; //FIXME: charge is not defined
87  }
88  }
90  virtual void setCharge( int charge) {}
92  virtual int threeCharge() const {return charge()*3;}
94  virtual void setThreeCharge( int threecharge) {}
96  virtual const LorentzVector & p4() const { if (!unpacked_) unpack(); return p4c_; }
98  virtual const PolarLorentzVector & polarP4() const { if (!unpacked_) unpack(); return p4_; }
100  virtual Vector momentum() const { if (!unpacked_) unpack(); return p4c_.Vect(); }
103  virtual Vector boostToCM() const { if (!unpacked_) unpack(); return p4c_.BoostToCM(); }
105  virtual double p() const { if (!unpacked_) unpack(); return p4c_.P(); }
107  virtual double energy() const { if (!unpacked_) unpack(); return p4c_.E(); }
109  virtual double et() const { if (!unpacked_) unpack(); return p4_.Et(); }
111  virtual float mass() const { if (!unpacked_) unpack(); return p4_.M(); }
113  virtual float massSqr() const { if (!unpacked_) unpack(); return p4_.M()*p4_.M(); }
114 
116  virtual double mt() const { if (!unpacked_) unpack(); return p4_.Mt(); }
118  virtual double mtSqr() const { if (!unpacked_) unpack(); return p4_.Mt2(); }
120  virtual double px() const { if (!unpacked_) unpack(); return p4c_.Px(); }
122  virtual double py() const { if (!unpacked_) unpack(); return p4c_.Py(); }
124  virtual double pz() const { if (!unpacked_) unpack(); return p4c_.Pz(); }
126  virtual float pt() const { if (!unpacked_) unpack(); return p4_.Pt();}
128  virtual float phi() const { if (!unpacked_) unpack(); return p4_.Phi(); }
130  virtual float phiAtVtx() const {
131  maybeUnpackBoth();
132  float ret = p4_.Phi() + dphi_;
133  while (ret > float(M_PI)) ret -= 2*float(M_PI);
134  while (ret < -float(M_PI)) ret += 2*float(M_PI);
135  return ret;
136  }
138  virtual double theta() const { if (!unpacked_) unpack(); return p4_.Theta(); }
140  virtual float eta() const { if (!unpacked_) unpack(); return p4_.Eta(); }
142  virtual double rapidity() const { if (!unpacked_) unpack(); return p4_.Rapidity(); }
144  virtual double y() const { if (!unpacked_) unpack(); return p4_.Rapidity(); }
146  virtual void setP4( const LorentzVector & p4 ) {
147  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
148  p4_ = PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M());
149  packBoth();
150  }
152  virtual void setP4( const PolarLorentzVector & p4 ) {
153  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
154  p4_ = p4;
155  packBoth();
156  }
158  virtual void setMass( double m ) {
159  if (!unpacked_) unpack();
160  p4_ = PolarLorentzVector(p4_.Pt(), p4_.Eta(), p4_.Phi(), m);
161  pack();
162  }
163  virtual void setPz( double pz ) {
164  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
165  p4c_ = LorentzVector(p4c_.Px(), p4c_.Py(), pz, p4c_.E());
166  p4_ = PolarLorentzVector(p4c_.Pt(), p4c_.Eta(), p4c_.Phi(), p4c_.M());
167  packBoth();
168  }
170 
171  virtual void setTrackProperties( const reco::Track & tk, const reco::Track::CovarianceMatrix & covariance) {
172  dxydxy_ = covariance(3,3);
173  dxydz_ = covariance(3,4);
174  dzdz_ = covariance(4,4);
175  dphidxy_ = covariance(2,3);
176  dlambdadz_ = covariance(1,4);
177  dptdpt_ = covariance(0,0)*pt()*pt();
178  detadeta_ = covariance(1,1);
179  dphidphi_ = covariance(2,2)*pt()*pt();
180 
182  int numberOfPixelHits_ = tk.hitPattern().numberOfValidPixelHits();
183  if (numberOfPixelHits_ > 7) numberOfPixelHits_ = 7;
184  int numberOfStripHits_ = tk.hitPattern().numberOfValidHits() - numberOfPixelHits_;
185  if (numberOfStripHits_ > 31) numberOfStripHits_ = 31;
186  packedHits_ = (numberOfPixelHits_&0x7) | (numberOfStripHits_ << 3);
187  packBoth();
188  }
189 
190  virtual void setTrackProperties( const reco::Track & tk ) {
192  }
193 
194  int numberOfPixelHits() const { return packedHits_ & 0x7; }
195  int numberOfHits() const { return (packedHits_ >> 3) + numberOfPixelHits(); }
196 
198  virtual const Point & vertex() const { maybeUnpackBoth(); return vertex_; }//{ if (fromPV_) return Point(0,0,0); else return Point(0,0,100); }
200  virtual double vx() const { maybeUnpackBoth(); return vertex_.X(); }//{ return 0; }
202  virtual double vy() const { maybeUnpackBoth(); return vertex_.Y(); }//{ return 0; }
204  virtual double vz() const { maybeUnpackBoth(); return vertex_.Z(); }//{ if (fromPV_) return 0; else return 100; }
206  virtual void setVertex( const Point & vertex ) { maybeUnpackBoth(); vertex_ = vertex; packVtx(); }
207 
208  enum PVAssoc { NoPV=0, PVLoose=1, PVTight=2, PVUsedInFit=3 } ;
209  const PVAssoc fromPV() const { return PVAssoc((qualityFlags_ & fromPVMask)>>fromPVShift); }
211 
214  const reco::VertexRef vertexRef() const { return pvRef_; }
215 
217  virtual float dxy() const { maybeUnpackBoth(); return dxy_; }
219  virtual float dz() const { maybeUnpackBoth(); return dz_; }
221  virtual float dxy(const Point &p) const ;
223  virtual float dz(const Point &p) const ;
224 
226  virtual float dzError() const { maybeUnpackBoth(); return sqrt(dzdz_); }
228  virtual float dxyError() const { maybeUnpackBoth(); return sqrt(dxydxy_); }
229 
230 
232  virtual const reco::Track & pseudoTrack() const { if (!unpackedTrk_) unpackTrk(); return track_; }
233 
235  virtual const reco::Track * bestTrack() const {
236  if (packedHits_!=0) {
237  if (!unpackedTrk_) unpackTrk();
238  return &track_;
239  }
240  else
241  return nullptr;
242  }
243 
248 
252  noLostInnerHits=0, // it could still not have a hit in the first layer, e.g. if it crosses an inactive sensor
255  };
258  }
260  int lost = hits; if (lost > 2) lost = 2; // protection against misuse
261  lost++; // shift so it's 0 .. 3 instead of (-1) .. 2
263  }
264 
265  void setMuonID(bool isStandAlone, bool isGlobal) {
266  int16_t muonFlags = isStandAlone | (2*isGlobal);
268  }
269 
271  virtual int pdgId() const { return pdgId_; }
272  // set PDG identifier
273  virtual void setPdgId( int pdgId ) { pdgId_ = pdgId; }
275  virtual int status() const { return qualityFlags_; } /*FIXME*/
277  virtual void setStatus( int status ) {} /*FIXME*/
279  static const unsigned int longLivedTag = 0; /*FIXME*/
281  virtual void setLongLived() {} /*FIXME*/
283  virtual bool longLived() const;
285  static const unsigned int massConstraintTag = 0; /*FIXME*/
287  virtual void setMassConstraint() {} /*FIXME*/
289  virtual bool massConstraint() const;
290 
292  virtual PackedCandidate * clone() const {
293  return new PackedCandidate( *this );
294  }
295 
297  virtual double vertexChi2() const;
304  virtual double vertexNdof() const;
306  virtual double vertexNormalizedChi2() const;
308  virtual double vertexCovariance(int i, int j) const;
312  virtual void fillVertexCovariance(CovarianceMatrix & v) const;
315  virtual bool hasMasterClone() const;
318  virtual const reco::CandidateBaseRef & masterClone() const;
321  virtual bool hasMasterClonePtr() const;
324 
325  virtual const reco::CandidatePtr & masterClonePtr() const;
326 
328  template<typename Ref>
329  Ref masterRef() const { return masterClone().template castTo<Ref>(); }
331 
332  /* template<typename T> T get() const { */
333  /* if ( hasMasterClone() ) return masterClone()->get<T>(); */
334  /* else return reco::get<T>( * this ); */
335  /* } */
336  /* /// get a component */
337  /* template<typename T, typename Tag> T get() const { */
338  /* if ( hasMasterClone() ) return masterClone()->get<T, Tag>(); */
339  /* else return reco::get<T, Tag>( * this ); */
340  /* } */
341  /* /// get a component */
342  /* template<typename T> T get( size_type i ) const { */
343  /* if ( hasMasterClone() ) return masterClone()->get<T>( i ); */
344  /* else return reco::get<T>( * this, i ); */
345  /* } */
346  /* /// get a component */
347  /* template<typename T, typename Tag> T get( size_type i ) const { */
348  /* if ( hasMasterClone() ) return masterClone()->get<T, Tag>( i ); */
349  /* else return reco::get<T, Tag>( * this, i ); */
350  /* } */
351  /* /// number of components */
352  /* template<typename T> size_type numberOf() const { */
353  /* if ( hasMasterClone() ) return masterClone()->numberOf<T>(); */
354  /* else return reco::numberOf<T>( * this ); */
355  /* } */
356  /* /// number of components */
357  /* template<typename T, typename Tag> size_type numberOf() const { */
358  /* if ( hasMasterClone() ) return masterClone()->numberOf<T, Tag>(); */
359  /* else return reco::numberOf<T, Tag>( * this ); */
360  /* } */
361 
362  /* template<typename S> */
363  /* struct daughter_iterator { */
364  /* typedef boost::filter_iterator<S, const_iterator> type; */
365  /* }; */
366 
367  /* template<typename S> */
368  /* typename daughter_iterator<S>::type beginFilter( const S & s ) const { */
369  /* return boost::make_filter_iterator(s, begin(), end()); */
370  /* } */
371  /* template<typename S> */
372  /* typename daughter_iterator<S>::type endFilter( const S & s ) const { */
373  /* return boost::make_filter_iterator(s, end(), end()); */
374  /* } */
375 
376 
377  virtual bool isElectron() const { return false; }
378  virtual bool isMuon() const { return false; }
379  virtual bool isStandAloneMuon() const { return ((qualityFlags_ & muonFlagsMask) >> muonFlagsShift) & 1; }
380  virtual bool isGlobalMuon() const { return ((qualityFlags_ & muonFlagsMask) >> muonFlagsShift) & 2; }
381  virtual bool isTrackerMuon() const { return false; }
382  virtual bool isCaloMuon() const { return false; }
383  virtual bool isPhoton() const { return false; }
384  virtual bool isConvertedPhoton() const { return false; }
385  virtual bool isJet() const { return false; }
386 
387  protected:
393  void pack(bool unpackAfterwards=true) ;
394  void unpack() const ;
395  void packVtx(bool unpackAfterwards=true) ;
396  void unpackVtx() const ;
397  void maybeUnpackBoth() const { if (!unpacked_) unpack(); if (!unpackedVtx_) unpackVtx(); }
398  void packBoth() { pack(false); packVtx(false); unpack(); unpackVtx(); } // do it this way, so that we don't loose precision on the angles before computing dxy,dz
399  void unpackTrk() const ;
400 
405  mutable Point vertex_;
406  mutable float dxy_, dz_, dphi_;
410  int pdgId_;
411  uint16_t qualityFlags_;
414  // is the momentum p4 unpacked
415  mutable bool unpacked_;
416  // are the dxy, dz and vertex unpacked
417  mutable bool unpackedVtx_;
418  // is the track unpacked
419  mutable bool unpackedTrk_;
422  uint8_t packedHits_;
424  uint8_t normalizedChi2_;
425 // uint8_t numberOfPixelHits_;
426  // uint8_t numberOfHits_;
427 
429  virtual bool overlap( const reco::Candidate & ) const;
430  template<typename, typename, typename> friend struct component;
431  friend class ::OverlapChecker;
432  friend class ShallowCloneCandidate;
434 
440  };
441  private:
442  // const iterator implementation
444  // iterator implementation
446  };
447 
448  typedef std::vector<pat::PackedCandidate> PackedCandidateCollection;
451 }
452 
453 #endif
virtual void setP4(const LorentzVector &p4)
set 4-momentum
void setMuonID(bool isStandAlone, bool isGlobal)
virtual void setVertex(const Point &vertex)
set vertex
int i
Definition: DBlmapReader.cc:9
virtual void setTrackProperties(const reco::Track &tk, const reco::Track::CovarianceMatrix &covariance)
set impact parameters covariance
virtual size_t numberOfMothers() const
number of mothers
virtual bool hasMasterClonePtr() const
virtual float phi() const
momentum azimuthal angle
virtual void setPdgId(int pdgId)
virtual float massSqr() const
mass squared
math::XYZVector Vector
point in the space
Definition: Candidate.h:47
virtual float dzError() const
uncertainty on dz
int numberOfHits() const
size_t size_type
Definition: Candidate.h:34
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:609
void setFromPV(PVAssoc fromPV)
virtual const reco::Track * bestTrack() const
return a pointer to the track if present. otherwise, return a null pointer
PackedCandidate(const PolarLorentzVector &p4, const Point &vtx, float phiAtVtx, int pdgId, const reco::VertexRef &pv)
candidate::const_iterator const_iterator
Definition: Candidate.h:35
virtual const_iterator begin() const
first daughter const_iterator
virtual bool isCaloMuon() const
void maybeUnpackBoth() const
static const unsigned int longLivedTag
long lived flag
int numberOfValidHits() const
Definition: HitPattern.h:734
virtual double y() const
rapidity
virtual void fillVertexCovariance(CovarianceMatrix &v) const
fill SMatrix
static const unsigned int massConstraintTag
do mass constraint flag
virtual double mtSqr() const
transverse mass squared
std::vector< pat::PackedCandidate > PackedCandidateCollection
math::XYZPoint Point
point in the space
virtual double vertexNdof() const
virtual void setStatus(int status)
set status word
virtual double vx() const
x coordinate of vertex position
virtual bool overlap(const reco::Candidate &) const
check overlap with another Candidate
virtual bool isPhoton() const
virtual void setP4(const PolarLorentzVector &p4)
set 4-momentum
virtual float pt() const
transverse momentum
const reco::VertexRef vertexRef() const
void unpackVtx() const
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Ref masterRef() const
cast master clone reference to a concrete type
PolarLorentzVector p4_
the four vector
void setVertexRef(const reco::VertexRef &vertexRef)
set reference to the primary vertex
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
reco::CandidateCollection daughters
collection of daughter candidates
virtual const reco::Candidate * daughter(size_type) const
return daughter at a given position (throws an exception)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual void setTrackProperties(const reco::Track &tk)
virtual bool isTrackerMuon() const
virtual void setLongLived()
set long lived flag
virtual bool isConvertedPhoton() const
friend struct component
virtual void setMassConstraint()
set mass constraint flag
virtual bool isMuon() const
reco::Track track_
reco::Track
virtual PackedCandidate * clone() const
returns a clone of the Candidate object
math::XYZTLorentzVector LorentzVector
Lorentz vector.
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:779
T sqrt(T t)
Definition: SSEVec.h:48
virtual double py() const
y coordinate of momentum vector
bool trackHighPurity() const
true if the track had the highPurity quality bit
LostInnerHits lostInnerHits() const
virtual int status() const
status word
PackedCandidate()
default constructor
virtual double rapidity() const
rapidity
math::XYZPoint Point
virtual const reco::CandidateBaseRef & masterClone() const
edm::Ref< pat::PackedCandidateCollection > PackedCandidateRef
friend class ShallowCloneCandidate
virtual double energy() const
energy
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual bool isJet() const
int j
Definition: DBlmapReader.cc:9
virtual int charge() const
electric charge
virtual const reco::Track & pseudoTrack() const
Return reference to a pseudo track made with candidate kinematics, parameterized error for eta...
virtual double theta() const
momentum polar angle
virtual int threeCharge() const
electric charge
virtual double vertexNormalizedChi2() const
chi-squared divided by n.d.o.f.
Point vertex_
vertex position
virtual void setThreeCharge(int threecharge)
set electric charge
virtual double et() const
transverse energy
virtual void setPz(double pz)
virtual double mt() const
transverse mass
int numberOfPixelHits() const
virtual const reco::CandidatePtr & masterClonePtr() const
#define M_PI
virtual double vy() const
y coordinate of vertex position
virtual const PolarLorentzVector & polarP4() const
four-momentum Lorentz vector
LostInnerHits
Enumerator specifying the.
uint8_t normalizedChi2_
track quality information
candidate::iterator iterator
Definition: Candidate.h:36
virtual size_t numberOfSourceCandidatePtrs() const
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
virtual Vector momentum() const
spatial momentum vector
virtual bool isGlobalMuon() const
PackedCandidate(const LorentzVector &p4, const Point &vtx, float phiAtVtx, int pdgId, const reco::VertexRef &pv)
virtual bool massConstraint() const
do mass constraint?
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:384
float dxydxy_
IP covariance.
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
edm::RefVector< pat::PackedCandidateCollection > PackedCandidateRefVector
edm::Ref< reco::VertexCollection > pvRef_
Ref to primary vertex.
virtual Vector boostToCM() const
uint16_t packedCovarianceDxyDxy_
virtual double vz() const
z coordinate of vertex position
reco::candidate::const_iterator_imp_specific< daughters > const_iterator_imp_specific
virtual void setMass(double m)
set particle mass
virtual reco::CandidatePtr sourceCandidatePtr(size_type i) const
virtual float phiAtVtx() const
momentum azimuthal angle from the track (normally identical to phi())
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
int pdgId_
PDG identifier.
virtual const Point & vertex() const
vertex position
virtual size_t numberOfDaughters() const
number of daughters
CovarianceMatrix vertexCovariance() const
return SMatrix
virtual bool isStandAloneMuon() const
friend class ShallowClonePtrCandidate
virtual bool longLived() const
is long lived?
virtual const reco::Candidate * mother(size_type) const
return mother at a given position (throws an exception)
virtual void setCharge(int charge)
set electric charge
virtual float mass() const
mass
void packVtx(bool unpackAfterwards=true)
void setLostInnerHits(LostInnerHits hits)
int numberOfValidPixelHits() const
Definition: HitPattern.h:749
virtual const LorentzVector & p4() const
four-momentum Lorentz vecto r
math::XYZPoint Point
point in the space
Definition: Candidate.h:45
void pack(bool unpackAfterwards=true)
virtual bool isElectron() const
get a component
virtual double px() const
x coordinate of momentum vector
volatile std::atomic< bool > shutdown_flag false
virtual float eta() const
momentum pseudorapidity
virtual float dxy() const
dxy with respect to the PV ref
virtual const_iterator end() const
last daughter const_iterator
virtual double vertexChi2() const
chi-squares
void setTrackHighPurity(bool highPurity)
set to true if the track had the highPurity quality bit
const PVAssoc fromPV() const
virtual ~PackedCandidate()
destructor
virtual int pdgId() const
PDG identifier.
virtual double pz() const
z coordinate of momentum vector
virtual float dxyError() const
uncertainty on dxy
reco::candidate::iterator_imp_specific< daughters > iterator_imp_specific
virtual float dz() const
dz with respect to the PV ref
math::XYZVector Vector
point in the space
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:76
virtual double p() const
magnitude of momentum vector
virtual bool hasMasterClone() const
PackedCandidate(const reco::Candidate &c, const reco::VertexRef &pv)
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:43