Logo ROOT  
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 #include <vector>
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 */
ROOT::Fit::FitData
Base class for all the fit data types: Stores the coordinates and the DataOptions.
Definition: FitData.h:66
n
const Int_t n
Definition: legend1.C:16
ROOT::Fit::UnBinData::Append
void Append(unsigned int newPoints, unsigned int dim=1, bool isWeighted=false)
Definition: UnBinData.h:303
ROOT::Fit::FitData::fWrapped
bool fWrapped
Definition: FitData.h:386
HFit::Fit
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
ROOT::Fit::DataOptions
DataOptions : simple structure holding the options on how the data are filled.
Definition: DataOptions.h:38
ROOT::Fit::FitData::GetCoordComponent
const double * GetCoordComponent(unsigned int ipoint, unsigned int icoord) const
returns a single coordinate component of a point.
Definition: FitData.h:229
ROOT::Fit::UnBinData
Class describing the unbinned data sets (just x coordinates values) of any dimensions.
Definition: UnBinData.h:52
ROOT::Fit::UnBinData::NDim
unsigned int NDim() const
return coordinate data dimension
Definition: UnBinData.h:295
ROOT::Fit::UnBinData::WeightsPtr
const double * WeightsPtr(unsigned int ipoint) const
Definition: UnBinData.h:280
x
Double_t x[n]
Definition: legend1.C:17
ROOT::Fit::FitData::Append
void Append(unsigned int newPoints, unsigned int dim=1)
Definition: FitData.cxx:258
ROOT::Fit::FitData::Add
void Add(double x)
add one dim data with only coordinate and values
Definition: FitData.h:264
MATH_ERROR_MSG
#define MATH_ERROR_MSG(loc, str)
Definition: Error.h:83
ROOT::Fit::UnBinData::UnBinData
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:123
ROOT::Fit::UnBinData::Weight
double Weight(unsigned int ipoint) const
return weight
Definition: UnBinData.h:272
ROOT::Fit::UnBinData::~UnBinData
virtual ~UnBinData()
destructor, delete pointer to internal data or external data wrapper
Definition: UnBinData.h:201
ROOT::Fit::UnBinData::operator=
UnBinData & operator=(const UnBinData &)
assignment operator (private)
Definition: UnBinData.h:195
ROOT::Fit::UnBinData::Add
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:215
Error.h
ROOT::Fit::FitData::fNPoints
unsigned int fNPoints
Definition: FitData.h:395
ROOT::Fit::DataRange
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition: DataRange.h:45
y
Double_t y[n]
Definition: legend1.C:17
ROOT::Fit::UnBinData::IsWeighted
bool IsWeighted() const
Definition: UnBinData.h:298
FitData.h
ROOT::Fit::UnBinData::UnBinData
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:65
ROOT::Fit::UnBinData::fWeighted
bool fWeighted
Definition: UnBinData.h:313
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Fit::FitData::fDim
unsigned int fDim
Definition: FitData.h:396