rivet is hosted by Hepforge, IPPP Durham
ParticleFinder.hh
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_ParticleFinder_HH
00003 #define RIVET_ParticleFinder_HH
00004 
00005 #include "Rivet/Projection.hh"
00006 
00007 namespace Rivet {
00008 
00009 
00010   /// @brief Base class for projections which return subsets of an event's particles
00011   class ParticleFinder : public Projection {
00012   public:
00013 
00014     /// @name Object lifetime management
00015     //@{
00016 
00017     /// Construction using Cuts object
00018     ParticleFinder(const Cut& c=Cuts::OPEN)
00019       : _cuts(c), _theParticles()
00020     { }
00021 
00022     /// Virtual destructor for inheritance
00023     virtual ~ParticleFinder() {}
00024 
00025     /// Clone on the heap.
00026     virtual unique_ptr<Projection> clone() const = 0;
00027 
00028     //@}
00029 
00030 
00031     /// @name Particle accessors
00032     //@{
00033 
00034     /// Get the final-state particles in no particular order, with no cuts.
00035     virtual const Particles& particles() const { return _theParticles; }
00036 
00037     /// Access the projected final-state particles.
00038     size_t size() const { return particles().size(); }
00039 
00040     /// Is this final state empty?
00041     bool empty() const { return particles().empty(); }
00042     /// @deprecated Is this final state empty?
00043     DEPRECATED("Use empty()")
00044     bool isEmpty() const { return particles().empty(); }
00045 
00046 
00047     /// @brief Get the final-state particles, with optional cuts.
00048     /// @note Returns a copy rather than a reference, due to cuts
00049     /// @todo Can't this be a const Cut& arg?
00050     Particles particles(const Cut& c) const {
00051       // Just return a copy of particles() if the cut is open
00052       if (c == Cuts::open()) return particles();
00053       // If there is a non-trivial cut...
00054       Particles rtn;
00055       rtn.reserve(size());
00056       foreach (const Particle& p, particles())
00057         if (c->accept(p)) rtn.push_back(p);
00058       return rtn;
00059     }
00060 
00061 
00062     /// @todo Want to add a general filtering function, but that clashes with the sorting functor... SFINAE?
00063 
00064 
00065     /// Get the final-state particles, ordered by supplied sorting function object.
00066     /// @note Returns a copy rather than a reference, due to cuts and sorting
00067     /// @todo Can't this be a const Cut& arg?
00068     /// @todo Use a std::function instead of typename F?
00069     template <typename F>
00070     Particles particles(F sorter, const Cut& c=Cuts::open()) const {
00071       /// @todo Will the vector be efficiently std::move'd by value through this function chain?
00072       return sortBy(particles(c), sorter);
00073     }
00074 
00075     /// Get the final-state particles, ordered by supplied sorting function object.
00076     /// @note Returns a copy rather than a reference, due to cuts and sorting
00077     /// @todo Can't this be a const Cut& arg?
00078     /// @todo Use a std::function instead of typename F?
00079     template <typename F>
00080     Particles particles(const Cut& c, F sorter) const {
00081       /// @todo Will the vector be efficiently std::move'd by value through this function chain?
00082       return sortBy(particles(c), sorter);
00083     }
00084 
00085     /// Get the final-state particles, ordered by decreasing \f$ p_T \f$ and with optional cuts.
00086     ///
00087     /// This is a very common use-case, so is available as syntatic sugar for particles(c, cmpMomByPt).
00088     Particles particlesByPt(const Cut& c=Cuts::open()) const {
00089       return particles(c, cmpMomByPt);
00090     }
00091 
00092     /// Get the final-state particles, ordered by decreasing \f$ p_T \f$ and with a cut on minimum \f$ p_T \f$.
00093     ///
00094     /// This is a very common use-case, so is available as syntatic sugar for particles(Cuts::pT >= ptmin, cmpMomByPt).
00095     Particles particlesByPt(double ptmin) const {
00096       return particles(Cuts::pT >= ptmin, cmpMomByPt);
00097     }
00098 
00099 
00100     /// @name Little-used sorted accessors
00101     /// @deprecated Use the versions with a sorter function argument
00102     //@{
00103 
00104     /// Get the final-state particles, ordered by decreasing \f$ p \f$.
00105     /// @todo Remove, since there is the templated method or sortByX methods available for these unusual cases?
00106     /// @deprecated Use the version with a sorter function argument
00107     DEPRECATED("Use the version with a sorter function argument")
00108     Particles particlesByP(const Cut & c=Cuts::open()) const {
00109       return particles(c, cmpMomByP);
00110     }
00111 
00112     /// Get the final-state particles, ordered by decreasing \f$ E \f$.
00113     /// @todo Remove, since there is the templated method or sortByX methods available for these unusual cases?
00114     /// @deprecated Use the version with a sorter function argument
00115     DEPRECATED("Use the version with a sorter function argument")
00116     Particles particlesByE(const Cut & c=Cuts::open()) const {
00117       return particles(c, cmpMomByE);
00118     }
00119 
00120     /// Get the final-state particles, ordered by decreasing \f$ E_T \f$.
00121     /// @todo Remove, since there is the templated method or sortByX methods available for these unusual cases?
00122     /// @deprecated Use the version with a sorter function argument
00123     DEPRECATED("Use the version with a sorter function argument")
00124     Particles particlesByEt(const Cut & c=Cuts::open()) const {
00125       return particles(c, cmpMomByEt);
00126     }
00127 
00128     /// Get the final-state particles, ordered by increasing \f$ \eta \f$.
00129     /// @todo Remove, since there is the templated method or sortByX methods available for these unusual cases?
00130     /// @deprecated Use the version with a sorter function argument
00131     DEPRECATED("Use the version with a sorter function argument")
00132     Particles particlesByEta(const Cut & c=Cuts::open()) const {
00133       return particles(c, cmpMomByEta);
00134     }
00135 
00136     /// Get the final-state particles, ordered by increasing \f$ |\eta| \f$.
00137     /// @todo Remove, since there is the templated method or sortByX methods available for these unusual cases?
00138     /// @deprecated Use the version with a sorter function argument
00139     DEPRECATED("Use the version with a sorter function argument")
00140     Particles particlesByModEta(const Cut & c=Cuts::open()) const {
00141       return particles(c, cmpMomByAbsEta);
00142     }
00143 
00144     /// Get the final-state particles, ordered by increasing \f$ y \f$.
00145     /// @todo Remove, since there is the templated method or sortByX methods available for these unusual cases?
00146     /// @deprecated Use the version with a sorter function argument
00147     DEPRECATED("Use the version with a sorter function argument")
00148     Particles particlesByRapidity(const Cut & c=Cuts::open()) const {
00149       return particles(c, cmpMomByRap);
00150     }
00151 
00152     /// Get the final-state particles, ordered by increasing \f$ |y| \f$.
00153     /// @todo Remove, since there is the templated method or sortByX methods available for these unusual cases?
00154     /// @deprecated Use the version with a sorter function argument
00155     DEPRECATED("Use the version with a sorter function argument")
00156     Particles particlesByModRapidity(const Cut & c=Cuts::open()) const {
00157       return particles(c, cmpMomByAbsRap);
00158     }
00159 
00160     //@}
00161 
00162     //@}
00163 
00164 
00165     /// @todo Replace with cuts() accessor
00166     ///virtual Cut cuts() const { return _cuts; }
00167 
00168 
00169     /// @name For JetAlg compatibility
00170     //@{
00171 
00172     typedef Particle entity_type;
00173     typedef Particles collection_type;
00174 
00175     /// Template-usable interface common to JetAlg
00176     const collection_type& entities() const {
00177       return particles();
00178     }
00179 
00180     //@}
00181 
00182 
00183   protected:
00184 
00185     /// Apply the projection to the event
00186     virtual void project(const Event& e) = 0;
00187 
00188     /// Compare projections
00189     virtual int compare(const Projection& p) const;
00190 
00191     /// The kinematic cuts cuts
00192     Cut _cuts;
00193 
00194     /// The found particles returned by the particles() methods
00195     Particles _theParticles;
00196 
00197   };
00198 
00199 
00200 }
00201 
00202 #endif