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 
11 /* #include "DataFormats/Math/interface/PtEtaPhiMass.h" */
12 
13 namespace pat {
15  public:
26 
27  typedef unsigned int index;
28 
32  explicit PackedCandidate( const reco::Candidate & c, const reco::VertexRef &pv)
34 
35  explicit PackedCandidate( const PolarLorentzVector &p4, const Point &vtx, float phiAtVtx, int pdgId, const reco::VertexRef &pv)
37 
38  explicit PackedCandidate( const LorentzVector &p4, const Point &vtx, float phiAtVtx, int pdgId, const reco::VertexRef &pv)
39  : 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),dptdpt_(0),detadeta_(0),dphidphi_(0),packedHits_(0),normalizedChi2_(0) { packBoth(); }
40 
41 
42 
43 
45  virtual ~PackedCandidate();
47  virtual size_t numberOfDaughters() const;
49  virtual const reco::Candidate * daughter( size_type ) const;
51  virtual size_t numberOfMothers() const;
53  virtual const reco::Candidate * mother( size_type ) const;
55  virtual reco::Candidate * daughter( size_type );
57  virtual reco::Candidate * daughter(const std::string& s );
59  virtual const reco::Candidate * daughter(const std::string& s ) const;
62  virtual size_t numberOfSourceCandidatePtrs() const {return 0;}
66  return reco::CandidatePtr();
67  }
68 
70  virtual int charge() const {
71  switch (abs(pdgId_)) {
72  case 211: return (pdgId_>0)-(pdgId_<0);
73  case 11: return (-1)*(pdgId_>0)+(pdgId_<0); //e
74  case 13: return (-1)*(pdgId_>0)+(pdgId_<0); //mu
75  case 15: return (-1)*(pdgId_>0)+(pdgId_<0); //tau
76  case 24: return (pdgId_>0)-(pdgId_<0); //W
77  default: return 0; //FIXME: charge is not defined
78  }
79  }
81  virtual void setCharge( int charge) {}
83  virtual int threeCharge() const {return charge()*3;}
85  virtual void setThreeCharge( int threecharge) {}
87  virtual const LorentzVector & p4() const { if (!unpacked_) unpack(); return p4c_; }
89  virtual const PolarLorentzVector & polarP4() const { if (!unpacked_) unpack(); return p4_; }
91  virtual Vector momentum() const { if (!unpacked_) unpack(); return p4c_.Vect(); }
94  virtual Vector boostToCM() const { if (!unpacked_) unpack(); return p4c_.BoostToCM(); }
96  virtual double p() const { if (!unpacked_) unpack(); return p4c_.P(); }
98  virtual double energy() const { if (!unpacked_) unpack(); return p4c_.E(); }
100  double et() const { return (pt()<=0) ? 0 : p4c_.Et(); }
102  double et2() const { return (pt()<=0) ? 0 : p4c_.Et2(); }
104  virtual double mass() const { if (!unpacked_) unpack(); return p4_.M(); }
106  virtual double massSqr() const { if (!unpacked_) unpack(); return p4_.M()*p4_.M(); }
107 
109  virtual double mt() const { if (!unpacked_) unpack(); return p4_.Mt(); }
111  virtual double mtSqr() const { if (!unpacked_) unpack(); return p4_.Mt2(); }
113  virtual double px() const { if (!unpacked_) unpack(); return p4c_.Px(); }
115  virtual double py() const { if (!unpacked_) unpack(); return p4c_.Py(); }
117  virtual double pz() const { if (!unpacked_) unpack(); return p4c_.Pz(); }
119  virtual double pt() const { if (!unpacked_) unpack(); return p4_.Pt();}
121  virtual double phi() const { if (!unpacked_) unpack(); return p4_.Phi(); }
123  virtual float phiAtVtx() const {
124  maybeUnpackBoth();
125  float ret = p4_.Phi() + dphi_;
126  while (ret > float(M_PI)) ret -= 2*float(M_PI);
127  while (ret < -float(M_PI)) ret += 2*float(M_PI);
128  return ret;
129  }
131  virtual double theta() const { if (!unpacked_) unpack(); return p4_.Theta(); }
133  virtual double eta() const { if (!unpacked_) unpack(); return p4_.Eta(); }
135  virtual double rapidity() const { if (!unpacked_) unpack(); return p4_.Rapidity(); }
137  virtual double y() const { if (!unpacked_) unpack(); return p4_.Rapidity(); }
139  virtual void setP4( const LorentzVector & p4 ) {
140  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
141  p4_ = PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M());
142  packBoth();
143  }
145  virtual void setP4( const PolarLorentzVector & p4 ) {
146  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
147  p4_ = p4;
148  packBoth();
149  }
151  virtual void setMass( double m ) {
152  if (!unpacked_) unpack();
153  p4_ = PolarLorentzVector(p4_.Pt(), p4_.Eta(), p4_.Phi(), m);
154  pack();
155  }
156  virtual void setPz( double pz ) {
157  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
158  p4c_ = LorentzVector(p4c_.Px(), p4c_.Py(), pz, p4c_.E());
159  p4_ = PolarLorentzVector(p4c_.Pt(), p4c_.Eta(), p4c_.Phi(), p4c_.M());
160  packBoth();
161  }
163 
164  virtual void setTrackProperties( const reco::Track & tk, const reco::Track::CovarianceMatrix & covariance) {
165  dxydxy_ = covariance(3,3);
166  dxydz_ = covariance(3,4);
167  dzdz_ = covariance(4,4);
168  dphidxy_ = covariance(2,3);
169  dlambdadz_ = covariance(1,4);
170  dptdpt_ = covariance(0,0)*pt()*pt();
171  detadeta_ = covariance(1,1);
172  dphidphi_ = covariance(2,2)*pt()*pt();
173 
175  int numberOfPixelHits_ = tk.hitPattern().numberOfValidPixelHits();
176  if (numberOfPixelHits_ > 7) numberOfPixelHits_ = 7;
177  int numberOfStripHits_ = tk.hitPattern().numberOfValidHits() - numberOfPixelHits_;
178  if (numberOfStripHits_ > 31) numberOfStripHits_ = 31;
179  packedHits_ = (numberOfPixelHits_&0x7) | (numberOfStripHits_ << 3);
180  packBoth();
181  }
182 
183  virtual void setTrackProperties( const reco::Track & tk ) {
185  }
186 
187  int numberOfPixelHits() const { return packedHits_ & 0x7; }
188  int numberOfHits() const { return (packedHits_ >> 3) + numberOfPixelHits(); }
189 
191  virtual const Point & vertex() const { maybeUnpackBoth(); return vertex_; }//{ if (fromPV_) return Point(0,0,0); else return Point(0,0,100); }
193  virtual double vx() const { maybeUnpackBoth(); return vertex_.X(); }//{ return 0; }
195  virtual double vy() const { maybeUnpackBoth(); return vertex_.Y(); }//{ return 0; }
197  virtual double vz() const { maybeUnpackBoth(); return vertex_.Z(); }//{ if (fromPV_) return 0; else return 100; }
199  virtual void setVertex( const Point & vertex ) { maybeUnpackBoth(); vertex_ = vertex; packVtx(); }
200 
202  enum PVAssoc { NoPV=0, PVLoose=1, PVTight=2, PVUsedInFit=3 } ;
203  const PVAssoc fromPV(size_t ipv=0) const {
204  if(pvAssociationQuality()==UsedInFitTight and pvRef_.key()==ipv) return PVUsedInFit;
205  if(pvRef_.key()==ipv or abs(pdgId())==13 or abs(pdgId())==11 ) return PVTight;
206  if(pvAssociationQuality() == CompatibilityBTag and std::abs(dzAssociatedPV()) > std::abs(dz(ipv))) return PVTight; // it is not closest, but at least prevents the B assignment stealing
207  if(pvAssociationQuality() < UsedInFitLoose or pvRef_->ndof() < 4.0 ) return PVLoose;
208  return NoPV;
209  }
210 
216 
219  const reco::VertexRef vertexRef() const { return pvRef_; }
220 
222  virtual float dxy() const { maybeUnpackBoth(); return dxy_; }
224  virtual float dz(size_t ipv=0) const { maybeUnpackBoth(); return dz_+pvRef_->position().z()-(*pvRef_.product())[ipv].position().z(); }
226  virtual float dzAssociatedPV() const { maybeUnpackBoth(); return dz_; }
228  virtual float dxy(const Point &p) const ;
230  virtual float dz(const Point &p) const ;
231 
233  virtual float dzError() const { maybeUnpackBoth(); return sqrt(dzdz_); }
235  virtual float dxyError() const { maybeUnpackBoth(); return sqrt(dxydxy_); }
236 
237 
239  virtual const reco::Track & pseudoTrack() const { if (!unpackedTrk_) unpackTrk(); return track_; }
240 
242  virtual const reco::Track * bestTrack() const {
243  if (packedHits_!=0) {
244  if (!unpackedTrk_) unpackTrk();
245  return &track_;
246  }
247  else
248  return nullptr;
249  }
250 
255 
259  noLostInnerHits=0, // it could still not have a hit in the first layer, e.g. if it crosses an inactive sensor
262  };
265  }
267  int lost = hits; if (lost > 2) lost = 2; // protection against misuse
268  lost++; // shift so it's 0 .. 3 instead of (-1) .. 2
270  }
271 
272  void setMuonID(bool isStandAlone, bool isGlobal) {
273  int16_t muonFlags = isStandAlone | (2*isGlobal);
275  }
276 
278  virtual int pdgId() const { return pdgId_; }
279  // set PDG identifier
280  virtual void setPdgId( int pdgId ) { pdgId_ = pdgId; }
282  virtual int status() const { return qualityFlags_; } /*FIXME*/
284  virtual void setStatus( int status ) {} /*FIXME*/
286  static const unsigned int longLivedTag = 0; /*FIXME*/
288  virtual void setLongLived() {} /*FIXME*/
290  virtual bool longLived() const;
292  static const unsigned int massConstraintTag = 0; /*FIXME*/
294  virtual void setMassConstraint() {} /*FIXME*/
296  virtual bool massConstraint() const;
297 
299  virtual PackedCandidate * clone() const {
300  return new PackedCandidate( *this );
301  }
302 
304  virtual double vertexChi2() const;
311  virtual double vertexNdof() const;
313  virtual double vertexNormalizedChi2() const;
315  virtual double vertexCovariance(int i, int j) const;
319  virtual void fillVertexCovariance(CovarianceMatrix & v) const;
322  virtual bool hasMasterClone() const;
325  virtual const reco::CandidateBaseRef & masterClone() const;
328  virtual bool hasMasterClonePtr() const;
331 
332  virtual const reco::CandidatePtr & masterClonePtr() const;
333 
335  template<typename Ref>
336  Ref masterRef() const { return masterClone().template castTo<Ref>(); }
337 
338  virtual bool isElectron() const { return false; }
339  virtual bool isMuon() const { return false; }
340  virtual bool isStandAloneMuon() const { return ((qualityFlags_ & muonFlagsMask) >> muonFlagsShift) & 1; }
341  virtual bool isGlobalMuon() const { return ((qualityFlags_ & muonFlagsMask) >> muonFlagsShift) & 2; }
342  virtual bool isTrackerMuon() const { return false; }
343  virtual bool isCaloMuon() const { return false; }
344  virtual bool isPhoton() const { return false; }
345  virtual bool isConvertedPhoton() const { return false; }
346  virtual bool isJet() const { return false; }
347 
348  // puppiweight
349  void setPuppiWeight(float p);
350  float puppiWeight() const;
351 
352  protected:
358  void pack(bool unpackAfterwards=true) ;
359  void unpack() const ;
360  void packVtx(bool unpackAfterwards=true) ;
361  void unpackVtx() const ;
362  void maybeUnpackBoth() const { if (!unpacked_) unpack(); if (!unpackedVtx_) unpackVtx(); }
363  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
364  void unpackTrk() const ;
365 
371  mutable Point vertex_;
372  mutable float dxy_, dz_, dphi_;
376  int pdgId_;
377  uint16_t qualityFlags_;
380  // is the momentum p4 unpacked
381  mutable bool unpacked_;
382  // are the dxy, dz and vertex unpacked
383  mutable bool unpackedVtx_;
384  // is the track unpacked
385  mutable bool unpackedTrk_;
388  uint8_t packedHits_;
390  uint8_t normalizedChi2_;
391 // uint8_t numberOfPixelHits_;
392  // uint8_t numberOfHits_;
393 
395  virtual bool overlap( const reco::Candidate & ) const;
396  template<typename, typename, typename> friend struct component;
397  friend class ::OverlapChecker;
398  friend class ShallowCloneCandidate;
400 
406  };
407  };
408 
409  typedef std::vector<pat::PackedCandidate> PackedCandidateCollection;
412 }
413 
414 #endif
float puppiWeight() const
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
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 void setPdgId(int pdgId)
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
virtual float dzError() const
uncertainty on dz
int numberOfHits() const
size_t size_type
Definition: Candidate.h:30
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
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:514
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)
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 double pt() const
transverse momentum
virtual void setStatus(int status)
set status word
key_type key() const
Accessor for product key.
Definition: Ref.h:266
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 double eta() const
momentum pseudorapidity
virtual void setP4(const PolarLorentzVector &p4)
set 4-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)
virtual double phi() const
momentum azimuthal angle
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 double mass() const
mass
virtual bool isConvertedPhoton() const
friend struct component
virtual void setMassConstraint()
set mass constraint flag
virtual bool isMuon() const
reco::Track track_
reco::Track
const PVAssociationQuality pvAssociationQuality() const
virtual PackedCandidate * clone() const
returns a clone of the Candidate object
math::XYZTLorentzVector LorentzVector
Lorentz vector.
const PVAssoc fromPV(size_t ipv=0) const
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:684
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
double et2() const
transverse energy squared (use this for cuts)!
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 void setPz(double pz)
virtual double mt() const
transverse mass
virtual float dzAssociatedPV() const
dz with respect to the PV ref
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
PVAssoc
This refers to the association to PV=ipv. &gt;=PVLoose corresponds to JME definition, &gt;=PVTight to isolation definition.
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:411
float dxydxy_
IP covariance.
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
virtual double massSqr() const
mass squared
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
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:37
void setPuppiWeight(float p)
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
static int position[264][3]
Definition: ReadPGInfo.cc:509
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:41
void pack(bool unpackAfterwards=true)
virtual bool isElectron() const
double et() const
transverse energy
virtual double px() const
x coordinate of momentum vector
volatile std::atomic< bool > shutdown_flag false
virtual float dxy() const
dxy with respect to the PV ref
virtual double vertexChi2() const
chi-squares
void setTrackHighPurity(bool highPurity)
set to true if the track had the highPurity quality bit
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
math::XYZVector Vector
point in the space
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77
virtual double p() const
magnitude of momentum vector
virtual bool hasMasterClone() const
PackedCandidate(const reco::Candidate &c, const reco::VertexRef &pv)
C const * product() const
Accessor for product collection.
Definition: Ref.h:601
void setAssociationQuality(PVAssociationQuality q)
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:39