Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:16

0001 #ifndef __FASTJET_TOOLS_RECLUSTER_HH__
0002 #define __FASTJET_TOOLS_RECLUSTER_HH__
0003 
0004 // $Id$
0005 //
0006 // Copyright (c) 2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
0007 //
0008 //----------------------------------------------------------------------
0009 // This file is part of FastJet
0010 //
0011 // It is free software; you can redistribute it and/or modify it under
0012 // the terms of the GNU General Public License as published by the
0013 // Free Software Foundation; either version 2 of the License, or (at
0014 // your option) any later version.
0015 //
0016 // It is distributed in the hope that it will be useful, but WITHOUT
0017 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
0018 // or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
0019 // License for more details.
0020 //
0021 // You should have received a copy of the GNU General Public License
0022 // along with this code. If not, see <http://www.gnu.org/licenses/>.
0023 //----------------------------------------------------------------------
0024 
0025 #include "fastjet/JetDefinition.hh"
0026 #include "fastjet/FunctionOfPseudoJet.hh"   // to derive Recluster from FOfPJ<PJ>
0027 #include <iostream>
0028 #include <string>
0029 
0030 // TODO:
0031 //
0032 //  - maintain Voronoi areas? Requires CSAB:has_voronoi_area()    {->UNASSIGNED}
0033 //  - make sure the description of the class is OK
0034 
0035 
0036 
0037 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
0038 
0039 //----------------------------------------------------------------------
0040 /// @ingroup tools_generic
0041 /// \class Recluster
0042 /// Recluster a jet's constituents with a new jet definition.
0043 ///
0044 /// When Recluster is constructed from a JetDefinition, it is that
0045 /// definition that will be used to obtain the new jets. The user may
0046 /// then decide if the recombiner should be the one from that jet
0047 /// definition or if it should be acquired from the jet being
0048 /// processed (the default).
0049 ///
0050 /// Alternatively, Recluster can be constructed from a jet algorithm
0051 /// and an optional radius. In that case the recombiner is
0052 /// systematically obtained from the jet being processed (unless you
0053 /// call set_acquire_recombiner(false)). If only the jet algorithm is
0054 /// specified, a default radius of max_allowable_R will be assumed if
0055 /// needed.
0056 ///
0057 /// Recluster has two possible behaviours:
0058 ///
0059 ///  - if it is constructed with keep=keep_only_hardest the hardest
0060 ///    inclusive jet is returned as a "standard" jet with an
0061 ///    associated cluster sequence (unless there were no inclusive
0062 ///    jets, in which case a zero jet is returned, with no associated
0063 ///    cluster sequence)
0064 ///
0065 ///  - if it is constructed with keep=keep_all
0066 ///    all the inclusive jets are joined into a composite jet
0067 ///
0068 /// [Note that since the structure of the resulting PseudoJet depends
0069 /// on its usage, this class inherits from
0070 /// FunctionOfPseudoJet<PseudoJet> (including a description) rather
0071 /// than being a full-fledged Transformer]
0072 ///
0073 class Recluster : public FunctionOfPseudoJet<PseudoJet> {
0074 public:
0075   /// the various options for the output of Recluster
0076   enum Keep{
0077     /// keep only the hardest inclusive jet and return a "standard" jet with
0078     /// an associated ClusterSequence [this will be the default]
0079     keep_only_hardest,
0080     /// keep all the inclusive jets. result() will join them into a composite
0081     /// jet
0082     keep_all
0083   };
0084 
0085   /// default constructor (uses an undefined JetDefinition, and so cannot
0086   /// be used directly).
0087   Recluster() : _new_jet_def(), _acquire_recombiner(true),
0088                 _keep(keep_only_hardest), _cambridge_optimisation_enabled(true){}
0089 
0090   /// Constructs a Recluster object that reclusters a jet into a new jet
0091   /// using a generic JetDefinition
0092   ///
0093   ///  \param new_jet_def   the jet definition applied to do the reclustering
0094   ///  \param acquire_recombiner
0095   ///                       when true, the reclustering will guess the
0096   ///                       recombiner from the input jet instead of
0097   ///                       the one in new_jet_def. An error is then
0098   ///                       thrown if no consistent recombiner is found
0099   ///  \param keep_in       Recluster::keep_only_hardest: the result is
0100   ///                       the hardest inclusive jet after reclustering,
0101   ///                       returned as a "standard" jet.
0102   ///                       Recluster::keep_all: the result is a
0103   ///                       composite jet with the inclusive jets as pieces.
0104   Recluster(const JetDefinition & new_jet_def, 
0105             bool acquire_recombiner_in = false, 
0106             Keep keep_in = keep_only_hardest)
0107     : _new_jet_def(new_jet_def), _acquire_recombiner(acquire_recombiner_in), 
0108       _keep(keep_in), _cambridge_optimisation_enabled(true) {}
0109 
0110   /// Constructs a Recluster object that reclusters a jet into a new jet
0111   /// using a JetAlgorithm and its parameters
0112   ///
0113   ///  \param new_jet_alg    the jet algorithm applied to obtain the new clustering
0114   ///  \param new_jet_radius the jet radius
0115   ///  \param keep_in        Recluster::keep_only_hardest: the result is
0116   ///                        the hardest inclusive jet after reclustering,
0117   ///                        returned as a "standard" jet.
0118   ///                        Recluster::keep_all: the result is a
0119   ///                        composite jet with the inclusive jets as pieces.
0120   /// 
0121   /// This ctor will always acquire the recombiner from the jet being
0122   /// reclustered (it will throw if none can be found).  If you wish
0123   /// to use Recluster with an algorithm that requires an extra
0124   /// parameter (like the genkt algorithm), please specify the jet
0125   /// definition fully using the constructor above.
0126   Recluster(JetAlgorithm new_jet_alg, double new_jet_radius, Keep keep_in = keep_only_hardest);
0127 
0128   /// constructor with just a jet algorithm, but no jet radius. If the
0129   /// algorithm requires a jet radius, JetDefinition::max_allowable_R will be used. 
0130   ///
0131   Recluster(JetAlgorithm new_jet_alg, Keep keep_in = keep_only_hardest);
0132 
0133   /// default dtor
0134   virtual ~Recluster(){}
0135 
0136   //----------------------------------------------------------------------
0137   // tweaking the behaviour and corresponding enquiry functions
0138 
0139   /// set whether the reclustering should attempt to acquire a
0140   /// recombiner from the input jet
0141   void set_acquire_recombiner(bool acquire) {_acquire_recombiner = acquire;}
0142 
0143   /// returns true if this reclusterer is set to acquire the
0144   /// recombiner from the input jet
0145   bool acquire_recombiner() const{ return _acquire_recombiner;}
0146 
0147 
0148   /// sets whether to try to optimise reclustering with
0149   /// Cambridge/Aachen algorithms (by not reclustering if the
0150   /// requested C/A reclustering can be obtained by using subjets of
0151   /// an input C/A jet or one composed of multiple C/A pieces from the
0152   /// same clustering sequence). By default this is enabled, and
0153   /// _should_ always be correct; disable it to test this statement!
0154   void set_cambridge_optimisation(bool enabled){ _cambridge_optimisation_enabled = enabled;}
0155   /// sets whether to try to optimise reclustering with Cambridge/Aachen algorithms (US spelling!)
0156   void set_cambridge_optimization(bool enabled){ _cambridge_optimisation_enabled = enabled;}
0157 
0158   /// returns true if the reclusterer tries to optimise reclustering
0159   /// with Cambridge/Aachen algorithms
0160   bool cambridge_optimization(){return _cambridge_optimisation_enabled;}
0161   bool cambridge_optimisation(){return _cambridge_optimisation_enabled;}
0162 
0163   /// set the behaviour with regards to keeping all resulting jets or
0164   /// just the hardest.
0165   void set_keep(Keep keep_in) {_keep = keep_in;}
0166 
0167   /// returns the current "keep" mode i.e. whether only the hardest
0168   /// inclusive jet is returned or all of them (see the Keep enum above)
0169   Keep keep() const{ return _keep;}
0170 
0171 
0172   //----------------------------------------------------------------------
0173   // retrieving info about the behaviour
0174 
0175   /// class description
0176   virtual std::string description() const;
0177 
0178 
0179   //----------------------------------------------------------------------
0180   // core action of ths class
0181 
0182   /// runs the reclustering and sets kept and rejected to be the jets
0183   /// of interest (with non-zero rho, they will have been
0184   /// subtracted). Normally this will be accessed through the base
0185   /// class's operator().
0186   ///
0187   /// \param jet    the jet that gets reclustered
0188   /// \return the reclustered jet
0189   virtual PseudoJet result(const PseudoJet & jet) const;
0190 
0191   /// A lower-level method that does the actual work of reclustering
0192   /// the input jet. The resulting jets are stored in output_jets.
0193   /// The jet definition that has been used can be accessed from the
0194   /// output_jets' ClusterSequence.
0195   ///
0196   /// \param input_jet       the (input) jet that one wants to recluster
0197   /// \param output_jets     inclusive jets resulting from the new clustering
0198   ///
0199   /// Returns true if the C/A optimisation has been used (this means
0200   /// that generate_output_jet then has to watch out for non-explicit-ghost
0201   /// areas that might be leftover)
0202   bool get_new_jets_and_def(const PseudoJet & input_jet, 
0203                             std::vector<PseudoJet> & output_jets) const;
0204 
0205   /// given a set of inclusive jets and a jet definition used, create the
0206   /// resulting PseudoJet;
0207   /// 
0208   /// If ca_optimisation_used then special care will be taken in
0209   /// deciding whether the final jet can legitimately have an area.
0210   PseudoJet generate_output_jet(std::vector<PseudoJet> & incljets,
0211                                 bool ca_optimisation_used) const;
0212 
0213 
0214 private:
0215   /// set the reclustered elements in the simple case of C/A+C/A
0216   void _recluster_ca(const std::vector<PseudoJet> & all_pieces,
0217                      std::vector<PseudoJet> & incljets,
0218                      double Rfilt) const;
0219 
0220   /// set the reclustered elements in the generic re-clustering case
0221   void _recluster_generic(const PseudoJet & jet, 
0222                           std::vector<PseudoJet> & incljets,
0223                           const JetDefinition & new_jet_def,
0224                           bool do_areas) const;
0225   
0226   // a series of checks
0227   //--------------------------------------------------------------------
0228   /// get the pieces down to the fundamental pieces
0229   bool _get_all_pieces(const PseudoJet &jet, std::vector<PseudoJet> &all_pieces) const;
0230 
0231   /// associate the proper recombiner taken from the underlying pieces
0232   /// (an error is thrown if the pieces do no share a common
0233   /// recombiner)
0234   void _acquire_recombiner_from_pieces(const std::vector<PseudoJet> &all_pieces, 
0235                                        JetDefinition &new_jet_def) const;
0236 
0237   /// check if one can apply the simplified trick for C/A subjets
0238   bool _check_ca(const std::vector<PseudoJet> &all_pieces, 
0239                  const JetDefinition &new_jet_def) const;
0240 
0241   /// check if the jet (or all its pieces) have explicit ghosts
0242   /// (assuming the jet has area support
0243   ///
0244   /// Note that if the jet has an associated cluster sequence that is no
0245   /// longer valid, an error will be thrown
0246   bool _check_explicit_ghosts(const std::vector<PseudoJet> &all_pieces) const;
0247 
0248   JetDefinition _new_jet_def;  ///< the jet definition to use to extract the jets
0249   bool _acquire_recombiner;    ///< get the recombiner from the input
0250                                ///< jet rather than from _new_jet_def
0251   Keep _keep;                  ///< dictates which inclusive jets are kept and
0252                                ///< which are returned (see Keep above)
0253 
0254   bool _cambridge_optimisation_enabled; ///<enable the checks to
0255                                         ///< perform optimisation when
0256                                         ///< C/A reclustering is asked
0257 
0258   static LimitedWarning   _explicit_ghost_warning;
0259 };
0260 
0261 FASTJET_END_NAMESPACE      // defined in fastjet/internal/base.hh
0262 
0263 #endif   // __FASTJET_TOOLS_RECLUSTER_HH__