FastJet  3.1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
RangeDefinition.hh
1 //FJSTARTHEADER
2 // $Id: RangeDefinition.hh 3433 2014-07-23 08:17:03Z salam $
3 //
4 // Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
5 //
6 //----------------------------------------------------------------------
7 // This file is part of FastJet.
8 //
9 // FastJet is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // The algorithms that underlie FastJet have required considerable
15 // development. They are described in the original FastJet paper,
16 // hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
17 // FastJet as part of work towards a scientific publication, please
18 // quote the version you use and include a citation to the manual and
19 // optionally also to hep-ph/0512210.
20 //
21 // FastJet is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with FastJet. If not, see <http://www.gnu.org/licenses/>.
28 //----------------------------------------------------------------------
29 //FJENDHEADER
30 
31 #ifndef __FASTJET_RANGEDEFINITION_HH__
32 #define __FASTJET_RANGEDEFINITION_HH__
33 
34 #include "fastjet/PseudoJet.hh"
35 #include "fastjet/Error.hh"
36 #include "fastjet/LimitedWarning.hh"
37 #include<sstream>
38 #include<iostream>
39 #include<string>
40 
41 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
42 
43 //----------------------------------------------------------------------
44 //
45 /// @ingroup area_classes
46 /// \class RangeDefinition
47 /// class for holding a range definition specification, given by limits
48 /// on rapidity and azimuth.
49 ///
51 public:
52  /// default constructor
53  RangeDefinition() { _warn_deprecated(); }
54 
55  /// constructor for a range definition given by |y|<rapmax
56  RangeDefinition(double rapmax) { _warn_deprecated();
57  assert ( rapmax > 0.0 );
58  _rapmax = rapmax;
59  _rapmin = -rapmax;
60  _phimin = 0.0;
61  _phimax = twopi;
62  _total_area = 2.0*rapmax*twopi;
63  _phispan = _phimax-_phimin; }
64 
65  /// destructor does nothing
66  virtual ~RangeDefinition() {}
67 
68  /// constructor for a range definition given by
69  /// rapmin <= y <= rapmax, phimin <= phi <= phimax
70  RangeDefinition(double rapmin, double rapmax,
71  double phimin = 0.0, double phimax = twopi) {
72  _warn_deprecated();
73  assert ( rapmin < rapmax);
74  assert ( phimin < phimax);
75  assert ( phimin > -twopi );
76  assert ( phimax < 2*twopi);
77  _rapmax = rapmax;
78  _rapmin = rapmin;
79  _phimin = phimin;
80  _phimax = phimax;
81  if (_phimax-_phimin > twopi)
82  _total_area = (_rapmax - _rapmin)*twopi;
83  else
84  _total_area = (_rapmax - _rapmin)*(_phimax - _phimin);
85  _phispan = _phimax-_phimin; }
86 
87  /// returns true if the range is localizable (i.e. set_position is
88  /// meant to do something meaningful).
89  ///
90  /// This version of the class is not localizable and so it returns
91  /// false.
92  ///
93  /// For localizable classes override this function with a function
94  /// that returns true
95  virtual inline bool is_localizable() const { return false; }
96 
97 
98  /// place the range on the rap-phi position
99  ///
100  /// THIS DOES NOT DO ANYTHING FOR THIS CLASS AND IS ONLY THERE
101  /// TO FACILITATE DERIVED CLASSES
102  ///
103  /// DON'T NECESSARILY COUNT ON IT IN THE FUTURE EITHER???
104  inline void set_position(const double & rap, const double & phi) {
105  if (! is_localizable() ) {
106  std::ostringstream err;
107  err << description() <<
108  "\nThis range is not localizable. set_position() should not be used on it.";
109  throw Error(err.str());
110  } else {
111  _rapjet = rap;
112  _phijet = phi;
113  }
114  }
115 
116  /// place the range on the jet position
117  inline void set_position(const PseudoJet & jet) {
118  set_position(jet.rap(),jet.phi());
119  }
120 
121  /// return bool according to whether the jet is within the given range
122  inline bool is_in_range(const PseudoJet & jet) const {
123  double rap = jet.rap();
124  double phi = jet.phi();
125  return is_in_range(rap,phi);
126  }
127 
128  /// return bool according to whether a (rap,phi) point is in range
129  virtual inline bool is_in_range(double rap, double phi) const {
130  double dphi=phi-_phimin;
131  if (dphi >= twopi) dphi -= twopi;
132  if (dphi < 0) dphi += twopi;
133  return ( rap >= _rapmin &&
134  rap <= _rapmax &&
135  dphi <= _phispan );
136  }
137 
138  /// return the minimal and maximal rapidity of this range; remember to
139  /// replace this if you write a derived class with more complex ranges;
140  virtual inline void get_rap_limits(double & rapmin, double & rapmax) const {
141  rapmin = _rapmin;
142  rapmax = _rapmax;
143  }
144 
145  /// area of the range region
146  virtual inline double area() const { return _total_area; }
147 
148  /// textual description of range
149  virtual inline std::string description() const {
150  std::ostringstream ostr;
151  ostr << "Range: " << _rapmin << " <= y <= " << _rapmax << ", "
152  << _phimin << " <= phi <= " << _phimax ;
153  return ostr.str();
154 }
155 
156 protected:
157  double _total_area; // total area of specified range
158 
159  /// calculate, and set _total_area, by calculating which of points on
160  /// a grid (npoints * npoints from -rapmax..rapmax,0..2pi) are contained
161  /// in the range; it takes a reasonable time with rapmax = 10,
162  /// npoints = 100.
163  void _numerical_total_area(double rapmax, int npoints) ;
164  double _rapjet,_phijet; // jet position. only used in localizable derived classes
165 
166 private:
167  double _rapmin,_rapmax,_phimin,_phimax,_phispan;
168 
169  static LimitedWarning _warnings_deprecated;
170 
171  /// the use of RangeDefinition is deprecated since FastJet version
172  /// 3.0 onwards. Please use Selector instead.
173  /// RangeDefinition is only provided for backward compatibility
174  /// reasons and is not guaranteed to work in future releases of
175  /// FastJet.
176  void _warn_deprecated() const;
177 };
178 
179 FASTJET_END_NAMESPACE // defined in fastjet/internal/base.hh
180 
181 #endif // __FASTJET_RANGEDEFINITION_HH__
double rap() const
returns the rapidity or some large value when the rapidity is infinite
Definition: PseudoJet.hh:123
virtual void get_rap_limits(double &rapmin, double &rapmax) const
return the minimal and maximal rapidity of this range; remember to replace this if you write a derive...
RangeDefinition(double rapmin, double rapmax, double phimin=0.0, double phimax=twopi)
constructor for a range definition given by rapmin <= y <= rapmax, phimin <= phi <= phimax ...
void set_position(const PseudoJet &jet)
place the range on the jet position
class for holding a range definition specification, given by limits on rapidity and azimuth...
void set_position(const double &rap, const double &phi)
place the range on the rap-phi position
class to provide facilities for giving warnings up to some maximum number of times and to provide glo...
virtual bool is_localizable() const
returns true if the range is localizable (i.e.
base class corresponding to errors that can be thrown by FastJet
Definition: Error.hh:47
bool is_in_range(const PseudoJet &jet) const
return bool according to whether the jet is within the given range
double phi() const
returns phi (in the range 0..2pi)
Definition: PseudoJet.hh:108
virtual bool is_in_range(double rap, double phi) const
return bool according to whether a (rap,phi) point is in range
virtual std::string description() const
textual description of range
virtual ~RangeDefinition()
destructor does nothing
Class to contain pseudojets, including minimal information of use to jet-clustering routines...
Definition: PseudoJet.hh:67
RangeDefinition()
default constructor
virtual double area() const
area of the range region
RangeDefinition(double rapmax)
constructor for a range definition given by |y|