Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 #ifndef RIVET_ParticleFinder_HH
0003 #define RIVET_ParticleFinder_HH
0004 
0005 #include "Rivet/Projection.hh"
0006 
0007 namespace Rivet {
0008 
0009 
0010   /// @brief Base class for projections which return subsets of an event's particles
0011   class ParticleFinder : public Projection {
0012   public:
0013 
0014     //using Projection::operator=;
0015 
0016     /// @name Object lifetime management
0017     /// @{
0018 
0019     /// Construction using Cuts object
0020     ParticleFinder(const Cut& c=Cuts::OPEN)
0021       : _cuts(c), _theParticles()
0022     {   }
0023 
0024     // /// @brief Construction using a wrapped other ParticleFinder plus cuts
0025     // ///
0026     // /// Useful to apply extra cuts to a generic PF's returned particles.
0027     // ParticleFinder(const ParticleFinder& pf, const Cut& c) //=Cuts::OPEN)
0028     //   : _cuts(c), _theParticles()
0029     // {
0030     //   setName("ParticleFinder[" + pf.name() + "]");      
0031     //   declare(pf, "PF");
0032     // }
0033     
0034     /// Virtual destructor for inheritance
0035     virtual ~ParticleFinder() {}
0036 
0037     /// Clone on the heap.
0038     virtual unique_ptr<Projection> clone() const = 0;
0039     // RIVET_DEFAULT_PROJ_CLONE(ParticleFinder);
0040 
0041     /// @}
0042 
0043     /// Import to avoid warnings about overload-hiding
0044     using Projection::operator =;
0045 
0046 
0047     /// @name Particle accessors
0048     /// @{
0049 
0050     /// Count the final-state particles
0051     size_t size() const { return particles().size(); }
0052     /// Count the final-state particles after a Cut is applied
0053     size_t size(const Cut& c) const { return particles(c).size(); }
0054     /// Count the final-state particles after a selection functor is applied
0055     size_t size(const ParticleSelector& s) const { return particles(s).size(); }
0056 
0057     /// Is this final state empty?
0058     bool empty() const { return size() == 0; }
0059     /// Is this final state empty after a Cut is applied?
0060     bool empty(const Cut& c) const { return size(c) == 0; }
0061     /// Is this final state empty after a selection functor is applied?
0062     bool empty(const ParticleSelector& s) const { return size(s) == 0; }
0063 
0064     /// Get the particles in no particular order, with no cuts
0065     virtual const Particles& particles() const { return _theParticles; }
0066 
0067     /// Get the raw particles in no particular order, with no cuts
0068     ///
0069     /// @note Raw particles are the final-state constituents, as opposed to
0070     /// potentially composite particles returned as the finder's particles()
0071     Particles rawParticles() const {
0072       Particles rtn;
0073       for (const Particle& p : particles()) rtn += p.rawConstituents();
0074       return rtn;
0075     }
0076 
0077     /// @brief Get the particles with selection cuts
0078     /// @note Returns a copy rather than a reference, due to the cuts.
0079     Particles particles(const Cut& c) const {
0080       return select(particles(), c);
0081     }
0082 
0083     /// @brief Get the particles with selection cuts via a functor
0084     /// @note Returns a copy rather than a reference, due to the cuts.
0085     Particles particles(const ParticleSelector& selector) const {
0086       return select(particles(), selector);
0087     }
0088 
0089     /// Get the particles, ordered by supplied sorting function object
0090     /// @note Returns a copy rather than a reference, due to cuts and sorting.
0091     Particles particles(const ParticleSorter& sorter, const Cut& c=Cuts::open()) const {
0092       return sortBy(particles(c), sorter);
0093     }
0094 
0095     /// Get the particles, ordered by supplied sorting function object
0096     /// @note Returns a copy rather than a reference, due to cuts and sorting.
0097     Particles particles(const Cut& c, const ParticleSorter& sorter) const {
0098       return sortBy(particles(c), sorter);
0099     }
0100 
0101     /// Get the particles, ordered by a sorting functor and filtered by a selection functor
0102     /// @note Returns a copy rather than a reference, due to cuts and sorting.
0103     Particles particles(const ParticleSelector& selector, const ParticleSorter& sorter) const {
0104       return sortBy(particles(selector), sorter);
0105     }
0106 
0107     /// Get the particles, ordered by a sorting functor and filtered by a selection functor
0108     /// @note Returns a copy rather than a reference, due to cuts and sorting.
0109     Particles particles(const ParticleSorter& sorter, const ParticleSelector& selector) const {
0110       return sortBy(particles(selector), sorter);
0111     }
0112 
0113     /// Get the particles, ordered by decreasing \f$ p_T \f$ and with optional cuts
0114     ///
0115     /// This is a very common use-case, so is available as syntatic sugar for particles(c, cmpMomByPt).
0116     Particles particlesByPt(const Cut& c=Cuts::open()) const {
0117       return particles(c, cmpMomByPt);
0118     }
0119 
0120     /// Get the particles, ordered by decreasing \f$ p_T \f$ and with optional cuts
0121     ///
0122     /// This is a very common use-case, so is available as syntatic sugar for particles(f, cmpMomByPt).
0123     Particles particlesByPt(const ParticleSelector& selector) const {
0124       return particles(selector, cmpMomByPt);
0125     }
0126 
0127     /// Get the particles, ordered by decreasing \f$ p_T \f$ and with a cut on minimum \f$ p_T \f$
0128     ///
0129     /// This is a very common use-case, so is available as syntatic sugar for particles(Cuts::pT >= ptmin, cmpMomByPt).
0130     Particles particlesByPt(double ptmin) const {
0131       return particles(Cuts::pT >= ptmin, cmpMomByPt);
0132     }
0133 
0134     /// @}
0135 
0136 
0137     /// @todo Replace with cuts() accessor
0138     ///virtual Cut cuts() const { return _cuts; }
0139 
0140 
0141     /// @name For JetAlg compatibility
0142     /// @{
0143 
0144     typedef Particle entity_type;
0145     typedef Particles collection_type;
0146 
0147     /// Template-usable interface common to JetAlg
0148     const collection_type& entities() const { return particles(); }
0149 
0150     /// @}
0151 
0152     /// Apply the projection to the event
0153     virtual void project(const Event& e) = 0;
0154 
0155     /// Compare projections
0156     virtual CmpState compare(const Projection& p) const;
0157 
0158 
0159   protected:
0160 
0161     /// The kinematic cuts
0162     Cut _cuts;
0163 
0164     /// The found particles returned by the particles() methods
0165     Particles _theParticles;
0166 
0167   };
0168 
0169 
0170 }
0171 
0172 #endif