CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 namespace pat {
18  public:
29 
30  typedef unsigned int index;
31 
34  : p4_(0,0,0,0), p4c_(0,0,0,0), vertex_(0,0,0), pdgId_(0), charge_(0), unpacked_(false) { }
36  : p4_(c.pt(), c.eta(), c.phi(), c.mass()), p4c_(p4_), vertex_(0,0,0), pdgId_(c.pdgId()), charge_(c.charge()), mother_(c.motherRef(0)), unpacked_(true),
37  statusFlags_(c.statusFlags()) { pack(); }
39  : p4_(c.pt(), c.eta(), c.phi(), c.mass()), p4c_(p4_), vertex_(0,0,0), pdgId_(c.pdgId()), charge_(c.charge()), mother_(mother), unpacked_(true),
40  statusFlags_(c.statusFlags()) { pack(); }
41 
42 
44  virtual ~PackedGenParticle();
46  virtual size_t numberOfDaughters() const;
48  virtual const reco::Candidate * daughter( size_type ) const;
50  virtual size_t numberOfMothers() const;
52  virtual const reco::Candidate * mother( size_type ) const;
54  const reco::GenParticleRef & motherRef() const { return mother_; }
55 
57  virtual reco::Candidate * daughter( size_type );
59  virtual reco::Candidate * daughter(const std::string& s );
61  virtual const reco::Candidate * daughter(const std::string& s ) const;
64  virtual size_t numberOfSourceCandidatePtrs() const {return 0;}
68  return reco::CandidatePtr();
69  }
70 
72  virtual int charge() const {
73  return charge_;
74  }
76  virtual void setCharge( int charge) {charge_=charge;}
78  virtual int threeCharge() const {return charge()*3;}
80  virtual void setThreeCharge( int threecharge) {}
82  virtual const LorentzVector & p4() const { if (!unpacked_) unpack(); return p4c_; }
84  virtual const PolarLorentzVector & polarP4() const { if (!unpacked_) unpack(); return p4_; }
86  virtual Vector momentum() const { if (!unpacked_) unpack(); return p4c_.Vect(); }
89  virtual Vector boostToCM() const { if (!unpacked_) unpack(); return p4c_.BoostToCM(); }
91  virtual double p() const { if (!unpacked_) unpack(); return p4c_.P(); }
93  virtual double energy() const { if (!unpacked_) unpack(); return p4c_.E(); }
95  double et() const { return (pt()<=0) ? 0 : p4c_.Et(); }
97  double et2() const { return (pt()<=0) ? 0 : p4c_.Et2(); }
99  virtual double mass() const { if (!unpacked_) unpack(); return p4_.M(); }
101  virtual double massSqr() const { if (!unpacked_) unpack(); return p4_.M()*p4_.M(); }
102 
104  virtual double mt() const { if (!unpacked_) unpack(); return p4_.Mt(); }
106  virtual double mtSqr() const { if (!unpacked_) unpack(); return p4_.Mt2(); }
108  virtual double px() const { if (!unpacked_) unpack(); return p4c_.Px(); }
110  virtual double py() const { if (!unpacked_) unpack(); return p4c_.Py(); }
112  virtual double pz() const { if (!unpacked_) unpack(); return p4c_.Pz(); }
114  virtual double pt() const { if (!unpacked_) unpack(); return p4_.Pt();}
116  virtual double phi() const { if (!unpacked_) unpack(); return p4_.Phi(); }
118  virtual double theta() const { if (!unpacked_) unpack(); return p4_.Theta(); }
120  virtual double eta() const { if (!unpacked_) unpack(); return p4_.Eta(); }
122  virtual double rapidity() const { if (!unpacked_) unpack(); return p4_.Rapidity(); }
124  virtual double y() const { if (!unpacked_) unpack(); return p4_.Rapidity(); }
126  virtual void setP4( const LorentzVector & p4 ) {
127  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
128  p4_ = PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M());
129  pack();
130  }
132  virtual void setP4( const PolarLorentzVector & p4 ) {
133  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
134  p4_ = p4;
135  pack();
136  }
138  virtual void setMass( double m ) {
139  if (!unpacked_) unpack();
140  p4_ = PolarLorentzVector(p4_.Pt(), p4_.Eta(), p4_.Phi(), m);
141  pack();
142  }
143  virtual void setPz( double pz ) {
144  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
145  p4c_ = LorentzVector(p4c_.Px(), p4c_.Py(), pz, p4c_.E());
146  p4_ = PolarLorentzVector(p4c_.Pt(), p4c_.Eta(), p4c_.Phi(), p4c_.M());
147  pack();
148  }
150  virtual const Point & vertex() const { return vertex_; }//{ if (fromPV_) return Point(0,0,0); else return Point(0,0,100); }
152  virtual double vx() const { return vertex_.X(); }//{ return 0; }
154  virtual double vy() const { return vertex_.Y(); }//{ return 0; }
156  virtual double vz() const { return vertex_.Z(); }//{ if (fromPV_) return 0; else return 100; }
158  virtual void setVertex( const Point & vertex ) { vertex_ = vertex; }
159 
160  enum PVAssoc { NoPV=0, PVLoose=1, PVTight=2, PVUsedInFit=3 } ;
161 
162 
164  virtual float dxy() const { unpack(); return dxy_; }
166  virtual float dz() const { unpack(); return dz_; }
168  virtual float dxy(const Point &p) const ;
170  virtual float dz(const Point &p) const ;
171 
172 
174  virtual int pdgId() const { return pdgId_; }
175  // set PDG identifier
176  virtual void setPdgId( int pdgId ) { pdgId_ = pdgId; }
178  virtual int status() const { return 1; } /*FIXME*/
180  virtual void setStatus( int status ) {} /*FIXME*/
182  static const unsigned int longLivedTag = 0; /*FIXME*/
184  virtual void setLongLived() {} /*FIXME*/
186  virtual bool longLived() const;
188  static const unsigned int massConstraintTag = 0; /*FIXME*/
190  virtual void setMassConstraint() {} /*FIXME*/
192  virtual bool massConstraint() const;
193 
195  virtual PackedGenParticle * clone() const {
196  return new PackedGenParticle( *this );
197  }
198 
200  virtual double vertexChi2() const;
207  virtual double vertexNdof() const;
209  virtual double vertexNormalizedChi2() const;
211  virtual double vertexCovariance(int i, int j) const;
215  virtual void fillVertexCovariance(CovarianceMatrix & v) const;
218  virtual bool hasMasterClone() const;
221  virtual const reco::CandidateBaseRef & masterClone() const;
224  virtual bool hasMasterClonePtr() const;
227 
228  virtual const reco::CandidatePtr & masterClonePtr() const;
229 
231  template<typename Ref>
232  Ref masterRef() const { return masterClone().template castTo<Ref>(); }
234 
235  virtual bool isElectron() const;
236  virtual bool isMuon() const;
237  virtual bool isStandAloneMuon() const;
238  virtual bool isGlobalMuon() const;
239  virtual bool isTrackerMuon() const;
240  virtual bool isCaloMuon() const;
241  virtual bool isPhoton() const;
242  virtual bool isConvertedPhoton() const;
243  virtual bool isJet() const;
244 
245  const reco::GenStatusFlags &statusFlags() const { return statusFlags_; }
247 
249  //basic set of gen status flags accessible directly here
250  //the rest accessible through statusFlags()
251  //(see GenStatusFlags.h for their meaning)
252 
254  //these are robust, generator-independent functions for categorizing
255  //mainly final state particles, but also intermediate hadrons/taus
256 
257  //is particle prompt (not from hadron, muon, or tau decay) and final state
258  bool isPromptFinalState() const { return status()==1 && statusFlags_.isPrompt(); }
259 
260  //this particle is a direct decay product of a prompt tau and is final state
261  //(eg an electron or muon from a leptonic decay of a prompt tau)
263 
265  //these are generator history-dependent functions for tagging particles
266  //associated with the hard process
267  //Currently implemented for Pythia 6 and Pythia 8 status codes and history
268  //and may not have 100% consistent meaning across all types of processes
269  //Users are strongly encouraged to stick to the more robust flags above,
270  //as well as the expanded set available in GenStatusFlags.h
271 
272  //this particle is the final state direct descendant of a hard process particle
274 
275  //this particle is a direct decay product of a hardprocess tau and is final state
276  //(eg an electron or muon from a leptonic decay of a tau from the hard process)
278 
279 
280  protected:
282  void pack(bool unpackAfterwards=true) ;
283  void unpack() const ;
284 
289  mutable Point vertex_;
290  mutable float dxy_, dz_, dphi_;
292  int pdgId_;
294  int8_t charge_;
297  // is the momentum p4 unpacked
298  mutable bool unpacked_;
299  //status flags
301 
303  virtual bool overlap( const reco::Candidate & ) const;
304  template<typename, typename, typename> friend struct component;
305  friend class ::OverlapChecker;
306  friend class ShallowCloneCandidate;
308 
309  };
310 
311  typedef std::vector<pat::PackedGenParticle> PackedGenParticleCollection;
314 }
315 
316 #endif
virtual PackedGenParticle * clone() const
returns a clone of the Candidate object
virtual double vx() const
x coordinate of vertex position
virtual void setStatus(int status)
set status word
int i
Definition: DBlmapReader.cc:9
virtual double pz() const
z coordinate of momentum vector
bool isPrompt() const
Point vertex_
vertex position
virtual Vector boostToCM() const
reco::GenStatusFlags & statusFlags()
edm::Ref< pat::PackedGenParticleCollection > PackedGenParticleRef
virtual void fillVertexCovariance(CovarianceMatrix &v) const
fill SMatrix
static const unsigned int longLivedTag
long lived flag
CovarianceMatrix vertexCovariance() const
return SMatrix
virtual size_t numberOfMothers() const
number of mothers
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
friend class ShallowCloneCandidate
size_t size_type
Definition: Candidate.h:30
virtual void setVertex(const Point &vertex)
set vertex
virtual double vertexNdof() const
virtual int threeCharge() const
electric charge
int pdgId_
PDG identifier.
virtual void setP4(const PolarLorentzVector &p4)
set 4-momentum
bool isDirectPromptTauDecayProduct() const
virtual void setP4(const LorentzVector &p4)
set 4-momentum
bool fromHardProcessFinalState() const
virtual double vy() const
y coordinate of vertex position
virtual int status() const
status word
virtual bool isTrackerMuon() const
virtual reco::CandidatePtr sourceCandidatePtr(size_type i) const
bool isDirectHardProcessTauDecayProduct() const
virtual bool isJet() const
virtual ~PackedGenParticle()
destructor
virtual double pt() const
transverse momentum
virtual const reco::Candidate * daughter(size_type) const
return daughter at a given position (throws an exception)
friend class ShallowClonePtrCandidate
virtual double mtSqr() const
transverse mass squared
virtual size_t numberOfSourceCandidatePtrs() const
PackedGenParticle()
default constructor
virtual bool isElectron() const
get a component
virtual double theta() const
momentum polar angle
virtual bool isPhoton() const
PolarLorentzVector p4_
the four vector
void pack(bool unpackAfterwards=true)
virtual double phi() const
momentum azimuthal angle
bool fromHardProcess() const
virtual Vector momentum() const
spatial momentum vector
math::XYZPoint Point
point in the space
virtual double vertexNormalizedChi2() const
chi-squared divided by n.d.o.f.
virtual double p() const
magnitude of momentum vector
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual void setLongLived()
set long lived flag
PackedGenParticle(const reco::GenParticle &c)
virtual void setThreeCharge(int threecharge)
set electric charge
virtual double massSqr() const
mass squared
bool isDirectPromptTauDecayProductFinalState() const
virtual void setPz(double pz)
reco::GenParticleRef mother_
Ref to first mother.
virtual void setMassConstraint()
set mass constraint flag
virtual double eta() const
momentum pseudorapidity
bool isDirectHardProcessTauDecayProductFinalState() const
virtual bool isMuon() const
virtual const Point & vertex() const
vertex position
virtual bool longLived() const
is long lived?
math::XYZVector Vector
point in the space
virtual const reco::CandidateBaseRef & masterClone() const
virtual double vertexChi2() const
chi-squares
virtual size_t numberOfDaughters() const
number of daughters
math::XYZPoint Point
virtual const LorentzVector & p4() const
four-momentum Lorentz vecto r
virtual bool isStandAloneMuon() const
int j
Definition: DBlmapReader.cc:9
bool isPromptFinalState() const
virtual const reco::CandidatePtr & masterClonePtr() const
virtual double mt() const
transverse mass
virtual bool hasMasterClonePtr() const
const reco::GenParticleRef & motherRef() const
direct access to the mother reference (may be null)
PackedGenParticle(const reco::GenParticle &c, const edm::Ref< reco::GenParticleCollection > &mother)
virtual void setPdgId(int pdgId)
virtual double y() const
rapidity
static const unsigned int massConstraintTag
do mass constraint flag
virtual int pdgId() const
PDG identifier.
reco::CandidateCollection daughters
collection of daughter candidates
virtual bool overlap(const reco::Candidate &) const
check overlap with another Candidate
virtual const PolarLorentzVector & polarP4() const
four-momentum Lorentz vector
virtual bool hasMasterClone() const
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
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
std::vector< pat::PackedGenParticle > PackedGenParticleCollection
const reco::GenStatusFlags & statusFlags() const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
virtual double energy() const
energy
virtual bool isCaloMuon() const
virtual bool isGlobalMuon() const
virtual const reco::Candidate * mother(size_type) const
return mother at a given position (throws an exception)
virtual double rapidity() const
rapidity
virtual double mass() const
mass
virtual int charge() const
electric charge
virtual bool isConvertedPhoton() const
reco::GenStatusFlags statusFlags_
math::XYZPoint Point
point in the space
Definition: Candidate.h:41
virtual bool massConstraint() const
do mass constraint?
double et2() const
transverse energy squared (use this for cuts)!
virtual void setCharge(int charge)
set electric charge
virtual double py() const
y coordinate of momentum vector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
volatile std::atomic< bool > shutdown_flag false
double et() const
transverse energy
virtual void setMass(double m)
set particle mass
virtual double px() const
x coordinate of momentum vector
Ref masterRef() const
cast master clone reference to a concrete type
edm::RefVector< pat::PackedGenParticleCollection > PackedGenParticleRefVector
virtual float dz() const
dz with respect to the PV ref
virtual float dxy() const
dxy with respect to the PV ref
math::XYZTLorentzVector LorentzVector
Lorentz vector.
virtual double vz() const
z coordinate of vertex position
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:39