CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DataFormats/Candidate/interface/LeafCandidate.h

Go to the documentation of this file.
00001 #ifndef Candidate_LeafCandidate_h
00002 #define Candidate_LeafCandidate_h
00003 
00012 #include "DataFormats/Candidate/interface/Candidate.h"
00013 
00014 #include "DataFormats/Candidate/interface/iterator_imp_specific.h"
00015 
00016 namespace reco {
00017   
00018   class LeafCandidate : public Candidate {
00019   public:
00021     typedef CandidateCollection daughters;
00023     typedef int Charge;
00025     typedef math::XYZTLorentzVector LorentzVector;
00027     typedef math::PtEtaPhiMLorentzVector PolarLorentzVector;
00029     typedef math::XYZPoint Point;
00031     typedef math::XYZVector Vector;
00032 
00033     typedef unsigned int index;
00034 
00036     LeafCandidate() : 
00037       qx3_(0), pt_(0), eta_(0), phi_(0), mass_(0), 
00038       vertex_(0, 0, 0), pdgId_(0), status_(0),
00039       cachePolarFixed_( false ), cacheCartesianFixed_( false ) { }
00040     // constructor from candidate                                                         
00041     explicit LeafCandidate( const Candidate & c) :
00042       qx3_( c.charge()*3 ), pt_( c.p4().pt() ), eta_( c.p4().eta() ), phi_( c.p4().phi() )\
00043       , mass_( c.p4().mass() ),
00044       vertex_( c.vertex() ), pdgId_( c.pdgId() ), status_( c.status() ),
00045       cachePolarFixed_( false ), cacheCartesianFixed_( false ) {}
00046 
00048     LeafCandidate( Charge q, const LorentzVector & p4, const Point & vtx = Point( 0, \
00049                                                                                       0, 0 ),
00050                        int pdgId = 0, int status = 0, bool integerCharge = true ) :
00051       qx3_( q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
00052       vertex_( vtx ), pdgId_( pdgId ), status_( status ),
00053       cachePolarFixed_( false ), cacheCartesianFixed_( false ) {
00054       if ( integerCharge ) qx3_ *= 3;
00055     }
00057     LeafCandidate( Charge q, const PolarLorentzVector & p4, const Point & vtx = Point\
00058                        ( 0, 0, 0 ),
00059                        int pdgId = 0, int status = 0, bool integerCharge = true ) :
00060       qx3_( q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
00061       vertex_( vtx ), pdgId_( pdgId ), status_( status ),
00062       cachePolarFixed_( false ), cacheCartesianFixed_( false ){
00063       if ( integerCharge ) qx3_ *= 3;
00064     }
00065 
00067     virtual ~LeafCandidate();
00069     virtual const_iterator begin() const;
00071     virtual const_iterator end() const;
00073     virtual iterator begin();
00075     virtual iterator end();
00077     virtual size_t numberOfDaughters() const;
00079     virtual const Candidate * daughter( size_type ) const;
00081     virtual size_t numberOfMothers() const;
00083     virtual const Candidate * mother( size_type ) const;
00085     virtual Candidate * daughter( size_type );
00087     virtual Candidate * daughter(const std::string& s );
00089     virtual const Candidate * daughter(const std::string& s ) const;
00092     virtual size_t numberOfSourceCandidatePtrs() const { return 0;}
00095     virtual CandidatePtr sourceCandidatePtr( size_type i ) const {
00096       return CandidatePtr();
00097     }
00098 
00100     virtual int charge() const { return qx3_ / 3; }
00102     virtual void setCharge( Charge q ) { qx3_ = q * 3; }
00104     virtual int threeCharge() const { return qx3_; }
00106     virtual void setThreeCharge( Charge qx3 ) { qx3_ = qx3; }
00108     virtual const LorentzVector & p4() const { cacheCartesian(); return p4Cartesian_; }
00110     virtual const PolarLorentzVector & polarP4() const { cachePolar(); return p4Polar_; }
00112     virtual Vector momentum() const { cacheCartesian(); return p4Cartesian_.Vect(); }
00115     virtual Vector boostToCM() const { cacheCartesian(); return p4Cartesian_.BoostToCM(); }
00117     virtual double p() const { cacheCartesian(); return p4Cartesian_.P(); }
00119     virtual double energy() const { cacheCartesian(); return p4Cartesian_.E(); }
00121     virtual double et() const { cachePolar(); return p4Polar_.Et(); }
00123     virtual double mass() const { return mass_; }
00125     virtual double massSqr() const { return mass_ * mass_; }
00127     virtual double mt() const { cachePolar(); return p4Polar_.Mt(); }
00129     virtual double mtSqr() const { cachePolar(); return p4Polar_.Mt2(); }
00131     virtual double px() const { cacheCartesian(); return p4Cartesian_.Px(); }
00133     virtual double py() const { cacheCartesian(); return p4Cartesian_.Py(); }
00135     virtual double pz() const { cacheCartesian(); return p4Cartesian_.Pz(); }
00137     virtual double pt() const; 
00139     virtual double phi() const { return phi_; }
00141     virtual double theta() const { cacheCartesian(); return p4Cartesian_.Theta(); }
00143     virtual double eta() const { return eta_; }
00145     virtual double rapidity() const { cachePolar(); return p4Polar_.Rapidity(); }
00147     virtual double y() const { return rapidity(); }
00149     virtual void setP4( const LorentzVector & p4 ) {
00150       p4Cartesian_ = p4;
00151       p4Polar_ = p4;
00152       pt_ = p4Polar_.pt();
00153       eta_ = p4Polar_.eta();
00154       phi_ = p4Polar_.phi();
00155       mass_ = p4Polar_.mass();
00156       cachePolarFixed_ = true;
00157       cacheCartesianFixed_ = true;
00158     }
00160     virtual void setP4( const PolarLorentzVector & p4 ) {
00161       p4Polar_ = p4;
00162       pt_ = p4Polar_.pt();
00163       eta_ = p4Polar_.eta();
00164       phi_ = p4Polar_.phi();
00165       mass_ = p4Polar_.mass();
00166       cachePolarFixed_ = true;
00167       cacheCartesianFixed_ = false;
00168     }
00170     virtual void setMass( double m ) {
00171       mass_ = m;
00172       clearCache();
00173     }
00174     virtual void setPz( double pz ) {
00175       cacheCartesian();
00176       p4Cartesian_.SetPz(pz);
00177       p4Polar_ = p4Cartesian_;
00178       pt_ = p4Polar_.pt();
00179       eta_ = p4Polar_.eta();
00180       phi_ = p4Polar_.phi();
00181       mass_ = p4Polar_.mass();
00182     }
00184     virtual const Point & vertex() const { return vertex_; }
00186     virtual double vx() const { return vertex_.X(); }
00188     virtual double vy() const { return vertex_.Y(); }
00190     virtual double vz() const { return vertex_.Z(); }
00192     virtual void setVertex( const Point & vertex ) { vertex_ = vertex; }
00194     virtual int pdgId() const { return pdgId_; }
00195     // set PDG identifier                                                                 
00196     virtual void setPdgId( int pdgId ) { pdgId_ = pdgId; }
00198     virtual int status() const { return status_; }
00200     virtual void setStatus( int status ) { status_ = status; }
00202     static const unsigned int longLivedTag;
00204     virtual void setLongLived() { status_ |= longLivedTag; }
00206     virtual bool longLived() const { return status_ & longLivedTag; }
00208     static const unsigned int massConstraintTag;
00210     virtual void setMassConstraint() { status_ |= massConstraintTag;}
00212     virtual bool massConstraint() const { return status_ & massConstraintTag; }
00214     virtual LeafCandidate * clone() const {
00215       return new LeafCandidate( *this );
00216     }
00217 
00219     virtual double vertexChi2() const;
00226     virtual double vertexNdof() const;
00228     virtual double vertexNormalizedChi2() const;
00230     virtual double vertexCovariance(int i, int j) const;
00232     CovarianceMatrix vertexCovariance() const { CovarianceMatrix m; fillVertexCovariance(m); return m; }
00234     virtual void fillVertexCovariance(CovarianceMatrix & v) const;
00237     virtual bool hasMasterClone() const;
00240     virtual const CandidateBaseRef & masterClone() const;
00243     virtual bool hasMasterClonePtr() const;
00246     virtual const CandidatePtr & masterClonePtr() const;
00247 
00249     template<typename Ref>
00250       Ref masterRef() const { return masterClone().template castTo<Ref>(); }
00252 
00253     template<typename T> T get() const {
00254       if ( hasMasterClone() ) return masterClone()->get<T>();
00255       else return reco::get<T>( * this );
00256     }
00258     template<typename T, typename Tag> T get() const {
00259       if ( hasMasterClone() ) return masterClone()->get<T, Tag>();
00260       else return reco::get<T, Tag>( * this );
00261     }
00263     template<typename T> T get( size_type i ) const {
00264       if ( hasMasterClone() ) return masterClone()->get<T>( i );
00265       else return reco::get<T>( * this, i );
00266     }
00268     template<typename T, typename Tag> T get( size_type i ) const {
00269       if ( hasMasterClone() ) return masterClone()->get<T, Tag>( i );
00270       else return reco::get<T, Tag>( * this, i );
00271     }
00273     template<typename T> size_type numberOf() const {
00274       if ( hasMasterClone() ) return masterClone()->numberOf<T>();
00275       else return reco::numberOf<T>( * this );
00276     }
00278     template<typename T, typename Tag> size_type numberOf() const {
00279       if ( hasMasterClone() ) return masterClone()->numberOf<T, Tag>();
00280       else return reco::numberOf<T, Tag>( * this );
00281     }
00282 
00283     template<typename S>
00284       struct daughter_iterator {
00285         typedef boost::filter_iterator<S, const_iterator> type;
00286       };
00287 
00288     template<typename S>
00289       typename daughter_iterator<S>::type beginFilter( const S & s ) const {
00290       return boost::make_filter_iterator(s, begin(), end());
00291     }
00292     template<typename S>
00293       typename daughter_iterator<S>::type endFilter( const S & s ) const {
00294       return boost::make_filter_iterator(s, end(), end());
00295     }
00296 
00297 
00298     virtual bool isElectron() const;
00299     virtual bool isMuon() const;
00300     virtual bool isStandAloneMuon() const;
00301     virtual bool isGlobalMuon() const;
00302     virtual bool isTrackerMuon() const;
00303     virtual bool isCaloMuon() const;
00304     virtual bool isPhoton() const;
00305     virtual bool isConvertedPhoton() const;
00306     virtual bool isJet() const;
00307 
00308   protected:
00310     Charge qx3_;
00312     float pt_, eta_, phi_, mass_;
00314     Point vertex_;
00316     int pdgId_;
00318     int status_;
00320     mutable PolarLorentzVector p4Polar_;
00322     mutable LorentzVector p4Cartesian_;
00324     mutable  bool cachePolarFixed_, cacheCartesianFixed_;
00326     inline void cachePolar() const {
00327       if ( cachePolarFixed_ ) return;
00328       p4Polar_ = PolarLorentzVector( pt_, eta_, phi_, mass_ );
00329       cachePolarFixed_ = true;
00330     }
00332     inline void cacheCartesian() const {
00333       if ( cacheCartesianFixed_ ) return;
00334       cachePolar();
00335       p4Cartesian_ = p4Polar_;
00336       cacheCartesianFixed_ = true;
00337     }
00339     inline void clearCache() const {
00340       cachePolarFixed_ = false;
00341       cacheCartesianFixed_ = false;
00342     }
00344     virtual bool overlap( const Candidate & ) const;
00345     template<typename, typename, typename> friend struct component;
00346     friend class ::OverlapChecker;
00347     friend class ShallowCloneCandidate;
00348     friend class ShallowClonePtrCandidate;
00349 
00350   private:
00351     // const iterator implementation
00352     typedef candidate::const_iterator_imp_specific<daughters> const_iterator_imp_specific;
00353     // iterator implementation
00354     typedef candidate::iterator_imp_specific<daughters> iterator_imp_specific;
00355   };
00356 
00357 }
00358 
00359 #endif