Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:06:56

0001 // -*- C++ -*-
0002 #ifndef RIVET_Jet_HH
0003 #define RIVET_Jet_HH
0004 
0005 #include "Rivet/Config/RivetCommon.hh"
0006 #include "Rivet/Jet.fhh"
0007 #include "Rivet/Particle.hh"
0008 #include "Rivet/Tools/Cuts.hh"
0009 #include "Rivet/Tools/Utils.hh"
0010 #include "Rivet/Tools/RivetFastJet.hh"
0011 #include "Rivet/Math/LorentzTrans.hh"
0012 #include <numeric>
0013 
0014 namespace Rivet {
0015 
0016 
0017   /// @brief Specialised vector of Jet objects.
0018   ///
0019   /// A specialised version of vector<Jet> which is able to implicitly and
0020   /// explicitly convert to a vector of FourMomentum or PseudoJet.
0021   class Jets : public std::vector<Jet> {
0022   public:
0023     using base = std::vector<Jet>; //< using-declarations don't like template syntax
0024     using base::base; //< import base-class constructors
0025     Jets();
0026     Jets(const std::vector<Jet>& vjs);
0027     FourMomenta moms() const;
0028     PseudoJets pseudojets() const;
0029     operator FourMomenta () const { return moms(); }
0030     operator PseudoJets () const { return pseudojets(); }
0031     Jets& operator += (const Jet& j);
0032     Jets& operator += (const Jets& js);
0033   };
0034 
0035   Jets operator + (const Jets& a, const Jets& b);
0036 
0037 
0038   //////////////////////
0039 
0040 
0041   /// @brief Representation of a clustered jet of particles.
0042   class Jet : public ParticleBase {
0043   public:
0044 
0045     /// @name Constructors
0046     /// @{
0047 
0048     /// Constructor from a FastJet PseudoJet, with optional full particle constituents information.
0049     Jet(const fastjet::PseudoJet& pj, const Particles& particles=Particles(), const Particles& tags=Particles()) {
0050       setState(pj, particles, tags);
0051     }
0052 
0053     /// Set the jet data, with optional full particle information.
0054     Jet(const FourMomentum& pjet, const Particles& particles=Particles(), const Particles& tags=Particles()) {
0055       setState(pjet, particles, tags);
0056     }
0057 
0058     /// Default constructor -- only for STL storability
0059     Jet() { clear(); }
0060 
0061     /// @}
0062 
0063 
0064     /// @name Access jet constituents
0065     /// @{
0066 
0067     /// Number of particles in this jet.
0068     size_t size() const { return _particles.size(); }
0069 
0070     /// Get the particles in this jet.
0071     Particles& particles() { return _particles; }
0072     /// Get the particles in this jet (const version)
0073     const Particles& particles() const { return _particles; }
0074     /// Get the particles in this jet which pass a cut (const)
0075     const Particles particles(const Cut& c) const { return select(_particles, c); }
0076     /// Get the particles in this jet which pass a filtering functor (const)
0077     const Particles particles(const ParticleSelector& s) const { return select(_particles, s); }
0078 
0079     /// Get the particles in this jet (FastJet-like alias)
0080     Particles& constituents() { return particles(); }
0081     /// Get the particles in this jet (FastJet-like alias, const version)
0082     const Particles& constituents() const { return particles(); }
0083     /// Get the particles in this jet which pass a cut (FastJet-like alias, const)
0084     const Particles constituents(const Cut& c) const { return particles(c); }
0085     /// Get the particles in this jet which pass a filtering functor (FastJet-like alias, const)
0086     const Particles constituents(const ParticleSelector& s) const { return particles(s); }
0087 
0088     /// Check whether this jet contains a particular particle.
0089     bool containsParticle(const Particle& particle) const;
0090     /// Nicer alias for containsParticleId
0091     bool containsPID(const Particle& particle) const { return containsParticle(particle); }
0092 
0093     /// Check whether this jet contains a certain particle type.
0094     bool containsParticleId(PdgId pid) const;
0095     /// Nicer alias for containsParticleId
0096     bool containsPID(PdgId pid) const { return containsParticleId(pid); }
0097 
0098     /// Check whether this jet contains at least one of certain particle types.
0099     bool containsParticleId(const vector<PdgId>& pids) const;
0100     /// Nicer alias for containsParticleId
0101     bool containsPID(const vector<PdgId>& pids) const { return containsParticleId(pids); }
0102 
0103     /// @}
0104 
0105 
0106     /// @name Tagging
0107     ///
0108     /// @note General sources of tag particles are planned. The default jet finding
0109     /// adds b-hadron, c-hadron, and tau tags by ghost association.
0110     /// @{
0111 
0112     /// @brief Particles which have been tag-matched to this jet
0113     Particles& tags() { return _tags; }
0114     /// @brief Particles which have been tag-matched to this jet (const version)
0115     const Particles& tags() const { return _tags; }
0116     /// @brief Particles which have been tag-matched to this jet _and_ pass a selector function
0117     ///
0118     /// @note Note the less efficient return by value, due to the filtering.
0119     Particles tags(const ParticleSelector& f) const { return select(tags(), f); }
0120     /// @brief Particles which have been tag-matched to this jet _and_ pass a Cut
0121     ///
0122     /// @note Note the less efficient return by value, due to the cut-pass filtering.
0123     Particles tags(const Cut& c) const;
0124 
0125 
0126     /// @brief b particles which have been tag-matched to this jet (and pass an optional Cut)
0127     ///
0128     /// The default jet finding adds b-hadron tags by ghost association.
0129     Particles bTags(const Cut& c=Cuts::open()) const;
0130     /// @brief b particles which have been tag-matched to this jet _and_ pass a selector function
0131     Particles bTags(const ParticleSelector& f) const { return select(bTags(), f); }
0132 
0133     /// Does this jet have at least one b-tag (that passes an optional Cut)?
0134     bool bTagged(const Cut& c=Cuts::open()) const { return !bTags(c).empty(); }
0135     /// Does this jet have at least one b-tag (that passes the supplied selector function)?
0136     bool bTagged(const ParticleSelector& f) const { return !bTags(f).empty(); }
0137 
0138 
0139     /// @brief c (and not b) particles which have been tag-matched to this jet (and pass an optional Cut)
0140     ///
0141     /// The default jet finding adds c-hadron tags by ghost association.
0142     Particles cTags(const Cut& c=Cuts::open()) const;
0143     /// @brief c (and not b) particles which have been tag-matched to this jet and pass a selector function
0144     Particles cTags(const ParticleSelector& f) const { return select(cTags(), f); }
0145 
0146     /// Does this jet have at least one c-tag (that passes an optional Cut)?
0147     bool cTagged(const Cut& c=Cuts::open()) const { return !cTags(c).empty(); }
0148     /// Does this jet have at least one c-tag (that passes the supplied selector function)?
0149     bool cTagged(const ParticleSelector& f) const { return !cTags(f).empty(); }
0150 
0151 
0152     /// @brief Tau particles which have been tag-matched to this jet (and pass an optional Cut)
0153     ///
0154     /// The default jet finding adds tau tags by ghost association.
0155     Particles tauTags(const Cut& c=Cuts::open()) const;
0156     /// @brief Tau particles which have been tag-matched to this jet and pass a selector function
0157     Particles tauTags(const ParticleSelector& f) const { return select(tauTags(), f); }
0158 
0159     /// Does this jet have at least one tau-tag (that passes an optional Cut)?
0160     bool tauTagged(const Cut& c=Cuts::open()) const { return !tauTags(c).empty(); }
0161     /// Does this jet have at least one tau-tag (that passes the supplied selector function)?
0162     bool tauTagged(const ParticleSelector& f) const { return !tauTags(f).empty(); }
0163 
0164     /// @}
0165 
0166 
0167     /// @name Effective jet 4-vector properties
0168     /// @{
0169 
0170     /// Get equivalent single momentum four-vector.
0171     const FourMomentum& momentum() const { return _momentum; }
0172 
0173     /// Apply an active Lorentz transform to this jet
0174     /// @note The Rivet jet momentum, constituent particles, and tag particles will be modified.
0175     /// @warning The FastJet cluster sequence and pseudojets will not be modified: don't use them after transformation!
0176     Jet& transformBy(const LorentzTransform& lt);
0177 
0178     /// Get the total energy of this jet.
0179     double totalEnergy() const { return momentum().E(); }
0180 
0181     /// Get the energy carried in this jet by neutral particles.
0182     double neutralEnergy() const;
0183 
0184     /// Get the energy carried in this jet by hadrons.
0185     double hadronicEnergy() const;
0186 
0187     /// @}
0188 
0189 
0190     /// @name Interaction with FastJet
0191     /// @{
0192 
0193     /// Access the internal FastJet3 PseudoJet (as a const reference)
0194     const fastjet::PseudoJet& pseudojet() const { return _pseudojet; }
0195 
0196     /// Cast operator to FastJet3 PseudoJet (as a const reference)
0197     operator const fastjet::PseudoJet& () const { return pseudojet(); }
0198 
0199     /// @}
0200 
0201 
0202     /// @name Set the jet constituents and properties
0203     /// @{
0204 
0205     /// @brief Set the jet data from a FastJet PseudoJet, with optional particle constituents and tags lists.
0206     ///
0207     /// @note The particles() list will be extracted from PseudoJet constituents
0208     /// by default, making use of an attached user info if one is found.
0209     Jet& setState(const fastjet::PseudoJet& pj, const Particles& particles=Particles(), const Particles& tags=Particles());
0210 
0211     /// Set all the jet data, with optional full particle constituent and tag information.
0212     Jet& setState(const FourMomentum& mom, const Particles& particles, const Particles& tags=Particles());
0213 
0214     /// @brief Set the particles collection with full particle information.
0215     ///
0216     /// If set, this overrides particle info extracted from the PseudoJet
0217     Jet& setParticles(const Particles& particles);
0218     Jet& setConstituents(const Particles& particles) { return setParticles(particles); }
0219 
0220     /// Reset this jet as empty.
0221     Jet& clear();
0222 
0223     /// @}
0224 
0225 
0226   private:
0227 
0228     /// FJ3 PseudoJet member to unify PseudoJet and Jet
0229     fastjet::PseudoJet _pseudojet;
0230 
0231     /// Full constituent particle information. (Filled from PseudoJet if possible.)
0232     /// @todo Make these mutable or similar? Add a flag to force a cache rebuild?
0233     Particles _particles;
0234 
0235     /// Particles used to tag this jet (can be anything, but c and b hadrons are the most common)
0236     Particles _tags;
0237 
0238     /// Effective jet 4-vector (just for caching)
0239     mutable FourMomentum _momentum;
0240 
0241     // /// Provide but hide the equality operators, to avoid implicit comparison via fastjet::PseudoJet
0242     // bool operator == (const Jet&) const;
0243     // bool operator != (const Jet&) const;
0244 
0245   };
0246 
0247 
0248   /// @name String representation and streaming support
0249   /// @{
0250 
0251   /// Allow a Jet to be passed to an ostream.
0252   std::ostream& operator << (std::ostream& os, const Jet& j);
0253 
0254   /// @}
0255 
0256 
0257 }
0258 
0259 
0260 #include "Rivet/Tools/JetUtils.hh"
0261 
0262 #endif