CMS 3D CMS Logo

PackedCandidate.h
Go to the documentation of this file.
1 #ifndef __DataFormats_PatCandidates_PackedCandidate_h__
2 #define __DataFormats_PatCandidates_PackedCandidate_h__
3 
4 #include <atomic>
5 #include <mutex>
15 
16 /* #include "DataFormats/Math/interface/PtEtaPhiMass.h" */
17 
18 //forward declare testing structure
19 class testPackedCandidate;
20 
21 namespace pat {
23  public:
34 
35  typedef unsigned int index;
36 
39  packedPt_(0), packedEta_(0),
40  packedPhi_(0), packedM_(0),
46  hcalFraction_(0),
48  p4_(new PolarLorentzVector(0,0,0,0)), p4c_( new LorentzVector(0,0,0,0)),
49  vertex_(new Point(0,0,0)), dphi_(0), deta_(0), dtrkpt_(0),track_(nullptr), pdgId_(0),
50  qualityFlags_(0), pvRefKey_(reco::VertexRef::invalidKey()),
52 
53  explicit PackedCandidate( const reco::Candidate & c,
54  const reco::VertexRefProd &pvRefProd,
55  reco::VertexRef::key_type pvRefKey) :
58  p4_( new PolarLorentzVector(c.pt(), c.eta(), c.phi(), c.mass())),
59  p4c_( new LorentzVector(*p4_)), vertex_( new Point(c.vertex())),
60  dphi_(0), deta_(0), dtrkpt_(0),
61  track_(nullptr), pdgId_(c.pdgId()), qualityFlags_(0), pvRefProd_(pvRefProd),
62  pvRefKey_(pvRefKey),m_(nullptr), packedHits_(0), packedLayers_(0),
64  packBoth();
65  }
66 
67  explicit PackedCandidate( const PolarLorentzVector &p4, const Point &vtx,
68  float trkPt,float etaAtVtx,float phiAtVtx,int pdgId,
69  const reco::VertexRefProd &pvRefProd,
70  reco::VertexRef::key_type pvRefKey) :
73  p4_( new PolarLorentzVector(p4) ), p4c_( new LorentzVector(*p4_)),
74  vertex_( new Point(vtx) ),
75  dphi_(reco::deltaPhi(phiAtVtx,p4_.load()->phi())),
76  deta_(std::abs(etaAtVtx-p4_.load()->eta())>=kMinDEtaToStore_ ? etaAtVtx-p4_.load()->eta() : 0.),
77  dtrkpt_(std::abs(trkPt-p4_.load()->pt())>=kMinDTrkPtToStore_ ? trkPt-p4_.load()->pt() : 0.),
78  track_(nullptr), pdgId_(pdgId),
79  qualityFlags_(0), pvRefProd_(pvRefProd), pvRefKey_(pvRefKey),
81  packBoth();
82  }
83 
84  explicit PackedCandidate( const LorentzVector &p4, const Point &vtx,
85  float trkPt, float etaAtVtx, float phiAtVtx, int pdgId,
86  const reco::VertexRefProd &pvRefProd,
87  reco::VertexRef::key_type pvRefKey) :
90  p4_(new PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M())),
91  p4c_( new LorentzVector(p4)), vertex_( new Point(vtx) ) ,
92  dphi_(reco::deltaPhi(phiAtVtx,p4_.load()->phi())),
93  deta_(std::abs(etaAtVtx-p4_.load()->eta())>=kMinDEtaToStore_ ? etaAtVtx-p4_.load()->eta() : 0.),
94  dtrkpt_(std::abs(trkPt-p4_.load()->pt())>=kMinDTrkPtToStore_ ? trkPt-p4_.load()->pt() : 0.),
95  track_(nullptr), pdgId_(pdgId), qualityFlags_(0),
96  pvRefProd_(pvRefProd), pvRefKey_(pvRefKey),
98  packBoth();
99  }
100 
102  packedPt_(iOther.packedPt_), packedEta_(iOther.packedEta_),
103  packedPhi_(iOther.packedPhi_), packedM_(iOther.packedM_),
104  packedDxy_(iOther.packedDxy_), packedDz_(iOther.packedDz_),
112  //Need to trigger unpacking in iOther
113  p4_( new PolarLorentzVector(iOther.polarP4() ) ),
114  p4c_( new LorentzVector(iOther.p4())), vertex_( new Point(iOther.vertex())),
115  dxy_(iOther.dxy_), dz_(iOther.dz_),
116  dphi_(iOther.dphi_), deta_(iOther.deta_), dtrkpt_(iOther.dtrkpt_),
117  track_( iOther.track_ ? new reco::Track(*iOther.track_) : nullptr),
118  pdgId_(iOther.pdgId_), qualityFlags_(iOther.qualityFlags_),
119  pvRefProd_(iOther.pvRefProd_),pvRefKey_(iOther.pvRefKey_),
120  m_(iOther.m_? new reco::TrackBase::CovarianceMatrix(*iOther.m_) : nullptr),
123  }
124 
126  packedPt_(iOther.packedPt_), packedEta_(iOther.packedEta_),
127  packedPhi_(iOther.packedPhi_), packedM_(iOther.packedM_),
128  packedDxy_(iOther.packedDxy_), packedDz_(iOther.packedDz_),
136  p4_( iOther.p4_.exchange(nullptr) ) ,
137  p4c_( iOther.p4c_.exchange(nullptr)), vertex_(iOther.vertex_.exchange(nullptr)),
138  dxy_(iOther.dxy_), dz_(iOther.dz_),
139  dphi_(iOther.dphi_), deta_(iOther.deta_), dtrkpt_(iOther.dtrkpt_),
140  track_( iOther.track_.exchange(nullptr) ),
141  pdgId_(iOther.pdgId_), qualityFlags_(iOther.qualityFlags_),
142  pvRefProd_(std::move(iOther.pvRefProd_)),pvRefKey_(iOther.pvRefKey_),
143  m_( iOther.m_.exchange(nullptr)),
146  }
147 
148 
150  if(this == &iOther) {
151  return *this;
152  }
153  packedPt_ =iOther.packedPt_;
154  packedEta_=iOther.packedEta_;
155  packedPhi_=iOther.packedPhi_;
156  packedM_=iOther.packedM_;
157  packedDxy_=iOther.packedDxy_;
158  packedDz_=iOther.packedDz_;
159  packedDPhi_=iOther.packedDPhi_;
160  packedDEta_=iOther.packedDEta_;
168  //Need to trigger unpacking in iOther
169  if(p4_) {
170  *p4_ = iOther.polarP4();
171  } else {
172  p4_.store( new PolarLorentzVector(iOther.polarP4() ) ) ;
173  }
174  if(p4c_) {
175  *p4c_ = iOther.p4();
176  } else {
177  p4c_.store( new LorentzVector(iOther.p4()));
178  }
179  if(vertex_) {
180  *vertex_ = iOther.vertex();
181  } else {
182  vertex_.store( new Point(iOther.vertex()));
183  }
184  dxy_=iOther.dxy_;
185  dz_ = iOther.dz_;
186  dphi_=iOther.dphi_;
187  deta_=iOther.deta_;
188  dtrkpt_=iOther.dtrkpt_;
189 
190  if(!iOther.track_) {
191  delete track_.exchange(nullptr);
192  } else {
193  if(!track_) {
194  track_.store( new reco::Track(*iOther.track_));
195  } else {
196  *track_ = *(iOther.track_);
197  }
198  }
199 
200  pdgId_=iOther.pdgId_;
202  pvRefProd_=iOther.pvRefProd_;
203  pvRefKey_=iOther.pvRefKey_;
204  if(!iOther.m_) {
205  delete m_.exchange(nullptr);
206  } else {
207  if(!m_) {
208  m_.store( new reco::Track::CovarianceMatrix(*iOther.m_));
209  } else {
210  *m_ = *(iOther.m_);
211  }
212  }
213 
214 
215  packedHits_=iOther.packedHits_;
220  return *this;
221  }
222 
224  if(this == &iOther) {
225  return *this;
226  }
227  packedPt_ =iOther.packedPt_;
228  packedEta_=iOther.packedEta_;
229  packedPhi_=iOther.packedPhi_;
230  packedM_=iOther.packedM_;
231  packedDxy_=iOther.packedDxy_;
232  packedDz_=iOther.packedDz_;
233  packedDPhi_=iOther.packedDPhi_;
234  packedDEta_=iOther.packedDEta_;
235  packedDTrkPt_=iOther.packedDTrkPt_;
236  packedCovariance_=iOther.packedCovariance_;
237  packedPuppiweight_=iOther.packedPuppiweight_;
238  packedPuppiweightNoLepDiff_=iOther.packedPuppiweightNoLepDiff_;
239  rawCaloFraction_=iOther.rawCaloFraction_;
240  hcalFraction_=iOther.hcalFraction_;
241  isIsolatedChargedHadron_=iOther.isIsolatedChargedHadron_;
242  delete p4_.exchange(iOther.p4_.exchange(nullptr));
243  delete p4c_.exchange(iOther.p4c_.exchange(nullptr));
244  delete vertex_.exchange(iOther.vertex_.exchange(nullptr));
245  dxy_=iOther.dxy_;
246  dz_ = iOther.dz_;
247  dphi_=iOther.dphi_;
248  deta_=iOther.deta_;
249  dtrkpt_=iOther.dtrkpt_;
250  delete track_.exchange(iOther.track_.exchange( nullptr));
251  pdgId_=iOther.pdgId_;
252  qualityFlags_=iOther.qualityFlags_;
253  pvRefProd_=iOther.pvRefProd_;
254  pvRefKey_=iOther.pvRefKey_;
255  delete m_.exchange(iOther.m_.exchange(nullptr));
256  packedHits_=iOther.packedHits_;
257  packedLayers_=iOther.packedLayers_;
258  normalizedChi2_=iOther.normalizedChi2_;
259  covarianceVersion_=iOther.covarianceVersion_;
260  covarianceSchema_=iOther.covarianceSchema_;
261  return *this;
262  }
263 
265  virtual ~PackedCandidate();
267  virtual size_t numberOfDaughters() const;
269  virtual const reco::Candidate * daughter( size_type ) const;
271  virtual size_t numberOfMothers() const;
273  virtual const reco::Candidate * mother( size_type ) const;
275  virtual reco::Candidate * daughter( size_type );
277  virtual reco::Candidate * daughter(const std::string& s );
279  virtual const reco::Candidate * daughter(const std::string& s ) const;
282  virtual size_t numberOfSourceCandidatePtrs() const {return 0;}
286  return reco::CandidatePtr();
287  }
288 
290  virtual int charge() const {
291  switch (abs(pdgId_)) {
292  case 211: return (pdgId_>0)-(pdgId_<0);
293  case 11: return (-1)*(pdgId_>0)+(pdgId_<0); //e
294  case 13: return (-1)*(pdgId_>0)+(pdgId_<0); //mu
295  case 15: return (-1)*(pdgId_>0)+(pdgId_<0); //tau
296  case 24: return (pdgId_>0)-(pdgId_<0); //W
297  default: return 0; //FIXME: charge is not defined
298  }
299  }
301  virtual void setCharge( int charge) {}
303  virtual int threeCharge() const {return charge()*3;}
305  virtual void setThreeCharge( int threecharge) {}
307  virtual const LorentzVector & p4() const { if (!p4c_) unpack(); return *p4c_; }
309  virtual const PolarLorentzVector & polarP4() const { if (!p4c_) unpack(); return *p4_; }
311  virtual Vector momentum() const { if (!p4c_) unpack(); return p4c_.load()->Vect(); }
314  virtual Vector boostToCM() const { if (!p4c_) unpack(); return p4c_.load()->BoostToCM(); }
316  virtual double p() const { if (!p4c_) unpack(); return p4c_.load()->P(); }
318  virtual double energy() const { if (!p4c_) unpack(); return p4c_.load()->E(); }
320  double et() const { return (pt()<=0) ? 0 : p4c_.load()->Et(); }
322  double et2() const { return (pt()<=0) ? 0 : p4c_.load()->Et2(); }
324  virtual double mass() const { if (!p4c_) unpack(); return p4_.load()->M(); }
326  virtual double massSqr() const { if (!p4c_) unpack(); auto m = p4_.load()->M(); return m*m;}
327 
329  virtual double mt() const { if (!p4c_) unpack(); return p4_.load()->Mt(); }
331  virtual double mtSqr() const { if (!p4c_) unpack(); return p4_.load()->Mt2(); }
333  virtual double px() const { if (!p4c_) unpack(); return p4c_.load()->Px(); }
335  virtual double py() const { if (!p4c_) unpack(); return p4c_.load()->Py(); }
337  virtual double pz() const { if (!p4c_) unpack(); return p4c_.load()->Pz(); }
339  virtual double pt() const { if (!p4c_) unpack(); return p4_.load()->Pt();}
341  virtual double phi() const { if (!p4c_) unpack(); return p4_.load()->Phi(); }
342 
344  virtual double ptTrk() const {
345  maybeUnpackBoth();
346  return p4_.load()->pt() + dtrkpt_;
347  }
349  virtual float phiAtVtx() const {
350  maybeUnpackBoth();
351  float ret = p4_.load()->Phi() + dphi_;
352  while (ret > float(M_PI)) ret -= 2*float(M_PI);
353  while (ret < -float(M_PI)) ret += 2*float(M_PI);
354  return ret;
355  }
357  virtual float etaAtVtx() const {
358  maybeUnpackBoth();
359  return p4_.load()->eta() + deta_;
360  }
361 
363  virtual double theta() const { if (!p4c_) unpack(); return p4_.load()->Theta(); }
365  virtual double eta() const { if (!p4c_) unpack(); return p4_.load()->Eta(); }
367  virtual double rapidity() const { if (!p4c_) unpack(); return p4_.load()->Rapidity(); }
369  virtual double y() const { if (!p4c_) unpack(); return p4_.load()->Rapidity(); }
371  virtual void setP4( const LorentzVector & p4 ) {
372  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
373  *p4_ = PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M());
374  packBoth();
375  }
377  virtual void setP4( const PolarLorentzVector & p4 ) {
378  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
379  *p4_ = p4;
380  packBoth();
381  }
383  virtual void setMass( double m ) {
384  if (!p4c_) unpack();
385  *p4_ = PolarLorentzVector(p4_.load()->Pt(), p4_.load()->Eta(), p4_.load()->Phi(), m);
386  pack();
387  }
388  virtual void setPz( double pz ) {
389  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
390  *p4c_ = LorentzVector(p4c_.load()->Px(), p4c_.load()->Py(), pz, p4c_.load()->E());
391  *p4_ = PolarLorentzVector(p4c_.load()->Pt(), p4c_.load()->Eta(), p4c_.load()->Phi(), p4c_.load()->M());
392  packBoth();
393  }
395 
396  // Note: mask is also the maximum value
400  };
401 
402  // set number of tracker hits and layers
403  virtual void setHits( const reco::Track & tk) {
404  // first we count the number of layers with hits
405  int numberOfPixelLayers_ = tk.hitPattern().pixelLayersWithMeasurement();
406  if (numberOfPixelLayers_ > trackPixelHitsMask) numberOfPixelLayers_ = trackPixelHitsMask;
407  int numberOfStripLayers_ = tk.hitPattern().stripLayersWithMeasurement();
408  if (numberOfStripLayers_ > trackStripHitsMask) numberOfStripLayers_ = trackStripHitsMask;
409  packedLayers_ = (numberOfPixelLayers_&trackPixelHitsMask) | (numberOfStripLayers_ << trackStripHitsShift);
410  // now we count number of additional hits, beyond the one-per-layer implied by packedLayers_
411  int numberOfPixelHits_ = tk.hitPattern().numberOfValidPixelHits() - numberOfPixelLayers_;
412  if (numberOfPixelHits_ > trackPixelHitsMask) numberOfPixelHits_ = trackPixelHitsMask;
413  int numberOfStripHits_ = tk.hitPattern().numberOfValidHits() - numberOfPixelHits_ - numberOfPixelLayers_ - numberOfStripLayers_;
414  if (numberOfStripHits_ > trackStripHitsMask) numberOfStripHits_ = trackStripHitsMask;
415 
416  packedHits_ = (numberOfPixelHits_&trackPixelHitsMask) | (numberOfStripHits_ << trackStripHitsShift);
417  }
418 
419  virtual void setTrackProperties( const reco::Track & tk, const reco::Track::CovarianceMatrix & covariance,int quality,int covarianceVersion) {
423  setHits(tk);
424  packBoth();
425  packCovariance(covariance,false);
426  }
427 
428  // set track properties using quality and covarianceVersion to define the level of details in the cov. matrix
429  virtual void setTrackProperties( const reco::Track & tk,int quality,int covarianceVersion ) {
431  }
432 
439  int covarianceVersion() const { return covarianceVersion_;}
440  int covarianceSchema() const { return covarianceSchema_;}
441 
442 
444  virtual const Point & vertex() const { maybeUnpackBoth(); return *vertex_; }//{ if (fromPV_) return Point(0,0,0); else return Point(0,0,100); }
446  virtual double vx() const { maybeUnpackBoth(); return vertex_.load()->X(); }//{ return 0; }
448  virtual double vy() const { maybeUnpackBoth(); return vertex_.load()->Y(); }//{ return 0; }
450  virtual double vz() const { maybeUnpackBoth(); return vertex_.load()->Z(); }//{ if (fromPV_) return 0; else return 100; }
452  virtual void setVertex( const Point & vertex ) { maybeUnpackBoth(); *vertex_ = vertex; packVtx(); }
453 
455  enum PVAssoc { NoPV=0, PVLoose=1, PVTight=2, PVUsedInFit=3 } ;
456  const PVAssoc fromPV(size_t ipv=0) const {
457  reco::VertexRef pvRef = vertexRef();
458  if(pvAssociationQuality()==UsedInFitTight and pvRef.key()==ipv) return PVUsedInFit;
459  if(pvRef.key()==ipv or abs(pdgId())==13 or abs(pdgId())==11 ) return PVTight;
460  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
461  if(pvAssociationQuality() < UsedInFitLoose or pvRef->ndof() < 4.0 ) return PVLoose;
462  return NoPV;
463  }
464 
470 
472 
474  virtual float dxy() const { maybeUnpackBoth(); return dxy_; }
476  virtual float dz(size_t ipv=0) const { maybeUnpackBoth(); return dz_ + (*pvRefProd_)[pvRefKey_].position().z()-(*pvRefProd_)[ipv].position().z(); }
478  virtual float dzAssociatedPV() const { maybeUnpackBoth(); return dz_; }
480  virtual float dxy(const Point &p) const ;
482  virtual float dz(const Point &p) const ;
483 
485  virtual float dzError() const { maybeUnpackCovariance(); return sqrt((*m_.load())(4,4)); }
487  virtual float dxyError() const { maybeUnpackCovariance(); return sqrt((*m_.load())(3,3)); }
488 
489 
491  virtual const reco::Track & pseudoTrack() const { if (!track_) unpackTrk(); return *track_; }
492 
494  virtual const reco::Track * bestTrack() const {
495  if (packedHits_!=0 || packedLayers_ !=0) {
497  return track_.load();
498  }
499  else
500  return nullptr;
501  }
503  bool hasTrackDetails() const {return (packedHits_!=0 || packedLayers_ !=0); }
504 
505 
510 
514  noLostInnerHits=0, // it could still not have a hit in the first layer, e.g. if it crosses an inactive sensor
517  };
520  }
522  int lost = hits; if (lost > 2) lost = 2; // protection against misuse
523  lost++; // shift so it's 0 .. 3 instead of (-1) .. 2
525  }
526 
527  void setMuonID(bool isStandAlone, bool isGlobal) {
528  int16_t muonFlags = isStandAlone | (2*isGlobal);
530  }
531 
533  virtual int pdgId() const { return pdgId_; }
534  // set PDG identifier
535  virtual void setPdgId( int pdgId ) { pdgId_ = pdgId; }
537  virtual int status() const { return qualityFlags_; } /*FIXME*/
539  virtual void setStatus( int status ) {} /*FIXME*/
541  static const unsigned int longLivedTag = 0; /*FIXME*/
543  virtual void setLongLived() {} /*FIXME*/
545  virtual bool longLived() const;
547  static const unsigned int massConstraintTag = 0; /*FIXME*/
549  virtual void setMassConstraint() {} /*FIXME*/
551  virtual bool massConstraint() const;
552 
554  virtual PackedCandidate * clone() const {
555  return new PackedCandidate( *this );
556  }
557 
559  virtual double vertexChi2() const;
566  virtual double vertexNdof() const;
568  virtual double vertexNormalizedChi2() const;
570  virtual double vertexCovariance(int i, int j) const;
574  virtual void fillVertexCovariance(CovarianceMatrix & v) const;
577  virtual bool hasMasterClone() const;
580  virtual const reco::CandidateBaseRef & masterClone() const;
583  virtual bool hasMasterClonePtr() const;
586 
587  virtual const reco::CandidatePtr & masterClonePtr() const;
588 
590  template<typename Ref>
591  Ref masterRef() const { return masterClone().template castTo<Ref>(); }
592 
593  virtual bool isElectron() const { return false; }
594  virtual bool isMuon() const { return false; }
595  virtual bool isStandAloneMuon() const { return ((qualityFlags_ & muonFlagsMask) >> muonFlagsShift) & 1; }
596  virtual bool isGlobalMuon() const { return ((qualityFlags_ & muonFlagsMask) >> muonFlagsShift) & 2; }
597  virtual bool isTrackerMuon() const { return false; }
598  virtual bool isCaloMuon() const { return false; }
599  virtual bool isPhoton() const { return false; }
600  virtual bool isConvertedPhoton() const { return false; }
601  virtual bool isJet() const { return false; }
602 
603  // puppiweights
604  void setPuppiWeight(float p, float p_nolep = 0.0);
605  float puppiWeight() const;
606  float puppiWeightNoLep() const;
607 
608  // for the neutral fractions
609  void setRawCaloFraction(float p);
610  float rawCaloFraction() const { return (rawCaloFraction_/100.); }
611  void setHcalFraction(float p);
612  float hcalFraction() const { return (hcalFraction_/100.); }
613 
614  // isolated charged hadrons
615  void setIsIsolatedChargedHadron(bool p);
617 
620  //3D IP covariance
621  uint16_t dxydxy;
622  uint16_t dxydz;
623  uint16_t dzdz;
624  //other IP relevant elements
625  uint16_t dlambdadz;
626  uint16_t dphidxy;
627  //other diag elements
628  uint16_t dptdpt;
629  uint16_t detadeta;
630  uint16_t dphidphi;
631  };
632 
633  private:
634  void unpackCovarianceElement(reco::TrackBase::CovarianceMatrix & m, uint16_t packed, int i,int j) const {
636  }
637  uint16_t packCovarianceElement(const reco::TrackBase::CovarianceMatrix &m,int i,int j) const {
639  }
640 
641  protected:
642  friend class ::testPackedCandidate;
643  static constexpr float kMinDEtaToStore_=0.001;
644  static constexpr float kMinDTrkPtToStore_=0.001;
645 
646 
650 
651  void pack(bool unpackAfterwards=true) ;
652  void unpack() const ;
653  void packVtx(bool unpackAfterwards=true) ;
654  void unpackVtx() const ;
655  void packCovariance(const reco::TrackBase::CovarianceMatrix & m,bool unpackAfterwards=true) ;
656  void unpackCovariance() const;
657  void maybeUnpackBoth() const { if (!p4c_) unpack(); if (!vertex_) unpackVtx(); }
658  void maybeUnpackTrack() const { if (!track_) unpackTrk(); }
659  void maybeUnpackCovariance() const { if (!m_) unpackCovariance(); }
660  void packBoth() { pack(false); packVtx(false); delete p4_.exchange(nullptr); delete p4c_.exchange(nullptr); delete vertex_.exchange(nullptr); unpack(); unpackVtx(); } // do it this way, so that we don't loose precision on the angles before computing dxy,dz
661  void unpackTrk() const ;
662 
664  int8_t packedPuppiweightNoLepDiff_; // storing the DIFFERENCE of (all - "no lep") for compression optimization
667 
669 
671  mutable std::atomic<PolarLorentzVector*> p4_;
672  mutable std::atomic<LorentzVector*> p4c_;
674  mutable std::atomic<Point*> vertex_;
675  CMS_THREAD_GUARD(vertex_) mutable float dxy_, dz_, dphi_, deta_, dtrkpt_;
677  mutable std::atomic<reco::Track*> track_;
679  int pdgId_;
680  uint16_t qualityFlags_;
684 
686  mutable std::atomic<reco::TrackBase::CovarianceMatrix *> m_;
687  uint8_t packedHits_, packedLayers_; // packedLayers_ -> layers with valid hits; packedHits_ -> extra hits beyond the one-per-layer implied by packedLayers_
688 
690  uint8_t normalizedChi2_;
694  //static std::atomic<CovarianceParameterization*> covarianceParameterization_;
695  static std::once_flag covariance_load_flag;
697  std::call_once(covariance_load_flag,[](int v) { covarianceParameterization_.load(v); } ,covarianceVersion_ );
698  if(covarianceParameterization_.loadedVersion() != covarianceVersion_ )
699  {
701  << "Attempting to load multiple covariance version in same process. This is not supported.";
702  }
704  }
705 
707  virtual bool overlap( const reco::Candidate & ) const;
708  template<typename, typename, typename> friend struct component;
709  friend class ::OverlapChecker;
710  friend class ShallowCloneCandidate;
712 
718  };
719  };
720 
721  typedef std::vector<pat::PackedCandidate> PackedCandidateCollection;
724 }
725 
726 #endif
float puppiWeight() const
Set both weights at once (with option for only full PUPPI)
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
virtual size_t numberOfMothers() const
number of mothers
virtual bool hasMasterClonePtr() const
virtual void setPdgId(int pdgId)
virtual float etaAtVtx() const
eta from the track (normally identical to eta())
int covarianceSchema() const
float puppiWeightNoLep() const
Weight from full PUPPI.
void setPuppiWeight(float p, float p_nolep=0.0)
virtual float dzError() const
uncertainty on dz
std::atomic< Point * > vertex_
vertex position
int numberOfHits() const
size_t size_type
Definition: Candidate.h:30
float unpack(uint16_t packed, int schema, int i, int j, float pt, float eta, int nHits, int pixelHits, float cii=1., float cjj=1.) const
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:556
uint16_t packCovarianceElement(const reco::TrackBase::CovarianceMatrix &m, int i, int j) const
float hcalFraction() const
Set the fraction of Hcal needed for HF and neutral hadrons and isolated charged hadrons.
virtual const reco::Track * bestTrack() const
return a pointer to the track if present. otherwise, return a null pointer
reco::VertexRef::key_type pvRefKey_
virtual bool isCaloMuon() const
int pixelLayersWithMeasurement() const
void maybeUnpackBoth() const
static const unsigned int longLivedTag
long lived flag
int numberOfValidHits() const
Definition: HitPattern.h:823
PackedCandidate & operator=(const PackedCandidate &iOther)
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 void setCovarianceVersion(int v)
virtual double vertexNdof() const
void setRawCaloFraction(float p)
Weight from PUPPI removing leptons.
PackedCandidate(const PackedCandidate &iOther)
void unpackCovarianceElement(reco::TrackBase::CovarianceMatrix &m, uint16_t packed, int i, int j) const
PackedCovariance packedCovariance_
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:264
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:493
virtual double vx() const
x coordinate of vertex position
virtual bool overlap(const reco::Candidate &) const
check overlap with another Candidate
#define nullptr
virtual bool isPhoton() const
virtual double eta() const
momentum pseudorapidity
virtual void setP4(const PolarLorentzVector &p4)
set 4-momentum
const reco::VertexRef vertexRef() const
PackedCandidate(PackedCandidate &&iOther)
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
#define constexpr
PackedCandidate(const reco::Candidate &c, const reco::VertexRefProd &pvRefProd, reco::VertexRef::key_type pvRefKey)
float pack(float value, int schema, int i, int j, float pt, float eta, int nHits, int pixelHits, float cii=1., float cjj=1.) const
Ref masterRef() const
cast master clone reference to a concrete type
Definition: HeavyIon.h:7
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 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
std::atomic< reco::Track * > track_
reco::Track
virtual bool isMuon() const
const PVAssociationQuality pvAssociationQuality() const
virtual PackedCandidate * clone() const
returns a clone of the Candidate object
void setHcalFraction(float p)
Raw ECAL+HCAL energy over candidate energy for isolated charged hadrons.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
virtual void setTrackProperties(const reco::Track &tk, int quality, int covarianceVersion)
void maybeUnpackCovariance() const
const PVAssoc fromPV(size_t ipv=0) const
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:726
T sqrt(T t)
Definition: SSEVec.h:18
virtual double py() const
y coordinate of momentum vector
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::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
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
virtual const reco::CandidateBaseRef & masterClone() const
edm::Ref< pat::PackedCandidateCollection > PackedCandidateRef
friend class ShallowCloneCandidate
static CovarianceParameterization covarianceParameterization_
virtual double energy() const
energy
virtual double ptTrk() const
pt from the track (normally identical to pt())
#define CMS_THREAD_GUARD(_var_)
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 stripLayersWithMeasurement() const
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
std::atomic< PolarLorentzVector * > p4_
the four vector
virtual int threeCharge() const
electric charge
#define CMS_THREAD_SAFE
PackedCandidate(const PolarLorentzVector &p4, const Point &vtx, float trkPt, float etaAtVtx, float phiAtVtx, int pdgId, const reco::VertexRefProd &pvRefProd, reco::VertexRef::key_type pvRefKey)
virtual double vertexNormalizedChi2() const
chi-squared divided by n.d.o.f.
virtual void setThreeCharge(int threecharge)
set electric charge
virtual void setPz(double pz)
virtual double mt() const
transverse mass
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
virtual float dzAssociatedPV() const
dz with respect to the PV ref
int numberOfPixelHits() const
virtual const reco::CandidatePtr & masterClonePtr() const
virtual double vy() const
y coordinate of vertex position
int trackerLayersWithMeasurement() const
std::atomic< LorentzVector * > p4c_
virtual const PolarLorentzVector & polarP4() const
four-momentum Lorentz vector
#define M_PI
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
std::atomic< reco::TrackBase::CovarianceMatrix * > m_
IP covariance.
LostInnerHits
Enumerator specifying the.
uint8_t normalizedChi2_
track quality information
PVAssoc
This refers to the association to PV=ipv. >=PVLoose corresponds to JME definition, >=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
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:445
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
def load(fileName)
Definition: svgfig.py:546
virtual Vector boostToCM() const
int stripLayersWithMeasurement() const
Definition: HitPattern.h:1035
static std::once_flag covariance_load_flag
virtual double vz() const
z coordinate of vertex position
int covarianceVersion() const
virtual void setMass(double m)
set particle mass
virtual reco::CandidatePtr sourceCandidatePtr(size_type i) const
static float kMinDEtaToStore_
virtual float phiAtVtx() const
momentum azimuthal angle from the track (normally identical to phi())
int pdgId_
PDG identifier.
virtual const Point & vertex() const
vertex position
edm::RefProd< VertexCollection > VertexRefProd
persistent reference to a Vertex
Definition: VertexFwd.h:15
virtual size_t numberOfDaughters() const
number of daughters
float rawCaloFraction() const
Set the raw ECAL+HCAL energy over candidate energy for isolated charged hadrons.
void unpackCovariance() const
CovarianceMatrix vertexCovariance() const
return SMatrix
virtual bool isStandAloneMuon() const
friend class ShallowClonePtrCandidate
fixed size matrix
Flag isolation (as in particle flow, i.e. at calorimeter surface rather than at PV) flag for charged ...
virtual bool longLived() const
is long lived?
PackedCandidate & operator=(PackedCandidate &&iOther)
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
void packVtx(bool unpackAfterwards=true)
void setLostInnerHits(LostInnerHits hits)
PackedCandidate(const LorentzVector &p4, const Point &vtx, float trkPt, float etaAtVtx, float phiAtVtx, int pdgId, const reco::VertexRefProd &pvRefProd, reco::VertexRef::key_type pvRefKey)
trackHitShiftsAndMasks
set impact parameters covariance
int numberOfValidPixelHits() const
Definition: HitPattern.h:838
void setIsIsolatedChargedHadron(bool p)
Fraction of Ecal and Hcal for HF and neutral hadrons and isolated charged hadrons.
virtual const LorentzVector & p4() const
four-momentum Lorentz vecto r
void pack(bool unpackAfterwards=true)
virtual bool isElectron() const
double et() const
transverse energy
virtual double px() const
x coordinate of momentum vector
void packCovariance(const reco::TrackBase::CovarianceMatrix &m, bool unpackAfterwards=true)
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 void setTrackProperties(const reco::Track &tk, const reco::Track::CovarianceMatrix &covariance, int quality, int covarianceVersion)
virtual ~PackedCandidate()
destructor
virtual int pdgId() const
PDG identifier.
void maybeUnpackTrack() const
virtual void setHits(const reco::Track &tk)
bool isIsolatedChargedHadron() const
Set isolation (as in particle flow, i.e. at calorimeter surface rather than at PV) flat for charged h...
const CovarianceParameterization & covarianceParameterization() const
virtual double pz() const
z coordinate of momentum vector
virtual float dxyError() const
uncertainty on dxy
math::XYZVector Vector
point in the space
def move(src, dest)
Definition: eostools.py:510
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:168
static float kMinDTrkPtToStore_
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
reco::VertexRefProd pvRefProd_
Use these to build a Ref to primary vertex.
void setAssociationQuality(PVAssociationQuality q)