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