Logo ROOT   6.13/01
Reference Guide
UnBinData.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Wed Aug 30 11:15:23 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class UnBinData
12 
13 #ifndef ROOT_Fit_UnBinData
14 #define ROOT_Fit_UnBinData
15 
16 #include "Fit/FitData.h"
17 #include "Math/Error.h"
18 
19 
20 
21 namespace ROOT {
22 
23  namespace Fit {
24 
25 
26 //___________________________________________________________________________________
27 /**
28  Class describing the unbinned data sets (just x coordinates values) of any dimensions
29 
30  There is the option to construct UnBindata copying the data in (using the DataVector class)
31  or using pointer to external data (DataWrapper) class.
32  In general is found to be more efficient to copy the data.
33  In case of really large data sets for limiting memory consumption then the other option can be used
34  Specialized constructor exists for using external data up to 3 dimensions.
35 
36  When the data are copying in the number of points can be set later (or re-set) using Initialize and
37  the data are inserted one by one using the Add method.
38  It is mandatory to set the size before using the Add method.
39 
40  @ingroup FitData
41 */
42 class UnBinData : public FitData {
43 
44 public :
45 
46  /**
47  constructor from dimension of point and max number of points (to pre-allocate vector)
48  */
49 
50  explicit UnBinData( unsigned int maxpoints = 0, unsigned int dim = 1,
51  bool isWeighted = false ) :
52  FitData( maxpoints, isWeighted ? dim + 1 : dim ),
53  fWeighted(isWeighted)
54  {
55  assert( dim >= 1 );
56  assert( !fWeighted || dim >= 2 );
57  }
58 
59 
60  /**
61  constructor from range and default option
62  */
63  explicit UnBinData ( const DataRange & range, unsigned int maxpoints = 0,
64  unsigned int dim = 1, bool isWeighted = false ) :
65  FitData( range, maxpoints, isWeighted ? dim + 1 : dim ),
66  fWeighted(isWeighted)
67  {
68  assert( dim >= 1 );
69  assert( !fWeighted || dim >= 2 );
70  }
71 
72  /**
73  constructor from options and range
74  */
75  UnBinData (const DataOptions & opt, const DataRange & range,
76  unsigned int maxpoints = 0, unsigned int dim = 1, bool isWeighted = false ) :
77  FitData( opt, range, maxpoints, isWeighted ? dim + 1 : dim ),
78  fWeighted(isWeighted)
79  {
80  assert( dim >= 1 );
81  assert( !fWeighted || dim >= 2 );
82  }
83 
84  /**
85  constructor for 1D external data (data are not copied inside)
86  */
87  UnBinData(unsigned int n, const double * dataX ) :
88  FitData( n, dataX ),
89  fWeighted( false )
90  {
91  }
92 
93  /**
94  constructor for 2D external data (data are not copied inside)
95  or 1D data with a weight (if isWeighted = true)
96  */
97  UnBinData(unsigned int n, const double * dataX, const double * dataY,
98  bool isWeighted = false ) :
99  FitData( n, dataX, dataY ),
100  fWeighted( isWeighted )
101  {
102  }
103 
104  /**
105  constructor for 3D external data (data are not copied inside)
106  or 2D data with a weight (if isWeighted = true)
107  */
108  UnBinData(unsigned int n, const double * dataX, const double * dataY,
109  const double * dataZ, bool isWeighted = false ) :
110  FitData( n, dataX, dataY, dataZ ),
111  fWeighted( isWeighted )
112  {
113  }
114 
115  /**
116  constructor for multi-dim external data (data are not copied inside)
117  Uses as argument an iterator of a list (or vector) containing the const double * of the data
118  An example could be the std::vector<const double *>::begin
119  In case of weighted data, the external data must have a dim+1 lists of data
120  The apssed dim refers just to the coordinate size
121  */
122  template<class Iterator>
123  UnBinData(unsigned int n, unsigned int dim, Iterator dataItr,
124  bool isWeighted = false ) :
125  FitData( n, isWeighted ? dim + 1 : dim, dataItr ),
126  fWeighted( isWeighted )
127  {
128  assert( dim >= 1 );
129  assert( !fWeighted || dim >= 2 );
130  }
131 
132  /**
133  constructor for 1D data and a range (data are copied inside according to the given range)
134  */
135  UnBinData(unsigned int maxpoints, const double * dataX, const DataRange & range) :
136  FitData( range, maxpoints, dataX ),
137  fWeighted( false )
138  {
139  }
140 
141 
142  /**
143  constructor for 2D data and a range (data are copied inside according to the given range)
144  or 1 1D data set + weight. If is weighted dataY is the pointer to the list of the weights
145  */
146  UnBinData(unsigned int maxpoints, const double * dataX, const double * dataY,
147  const DataRange & range, bool isWeighted = false) :
148  FitData( range, maxpoints, dataX, dataY ),
149  fWeighted( isWeighted )
150  {
151  }
152 
153  /**
154  constructor for 3D data and a range (data are copied inside according to the given range)
155  or a 2D data set + weights. If is weighted dataZ is the pointer to the list of the weights
156  */
157  UnBinData(unsigned int maxpoints, const double * dataX, const double * dataY,
158  const double * dataZ, const DataRange & range, bool isWeighted = false) :
159  FitData( range, maxpoints, dataX, dataY, dataZ ),
160  fWeighted( isWeighted )
161  {
162  }
163 
164  /**
165  constructor for multi-dim external data and a range (data are copied inside according to the range)
166  Uses as argument an iterator of a list (or vector) containing the const double * of the data
167  An example could be the std::vector<const double *>::begin
168  */
169  template<class Iterator>
170  UnBinData( unsigned int maxpoints, unsigned int dim, Iterator dataItr, const DataRange & range, bool isWeighted = false ) :
171  FitData( range, maxpoints, dim, dataItr ),
172  fWeighted( isWeighted )
173  {
174  }
175 
176 private:
177  /// copy constructor (private)
178  UnBinData(const UnBinData &) : FitData() { assert(false); }
179  /// assignment operator (private)
180  UnBinData & operator= (const UnBinData &) { assert(false); return *this; }
181 
182 public:
183  /**
184  destructor, delete pointer to internal data or external data wrapper
185  */
186  virtual ~UnBinData() {
187  }
188 
189  /**
190  preallocate a data set given size and dimension of the coordinates
191  if a vector already exists with correct dimension (point size) extend the existing one
192  to a total size of maxpoints (equivalent to a Resize)
193  */
194  //void Initialize(unsigned int maxpoints, unsigned int dim = 1, bool isWeighted = false);
195 
196 
197  /**
198  add one dim coordinate data (unweighted)
199  */
200  void Add(double x)
201  {
202  assert( !fWeighted );
203 
204  FitData::Add( x );
205  }
206 
207 
208  /**
209  add 2-dim coordinate data
210  can also be used to add 1-dim data with a weight
211  */
212  void Add(double x, double y)
213  {
214  assert( fDim == 2 );
215  double dataTmp[] = { x, y };
216 
217  FitData::Add( dataTmp );
218  }
219 
220  /**
221  add 3-dim coordinate data
222  can also be used to add 2-dim data with a weight
223  */
224  void Add(double x, double y, double z)
225  {
226  assert( fDim == 3 );
227  double dataTmp[] = { x, y, z };
228 
229  FitData::Add( dataTmp );
230  }
231 
232  /**
233  add multi-dim coordinate data
234  */
235  void Add( const double* x )
236  {
237  FitData::Add( x );
238  }
239 
240  /**
241  add multi-dim coordinate data + weight
242  */
243  void Add(const double *x, double w)
244  {
245  assert( fWeighted );
246 
247  std::vector<double> tmpVec(fDim);
248  std::copy( x, x + fDim - 1, tmpVec.begin() );
249  tmpVec[fDim-1] = w;
250 
251  FitData::Add( &tmpVec.front() );
252  }
253 
254  /**
255  return weight
256  */
257  double Weight( unsigned int ipoint ) const
258  {
259  assert( ipoint < fNPoints );
260 
261  if ( !fWeighted ) return 1.0;
262  return *GetCoordComponent(ipoint, fDim-1);
263  }
264 
265  const double * WeightsPtr( unsigned int ipoint ) const
266  {
267  assert( ipoint < fNPoints );
268 
269  if ( !fWeighted ){
270  MATH_ERROR_MSG("UnBinData::WeightsPtr","The function is unweighted!");
271  return nullptr;
272  }
273  return GetCoordComponent(ipoint, fDim-1);
274  }
275 
276 
277  /**
278  return coordinate data dimension
279  */
280  unsigned int NDim() const
281  { return fWeighted ? fDim -1 : fDim; }
282 
283  bool IsWeighted() const
284  {
285  return fWeighted;
286  }
287 
288  void Append( unsigned int newPoints, unsigned int dim = 1, bool isWeighted = false )
289  {
290  assert( !fWrapped );
291 
292  fWeighted = isWeighted;
293 
294  FitData::Append( newPoints, dim );
295  }
296 
297 private:
298  bool fWeighted;
299 
300 };
301 
302 
303  } // end namespace Fit
304 
305 } // end namespace ROOT
306 
307 
308 
309 #endif /* ROOT_Fit_UnBinData */
UnBinData(unsigned int n, unsigned int dim, Iterator dataItr, bool isWeighted=false)
constructor for multi-dim external data (data are not copied inside) Uses as argument an iterator of ...
Definition: UnBinData.h:123
unsigned int NDim() const
return coordinate data dimension
Definition: UnBinData.h:280
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
UnBinData(unsigned int maxpoints, const double *dataX, const DataRange &range)
constructor for 1D data and a range (data are copied inside according to the given range) ...
Definition: UnBinData.h:135
Base class for all the fit data types: Stores the coordinates and the DataOptions.
Definition: FitData.h:66
Class describing the unbinned data sets (just x coordinates values) of any dimensions.
Definition: UnBinData.h:42
you should not use this method at all Int_t y
Definition: TRolke.cxx:630
UnBinData(unsigned int n, const double *dataX, const double *dataY, const double *dataZ, bool isWeighted=false)
constructor for 3D external data (data are not copied inside) or 2D data with a weight (if isWeighted...
Definition: UnBinData.h:108
const double * GetCoordComponent(unsigned int ipoint, unsigned int icoord) const
returns a single coordinate component of a point.
Definition: FitData.h:229
UnBinData(unsigned int maxpoints, const double *dataX, const double *dataY, const double *dataZ, const DataRange &range, bool isWeighted=false)
constructor for 3D data and a range (data are copied inside according to the given range) or a 2D dat...
Definition: UnBinData.h:157
void Append(unsigned int newPoints, unsigned int dim=1)
Definition: FitData.cxx:248
void Add(double x, double y)
add 2-dim coordinate data can also be used to add 1-dim data with a weight
Definition: UnBinData.h:212
UnBinData(const DataOptions &opt, const DataRange &range, unsigned int maxpoints=0, unsigned int dim=1, bool isWeighted=false)
constructor from options and range
Definition: UnBinData.h:75
#define MATH_ERROR_MSG(loc, str)
Definition: Error.h:50
void Add(double x, double y, double z)
add 3-dim coordinate data can also be used to add 2-dim data with a weight
Definition: UnBinData.h:224
void Add(const double *x, double w)
add multi-dim coordinate data + weight
Definition: UnBinData.h:243
bool IsWeighted() const
Definition: UnBinData.h:283
double Weight(unsigned int ipoint) const
return weight
Definition: UnBinData.h:257
DataOptions : simple structure holding the options on how the data are filled.
Definition: DataOptions.h:28
UnBinData & operator=(const UnBinData &)
assignment operator (private)
Definition: UnBinData.h:180
void Add(double x)
add one dim data with only coordinate and values
Definition: FitData.h:264
UnBinData(unsigned int n, const double *dataX)
constructor for 1D external data (data are not copied inside)
Definition: UnBinData.h:87
UnBinData(const UnBinData &)
copy constructor (private)
Definition: UnBinData.h:178
UnBinData(unsigned int maxpoints, unsigned int dim, Iterator dataItr, const DataRange &range, bool isWeighted=false)
constructor for multi-dim external data and a range (data are copied inside according to the range) U...
Definition: UnBinData.h:170
UnBinData(const DataRange &range, unsigned int maxpoints=0, unsigned int dim=1, bool isWeighted=false)
constructor from range and default option
Definition: UnBinData.h:63
* x
Deprecated and error prone model selection interface.
Definition: TRolke.cxx:630
virtual ~UnBinData()
destructor, delete pointer to internal data or external data wrapper
Definition: UnBinData.h:186
UnBinData(unsigned int n, const double *dataX, const double *dataY, bool isWeighted=false)
constructor for 2D external data (data are not copied inside) or 1D data with a weight (if isWeighted...
Definition: UnBinData.h:97
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition: DataRange.h:34
void Add(double x)
preallocate a data set given size and dimension of the coordinates if a vector already exists with co...
Definition: UnBinData.h:200
unsigned int fNPoints
Definition: FitData.h:395
void Append(unsigned int newPoints, unsigned int dim=1, bool isWeighted=false)
Definition: UnBinData.h:288
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
unsigned int fDim
Definition: FitData.h:396
void Add(const double *x)
add multi-dim coordinate data
Definition: UnBinData.h:235
UnBinData(unsigned int maxpoints, const double *dataX, const double *dataY, const DataRange &range, bool isWeighted=false)
constructor for 2D data and a range (data are copied inside according to the given range) or 1 1D dat...
Definition: UnBinData.h:146
const double * WeightsPtr(unsigned int ipoint) const
Definition: UnBinData.h:265
UnBinData(unsigned int maxpoints=0, unsigned int dim=1, bool isWeighted=false)
constructor from dimension of point and max number of points (to pre-allocate vector) ...
Definition: UnBinData.h:50