Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:13:36

0001 // -*- C++ -*-
0002 #ifndef RIVET_FastJets_HH
0003 #define RIVET_FastJets_HH
0004 
0005 #include "Rivet/Jet.hh"
0006 #include "Rivet/Particle.hh"
0007 #include "Rivet/Projection.hh"
0008 #include "Rivet/Projections/JetFinder.hh"
0009 #include "Rivet/Projections/FinalState.hh"
0010 #include "Rivet/Tools/RivetFastJet.hh"
0011 
0012 #include "fastjet/SISConePlugin.hh"
0013 #include "fastjet/ATLASConePlugin.hh"
0014 #include "fastjet/CMSIterativeConePlugin.hh"
0015 #include "fastjet/CDFJetCluPlugin.hh"
0016 #include "fastjet/CDFMidPointPlugin.hh"
0017 #include "fastjet/D0RunIIConePlugin.hh"
0018 #include "fastjet/TrackJetPlugin.hh"
0019 #include "fastjet/JadePlugin.hh"
0020 #include "fastjet/contrib/VariableRPlugin.hh"
0021 
0022 #include "Rivet/Projections/PxConePlugin.hh"
0023 #include "Rivet/Tools/TypeTraits.hh"
0024 
0025 namespace Rivet {
0026 
0027   typedef std::shared_ptr<fastjet::JetDefinition::Plugin> FJPluginPtr;
0028 
0029   /// Find jets using jet algorithms via the FastJet package
0030   class FastJets : public JetFinder {
0031   public:
0032 
0033     using JetFinder::operator =;
0034 
0035 
0036     /// @name Constructors etc.
0037     /// @{
0038 
0039     /// Constructor from a FastJet JetDefinition
0040     ///
0041     /// @warning The AreaDefinition pointer must be heap-allocated: it will be stored/deleted via a shared_ptr.
0042     FastJets(const FinalState& fsp,
0043              const fastjet::JetDefinition& jdef,
0044              JetMuons usemuons=JetMuons::ALL,
0045              JetInvisibles useinvis=JetInvisibles::NONE,
0046              fastjet::AreaDefinition* adef=nullptr)
0047       : JetFinder(fsp, usemuons, useinvis), _jdef(jdef),
0048         _adef(adef), _cuts(Cuts::OPEN)
0049     {
0050       _initBase();
0051     }
0052 
0053     /// Constructor from a FastJet JetDefinition with optional Cut argument
0054     ///
0055     /// @warning The AreaDefinition pointer must be heap-allocated: it will be stored/deleted via a shared_ptr.
0056     FastJets(const FinalState& fsp,
0057              const fastjet::JetDefinition& jdef,
0058              const Cut& c,
0059              JetMuons usemuons=JetMuons::ALL,
0060              JetInvisibles useinvis=JetInvisibles::NONE,
0061              fastjet::AreaDefinition* adef=nullptr)
0062       : JetFinder(fsp, usemuons, useinvis), _jdef(jdef),
0063         _adef(adef), _cuts(c)
0064     {
0065       _initBase();
0066     }
0067 
0068     /// JetDefinition-based constructor with reordered args for easier specification of jet area definition
0069     ///
0070     /// @warning The AreaDefinition pointer must be heap-allocated: it will be stored/deleted via a shared_ptr.
0071     FastJets(const FinalState& fsp,
0072              const fastjet::JetDefinition& jdef,
0073              fastjet::AreaDefinition* adef,
0074              JetMuons usemuons=JetMuons::ALL,
0075              JetInvisibles useinvis=JetInvisibles::NONE)
0076       : FastJets(fsp, jdef, usemuons, useinvis, adef)
0077     {    }
0078 
0079     /// JetDefinition-based constructor with Cut argument and reordered args for easier
0080     /// specification of jet area definition
0081     ///
0082     /// @warning The AreaDefinition pointer must be heap-allocated: it will be stored/deleted via a shared_ptr.
0083     FastJets(const FinalState& fsp,
0084              const fastjet::JetDefinition& jdef,
0085              fastjet::AreaDefinition* adef,
0086              const Cut& c,
0087              JetMuons usemuons=JetMuons::ALL,
0088              JetInvisibles useinvis=JetInvisibles::NONE)
0089       : FastJets(fsp, jdef, c, usemuons, useinvis, adef)
0090     {    }
0091 
0092 
0093     /// Native argument constructor, using FastJet alg/scheme enums.
0094     ///
0095     /// @warning The AreaDefinition pointer must be heap-allocated: it will be stored/deleted via a shared_ptr.
0096     FastJets(const FinalState& fsp,
0097              fastjet::JetAlgorithm type,
0098              fastjet::RecombinationScheme recom, double rparameter,
0099              JetMuons usemuons=JetMuons::ALL,
0100              JetInvisibles useinvis=JetInvisibles::NONE,
0101              fastjet::AreaDefinition* adef=nullptr)
0102       : FastJets(fsp, fastjet::JetDefinition(type, rparameter, recom), usemuons, useinvis, adef)
0103     {    }
0104 
0105     /// Native argument constructor with Cut argument, using FastJet alg/scheme enums.
0106     ///
0107     /// @warning The AreaDefinition pointer must be heap-allocated: it will be stored/deleted via a shared_ptr.
0108     FastJets(const FinalState& fsp,
0109              fastjet::JetAlgorithm type,
0110              fastjet::RecombinationScheme recom, double rparameter,
0111              const Cut& c,
0112              JetMuons usemuons=JetMuons::ALL,
0113              JetInvisibles useinvis=JetInvisibles::NONE,
0114              fastjet::AreaDefinition* adef=nullptr)
0115       : FastJets(fsp, fastjet::JetDefinition(type, rparameter, recom), c, usemuons, useinvis, adef)
0116     {    }
0117 
0118     /// Native argument constructor with reordered args for easier specification of jet area definition
0119     ///
0120     /// @warning The AreaDefinition pointer must be heap-allocated: it will be stored/deleted via a shared_ptr.
0121     FastJets(const FinalState& fsp,
0122              fastjet::JetAlgorithm type,
0123              fastjet::RecombinationScheme recom, double rparameter,
0124              fastjet::AreaDefinition* adef,
0125              JetMuons usemuons=JetMuons::ALL,
0126              JetInvisibles useinvis=JetInvisibles::NONE)
0127       : FastJets(fsp, type, recom, rparameter, usemuons, useinvis, adef)
0128     {    }
0129 
0130     /// Native argument constructor with Cut argument and reordered args for easier specification of jet area definition
0131     ///
0132     /// @warning The AreaDefinition pointer must be heap-allocated: it will be stored/deleted via a shared_ptr.
0133     FastJets(const FinalState& fsp,
0134              fastjet::JetAlgorithm type,
0135              fastjet::RecombinationScheme recom, double rparameter,
0136              fastjet::AreaDefinition* adef,
0137              const Cut& c,
0138              JetMuons usemuons=JetMuons::ALL,
0139              JetInvisibles useinvis=JetInvisibles::NONE)
0140       : FastJets(fsp, type, recom, rparameter, c, usemuons, useinvis, adef)
0141     {    }
0142 
0143     /// @brief Explicitly pass in an externally-constructed plugin
0144     ///
0145     /// @warning Provided plugin and area definition pointers must be heap-allocated; Rivet will store/delete via a shared_ptr
0146     FastJets(const FinalState& fsp,
0147              FJPluginPtr plugin,
0148              JetMuons usemuons=JetMuons::ALL,
0149              JetInvisibles useinvis=JetInvisibles::NONE,
0150              fastjet::AreaDefinition* adef=nullptr)
0151       : FastJets(fsp, fastjet::JetDefinition(plugin.get()), usemuons, useinvis, adef)
0152     {
0153       _plugin = plugin;
0154     }
0155 
0156     /// @brief Explicitly pass in an externally-constructed plugin
0157     ///
0158     /// @warning Provided plugin and area definition pointers must be heap-allocated; Rivet will store/delete via a shared_ptr
0159     FastJets(const FinalState& fsp,
0160              FJPluginPtr plugin,
0161              const Cut& c,
0162              JetMuons usemuons=JetMuons::ALL,
0163              JetInvisibles useinvis=JetInvisibles::NONE,
0164              fastjet::AreaDefinition* adef=nullptr)
0165       : FastJets(fsp, fastjet::JetDefinition(plugin.get()), c, usemuons, useinvis, adef)
0166     {
0167       _plugin = plugin;
0168     }
0169 
0170     /// @brief Explicitly pass in an externally-constructed plugin, with reordered args for easier specification of jet area definition
0171     ///
0172     /// @warning Provided plugin and area definition pointers must be heap-allocated; Rivet will store/delete via a shared_ptr
0173     FastJets(const FinalState& fsp,
0174              FJPluginPtr plugin,
0175              fastjet::AreaDefinition* adef,
0176              JetMuons usemuons=JetMuons::ALL,
0177              JetInvisibles useinvis=JetInvisibles::NONE)
0178       : FastJets(fsp, plugin, usemuons, useinvis, adef)
0179     {    }
0180 
0181     /// @brief Explicitly pass in an externally-constructed plugin, with reordered args for easier specification of jet area definition
0182     ///
0183     /// @warning Provided plugin and area definition pointers must be heap-allocated; Rivet will store/delete via a shared_ptr
0184     FastJets(const FinalState& fsp,
0185              FJPluginPtr plugin,
0186              fastjet::AreaDefinition* adef,
0187              const Cut& c,
0188              JetMuons usemuons=JetMuons::ALL,
0189              JetInvisibles useinvis=JetInvisibles::NONE)
0190       : FastJets(fsp, plugin, c, usemuons, useinvis, adef)
0191     {    }
0192 
0193     /// @brief Convenience constructor using Rivet enums for most common jet algs (including some plugins).
0194     ///
0195     /// For the built-in algs, E-scheme recombination is used. For full control
0196     /// of FastJet built-in jet algs, use the constructors from native-args or a
0197     /// plugin pointer.
0198     ///
0199     /// @warning Provided area definition pointer must be heap-allocated; Rivet will store/delete via a shared_ptr
0200     FastJets(const FinalState& fsp,
0201              JetAlg alg, double rparameter=-1,
0202              JetMuons usemuons=JetMuons::ALL,
0203              JetInvisibles useinvis=JetInvisibles::NONE,
0204              fastjet::AreaDefinition* adef=nullptr)
0205       : JetFinder(fsp, usemuons, useinvis),
0206         _adef(adef), _cuts(Cuts::OPEN)
0207     {
0208       _initBase();
0209       _initJdef(alg, rparameter);
0210     }
0211 
0212     /// @brief Convenience constructor using Cut argument and Rivet enums for most common jet algs (including some plugins).
0213     ///
0214     /// For the built-in algs, E-scheme recombination is used. For full control
0215     /// of FastJet built-in jet algs, use the constructors from native-args or a
0216     /// plugin pointer.
0217     ///
0218     /// @warning Provided area definition pointer must be heap-allocated; Rivet will store/delete via a shared_ptr
0219     FastJets(const FinalState& fsp,
0220              JetAlg alg, double rparameter,
0221              const Cut& c,
0222              JetMuons usemuons=JetMuons::ALL,
0223              JetInvisibles useinvis=JetInvisibles::NONE,
0224              fastjet::AreaDefinition* adef=nullptr)
0225       : JetFinder(fsp, usemuons, useinvis), _adef(adef), _cuts(c)
0226     {
0227       _initBase();
0228       _initJdef(alg, rparameter);
0229     }
0230 
0231 
0232 
0233     /// Clone on the heap.
0234     RIVET_DEFAULT_PROJ_CLONE(FastJets);
0235 
0236     /// @}
0237 
0238 
0239     /// Import to avoid warnings about overload-hiding
0240     using Projection::operator =;
0241 
0242 
0243     /// @name Static helper functions for FastJet interaction, with tagging
0244     /// @{
0245 
0246     /// Make a FastJet JetDefinition according to enum JetAlg
0247     static fastjet::JetDefinition mkJetDef(JetAlg alg, double rparameter);
0248 
0249     /// Make a shared pointer to a FastJet plugin according to enum JetAlg
0250     /// Templated version for setting arbitrary parameters
0251     template<JetAlg JETALG, typename... Args>
0252     static FJPluginPtr mkPlugin(Args&&... args){
0253       return std::make_shared<mapJetAlg2Plugin_t<JETALG>>(std::forward<Args>(args)...);
0254     }
0255 
0256     /// Non-templated version only allowing to set rparameter
0257     static FJPluginPtr mkPlugin(JetAlg alg, double rparameter=-1);
0258 
0259     /// Make PseudoJets for input to a ClusterSequence, with user_index codes for constituent- and tag-particle linking
0260     static PseudoJets mkClusterInputs(const Particles& fsparticles, const Particles& tagparticles=Particles());
0261     /// Make a Rivet Jet from a PseudoJet holding a user_index code for lookup of Rivet fsparticle or tagparticle links
0262     static Jet mkJet(const PseudoJet& pj, const Particles& fsparticles, const Particles& tagparticles=Particles());
0263     /// Convert a whole list of PseudoJets to a list of Jets, with mkJet-style unpacking
0264     static Jets mkJets(const PseudoJets& pjs, const Particles& fsparticles=Particles(), const Particles& tagparticles=Particles());
0265 
0266     /// @}
0267 
0268 
0269     /// @defgroup jetutils_recluster QoL operations for FastJet reclustering
0270     /// @{
0271 
0272     typedef std::pair<PseudoJets, Particles> PJetsParts;
0273 
0274     /// @brief Recluster Rivet::Jets @param jetsIn according to fastjet::JetDefinition @param jDef
0275     ///
0276     /// @return jet collection with FastJet jet algorithm applied
0277     ///
0278     /// @note forwards the particles and tags of the original jets to the reclustered jets,
0279     /// i.e. R=0.8 jets reclustered from R=0.4 jets will still have the particles/tags of the R=0.4 jets as constituents,
0280     /// not the R=0.4 jets themselves as constituents.
0281     /// This means that the number of constituents (omitting the filter) is preserved
0282     ///
0283     /// @note Returned jets are sorted by (descending) pT
0284     template <
0285       typename CONTAINER,
0286       typename = std::enable_if_t<
0287         is_citerable_v<CONTAINER>,
0288         Jet
0289       >
0290     >
0291     static CONTAINER reclusterJets(const CONTAINER &jetsIn, const fastjet::JetDefinition &jDef){
0292       PJetsParts reclusteredConsts = reclusterJetsParts(jetsIn, jDef);
0293       return mkTaggedJets(jetsIn, reclusteredConsts);
0294     }
0295 
0296     /// @brief Recluster Rivet::Jets @param jetsIn according to fastjet::JetDefinition @param jDef
0297     ///
0298     /// @return jet collection with FastJet jet algorithm applied
0299     ///
0300     /// @param filter a FastJet::Filter to be applied before re-assigning the tags
0301     /// Needed as separate function because FastJet doesn't grant us any easy initialisation check for filters
0302     ///
0303     /// @note Returned jets are sorted by (descending) pT
0304     template <
0305       typename CONTAINER,
0306       typename = std::enable_if_t<
0307         is_citerable_v<CONTAINER>,
0308         Jet
0309       >
0310     >
0311     static CONTAINER reclusterJets(const CONTAINER &jetsIn, const fastjet::JetDefinition &jDef, const fastjet::Filter &filter){
0312       PJetsParts reclusteredConsts = reclusterJetsParts(jetsIn, jDef);
0313       ifilterPseudoJets(reclusteredConsts.first, filter);
0314       return mkTaggedJets(jetsIn, reclusteredConsts);
0315     }
0316 
0317     /// @brief Apply the @param jetAlg (given as shared pointer to JetDefinition::Plugin) to the given @param jetsIn jet collection.
0318     ///
0319     /// @return jet collection with FastJet jet algorithm applied
0320     template <
0321       typename CONTAINER,
0322       typename = std::enable_if_t<
0323         is_citerable_v<CONTAINER>,
0324         Jet
0325       >
0326     >
0327     static CONTAINER reclusterJets(const CONTAINER &jetsIn, const FJPluginPtr &jetAlg){
0328       const fastjet::JetDefinition jDef(jetAlg.get());
0329       return reclusterJets(jetsIn, jDef);
0330     }
0331 
0332     /// @brief Apply the @param jetAlg (given as shared pointer to JetDefinition::Plugin) to the given @param jetsIn jet collection.
0333     ///
0334     /// @return jet collection with FastJet jet algorithm applied
0335     ///
0336     /// @param filter a FastJet::Filter to be applied before re-assigning the tags
0337     /// Needed as separate function because FastJet doesn't grant us any easy initialisation check for filters
0338     template <
0339       typename CONTAINER,
0340       typename = std::enable_if_t<
0341         is_citerable_v<CONTAINER>,
0342         Jet
0343       >
0344     >
0345     static CONTAINER reclusterJets(const CONTAINER &jetsIn, const FJPluginPtr &jetAlg, const fastjet::Filter &filter){
0346       const fastjet::JetDefinition jDef(jetAlg.get());
0347       return reclusterJets(jetsIn, jDef, filter);
0348     }
0349 
0350     /// @brief Apply the @param JETALG (given as an template-enum JetAlg and arbitrary @param args...) to the given @param jetsIn jet collection.
0351     ///
0352     /// @return jet collection with FastJet jet algorithm applied
0353     template <
0354       JetAlg JETALG, typename... Args, typename CONTAINER,
0355       typename = std::enable_if_t<
0356         is_citerable_v<CONTAINER>,
0357         Jet
0358       >
0359     >
0360     static CONTAINER reclusterJets(const CONTAINER &jetsIn, Args&&... args){
0361       if constexpr (JETALG<JetAlg::SISCONE){ // JetDefinition
0362         const fastjet::JetDefinition jDef = mkJetDef(JETALG, std::forward<Args>(args)...);
0363         return reclusterJets(jetsIn, jDef);
0364       } else { // Plugin
0365         const FJPluginPtr plugin = mkPlugin<JETALG>(std::forward<Args>(args)...);
0366         return reclusterJets(jetsIn, plugin);
0367       }
0368       throw std::invalid_argument( "Unknown jet algorithm: "+to_string(int(JETALG)) );
0369     }
0370 
0371     /// @brief Apply the @param JETALG (given as an template-enum JetAlg and arbitrary @param args...) to the given @param jetsIn jet collection.
0372     ///
0373     /// @return jet collection with FastJet jet algorithm applied
0374     ///
0375     /// @param filter a FastJet::Filter to be applied before re-assigning the tags
0376     /// Needed as separate function because FastJet doesn't grant us any easy initialisation check for filters
0377     template <
0378       JetAlg JETALG, typename... Args, typename CONTAINER,
0379       typename = std::enable_if_t<
0380         is_citerable_v<CONTAINER>,
0381         Jet
0382       >
0383     >
0384     static CONTAINER reclusterJets(const CONTAINER &jetsIn, const fastjet::Filter &filter, Args&&... args){
0385       if constexpr (JETALG<JetAlg::SISCONE){ // JetDefinition
0386         const fastjet::JetDefinition jDef = mkJetDef(JETALG, std::forward<Args>(args)...);
0387         return reclusterJets(jetsIn, jDef, filter);
0388       } else { // Plugin
0389         const FJPluginPtr plugin = mkPlugin<JETALG>(std::forward<Args>(args)...);
0390         return reclusterJets(jetsIn, plugin, filter);
0391       }
0392       throw std::invalid_argument( "Unknown jet algorithm: "+to_string(int(JETALG)) );
0393     }
0394 
0395     /// @brief Apply the @param args... to the given @param jetsMap map of jets.
0396     ///
0397     /// @return map of jets with FastJet jet algorithm applied
0398     template <typename T, typename U, typename... Args>
0399     static std::map<T, U> reclusterJets(const std::map<T, U> &jetsMap, Args&&... args){
0400       std::map<T, U> rtn;
0401       for ( auto const &[key, jetsIn] : jetsMap ) rtn[key] = reclusterJets(jetsIn, std::forward<Args>(args)...);
0402       return rtn;
0403     }
0404 
0405     /// @brief Apply the @param JETALG (given as an template-enum JetAlg and arbitrary @param args...) to the given @param jetsMap map of jets.
0406     ///
0407     /// @return map of jets with FastJet jet algorithm applied
0408     template <JetAlg JETALG, typename T, typename U, typename... Args>
0409     static std::map<T, U> reclusterJets(const std::map<T, U> &jetsMap, Args&&... args){
0410       std::map<T, U> rtn;
0411       for ( auto const &[key, jetsIn] : jetsMap ) rtn[key] = reclusterJets<JETALG>(jetsIn, std::forward<Args>(args)...);
0412       return rtn;
0413     }
0414 
0415     /// @}
0416 
0417 
0418     /// Reset the projection. Jet def, etc. are unchanged.
0419     void reset();
0420 
0421 
0422     /// @name Jet-area calculations
0423     /// @{
0424 
0425     /// @brief Use provided jet area definition
0426     ///
0427     /// @warning The provided pointer must be heap-allocated: it will be stored/deleted via a shared_ptr.
0428     /// @note Provide an adef null pointer to re-disable jet area calculation
0429     void useJetArea(fastjet::AreaDefinition* adef) {
0430       _adef.reset(adef);
0431     }
0432 
0433     /// Don't calculate a jet area
0434     void clearJetArea() {
0435       _adef.reset();
0436     }
0437 
0438     /// @}
0439 
0440 
0441     /// @name Jet grooming
0442     /// @{
0443 
0444     /// @brief Add a grooming transformer (base class of fastjet::Filter, etc.)
0445     ///
0446     /// @warning The provided pointer must be heap-allocated: it will be stored/deleted via a shared_ptr.
0447     /// @note Provide an adef null pointer to re-disable jet area calculation
0448     void addTrf(fastjet::Transformer* trf) {
0449       _trfs.push_back(shared_ptr<fastjet::Transformer>(trf));
0450     }
0451 
0452     /// @brief Add a list of grooming transformers
0453     ///
0454     /// @warning The provided pointers must be heap-allocated: they will be stored/deleted via a shared_ptr.
0455     /// @note Provide an adef null pointer to re-disable jet area calculation
0456     template<typename TRFS, typename TRF=typename TRFS::value_type>
0457     typename std::enable_if<Derefable<TRF>::value, void>::type
0458     addTrfs(const TRFS& trfs) {
0459       for (auto& trf : trfs) addTrf(trf);
0460     }
0461 
0462     /// @brief Add a grooming filter
0463     ///
0464     /// @note Technically just a more physics-oriented wrapper of addTrf()
0465     void addFilter(fastjet::Filter* filter) {
0466       addTrf(filter);
0467     }
0468 
0469     /// @brief Add a list of grooming filters
0470     ///
0471     /// @note Technically just a more physics-oriented wrapper of addTrfs()
0472     template<typename FILTERS, typename FILTER=typename FILTERS::value_type>
0473     typename std::enable_if<Derefable<FILTER>::value, void>::type
0474     addFilters(const FILTERS& filters) {
0475       addTrfs(filters);
0476     }
0477 
0478     /// Don't apply any jet transformers
0479     void clearTrfs() {
0480       _trfs.clear();
0481     }
0482 
0483     /// @}
0484 
0485 
0486     /// @name Access to the jets
0487     /// @{
0488 
0489     /// Get the jets (unordered) with pT > ptmin.
0490     Jets _jets() const;
0491 
0492     /// Get the pseudo jets (unordered).
0493     /// @deprecated Use pseudojets
0494     PseudoJets pseudojets(double ptmin=0.0) const;
0495 
0496     /// Get the pseudo jets, ordered by \f$ p_T \f$.
0497     PseudoJets pseudojetsByPt(double ptmin=0.0) const {
0498       return sorted_by_pt(pseudojets(ptmin));
0499     }
0500 
0501     /// Get the pseudo jets, ordered by \f$ E \f$.
0502     PseudoJets pseudojetsByE(double ptmin=0.0) const {
0503       return sorted_by_E(pseudojets(ptmin));
0504     }
0505 
0506     /// Get the pseudo jets, ordered by rapidity.
0507     PseudoJets pseudojetsByRapidity(double ptmin=0.0) const {
0508       return sorted_by_rapidity(pseudojets(ptmin));
0509     }
0510 
0511     /// @}
0512 
0513 
0514     /// @name Access to the FastJet clustering objects such as jet def, area def, and cluster
0515     /// @{
0516 
0517     /// Return the cluster sequence.
0518     /// @todo Care needed re. const shared_ptr<T> vs. shared_ptr<const T>
0519     const shared_ptr<fastjet::ClusterSequence> clusterSeq() const {
0520       return _cseq;
0521     }
0522 
0523     /// Return the area-enabled cluster sequence (if an area defn exists, otherwise returns a null ptr).
0524     /// @todo Care needed re. const shared_ptr<T> vs. shared_ptr<const T>
0525     const shared_ptr<fastjet::ClusterSequenceArea> clusterSeqArea() const {
0526       return areaDef() ? dynamic_pointer_cast<fastjet::ClusterSequenceArea>(_cseq) : nullptr;
0527     }
0528 
0529     /// Return the jet definition.
0530     const fastjet::JetDefinition& jetDef() const {
0531       return _jdef;
0532     }
0533 
0534     /// @brief Return the area definition.
0535     ///
0536     /// @warning May be null!
0537     /// @todo Care needed re. const shared_ptr<T> vs. shared_ptr<const T>
0538     const shared_ptr<fastjet::AreaDefinition> areaDef() const {
0539       return _adef;
0540     }
0541 
0542     /// @}
0543 
0544 
0545   protected:
0546 
0547     /// Shared utility functions to implement constructor behaviour
0548     void _initBase();
0549 
0550 
0551     void _initJdef(JetAlg alg, double rparameter){
0552       MSG_DEBUG("JetAlg = " << static_cast<int>(alg));
0553       MSG_DEBUG("R parameter = " << rparameter);
0554       if ( alg < JetAlg::SISCONE ){ // fastjet::JetDefinitions
0555         _jdef = mkJetDef(alg, rparameter);
0556       } else { // fastjet::JetDefinition::Plugins
0557         _plugin = mkPlugin(alg, rparameter);
0558         _jdef = fastjet::JetDefinition(_plugin.get());
0559       }
0560     }
0561 
0562     /// Aux function for reclustering
0563     static Jets mkTaggedJets(const Jets &jetsIn, const PJetsParts &pJetsParts);
0564 
0565     /// Aux function for reclustering
0566     static PJetsParts reclusterJetsParts(const Jets &jetsIn, const fastjet::JetDefinition &jDef);
0567 
0568   protected:
0569 
0570     /// Perform the projection on the Event.
0571     void project(const Event& e);
0572 
0573     /// Compare projections.
0574     CmpState compare(const Projection& p) const;
0575 
0576   public:
0577 
0578     /// Do the calculation locally (no caching).
0579     void calc(const Particles& fsparticles, const Particles& tagparticles=Particles());
0580 
0581 
0582   protected:
0583 
0584     /// Jet definition
0585     fastjet::JetDefinition _jdef;
0586 
0587     /// Pointer to user-handled area definition
0588     std::shared_ptr<fastjet::AreaDefinition> _adef;
0589 
0590     /// Cluster sequence
0591     std::shared_ptr<fastjet::ClusterSequence> _cseq;
0592 
0593     /// The kinematic cuts
0594     Cut _cuts;
0595 
0596     /// FastJet external plugin
0597     FJPluginPtr _plugin;
0598 
0599     /// List of jet groomers to be applied
0600     std::vector< std::shared_ptr<fastjet::Transformer> > _trfs;
0601 
0602     /// Map of Rivet::JetAlg to targeted fastjet::JetAlgorithm and fastjet::RecombinationScheme
0603     static const std::map<JetAlg, std::pair<fastjet::JetAlgorithm, fastjet::RecombinationScheme>> jetAlgMap;
0604 
0605     /// "Map" of Rivet::JetAlg to targeted fastjet::JetDefinition::Plugin
0606     /// Use dummy X so we can specialise mapJetAlg2Plugin in header
0607     template<JetAlg, typename X> struct mapJetAlg2Plugin;
0608 
0609     /// populate "map"
0610     template<typename X> struct mapJetAlg2Plugin<JetAlg::SISCONE,     X>{ using type = fastjet::SISConePlugin; };
0611     template<typename X> struct mapJetAlg2Plugin<JetAlg::PXCONE,      X>{ using type = Rivet::PxConePlugin; };
0612     template<typename X> struct mapJetAlg2Plugin<JetAlg::CDFJETCLU,   X>{ using type = fastjet::CDFJetCluPlugin; };
0613     template<typename X> struct mapJetAlg2Plugin<JetAlg::CDFMIDPOINT, X>{ using type = fastjet::CDFMidPointPlugin; };
0614     template<typename X> struct mapJetAlg2Plugin<JetAlg::D0ILCONE,    X>{ using type = fastjet::D0RunIIConePlugin; };
0615     template<typename X> struct mapJetAlg2Plugin<JetAlg::JADE,        X>{ using type = fastjet::JadePlugin; };
0616     template<typename X> struct mapJetAlg2Plugin<JetAlg::TRACKJET,    X>{ using type = fastjet::TrackJetPlugin; };
0617     template<typename X> struct mapJetAlg2Plugin<JetAlg::VARIABLER,   X>{ using type = fastjet::contrib::VariableRPlugin; };
0618 
0619     /// Make usage of "map" a bit more convenient
0620     template<JetAlg JETALG>
0621     using mapJetAlg2Plugin_t = typename mapJetAlg2Plugin<JETALG, void>::type;
0622 
0623     /// Map of vectors of y scales. This is mutable so we can use caching/lazy evaluation.
0624     mutable std::map<int, vector<double> > _yscales;
0625 
0626     /// Particles used for constituent and tag lookup
0627     Particles _fsparticles, _tagparticles;
0628 
0629   };
0630 
0631 }
0632 
0633 #endif