JetDefinition.hh

00001 //STARTHEADER
00002 // $Id: JetDefinition.hh 1850 2011-01-25 19:33:24Z soyez $
00003 //
00004 // Copyright (c) 2005-2006, Matteo Cacciari and Gavin Salam
00005 //
00006 //----------------------------------------------------------------------
00007 // This file is part of FastJet.
00008 //
00009 //  FastJet is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU General Public License as published by
00011 //  the Free Software Foundation; either version 2 of the License, or
00012 //  (at your option) any later version.
00013 //
00014 //  The algorithms that underlie FastJet have required considerable
00015 //  development and are described in hep-ph/0512210. If you use
00016 //  FastJet as part of work towards a scientific publication, please
00017 //  include a citation to the FastJet paper.
00018 //
00019 //  FastJet is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU General Public License
00025 //  along with FastJet; if not, write to the Free Software
00026 //  Foundation, Inc.:
00027 //      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //----------------------------------------------------------------------
00029 //ENDHEADER
00030 
00031 #ifndef __FASTJET_JETDEFINITION_HH__
00032 #define __FASTJET_JETDEFINITION_HH__
00033 
00034 #include<cassert>
00035 #include "fastjet/internal/numconsts.hh"
00036 #include "fastjet/PseudoJet.hh"
00037 #include<string>
00038 #include<memory>
00039 
00040 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00041 
00042 /// return a string containing information about the release
00043 //  NB: (implemented in ClusterSequence.cc but defined here because
00044 //  this is a visible location)
00045 std::string fastjet_version_string();
00046 
00047 //======================================================================
00048 /// the various options for the algorithmic strategy to adopt in
00049 /// clustering events with kt and cambridge style algorithms.
00050 enum Strategy {
00051   /// fastest form about 500..10^4
00052   N2MinHeapTiled   = -4, 
00053   /// fastest from about 50..500
00054   N2Tiled     = -3, 
00055   /// legacy
00056   N2PoorTiled = -2, 
00057   /// fastest below 50
00058   N2Plain     = -1, 
00059   /// worse even than the usual N^3 algorithms
00060   N3Dumb      =  0, 
00061   /// automatic selection of the best (based on N)
00062   Best        =  1, 
00063   /// best of the NlnN variants -- best overall for N>10^4.
00064   /// (Does not work for R>=2pi)
00065   NlnN        =  2, 
00066   /// legacy N ln N using 3pi coverage of cylinder.
00067   /// (Does not work for R>=2pi)
00068   NlnN3pi     =  3, 
00069   /// legacy N ln N using 4pi coverage of cylinder
00070   NlnN4pi     =  4,
00071   /// Chan's closest pair method (in a variant with 4pi coverage),
00072   /// for use exclusively with the Cambridge algorithm.
00073   /// (Does not work for R>=2pi)
00074   NlnNCam4pi   = 14,
00075   /// Chan's closest pair method (in a variant with 2pi+2R coverage),
00076   /// for use exclusively with the Cambridge algorithm.
00077   /// (Does not work for R>=2pi)
00078   NlnNCam2pi2R = 13,
00079   /// Chan's closest pair method (in a variant with 2pi+minimal extra
00080   /// variant), for use exclusively with the Cambridge algorithm. 
00081   /// (Does not work for R>=2pi)
00082   NlnNCam      = 12, // 2piMultD
00083   /// the plugin has been used...
00084   plugin_strategy = 999
00085 };
00086 
00087 
00088 //======================================================================
00089 /// \enum JetAlgorithm
00090 /// the various families of jet-clustering algorithm
00091 enum JetAlgorithm {
00092   /// the longitudinally invariant kt algorithm
00093   kt_algorithm=0,
00094   /// the longitudinally invariant variant of the cambridge algorithm
00095   /// (aka Aachen algoithm).
00096   cambridge_algorithm=1,
00097   /// like the k_t but with distance measures 
00098   ///       dij = min(1/kti^2,1/ktj^2) Delta R_{ij}^2 / R^2
00099   ///       diB = 1/kti^2
00100   antikt_algorithm=2, 
00101   /// like the k_t but with distance measures 
00102   ///       dij = min(kti^{2p},ktj^{2p}) Delta R_{ij}^2 / R^2
00103   ///       diB = 1/kti^{2p}
00104   /// where p = extra_param()
00105   genkt_algorithm=3, 
00106   /// a version of cambridge with a special distance measure for particles
00107   /// whose pt is < extra_param()
00108   cambridge_for_passive_algorithm=11,
00109   /// a version of genkt with a special distance measure for particles
00110   /// whose pt is < extra_param() [relevant for passive areas when p<=0]
00111   genkt_for_passive_algorithm=13, 
00112   //.................................................................
00113   /// the e+e- kt algorithm
00114   ee_kt_algorithm=50,
00115   /// the e+e- genkt algorithm  (R > 2 and p=1 gives ee_kt)
00116   ee_genkt_algorithm=53,
00117   //.................................................................
00118   /// any plugin algorithm supplied by the user
00119   plugin_algorithm = 99
00120 };
00121 
00122 /// make standard Les Houches nomenclature JetAlgorithm (algorithm is general
00123 /// recipe without the parameters) backward-compatible with old JetFinder
00124 typedef JetAlgorithm JetFinder;
00125 
00126 /// provide other possible names for the Cambridge/Aachen algorithm?
00127 const JetAlgorithm aachen_algorithm = cambridge_algorithm;
00128 const JetAlgorithm cambridge_aachen_algorithm = cambridge_algorithm;
00129 
00130 //======================================================================
00131 /// the various recombination schemes
00132 enum RecombinationScheme {
00133   /// summing the 4-momenta
00134   E_scheme=0,
00135   /// pt weighted recombination of y,phi (and summing of pt's)
00136   /// with preprocessing to make things massless by rescaling E=|\vec p|
00137   pt_scheme=1,
00138   /// pt^2 weighted recombination of y,phi (and summing of pt's)
00139   /// with preprocessing to make things massless by rescaling E=|\vec p|
00140   pt2_scheme=2,
00141   /// pt weighted recombination of y,phi (and summing of pt's)
00142   /// with preprocessing to make things massless by rescaling |\vec p|->=E
00143   Et_scheme=3,
00144   /// pt^2 weighted recombination of y,phi (and summing of pt's)
00145   /// with preprocessing to make things massless by rescaling |\vec p|->=E
00146   Et2_scheme=4,
00147   /// pt weighted recombination of y,phi (and summing of pt's), with 
00148   /// no preprocessing
00149   BIpt_scheme=5,
00150   /// pt^2 weighted recombination of y,phi (and summing of pt's)
00151   /// no preprocessing
00152   BIpt2_scheme=6,
00153   /// for the user's external scheme
00154   external_scheme = 99
00155 };
00156 
00157 
00158 
00159 
00160 // forward declaration, needed in order to specify interface for the
00161 // plugin.
00162 class ClusterSequence;
00163 
00164 
00165 
00166 
00167 //======================================================================
00168 /// @ingroup basic_classes
00169 /// \class JetDefinition
00170 /// class that is intended to hold a full definition of the jet
00171 /// clusterer
00172 class JetDefinition {
00173   
00174 public:
00175 
00176   /// forward declaration of a class that allows the user to introduce
00177   /// their own plugin 
00178   class Plugin;
00179 
00180   // forward declaration of a class that will provide the
00181   // recombination scheme facilities and/or allow a user to
00182   // extend these facilities
00183   class Recombiner;
00184 
00185   
00186 
00187   /// constructor with alternative ordering or arguments -- note that
00188   /// we have not provided a default jet finder, to avoid ambiguous
00189   /// JetDefinition() constructor.
00190   JetDefinition(JetAlgorithm jet_algorithm, 
00191                 double R, 
00192                 RecombinationScheme recomb_scheme = E_scheme,
00193                 Strategy strategy = Best) {
00194     *this = JetDefinition(jet_algorithm, R, strategy, recomb_scheme, 1);
00195   }
00196 
00197   /// constructor for algorithms that have no free parameters
00198   /// (e.g. ee_kt_algorithm)
00199   JetDefinition(JetAlgorithm jet_algorithm, 
00200                 RecombinationScheme recomb_scheme = E_scheme,
00201                 Strategy strategy = Best) {
00202     double dummyR = 0.0;
00203     *this = JetDefinition(jet_algorithm, dummyR, strategy, recomb_scheme, 0);
00204   }
00205 
00206   /// constructor for algorithms that require R + one extra parameter to be set 
00207   /// (the gen-kt series for example)
00208   JetDefinition(JetAlgorithm jet_algorithm, 
00209                 double R, 
00210                 double xtra_param,
00211                 RecombinationScheme recomb_scheme = E_scheme,
00212                 Strategy strategy = Best) {
00213     *this = JetDefinition(jet_algorithm, R, strategy, recomb_scheme, 2);
00214     set_extra_param(xtra_param);
00215   }
00216 
00217 
00218   /// constructor in a form that allows the user to provide a pointer
00219   /// to an external recombiner class (which must remain valid for the
00220   /// life of the JetDefinition object).
00221   JetDefinition(JetAlgorithm jet_algorithm, 
00222                 double R, 
00223                 const Recombiner * recombiner,
00224                 Strategy strategy = Best) {
00225     *this = JetDefinition(jet_algorithm, R, external_scheme, strategy);
00226     _recombiner = recombiner;
00227   }
00228 
00229 
00230   /// constructor for case with 0 parameters (ee_kt_algorithm) and
00231   /// and external recombiner
00232   JetDefinition(JetAlgorithm jet_algorithm, 
00233                 const Recombiner * recombiner,
00234                 Strategy strategy = Best) {
00235     *this = JetDefinition(jet_algorithm, external_scheme, strategy);
00236     _recombiner = recombiner;
00237   }
00238 
00239   /// constructor allowing the extra parameter to be set and a pointer to
00240   /// a recombiner
00241   JetDefinition(JetAlgorithm jet_algorithm, 
00242                 double R, 
00243                 double xtra_param,
00244                 const Recombiner * recombiner,
00245                 Strategy strategy = Best) {
00246     *this = JetDefinition(jet_algorithm, R, external_scheme, strategy);
00247     _recombiner = recombiner;
00248     set_extra_param(xtra_param);
00249   }
00250 
00251   /// a default constructor
00252   JetDefinition() {
00253     *this = JetDefinition(kt_algorithm, 1.0);
00254   }
00255 
00256   /// constructor based on a pointer to a user's plugin; the object
00257   /// pointed to must remain valid for the whole duration of existence
00258   /// of the JetDefinition and any related ClusterSequences
00259   JetDefinition(const Plugin * plugin) {
00260     _plugin = plugin;
00261     _strategy = plugin_strategy;
00262     _Rparam = _plugin->R();
00263     _jet_algorithm = plugin_algorithm;
00264     set_recombination_scheme(E_scheme);
00265   }
00266 
00267 
00268   /// constructor to fully specify a jet-definition (together with
00269   /// information about how algorithically to run it).
00270   ///
00271   /// the ordering of arguments here is old and deprecated (except
00272   /// as the common constructor for internal use)
00273   JetDefinition(JetAlgorithm jet_algorithm, 
00274                 double R, 
00275                 Strategy strategy,
00276                 RecombinationScheme recomb_scheme = E_scheme,
00277                 int nparameters = 1);
00278 // :
00279 //    _jet_algorithm(jet_algorithm), _Rparam(R), _strategy(strategy) {
00280 //    // the largest sensible value for R
00281 //    if (jet_algorithm != ee_kt_algorithm &&
00282 //      jet_algorithm != ee_genkt_algorithm) assert(_Rparam <= 0.5*pi);
00283 //    assert(_jet_algorithm != plugin_algorithm &&
00284 //           _strategy   != plugin_strategy);
00285 //    _plugin = NULL;
00286 //    set_recombination_scheme(recomb_scheme);
00287 //    set_extra_param(0.0); // make sure it's defined
00288 //  }
00289 
00290 
00291   /// set the recombination scheme to the one provided
00292   void set_recombination_scheme(RecombinationScheme);
00293 
00294   /// set the recombiner class to the one provided
00295   void set_recombiner(const Recombiner * recomb) {
00296     _recombiner = recomb;
00297     _default_recombiner = DefaultRecombiner(external_scheme);
00298   }
00299 
00300   /// return a pointer to the plugin 
00301   const Plugin * plugin() const {return _plugin;};
00302 
00303   /// return information about the definition...
00304   JetAlgorithm jet_algorithm  () const {return _jet_algorithm  ;}
00305   /// same as above for backward compatibility
00306   JetAlgorithm jet_finder     () const {return _jet_algorithm  ;}
00307   double    R           () const {return _Rparam      ;}
00308   // a general purpose extra parameter, whose meaning depends on
00309   // the algorithm, and may often be unused.
00310   double    extra_param () const {return _extra_param ;}
00311   Strategy  strategy    () const {return _strategy    ;}
00312   RecombinationScheme recombination_scheme() const {
00313     return _default_recombiner.scheme();}
00314 
00315   /// (re)set the jet finder
00316   void set_jet_algorithm(JetAlgorithm njf) {_jet_algorithm = njf;}
00317   /// same as above for backward compatibility
00318   void set_jet_finder(JetAlgorithm njf)    {_jet_algorithm = njf;}
00319   /// (re)set the general purpose extra parameter
00320   void set_extra_param(double xtra_param) {_extra_param = xtra_param;}
00321 
00322   /// return a pointer to the currently defined recombiner. 
00323   ///
00324   /// Warning: the pointer may be to an internal recombiner (for
00325   /// default recombination schemes), in which case if the
00326   /// JetDefinition becomes invalid (e.g. is deleted), the pointer
00327   /// will then point to an object that no longer exists.
00328   /// 
00329   /// Note also that if you copy a JetDefinition with a default
00330   /// recombination scheme, then the two copies will have distinct
00331   /// recombiners, and return different recombiner() pointers.
00332   const Recombiner * recombiner() const {
00333     return _recombiner == 0 ? & _default_recombiner : _recombiner;}
00334 
00335   /// return a textual description of the current jet definition 
00336   std::string description() const;
00337 
00338 
00339 public:
00340   //======================================================================
00341   /// @ingroup advanced_usage
00342   /// \class Recombiner
00343   /// An abstract base class that will provide the recombination scheme
00344   /// facilities and/or allow a user to extend these facilities
00345   class Recombiner {
00346   public:
00347     /// return a textual description of the recombination scheme
00348     /// implemented here
00349     virtual std::string description() const = 0;
00350     
00351     /// recombine pa and pb and put result into pab
00352     virtual void recombine(const PseudoJet & pa, const PseudoJet & pb, 
00353                            PseudoJet & pab) const = 0;
00354 
00355     /// routine called to preprocess each input jet (to make all input
00356     /// jets compatible with the scheme requirements (e.g. massless).
00357     virtual void preprocess(PseudoJet & ) const {};
00358     
00359     /// a destructor to be replaced if necessary in derived classes...
00360     virtual ~Recombiner() {};
00361 
00362     /// pa += pb in the given recombination scheme. Not virtual -- the
00363     /// user should have no reason to want to redefine this!
00364     inline void plus_equal(PseudoJet & pa, const PseudoJet & pb) const {
00365       // put result in a temporary location in case the recombiner
00366       // does something funny (ours doesn't, but who knows about the
00367       // user's)
00368       PseudoJet pres; 
00369       recombine(pa,pb,pres);
00370       pa = pres;
00371     }
00372 
00373   };
00374   
00375   
00376   //======================================================================
00377   /// @ingroup advanced_usage
00378   /// \class DefaultRecombiner
00379   /// A class that will provide the recombination scheme facilities and/or
00380   /// allow a user to extend these facilities
00381   ///
00382   /// This class is derived from the (abstract) class Recombiner. It
00383   /// simply "sums" PseudoJets using a specified recombination scheme
00384   /// (E-scheme by default)
00385   class DefaultRecombiner : public Recombiner {
00386   public:
00387     DefaultRecombiner(RecombinationScheme recomb_scheme = E_scheme) : 
00388       _recomb_scheme(recomb_scheme) {}
00389     
00390     virtual std::string description() const;
00391     
00392     /// recombine pa and pb and put result into pab
00393     virtual void recombine(const PseudoJet & pa, const PseudoJet & pb, 
00394                            PseudoJet & pab) const;
00395 
00396     virtual void preprocess(PseudoJet & p) const;
00397 
00398     /// return the index of the recombination scheme
00399     RecombinationScheme scheme() const {return _recomb_scheme;}
00400     
00401   private:
00402     RecombinationScheme _recomb_scheme;
00403   };
00404 
00405 
00406   //======================================================================
00407   /// @ingroup advanced_usage
00408   /// \class Plugin
00409   /// a class that allows a user to introduce their own "plugin" jet
00410   /// finder
00411   ///
00412   /// Note that all the plugins provided with FastJet are derived from
00413   /// this class
00414   class Plugin{
00415   public:
00416     /// return a textual description of the jet-definition implemented
00417     /// in this plugin
00418     virtual std::string description() const = 0;
00419     
00420     /// given a ClusterSequence that has been filled up with initial
00421     /// particles, the following function should fill up the rest of the
00422     /// ClusterSequence, using the following member functions of
00423     /// ClusterSequence:
00424     ///   - plugin_do_ij_recombination(...)
00425     ///   - plugin_do_iB_recombination(...)
00426     virtual void run_clustering(ClusterSequence &) const = 0;
00427     
00428     virtual double R() const = 0;
00429     
00430     /// return true if there is specific support for the measurement
00431     /// of passive areas, in the sense that areas determined from all
00432     /// particles below the ghost separation scale will be a passive
00433     /// area. [If you don't understand this, ignore it!]
00434     virtual bool supports_ghosted_passive_areas() const {return false;}
00435 
00436     /// set the ghost separation scale for passive area determinations
00437     /// in future runs (strictly speaking that makes the routine
00438     /// a non const, so related internal info must be stored as a mutable)
00439     virtual void set_ghost_separation_scale(double scale) const;
00440     virtual double ghost_separation_scale() const {return 0.0;}
00441 
00442     /// if this returns false then a warning will be given
00443     /// whenever the user requests "exclusive" jets from the
00444     /// cluster sequence
00445     virtual bool exclusive_sequence_meaningful() const {return false;}
00446 
00447     /// a destructor to be replaced if necessary in derived classes...
00448     virtual ~Plugin() {};
00449   };
00450 
00451 private:
00452 
00453 
00454   JetAlgorithm _jet_algorithm;
00455   double    _Rparam;
00456   double    _extra_param ; ///< parameter whose meaning varies according to context
00457   Strategy  _strategy  ;
00458 
00459   const Plugin * _plugin;
00460 
00461   // when we use our own recombiner it's useful to point to it here
00462   // so that we don't have to worry about deleting it etc...
00463   DefaultRecombiner _default_recombiner;
00464   const Recombiner * _recombiner;
00465 
00466 };
00467 
00468 
00469 
00470 
00471 
00472 
00473 FASTJET_END_NAMESPACE
00474 
00475 #endif // __FASTJET_JETDEFINITION_HH__