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