Go to the documentation of this file.00001 #ifndef Candidate_LeafRefCandidateT_h
00002 #define Candidate_LeafRefCandidateT_h
00003
00012 #include "DataFormats/Candidate/interface/Candidate.h"
00013
00014 #include "DataFormats/Candidate/interface/iterator_imp_specific.h"
00015
00016 #include "DataFormats/Common/interface/BoolCache.h"
00017
00018 namespace reco {
00019
00020 template < class T >
00021 class LeafRefCandidateT : public Candidate {
00022 public:
00024 typedef CandidateCollection daughters;
00026 typedef int Charge;
00028 typedef math::XYZTLorentzVector LorentzVector;
00030 typedef math::PtEtaPhiMLorentzVector PolarLorentzVector;
00032 typedef math::XYZPoint Point;
00034 typedef math::XYZVector Vector;
00035
00036 typedef unsigned int index;
00037
00039 LeafRefCandidateT() :
00040 mass_(0),
00041 cachePolarFixed_( false ) { }
00042
00043 explicit LeafRefCandidateT( const T & c, float m) :
00044 ref_(c),
00045 mass_( m ),
00046 cachePolarFixed_( false ), cacheCartesianFixed_( false ) {}
00047
00049 virtual ~LeafRefCandidateT() {}
00051 virtual const_iterator begin() const;
00053 virtual const_iterator end() const;
00055 virtual iterator begin();
00057 virtual iterator end();
00059 virtual size_t numberOfDaughters() const GCC11_FINAL { return 0; }
00061 virtual const Candidate * daughter( size_type ) const GCC11_FINAL { return 0; }
00063 virtual size_t numberOfMothers() const GCC11_FINAL { return 0; }
00065 virtual const Candidate * mother( size_type ) const GCC11_FINAL { return 0; }
00067 virtual Candidate * daughter( size_type ) GCC11_FINAL { return 0; }
00069 virtual Candidate * daughter(const std::string& s ) GCC11_FINAL { return 0; }
00071 virtual const Candidate * daughter(const std::string& s ) const GCC11_FINAL { return 0; }
00074 virtual size_t numberOfSourceCandidatePtrs() const GCC11_FINAL { return 0;}
00077 virtual CandidatePtr sourceCandidatePtr( size_type i ) const GCC11_FINAL {
00078 static CandidatePtr dummyPtr;
00079 return dummyPtr;
00080 }
00081
00083 virtual int charge() const GCC11_FINAL { return ref_->charge(); }
00085 virtual int pdgId() const GCC11_FINAL { return 0; }
00086
00088 virtual const LorentzVector & p4() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_; }
00090 virtual const PolarLorentzVector & polarP4() const GCC11_FINAL { cachePolar(); return p4Polar_; }
00092 virtual Vector momentum() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Vect(); }
00095 virtual Vector boostToCM() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.BoostToCM(); }
00097 virtual double p() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.P(); }
00099 virtual double energy() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.E(); }
00101 virtual double et() const GCC11_FINAL { cachePolar(); return p4Polar_.Et(); }
00103 virtual float mass() const GCC11_FINAL { return mass_; }
00105 virtual float massSqr() const GCC11_FINAL { return mass_ * mass_; }
00107 virtual double mt() const GCC11_FINAL { cachePolar(); return p4Polar_.Mt(); }
00109 virtual double mtSqr() const GCC11_FINAL { cachePolar(); return p4Polar_.Mt2(); }
00111 virtual double px() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Px(); }
00113 virtual double py() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Py(); }
00115 virtual double pz() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Pz(); }
00117 virtual float pt() const GCC11_FINAL { return ref_->pt(); }
00119 virtual float phi() const GCC11_FINAL { return ref_->phi(); }
00121 virtual double theta() const GCC11_FINAL { return ref_->theta(); }
00123 virtual float eta() const GCC11_FINAL { return ref_->eta(); }
00125 virtual double rapidity() const GCC11_FINAL { cachePolar(); return p4Polar_.Rapidity(); }
00127 virtual double y() const GCC11_FINAL { return rapidity(); }
00128
00130 virtual void setMass( double m ) GCC11_FINAL {
00131 mass_ = m;
00132 clearCache();
00133 }
00134
00136 virtual const Point & vertex() const GCC11_FINAL { return ref_->vertex(); }
00138 virtual double vx() const GCC11_FINAL { return ref_->vx(); }
00140 virtual double vy() const GCC11_FINAL { return ref_->vy(); }
00142 virtual double vz() const GCC11_FINAL { return ref_->vz(); }
00143
00144
00146 virtual LeafRefCandidateT<T> * clone() const GCC11_FINAL {
00147 return new LeafRefCandidateT<T>( *this );
00148 }
00149
00150
00152 virtual bool hasMasterClone() const GCC11_FINAL { return false; }
00155 virtual const CandidateBaseRef & masterClone() const GCC11_FINAL {
00156 static CandidateBaseRef dummyRef; return dummyRef;
00157 }
00160 virtual bool hasMasterClonePtr() const GCC11_FINAL { return false; }
00163 virtual const CandidatePtr & masterClonePtr() const GCC11_FINAL {
00164 static CandidatePtr dummyPtr; return dummyPtr;
00165 }
00166
00168 template<typename Ref>
00169 Ref masterRef() const { Ref dummyRef; return dummyRef; }
00171
00172 template<typename C> C get() const {
00173 if ( hasMasterClone() ) return masterClone()->template get<C>();
00174 else return reco::get<C>( * this );
00175 }
00177 template<typename C, typename Tag> C get() const {
00178 if ( hasMasterClone() ) return masterClone()->template get<C, Tag>();
00179 else return reco::get<C, Tag>( * this );
00180 }
00182 template<typename C> C get( size_type i ) const {
00183 if ( hasMasterClone() ) return masterClone()->template get<C>( i );
00184 else return reco::get<C>( * this, i );
00185 }
00187 template<typename C, typename Tag> C get( size_type i ) const {
00188 if ( hasMasterClone() ) return masterClone()->template get<C, Tag>( i );
00189 else return reco::get<C, Tag>( * this, i );
00190 }
00192 template<typename C> size_type numberOf() const {
00193 if ( hasMasterClone() ) return masterClone()->template numberOf<C>();
00194 else return reco::numberOf<C>( * this );
00195 }
00197 template<typename C, typename Tag> size_type numberOf() const {
00198 if ( hasMasterClone() ) return masterClone()->template numberOf<C, Tag>();
00199 else return reco::numberOf<C, Tag>( * this );
00200 }
00201
00202 template<typename S>
00203 struct daughter_iterator GCC11_FINAL {
00204 typedef boost::filter_iterator<S, const_iterator> type;
00205 };
00206
00207 template<typename S>
00208 typename daughter_iterator<S>::type beginFilter( const S & s ) const {
00209 return boost::make_filter_iterator(s, begin(), end());
00210 }
00211 template<typename S>
00212 typename daughter_iterator<S>::type endFilter( const S & s ) const {
00213 return boost::make_filter_iterator(s, end(), end());
00214 }
00215
00216
00217 virtual bool isElectron() const GCC11_FINAL { return false; }
00218 virtual bool isMuon() const GCC11_FINAL { return false; }
00219 virtual bool isStandAloneMuon() const GCC11_FINAL { return false; }
00220 virtual bool isGlobalMuon() const GCC11_FINAL { return false; }
00221 virtual bool isTrackerMuon() const GCC11_FINAL { return false; }
00222 virtual bool isCaloMuon() const GCC11_FINAL { return false; }
00223 virtual bool isPhoton() const GCC11_FINAL { return false; }
00224 virtual bool isConvertedPhoton() const GCC11_FINAL { return false; }
00225 virtual bool isJet() const GCC11_FINAL { return false; }
00226
00227 protected:
00230 T ref_;
00232 float mass_;
00234 mutable PolarLorentzVector p4Polar_;
00236 mutable LorentzVector p4Cartesian_;
00238 mutable edm::BoolCache cachePolarFixed_, cacheCartesianFixed_;
00240 inline void cachePolar() const {
00241 if ( cachePolarFixed_ ) return;
00242 p4Polar_ = PolarLorentzVector( ref_->pt(), ref_->eta(), ref_->phi(), mass_ );
00243 cachePolarFixed_ = true;
00244 }
00246 inline void cacheCartesian() const {
00247 if ( cacheCartesianFixed_ ) return;
00248 cachePolar();
00249 p4Cartesian_ = p4Polar_;
00250 cacheCartesianFixed_ = true;
00251 }
00253 inline void clearCache() const {
00254 cachePolarFixed_ = false;
00255 cacheCartesianFixed_ = false;
00256 }
00258 virtual bool overlap( const Candidate & ) const;
00259 virtual bool overlap( const LeafRefCandidateT & ) const;
00260 template<typename, typename, typename> friend struct component;
00261 friend class ::OverlapChecker;
00262 friend class ShallowCloneCandidate;
00263 friend class ShallowClonePtrCandidate;
00264
00265 private:
00266
00267 typedef candidate::const_iterator_imp_specific<daughters> const_iterator_imp_specific;
00268
00269 typedef candidate::iterator_imp_specific<daughters> iterator_imp_specific;
00270
00271
00275
00276 virtual void setCharge( Charge q ) GCC11_FINAL { return; }
00277 virtual int threeCharge() const GCC11_FINAL { return 0; }
00278 virtual void setThreeCharge( Charge qx3 ) GCC11_FINAL { return; }
00279 virtual void setP4( const LorentzVector & p4 ) GCC11_FINAL {
00280 return;
00281 }
00282 virtual void setP4( const PolarLorentzVector & p4 ) GCC11_FINAL {
00283 return;
00284 }
00285 virtual void setPz( double pz ) GCC11_FINAL {
00286 return;
00287 }
00288 virtual void setVertex( const Point & vertex ) GCC11_FINAL { return; }
00289 virtual void setPdgId( int pdgId ) GCC11_FINAL { return; }
00290 virtual int status() const GCC11_FINAL { return 0; }
00291 virtual void setStatus( int status ) GCC11_FINAL { return; }
00292 static const unsigned int longLivedTag;
00293 virtual void setLongLived() GCC11_FINAL { return; }
00294 virtual bool longLived() const GCC11_FINAL { return false; }
00295 static const unsigned int massConstraintTag;
00296 virtual void setMassConstraint() GCC11_FINAL { return;}
00297 virtual bool massConstraint() const GCC11_FINAL { return false; }
00298 virtual double vertexChi2() const GCC11_FINAL { return 0.; }
00299 virtual double vertexNdof() const GCC11_FINAL { return 0.; }
00300 virtual double vertexNormalizedChi2() const GCC11_FINAL { return 0.; }
00301 virtual double vertexCovariance(int i, int j) const GCC11_FINAL { return 0.; }
00302 CovarianceMatrix vertexCovariance() const GCC11_FINAL { CovarianceMatrix m; return m; }
00303 virtual void fillVertexCovariance(CovarianceMatrix & v) const GCC11_FINAL { return ; }
00304
00305 };
00306
00307
00308
00309 template<class T>
00310 Candidate::const_iterator LeafRefCandidateT<T>::begin() const {
00311 return const_iterator( new const_iterator_imp_specific );
00312 }
00313
00314 template<class T>
00315 Candidate::const_iterator LeafRefCandidateT<T>::end() const {
00316 return const_iterator( new const_iterator_imp_specific );
00317 }
00318
00319 template<class T>
00320 Candidate::iterator LeafRefCandidateT<T>::begin() {
00321 return iterator( new iterator_imp_specific );
00322 }
00323
00324 template<class T>
00325 Candidate::iterator LeafRefCandidateT<T>::end() {
00326 return iterator( new iterator_imp_specific );
00327 }
00328
00329
00330 template<class T>
00331 bool LeafRefCandidateT<T>::overlap( const Candidate & o ) const {
00332 return p4() == o.p4() && vertex() == o.vertex() && charge() == o.charge();
00333 }
00334
00335
00336 template<class T>
00337 bool LeafRefCandidateT<T>::overlap( const LeafRefCandidateT & o ) const {
00338 return ref_ == o.ref_;
00339 }
00340
00341
00342
00343 }
00344
00345 #endif