FastJet 3.0beta1
RangeDefinition.hh
00001 //STARTHEADER
00002 // $Id: RangeDefinition.hh 2366 2011-07-06 09:57:52Z soyez $
00003 //
00004 // Copyright (c) 2005-2007, 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_RANGEDEFINITION_HH__
00032 #define __FASTJET_RANGEDEFINITION_HH__
00033 
00034 #include "fastjet/PseudoJet.hh"
00035 #include "fastjet/Error.hh"
00036 #include "fastjet/internal/LimitedWarning.hh"
00037 #include<sstream>
00038 #include<iostream>
00039 #include<string>
00040 
00041 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00042 
00043 //----------------------------------------------------------------------
00044 //
00045 /// @ingroup area_classes
00046 /// \class RangeDefinition
00047 /// class for holding a range definition specification, given by limits
00048 /// on rapidity and azimuth.
00049 ///
00050 class RangeDefinition {
00051 public:
00052   /// default constructor
00053   RangeDefinition() { _warn_deprecated(); }
00054 
00055   /// constructor for a range definition given by |y|<rapmax
00056   RangeDefinition(double rapmax) {  _warn_deprecated(); 
00057                      assert ( rapmax > 0.0 );
00058                      _rapmax = rapmax;
00059                      _rapmin = -rapmax;
00060                      _phimin = 0.0;
00061                      _phimax = twopi;
00062                      _total_area = 2.0*rapmax*twopi;
00063                      _phispan = _phimax-_phimin; }
00064   
00065   /// destructor does nothing
00066   virtual ~RangeDefinition() {}
00067      
00068   /// constructor for a range definition given by 
00069   /// rapmin <= y <= rapmax, phimin <= phi <= phimax
00070   RangeDefinition(double rapmin, double rapmax, 
00071                   double phimin = 0.0, double phimax = twopi) {
00072                      _warn_deprecated(); 
00073                      assert ( rapmin < rapmax);
00074                      assert ( phimin < phimax);
00075                      assert ( phimin > -twopi );
00076                      assert ( phimax < 2*twopi);
00077                      _rapmax = rapmax;
00078                      _rapmin = rapmin;
00079                      _phimin = phimin;
00080                      _phimax = phimax;
00081                      if (_phimax-_phimin > twopi)
00082                        _total_area = (_rapmax - _rapmin)*twopi;
00083                      else
00084                        _total_area = (_rapmax - _rapmin)*(_phimax - _phimin);
00085                      _phispan = _phimax-_phimin; }
00086 
00087   /// returns true if the range is localizable (i.e. set_position is
00088   /// meant to do something meaningful). 
00089   ///
00090   /// This version of the class is not localizable and so it returns
00091   /// false.
00092   ///
00093   /// For localizable classes override this function with a function
00094   /// that returns true
00095   virtual inline bool is_localizable() const { return false; }
00096 
00097 
00098   /// place the range on the rap-phi position
00099   ///
00100   /// THIS DOES NOT DO ANYTHING FOR THIS CLASS AND IS ONLY THERE
00101   /// TO FACILITATE DERIVED CLASSES
00102   ///
00103   /// DON'T NECESSARILY COUNT ON IT IN THE FUTURE EITHER???
00104   inline void set_position(const double & rap, const double & phi) {
00105      if (! is_localizable() ) {
00106        std::ostringstream err;
00107        err << description() << 
00108          "\nThis range is not localizable. set_position() should not be used on it.";         
00109        throw fastjet::Error(err.str()); 
00110      } else {
00111        _rapjet = rap;
00112        _phijet = phi;
00113      }
00114   }
00115 
00116   /// place the range on the jet position
00117   inline void set_position(const PseudoJet & jet) {
00118      set_position(jet.rap(),jet.phi());
00119   }
00120 
00121   /// return bool according to whether the jet is within the given range
00122   inline bool is_in_range(const PseudoJet & jet) const {
00123     double rap = jet.rap();
00124     double phi = jet.phi();
00125     return is_in_range(rap,phi);
00126   }
00127   
00128   /// return bool according to whether a (rap,phi) point is in range
00129   virtual inline bool is_in_range(double rap, double phi) const {
00130     double dphi=phi-_phimin;
00131     if (dphi >= twopi) dphi -= twopi;
00132     if (dphi < 0)      dphi += twopi;
00133     return  ( rap  >= _rapmin && 
00134               rap  <= _rapmax &&
00135               dphi <= _phispan );
00136   }
00137 
00138   /// return the minimal and maximal rapidity of this range; remember to 
00139   /// replace this if you write a derived class with more complex ranges;
00140   virtual inline void get_rap_limits(double & rapmin, double & rapmax) const {
00141     rapmin = _rapmin;
00142     rapmax = _rapmax;
00143   }
00144   
00145   /// area of the range region
00146   virtual inline double area() const { return _total_area; }
00147   
00148   /// textual description of range
00149   virtual inline std::string description() const {
00150     std::ostringstream ostr;
00151     ostr << "Range: " << _rapmin << " <= y <= "   << _rapmax << ", "
00152                       << _phimin << " <= phi <= " << _phimax ;
00153     return ostr.str();
00154 }
00155 
00156 protected:
00157   double _total_area;  // total area of specified range
00158 
00159   /// calculate, and set  _total_area, by calculating which of points on 
00160   /// a grid (npoints * npoints from -rapmax..rapmax,0..2pi) are contained
00161   /// in the range; it takes a reasonable time with rapmax = 10,
00162   /// npoints = 100.
00163   void _numerical_total_area(double rapmax, int npoints) ;
00164   double _rapjet,_phijet; // jet position. only used in localizable derived classes
00165   
00166 private:
00167   double _rapmin,_rapmax,_phimin,_phimax,_phispan;
00168 
00169   static LimitedWarning _warnings_deprecated;
00170 
00171   /// the use of RangeDefinition is deprecated since FastJet version
00172   /// 3.0 onwards. Please use Selector instead.  
00173   /// RangeDefinition is only provided for backward compatibility
00174   /// reasons and is not guaranteed to work in future releases of
00175   /// FastJet.
00176   void _warn_deprecated() const; 
00177 };
00178 
00179 FASTJET_END_NAMESPACE        // defined in fastjet/internal/base.hh
00180 
00181 #endif // __FASTJET_RANGEDEFINITION_HH__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends