ClusterSequenceArea.hh

00001 //STARTHEADER
00002 // $Id: ClusterSequenceArea.hh 1761 2010-09-16 10:43:18Z 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, in the given rap-phi range, that is free of jets
00107   virtual double empty_area(const RangeDefinition & range) const {
00108     return _area_base->empty_area(range);}
00109 
00110   /// return something similar to the number of pure ghost jets
00111   /// in the given rap-phi range in an active area case.
00112   /// For the local implementation we return empty_area/(0.55 pi R^2),
00113   /// based on measured properties of ghost jets with kt and cam. Note
00114   /// that the number returned is a double.
00115   virtual double n_empty_jets(const RangeDefinition & range) const {
00116     return _area_base->n_empty_jets(range);
00117   }
00118 
00119   /// true if a jet is made exclusively of ghosts
00120   virtual bool is_pure_ghost(const PseudoJet & jet) const {
00121     return _area_base->is_pure_ghost(jet);
00122   }
00123 
00124   /// true if this ClusterSequence has explicit ghosts
00125   virtual bool has_explicit_ghosts() const {
00126     return _area_base->has_explicit_ghosts();
00127   }
00128   
00129 
00130   /// overload version of what's in the ClusterSequenceAreaBase class, which 
00131   /// additionally checks compatibility between "range" and region in which
00132   /// ghosts are thrown.
00133   virtual void get_median_rho_and_sigma(const std::vector<PseudoJet> & all_jets,
00134                                         const RangeDefinition & range, 
00135                                         bool use_area_4vector,
00136                                         double & median, double & sigma,
00137                                         double & mean_area,
00138                                         bool all_are_incl = false) const {
00139     _warn_if_range_unsuitable(range);
00140     ClusterSequenceAreaBase::get_median_rho_and_sigma(
00141                                  all_jets, range, use_area_4vector,
00142                                  median, sigma, mean_area, all_are_incl);
00143   }
00144 
00145   /// overload version of what's in the ClusterSequenceAreaBase class,
00146   /// which actually just does the same thing as the base version (but
00147   /// since we've overridden the 5-argument version above, we have to
00148   /// override the 4-argument version too.
00149   virtual void get_median_rho_and_sigma(const RangeDefinition & range, 
00150                                         bool use_area_4vector,
00151                                         double & median, double & sigma) const {
00152     ClusterSequenceAreaBase::get_median_rho_and_sigma(range,use_area_4vector,
00153                                                       median,sigma);
00154   }
00155 
00156   /// overload version of what's in the ClusterSequenceAreaBase class,
00157   /// which actually just does the same thing as the base version (but
00158   /// since we've overridden the multi-argument version above, we have to
00159   /// override the 5-argument version too.
00160   virtual void get_median_rho_and_sigma(const RangeDefinition & range, 
00161                                         bool use_area_4vector,
00162                                         double & median, double & sigma,
00163                                         double & mean_area) const {
00164     ClusterSequenceAreaBase::get_median_rho_and_sigma(range,use_area_4vector,
00165                                                       median,sigma, mean_area);
00166   }
00167 
00168 
00169   /// overload version of what's in the ClusterSequenceAreaBase class, which 
00170   /// additionally checks compatibility between "range" and region in which
00171   /// ghosts are thrown.
00172   virtual void parabolic_pt_per_unit_area(double & a, double & b, 
00173                                           const RangeDefinition & range, 
00174                                           double exclude_above=-1.0, 
00175                                           bool use_area_4vector=false) const {
00176     _warn_if_range_unsuitable(range);
00177     ClusterSequenceAreaBase::parabolic_pt_per_unit_area(
00178                                 a,b,range, exclude_above, use_area_4vector);
00179   }
00180 
00181 
00182 private:
00183   
00184   /// print a warning if the range is unsuitable for the current
00185   /// calculation of the area (e.g. because ghosts do not extend
00186   /// far enough).
00187   void _warn_if_range_unsuitable(const RangeDefinition & range) const;
00188 
00189   template<class L> void initialize_and_run_cswa (
00190                                  const std::vector<L> & pseudojets, 
00191                                  const JetDefinition & jet_def);
00192 
00193   std::auto_ptr<ClusterSequenceAreaBase> _area_base;
00194   AreaDefinition _area_def;
00195   static LimitedWarning _range_warnings;
00196   static LimitedWarning _explicit_ghosts_repeats_warnings;
00197 
00198 };
00199 
00200 //----------------------------------------------------------------------
00201 template<class L> void ClusterSequenceArea::initialize_and_run_cswa(
00202            const std::vector<L> & pseudojets, 
00203            const JetDefinition  & jet_def)
00204  {
00205   
00206   ClusterSequenceAreaBase * _area_base_ptr;
00207   switch(_area_def.area_type()) {
00208   case active_area:
00209     _area_base_ptr = new ClusterSequenceActiveArea(pseudojets, 
00210                                                    jet_def, 
00211                                                    _area_def.ghost_spec());
00212     break;
00213   case active_area_explicit_ghosts:
00214     if (_area_def.ghost_spec().repeat() != 1) 
00215       _explicit_ghosts_repeats_warnings.warn("Requested active area with explicit ghosts with repeat != 1; only 1 set of ghosts will be used");
00216     _area_base_ptr = new ClusterSequenceActiveAreaExplicitGhosts(pseudojets, 
00217                                                    jet_def, 
00218                                                    _area_def.ghost_spec());
00219     break;
00220   case voronoi_area:
00221     _area_base_ptr = new ClusterSequenceVoronoiArea(pseudojets, 
00222                                                    jet_def, 
00223                                                    _area_def.voronoi_spec());
00224     break;
00225   case one_ghost_passive_area:
00226     _area_base_ptr = new ClusterSequence1GhostPassiveArea(pseudojets, 
00227                                                     jet_def, 
00228                                                     _area_def.ghost_spec());
00229     break;
00230   case passive_area:
00231     _area_base_ptr = new ClusterSequencePassiveArea(pseudojets, 
00232                                                     jet_def, 
00233                                                     _area_def.ghost_spec());
00234     break;
00235   default:
00236     std::cerr << "Error: unrecognized area_type in ClusterSequenceArea:" 
00237               << _area_def.area_type() << std::endl;
00238     exit(-1);
00239   }
00240   // now copy across the information from the area base class
00241   _area_base = std::auto_ptr<ClusterSequenceAreaBase>(_area_base_ptr);
00242   transfer_from_sequence(*_area_base);
00243 }
00244 
00245 FASTJET_END_NAMESPACE
00246 
00247 #endif // __FASTJET_CLUSTERSEQUENCEAREA_HH__
00248 
00249