CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DataFormats/Candidate/interface/LeafRefCandidateT.h

Go to the documentation of this file.
00001 #ifndef Candidate_LeafRefCandidateT_h
00002 #define Candidate_LeafRefCandidateT_h
00003 
00013 #include "DataFormats/Candidate/interface/Candidate.h"
00014 
00015 #include "DataFormats/Candidate/interface/iterator_imp_specific.h"
00016 
00017 namespace reco {
00018   
00019   template < class T >
00020   class LeafRefCandidateT : public Candidate {
00021   public:
00023     typedef CandidateCollection daughters;
00025     typedef int Charge;
00027     typedef math::XYZTLorentzVector LorentzVector;
00029     typedef math::PtEtaPhiMLorentzVector PolarLorentzVector;
00031     typedef math::XYZPoint Point;
00033     typedef math::XYZVector Vector;
00034 
00035     typedef unsigned int index;
00036 
00038     LeafRefCandidateT() : 
00039       mass_(0), 
00040       cachePolarFixed_( false ) { }
00041     // constructor from T                                                        
00042     explicit LeafRefCandidateT( const T & c, float m) :
00043       ref_(c),
00044       mass_( m ),
00045       cachePolarFixed_( false ), cacheCartesianFixed_( false ) {}
00046 
00048     virtual ~LeafRefCandidateT() {}
00050     virtual const_iterator begin() const;
00052     virtual const_iterator end() const;
00054     virtual iterator begin();
00056     virtual iterator end();
00058     virtual size_t numberOfDaughters() const { return 0; }
00060     virtual const Candidate * daughter( size_type ) const { return 0; }
00062     virtual size_t numberOfMothers() const { return 0; }
00064     virtual const Candidate * mother( size_type ) const { return 0; }
00066     virtual Candidate * daughter( size_type ) { return 0; }
00068     virtual Candidate * daughter(const std::string& s ) { return 0; }
00070     virtual const Candidate * daughter(const std::string& s ) const { return 0; }
00073     virtual size_t numberOfSourceCandidatePtrs() const { return 0;}
00076     virtual CandidatePtr sourceCandidatePtr( size_type i ) const {
00077       static CandidatePtr dummyPtr;
00078       return dummyPtr;
00079     }
00080 
00082     virtual int charge() const { return ref_->charge(); }
00084     virtual int pdgId() const { return 0; }
00085 
00087     virtual const LorentzVector & p4() const { cacheCartesian(); return p4Cartesian_; }
00089     virtual const PolarLorentzVector & polarP4() const { cachePolar(); return p4Polar_; }
00091     virtual Vector momentum() const { cacheCartesian(); return p4Cartesian_.Vect(); }
00094     virtual Vector boostToCM() const { cacheCartesian(); return p4Cartesian_.BoostToCM(); }
00096     virtual double p() const { cacheCartesian(); return p4Cartesian_.P(); }
00098     virtual double energy() const { cacheCartesian(); return p4Cartesian_.E(); }
00100     virtual double et() const { cachePolar(); return p4Polar_.Et(); }
00102     virtual double mass() const { return mass_; }
00104     virtual double massSqr() const { return mass_ * mass_; }
00106     virtual double mt() const { cachePolar(); return p4Polar_.Mt(); }
00108     virtual double mtSqr() const { cachePolar(); return p4Polar_.Mt2(); }
00110     virtual double px() const { cacheCartesian(); return p4Cartesian_.Px(); }
00112     virtual double py() const { cacheCartesian(); return p4Cartesian_.Py(); }
00114     virtual double pz() const { cacheCartesian(); return p4Cartesian_.Pz(); }
00116     virtual double pt() const { return ref_->pt(); } 
00118     virtual double phi() const { return ref_->phi(); }
00120     virtual double theta() const { return ref_->theta(); }
00122     virtual double eta() const { return ref_->eta(); }
00124     virtual double rapidity() const { cachePolar(); return p4Polar_.Rapidity(); }
00126     virtual double y() const { return rapidity(); }
00127 
00129     virtual void setMass( double m ) {
00130       mass_ = m;
00131       clearCache();
00132     }
00133 
00135     virtual const Point & vertex() const { return ref_->vertex(); }
00137     virtual double vx() const { return ref_->vx(); }
00139     virtual double vy() const { return ref_->vy(); }
00141     virtual double vz() const { return ref_->vz(); }
00142 
00143 
00145     virtual LeafRefCandidateT<T> * clone() const {
00146       return new LeafRefCandidateT<T>( *this );
00147     }
00148 
00149                      
00151     virtual bool hasMasterClone() const { return false; }
00154     virtual const CandidateBaseRef & masterClone() const { 
00155       static CandidateBaseRef dummyRef; return dummyRef; 
00156     }
00159     virtual bool hasMasterClonePtr() const { return false; }
00162     virtual const CandidatePtr & masterClonePtr() const { 
00163       static CandidatePtr dummyPtr; return dummyPtr; 
00164     }
00165 
00167     template<typename Ref>
00168       Ref masterRef() const { Ref dummyRef; return dummyRef; }
00170 
00171     template<typename C> C get() const {
00172       if ( hasMasterClone() ) return masterClone()->get<C>();
00173       else return reco::get<C>( * this );
00174     }
00176     template<typename C, typename Tag> C get() const {
00177       if ( hasMasterClone() ) return masterClone()->get<C, Tag>();
00178       else return reco::get<C, Tag>( * this );
00179     }
00181     template<typename C> C get( size_type i ) const {
00182       if ( hasMasterClone() ) return masterClone()->get<C>( i );
00183       else return reco::get<C>( * this, i );
00184     }
00186     template<typename C, typename Tag> C get( size_type i ) const {
00187       if ( hasMasterClone() ) return masterClone()->get<C, Tag>( i );
00188       else return reco::get<C, Tag>( * this, i );
00189     }
00191     template<typename C> size_type numberOf() const {
00192       if ( hasMasterClone() ) return masterClone()->numberOf<C>();
00193       else return reco::numberOf<C>( * this );
00194     }
00196     template<typename C, typename Tag> size_type numberOf() const {
00197       if ( hasMasterClone() ) return masterClone()->numberOf<C, Tag>();
00198       else return reco::numberOf<C, Tag>( * this );
00199     }
00200 
00201     template<typename S>
00202       struct daughter_iterator {
00203         typedef boost::filter_iterator<S, const_iterator> type;
00204       };
00205 
00206     template<typename S>
00207       typename daughter_iterator<S>::type beginFilter( const S & s ) const {
00208       return boost::make_filter_iterator(s, begin(), end());
00209     }
00210     template<typename S>
00211       typename daughter_iterator<S>::type endFilter( const S & s ) const {
00212       return boost::make_filter_iterator(s, end(), end());
00213     }
00214 
00215 
00216     virtual bool isElectron() const { return false; }
00217     virtual bool isMuon() const { return false; }
00218     virtual bool isStandAloneMuon() const { return false; }
00219     virtual bool isGlobalMuon() const { return false; }
00220     virtual bool isTrackerMuon() const { return false; }
00221     virtual bool isCaloMuon() const { return false; }
00222     virtual bool isPhoton() const { return false; }
00223     virtual bool isConvertedPhoton() const { return false; }
00224     virtual bool isJet() const { return false; }
00225 
00226   protected:
00229     T    ref_;
00231     float mass_;
00233     mutable PolarLorentzVector p4Polar_;
00235     mutable LorentzVector p4Cartesian_;
00237     mutable  edm::BoolCache cachePolarFixed_, cacheCartesianFixed_;
00239     inline void cachePolar() const {
00240       if ( cachePolarFixed_ ) return;
00241       p4Polar_ = PolarLorentzVector( ref_->pt(), ref_->eta(), ref_->phi(), mass_ );
00242       cachePolarFixed_ = true;
00243     }
00245     inline void cacheCartesian() const {
00246       if ( cacheCartesianFixed_ ) return;
00247       cachePolar();
00248       p4Cartesian_ = p4Polar_;
00249       cacheCartesianFixed_ = true;
00250     }
00252     inline void clearCache() const {
00253       cachePolarFixed_ = false;
00254       cacheCartesianFixed_ = false;
00255     }
00257     virtual bool overlap( const Candidate & ) const;
00258     virtual bool overlap( const LeafRefCandidateT & ) const;
00259     template<typename, typename, typename> friend struct component;
00260     friend class ::OverlapChecker;
00261     friend class ShallowCloneCandidate;
00262     friend class ShallowClonePtrCandidate;
00263 
00264   private:
00265     // const iterator implementation
00266     typedef candidate::const_iterator_imp_specific<daughters> const_iterator_imp_specific;
00267     // iterator implementation
00268     typedef candidate::iterator_imp_specific<daughters> iterator_imp_specific;
00269 
00270 
00274                                         
00275     virtual void setCharge( Charge q ) { return; }                                         
00276     virtual int threeCharge() const { return 0; }
00277     virtual void setThreeCharge( Charge qx3 ) { return; }
00278     virtual void setP4( const LorentzVector & p4 ) {
00279       return;
00280     }
00281     virtual void setP4( const PolarLorentzVector & p4 ) {
00282       return;
00283     }
00284     virtual void setPz( double pz ) {
00285       return;
00286     }                            
00287     virtual void setVertex( const Point & vertex ) { return; }
00288     virtual void setPdgId( int pdgId ) { return; }                                              
00289     virtual int status() const { return 0; }                                      
00290     virtual void setStatus( int status ) { return; }
00291     static const unsigned int longLivedTag;                                               
00292     virtual void setLongLived() { return; }                                      
00293     virtual bool longLived() const { return false; }
00294     static const unsigned int massConstraintTag;
00295     virtual void setMassConstraint() { return;}
00296     virtual bool massConstraint() const { return false; }  
00297     virtual double vertexChi2() const { return 0.; }
00298     virtual double vertexNdof() const { return 0.; }
00299     virtual double vertexNormalizedChi2() const { return 0.; }
00300     virtual double vertexCovariance(int i, int j) const { return 0.; }
00301     CovarianceMatrix vertexCovariance() const { CovarianceMatrix m; return m; }
00302     virtual void fillVertexCovariance(CovarianceMatrix & v) const { return ; }
00303     
00304   };
00305 
00306 
00307 
00308   template<class T>
00309   Candidate::const_iterator LeafRefCandidateT<T>::begin() const { 
00310     return const_iterator( new const_iterator_imp_specific ); 
00311   }
00312 
00313   template<class T>
00314   Candidate::const_iterator LeafRefCandidateT<T>::end() const { 
00315     return  const_iterator( new const_iterator_imp_specific ); 
00316   }
00317 
00318   template<class T>
00319   Candidate::iterator LeafRefCandidateT<T>::begin() { 
00320     return iterator( new iterator_imp_specific ); 
00321   }
00322   
00323   template<class T>
00324   Candidate::iterator LeafRefCandidateT<T>::end() { 
00325     return iterator( new iterator_imp_specific ); 
00326   }
00327   
00328   
00329   template<class T>
00330   bool LeafRefCandidateT<T>::overlap( const Candidate & o ) const { 
00331     return  p4() == o.p4() && vertex() == o.vertex() && charge() == o.charge();
00332   }
00333   
00334   
00335   template<class T>
00336   bool LeafRefCandidateT<T>::overlap( const LeafRefCandidateT & o ) const { 
00337     return  ref_ == o.ref_;
00338   }
00339 
00340 
00341 
00342 }
00343 
00344 #endif