Logo ROOT   master
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 
17 namespace 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  }
207  if (fpTmpCoordVector) delete[] fpTmpCoordVector;
208 
209  }
210 
212  {
213  *this = rhs;
214  }
215 
217  {
218  fWrapped = rhs.fWrapped;
219  fOptions = rhs.fOptions;
220  fRange = rhs.fRange;
221  fDim = rhs.fDim;
222  fMaxPoints = rhs.fMaxPoints;
223 
224  if (fWrapped) {
225  fCoords.clear();
226 
227  fCoordsPtr = rhs.fCoordsPtr;
228  } else {
229  fCoords = rhs.fCoords;
230 
231  fCoordsPtr.resize(fDim);
232 
233  for (unsigned int i = 0; i < fDim; i++) {
234  fCoordsPtr[i] = fCoords[i].empty() ? nullptr : &fCoords[i].front();
235  }
236  }
237 
238  if (fpTmpCoordVector) {
239  delete[] fpTmpCoordVector;
240  fpTmpCoordVector = nullptr;
241  }
242 
243  fpTmpCoordVector = new double [fDim];
244 
245  return *this;
246  }
247 
248  void FitData::Append(unsigned int newPoints, unsigned int dim)
249  {
250  assert(!fWrapped);
251 
252  fMaxPoints = fMaxPoints + newPoints;
253  fDim = dim;
254 
256  }
257 
258  } // end namespace Fit
259 
260 } // end namespace ROOT
double * fpTmpCoordVector
Definition: FitData.h:416
Returns the available number of logical cores.
Definition: StringConv.hxx:21
virtual ~FitData()
dummy virtual destructor
Definition: FitData.cxx:201
Base class for all the fit data types: Stores the coordinates and the DataOptions.
Definition: FitData.h:66
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
DataOptions fOptions
Definition: FitData.h:390
void Append(unsigned int newPoints, unsigned int dim=1)
Definition: FitData.cxx:248
void InitCoordsVector()
initializer routines to set the corresponding pointers right The vectors must NOT be resized after th...
Definition: FitData.h:181
DataOptions : simple structure holding the options on how the data are filled.
Definition: DataOptions.h:28
DataRange fRange
Definition: FitData.h:391
std::vector< const double *> fCoordsPtr
Definition: FitData.h:414
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition: DataRange.h:34
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:134
FitData & operator=(const FitData &rhs)
Definition: FitData.cxx:216
unsigned int fDim
Definition: FitData.h:396
unsigned int fMaxPoints
Definition: FitData.h:394
void InitFromRange(Iterator dataItr)
Definition: FitData.h:200
const Int_t n
Definition: legend1.C:16
FitData(unsigned int maxpoints=0, unsigned int dim=1)
construct with default option and data range
Definition: FitData.cxx:20