Logo ROOT  
Reference Guide
DataRange.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: L. Moneta Wed Aug 30 11:05:02 2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class DataRange
12
13#ifndef ROOT_Fit_DataRange
14#define ROOT_Fit_DataRange
15
16#include <vector>
17#include <utility>
18
19namespace ROOT {
20
21 namespace Fit {
22
23
24//___________________________________________________________________________________
25/**
26 class describing the range in the coordinates
27 it supports multiple range in a coordinate.
28 The rnage dimension is the dimension of the coordinate, its size is
29 the number of interval for each coordinate.
30 Default range is -inf, inf
31 Range can be modified with the add range method
32
33 @ingroup FitData
34*/
35class DataRange {
36
37public:
38
39 typedef std::vector<std::pair<double,double> > RangeSet;
40 typedef std::vector< RangeSet > RangeIntervals;
41
42 /**
43 Default constructor (infinite range)
44 */
45 explicit DataRange (unsigned int dim = 1) :
46 fRanges ( std::vector<RangeSet> (dim) )
47 {}
48
49 /**
50 construct a range for [xmin, xmax]
51 */
52 DataRange(double xmin, double xmax);
53
54 /**
55 construct a range for [xmin, xmax] , [ymin, ymax]
56 */
57 DataRange(double xmin, double xmax, double ymin, double ymax);
58 /**
59 construct a range for [xmin, xmax] , [ymin, ymax] , [zmin, zmax]
60 */
61 DataRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
62 /**
63 get range dimension
64 */
65 unsigned int NDim() const { return fRanges.size(); }
66
67 /**
68 return range size for coordinate icoord (starts from zero)
69 Size == 0 indicates no range is present [-inf, + inf]
70 */
71 unsigned int Size(unsigned int icoord = 0) const {
72 return icoord < fRanges.size() ? fRanges[icoord].size() : 0;
73 }
74
75 /**
76 return true if a range has been set in any of the coordinates
77 i.e. when it is not [-inf,+inf] for all coordinates
78 Avoid in case of multi-dim to loop on all the coordinated and ask the size
79 */
80 bool IsSet() const {
81 for (unsigned int icoord = 0; icoord < fRanges.size(); ++icoord)
82 if (fRanges[icoord].size() > 0) return true;
83 return false;
84 }
85
86 /**
87 return the vector of ranges for the coordinate icoord
88 */
89 const RangeSet & Ranges(unsigned int icoord = 0) const {
90 // return icoord < fRanges.size() ? fRanges[icoord] : RangeSet();
91 return fRanges.at(icoord);
92 }
93
94 /**
95 return the i-th range for the coordinate icoord.
96 Useful method when only one range is present for the given coordinate
97 */
98 std::pair<double, double> operator() (unsigned int icoord = 0,unsigned int irange = 0) const;
99
100 /**
101 get the i-th range for given coordinate. If range does not exist
102 return -inf, +inf
103 */
104 void GetRange(unsigned int irange, unsigned int icoord, double & xmin, double & xmax) const {
105 if (Size(icoord)<= irange) GetInfRange(xmin,xmax);
106 else {
107 xmin = fRanges[icoord][irange].first;
108 xmax = fRanges[icoord][irange].second;
109 }
110 }
111 /**
112 get the first range for given coordinate. If range does not exist
113 return -inf, +inf
114 */
115 void GetRange(unsigned int icoord, double & xmin, double & xmax) const {
116 if (Size(icoord) == 0) GetInfRange(xmin,xmax);
117 else {
118 xmin = fRanges[icoord].front().first;
119 xmax = fRanges[icoord].front().second;
120 }
121 }
122 /**
123 get first range for the x - coordinate
124 */
125 void GetRange(double & xmin, double & xmax,unsigned int irange = 0) const { GetRange(irange,0,xmin,xmax); }
126 /**
127 get range for the x and y coordinates
128 */
129 void GetRange(double & xmin, double & xmax, double & ymin, double & ymax,unsigned int irange = 0) const {
130 GetRange(irange,0,xmin,xmax); GetRange(irange,1,ymin,ymax);
131 }
132 /**
133 get range for the x and y and z coordinates
134 */
135 void GetRange(double & xmin, double & xmax, double & ymin, double & ymax, double & zmin, double & zmax,unsigned int irange=0) const {
136 GetRange(irange,0,xmin,xmax); GetRange(irange,1,ymin,ymax); GetRange(irange,2,zmin,zmax);
137 }
138 /**
139 get range for coordinates and fill the vector
140 */
141 void GetRange(double * xmin, double * xmax, unsigned int irange = 0) const {
142 for (unsigned int i = 0; i < fRanges.size(); ++i)
143 GetRange(irange,i,xmin[i],xmax[i]);
144 }
145
146 /**
147 Destructor (no operations)
148 */
150
151
152
153 /**
154 add a range [xmin,xmax] for the new coordinate icoord
155 Adding a range does not delete existing one, but takes the OR with
156 existing ranges.
157 if want to replace range use method SetRange, which replace range with existing one
158 */
159 void AddRange(unsigned int icoord , double xmin, double xmax );
160
161 /**
162 add a range [xmin,xmax] for the first coordinate icoord
163 */
164 void AddRange(double xmin, double xmax ) { AddRange(0,xmin,xmax); }
165 /**
166 add a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate
167 */
168 void AddRange(double xmin, double xmax, double ymin, double ymax ) { AddRange(0,xmin,xmax); AddRange(1,ymin,ymax); }
169 /**
170 add a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate and
171 [zmin,zmax] for the third coordinate
172 */
173 void AddRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax ) {
174 AddRange(0,xmin,xmax); AddRange(1,ymin,ymax); AddRange(2,zmin,zmax); }
175
176 /**
177 set a range [xmin,xmax] for the new coordinate icoord
178 If more range exists for other coordinates, delete the existing one and use it the new one
179 Use Add range if want to keep the union of the existing ranges
180 */
181 void SetRange(unsigned int icoord , double xmin, double xmax );
182
183 /**
184 set a range [xmin,xmax] for the first coordinate icoord
185 */
186 void SetRange(double xmin, double xmax ) { SetRange(0,xmin,xmax); }
187 /**
188 set a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate
189 */
190 void SetRange(double xmin, double xmax, double ymin, double ymax ) { SetRange(0,xmin,xmax); SetRange(1,ymin,ymax); }
191 /**
192 set a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate and
193 [zmin,zmax] for the third coordinate
194 */
195 void SetRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax ) {
196 SetRange(0,xmin,xmax); SetRange(1,ymin,ymax); SetRange(2,zmin,zmax); }
197
198 /**
199 clear all ranges in one coordinate (is now -inf, +inf)
200 */
201 void Clear (unsigned int icoord = 0 );
202
203 /**
204 check if a point is inside the range for the given coordinate
205 */
206 bool IsInside(double x, unsigned int icoord = 0) const;
207
208 /**
209 check if a multi-dimpoint is inside the range
210 */
211 bool IsInside(const double *x) const {
212 bool ret = true;
213 for (unsigned int idim = 0; idim < fRanges.size(); ++idim) {
214 ret &= IsInside(x[idim],idim);
215 if (!ret) return ret;
216 }
217 return ret;
218 }
219
220protected:
221 /**
222 internal function to remove all the existing ranges between xmin and xmax
223 called when a new range is inserted
224 */
225 void CleanRangeSet(unsigned int icoord, double xmin, double xmax);
226
227 // get the full range (-inf, +inf)
228 static void GetInfRange(double &x1, double &x2);
229
230private:
231
232 RangeIntervals fRanges; // list of all ranges
233
234
235};
236
237 } // end namespace Fit
238
239} // end namespace ROOT
240
241
242#endif /* ROOT_Fit_DataRange */
static const double x2[5]
static const double x1[5]
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
float xmin
Definition: THbookFile.cxx:95
float ymin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
float ymax
Definition: THbookFile.cxx:95
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition: DataRange.h:35
static void GetInfRange(double &x1, double &x2)
Definition: DataRange.cxx:182
void AddRange(double xmin, double xmax)
add a range [xmin,xmax] for the first coordinate icoord
Definition: DataRange.h:164
std::vector< std::pair< double, double > > RangeSet
Definition: DataRange.h:39
void AddRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
add a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate and [zmin,...
Definition: DataRange.h:173
bool IsInside(const double *x) const
check if a multi-dimpoint is inside the range
Definition: DataRange.h:211
void GetRange(double &xmin, double &xmax, double &ymin, double &ymax, unsigned int irange=0) const
get range for the x and y coordinates
Definition: DataRange.h:129
std::vector< RangeSet > RangeIntervals
Definition: DataRange.h:40
RangeIntervals fRanges
Definition: DataRange.h:232
void AddRange(double xmin, double xmax, double ymin, double ymax)
add a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate
Definition: DataRange.h:168
void SetRange(double xmin, double xmax, double ymin, double ymax)
set a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate
Definition: DataRange.h:190
void GetRange(double &xmin, double &xmax, double &ymin, double &ymax, double &zmin, double &zmax, unsigned int irange=0) const
get range for the x and y and z coordinates
Definition: DataRange.h:135
void CleanRangeSet(unsigned int icoord, double xmin, double xmax)
internal function to remove all the existing ranges between xmin and xmax called when a new range is ...
Definition: DataRange.cxx:165
bool IsInside(double x, unsigned int icoord=0) const
check if a point is inside the range for the given coordinate
Definition: DataRange.cxx:146
void GetRange(double &xmin, double &xmax, unsigned int irange=0) const
get first range for the x - coordinate
Definition: DataRange.h:125
const RangeSet & Ranges(unsigned int icoord=0) const
return the vector of ranges for the coordinate icoord
Definition: DataRange.h:89
bool IsSet() const
return true if a range has been set in any of the coordinates i.e.
Definition: DataRange.h:80
unsigned int NDim() const
get range dimension
Definition: DataRange.h:65
void Clear(unsigned int icoord=0)
clear all ranges in one coordinate (is now -inf, +inf)
Definition: DataRange.cxx:158
void AddRange(unsigned int icoord, double xmin, double xmax)
add a range [xmin,xmax] for the new coordinate icoord Adding a range does not delete existing one,...
Definition: DataRange.cxx:94
DataRange(unsigned int dim=1)
Default constructor (infinite range)
Definition: DataRange.h:45
unsigned int Size(unsigned int icoord=0) const
return range size for coordinate icoord (starts from zero) Size == 0 indicates no range is present [-...
Definition: DataRange.h:71
void GetRange(double *xmin, double *xmax, unsigned int irange=0) const
get range for coordinates and fill the vector
Definition: DataRange.h:141
void GetRange(unsigned int icoord, double &xmin, double &xmax) const
get the first range for given coordinate.
Definition: DataRange.h:115
std::pair< double, double > operator()(unsigned int icoord=0, unsigned int irange=0) const
return the i-th range for the coordinate icoord.
Definition: DataRange.cxx:78
void GetRange(unsigned int irange, unsigned int icoord, double &xmin, double &xmax) const
get the i-th range for given coordinate.
Definition: DataRange.h:104
void SetRange(unsigned int icoord, double xmin, double xmax)
set a range [xmin,xmax] for the new coordinate icoord If more range exists for other coordinates,...
Definition: DataRange.cxx:124
void SetRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
set a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate and [zmin,...
Definition: DataRange.h:195
void SetRange(double xmin, double xmax)
set a range [xmin,xmax] for the first coordinate icoord
Definition: DataRange.h:186
~DataRange()
Destructor (no operations)
Definition: DataRange.h:149
Double_t x[n]
Definition: legend1.C:17
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:133
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...