2 // $Id: RangeDefinition.hh 1404 2009-01-21 18:43:57Z salam $
4 // Copyright (c) 2005-2007, Matteo Cacciari and Gavin Salam
6 //----------------------------------------------------------------------
7 // This file is part of FastJet.
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.
14 // The algorithms that underlie FastJet have required considerable
15 // development and are described in hep-ph/0512210. If you use
16 // FastJet as part of work towards a scientific publication, please
17 // include a citation to the FastJet paper.
19 // FastJet is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
24 // You should have received a copy of the GNU General Public License
25 // along with FastJet; if not, write to the Free Software
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 //----------------------------------------------------------------------
31 #ifndef __FASTJET_RANGEDEFINITION_HH__
32 #define __FASTJET_RANGEDEFINITION_HH__
34 #include "fastjet/PseudoJet.hh"
35 #include "fastjet/Error.hh"
40 namespace fastjet { // defined in fastjet/internal/base.hh
42 //----------------------------------------------------------------------
44 /// class for holding a range definition specification, given by limits
45 /// on rapidity and azimuth.
47 class RangeDefinition {
49 /// default constructor
52 /// constructor for a range definition given by |y|<rapmax
53 RangeDefinition(double rapmax) {
54 assert ( rapmax > 0.0 );
59 _total_area = 2.0*rapmax*twopi;
60 _phispan = _phimax-_phimin; }
62 /// destructor does nothing
63 virtual ~RangeDefinition() {}
65 /// constructor for a range definition given by
66 /// rapmin <= y <= rapmax, phimin <= phi <= phimax
67 RangeDefinition(double rapmin, double rapmax,
68 double phimin = 0.0, double phimax = twopi) {
69 assert ( rapmin < rapmax);
70 assert ( phimin < phimax);
71 assert ( phimin > -twopi );
72 assert ( phimax < 2*twopi);
77 if (_phimax-_phimin > twopi)
78 _total_area = (_rapmax - _rapmin)*twopi;
80 _total_area = (_rapmax - _rapmin)*(_phimax - _phimin);
81 _phispan = _phimax-_phimin; }
83 /// returns true if the range is localizable (i.e. set_position is
84 /// meant to do something meaningful).
86 /// This version of the class is not localizable and so it returns
89 /// For localizable classes override this function with a function
91 virtual inline bool is_localizable() const { return false; }
94 /// place the range on the rap-phi position
96 /// THIS DOES NOT DO ANYTHING FOR THIS CLASS AND IS ONLY THERE
97 /// TO FACILITATE DERIVED CLASSES
99 /// DON'T NECESSARILY COUNT ON IT IN THE FUTURE EITHER???
100 inline void set_position(const double & rap, const double & phi) {
101 if (! is_localizable() ) {
102 std::ostringstream err;
103 err << description() <<
104 "\nThis range is not localizable. set_position() should not be used on it.";
105 throw fastjet::Error(err.str());
112 /// place the range on the jet position
113 inline void set_position(const PseudoJet & jet) {
114 set_position(jet.rap(),jet.phi());
117 /// return bool according to whether the jet is within the given range
118 inline bool is_in_range(const PseudoJet & jet) const {
119 double rap = jet.rap();
120 double phi = jet.phi();
121 return is_in_range(rap,phi);
124 /// return bool according to whether a (rap,phi) point is in range
125 virtual inline bool is_in_range(double rap, double phi) const {
126 double dphi=phi-_phimin;
127 if (dphi >= twopi) dphi -= twopi;
128 if (dphi < 0) dphi += twopi;
129 return ( rap >= _rapmin &&
134 /// return the minimal and maximal rapidity of this range; remember to
135 /// replace this if you write a derived class with more complex ranges;
136 virtual inline void get_rap_limits(double & rapmin, double & rapmax) const {
141 /// area of the range region
142 virtual inline double area() const { return _total_area; }
144 /// textual description of range
145 virtual inline std::string description() const {
146 std::ostringstream ostr;
147 ostr << "Range: " << _rapmin << " <= y <= " << _rapmax << ", "
148 << _phimin << " <= phi <= " << _phimax ;
153 double _total_area; // total area of specified range
155 /// calculate, and set _total_area, by calculating which of points on
156 /// a grid (npoints * npoints from -rapmax..rapmax,0..2pi) are contained
157 /// in the range; it takes a reasonable time with rapmax = 10,
159 void _numerical_total_area(double rapmax, int npoints) ;
160 double _rapjet,_phijet; // jet position. only used in localizable derived classes
163 double _rapmin,_rapmax,_phimin,_phimax,_phispan;
167 } // fastjet namespace
169 #endif // __FASTJET_RANGEDEFINITION_HH__