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