Logo ROOT  
Reference Guide
FitData.cxx
Go to the documentation of this file.
1// @(#)root/mathcore:$Id: FitData.cxx 45049 2012-07-13 12:31:59Z mborinsk $
2// Author: M. Borinsky
3
4
5/**********************************************************************
6 * *
7 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
8 * *
9 * *
10 **********************************************************************/
11
12
13#include "Fit/FitData.h"
14
15// Implementation file for class FitData
16
17namespace ROOT {
18
19 namespace Fit {
20 FitData::FitData(unsigned int maxpoints, unsigned int dim) :
21 fWrapped(false),
22 fMaxPoints(maxpoints),
23 fNPoints(0),
24 fDim(dim),
25 fpTmpCoordVector(nullptr)
26 {
27 assert(fDim >= 1);
29 }
30
31 /// construct passing options and default data range
32 FitData::FitData(const DataOptions &opt, unsigned int maxpoints, unsigned int dim) :
33 fWrapped(false),
34 fOptions(opt),
35 fMaxPoints(maxpoints),
36 fNPoints(0),
37 fDim(dim),
38 fpTmpCoordVector(nullptr)
39 {
40 assert(fDim >= 1);
42 }
43
44
45 /// construct passing range and default options
46 FitData::FitData(const DataRange &range, unsigned int maxpoints, unsigned int dim) :
47 fWrapped(false),
48 fRange(range),
49 fMaxPoints(maxpoints),
50 fNPoints(0),
51 fDim(dim),
52 fpTmpCoordVector(nullptr)
53 {
54 assert(fDim >= 1);
56 }
57
58 /// construct passing options and data range
59 FitData::FitData(const DataOptions &opt, const DataRange &range,
60 unsigned int maxpoints, unsigned int dim) :
61 fWrapped(false),
62 fOptions(opt),
63 fRange(range),
64 fMaxPoints(maxpoints),
65 fNPoints(0),
66 fDim(dim),
67 fCoords(fDim),
68 fCoordsPtr(fDim),
69 fpTmpCoordVector(nullptr)
70 {
71 assert(fDim >= 1);
73 }
74
75 /// constructor from external data for 1D data
76 FitData::FitData(unsigned int n, const double *dataX) :
77 fWrapped(true),
78 fMaxPoints(n),
79 fNPoints(n),
80 fDim(1),
81 fCoordsPtr(fDim),
82 fpTmpCoordVector(nullptr)
83 {
84 assert(dataX);
85 fCoordsPtr[0] = dataX;
86
87 if (fpTmpCoordVector) {
88 delete[] fpTmpCoordVector;
89 fpTmpCoordVector = nullptr;
90 }
91
92 fpTmpCoordVector = new double [fDim];
93 }
94
95 /// constructor from external data for 2D data
96 FitData::FitData(unsigned int n, const double *dataX, const double *dataY) :
97 fWrapped(true),
98 fMaxPoints(n),
99 fNPoints(n),
100 fDim(2),
101 fCoordsPtr(fDim),
102 fpTmpCoordVector(nullptr)
103 {
104 assert(dataX && dataY);
105 fCoordsPtr[0] = dataX;
106 fCoordsPtr[1] = dataY;
107
108 if (fpTmpCoordVector) {
109 delete[] fpTmpCoordVector;
110 fpTmpCoordVector = nullptr;
111 }
112
113 fpTmpCoordVector = new double [fDim];
114 }
115
116 /// constructor from external data for 3D data
117 FitData::FitData(unsigned int n, const double *dataX, const double *dataY,
118 const double *dataZ) :
119 fWrapped(true),
120 fMaxPoints(n),
121 fNPoints(fMaxPoints),
122 fDim(3),
123 fCoordsPtr(fDim),
124 fpTmpCoordVector(nullptr)
125 {
126 assert(dataX && dataY && dataZ);
127 fCoordsPtr[0] = dataX;
128 fCoordsPtr[1] = dataY;
129 fCoordsPtr[2] = dataZ;
130
131 if (fpTmpCoordVector) {
132 delete[] fpTmpCoordVector;
133 fpTmpCoordVector = nullptr;
134 }
135
136 fpTmpCoordVector = new double [fDim];
137 }
138
139 /**
140 constructor for multi-dim external data and a range (data are copied inside according to the range)
141 Uses as argument an iterator of a list (or vector) containing the const double * of the data
142 An example could be the std::vector<const double *>::begin
143 */
144 FitData::FitData(const DataRange &range, unsigned int maxpoints, const double *dataX) :
145 fWrapped(false),
146 fRange(range),
147 fMaxPoints(maxpoints),
148 fNPoints(0),
149 fDim(1),
150 fpTmpCoordVector(nullptr)
151 {
153
154 const double *ptrList[] = { dataX };
155
156 InitFromRange(ptrList);
157 }
158
159 /**
160 constructor for multi-dim external data and a range (data are copied inside according to the range)
161 Uses as argument an iterator of a list (or vector) containing the const double * of the data
162 An example could be the std::vector<const double *>::begin
163 */
164 FitData::FitData(const DataRange &range, unsigned int maxpoints, const double *dataX, const double *dataY) :
165 fWrapped(false),
166 fRange(range),
167 fMaxPoints(maxpoints),
168 fNPoints(0),
169 fDim(2),
170 fpTmpCoordVector(nullptr)
171 {
173
174 const double *ptrList[] = { dataX, dataY };
175
176 InitFromRange(ptrList);
177 }
178
179 /**
180 constructor for multi-dim external data and a range (data are copied inside according to the range)
181 Uses as argument an iterator of a list (or vector) containing the const double * of the data
182 An example could be the std::vector<const double *>::begin
183 */
184 FitData::FitData(const DataRange &range, unsigned int maxpoints, const double *dataX, const double *dataY,
185 const double *dataZ) :
186 fWrapped(false),
187 fRange(range),
188 fMaxPoints(maxpoints),
189 fNPoints(0),
190 fDim(3),
191 fpTmpCoordVector(nullptr)
192 {
194
195 const double *ptrList[] = { dataX, dataY, dataZ };
196
197 InitFromRange(ptrList);
198 }
199
200 /// dummy virtual destructor
202 {
203 assert(fWrapped == fCoords.empty());
204 for (unsigned int i = 0; i < fDim; i++) {
205 assert(fWrapped || fCoords[i].empty() || &fCoords[i].front() == fCoordsPtr[i]);
206 }
208
209 }
210
212 : fWrapped(false), fMaxPoints(0), fNPoints(0), fDim(0),
213 fpTmpCoordVector(nullptr)
214 {
215 *this = rhs;
216 }
217
219 {
220 fWrapped = rhs.fWrapped;
221 fOptions = rhs.fOptions;
222 fRange = rhs.fRange;
223 fDim = rhs.fDim;
225
226 if (fWrapped) {
227 fCoords.clear();
228
230 } else {
231 fCoords = rhs.fCoords;
232
233 fCoordsPtr.resize(fDim);
234
235 for (unsigned int i = 0; i < fDim; i++) {
236 fCoordsPtr[i] = fCoords[i].empty() ? nullptr : &fCoords[i].front();
237 }
238 }
239
240 if (fpTmpCoordVector) {
241 delete[] fpTmpCoordVector;
242 fpTmpCoordVector = nullptr;
243 }
244
245 fpTmpCoordVector = new double [fDim];
246
247 return *this;
248 }
249
250 void FitData::Append(unsigned int newPoints, unsigned int dim)
251 {
252 assert(!fWrapped);
253
254 fMaxPoints = fMaxPoints + newPoints;
255 fDim = dim;
256
258 }
259
260 } // end namespace Fit
261
262} // end namespace ROOT
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:66
double * fpTmpCoordVector
Definition: FitData.h:416
FitData(unsigned int maxpoints=0, unsigned int dim=1)
construct with default option and data range
Definition: FitData.cxx:20
void InitCoordsVector()
initializer routines to set the corresponding pointers right The vectors must NOT be resized after th...
Definition: FitData.h:181
DataRange fRange
Definition: FitData.h:391
void Append(unsigned int newPoints, unsigned int dim=1)
Definition: FitData.cxx:250
std::vector< std::vector< double > > fCoords
This vector stores the vectorizable data: The inner vectors contain the coordinates data fCoords[0] i...
Definition: FitData.h:413
unsigned int fMaxPoints
Definition: FitData.h:394
std::vector< const double * > fCoordsPtr
Definition: FitData.h:414
void InitFromRange(Iterator dataItr)
Definition: FitData.h:200
DataOptions fOptions
Definition: FitData.h:390
unsigned int fDim
Definition: FitData.h:396
FitData & operator=(const FitData &rhs)
Definition: FitData.cxx:218
virtual ~FitData()
dummy virtual destructor
Definition: FitData.cxx:201
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