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/Config/RivetCommon.hh"
00006 #include "Rivet/Jet.fhh"
00007 #include "Rivet/Particle.hh"
00008 #include "Rivet/Tools/Cuts.hh"
00009 #include "Rivet/Tools/Utils.hh"
00010 #include "Rivet/Tools/RivetFastJet.hh"
00011 #include "Rivet/Math/LorentzTrans.hh"
00012 #include <numeric>
00013 
00014 namespace Rivet {
00015 
00016 
00017   /// @brief Representation of a clustered jet of particles.
00018   class Jet : public ParticleBase {
00019   public:
00020 
00021     /// @name Constructors
00022     //@{
00023 
00024     /// Constructor from a FastJet PseudoJet, with optional full particle constituents information.
00025     Jet(const fastjet::PseudoJet& pj, const Particles& particles=Particles(), const Particles& tags=Particles()) {
00026       setState(pj, particles, tags);
00027     }
00028 
00029     /// Set the jet data, with optional full particle information.
00030     Jet(const FourMomentum& pjet, const Particles& particles=Particles(), const Particles& tags=Particles()) {
00031       setState(pjet, particles, tags);
00032     }
00033 
00034     /// Set all the jet data, with full particle information.
00035     /// @deprecated Prefer the form where the 4-vec comes first and the particles list is optional.
00036     DEPRECATED("Prefer the form where the 4-vec comes first and the particles list is optional.")
00037     Jet(const Particles& particles, const FourMomentum& pjet) {
00038       setState(pjet, particles);
00039     }
00040 
00041     /// Default constructor -- only for STL storability
00042     Jet() { clear(); }
00043 
00044     //@}
00045 
00046 
00047     /// @name Access jet constituents
00048     //@{
00049 
00050     /// Number of particles in this jet.
00051     size_t size() const { return _particles.size(); }
00052 
00053     /// Get the particles in this jet.
00054     Particles& particles() { return _particles; }
00055     /// Get the particles in this jet (const version)
00056     const Particles& particles() const { return _particles; }
00057     /// Get the particles in this jet which pass a cut (const)
00058     const Particles particles(const Cut& c) const { return filterBy(_particles, c); }
00059 
00060     /// Get the particles in this jet (FastJet-like alias)
00061     Particles& constituents() { return particles(); }
00062     /// Get the particles in this jet (FastJet-like alias, const version)
00063     const Particles& constituents() const { return particles(); }
00064     /// Get the particles in this jet which pass a cut (FastJet-like alias, const)
00065     const Particles constituents(const Cut& c) const { return particles(c); }
00066 
00067     /// Check whether this jet contains a particular particle.
00068     bool containsParticle(const Particle& particle) const;
00069     /// Nicer alias for containsParticleId
00070     bool containsPID(const Particle& particle) const { return containsParticle(particle); }
00071 
00072     /// Check whether this jet contains a certain particle type.
00073     bool containsParticleId(PdgId pid) const;
00074     /// Nicer alias for containsParticleId
00075     bool containsPID(PdgId pid) const { return containsParticleId(pid); }
00076 
00077     /// Check whether this jet contains at least one of certain particle types.
00078     bool containsParticleId(const vector<PdgId>& pids) const;
00079     /// Nicer alias for containsParticleId
00080     bool containsPID(const vector<PdgId>& pids) const { return containsParticleId(pids); }
00081 
00082     //@}
00083 
00084 
00085     /// @name Tagging
00086     ///
00087     /// @note General sources of tag particles are planned. The default jet finding
00088     /// adds b-hadron, c-hadron, and tau tags by ghost association.
00089     //@{
00090 
00091     /// @brief Particles which have been tag-matched to this jet
00092     Particles& tags() { return _tags; }
00093     /// @brief Particles which have been tag-matched to this jet (const version)
00094     const Particles& tags() const { return _tags; }
00095     /// @brief Particles which have been tag-matched to this jet _and_ pass a selector function
00096     ///
00097     /// @note Note the less efficient return by value, due to the filtering.
00098     template <typename FN>
00099     Particles tags(const FN& f) const { return filter_select(tags(), f); }
00100     /// @brief Particles which have been tag-matched to this jet _and_ pass a Cut
00101     ///
00102     /// @note Note the less efficient return by value, due to the cut-pass filtering.
00103     Particles tags(const Cut& c) const;
00104 
00105 
00106     /// @brief b particles which have been tag-matched to this jet (and pass an optional Cut)
00107     ///
00108     /// The default jet finding adds b-hadron tags by ghost association.
00109     Particles bTags(const Cut& c=Cuts::open()) const;
00110     /// @brief b particles which have been tag-matched to this jet _and_ pass a selector function
00111     template <typename FN>
00112     Particles bTags(const FN& f) const { return filter_select(bTags(), f); }
00113 
00114     /// Does this jet have at least one b-tag (that passes an optional Cut)?
00115     bool bTagged(const Cut& c=Cuts::open()) const { return !bTags(c).empty(); }
00116     /// Does this jet have at least one b-tag (that passes the supplied selector function)?
00117     template <typename FN>
00118     Particles bTagged(const FN& f) const { return !bTags(f).empty(); }
00119 
00120 
00121     /// @brief c (and not b) particles which have been tag-matched to this jet (and pass an optional Cut)
00122     ///
00123     /// The default jet finding adds c-hadron tags by ghost association.
00124     Particles cTags(const Cut& c=Cuts::open()) const;
00125     /// @brief c (and not b) particles which have been tag-matched to this jet and pass a selector function
00126     template <typename FN>
00127     Particles cTags(const FN& f) const { return filter_select(cTags(), f); }
00128 
00129     /// Does this jet have at least one c-tag (that passes an optional Cut)?
00130     bool cTagged(const Cut& c=Cuts::open()) const { return !cTags(c).empty(); }
00131     /// Does this jet have at least one c-tag (that passes the supplied selector function)?
00132     template <typename FN>
00133     bool cTagged(const FN& f) const { return !cTags(f).empty(); }
00134 
00135 
00136     /// @brief Tau particles which have been tag-matched to this jet (and pass an optional Cut)
00137     ///
00138     /// The default jet finding adds tau tags by ghost association.
00139     Particles tauTags(const Cut& c=Cuts::open()) const;
00140     /// @brief Tau particles which have been tag-matched to this jet and pass a selector function
00141     template <typename FN>
00142     Particles tauTags(const FN& f) const { return filter_select(tauTags(), f); }
00143 
00144     /// Does this jet have at least one tau-tag (that passes an optional Cut)?
00145     bool tauTagged(const Cut& c=Cuts::open()) const { return !tauTags(c).empty(); }
00146     /// Does this jet have at least one tau-tag (that passes the supplied selector function)?
00147     template <typename FN>
00148     bool tauTagged(const FN& f) const { return !tauTags(f).empty(); }
00149 
00150 
00151     /// @brief Check whether this jet contains a bottom-flavoured hadron.
00152     ///
00153     /// @deprecated The bTags() or bTagged() function is probably what you want
00154     /// for tagging. This one ignores the tags() list and draws conclusions
00155     /// based directly on the jet constituents; the other gives a much better match
00156     /// to typical experimental methods.
00157     ///
00158     /// @note The decision is made by first trying to find a bottom-flavoured particle
00159     /// in the particles list. Most likely this will fail unless bottom hadrons
00160     /// are set stable. If @a include_decay_products is true (the default), a
00161     /// fallback is attempted, using the post-hadronization ancestor history of
00162     /// all constituents.
00163     //DEPRECATED("Prefer the bTags() or bTagged() function")
00164     bool containsBottom(bool include_decay_products=true) const;
00165 
00166     /// @brief Check whether this jet contains a charm-flavoured hadron.
00167     ///
00168     /// @deprecated The cTags() or cTagged() function is probably what you want
00169     /// for tagging. This one ignores the tags() list and draws conclusions
00170     /// based directly on the jet constituents; the other gives a much better match
00171     /// to typical experimental methods.
00172     ///
00173     /// @note The decision is made by first trying to find a charm-flavoured particle
00174     /// in the particles list. Most likely this will fail unless charmed hadrons
00175     /// are set stable. If @a include_decay_products is true (the default), a
00176     /// fallback is attempted, using the post-hadronization ancestor history of
00177     /// all constituents.
00178     //DEPRECATED("Prefer the cTags() or cTagged() function")
00179     bool containsCharm(bool include_decay_products=true) const;
00180 
00181     //@}
00182 
00183 
00184     /// @name Effective jet 4-vector properties
00185     //@{
00186 
00187     /// Get equivalent single momentum four-vector.
00188     const FourMomentum& momentum() const { return _momentum; }
00189 
00190     /// Apply an active Lorentz transform to this jet
00191     /// @note The Rivet jet momentum, constituent particles, and tag particles will be modified.
00192     /// @warning The FastJet cluster sequence and pseudojets will not be modified: don't use them after transformation!
00193     Jet& transformBy(const LorentzTransform& lt);
00194 
00195     /// Get the total energy of this jet.
00196     double totalEnergy() const { return momentum().E(); }
00197 
00198     /// Get the energy carried in this jet by neutral particles.
00199     double neutralEnergy() const;
00200 
00201     /// Get the energy carried in this jet by hadrons.
00202     double hadronicEnergy() const;
00203 
00204     //@}
00205 
00206 
00207     /// @name Interaction with FastJet
00208     //@{
00209 
00210     /// Access the internal FastJet3 PseudoJet (as a const reference)
00211     const fastjet::PseudoJet& pseudojet() const { return _pseudojet; }
00212 
00213     /// Cast operator to FastJet3 PseudoJet (as a const reference)
00214     operator const fastjet::PseudoJet& () const { return pseudojet(); }
00215 
00216     //@}
00217 
00218 
00219     /// @name Set the jet constituents and properties
00220     //@{
00221 
00222     /// @brief Set the jet data from a FastJet PseudoJet, with optional particle constituents and tags lists.
00223     ///
00224     /// @note The particles() list will be extracted from PseudoJet constituents
00225     /// by default, making use of an attached user info if one is found.
00226     Jet& setState(const fastjet::PseudoJet& pj, const Particles& particles=Particles(), const Particles& tags=Particles());
00227 
00228     /// Set all the jet data, with optional full particle constituent and tag information.
00229     Jet& setState(const FourMomentum& mom, const Particles& particles, const Particles& tags=Particles());
00230 
00231     /// @deprecated Prefer the 4-mom first-arg versions. Remove in Rivet v3
00232     DEPRECATED("Prefer the 4-mom first-arg versions")
00233     Jet& setState(const Particles& particles, const FourMomentum& mom) { return setState(mom, particles); }
00234 
00235     /// @brief Set the particles collection with full particle information.
00236     ///
00237     /// If set, this overrides particle info extracted from the PseudoJet
00238     Jet& setParticles(const Particles& particles);
00239     Jet& setConstituents(const Particles& particles) { return setParticles(particles); }
00240 
00241     /// Reset this jet as empty.
00242     Jet& clear();
00243 
00244     //@}
00245 
00246 
00247   private:
00248 
00249     /// FJ3 PseudoJet member to unify PseudoJet and Jet
00250     fastjet::PseudoJet _pseudojet;
00251 
00252     /// Full constituent particle information. (Filled from PseudoJet if possible.)
00253     /// @todo Make these mutable or similar? Add a flag to force a cache rebuild?
00254     Particles _particles;
00255 
00256     /// Particles used to tag this jet (can be anything, but c and b hadrons are the most common)
00257     Particles _tags;
00258 
00259     /// Effective jet 4-vector (just for caching)
00260     mutable FourMomentum _momentum;
00261 
00262   };
00263 
00264 
00265   /// @name String representation and streaming support
00266   //@{
00267 
00268   /// Represent a Jet as a string.
00269   std::string to_str(const Jet& j);
00270 
00271   /// Allow a Jet to be passed to an ostream.
00272   inline std::ostream& operator<<(std::ostream& os, const Jet& j) {
00273     os << to_str(j);
00274     return os;
00275   }
00276 
00277   //@}
00278 
00279 
00280 }
00281 
00282 
00283 #include "Rivet/Tools/JetUtils.hh"
00284 
00285 #endif