]>
Commit | Line | Data |
---|---|---|
370be031 | 1 | //STARTHEADER |
2 | // $Id: RangeDefinition.hh 1404 2009-01-21 18:43:57Z salam $ | |
3 | // | |
4 | // Copyright (c) 2005-2007, Matteo Cacciari and Gavin Salam | |
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 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. | |
18 | // | |
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. | |
23 | // | |
24 | // You should have received a copy of the GNU General Public License | |
25 | // along with FastJet; if not, write to the Free Software | |
26 | // Foundation, Inc.: | |
27 | // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
28 | //---------------------------------------------------------------------- | |
29 | //ENDHEADER | |
30 | ||
31 | #ifndef __FASTJET_RANGEDEFINITION_HH__ | |
32 | #define __FASTJET_RANGEDEFINITION_HH__ | |
33 | ||
34 | #include "fastjet/PseudoJet.hh" | |
35 | #include "fastjet/Error.hh" | |
36 | #include<sstream> | |
37 | #include<iostream> | |
38 | #include<string> | |
39 | ||
40 | namespace fastjet { // defined in fastjet/internal/base.hh | |
41 | ||
42 | //---------------------------------------------------------------------- | |
43 | // | |
44 | /// class for holding a range definition specification, given by limits | |
45 | /// on rapidity and azimuth. | |
46 | /// | |
47 | class RangeDefinition { | |
48 | public: | |
49 | /// default constructor | |
50 | RangeDefinition() {} | |
51 | ||
52 | /// constructor for a range definition given by |y|<rapmax | |
53 | RangeDefinition(double rapmax) { | |
54 | assert ( rapmax > 0.0 ); | |
55 | _rapmax = rapmax; | |
56 | _rapmin = -rapmax; | |
57 | _phimin = 0.0; | |
58 | _phimax = twopi; | |
59 | _total_area = 2.0*rapmax*twopi; | |
60 | _phispan = _phimax-_phimin; } | |
61 | ||
62 | /// destructor does nothing | |
63 | virtual ~RangeDefinition() {} | |
64 | ||
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); | |
73 | _rapmax = rapmax; | |
74 | _rapmin = rapmin; | |
75 | _phimin = phimin; | |
76 | _phimax = phimax; | |
77 | if (_phimax-_phimin > twopi) | |
78 | _total_area = (_rapmax - _rapmin)*twopi; | |
79 | else | |
80 | _total_area = (_rapmax - _rapmin)*(_phimax - _phimin); | |
81 | _phispan = _phimax-_phimin; } | |
82 | ||
83 | /// returns true if the range is localizable (i.e. set_position is | |
84 | /// meant to do something meaningful). | |
85 | /// | |
86 | /// This version of the class is not localizable and so it returns | |
87 | /// false. | |
88 | /// | |
89 | /// For localizable classes override this function with a function | |
90 | /// that returns true | |
91 | virtual inline bool is_localizable() const { return false; } | |
92 | ||
93 | ||
94 | /// place the range on the rap-phi position | |
95 | /// | |
96 | /// THIS DOES NOT DO ANYTHING FOR THIS CLASS AND IS ONLY THERE | |
97 | /// TO FACILITATE DERIVED CLASSES | |
98 | /// | |
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()); | |
106 | } else { | |
107 | _rapjet = rap; | |
108 | _phijet = phi; | |
109 | } | |
110 | } | |
111 | ||
112 | /// place the range on the jet position | |
113 | inline void set_position(const PseudoJet & jet) { | |
114 | set_position(jet.rap(),jet.phi()); | |
115 | } | |
116 | ||
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); | |
122 | } | |
123 | ||
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 && | |
130 | rap <= _rapmax && | |
131 | dphi <= _phispan ); | |
132 | } | |
133 | ||
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 { | |
137 | rapmin = _rapmin; | |
138 | rapmax = _rapmax; | |
139 | } | |
140 | ||
141 | /// area of the range region | |
142 | virtual inline double area() const { return _total_area; } | |
143 | ||
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 ; | |
149 | return ostr.str(); | |
150 | } | |
151 | ||
152 | protected: | |
153 | double _total_area; // total area of specified range | |
154 | ||
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, | |
158 | /// npoints = 100. | |
159 | void _numerical_total_area(double rapmax, int npoints) ; | |
160 | double _rapjet,_phijet; // jet position. only used in localizable derived classes | |
161 | ||
162 | private: | |
163 | double _rapmin,_rapmax,_phimin,_phimax,_phispan; | |
164 | ||
165 | }; | |
166 | ||
167 | } // fastjet namespace | |
168 | ||
169 | #endif // __FASTJET_RANGEDEFINITION_HH__ |