ClusterSequenceActiveArea.hh

00001 //STARTHEADER
00002 // $Id: ClusterSequenceActiveArea.hh 1761 2010-09-16 10:43:18Z 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_CLUSTERSEQUENCEACTIVEAREA_HH__
00032 #define __FASTJET_CLUSTERSEQUENCEACTIVEAREA_HH__
00033 
00034 
00035 #include "fastjet/PseudoJet.hh"
00036 #include "fastjet/ClusterSequenceAreaBase.hh"
00037 #include "fastjet/ClusterSequenceActiveAreaExplicitGhosts.hh"
00038 #include<iostream>
00039 #include<vector>
00040 
00041 //------------ backwards compatibility with version 2.1 -------------
00042 // for backwards compatibility make ActiveAreaSpec name available
00043 #include "fastjet/ActiveAreaSpec.hh"
00044 #include "fastjet/ClusterSequenceWithArea.hh"
00045 //--------------------------------------------------------------------
00046 
00047 
00048 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00049 
00050 //using namespace std;
00051 
00052 /// @ingroup sec_area_classes
00053 /// \class ClusterSequenceActiveArea
00054 /// Like ClusterSequence with computation of the active jet area
00055 ///
00056 /// Class that behaves essentially like ClusterSequence except
00057 /// that it also provides access to the area of a jet (which
00058 /// will be a random quantity... Figure out what to do about seeds 
00059 /// later...)
00060 ///
00061 /// This class should not be used directly. Rather use
00062 /// ClusterSequenceArea with the appropriate AreaDefinition
00063 class ClusterSequenceActiveArea : public ClusterSequenceAreaBase {
00064 public:
00065 
00066   /// default constructor
00067   ClusterSequenceActiveArea() {}
00068 
00069   /// constructor based on JetDefinition and GhostedAreaSpec
00070   template<class L> ClusterSequenceActiveArea
00071          (const std::vector<L> & pseudojets, 
00072           const JetDefinition & jet_def,
00073           const GhostedAreaSpec & ghost_spec,
00074           const bool & writeout_combinations = false) ;
00075 
00076   virtual double area (const PseudoJet & jet) const {
00077                              return _average_area[jet.cluster_hist_index()];};
00078   virtual double area_error (const PseudoJet & jet) const {
00079                              return _average_area2[jet.cluster_hist_index()];};
00080 
00081   virtual PseudoJet area_4vector (const PseudoJet & jet) const {
00082                     return _average_area_4vector[jet.cluster_hist_index()];};
00083 
00084   /// enum providing a variety of tentative strategies for estimating
00085   /// the background (e.g. non-jet) activity in a highly populated event; the
00086   /// one that has been most extensively tested is median.
00087   enum mean_pt_strategies{median=0, non_ghost_median, pttot_over_areatot, 
00088                           pttot_over_areatot_cut, mean_ratio_cut, play,
00089                           median_4vector};
00090 
00091   /// return the transverse momentum per unit area according to one
00092   /// of the above strategies; for some strategies (those with "cut"
00093   /// in their name) the parameter "range" allows one to exclude a
00094   /// subset of the jets for the background estimation, those that
00095   /// have pt/area > median(pt/area)*range.
00096   ///
00097   /// NB: This call is OBSOLETE; use media_pt_per_unit_area from the
00098   //      ClusterSequenceAreaBase class instead
00099   double pt_per_unit_area(mean_pt_strategies strat=median, 
00100                           double range=2.0 ) const;
00101 
00102   // following code removed -- now dealt with by AreaBase class (and
00103   // this definition here conflicts with it).
00104 //   /// fits a form pt_per_unit_area(y) = a + b*y^2 in the range
00105 //   /// abs(y)<raprange (for negative raprange, it defaults to
00106 //   /// _safe_rap_for_area).
00107 //   void parabolic_pt_per_unit_area(double & a,double & b, double raprange=-1.0,
00108 //                                double exclude_above=-1.0, 
00109 //                                bool use_area_4vector=false ) const;
00110 // 
00111   /// rewrite the empty area from the parent class, so as to use
00112   /// all info at our disposal
00113   /// return the total area, in the given y-phi range, that consists of ghost
00114   /// jets or unclustered ghosts
00115   virtual double empty_area(const RangeDefinition & range) const;
00116 
00117   /// return the true number of empty jets (replaces
00118   /// ClusterSequenceAreaBase::n_empty_jets(...))
00119   virtual double n_empty_jets(const RangeDefinition & range) const;
00120 
00121 protected:
00122   void _resize_and_zero_AA ();
00123   void _initialise_AA(const JetDefinition & jet_def,
00124                       const GhostedAreaSpec & ghost_spec,
00125                       const bool & writeout_combinations,
00126                       bool & continue_running);
00127 
00128   void _run_AA(const GhostedAreaSpec & ghost_spec);
00129 
00130   void _postprocess_AA(const GhostedAreaSpec & ghost_spec);
00131 
00132   /// does the initialisation and running specific to the active
00133   /// areas class
00134   void _initialise_and_run_AA (const JetDefinition & jet_def,
00135                                const GhostedAreaSpec & ghost_spec,
00136                                const bool & writeout_combinations = false);
00137 
00138   /// transfer the history (and jet-momenta) from clust_seq to our
00139   /// own internal structure while removing ghosts
00140   void _transfer_ghost_free_history(
00141            const ClusterSequenceActiveAreaExplicitGhosts & clust_seq);
00142 
00143 
00144   /// transfer areas from the ClusterSequenceActiveAreaExplicitGhosts
00145   /// object into our internal area bookkeeping...
00146   void _transfer_areas(const std::vector<int> & unique_hist_order, 
00147                        const ClusterSequenceActiveAreaExplicitGhosts & );
00148 
00149   /// child classes benefit from having these at their disposal
00150   std::valarray<double> _average_area, _average_area2;
00151   std::valarray<PseudoJet> _average_area_4vector;
00152 
00153   /// returns true if there are any particles whose transverse momentum
00154   /// if so low that there's a risk of the ghosts having modified the
00155   /// clustering sequence
00156   bool has_dangerous_particles() const {return _has_dangerous_particles;}
00157 
00158 private:
00159 
00160 
00161   double           _non_jet_area, _non_jet_area2, _non_jet_number;
00162 
00163   double _maxrap_for_area; // max rap where we put ghosts
00164   double _safe_rap_for_area; // max rap where we trust jet areas
00165 
00166   bool   _has_dangerous_particles; 
00167 
00168 
00169   /// routine for extracting the tree in an order that will be independent
00170   /// of any degeneracies in the recombination sequence that don't
00171   /// affect the composition of the final jets
00172   void _extract_tree(std::vector<int> &) const;
00173   /// do the part of the extraction associated with pos, working
00174   /// through its children and their parents
00175   void _extract_tree_children(int pos, std::valarray<bool> &, const std::valarray<int> &, std::vector<int> &) const;
00176   /// do the part of the extraction associated with the parents of pos.
00177   void _extract_tree_parents (int pos, std::valarray<bool> &, const std::valarray<int> &,  std::vector<int> &) const;
00178 
00179   /// check if two jets have the same momentum to within the
00180   /// tolerance (and if pt's are not the same we're forgiving and
00181   /// look to see if the energy is the same)
00182   void _throw_unless_jets_have_same_perp_or_E(const PseudoJet & jet, 
00183                                               const PseudoJet & refjet, 
00184                                               double tolerance,
00185              const ClusterSequenceActiveAreaExplicitGhosts & jets_ghosted_seq
00186                                               ) const;
00187 
00188   /// since we are playing nasty games with seeds, we should warn
00189   /// the user a few times
00190   //static int _n_seed_warnings;
00191   //const static int _max_seed_warnings = 10;
00192 
00193   // record the number of repeats
00194   int _ghost_spec_repeat;
00195 
00196   /// a class for our internal storage of ghost jets
00197   class GhostJet : public PseudoJet {
00198   public:
00199     GhostJet(const PseudoJet & j, double a) : PseudoJet(j), area(a){}
00200     double area;
00201   };
00202 
00203   std::vector<GhostJet> _ghost_jets;
00204   std::vector<GhostJet> _unclustered_ghosts;
00205 };
00206 
00207 
00208 
00209 
00210 template<class L> ClusterSequenceActiveArea::ClusterSequenceActiveArea 
00211 (const std::vector<L> & pseudojets, 
00212  const JetDefinition & jet_def,
00213  const GhostedAreaSpec & ghost_spec,
00214  const bool & writeout_combinations) {
00215 
00216   // transfer the initial jets (type L) into our own array
00217   _transfer_input_jets(pseudojets);
00218 
00219   // run the clustering for active areas
00220   _initialise_and_run_AA(jet_def, ghost_spec, writeout_combinations);
00221 
00222 }
00223 
00224 
00225   
00226 FASTJET_END_NAMESPACE
00227 
00228 #endif // __FASTJET_CLUSTERSEQUENCEACTIVEAREA_HH__