CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LeafCandidate.h
Go to the documentation of this file.
1 #ifndef Candidate_LeafCandidate_h
2 #define Candidate_LeafCandidate_h
3 
12 
14 
17 
18 
19 namespace reco {
20 
21  class LeafCandidate : public Candidate {
22  public:
26  typedef int Charge;
35 
36  typedef unsigned int index;
37 
38  static double magd(GlobalVector v) { return std::sqrt(double(v.x())*double(v.x()) + double(v.y())*double(v.y()) + double(v.z())*double(v.z()) );}
39  static double dmass(GlobalVector v, double e) { double m2 = e*e-magd(v); return m2>0 ? std::sqrt(m2) : 0;}
40 
43  qx3_(0), pt_(0), eta_(0), phi_(0), mass_(0),
44  vertex_(0, 0, 0), pdgId_(0), status_(0),
46  // constructor from candidate
47  explicit LeafCandidate( const Candidate & c) :
48  qx3_( c.charge()*3 ), pt_( c.p4().pt() ), eta_( c.p4().eta() ), phi_( c.p4().phi() )
49  , mass_( c.p4().mass() ),
50  vertex_( c.vertex() ), pdgId_( c.pdgId() ), status_( c.status() ),
52 
54  template<typename P4>
55  LeafCandidate( Charge q, const P4 & p4, const Point & vtx = Point( 0, 0, 0 ),
56  int pdgId = 0, int status = 0, bool integerCharge = true ) :
57  qx3_(integerCharge ? 3*q : q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
58  vertex_( vtx ), pdgId_( pdgId ), status_( status ),
60 
61 
63  LeafCandidate( Charge q, const PtEtaPhiMass & p4, const Point & vtx = Point( 0, 0, 0 ),
64  int pdgId = 0, int status = 0, bool integerCharge = true ) :
65  qx3_(integerCharge ? 3*q : q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
66  vertex_( vtx ), pdgId_( pdgId ), status_( status ),
68 
70  LeafCandidate( Charge q, const LorentzVector & p4, const Point & vtx = Point( 0, 0, 0 ),
71  int pdgId = 0, int status = 0, bool integerCharge = true ) :
72  qx3_( q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
73  vertex_( vtx ), pdgId_( pdgId ), status_( status ), p4Cartesian_(p4),
75  if ( integerCharge ) qx3_ *= 3;
76  }
78  LeafCandidate( Charge q, const PolarLorentzVector & p4, const Point & vtx = Point( 0, 0, 0 ),
79  int pdgId = 0, int status = 0, bool integerCharge = true ) :
80  qx3_( q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
81  vertex_( vtx ), pdgId_( pdgId ), status_( status ), p4Polar_(p4),
83  if ( integerCharge ) qx3_ *= 3;
84  }
85 
87  LeafCandidate( Charge q, const GlobalVector & p3, float iEnergy, bool massless, const Point & vtx = Point( 0, 0, 0 ),
88  int pdgId = 0, int status = 0, bool integerCharge = true ) :
89  qx3_( q ), pt_( p3.perp() ), eta_( p3.eta() ), phi_( p3.phi() ), mass_(massless ? 0. : dmass(p3,iEnergy) ),
90  vertex_( vtx ), pdgId_( pdgId ), status_( status ), p4Polar_(pt_,eta_,phi_,mass_), p4Cartesian_(p3.x(),p3.y(),p3.z(), massless ? magd(p3) : iEnergy),
92  if ( integerCharge ) qx3_ *= 3;
93  }
94 
95 
97  LeafCandidate( Charge q, const GlobalVector & p3, float iEnergy, float imass, const Point & vtx = Point( 0, 0, 0 ),
98  int pdgId = 0, int status = 0, bool integerCharge = true ) :
99  qx3_( q ), pt_( p3.perp() ), eta_( p3.eta() ), phi_( p3.phi() ), mass_(imass),
100  vertex_( vtx ), pdgId_( pdgId ), status_( status ), p4Polar_(pt_,eta_,phi_,mass_), p4Cartesian_(p3.x(),p3.y(),p3.z(), iEnergy),
102  if ( integerCharge ) qx3_ *= 3;
103  }
104 
105 
107  virtual ~LeafCandidate();
109  virtual const_iterator begin() const;
111  virtual const_iterator end() const;
113  virtual iterator begin();
115  virtual iterator end();
117  virtual size_t numberOfDaughters() const;
119  virtual const Candidate * daughter( size_type ) const;
121  virtual size_t numberOfMothers() const;
123  virtual const Candidate * mother( size_type ) const;
125  virtual Candidate * daughter( size_type );
127  virtual Candidate * daughter(const std::string& s );
129  virtual const Candidate * daughter(const std::string& s ) const;
132  virtual size_t numberOfSourceCandidatePtrs() const { return 0;}
136  return CandidatePtr();
137  }
138 
140  virtual int charge() const GCC11_FINAL { return qx3_ / 3; }
142  virtual void setCharge( Charge q ) GCC11_FINAL { qx3_ = q * 3; }
144  virtual int threeCharge() const GCC11_FINAL { return qx3_; }
146  virtual void setThreeCharge( Charge qx3 ) GCC11_FINAL { qx3_ = qx3; }
148  virtual const LorentzVector & p4() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_; }
152  virtual Vector momentum() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Vect(); }
155  virtual Vector boostToCM() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.BoostToCM(); }
157  virtual double p() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.P(); }
159  virtual double energy() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.E(); }
161  virtual double et() const GCC11_FINAL { cachePolar(); return (pt_<=0) ? 0 : p4Polar_.Et(); }
163  virtual float mass() const GCC11_FINAL { return mass_; }
165  virtual float massSqr() const GCC11_FINAL { return mass_ * mass_; }
166 
168  virtual double mt() const GCC11_FINAL { cachePolar(); return p4Polar_.Mt(); }
170  virtual double mtSqr() const GCC11_FINAL { cachePolar(); return p4Polar_.Mt2(); }
172  virtual double px() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Px(); }
174  virtual double py() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Py(); }
176  virtual double pz() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Pz(); }
178  virtual float pt() const GCC11_FINAL { return pt_;}
180  virtual float phi() const GCC11_FINAL { return phi_; }
182  virtual double theta() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Theta(); }
184  virtual float eta() const GCC11_FINAL { return eta_; }
186  virtual double rapidity() const GCC11_FINAL { cachePolar(); return p4Polar_.Rapidity(); }
188  virtual double y() const GCC11_FINAL { return rapidity(); }
190  virtual void setP4( const LorentzVector & p4 ) GCC11_FINAL {
191  p4Cartesian_ = p4;
192  p4Polar_ = p4;
193  pt_ = p4Polar_.pt();
194  eta_ = p4Polar_.eta();
195  phi_ = p4Polar_.phi();
196  mass_ = p4Polar_.mass();
197  cachePolarFixed_ = true;
198  cacheCartesianFixed_ = true;
199  }
201  virtual void setP4( const PolarLorentzVector & p4 ) GCC11_FINAL {
202  p4Polar_ = p4;
203  pt_ = p4Polar_.pt();
204  eta_ = p4Polar_.eta();
205  phi_ = p4Polar_.phi();
206  mass_ = p4Polar_.mass();
207  cachePolarFixed_ = true;
208  cacheCartesianFixed_ = false;
209  }
211  virtual void setMass( double m ) GCC11_FINAL {
212  mass_ = m;
213  clearCache();
214  }
215  virtual void setPz( double pz ) GCC11_FINAL {
216  cacheCartesian();
217  p4Cartesian_.SetPz(pz);
219  pt_ = p4Polar_.pt();
220  eta_ = p4Polar_.eta();
221  phi_ = p4Polar_.phi();
222  mass_ = p4Polar_.mass();
223  }
225  virtual const Point & vertex() const { return vertex_; }
227  virtual double vx() const { return vertex_.X(); }
229  virtual double vy() const { return vertex_.Y(); }
231  virtual double vz() const { return vertex_.Z(); }
233  virtual void setVertex( const Point & vertex ) { vertex_ = vertex; }
234 
236  virtual int pdgId() const GCC11_FINAL { return pdgId_; }
237  // set PDG identifier
238  virtual void setPdgId( int pdgId ) GCC11_FINAL { pdgId_ = pdgId; }
240  virtual int status() const GCC11_FINAL { return status_; }
242  virtual void setStatus( int status ) GCC11_FINAL { status_ = status; }
244  static const unsigned int longLivedTag;
248  virtual bool longLived() const GCC11_FINAL { return status_ & longLivedTag; }
250  static const unsigned int massConstraintTag;
255 
257  virtual LeafCandidate * clone() const {
258  return new LeafCandidate( *this );
259  }
260 
262  virtual double vertexChi2() const;
269  virtual double vertexNdof() const;
271  virtual double vertexNormalizedChi2() const;
273  virtual double vertexCovariance(int i, int j) const;
277  virtual void fillVertexCovariance(CovarianceMatrix & v) const;
280  virtual bool hasMasterClone() const;
283  virtual const CandidateBaseRef & masterClone() const;
286  virtual bool hasMasterClonePtr() const;
289  virtual const CandidatePtr & masterClonePtr() const;
290 
292  template<typename Ref>
293  Ref masterRef() const { return masterClone().template castTo<Ref>(); }
295 
296  template<typename T> T get() const {
297  if ( hasMasterClone() ) return masterClone()->get<T>();
298  else return reco::get<T>( * this );
299  }
301  template<typename T, typename Tag> T get() const {
302  if ( hasMasterClone() ) return masterClone()->get<T, Tag>();
303  else return reco::get<T, Tag>( * this );
304  }
306  template<typename T> T get( size_type i ) const {
307  if ( hasMasterClone() ) return masterClone()->get<T>( i );
308  else return reco::get<T>( * this, i );
309  }
311  template<typename T, typename Tag> T get( size_type i ) const {
312  if ( hasMasterClone() ) return masterClone()->get<T, Tag>( i );
313  else return reco::get<T, Tag>( * this, i );
314  }
316  template<typename T> size_type numberOf() const {
317  if ( hasMasterClone() ) return masterClone()->numberOf<T>();
318  else return reco::numberOf<T>( * this );
319  }
321  template<typename T, typename Tag> size_type numberOf() const {
322  if ( hasMasterClone() ) return masterClone()->numberOf<T, Tag>();
323  else return reco::numberOf<T, Tag>( * this );
324  }
325 
326  template<typename S>
328  typedef boost::filter_iterator<S, const_iterator> type;
329  };
330 
331  template<typename S>
332  typename daughter_iterator<S>::type beginFilter( const S & s ) const {
333  return boost::make_filter_iterator(s, begin(), end());
334  }
335  template<typename S>
336  typename daughter_iterator<S>::type endFilter( const S & s ) const {
337  return boost::make_filter_iterator(s, end(), end());
338  }
339 
340 
341  virtual bool isElectron() const;
342  virtual bool isMuon() const;
343  virtual bool isStandAloneMuon() const;
344  virtual bool isGlobalMuon() const;
345  virtual bool isTrackerMuon() const;
346  virtual bool isCaloMuon() const;
347  virtual bool isPhoton() const;
348  virtual bool isConvertedPhoton() const;
349  virtual bool isJet() const;
350 
351  protected:
355  float pt_, eta_, phi_, mass_;
359  int pdgId_;
361  int status_;
369  inline void cachePolar() const {
370  if ( cachePolarFixed_ ) return;
372  cachePolarFixed_ = true;
373  }
375  inline void cacheCartesian() const {
376  if ( cacheCartesianFixed_ ) return;
377  cachePolar();
379  cacheCartesianFixed_ = true;
380  }
382  inline void clearCache() const {
383  cachePolarFixed_ = false;
384  cacheCartesianFixed_ = false;
385  }
387  virtual bool overlap( const Candidate & ) const;
388  template<typename, typename, typename> friend struct component;
389  friend class ::OverlapChecker;
390  friend class ShallowCloneCandidate;
392 
393  private:
394  // const iterator implementation
396  // iterator implementation
398  };
399 
400 }
401 
402 #endif
value_type const * get() const
Definition: RefToBase.h:213
int Charge
electric charge type
Definition: Candidate.h:39
int i
Definition: DBlmapReader.cc:9
virtual int pdgId() const
PDG identifier.
virtual double p() const
magnitude of momentum vector
static const unsigned int longLivedTag
long lived flag
virtual void setMassConstraint()
set mass constraint flag
virtual float massSqr() const
mass squared
#define GCC11_FINAL
LorentzVector p4Cartesian_
internal cache for p4
void clearCache() const
clear internal cache
daughter_iterator< S >::type endFilter(const S &s) const
math::XYZVector Vector
point in the space
Definition: Candidate.h:47
virtual float pt() const
transverse momentum
size_t size_type
Definition: Candidate.h:34
virtual double et() const
transverse energy
candidate::const_iterator const_iterator
Definition: Candidate.h:35
virtual void setCharge(Charge q)
set electric charge
size_type numberOf() const
number of components
virtual double vertexChi2() const
chi-squares
int pdgId_
PDG identifier.
virtual void setStatus(int status)
set status word
virtual const Point & vertex() const
vertex position (overwritten by PF...)
size_type numberOf() const
number of components
virtual int status() const
status word
virtual bool isConvertedPhoton() const
candidate::const_iterator_imp_specific< daughters > const_iterator_imp_specific
virtual float phi() const
momentum azimuthal angle
daughter_iterator< S >::type beginFilter(const S &s) const
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: LeafCandidate.h:30
CandidateCollection daughters
collection of daughter candidates
Definition: LeafCandidate.h:24
float pt_
four-momentum Lorentz vector
virtual Vector momentum() const
spatial momentum vector
virtual bool isPhoton() const
virtual double y() const
rapidity
virtual bool isStandAloneMuon() const
virtual void setP4(const LorentzVector &p4)
set 4-momentum
PolarLorentzVector p4Polar_
internal cache for p4
void cachePolar() const
set internal cache
candidate::iterator_imp_specific< daughters > iterator_imp_specific
Point vertex_
vertex position
LeafCandidate(Charge q, const GlobalVector &p3, float iEnergy, bool massless, const Point &vtx=Point(0, 0, 0), int pdgId=0, int status=0, bool integerCharge=true)
constructor from values
Definition: LeafCandidate.h:87
virtual double vy() const
y coordinate of vertex position
virtual bool longLived() const
is long lived?
float float float z
virtual bool isMuon() const
virtual void setP4(const PolarLorentzVector &p4)
set 4-momentum
static const unsigned int massConstraintTag
do mass constraint flag
virtual size_t numberOfDaughters() const
number of daughters
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
static double magd(GlobalVector v)
Definition: LeafCandidate.h:38
virtual bool isGlobalMuon() const
virtual double energy() const
energy
virtual const CandidatePtr & masterClonePtr() const
virtual const Candidate * daughter(size_type) const
return daughter at a given position (throws an exception)
CovarianceMatrix vertexCovariance() const
return SMatrix
virtual ~LeafCandidate()
destructor
Definition: LeafCandidate.cc:5
virtual void setThreeCharge(Charge qx3)
set electric charge
virtual bool hasMasterClone() const
Ref masterRef() const
cast master clone reference to a concrete type
virtual float eta() const
momentum pseudorapidity
T sqrt(T t)
Definition: SSEVec.h:48
LeafCandidate(const Candidate &c)
Definition: LeafCandidate.h:47
int status_
status word
virtual int charge() const
electric charge
LeafCandidate(Charge q, const GlobalVector &p3, float iEnergy, float imass, const Point &vtx=Point(0, 0, 0), int pdgId=0, int status=0, bool integerCharge=true)
constructor from values
Definition: LeafCandidate.h:97
virtual CandidatePtr sourceCandidatePtr(size_type i) const
int j
Definition: DBlmapReader.cc:9
virtual double vertexNormalizedChi2() const
chi-squared divided by n.d.o.f.
LeafCandidate(Charge q, const PolarLorentzVector &p4, const Point &vtx=Point(0, 0, 0), int pdgId=0, int status=0, bool integerCharge=true)
constructor from values
Definition: LeafCandidate.h:78
static double dmass(GlobalVector v, double e)
Definition: LeafCandidate.h:39
virtual int threeCharge() const
electric charge
LeafCandidate(Charge q, const PtEtaPhiMass &p4, const Point &vtx=Point(0, 0, 0), int pdgId=0, int status=0, bool integerCharge=true)
constructor from values
Definition: LeafCandidate.h:63
unsigned int index
Definition: LeafCandidate.h:36
virtual bool overlap(const Candidate &) const
check overlap with another Candidate
virtual double vz() const
z coordinate of vertex position
virtual bool hasMasterClonePtr() const
virtual const_iterator begin() const
first daughter const_iterator
Definition: LeafCandidate.cc:7
virtual void setVertex(const Point &vertex)
set vertex
virtual bool isElectron() const
virtual double theta() const
momentum polar angle
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalVector
vector in glovbal coordinate system
Definition: Vector3D.h:27
boost::filter_iterator< S, const_iterator > type
virtual bool isCaloMuon() const
virtual void setPz(double pz)
candidate::iterator iterator
Definition: Candidate.h:36
LeafCandidate(Charge q, const LorentzVector &p4, const Point &vtx=Point(0, 0, 0), int pdgId=0, int status=0, bool integerCharge=true)
constructor from values
Definition: LeafCandidate.h:70
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
virtual size_t numberOfSourceCandidatePtrs() const
virtual double px() const
x coordinate of momentum vector
virtual void setLongLived()
set long lived flag
virtual bool isTrackerMuon() const
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
virtual double mt() const
transverse mass
void cacheCartesian() const
set internal cache
string const
Definition: compareJSON.py:14
virtual bool isJet() const
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
virtual double pz() const
z coordinate of momentum vector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
LeafCandidate()
default constructor
Definition: LeafCandidate.h:42
virtual double rapidity() const
rapidity
LeafCandidate(Charge q, const P4 &p4, const Point &vtx=Point(0, 0, 0), int pdgId=0, int status=0, bool integerCharge=true)
constructor from Any values
Definition: LeafCandidate.h:55
virtual Vector boostToCM() const
T perp() const
Magnitude of transverse component.
virtual const PolarLorentzVector & polarP4() const
four-momentum Lorentz vector
virtual size_t numberOfMothers() const
number of mothers
virtual const CandidateBaseRef & masterClone() const
virtual void setPdgId(int pdgId)
math::XYZVector Vector
point in the space
Definition: LeafCandidate.h:34
virtual double mtSqr() const
transverse mass squared
virtual double vx() const
x coordinate of vertex position
math::XYZPoint Point
point in the space
Definition: Candidate.h:45
virtual float mass() const
mass
bool cachePolarFixed_
has cache been set?
volatile std::atomic< bool > shutdown_flag false
virtual LeafCandidate * clone() const
returns a clone of the Candidate object
virtual void setMass(double m)
set particle mass
Definition: DDAxes.h:10
long double T
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
virtual bool massConstraint() const
do mass constraint?
virtual const_iterator end() const
last daughter const_iterator
virtual void fillVertexCovariance(CovarianceMatrix &v) const
fill SMatrix
virtual double vertexNdof() const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:28
virtual double py() const
y coordinate of momentum vector
int Charge
electric charge type
Definition: LeafCandidate.h:26
Charge qx3_
electric charge
virtual const Candidate * mother(size_type) const
return mother at a given position (throws an exception)
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:32
double p3[4]
Definition: TauolaWrapper.h:91
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:43