rivet is hosted by Hepforge, IPPP Durham
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   /// @brief Representation of a clustered jet of particles.
00012   class Jet : public ParticleBase {
00013   public:
00014 
00015     /// @name Constructors
00016     //@{
00017 
00018     Jet() : ParticleBase() { clear(); }
00019 
00020     /// Set all the jet data, with full particle information.
00021     Jet(const vector<Particle>& particles, const FourMomentum& pjet)
00022       : ParticleBase() {
00023       setState(particles, pjet);
00024     }
00025 
00026     // /// Set all the jet data, without particle ID information.
00027     // Jet(const vector<FourMomentum>& momenta, const FourMomentum& pjet)
00028     //   : ParticleBase() {
00029     //   setState(momenta, pjet);
00030     // }
00031 
00032     //@}
00033 
00034 
00035     /// @name Access jet constituents
00036     //@{
00037 
00038     /// Number of particles in this jet.
00039     size_t size() const { return _particles.size(); }
00040 
00041     // /// Define a Jet::iterator via a typedef.
00042     // typedef vector<FourMomentum>::iterator iterator;
00043 
00044     // /// Define a Jet::const_iterator via a typedef.
00045     // typedef vector<FourMomentum>::const_iterator const_iterator;
00046 
00047     // /// Get a begin iterator over the particle/track four-momenta in this jet.
00048     // iterator begin() {
00049     //   return _momenta.begin();
00050     // }
00051 
00052     // /// Get an end iterator over the particle/track four-momenta in this jet.
00053     // iterator end() {
00054     //   return _momenta.end();
00055     // }
00056 
00057     // /// Get a const begin iterator over the particle/track four-momenta in this jet.
00058     // const_iterator begin() const {
00059     //   return _momenta.begin();
00060     // }
00061 
00062     // /// Get a const end iterator over the particle/track four-momenta in this jet.
00063     // const_iterator end() const {
00064     //   return _momenta.end();
00065     // }
00066 
00067     // /// Get the track momenta in this jet.
00068     // vector<FourMomentum>& momenta() {
00069     //   return _momenta;
00070     // }
00071 
00072     // /// Get the track momenta in this jet (const version).
00073     // const vector<FourMomentum>& momenta() const {
00074     //   return _momenta;
00075     // }
00076 
00077     /// Get the particles in this jet.
00078     vector<Particle>& particles() { return _particles; }
00079 
00080     /// Get the particles in this jet (const version)
00081     const vector<Particle>& particles() const { return _particles; }
00082 
00083     /// Check whether this jet contains a particular particle.
00084     bool containsParticle(const Particle& particle) const;
00085 
00086     /// Check whether this jet contains a certain particle type.
00087     bool containsParticleId(PdgId pid) const;
00088 
00089     /// Check whether this jet contains at least one of certain particle types.
00090     bool containsParticleId(const vector<PdgId>& pids) const;
00091 
00092     /// Check whether this jet contains a charm-flavoured hadron (or decay products from one).
00093     bool containsCharm() const;
00094 
00095     /// Check whether this jet contains a bottom-flavoured hadron (or decay products from one).
00096     bool containsBottom() const;
00097 
00098     //@}
00099 
00100 
00101     /// @name Access the effective jet 4-vector properties
00102     //@{
00103 
00104     /// Get equivalent single momentum four-vector.
00105     const FourMomentum& momentum() const { return _momentum; }
00106 
00107     /// Get the unweighted average \f$ \eta \f$ for this jet. (caches)
00108     double eta() const { return momentum().eta(); }
00109 
00110     /// Get the unweighted average \f$ \phi \f$ for this jet. (caches)
00111     double phi() const { return momentum().phi(); }
00112 
00113     /// Get the total energy of this jet.
00114     double totalEnergy() const { return momentum().E(); }
00115 
00116     /// Get the energy carried in this jet by neutral particles.
00117     double neutralEnergy() const;
00118 
00119     /// Get the energy carried in this jet by hadrons.
00120     double hadronicEnergy() const;
00121 
00122     /// Get the sum of the \f$ p_T \f$ values of the constituent tracks. (caches)
00123     double ptSum() const { return momentum().pT(); }
00124 
00125     /// Get the sum of the \f$ E_T \f$ values of the constituent tracks. (caches)
00126     double EtSum() const { return momentum().Et(); }
00127 
00128     //@}
00129 
00130 
00131     /// @name Set the jet constituents and properties
00132     //@{
00133 
00134     /// Set all the jet data, with full particle information.
00135     Jet& setState(const vector<Particle>& particles, const FourMomentum& pjet);
00136 
00137     // /// Set all the jet data, without particle ID information.
00138     // Jet& setState(const vector<FourMomentum>& momenta, const FourMomentum& pjet);
00139 
00140     /// Set the effective 4-momentum of the jet.
00141     Jet& setMomentum(const FourMomentum& momentum);
00142 
00143     /// Set the particles collection with full particle information.
00144     Jet& setParticles(const vector<Particle>& particles);
00145 
00146     // /// Set the particles collection with momentum information only.
00147     // Jet& setParticles(const vector<FourMomentum>& momenta);
00148 
00149     // /// Add a particle/track to this jet.
00150     // Jet& addParticle(const FourMomentum& particle);
00151 
00152     // /// Add a particle/track to this jet.
00153     // Jet& addParticle(const Particle& particle);
00154 
00155     /// Reset this jet as empty.
00156     Jet& clear();
00157 
00158     //@}
00159 
00160 
00161   private:
00162 
00163     /// Full particle information including tracks, ID etc
00164     ParticleVector _particles;
00165 
00166     // /// The particle momenta.
00167     // /// @todo Eliminate this to ensure consistency.
00168     // std::vector<FourMomentum> _momenta;
00169 
00170     /// Effective jet 4-vector
00171     FourMomentum _momentum;
00172 
00173   };
00174 
00175 
00176   /// Typedef for a collection of Jet objects.
00177   typedef std::vector<Jet> Jets;
00178 
00179 
00180   /// @name Jet comparison functions for STL sorting
00181   //@{
00182 
00183   /// @brief Compare jets by \f$ p_\perp \f$ (descending - usual sorting for HEP)
00184   /// Use this so that highest \f$ p_\perp \f$ is at the front of the list
00185   inline bool cmpJetsByPt(const Jet& a, const Jet& b) {
00186     return a.ptSum() > b.ptSum();
00187   }
00188   /// @brief Compare jets by \f$ p_\perp \f$ (ascending)
00189   /// Use this so that lowest \f$ p_\perp \f$ is at the front of the list
00190   inline bool cmpJetsByAscPt(const Jet& a, const Jet& b) {
00191     return a.ptSum() < b.ptSum();
00192   }
00193 
00194   /// @brief Compare jets by descending momentum, \f$ p \f$
00195   inline bool cmpJetsByP(const Jet& a, const Jet& b) {
00196     return a.momentum().vector3().mod() > b.momentum().vector3().mod();
00197   }
00198   /// @brief Compare jets by ascending momentum, \f$ p \f$
00199   inline bool cmpJetsByAscP(const Jet& a, const Jet& b) {
00200     return a.momentum().vector3().mod() < b.momentum().vector3().mod();
00201   }
00202 
00203   // @brief Compare jets by \f$ E_\perp \f$ (descending - usual sorting for HEP)
00204   /// Use this so that highest \f$ E_\perp \f$ is at the front of the list
00205   inline bool cmpJetsByEt(const Jet& a, const Jet& b) {
00206     return a.EtSum() > b.EtSum();
00207   }
00208   // @brief Compare jets by \f$ E_\perp \f$ (ascending)
00209   /// Use this so that lowest \f$ E_\perp \f$ is at the front of the list
00210   inline bool cmpJetsByEtDesc(const Jet& a, const Jet& b) {
00211     return a.EtSum() < b.EtSum();
00212   }
00213 
00214   /// @brief Compare jets by \f$ E \f$ (descending - usual sorting for HEP)
00215   /// Use this so that highest \f$ E \f$ is at the front of the list
00216   inline bool cmpJetsByE(const Jet& a, const Jet& b) {
00217     return a.momentum().E() > b.momentum().E();
00218   }
00219   /// @brief Compare jets by \f$ E \f$ (ascending)
00220   /// Use this so that lowest \f$ E \f$ is at the front of the list
00221   inline bool cmpJetsByAscE(const Jet& a, const Jet& b) {
00222     return a.momentum().E() < b.momentum().E();
00223   }
00224 
00225   /// @brief Compare jets by \f$ \eta \f$ (descending)
00226   /// Use this so that highest \f$ \eta \f$ is at the front of the list
00227   inline bool cmpJetsByDescPseudorapidity(const Jet& a, const Jet& b) {
00228     return a.momentum().pseudorapidity() > b.momentum().pseudorapidity();
00229   }
00230   /// @brief Compare jets by \f$ \eta \f$ (ascending)
00231   /// Use this so that lowest \f$ \eta \f$ is at the front of the list
00232   inline bool cmpJetsByAscPseudorapidity(const Jet& a, const Jet& b) {
00233     return a.momentum().pseudorapidity() < b.momentum().pseudorapidity();
00234   }
00235 
00236   /// @brief Compare jets by \f$ |\eta| \f$ (descending)
00237   /// Use this so that highest \f$ |\eta| \f$ is at the front of the list
00238   inline bool cmpJetsByDescAbsPseudorapidity(const Jet& a, const Jet& b) {
00239     return fabs(a.momentum().pseudorapidity()) > fabs(b.momentum().pseudorapidity());
00240   }
00241   /// @brief Compare jets by \f$ |\eta| \f$ (ascending)
00242   /// Use this so that lowest \f$ |\eta| \f$ is at the front of the list
00243   inline bool cmpJetsByAscAbsPseudorapidity(const Jet& a, const Jet& b) {
00244     return fabs(a.momentum().pseudorapidity()) < fabs(b.momentum().pseudorapidity());
00245   }
00246 
00247   /// @brief Compare jets by \f$ y \f$ (descending)
00248   /// Use this so that highest \f$ y \f$ is at the front of the list
00249   inline bool cmpJetsByDescRapidity(const Jet& a, const Jet& b) {
00250     return a.momentum().rapidity() > b.momentum().rapidity();
00251   }
00252   /// @brief Compare jets by \f$ y \f$ (ascending)
00253   /// Use this so that lowest \f$ y \f$ is at the front of the list
00254   inline bool cmpJetsByAscRapidity(const Jet& a, const Jet& b) {
00255     return a.momentum().rapidity() < b.momentum().rapidity();
00256   }
00257 
00258   /// @brief Compare jets by \f$ |y| \f$ (descending)
00259   /// Use this so that highest \f$ |y| \f$ is at the front of the list
00260   inline bool cmpJetsByDescAbsRapidity(const Jet& a, const Jet& b) {
00261     return fabs(a.momentum().rapidity()) > fabs(b.momentum().rapidity());
00262   }
00263   /// @brief Compare jets by \f$ |y| \f$ (ascending)
00264   /// Use this so that lowest \f$ |y| \f$ is at the front of the list
00265   inline bool cmpJetsByAscAbsRapidity(const Jet& a, const Jet& b) {
00266     return fabs(a.momentum().rapidity()) < fabs(b.momentum().rapidity());
00267   }
00268 
00269   //@}
00270 
00271   inline double deltaR(const Jet& j1, const Jet& j2,
00272                        RapScheme scheme = PSEUDORAPIDITY) {
00273     return deltaR(j1.momentum(), j2.momentum(), scheme);
00274   }
00275 
00276   inline double deltaR(const Jet& j, const Particle& p,
00277                        RapScheme scheme = PSEUDORAPIDITY) {
00278     return deltaR(j.momentum(), p.momentum(), scheme);
00279   }
00280 
00281   inline double deltaR(const Particle& p, const Jet& j,
00282                        RapScheme scheme = PSEUDORAPIDITY) {
00283     return deltaR(p.momentum(), j.momentum(), scheme);
00284   }
00285 
00286   inline double deltaR(const Jet& j, const FourMomentum& v,
00287                        RapScheme scheme = PSEUDORAPIDITY) {
00288     return deltaR(j.momentum(), v, scheme);
00289   }
00290 
00291   inline double deltaR(const Jet& j, const FourVector& v,
00292                        RapScheme scheme = PSEUDORAPIDITY) {
00293     return deltaR(j.momentum(), v, scheme);
00294   }
00295 
00296   inline double deltaR(const Jet& j, const Vector3& v) {
00297     return deltaR(j.momentum(), v);
00298   }
00299 
00300   inline double deltaR(const Jet& j, double eta, double phi) {
00301     return deltaR(j.momentum(), eta, phi);
00302   }
00303 
00304   inline double deltaR(const FourMomentum& v, const Jet& j,
00305                        RapScheme scheme = PSEUDORAPIDITY) {
00306     return deltaR(v, j.momentum(), scheme);
00307   }
00308 
00309   inline double deltaR(const FourVector& v, const Jet& j,
00310                        RapScheme scheme = PSEUDORAPIDITY) {
00311     return deltaR(v, j.momentum(), scheme);
00312   }
00313 
00314   inline double deltaR(const Vector3& v, const Jet& j) {
00315     return deltaR(v, j.momentum());
00316   }
00317 
00318   inline double deltaR(double eta, double phi, const Jet& j) {
00319     return deltaR(eta, phi, j.momentum());
00320   }
00321 
00322 
00323   inline double deltaPhi(const Jet& j1, const Jet& j2) {
00324     return deltaPhi(j1.momentum(), j2.momentum());
00325   }
00326 
00327   inline double deltaPhi(const Jet& j, const Particle& p) {
00328     return deltaPhi(j.momentum(), p.momentum());
00329   }
00330 
00331   inline double deltaPhi(const Particle& p, const Jet& j) {
00332     return deltaPhi(p.momentum(), j.momentum());
00333   }
00334 
00335   inline double deltaPhi(const Jet& j, const FourMomentum& v) {
00336     return deltaPhi(j.momentum(), v);
00337   }
00338 
00339   inline double deltaPhi(const Jet& j, const FourVector& v) {
00340     return deltaPhi(j.momentum(), v);
00341   }
00342 
00343   inline double deltaPhi(const Jet& j, const Vector3& v) {
00344     return deltaPhi(j.momentum(), v);
00345   }
00346 
00347   inline double deltaPhi(const Jet& j, double phi) {
00348     return deltaPhi(j.momentum(), phi);
00349   }
00350 
00351   inline double deltaPhi(const FourMomentum& v, const Jet& j) {
00352     return deltaPhi(v, j.momentum());
00353   }
00354 
00355   inline double deltaPhi(const FourVector& v, const Jet& j) {
00356     return deltaPhi(v, j.momentum());
00357   }
00358 
00359   inline double deltaPhi(const Vector3& v, const Jet& j) {
00360     return deltaPhi(v, j.momentum());
00361   }
00362 
00363   inline double deltaPhi(double phi, const Jet& j) {
00364     return deltaPhi(phi, j.momentum());
00365   }
00366 
00367 
00368   inline double deltaEta(const Jet& j1, const Jet& j2) {
00369     return deltaEta(j1.momentum(), j2.momentum());
00370   }
00371 
00372   inline double deltaEta(const Jet& j, const Particle& p) {
00373     return deltaEta(j.momentum(), p.momentum());
00374   }
00375 
00376   inline double deltaEta(const Particle& p, const Jet& j) {
00377     return deltaEta(p.momentum(), j.momentum());
00378   }
00379 
00380   inline double deltaEta(const Jet& j, const FourMomentum& v) {
00381     return deltaEta(j.momentum(), v);
00382   }
00383 
00384   inline double deltaEta(const Jet& j, const FourVector& v) {
00385     return deltaEta(j.momentum(), v);
00386   }
00387 
00388   inline double deltaEta(const Jet& j, const Vector3& v) {
00389     return deltaEta(j.momentum(), v);
00390   }
00391 
00392   inline double deltaEta(const Jet& j, double eta) {
00393     return deltaEta(j.momentum(), eta);
00394   }
00395 
00396   inline double deltaEta(const FourMomentum& v, const Jet& j) {
00397     return deltaEta(v, j.momentum());
00398   }
00399 
00400   inline double deltaEta(const FourVector& v, const Jet& j) {
00401     return deltaEta(v, j.momentum());
00402   }
00403 
00404   inline double deltaEta(const Vector3& v, const Jet& j) {
00405     return deltaEta(v, j.momentum());
00406   }
00407 
00408   inline double deltaEta(double eta, const Jet& j) {
00409     return deltaEta(eta, j.momentum());
00410   }
00411 
00412 }
00413 
00414 #endif