FastJet 3.0beta1
ClusterSequenceArea.hh
00001 //STARTHEADER
00002 // $Id: ClusterSequenceArea.hh 2041 2011-04-12 13:33:58Z soyez $
00003 //
00004 // Copyright (c) 2006-2007, Matteo Cacciari, Gavin Salam and Gregory Soyez
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_CLUSTERSEQUENCEAREA_HH__
00032 #define __FASTJET_CLUSTERSEQUENCEAREA_HH__
00033 
00034 #include "fastjet/ClusterSequenceAreaBase.hh"
00035 #include "fastjet/ClusterSequenceActiveArea.hh"
00036 #include "fastjet/ClusterSequenceActiveAreaExplicitGhosts.hh"
00037 #include "fastjet/ClusterSequencePassiveArea.hh"
00038 #include "fastjet/ClusterSequenceVoronoiArea.hh"
00039 #include "fastjet/AreaDefinition.hh"
00040 
00041 FASTJET_BEGIN_NAMESPACE
00042 
00043 /// @ingroup area_classes
00044 /// \class ClusterSequenceArea
00045 /// General class for user to obtain ClusterSequence with additional
00046 /// area information.
00047 ///
00048 /// Based on the area_def, it automatically dispatches the work to the
00049 /// appropriate actual ClusterSequenceAreaBase-derived-class to do the
00050 /// real work.
00051 class ClusterSequenceArea : public ClusterSequenceAreaBase {
00052 public:
00053   /// main constructor
00054   template<class L> ClusterSequenceArea
00055          (const std::vector<L> & pseudojets, 
00056           const JetDefinition & jet_def,
00057           const AreaDefinition & area_def_in)  : _area_def(area_def_in) {
00058     initialize_and_run_cswa(pseudojets, jet_def);
00059   }
00060 
00061   /// constructor with a GhostedAreaSpec
00062   template<class L> ClusterSequenceArea
00063          (const std::vector<L> & pseudojets, 
00064           const JetDefinition & jet_def,
00065           const GhostedAreaSpec & ghost_spec)   : _area_def(ghost_spec){
00066     initialize_and_run_cswa(pseudojets, jet_def);
00067   }
00068 
00069   /// constructor with a VoronoiAreaSpec
00070   template<class L> ClusterSequenceArea
00071          (const std::vector<L> & pseudojets, 
00072           const JetDefinition & jet_def,
00073           const VoronoiAreaSpec & voronoi_spec)   : _area_def(voronoi_spec){
00074     initialize_and_run_cswa(pseudojets, jet_def);
00075   }
00076 
00077   /// return a reference to the area definition
00078   const AreaDefinition & area_def() const {return _area_def;}
00079 
00080 
00081   /// return the area associated with the given jet
00082   virtual double area       (const PseudoJet & jet) const {
00083     return _area_base->area(jet);}
00084 
00085   /// return the error (uncertainty) associated with the determination
00086   /// of the area of this jet
00087   virtual double area_error (const PseudoJet & jet) const {
00088     return _area_base->area_error(jet);}
00089 
00090   /// return the 4-vector area
00091   virtual PseudoJet area_4vector(const PseudoJet & jet) const {
00092     return _area_base->area_4vector(jet);}
00093 
00094   // /// return the total area, up to |y|<maxrap, that is free of jets
00095   // virtual double empty_area(double maxrap) const {
00096   //   return _area_base->empty_area(maxrap);}
00097   // 
00098   // /// return something similar to the number of pure ghost jets
00099   // /// in the given rapidity range in an active area case.
00100   // /// For the local implementation we return empty_area/(0.55 pi R^2),
00101   // /// based on measured properties of ghost jets with kt and cam. Note
00102   // /// that the number returned is a double.
00103   // virtual double n_empty_jets(double maxrap) const {
00104   //   return _area_base->n_empty_jets(maxrap);
00105 
00106   /// return the total area, corresponding to the given selector, that
00107   /// is free of jets
00108   ///
00109   /// The selector need to have a finite area and be applicable jet by
00110   /// jet (see the BackgroundEstimator and Subtractor tools for more
00111   /// advanced usage)
00112   virtual double empty_area(const Selector & selector) const {
00113     return _area_base->empty_area(selector);}
00114 
00115   /// return something similar to the number of pure ghost jets
00116   /// in the given rap-phi range in an active area case.
00117   /// For the local implementation we return empty_area/(0.55 pi R^2),
00118   /// based on measured properties of ghost jets with kt and cam. Note
00119   /// that the number returned is a double.
00120   ///
00121   /// The selector need to have a finite area and be applicable jet by
00122   /// jet (see the BackgroundEstimator and Subtractor tools for more
00123   /// advanced usage)
00124   virtual double n_empty_jets(const Selector & selector) const {
00125     return _area_base->n_empty_jets(selector);
00126   }
00127 
00128   /// true if a jet is made exclusively of ghosts
00129   virtual bool is_pure_ghost(const PseudoJet & jet) const {
00130     return _area_base->is_pure_ghost(jet);
00131   }
00132 
00133   /// true if this ClusterSequence has explicit ghosts
00134   virtual bool has_explicit_ghosts() const {
00135     return _area_base->has_explicit_ghosts();
00136   }
00137   
00138 
00139   /// overload version of what's in the ClusterSequenceAreaBase class, which 
00140   /// additionally checks compatibility between "selector" and region in which
00141   /// ghosts are thrown.
00142   ///
00143   /// The selector need to have a finite area and be applicable jet by
00144   /// jet (see the BackgroundEstimator and Subtractor tools for more
00145   /// advanced usage)
00146   virtual void get_median_rho_and_sigma(const std::vector<PseudoJet> & all_jets,
00147                                         const Selector & selector, 
00148                                         bool use_area_4vector,
00149                                         double & median, double & sigma,
00150                                         double & mean_area,
00151                                         bool all_are_incl = false) const {
00152     _warn_if_range_unsuitable(selector);
00153     ClusterSequenceAreaBase::get_median_rho_and_sigma(
00154                                  all_jets, selector, use_area_4vector,
00155                                  median, sigma, mean_area, all_are_incl);
00156   }
00157 
00158   /// overload version of what's in the ClusterSequenceAreaBase class,
00159   /// which actually just does the same thing as the base version (but
00160   /// since we've overridden the 5-argument version above, we have to
00161   /// override the 4-argument version too.
00162   virtual void get_median_rho_and_sigma(const Selector & selector, 
00163                                         bool use_area_4vector,
00164                                         double & median, double & sigma) const {
00165     ClusterSequenceAreaBase::get_median_rho_and_sigma(selector,use_area_4vector,
00166                                                       median,sigma);
00167   }
00168 
00169   /// overload version of what's in the ClusterSequenceAreaBase class,
00170   /// which actually just does the same thing as the base version (but
00171   /// since we've overridden the multi-argument version above, we have to
00172   /// override the 5-argument version too.
00173   virtual void get_median_rho_and_sigma(const Selector & selector, 
00174                                         bool use_area_4vector,
00175                                         double & median, double & sigma,
00176                                         double & mean_area) const {
00177     ClusterSequenceAreaBase::get_median_rho_and_sigma(selector,use_area_4vector,
00178                                                       median,sigma, mean_area);
00179   }
00180 
00181 
00182   /// overload version of what's in the ClusterSequenceAreaBase class, which 
00183   /// additionally checks compatibility between "range" and region in which
00184   /// ghosts are thrown.
00185   virtual void parabolic_pt_per_unit_area(double & a, double & b, 
00186                                           const Selector & selector, 
00187                                           double exclude_above=-1.0, 
00188                                           bool use_area_4vector=false) const {
00189     _warn_if_range_unsuitable(selector);
00190     ClusterSequenceAreaBase::parabolic_pt_per_unit_area(
00191                                 a,b,selector, exclude_above, use_area_4vector);
00192   }
00193 
00194 
00195 private:
00196   
00197   /// print a warning if the range is unsuitable for the current
00198   /// calculation of the area (e.g. because ghosts do not extend
00199   /// far enough).
00200   void _warn_if_range_unsuitable(const Selector & selector) const;
00201 
00202   template<class L> void initialize_and_run_cswa (
00203                                  const std::vector<L> & pseudojets, 
00204                                  const JetDefinition & jet_def);
00205 
00206   std::auto_ptr<ClusterSequenceAreaBase> _area_base;
00207   AreaDefinition _area_def;
00208   static LimitedWarning _range_warnings;
00209   static LimitedWarning _explicit_ghosts_repeats_warnings;
00210 
00211 };
00212 
00213 //----------------------------------------------------------------------
00214 template<class L> void ClusterSequenceArea::initialize_and_run_cswa(
00215            const std::vector<L> & pseudojets, 
00216            const JetDefinition  & jet_def)
00217  {
00218   
00219   ClusterSequenceAreaBase * _area_base_ptr;
00220   switch(_area_def.area_type()) {
00221   case active_area:
00222     _area_base_ptr = new ClusterSequenceActiveArea(pseudojets, 
00223                                                    jet_def, 
00224                                                    _area_def.ghost_spec());
00225     break;
00226   case active_area_explicit_ghosts:
00227     if (_area_def.ghost_spec().repeat() != 1) 
00228       _explicit_ghosts_repeats_warnings.warn("Requested active area with explicit ghosts with repeat != 1; only 1 set of ghosts will be used");
00229     _area_base_ptr = new ClusterSequenceActiveAreaExplicitGhosts(pseudojets, 
00230                                                    jet_def, 
00231                                                    _area_def.ghost_spec());
00232     break;
00233   case voronoi_area:
00234     _area_base_ptr = new ClusterSequenceVoronoiArea(pseudojets, 
00235                                                    jet_def, 
00236                                                    _area_def.voronoi_spec());
00237     break;
00238   case one_ghost_passive_area:
00239     _area_base_ptr = new ClusterSequence1GhostPassiveArea(pseudojets, 
00240                                                     jet_def, 
00241                                                     _area_def.ghost_spec());
00242     break;
00243   case passive_area:
00244     _area_base_ptr = new ClusterSequencePassiveArea(pseudojets, 
00245                                                     jet_def, 
00246                                                     _area_def.ghost_spec());
00247     break;
00248   default:
00249     std::cerr << "Error: unrecognized area_type in ClusterSequenceArea:" 
00250               << _area_def.area_type() << std::endl;
00251     exit(-1);
00252   }
00253   // now copy across the information from the area base class
00254   _area_base = std::auto_ptr<ClusterSequenceAreaBase>(_area_base_ptr);
00255   transfer_from_sequence(*_area_base);
00256 }
00257 
00258 FASTJET_END_NAMESPACE
00259 
00260 #endif // __FASTJET_CLUSTERSEQUENCEAREA_HH__
00261 
00262 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends