ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 first range for given coordinate. If range does not exist
101  return -inf, +inf
102  */
103  void GetRange(unsigned int icoord, double & xmin, double & xmax) const {
104  if (Size(icoord) == 0) GetInfRange(xmin,xmax);
105  else {
106  xmin = fRanges[icoord].front().first;
107  xmax = fRanges[icoord].front().second;
108  }
109  }
110  /**
111  get first range for the x - coordinate
112  */
113  void GetRange(double & xmin, double & xmax) const { GetRange(0,xmin,xmax); }
114  /**
115  get first range for the x and y coordinates
116  */
117  void GetRange(double & xmin, double & xmax, double & ymin, double & ymax) const {
118  GetRange(0,xmin,xmax); GetRange(1,ymin,ymax);
119  }
120  /**
121  get first range for the x and y and z coordinates
122  */
123  void GetRange(double & xmin, double & xmax, double & ymin, double & ymax, double & zmin, double & zmax) const {
124  GetRange(0,xmin,xmax); GetRange(1,ymin,ymax); GetRange(2,zmin,zmax);
125  }
126  /**
127  get first range for coordinates and fill the vector
128  */
129  void GetRange(double * xmin, double * xmax) const {
130  for (unsigned int i = 0; i < fRanges.size(); ++i)
131  GetRange(i,xmin[i],xmax[i]);
132  }
133 
134  /**
135  Destructor (no operations)
136  */
138 
139 
140 
141  /**
142  add a range [xmin,xmax] for the new coordinate icoord
143  Adding a range does not delete existing one, but takes the OR with
144  existing ranges.
145  if want to replace range use method SetRange, which replace range with existing one
146  */
147  void AddRange(unsigned int icoord , double xmin, double xmax );
148 
149  /**
150  add a range [xmin,xmax] for the first coordinate icoord
151  */
152  void AddRange(double xmin, double xmax ) { AddRange(0,xmin,xmax); }
153  /**
154  add a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate
155  */
156  void AddRange(double xmin, double xmax, double ymin, double ymax ) { AddRange(0,xmin,xmax); AddRange(1,ymin,ymax); }
157  /**
158  add a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate and
159  [zmin,zmax] for the third coordinate
160  */
161  void AddRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax ) {
162  AddRange(0,xmin,xmax); AddRange(1,ymin,ymax); AddRange(2,zmin,zmax); }
163 
164  /**
165  set a range [xmin,xmax] for the new coordinate icoord
166  If more range exists for other coordinates, delete the existing one and use it the new one
167  Use Add range if want to keep the union of the existing ranges
168  */
169  void SetRange(unsigned int icoord , double xmin, double xmax );
170 
171  /**
172  set a range [xmin,xmax] for the first coordinate icoord
173  */
174  void SetRange(double xmin, double xmax ) { SetRange(0,xmin,xmax); }
175  /**
176  set a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate
177  */
178  void SetRange(double xmin, double xmax, double ymin, double ymax ) { SetRange(0,xmin,xmax); SetRange(1,ymin,ymax); }
179  /**
180  set a range [xmin,xmax] for the first and [ymin,ymax] for the second coordinate and
181  [zmin,zmax] for the third coordinate
182  */
183  void SetRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax ) {
184  SetRange(0,xmin,xmax); SetRange(1,ymin,ymax); SetRange(2,zmin,zmax); }
185 
186  /**
187  clear all ranges in one coordinate (is now -inf, +inf)
188  */
189  void Clear (unsigned int icoord = 0 );
190 
191  /**
192  check if a point is inside the range for the given coordinate
193  */
194  bool IsInside(double x, unsigned int icoord = 0) const;
195 
196 protected:
197  /**
198  internal function to remove all the existing ranges between xmin and xmax
199  called when a new range is inserted
200  */
201  void CleanRangeSet(unsigned int icoord, double xmin, double xmax);
202 
203  // get the full range (-inf, +inf)
204  static void GetInfRange(double &x1, double &x2);
205 
206 private:
207 
208  RangeIntervals fRanges; // list of all ranges
209 
210 
211 };
212 
213  } // end namespace Fit
214 
215 } // end namespace ROOT
216 
217 
218 #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
const RangeSet & Ranges(unsigned int icoord=0) const
return the vector of ranges for the coordinate icoord
Definition: DataRange.h:88
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:161
RangeIntervals fRanges
Definition: DataRange.h:208
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:183
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:178
bool IsSet() const
return true if a range has been set in any of the coordinates i.e.
Definition: DataRange.h:79
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
void SetRange(double xmin, double xmax)
set a range [xmin,xmax] for the first coordinate icoord
Definition: DataRange.h:174
static const double x2[5]
Double_t x[n]
Definition: legend1.C:17
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
DataRange(unsigned int dim=1)
Default constructor (infinite range)
Definition: DataRange.h:44
std::vector< RangeSet > RangeIntervals
Definition: DataRange.h:39
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 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
void GetRange(double *xmin, double *xmax) const
get first range for coordinates and fill the vector
Definition: DataRange.h:129
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:156
std::vector< std::pair< double, double > > RangeSet
Definition: DataRange.h:38
unsigned int NDim() const
get range dimension
Definition: DataRange.h:64
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:137
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
void GetRange(double &xmin, double &xmax, double &ymin, double &ymax) const
get first range for the x and y coordinates
Definition: DataRange.h:117
void GetRange(double &xmin, double &xmax) const
get first range for the x - coordinate
Definition: DataRange.h:113
void GetRange(double &xmin, double &xmax, double &ymin, double &ymax, double &zmin, double &zmax) const
get first range for the x and y and z coordinates
Definition: DataRange.h:123
static void GetInfRange(double &x1, double &x2)
Definition: DataRange.cxx:182
void GetRange(unsigned int icoord, double &xmin, double &xmax) const
get the first range for given coordinate.
Definition: DataRange.h:103
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 AddRange(double xmin, double xmax)
add a range [xmin,xmax] for the first coordinate icoord
Definition: DataRange.h:152