CMS 3D CMS Logo

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