FastJet 3.0alpha3
JetDefinition.hh
00001 //STARTHEADER
00002 // $Id: JetDefinition.hh 2222 2011-06-02 23:27:59Z 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   /// the value for the jet algorithm in a JetDefinition for which
00122   /// no algorithm has yet been defined
00123   undefined_jet_algorithm = 999
00124 };
00125 
00126 /// make standard Les Houches nomenclature JetAlgorithm (algorithm is general
00127 /// recipe without the parameters) backward-compatible with old JetFinder
00128 typedef JetAlgorithm JetFinder;
00129 
00130 /// provide other possible names for the Cambridge/Aachen algorithm?
00131 const JetAlgorithm aachen_algorithm = cambridge_algorithm;
00132 const JetAlgorithm cambridge_aachen_algorithm = cambridge_algorithm;
00133 
00134 //======================================================================
00135 /// the various recombination schemes
00136 enum RecombinationScheme {
00137   /// summing the 4-momenta
00138   E_scheme=0,
00139   /// pt weighted recombination of y,phi (and summing of pt's)
00140   /// with preprocessing to make things massless by rescaling E=|\vec p|
00141   pt_scheme=1,
00142   /// pt^2 weighted recombination of y,phi (and summing of pt's)
00143   /// with preprocessing to make things massless by rescaling E=|\vec p|
00144   pt2_scheme=2,
00145   /// pt weighted recombination of y,phi (and summing of pt's)
00146   /// with preprocessing to make things massless by rescaling |\vec p|->=E
00147   Et_scheme=3,
00148   /// pt^2 weighted recombination of y,phi (and summing of pt's)
00149   /// with preprocessing to make things massless by rescaling |\vec p|->=E
00150   Et2_scheme=4,
00151   /// pt weighted recombination of y,phi (and summing of pt's), with 
00152   /// no preprocessing
00153   BIpt_scheme=5,
00154   /// pt^2 weighted recombination of y,phi (and summing of pt's)
00155   /// no preprocessing
00156   BIpt2_scheme=6,
00157   /// for the user's external scheme
00158   external_scheme = 99
00159 };
00160 
00161 
00162 
00163 
00164 // forward declaration, needed in order to specify interface for the
00165 // plugin.
00166 class ClusterSequence;
00167 
00168 
00169 
00170 
00171 //======================================================================
00172 /// @ingroup basic_classes
00173 /// \class JetDefinition
00174 /// class that is intended to hold a full definition of the jet
00175 /// clusterer
00176 class JetDefinition {
00177   
00178 public:
00179 
00180   /// forward declaration of a class that allows the user to introduce
00181   /// their own plugin 
00182   class Plugin;
00183 
00184   // forward declaration of a class that will provide the
00185   // recombination scheme facilities and/or allow a user to
00186   // extend these facilities
00187   class Recombiner;
00188 
00189 
00190   /// constructor with alternative ordering or arguments -- note that
00191   /// we have not provided a default jet finder, to avoid ambiguous
00192   /// JetDefinition() constructor.
00193   JetDefinition(JetAlgorithm jet_algorithm, 
00194                 double R, 
00195                 RecombinationScheme recomb_scheme = E_scheme,
00196                 Strategy strategy = Best) {
00197     *this = JetDefinition(jet_algorithm, R, strategy, recomb_scheme, 1);
00198   }
00199 
00200   /// constructor for algorithms that have no free parameters
00201   /// (e.g. ee_kt_algorithm)
00202   JetDefinition(JetAlgorithm jet_algorithm, 
00203                 RecombinationScheme recomb_scheme = E_scheme,
00204                 Strategy strategy = Best) {
00205     double dummyR = 0.0;
00206     *this = JetDefinition(jet_algorithm, dummyR, strategy, recomb_scheme, 0);
00207   }
00208 
00209   /// constructor for algorithms that require R + one extra parameter to be set 
00210   /// (the gen-kt series for example)
00211   JetDefinition(JetAlgorithm jet_algorithm, 
00212                 double R, 
00213                 double xtra_param,
00214                 RecombinationScheme recomb_scheme = E_scheme,
00215                 Strategy strategy = Best) {
00216     *this = JetDefinition(jet_algorithm, R, strategy, recomb_scheme, 2);
00217     set_extra_param(xtra_param);
00218   }
00219 
00220 
00221   /// constructor in a form that allows the user to provide a pointer
00222   /// to an external recombiner class (which must remain valid for the
00223   /// life of the JetDefinition object).
00224   JetDefinition(JetAlgorithm jet_algorithm, 
00225                 double R, 
00226                 const Recombiner * recombiner,
00227                 Strategy strategy = Best) {
00228     *this = JetDefinition(jet_algorithm, R, external_scheme, strategy);
00229     _recombiner = recombiner;
00230   }
00231 
00232 
00233   /// constructor for case with 0 parameters (ee_kt_algorithm) and
00234   /// and external recombiner
00235   JetDefinition(JetAlgorithm jet_algorithm, 
00236                 const Recombiner * recombiner,
00237                 Strategy strategy = Best) {
00238     *this = JetDefinition(jet_algorithm, external_scheme, strategy);
00239     _recombiner = recombiner;
00240   }
00241 
00242   /// constructor allowing the extra parameter to be set and a pointer to
00243   /// a recombiner
00244   JetDefinition(JetAlgorithm jet_algorithm, 
00245                 double R, 
00246                 double xtra_param,
00247                 const Recombiner * recombiner,
00248                 Strategy strategy = Best) {
00249     *this = JetDefinition(jet_algorithm, R, external_scheme, strategy);
00250     _recombiner = recombiner;
00251     set_extra_param(xtra_param);
00252   }
00253 
00254   /// a default constructor which creates a jet definition that is in
00255   /// a well-defined internal state, but not actually usable for jet
00256   /// clustering.
00257   JetDefinition()  {
00258     *this = JetDefinition(undefined_jet_algorithm, 1.0);
00259   }
00260   
00261 
00262   // /// a default constructor
00263   // JetDefinition() {
00264   //   *this = JetDefinition(kt_algorithm, 1.0);
00265   // }
00266 
00267   /// constructor based on a pointer to a user's plugin; the object
00268   /// pointed to must remain valid for the whole duration of existence
00269   /// of the JetDefinition and any related ClusterSequences
00270   JetDefinition(const Plugin * plugin) {
00271     _plugin = plugin;
00272     _strategy = plugin_strategy;
00273     _Rparam = _plugin->R();
00274     _jet_algorithm = plugin_algorithm;
00275     set_recombination_scheme(E_scheme);
00276   }
00277 
00278 
00279   /// constructor to fully specify a jet-definition (together with
00280   /// information about how algorithically to run it).
00281   ///
00282   /// the ordering of arguments here is old and deprecated (except
00283   /// as the common constructor for internal use)
00284   JetDefinition(JetAlgorithm jet_algorithm, 
00285                 double R, 
00286                 Strategy strategy,
00287                 RecombinationScheme recomb_scheme = E_scheme,
00288                 int nparameters = 1);
00289 // :
00290 //    _jet_algorithm(jet_algorithm), _Rparam(R), _strategy(strategy) {
00291 //    // the largest sensible value for R
00292 //    if (jet_algorithm != ee_kt_algorithm &&
00293 //      jet_algorithm != ee_genkt_algorithm) assert(_Rparam <= 0.5*pi);
00294 //    assert(_jet_algorithm != plugin_algorithm &&
00295 //           _strategy   != plugin_strategy);
00296 //    _plugin = NULL;
00297 //    set_recombination_scheme(recomb_scheme);
00298 //    set_extra_param(0.0); // make sure it's defined
00299 //  }
00300 
00301 
00302   /// set the recombination scheme to the one provided
00303   void set_recombination_scheme(RecombinationScheme);
00304 
00305   /// set the recombiner class to the one provided
00306   void set_recombiner(const Recombiner * recomb) {
00307     _recombiner = recomb;
00308     _default_recombiner = DefaultRecombiner(external_scheme);
00309   }
00310 
00311   /// return a pointer to the plugin 
00312   const Plugin * plugin() const {return _plugin;};
00313 
00314   /// return information about the definition...
00315   JetAlgorithm jet_algorithm  () const {return _jet_algorithm  ;}
00316   /// same as above for backward compatibility
00317   JetAlgorithm jet_finder     () const {return _jet_algorithm  ;}
00318   double    R           () const {return _Rparam      ;}
00319   // a general purpose extra parameter, whose meaning depends on
00320   // the algorithm, and may often be unused.
00321   double    extra_param () const {return _extra_param ;}
00322   Strategy  strategy    () const {return _strategy    ;}
00323   RecombinationScheme recombination_scheme() const {
00324     return _default_recombiner.scheme();}
00325 
00326   /// (re)set the jet finder
00327   void set_jet_algorithm(JetAlgorithm njf) {_jet_algorithm = njf;}
00328   /// same as above for backward compatibility
00329   void set_jet_finder(JetAlgorithm njf)    {_jet_algorithm = njf;}
00330   /// (re)set the general purpose extra parameter
00331   void set_extra_param(double xtra_param) {_extra_param = xtra_param;}
00332 
00333   /// return a pointer to the currently defined recombiner. 
00334   ///
00335   /// Warning: the pointer may be to an internal recombiner (for
00336   /// default recombination schemes), in which case if the
00337   /// JetDefinition becomes invalid (e.g. is deleted), the pointer
00338   /// will then point to an object that no longer exists.
00339   /// 
00340   /// Note also that if you copy a JetDefinition with a default
00341   /// recombination scheme, then the two copies will have distinct
00342   /// recombiners, and return different recombiner() pointers.
00343   const Recombiner * recombiner() const {
00344     return _recombiner == 0 ? & _default_recombiner : _recombiner;}
00345 
00346   /// returns true if the current jet definitions shares the same
00347   /// recombiner as teh one passed as an argument
00348   bool has_same_recombiner(const JetDefinition &other_jd) const;
00349 
00350   /// return a textual description of the current jet definition 
00351   std::string description() const;
00352 
00353 
00354 public:
00355   //======================================================================
00356   /// @ingroup advanced_usage
00357   /// \class Recombiner
00358   /// An abstract base class that will provide the recombination scheme
00359   /// facilities and/or allow a user to extend these facilities
00360   class Recombiner {
00361   public:
00362     /// return a textual description of the recombination scheme
00363     /// implemented here
00364     virtual std::string description() const = 0;
00365     
00366     /// recombine pa and pb and put result into pab
00367     virtual void recombine(const PseudoJet & pa, const PseudoJet & pb, 
00368                            PseudoJet & pab) const = 0;
00369 
00370     /// routine called to preprocess each input jet (to make all input
00371     /// jets compatible with the scheme requirements (e.g. massless).
00372     virtual void preprocess(PseudoJet & ) const {};
00373     
00374     /// a destructor to be replaced if necessary in derived classes...
00375     virtual ~Recombiner() {};
00376 
00377     /// pa += pb in the given recombination scheme. Not virtual -- the
00378     /// user should have no reason to want to redefine this!
00379     inline void plus_equal(PseudoJet & pa, const PseudoJet & pb) const {
00380       // put result in a temporary location in case the recombiner
00381       // does something funny (ours doesn't, but who knows about the
00382       // user's)
00383       PseudoJet pres; 
00384       recombine(pa,pb,pres);
00385       pa = pres;
00386     }
00387 
00388   };
00389   
00390   
00391   //======================================================================
00392   /// @ingroup advanced_usage
00393   /// \class DefaultRecombiner
00394   /// A class that will provide the recombination scheme facilities and/or
00395   /// allow a user to extend these facilities
00396   ///
00397   /// This class is derived from the (abstract) class Recombiner. It
00398   /// simply "sums" PseudoJets using a specified recombination scheme
00399   /// (E-scheme by default)
00400   class DefaultRecombiner : public Recombiner {
00401   public:
00402     DefaultRecombiner(RecombinationScheme recomb_scheme = E_scheme) : 
00403       _recomb_scheme(recomb_scheme) {}
00404     
00405     virtual std::string description() const;
00406     
00407     /// recombine pa and pb and put result into pab
00408     virtual void recombine(const PseudoJet & pa, const PseudoJet & pb, 
00409                            PseudoJet & pab) const;
00410 
00411     virtual void preprocess(PseudoJet & p) const;
00412 
00413     /// return the index of the recombination scheme
00414     RecombinationScheme scheme() const {return _recomb_scheme;}
00415     
00416   private:
00417     RecombinationScheme _recomb_scheme;
00418   };
00419 
00420 
00421   //======================================================================
00422   /// @ingroup advanced_usage
00423   /// \class Plugin
00424   /// a class that allows a user to introduce their own "plugin" jet
00425   /// finder
00426   ///
00427   /// Note that all the plugins provided with FastJet are derived from
00428   /// this class
00429   class Plugin{
00430   public:
00431     /// return a textual description of the jet-definition implemented
00432     /// in this plugin
00433     virtual std::string description() const = 0;
00434     
00435     /// given a ClusterSequence that has been filled up with initial
00436     /// particles, the following function should fill up the rest of the
00437     /// ClusterSequence, using the following member functions of
00438     /// ClusterSequence:
00439     ///   - plugin_do_ij_recombination(...)
00440     ///   - plugin_do_iB_recombination(...)
00441     virtual void run_clustering(ClusterSequence &) const = 0;
00442     
00443     virtual double R() const = 0;
00444     
00445     /// return true if there is specific support for the measurement
00446     /// of passive areas, in the sense that areas determined from all
00447     /// particles below the ghost separation scale will be a passive
00448     /// area. [If you don't understand this, ignore it!]
00449     virtual bool supports_ghosted_passive_areas() const {return false;}
00450 
00451     /// set the ghost separation scale for passive area determinations
00452     /// in future runs (strictly speaking that makes the routine
00453     /// a non const, so related internal info must be stored as a mutable)
00454     virtual void set_ghost_separation_scale(double scale) const;
00455     virtual double ghost_separation_scale() const {return 0.0;}
00456 
00457     /// if this returns false then a warning will be given
00458     /// whenever the user requests "exclusive" jets from the
00459     /// cluster sequence
00460     virtual bool exclusive_sequence_meaningful() const {return false;}
00461 
00462     /// a destructor to be replaced if necessary in derived classes...
00463     virtual ~Plugin() {};
00464   };
00465 
00466 private:
00467 
00468 
00469   JetAlgorithm _jet_algorithm;
00470   double    _Rparam;
00471   double    _extra_param ; ///< parameter whose meaning varies according to context
00472   Strategy  _strategy  ;
00473 
00474   const Plugin * _plugin;
00475 
00476   // when we use our own recombiner it's useful to point to it here
00477   // so that we don't have to worry about deleting it etc...
00478   DefaultRecombiner _default_recombiner;
00479   const Recombiner * _recombiner;
00480 
00481 };
00482 
00483 
00484 //-------------------------------------------------------------------------------
00485 // helper functions to build a jet made of pieces
00486 //
00487 // These functions include an options recombiner used to compute the
00488 // total composite jet momentum
00489 // -------------------------------------------------------------------------------
00490 
00491 /// build a "CompositeJet" from the vector of its pieces
00492 ///
00493 /// In this case, E-scheme recombination is assumed to compute the
00494 /// total momentum
00495 PseudoJet join(const std::vector<PseudoJet> & pieces, const JetDefinition::Recombiner & recombiner);
00496 
00497 /// build a MergedJet from a single PseudoJet
00498 PseudoJet join(const PseudoJet & j1, 
00499                const JetDefinition::Recombiner & recombiner);
00500 
00501 /// build a MergedJet from 2 PseudoJet
00502 PseudoJet join(const PseudoJet & j1, const PseudoJet & j2, 
00503                const JetDefinition::Recombiner & recombiner);
00504 
00505 /// build a MergedJet from 3 PseudoJet
00506 PseudoJet join(const PseudoJet & j1, const PseudoJet & j2, const PseudoJet & j3, 
00507                const JetDefinition::Recombiner & recombiner);
00508 
00509 /// build a MergedJet from 4 PseudoJet
00510 PseudoJet join(const PseudoJet & j1, const PseudoJet & j2, const PseudoJet & j3, const PseudoJet & j4, 
00511                const JetDefinition::Recombiner & recombiner);
00512 
00513 
00514 
00515 
00516 
00517 FASTJET_END_NAMESPACE
00518 
00519 #endif // __FASTJET_JETDEFINITION_HH__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends