Logo ROOT   6.10/09
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(NULL)
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),
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),
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),
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),
83  {
84  assert(dataX);
85  fCoordsPtr[0] = dataX;
86 
87  if (fpTmpCoordVector) {
88  delete fpTmpCoordVector;
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),
103  {
104  assert(dataX && dataY);
105  fCoordsPtr[0] = dataX;
106  fCoordsPtr[1] = dataY;
107 
108  if (fpTmpCoordVector) {
109  delete fpTmpCoordVector;
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),
122  fDim(3),
123  fCoordsPtr(fDim),
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;
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),
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),
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),
192  {
194 
195  const double *ptrList[] = { dataX, dataY, dataZ };
196 
197  InitFromRange(ptrList);
198  }
199 
200  /// dummy virtual destructor
202  {
203  for (unsigned int i = 0; i < fDim; i++) {
204  assert(fWrapped == fCoords.empty());
205  assert(fCoords.empty() || &fCoords[i].front() == fCoordsPtr[i]);
206  }
207 
208  }
209 
211  {
212  *this = rhs;
213  }
214 
216  {
217  fWrapped = rhs.fWrapped;
218  fOptions = rhs.fOptions;
219  fRange = rhs.fRange;
220  fDim = rhs.fDim;
221  fMaxPoints = rhs.fMaxPoints;
222 
223  if (fWrapped) {
224  fCoords.clear();
225 
226  fCoordsPtr = rhs.fCoordsPtr;
227  } else {
228  fCoords = rhs.fCoords;
229 
230  fCoordsPtr.resize(fDim);
231 
232  for (unsigned int i = 0; i < fDim; i++) {
233  fCoordsPtr[i] = &fCoords[i].front();
234  }
235  }
236 
237  if (fpTmpCoordVector) {
238  delete fpTmpCoordVector;
240  }
241 
242  fpTmpCoordVector = new double [fDim];
243 
244  return *this;
245  }
246 
247  void FitData::Append(unsigned int newPoints, unsigned int dim)
248  {
249  assert(!fWrapped);
250 
251  fMaxPoints = fMaxPoints + newPoints;
252  fDim = dim;
253 
255  }
256 
257  } // end namespace Fit
258 
259 } // end namespace ROOT
double * fpTmpCoordVector
Definition: FitData.h:392
Namespace for new ROOT classes and functions.
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:65
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:389
#define NULL
Definition: RtypesCore.h:88
DataOptions fOptions
Definition: FitData.h:366
void Append(unsigned int newPoints, unsigned int dim=1)
Definition: FitData.cxx:247
void InitCoordsVector()
initializer routines to set the corresponding pointers right The vectors must NOT be resized after th...
Definition: FitData.h:180
DataOptions : simple structure holding the options on how the data are filled.
Definition: DataOptions.h:28
DataRange fRange
Definition: FitData.h:367
std::vector< const double *> fCoordsPtr
Definition: FitData.h:390
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
unsigned int fNPoints
Definition: FitData.h:371
FitData & operator=(const FitData &rhs)
Definition: FitData.cxx:215
unsigned int fDim
Definition: FitData.h:372
unsigned int fMaxPoints
Definition: FitData.h:370
void InitFromRange(Iterator dataItr)
Definition: FitData.h:199
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