Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef __FASTJET_TOOLS_FILTER_HH__
0002 #define __FASTJET_TOOLS_FILTER_HH__
0003 
0004 //FJSTARTHEADER
0005 // $Id$
0006 //
0007 // Copyright (c) 2005-2021, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
0008 //
0009 //----------------------------------------------------------------------
0010 // This file is part of FastJet.
0011 //
0012 //  FastJet is free software; you can redistribute it and/or modify
0013 //  it under the terms of the GNU General Public License as published by
0014 //  the Free Software Foundation; either version 2 of the License, or
0015 //  (at your option) any later version.
0016 //
0017 //  The algorithms that underlie FastJet have required considerable
0018 //  development. They are described in the original FastJet paper,
0019 //  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
0020 //  FastJet as part of work towards a scientific publication, please
0021 //  quote the version you use and include a citation to the manual and
0022 //  optionally also to hep-ph/0512210.
0023 //
0024 //  FastJet is distributed in the hope that it will be useful,
0025 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
0026 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0027 //  GNU General Public License for more details.
0028 //
0029 //  You should have received a copy of the GNU General Public License
0030 //  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
0031 //----------------------------------------------------------------------
0032 //FJENDHEADER
0033 
0034 #include "fastjet/ClusterSequence.hh"
0035 #include "fastjet/Selector.hh"
0036 #include "fastjet/CompositeJetStructure.hh" // to derive the FilterStructure from CompositeJetStructure
0037 #include "fastjet/tools/Transformer.hh"     // to derive Filter from Transformer
0038 #include <iostream>
0039 #include <string>
0040 
0041 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
0042 
0043 // fwd declarations
0044 class Filter;
0045 class FilterStructure;
0046 
0047 //----------------------------------------------------------------------
0048 /// @ingroup tools_generic
0049 /// \class Filter
0050 /// Class that helps perform filtering (Butterworth, Davison, Rubin
0051 /// and Salam, arXiv:0802.2470) and trimming (Krohn, Thaler and Wang,
0052 /// arXiv:0912.1342) on jets, optionally in conjunction with
0053 /// subtraction (Cacciari and Salam, arXiv:0707.1378).
0054 ///
0055 /// For example, to apply filtering that reclusters a jet's
0056 /// constituents with the Cambridge/Aachen jet algorithm with R=0.3
0057 /// and then selects the 3 hardest subjets, one can use the following
0058 /// code:
0059 /// \code
0060 ///    Filter filter(JetDefinition(cambridge_algorithm, 0.3), SelectorNHardest(3));
0061 ///    PseudoJet filtered_jet = filter(original_jet);
0062 /// \endcode
0063 ///
0064 /// To obtain trimming, involving for example the selection of all
0065 /// subjets carrying at least 3% of the original jet's pt, the
0066 /// selector would be replaced by SelectorPtFractionMin(0.03).
0067 ///
0068 /// To additionally perform subtraction on the subjets prior to
0069 /// selection, either include a 3rd argument specifying the background
0070 /// density rho, or call the set_subtractor(...) member function.  If
0071 /// subtraction is requested, the original jet must be the result of a
0072 /// clustering with active area with explicit ghosts support or a
0073 /// merging of such pieces.
0074 ///
0075 /// The information on the subjets that were kept and rejected can be
0076 /// obtained using:
0077 /// \code
0078 ///    vector<PseudoJet> kept_subjets = filtered_jet.pieces();
0079 ///    vector<PseudoJet> rejected_subjets = filtered_jet.structure_of<Filter>().rejected();
0080 /// \endcode
0081 ///
0082 /// \section impl Implementation Note
0083 /// 
0084 /// If the original jet was defined with the Cambridge/Aachen
0085 /// algorithm (or is made of pieces each of which comes from the C/A
0086 /// alg) and the filtering definition is C/A, then the filter does not
0087 /// rerun the C/A algorithm on the constituents, but instead makes use
0088 /// of the existent C/A cluster sequence in the original jet. This
0089 /// increases the speed of the filter. 
0090 ///
0091 /// See also \subpage Example11 for a further usage example.
0092 ///
0093 /// Support for areas, reuse of C/A cluster sequences, etc.,
0094 /// considerably complicates the implementation of Filter. For an
0095 /// explanation of how a simpler filter might be coded, see the
0096 /// "User-defined transformers" appendix of the manual.
0097 class Filter : public Transformer{
0098 public:
0099   /// trivial ctor
0100   /// Note: this is just for derived classes
0101   ///       a Filter initialised through this constructor will not work!
0102   Filter() : _Rfiltfunc(0), _initialised(false){};
0103 
0104   /// define a filter that decomposes a jet into subjets using a
0105   /// generic JetDefinition and then keeps only a subset of these
0106   /// subjets according to a Selector. Optionally, each subjet may be
0107   /// internally bakground-subtracted prior to selection.
0108   ///
0109   ///  \param subjet_def   the jet definition applied to obtain the subjets
0110   ///  \param selector     the Selector applied to compute the kept subjets
0111   ///  \param rho          if non-zero, backgruond-subtract each subjet befor selection
0112   ///
0113   /// Note: internal subtraction only applies on jets that are
0114   /// obtained with a cluster sequence with area support and explicit
0115   /// ghosts
0116   Filter(JetDefinition subjet_def, Selector selector, double rho = 0.0) : 
0117     _subjet_def(subjet_def), _Rfiltfunc(0), _Rfilt(-1), _selector(selector), _rho(rho), _subtractor(0), _initialised(true) {}
0118 
0119   /// Same as the full constructor (see above) but just specifying the radius
0120   /// By default, Cambridge-Aachen is used
0121   /// If the jet (or all its pieces) is obtained with a non-default
0122   /// recombiner, that one will be used
0123   ///  \param Rfilt   the filtering radius
0124   Filter(double Rfilt, Selector selector, double rho = 0.0) : 
0125     _Rfiltfunc(0), _Rfilt(Rfilt), _selector(selector), _rho(rho), _subtractor(0), _initialised(true) { 
0126     if (_Rfilt<0)
0127       throw Error("Attempt to create a Filter with a negative filtering radius");
0128   }
0129 
0130   /// Same as the full constructor (see above) but just specifying a
0131   /// filtering radius that will depend on the jet being filtered
0132   /// As for the previous case, Cambridge-Aachen is used
0133   /// If the jet (or all its pieces) is obtained with a non-default
0134   /// recombiner, that one will be used
0135   ///  \param Rfilt_func   the filtering radius function of a PseudoJet
0136   Filter(FunctionOfPseudoJet<double> *Rfilt_func, Selector selector, double rho = 0.0) : 
0137     _Rfiltfunc(Rfilt_func), _Rfilt(-1), _selector(selector), _rho(rho), _subtractor(0), _initialised(true) {}
0138 
0139   /// default dtor
0140   virtual ~Filter(){};
0141 
0142   /// Set a subtractor that is applied to all individual subjets before
0143   /// deciding which ones to keep. It takes precedence over a non-zero rho.
0144   void set_subtractor(const FunctionOfPseudoJet<PseudoJet> * subtractor_in) {_subtractor = subtractor_in;}
0145 
0146   /// Set a subtractor that is applied to all individual subjets before
0147   /// deciding which ones to keep. It takes precedence over a non-zero rho.
0148   const FunctionOfPseudoJet<PseudoJet> * subtractor() const{ return _subtractor;}
0149 
0150   /// runs the filtering and sets kept and rejected to be the jets of interest
0151   /// (with non-zero rho, they will have been subtracted).
0152   ///
0153   /// \param jet    the jet that gets filtered
0154   /// \return the filtered jet
0155   virtual PseudoJet result(const PseudoJet & jet) const;
0156 
0157   /// class description
0158   virtual std::string description() const;
0159 
0160   // the type of the associated structure
0161   typedef FilterStructure StructureType;
0162 
0163 private:
0164   /// Sets filtered_elements to be all the subjets on which filtering will work.
0165   /// It also sets the subjet_def to be used in joining things (the bit of
0166   /// subjet def that is of interest for later is the recombiner).
0167   ///
0168   /// this returns true if teh optimisation trick for C/A reclustering has been used
0169   bool _set_filtered_elements(const PseudoJet & jet,
0170                               std::vector<PseudoJet> & filtered_elements) const;
0171   
0172   /// gather the information about what is kept and rejected under the
0173   /// form of a PseudoJet with a special ClusterSequenceInfo
0174   ///
0175   /// The last argument (ca_optimisation_used) should be true if the
0176   /// optimisation trick for C/A reclustering has been used (in which
0177   /// case some extra tests have to be run for non-explicit-ghost
0178   /// areas)
0179   PseudoJet _finalise(const PseudoJet & jet, 
0180                       std::vector<PseudoJet> & kept, 
0181                       std::vector<PseudoJet> & rejected,
0182               bool ca_optimisation_used) const;
0183 
0184   bool _uses_subtraction() const {return (_subtractor || _rho != 0);}
0185 
0186   JetDefinition _subjet_def;   ///< the jet definition to use to extract the subjets
0187   FunctionOfPseudoJet<double> *_Rfiltfunc; 
0188                                ///< a dynamic filtering radius function of the jet being filtered
0189   double _Rfilt;               ///< a constant specifying the subjet radius (with C/A)
0190   Selector _selector;  ///< the subjet selection criterium
0191   double _rho;                 ///< the background density (used for subtraction when possible)
0192   const FunctionOfPseudoJet<PseudoJet> * _subtractor; ///< for subtracting bkgd density from subjets
0193 
0194   bool _initialised;    ///< true when the Filter has been properly intialised
0195 };
0196 
0197 
0198 
0199 //----------------------------------------------------------------------
0200 /// @ingroup tools_generic
0201 /// \class FilterStructure
0202 /// Class to contain structure information for a filtered jet.
0203 class FilterStructure : public CompositeJetStructure {
0204 public:
0205   /// constructor from an original ClusterSequenceInfo
0206   /// We just share the original ClusterSequenceWrapper and initialise
0207   /// the rest
0208   FilterStructure(const std::vector<PseudoJet> & pieces_in, 
0209                   const JetDefinition::Recombiner *rec = 0)
0210     : CompositeJetStructure(pieces_in, rec){}
0211 
0212   /// virtual dtor to allow further overloading  
0213   virtual ~FilterStructure(){}
0214 
0215   /// description
0216   virtual std::string description() const { return "Filtered PseudoJet"; }
0217 
0218   //------------------------------------------------------------------
0219   /// @name The filter-specific information
0220   //------------------------------------------------------------------
0221 
0222 //  /// returns the original jet (the first of the original jets
0223 //  /// if you filtered a collection of jets)
0224 //  const PseudoJet & original() const {return _original_jet;}
0225 
0226   /// returns the subjets that were not kept during the filtering procedure
0227   /// (subtracted if the filter requests it, and valid in the original cs)
0228   const std::vector<PseudoJet> & rejected() const {return _rejected;}
0229 
0230   friend class Filter;  // allow the filter to change the protected/private members
0231 
0232 protected:
0233 //  PseudoJet _original_jet;           ///< the original jet
0234   std::vector<PseudoJet> _rejected;  ///< the subjets rejected by the filter
0235 };
0236 
0237 
0238 FASTJET_END_NAMESPACE      // defined in fastjet/internal/base.hh
0239 
0240 #endif   // __FASTJET_TOOLS_FILTER_HH__