rivet is hosted by Hepforge, IPPP Durham
JetAlg.hh
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_JetAlg_HH
00003 #define RIVET_JetAlg_HH
00004 
00005 #include "Rivet/Projection.hh"
00006 #include "Rivet/Projections/FinalState.hh"
00007 #include "Rivet/Projections/VisibleFinalState.hh"
00008 #include "Rivet/Particle.hh"
00009 #include "Rivet/Jet.hh"
00010 
00011 namespace Rivet {
00012 
00013 
00014   /// Abstract base class for projections which can return a set of {@link Jet}s.
00015   class JetAlg : public Projection {
00016   public:
00017 
00018     /// Enum for the treatment of muons: whether to include all, some, or none in jet-finding
00019     enum MuonsStrategy { NO_MUONS, DECAY_MUONS, ALL_MUONS };
00020 
00021     /// Enum for the treatment of invisible particles: whether to include all, some, or none in jet-finding
00022     enum InvisiblesStrategy { NO_INVISIBLES, DECAY_INVISIBLES, ALL_INVISIBLES };
00023 
00024 
00025 
00026     /// Constructor
00027     JetAlg(const FinalState& fs, MuonsStrategy usemuons=JetAlg::ALL_MUONS, InvisiblesStrategy useinvis=JetAlg::NO_INVISIBLES);
00028 
00029     /// Default constructor
00030     JetAlg() {};
00031 
00032     /// Clone on the heap.
00033     virtual unique_ptr<Projection> clone() const = 0;
00034 
00035     /// Destructor
00036     virtual ~JetAlg() { }
00037 
00038 
00039     /// @name Control the treatment of muons and invisible particles
00040     ///
00041     /// Since MC-based jet calibration (and/or particle flow) can add back in
00042     /// particles that weren't seen in calorimeters/trackers.
00043     //@{
00044 
00045     /// @brief Include (some) muons in jet construction.
00046     ///
00047     /// The default behaviour is that jets are only constructed from visible
00048     /// particles. Some jet studies, including those from ATLAS, use a definition
00049     /// in which neutrinos from hadron decays are included via MC-based calibrations.
00050     /// Setting this flag to true avoids the automatic restriction to a VisibleFinalState.
00051     void useMuons(MuonsStrategy usemuons=ALL_MUONS) {
00052       _useMuons = usemuons;
00053     }
00054 
00055     /// @brief Include (some) invisible particles in jet construction.
00056     ///
00057     /// The default behaviour is that jets are only constructed from visible
00058     /// particles. Some jet studies, including those from ATLAS, use a definition
00059     /// in which neutrinos from hadron decays are included via MC-based calibrations.
00060     /// Setting this flag to true avoids the automatic restriction to a VisibleFinalState.
00061     void useInvisibles(InvisiblesStrategy useinvis=DECAY_INVISIBLES) {
00062       _useInvisibles = useinvis;
00063     }
00064 
00065     /// @brief Include (some) invisible particles in jet construction.
00066     ///
00067     /// The default behaviour is that jets are only constructed from visible
00068     /// particles. Some jet studies, including those from ATLAS, use a definition
00069     /// in which neutrinos from hadron decays are included via MC-based calibrations.
00070     /// Setting this flag to true avoids the automatic restriction to a VisibleFinalState.
00071     ///
00072     /// @deprecated Use the enum-arg version instead. Will be removed in Rivet v3
00073     void useInvisibles(bool useinvis) {
00074       _useInvisibles = useinvis ? DECAY_INVISIBLES : NO_INVISIBLES;
00075     }
00076 
00077     //@}
00078 
00079 
00080     /// @name Access to jet objects
00081     //@{
00082 
00083     /// Get jets in no guaranteed order, with optional cuts on \f$ p_\perp \f$ and rapidity.
00084     /// @note Returns a copy rather than a reference, due to cuts
00085     virtual Jets jets(const Cut& c=Cuts::open()) const {
00086       return filterBy(_jets(), c);
00087       // const Jets rawjets = _jets();
00088       // // Just return a copy of rawjets if the cut is open
00089       // if (c == Cuts::open()) return rawjets;
00090       // // If there is a non-trivial cut...
00091       // /// @todo Use an STL erase(remove_if) and lambda function for this
00092       // Jets rtn;
00093       // rtn.reserve(size());
00094       // foreach (const Jet& j, rawjets)
00095       //   if (c->accept(j)) rtn.push_back(j);
00096       // return rtn;
00097     }
00098 
00099 
00100     /// @todo Want to add a general filtering function, but that clashes with the sorting functor... SFINAE?
00101 
00102 
00103     /// Get the jets, ordered by supplied sorting function object, with optional cuts on \f$ p_\perp \f$ and rapidity.
00104     /// @note Returns a copy rather than a reference, due to cuts and sorting
00105     template <typename F>
00106     Jets jets(F sorter, const Cut& c=Cuts::open()) const {
00107       /// @todo Will the vector be efficiently std::move'd by value through this function chain?
00108       return sortBy(jets(c), sorter);
00109     }
00110 
00111     /// Get the jets, ordered by supplied sorting function object, with optional cuts on \f$ p_\perp \f$ and rapidity.
00112     /// @note Returns a copy rather than a reference, due to cuts and sorting
00113     template <typename F>
00114     Jets jets(const Cut& c, F sorter) const {
00115       /// @todo Will the vector be efficiently std::move'd by value through this function chain?
00116       return sortBy(jets(c), sorter);
00117     }
00118 
00119 
00120     /// Get the jets, ordered by \f$ p_T \f$, with optional cuts.
00121     ///
00122     /// @note Returns a copy rather than a reference, due to cuts and sorting
00123     ///
00124     /// This is a very common use-case, so is available as syntatic sugar for jets(c, cmpMomByPt).
00125     /// @todo The other sorted accessors should be removed in a cleanup.
00126     Jets jetsByPt(const Cut& c=Cuts::open()) const {
00127       return jets(c, cmpMomByPt);
00128     }
00129 
00130     //@}
00131 
00132 
00133     /// @name Old sorted jet accessors
00134     /// @deprecated Use the versions with sorter function arguments. These will be removed in Rivet v3
00135     //@{
00136 
00137     /// Get the jets, ordered by \f$ |p| \f$, with optional cuts on \f$ p_\perp \f$ and rapidity.
00138     /// @note Returns a copy rather than a reference, due to cuts and sorting
00139     /// @deprecated Use the version with a sorter function argument.
00140     DEPRECATED("Use the version with a sorter function argument.")
00141     Jets jetsByP(const Cut& c=Cuts::open()) const {
00142       return jets(c, cmpMomByP);
00143     }
00144 
00145     /// Get the jets, ordered by \f$ E \f$, with optional cuts on \f$ p_\perp \f$ and rapidity.
00146     /// @note Returns a copy rather than a reference, due to cuts and sorting
00147     /// @deprecated Use the version with a sorter function argument.
00148     DEPRECATED("Use the version with a sorter function argument.")
00149     Jets jetsByE(const Cut &c=Cuts::open()) const {
00150       return jets(c, cmpMomByE);
00151     }
00152 
00153     /// Get the jets, ordered by \f$ E_T \f$, with optional cuts on \f$ p_\perp \f$ and rapidity.
00154     /// @note Returns a copy rather than a reference, due to cuts and sorting
00155     /// @deprecated Use the version with a sorter function argument.
00156     DEPRECATED("Use the version with a sorter function argument.")
00157     Jets jetsByEt(const Cut& c=Cuts::open()) const {
00158       return jets(c, cmpMomByEt);
00159     }
00160 
00161     //@}
00162 
00163 
00164     /// @name Old jet accessors
00165     /// @deprecated Use the versions with Cut arguments
00166     //@{
00167 
00168     /// Get jets in no guaranteed order, with optional cuts on \f$ p_\perp \f$ and rapidity.
00169     ///
00170     /// @deprecated Use the version with a Cut argument
00171     /// @note Returns a copy rather than a reference, due to cuts
00172     DEPRECATED("Use the version with a Cut argument.")
00173     Jets jets(double ptmin, double ptmax=MAXDOUBLE,
00174               double rapmin=-MAXDOUBLE, double rapmax=MAXDOUBLE,
00175               RapScheme rapscheme=PSEUDORAPIDITY) const {
00176       if (rapscheme == PSEUDORAPIDITY) {
00177         return jets((Cuts::pT >= ptmin) & (Cuts::pT < ptmax) & (Cuts::rapIn(rapmin, rapmax)));
00178       } else if (rapscheme == RAPIDITY) {
00179         return jets((Cuts::pT >= ptmin) & (Cuts::pT < ptmax) & (Cuts::etaIn(rapmin, rapmax)));
00180       }
00181       throw LogicError("Unknown rapidity scheme. This shouldn't be possible!");
00182     }
00183 
00184     /// Get the jets, ordered by \f$ p_T \f$, with a cut on \f$ p_\perp \f$.
00185     ///
00186     /// @deprecated Use the version with a Cut argument
00187     /// @note Returns a copy rather than a reference, due to cuts and sorting
00188     ///
00189     /// This is a very common use-case, so is available as syntatic sugar for jets(Cuts::pT >= ptmin, cmpMomByPt).
00190     /// @todo The other sorted accessors should be removed in a cleanup.
00191     Jets jetsByPt(double ptmin) const {
00192       return jets(Cuts::pT >= ptmin, cmpMomByPt);
00193     }
00194 
00195     //@}
00196 
00197 
00198   protected:
00199 
00200     /// @brief Internal pure virtual method for getting jets in no guaranteed order.
00201     virtual Jets _jets() const = 0;
00202 
00203 
00204   public:
00205 
00206     /// Number of jets passing the provided Cut.
00207     size_t numJets(const Cut& c=Cuts::open()) const { return jets(c).size(); }
00208 
00209     /// Number of jets (without cuts).
00210     size_t size() const { return jets().size(); }
00211     /// Whether the inclusive jet collection is empty.
00212     bool empty() const { return size() != 0; }
00213 
00214     /// Clear the projection.
00215     virtual void reset() = 0;
00216 
00217     typedef Jet entity_type;
00218     typedef Jets collection_type;
00219 
00220     /// Template-usable interface common to FinalState.
00221     collection_type entities() const { return jets(); }
00222 
00223     // /// Do the calculation locally (no caching).
00224     // virtual void calc(const Particles& constituents, const Particles& tagparticles=Particles()) = 0;
00225 
00226 
00227   protected:
00228 
00229     /// Perform the projection on the Event.
00230     virtual void project(const Event& e) = 0;
00231 
00232     /// Compare projections.
00233     virtual int compare(const Projection& p) const = 0;
00234 
00235 
00236   protected:
00237 
00238     /// Flag to determine whether or not to exclude (some) muons from the would-be constituents.
00239     MuonsStrategy _useMuons;
00240 
00241     /// Flag to determine whether or not to exclude (some) invisible particles from the would-be constituents.
00242     InvisiblesStrategy _useInvisibles;
00243 
00244 
00245   };
00246 
00247 
00248 }
00249 
00250 #endif