00001 #ifndef Candidate_LeafCandidate_h
00002 #define Candidate_LeafCandidate_h
00003
00011 #include "DataFormats/Candidate/interface/Candidate.h"
00012
00013 #include "DataFormats/Candidate/interface/iterator_imp_specific.h"
00014
00015 #include "DataFormats/Math/interface/PtEtaPhiMass.h"
00016
00017 namespace reco {
00018
00019 class LeafCandidate : public Candidate {
00020 public:
00022 typedef CandidateCollection daughters;
00024 typedef int Charge;
00026 typedef math::XYZTLorentzVector LorentzVector;
00028 typedef math::PtEtaPhiMLorentzVector PolarLorentzVector;
00030 typedef math::XYZPoint Point;
00032 typedef math::XYZVector Vector;
00033
00034 typedef unsigned int index;
00035
00037 LeafCandidate() :
00038 qx3_(0), pt_(0), eta_(0), phi_(0), mass_(0),
00039 vertex_(0, 0, 0), pdgId_(0), status_(0),
00040 cachePolarFixed_( false ), cacheCartesianFixed_( false ) { }
00041
00042 explicit LeafCandidate( const Candidate & c) :
00043 qx3_( c.charge()*3 ), pt_( c.p4().pt() ), eta_( c.p4().eta() ), phi_( c.p4().phi() )
00044 , mass_( c.p4().mass() ),
00045 vertex_( c.vertex() ), pdgId_( c.pdgId() ), status_( c.status() ),
00046 cachePolarFixed_( false ), cacheCartesianFixed_( false ) {}
00047
00049 template<typename P4>
00050 LeafCandidate( Charge q, const P4 & p4, const Point & vtx = Point( 0, 0, 0 ),
00051 int pdgId = 0, int status = 0, bool integerCharge = true ) :
00052 qx3_(integerCharge ? 3*q : q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
00053 vertex_( vtx ), pdgId_( pdgId ), status_( status ),
00054 cachePolarFixed_( false ), cacheCartesianFixed_( false ) {}
00055
00056
00058 LeafCandidate( Charge q, const PtEtaPhiMass & p4, const Point & vtx = Point( 0, 0, 0 ),
00059 int pdgId = 0, int status = 0, bool integerCharge = true ) :
00060 qx3_(integerCharge ? 3*q : 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
00065 LeafCandidate( Charge q, const LorentzVector & p4, const Point & vtx = Point( 0, 0, 0 ),
00066 int pdgId = 0, int status = 0, bool integerCharge = true ) :
00067 qx3_( q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
00068 vertex_( vtx ), pdgId_( pdgId ), status_( status ),
00069 cachePolarFixed_( false ), cacheCartesianFixed_( false ) {
00070 if ( integerCharge ) qx3_ *= 3;
00071 }
00073 LeafCandidate( Charge q, const PolarLorentzVector & p4, const Point & vtx = Point( 0, 0, 0 ),
00074 int pdgId = 0, int status = 0, bool integerCharge = true ) :
00075 qx3_( q ), pt_( p4.pt() ), eta_( p4.eta() ), phi_( p4.phi() ), mass_( p4.mass() ),
00076 vertex_( vtx ), pdgId_( pdgId ), status_( status ),
00077 cachePolarFixed_( false ), cacheCartesianFixed_( false ){
00078 if ( integerCharge ) qx3_ *= 3;
00079 }
00080
00082 virtual ~LeafCandidate();
00084 virtual const_iterator begin() const;
00086 virtual const_iterator end() const;
00088 virtual iterator begin();
00090 virtual iterator end();
00092 virtual size_t numberOfDaughters() const;
00094 virtual const Candidate * daughter( size_type ) const;
00096 virtual size_t numberOfMothers() const;
00098 virtual const Candidate * mother( size_type ) const;
00100 virtual Candidate * daughter( size_type );
00102 virtual Candidate * daughter(const std::string& s );
00104 virtual const Candidate * daughter(const std::string& s ) const;
00107 virtual size_t numberOfSourceCandidatePtrs() const { return 0;}
00110 virtual CandidatePtr sourceCandidatePtr( size_type i ) const {
00111 return CandidatePtr();
00112 }
00113
00115 virtual int charge() const GCC11_FINAL { return qx3_ / 3; }
00117 virtual void setCharge( Charge q ) GCC11_FINAL { qx3_ = q * 3; }
00119 virtual int threeCharge() const GCC11_FINAL { return qx3_; }
00121 virtual void setThreeCharge( Charge qx3 ) GCC11_FINAL { qx3_ = qx3; }
00123 virtual const LorentzVector & p4() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_; }
00125 virtual const PolarLorentzVector & polarP4() const GCC11_FINAL { cachePolar(); return p4Polar_; }
00127 virtual Vector momentum() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Vect(); }
00130 virtual Vector boostToCM() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.BoostToCM(); }
00132 virtual double p() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.P(); }
00134 virtual double energy() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.E(); }
00136 virtual double et() const GCC11_FINAL { cachePolar(); return p4Polar_.Et(); }
00138 virtual float mass() const GCC11_FINAL { return mass_; }
00140 virtual float massSqr() const GCC11_FINAL { return mass_ * mass_; }
00141
00143 virtual double mt() const GCC11_FINAL { cachePolar(); return p4Polar_.Mt(); }
00145 virtual double mtSqr() const GCC11_FINAL { cachePolar(); return p4Polar_.Mt2(); }
00147 virtual double px() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Px(); }
00149 virtual double py() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Py(); }
00151 virtual double pz() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Pz(); }
00153 virtual float pt() const GCC11_FINAL { return pt_;}
00155 virtual float phi() const GCC11_FINAL { return phi_; }
00157 virtual double theta() const GCC11_FINAL { cacheCartesian(); return p4Cartesian_.Theta(); }
00159 virtual float eta() const GCC11_FINAL { return eta_; }
00161 virtual double rapidity() const GCC11_FINAL { cachePolar(); return p4Polar_.Rapidity(); }
00163 virtual double y() const GCC11_FINAL { return rapidity(); }
00165 virtual void setP4( const LorentzVector & p4 ) GCC11_FINAL {
00166 p4Cartesian_ = p4;
00167 p4Polar_ = p4;
00168 pt_ = p4Polar_.pt();
00169 eta_ = p4Polar_.eta();
00170 phi_ = p4Polar_.phi();
00171 mass_ = p4Polar_.mass();
00172 cachePolarFixed_ = true;
00173 cacheCartesianFixed_ = true;
00174 }
00176 virtual void setP4( const PolarLorentzVector & p4 ) GCC11_FINAL {
00177 p4Polar_ = p4;
00178 pt_ = p4Polar_.pt();
00179 eta_ = p4Polar_.eta();
00180 phi_ = p4Polar_.phi();
00181 mass_ = p4Polar_.mass();
00182 cachePolarFixed_ = true;
00183 cacheCartesianFixed_ = false;
00184 }
00186 virtual void setMass( double m ) GCC11_FINAL {
00187 mass_ = m;
00188 clearCache();
00189 }
00190 virtual void setPz( double pz ) GCC11_FINAL {
00191 cacheCartesian();
00192 p4Cartesian_.SetPz(pz);
00193 p4Polar_ = p4Cartesian_;
00194 pt_ = p4Polar_.pt();
00195 eta_ = p4Polar_.eta();
00196 phi_ = p4Polar_.phi();
00197 mass_ = p4Polar_.mass();
00198 }
00200 virtual const Point & vertex() const { return vertex_; }
00202 virtual double vx() const { return vertex_.X(); }
00204 virtual double vy() const { return vertex_.Y(); }
00206 virtual double vz() const { return vertex_.Z(); }
00208 virtual void setVertex( const Point & vertex ) { vertex_ = vertex; }
00209
00211 virtual int pdgId() const GCC11_FINAL { return pdgId_; }
00212
00213 virtual void setPdgId( int pdgId ) GCC11_FINAL { pdgId_ = pdgId; }
00215 virtual int status() const GCC11_FINAL { return status_; }
00217 virtual void setStatus( int status ) GCC11_FINAL { status_ = status; }
00219 static const unsigned int longLivedTag;
00221 virtual void setLongLived() GCC11_FINAL { status_ |= longLivedTag; }
00223 virtual bool longLived() const GCC11_FINAL { return status_ & longLivedTag; }
00225 static const unsigned int massConstraintTag;
00227 virtual void setMassConstraint() GCC11_FINAL { status_ |= massConstraintTag;}
00229 virtual bool massConstraint() const GCC11_FINAL { return status_ & massConstraintTag; }
00230
00232 virtual LeafCandidate * clone() const {
00233 return new LeafCandidate( *this );
00234 }
00235
00237 virtual double vertexChi2() const;
00244 virtual double vertexNdof() const;
00246 virtual double vertexNormalizedChi2() const;
00248 virtual double vertexCovariance(int i, int j) const;
00250 CovarianceMatrix vertexCovariance() const GCC11_FINAL { CovarianceMatrix m; fillVertexCovariance(m); return m; }
00252 virtual void fillVertexCovariance(CovarianceMatrix & v) const;
00255 virtual bool hasMasterClone() const;
00258 virtual const CandidateBaseRef & masterClone() const;
00261 virtual bool hasMasterClonePtr() const;
00264 virtual const CandidatePtr & masterClonePtr() const;
00265
00267 template<typename Ref>
00268 Ref masterRef() const { return masterClone().template castTo<Ref>(); }
00270
00271 template<typename T> T get() const {
00272 if ( hasMasterClone() ) return masterClone()->get<T>();
00273 else return reco::get<T>( * this );
00274 }
00276 template<typename T, typename Tag> T get() const {
00277 if ( hasMasterClone() ) return masterClone()->get<T, Tag>();
00278 else return reco::get<T, Tag>( * this );
00279 }
00281 template<typename T> T get( size_type i ) const {
00282 if ( hasMasterClone() ) return masterClone()->get<T>( i );
00283 else return reco::get<T>( * this, i );
00284 }
00286 template<typename T, typename Tag> T get( size_type i ) const {
00287 if ( hasMasterClone() ) return masterClone()->get<T, Tag>( i );
00288 else return reco::get<T, Tag>( * this, i );
00289 }
00291 template<typename T> size_type numberOf() const {
00292 if ( hasMasterClone() ) return masterClone()->numberOf<T>();
00293 else return reco::numberOf<T>( * this );
00294 }
00296 template<typename T, typename Tag> size_type numberOf() const {
00297 if ( hasMasterClone() ) return masterClone()->numberOf<T, Tag>();
00298 else return reco::numberOf<T, Tag>( * this );
00299 }
00300
00301 template<typename S>
00302 struct daughter_iterator GCC11_FINAL {
00303 typedef boost::filter_iterator<S, const_iterator> type;
00304 };
00305
00306 template<typename S>
00307 typename daughter_iterator<S>::type beginFilter( const S & s ) const {
00308 return boost::make_filter_iterator(s, begin(), end());
00309 }
00310 template<typename S>
00311 typename daughter_iterator<S>::type endFilter( const S & s ) const {
00312 return boost::make_filter_iterator(s, end(), end());
00313 }
00314
00315
00316 virtual bool isElectron() const;
00317 virtual bool isMuon() const;
00318 virtual bool isStandAloneMuon() const;
00319 virtual bool isGlobalMuon() const;
00320 virtual bool isTrackerMuon() const;
00321 virtual bool isCaloMuon() const;
00322 virtual bool isPhoton() const;
00323 virtual bool isConvertedPhoton() const;
00324 virtual bool isJet() const;
00325
00326 protected:
00328 Charge qx3_;
00330 float pt_, eta_, phi_, mass_;
00332 Point vertex_;
00334 int pdgId_;
00336 int status_;
00338 mutable PolarLorentzVector p4Polar_;
00340 mutable LorentzVector p4Cartesian_;
00342 mutable bool cachePolarFixed_, cacheCartesianFixed_;
00344 inline void cachePolar() const {
00345 if ( cachePolarFixed_ ) return;
00346 p4Polar_ = PolarLorentzVector( pt_, eta_, phi_, mass_ );
00347 cachePolarFixed_ = true;
00348 }
00350 inline void cacheCartesian() const {
00351 if ( cacheCartesianFixed_ ) return;
00352 cachePolar();
00353 p4Cartesian_ = p4Polar_;
00354 cacheCartesianFixed_ = true;
00355 }
00357 inline void clearCache() const {
00358 cachePolarFixed_ = false;
00359 cacheCartesianFixed_ = false;
00360 }
00362 virtual bool overlap( const Candidate & ) const;
00363 template<typename, typename, typename> friend struct component;
00364 friend class ::OverlapChecker;
00365 friend class ShallowCloneCandidate;
00366 friend class ShallowClonePtrCandidate;
00367
00368 private:
00369
00370 typedef candidate::const_iterator_imp_specific<daughters> const_iterator_imp_specific;
00371
00372 typedef candidate::iterator_imp_specific<daughters> iterator_imp_specific;
00373 };
00374
00375 }
00376
00377 #endif