CMS 3D CMS Logo

PackedGenParticle.h
Go to the documentation of this file.
1 #ifndef __AnalysisDataFormats_PackedGenParticle_h__
2 #define __AnalysisDataFormats_PackedGenParticle_h__
3 
14 /* #include "DataFormats/Math/interface/PtEtaPhiMass.h" */
15 
16 class testPackedGenParticle;
17 
18 namespace pat {
20  public:
21  friend class ::testPackedGenParticle;
22 
33 
34  typedef unsigned int index;
35 
38  : packedPt_(0), packedY_(0), packedPhi_(0), packedM_(0),
39  p4_(nullptr), p4c_(nullptr), vertex_(0,0,0), pdgId_(0), charge_(0) { }
41  : p4_(new PolarLorentzVector(c.pt(), c.eta(), c.phi(), c.mass())), p4c_( new LorentzVector(*p4_)), vertex_(0,0,0), pdgId_(c.pdgId()), charge_(c.charge()), mother_(c.motherRef(0)),
42  statusFlags_(c.statusFlags()) { pack(); }
44  : p4_(new PolarLorentzVector(c.pt(), c.eta(), c.phi(), c.mass())), p4c_(new LorentzVector(*p4_)), vertex_(0,0,0), pdgId_(c.pdgId()), charge_(c.charge()), mother_(mother),
45  statusFlags_(c.statusFlags()) { pack(); }
46 
48  : packedPt_(iOther.packedPt_), packedY_(iOther.packedY_), packedPhi_(iOther.packedPhi_), packedM_(iOther.packedM_),
50  vertex_(iOther.vertex_), dxy_(iOther.dxy_), dz_(iOther.dz_),dphi_(iOther.dphi_),
51  pdgId_(iOther.pdgId_),charge_(iOther.charge_),mother_(iOther.mother_),
52  statusFlags_(iOther.statusFlags_) {
53  if(iOther.p4c_) {
54  p4_.store( new PolarLorentzVector(*iOther.p4_) );
55  p4c_.store( new LorentzVector(*iOther.p4c_) );
56  }
57  }
58 
60  : packedPt_(iOther.packedPt_), packedY_(iOther.packedY_), packedPhi_(iOther.packedPhi_), packedM_(iOther.packedM_),
62  vertex_(std::move(iOther.vertex_)), dxy_(iOther.dxy_), dz_(iOther.dz_),dphi_(iOther.dphi_),
63  pdgId_(iOther.pdgId_),charge_(iOther.charge_),mother_(std::move(iOther.mother_)),
64  statusFlags_(iOther.statusFlags_) {
65  if(iOther.p4c_) {
66  p4_.store( p4_.exchange(nullptr) );
67  p4c_.store( p4c_.exchange(nullptr) );
68  }
69  }
70 
72  if(this != &iOther) {
73  packedPt_ = iOther.packedPt_;
74  packedY_ = iOther.packedY_;
75  packedPhi_ = iOther.packedPhi_;
76  packedM_ = iOther.packedM_;
77  if(p4c_) {
78  delete p4_.exchange(iOther.p4_.exchange(nullptr));
79  delete p4c_.exchange(iOther.p4c_.exchange(nullptr)) ;
80  } else {
81  delete p4_.exchange(nullptr);
82  delete p4c_.exchange(nullptr);
83  }
84  vertex_=std::move(iOther.vertex_);
85  dxy_ = iOther.dxy_;
86  dz_ = iOther.dz_;
87  dphi_ = iOther.dphi_;
88  pdgId_ = iOther.pdgId_;
89  charge_ = iOther.charge_;
90  mother_ = std::move(iOther.mother_);
91  statusFlags_ = iOther.statusFlags_;
92  }
93  return *this;
94  }
95 
97  PackedGenParticle c(iOther);
98  *this = std::move(c);
99  return *this;
100  }
101 
103  ~PackedGenParticle() override;
105  size_t numberOfDaughters() const override;
107  const reco::Candidate * daughter( size_type ) const override;
109  size_t numberOfMothers() const override;
111  const reco::Candidate * mother( size_type ) const override;
114  if(mother_.isNonnull() && mother_.isAvailable()&& mother_->status()==1 ){ //if pointing to the pruned version of myself
115  if(mother_->numberOfMothers() > 0)
116  return mother_->motherRef(0); // return my mother's (that is actually myself) mother
117  else
118  return edm::Ref<reco::GenParticleCollection>(); // return null ref
119  } else {
120  return mother_; //the stored ref is really my mother, or null, return that
121  }
122  }
124  const reco::GenParticleRef & lastPrunedRef() const { return mother_; }
125 
127  reco::Candidate * daughter( size_type ) override;
129  reco::Candidate * daughter(const std::string& s ) override;
131  const reco::Candidate * daughter(const std::string& s ) const override;
134  size_t numberOfSourceCandidatePtrs() const override {return 0;}
138  return reco::CandidatePtr();
139  }
140 
142  int charge() const override {
143  return charge_;
144  }
146  void setCharge( int charge) override {charge_=charge;}
148  int threeCharge() const override {return charge()*3;}
150  void setThreeCharge( int threecharge) override {}
152  const LorentzVector & p4() const override { if (!p4c_) unpack(); return *p4c_; }
154  const PolarLorentzVector & polarP4() const override { if (!p4c_) unpack(); return *p4_; }
156  Vector momentum() const override { if (!p4c_) unpack(); return p4c_.load()->Vect(); }
159  Vector boostToCM() const override { if (!p4c_) unpack(); return p4c_.load()->BoostToCM(); }
161  double p() const override { if (!p4c_) unpack(); return p4c_.load()->P(); }
163  double energy() const override { if (!p4c_) unpack(); return p4c_.load()->E(); }
165  double et() const override { return (pt()<=0) ? 0 : p4c_.load()->Et(); }
167  double et2() const override { return (pt()<=0) ? 0 : p4c_.load()->Et2(); }
169  double mass() const override { if (!p4c_) unpack(); return p4_.load()->M(); }
171  double massSqr() const override { if (!p4c_) unpack(); return p4_.load()->M()*p4_.load()->M(); }
172 
174  double mt() const override { if (!p4c_) unpack(); return p4_.load()->Mt(); }
176  double mtSqr() const override { if (!p4c_) unpack(); return p4_.load()->Mt2(); }
178  double px() const override { if (!p4c_) unpack(); return p4c_.load()->Px(); }
180  double py() const override { if (!p4c_) unpack(); return p4c_.load()->Py(); }
182  double pz() const override { if (!p4c_) unpack(); return p4c_.load()->Pz(); }
184  double pt() const override { if (!p4c_) unpack(); return p4_.load()->Pt();}
186  double phi() const override { if (!p4c_) unpack(); return p4_.load()->Phi(); }
188  double theta() const override { if (!p4c_) unpack(); return p4_.load()->Theta(); }
190  double eta() const override { if (!p4c_) unpack(); return p4_.load()->Eta(); }
192  double rapidity() const override { if (!p4c_) unpack(); return p4_.load()->Rapidity(); }
194  double y() const override { if (!p4c_) unpack(); return p4_.load()->Rapidity(); }
196  void setP4( const LorentzVector & p4 ) override {
197  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
198  *p4_ = PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M());
199  pack();
200  }
202  void setP4( const PolarLorentzVector & p4 ) override {
203  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
204  *p4_ = p4;
205  pack();
206  }
208  void setMass( double m ) override {
209  if (!p4c_) unpack();
210  *p4_ = PolarLorentzVector(p4_.load()->Pt(), p4_.load()->Eta(), p4_.load()->Phi(), m);
211  pack();
212  }
213  void setPz( double pz ) override {
214  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
215  *p4c_ = LorentzVector(p4c_.load()->Px(), p4c_.load()->Py(), pz, p4c_.load()->E());
216  *p4_ = PolarLorentzVector(p4c_.load()->Pt(), p4c_.load()->Eta(), p4c_.load()->Phi(), p4c_.load()->M());
217  pack();
218  }
220  const Point & vertex() const override { return vertex_; }//{ if (fromPV_) return Point(0,0,0); else return Point(0,0,100); }
222  double vx() const override { return vertex_.X(); }//{ return 0; }
224  double vy() const override { return vertex_.Y(); }//{ return 0; }
226  double vz() const override { return vertex_.Z(); }//{ if (fromPV_) return 0; else return 100; }
228  void setVertex( const Point & vertex ) override { vertex_ = vertex; }
229 
230  enum PVAssoc { NoPV=0, PVLoose=1, PVTight=2, PVUsedInFit=3 } ;
231 
232 
234  virtual float dxy() const { unpack(); return dxy_; }
236  virtual float dz() const { unpack(); return dz_; }
238  virtual float dxy(const Point &p) const ;
240  virtual float dz(const Point &p) const ;
241 
242 
244  int pdgId() const override { return pdgId_; }
245  // set PDG identifier
246  void setPdgId( int pdgId ) override { pdgId_ = pdgId; }
248  int status() const override { return 1; } /*FIXME*/
250  void setStatus( int status ) override {} /*FIXME*/
252  static const unsigned int longLivedTag = 0; /*FIXME*/
254  void setLongLived() override {} /*FIXME*/
256  bool longLived() const override;
258  static const unsigned int massConstraintTag = 0; /*FIXME*/
260  void setMassConstraint() override {} /*FIXME*/
262  bool massConstraint() const override;
263 
265  PackedGenParticle * clone() const override {
266  return new PackedGenParticle( *this );
267  }
268 
270  double vertexChi2() const override;
277  double vertexNdof() const override;
279  double vertexNormalizedChi2() const override;
281  double vertexCovariance(int i, int j) const override;
285  void fillVertexCovariance(CovarianceMatrix & v) const override;
288  bool hasMasterClone() const override;
291  const reco::CandidateBaseRef & masterClone() const override;
294  bool hasMasterClonePtr() const override;
297 
298  const reco::CandidatePtr & masterClonePtr() const override;
299 
301  template<typename Ref>
302  Ref masterRef() const { return masterClone().template castTo<Ref>(); }
304 
305  bool isElectron() const override;
306  bool isMuon() const override;
307  bool isStandAloneMuon() const override;
308  bool isGlobalMuon() const override;
309  bool isTrackerMuon() const override;
310  bool isCaloMuon() const override;
311  bool isPhoton() const override;
312  bool isConvertedPhoton() const override;
313  bool isJet() const override;
314 
315  const reco::GenStatusFlags &statusFlags() const { return statusFlags_; }
317 
319  //basic set of gen status flags accessible directly here
320  //the rest accessible through statusFlags()
321  //(see GenStatusFlags.h for their meaning)
322 
324  //these are robust, generator-independent functions for categorizing
325  //mainly final state particles, but also intermediate hadrons/taus
326 
327  //is particle prompt (not from hadron, muon, or tau decay) and final state
328  bool isPromptFinalState() const { return status()==1 && statusFlags_.isPrompt(); }
329 
330  //this particle is a direct decay product of a prompt tau and is final state
331  //(eg an electron or muon from a leptonic decay of a prompt tau)
333 
335  //these are generator history-dependent functions for tagging particles
336  //associated with the hard process
337  //Currently implemented for Pythia 6 and Pythia 8 status codes and history
338  //and may not have 100% consistent meaning across all types of processes
339  //Users are strongly encouraged to stick to the more robust flags above,
340  //as well as the expanded set available in GenStatusFlags.h
341 
342  //this particle is the final state direct descendant of a hard process particle
344 
345  //this particle is a direct decay product of a hardprocess tau and is final state
346  //(eg an electron or muon from a leptonic decay of a tau from the hard process)
348 
349 
350  protected:
352  void pack(bool unpackAfterwards=true) ;
353  void unpack() const ;
354 
356  mutable std::atomic<PolarLorentzVector*> p4_;
357  mutable std::atomic<LorentzVector*> p4c_;
359  Point vertex_;
360  float dxy_, dz_, dphi_;
362  int pdgId_;
364  int8_t charge_;
367  //status flags
369 
371  bool overlap( const reco::Candidate & ) const override;
372  template<typename, typename, typename> friend struct component;
373  friend class ::OverlapChecker;
374  friend class ShallowCloneCandidate;
376 
377  };
378 
379  typedef std::vector<pat::PackedGenParticle> PackedGenParticleCollection;
382 }
383 
384 #endif
bool isConvertedPhoton() const override
bool isAvailable() const
Definition: Ref.h:575
const reco::Candidate * mother(size_type) const override
return mother at a given position (throws an exception)
bool isTrackerMuon() const override
double py() const override
y coordinate of momentum vector
bool isPrompt() const
Point vertex_
vertex position
reco::GenStatusFlags & statusFlags()
edm::Ref< pat::PackedGenParticleCollection > PackedGenParticleRef
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
static const unsigned int longLivedTag
long lived flag
bool isElectron() const override
get a component
int threeCharge() const override
electric charge
friend class ShallowCloneCandidate
size_t size_type
Definition: Candidate.h:30
void setMassConstraint() override
set mass constraint flag
double eta() const override
momentum pseudorapidity
bool isGlobalMuon() const override
const reco::Candidate * daughter(size_type) const override
return daughter at a given position (throws an exception)
int pdgId_
PDG identifier.
bool isDirectPromptTauDecayProduct() const
bool fromHardProcessFinalState() const
#define nullptr
const PolarLorentzVector & polarP4() const override
four-momentum Lorentz vector
bool isDirectHardProcessTauDecayProduct() const
CovarianceMatrix vertexCovariance() const override
return SMatrix
PackedGenParticle(const PackedGenParticle &iOther)
friend class ShallowClonePtrCandidate
double energy() const override
energy
bool massConstraint() const override
do mass constraint?
const reco::CandidatePtr & masterClonePtr() const override
PackedGenParticle()
default constructor
bool isPhoton() const override
double pz() const override
z coordinate of momentum vector
void setCharge(int charge) override
set electric charge
PackedGenParticle & operator=(PackedGenParticle const &iOther)
std::atomic< LorentzVector * > p4c_
void setMass(double m) override
set particle mass
double vz() const override
z coordinate of vertex position
void pack(bool unpackAfterwards=true)
Vector momentum() const override
spatial momentum vector
bool fromHardProcess() const
Definition: HeavyIon.h:7
math::XYZPoint Point
point in the space
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
double px() const override
x coordinate of momentum vector
void setVertex(const Point &vertex) override
set vertex
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
reco::GenParticleRef motherRef() const
direct access to the mother reference (may be null)
PackedGenParticle(const reco::GenParticle &c)
double mass() const override
mass
double pt() const override
transverse momentum
double p() const override
magnitude of momentum vector
bool isDirectPromptTauDecayProductFinalState() const
int status() const override
status word
double theta() const override
momentum polar angle
reco::GenParticleRef mother_
Ref to first mother.
bool isDirectHardProcessTauDecayProductFinalState() const
math::XYZVector Vector
point in the space
bool isCaloMuon() const override
void setPz(double pz) override
bool hasMasterClonePtr() const override
size_t numberOfDaughters() const override
number of daughters
bool isPromptFinalState() const
PackedGenParticle & operator=(PackedGenParticle &&iOther)
~PackedGenParticle() override
destructor
void setThreeCharge(int threecharge) override
set electric charge
bool longLived() const override
is long lived?
const LorentzVector & p4() const override
four-momentum Lorentz vecto r
void setPdgId(int pdgId) override
double massSqr() const override
mass squared
size_t numberOfSourceCandidatePtrs() const override
PackedGenParticle(const reco::GenParticle &c, const edm::Ref< reco::GenParticleCollection > &mother)
const reco::GenParticleRef & lastPrunedRef() const
last surviving in pruned
double vx() const override
x coordinate of vertex position
void setLongLived() override
set long lived flag
double et2() const override
transverse energy squared (use this for cuts)!
static const unsigned int massConstraintTag
do mass constraint flag
reco::CandidateCollection daughters
collection of daughter candidates
std::atomic< PolarLorentzVector * > p4_
the four vector
double et() const override
transverse energy
int pdgId() const override
PDG identifier.
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
reco::CandidatePtr sourceCandidatePtr(size_type i) const override
void setP4(const PolarLorentzVector &p4) override
set 4-momentum
int charge() const override
electric charge
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
double mtSqr() const override
transverse mass squared
PackedGenParticle(PackedGenParticle &&iOther)
const Point & vertex() const override
vertex position
std::vector< pat::PackedGenParticle > PackedGenParticleCollection
double mt() const override
transverse mass
double vertexNdof() const override
const reco::GenStatusFlags & statusFlags() const
bool isJet() const override
void setStatus(int status) override
set status word
const reco::CandidateBaseRef & masterClone() const override
double vy() const override
y coordinate of vertex position
reco::GenStatusFlags statusFlags_
bool hasMasterClone() const override
double phi() const override
momentum azimuthal angle
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
double y() const override
rapidity
void setP4(const LorentzVector &p4) override
set 4-momentum
Ref masterRef() const
cast master clone reference to a concrete type
edm::RefVector< pat::PackedGenParticleCollection > PackedGenParticleRefVector
double rapidity() const override
rapidity
double vertexNormalizedChi2() const override
chi-squared divided by n.d.o.f.
virtual float dz() const
dz with respect to the PV ref
size_t numberOfMothers() const override
number of mothers
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
virtual float dxy() const
dxy with respect to the PV ref
def move(src, dest)
Definition: eostools.py:511
PackedGenParticle * clone() const override
returns a clone of the Candidate object
bool isStandAloneMuon() const override
math::XYZTLorentzVector LorentzVector
Lorentz vector.
bool overlap(const reco::Candidate &) const override
check overlap with another Candidate
double vertexChi2() const override
chi-squares
Vector boostToCM() const override
bool isMuon() const override