Jet.hh

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_Jet_HH
00003 #define RIVET_Jet_HH
00004 
00005 #include "Rivet/Rivet.hh"
00006 #include <numeric>
00007 
00008 namespace Rivet {
00009 
00010 
00011   /// A minimal class representing a jet of particles.
00012   class Jet : public ParticleBase {
00013   public:
00014 
00015     /// Constructor.
00016     Jet();
00017 
00018     /// Define a Jet::iterator via a typedef.
00019     typedef vector<FourMomentum>::iterator iterator;
00020 
00021     /// Define a Jet::const_iterator via a typedef.
00022     typedef vector<FourMomentum>::const_iterator const_iterator;
00023 
00024     /// Get a begin iterator over the particle/track four-momenta in this jet.
00025     iterator begin() {
00026       return _particles.begin();
00027     }
00028 
00029     /// Get an end iterator over the particle/track four-momenta in this jet.
00030     iterator end() {
00031       return _particles.end();
00032     }
00033 
00034     /// Get a const begin iterator over the particle/track four-momenta in this jet.
00035     const_iterator begin() const {
00036       return _particles.begin();
00037     }
00038 
00039     /// Get a const end iterator over the particle/track four-momenta in this jet.
00040     const_iterator end() const {
00041       return _particles.end();
00042     }
00043 
00044     /// Get the track momenta in this jet.
00045     vector<FourMomentum>& momenta() {
00046       return _particles;
00047     }
00048 
00049     /// Get the track momenta in this jet (const version).
00050     const vector<FourMomentum>& momenta() const {
00051       return _particles;
00052     }
00053 
00054     /// Get the Rivet::Particles (full information) in this jet
00055     vector<Particle>& particles() {
00056       return _fullParticles;
00057     }
00058  
00059     /// Get the Rivet::Particles (full information) in this jet (const version)
00060     const vector<Particle>& particles() const {
00061       return _fullParticles;
00062     }
00063  
00064     /// Number of particles (tracks) in this jet.
00065     size_t size() const {
00066       return _particles.size();
00067     }
00068 
00069     /// Set the particles/tracks collection.
00070     Jet& setParticles(const vector<FourMomentum>& particles);
00071 
00072     /// Add a particle/track to this jet.
00073     Jet& addParticle(const FourMomentum& particle);
00074 
00075     /// Add a particle/track to this jet.
00076     Jet& addParticle(const Particle& particle);
00077  
00078     /// Check whether this jet contains a particular particle.
00079     bool containsParticle(const Particle& particle) const;
00080 
00081     /// Check whether this jet contains a certain particle type.
00082     bool containsParticleId(PdgId pid) const;
00083 
00084     /// Check whether this jet contains at least one of certain particle types.
00085     bool containsParticleId(const vector<PdgId>& pids) const;
00086 
00087     /// Check whether this jet contains a charm-flavoured hadron.
00088     bool containsCharm() const;
00089 
00090     /// Check whether this jet contains a bottom-flavoured hadron.
00091     bool containsBottom() const;
00092 
00093     /// Reset this jet as empty.
00094     Jet& clear();
00095 
00096     /// Get the average \f$ \eta \f$ for this jet, with the average weighted
00097     /// by the \f$ p_T \f$ values of the constituent tracks. (caches)
00098     double ptWeightedEta() const;
00099 
00100     /// Get the average \f$ \phi \f$ for this jet, with the average weighted
00101     /// by the \f$ p_T \f$ values of the constituent tracks. (caches)
00102     double ptWeightedPhi() const;
00103 
00104     /// Get the unweighted average \f$ \eta \f$ for this jet. (caches)
00105     double eta() const;
00106 
00107     /// Get the unweighted average \f$ \phi \f$ for this jet. (caches)
00108     double phi() const;
00109 
00110     /// Get equivalent single momentum four-vector. (caches)
00111     const FourMomentum& momentum() const;
00112  
00113     // /// Get equivalent single momentum four-vector. (caches)
00114     // FourMomentum& momentum();
00115 
00116 
00117 
00118   public:
00119 
00120     /// Get the total energy of this jet.
00121     double totalEnergy() const;
00122 
00123     /// Get the energy carried in this jet by neutral particles.
00124     double neutralEnergy() const;
00125  
00126     /// Get the energy carried in this jet by hadrons.
00127     double hadronicEnergy() const;
00128 
00129     /// Get the sum of the \f$ p_T \f$ values of the constituent tracks. (caches)
00130     double ptSum() const;
00131 
00132     /// Get the sum of the \f$ E_T \f$ values of the constituent tracks. (caches)
00133     double EtSum() const;
00134 
00135 
00136   private:
00137 
00138     /// @brief Clear the internal cached values.
00139     /// Const because cache variables are mutable.
00140     void _resetCaches() const;
00141 
00142     /// @brief Calculate cached equivalent momentum vector.
00143     /// Const because cache variables are mutable.
00144     void _calcMomVector() const;
00145 
00146     /// Internal caching method to calculate the average \f$ \eta \f$ and \f$
00147     /// \phi \f$ for this jet, weighted by the \f$ p_T \f$ values of the
00148     /// constituent tracks.
00149     /// Const because cache variables are mutable.
00150     void _calcPtAvgs() const;
00151 
00152 
00153   private:
00154 
00155     /// The particle tracks.
00156     std::vector<FourMomentum> _particles;
00157 
00158     /// Full particle information including tracks, ID etc
00159     ParticleVector _fullParticles;
00160 
00161     /// Cached values of the \f$ p_T \f$-weighted \f$ \bar{\phi} \f$ and \f$ \bar{\eta} \f$.
00162     mutable double _ptWeightedPhi, _ptWeightedEta;
00163     mutable bool _okPtWeightedPhi, _okPtWeightedEta;
00164 
00165     /// Cached effective jet 4-vector
00166     mutable FourMomentum _momentum;
00167     mutable bool _okMomentum;
00168  
00169   };
00170 
00171 
00172   /// Typedef for a collection of Jet objects.
00173   typedef std::vector<Jet> Jets;
00174 
00175 
00176   /// @name Jet comparison functions for STL sorting
00177   //@{
00178 
00179   // @brief Compare jets by \f$ p_\perp \f$ (descending - usual sorting for HEP)
00180   /// Use this so that highest \f$ p_\perp \f$ is at the front of the list
00181   inline bool cmpJetsByPt(const Jet& a, const Jet& b) {
00182     return a.ptSum() > b.ptSum();
00183   }
00184   // @brief Compare jets by \f$ p_\perp \f$ (ascending)
00185   /// Use this so that lowest \f$ p_\perp \f$ is at the front of the list
00186   inline bool cmpJetsByAscPt(const Jet& a, const Jet& b) {
00187     return a.ptSum() < b.ptSum();
00188   }
00189 
00190   // @brief Compare jets by \f$ E_\perp \f$ (descending - usual sorting for HEP)
00191   /// Use this so that highest \f$ E_\perp \f$ is at the front of the list
00192   inline bool cmpJetsByEt(const Jet& a, const Jet& b) {
00193     return a.EtSum() > b.EtSum();
00194   }
00195   // @brief Compare jets by \f$ E_\perp \f$ (ascending)
00196   /// Use this so that lowest \f$ E_\perp \f$ is at the front of the list
00197   inline bool cmpJetsByEtDesc(const Jet& a, const Jet& b) {
00198     return a.EtSum() < b.EtSum();
00199   }
00200 
00201   // @brief Compare jets by \f$ E \f$ (descending - usual sorting for HEP)
00202   /// Use this so that highest \f$ E \f$ is at the front of the list
00203   inline bool cmpJetsByE(const Jet& a, const Jet& b) {
00204     return a.momentum().E() > b.momentum().E();
00205   }
00206   // @brief Compare jets by \f$ E \f$ (ascending)
00207   /// Use this so that lowest \f$ E \f$ is at the front of the list
00208   inline bool cmpJetsByAscE(const Jet& a, const Jet& b) {
00209     return a.momentum().E() < b.momentum().E();
00210   }
00211 
00212   // @brief Compare jets by \f$ \eta \f$ (descending)
00213   /// Use this so that highest \f$ \eta \f$ is at the front of the list
00214   inline bool cmpJetsByDescPseudorapidity(const Jet& a, const Jet& b) {
00215     return a.momentum().pseudorapidity() > b.momentum().pseudorapidity();
00216   }
00217   // @brief Compare jets by \f$ \eta \f$ (ascending)
00218   /// Use this so that lowest \f$ \eta \f$ is at the front of the list
00219   inline bool cmpJetsByAscPseudorapidity(const Jet& a, const Jet& b) {
00220     return a.momentum().pseudorapidity() < b.momentum().pseudorapidity();
00221   }
00222 
00223   // @brief Compare jets by \f$ |\eta| \f$ (descending)
00224   /// Use this so that highest \f$ |\eta| \f$ is at the front of the list
00225   inline bool cmpJetsByDescAbsPseudorapidity(const Jet& a, const Jet& b) {
00226     return fabs(a.momentum().pseudorapidity()) > fabs(b.momentum().pseudorapidity());
00227   }
00228   // @brief Compare jets by \f$ |\eta| \f$ (ascending)
00229   /// Use this so that lowest \f$ |\eta| \f$ is at the front of the list
00230   inline bool cmpJetsByAscAbsPseudorapidity(const Jet& a, const Jet& b) {
00231     return fabs(a.momentum().pseudorapidity()) < fabs(b.momentum().pseudorapidity());
00232   }
00233 
00234   // @brief Compare jets by \f$ y \f$ (descending)
00235   /// Use this so that highest \f$ y \f$ is at the front of the list
00236   inline bool cmpJetsByDescRapidity(const Jet& a, const Jet& b) {
00237     return a.momentum().rapidity() > b.momentum().rapidity();
00238   }
00239   // @brief Compare jets by \f$ y \f$ (ascending)
00240   /// Use this so that lowest \f$ y \f$ is at the front of the list
00241   inline bool cmpJetsByAscRapidity(const Jet& a, const Jet& b) {
00242     return a.momentum().rapidity() < b.momentum().rapidity();
00243   }
00244 
00245   // @brief Compare jets by \f$ |y| \f$ (descending)
00246   /// Use this so that highest \f$ |y| \f$ is at the front of the list
00247   inline bool cmpJetsByDescAbsRapidity(const Jet& a, const Jet& b) {
00248     return fabs(a.momentum().rapidity()) > fabs(b.momentum().rapidity());
00249   }
00250   // @brief Compare jets by \f$ |y| \f$ (ascending)
00251   /// Use this so that lowest \f$ |y| \f$ is at the front of the list
00252   inline bool cmpJetsByAscAbsRapidity(const Jet& a, const Jet& b) {
00253     return fabs(a.momentum().rapidity()) < fabs(b.momentum().rapidity());
00254   }
00255 
00256   //@}
00257 
00258 
00259 }
00260 
00261 #endif