File indexing completed on 2026-09-25 09:27:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_Fit_FitData
0014 #define ROOT_Fit_FitData
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #include "Fit/DataOptions.h"
0026 #include "Fit/DataRange.h"
0027 #include "Math/Types.h"
0028
0029 #include <algorithm>
0030 #include <vector>
0031 #include <cassert>
0032
0033 namespace ROOT {
0034
0035 namespace Fit {
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 class FitData {
0056 public:
0057
0058
0059 explicit FitData(unsigned int maxpoints = 0, unsigned int dim = 1);
0060
0061
0062 explicit FitData(const DataOptions &opt, unsigned int maxpoints = 0, unsigned int dim = 1);
0063
0064
0065
0066 explicit FitData(const DataRange &range, unsigned int maxpoints = 0, unsigned int dim = 1);
0067
0068
0069 FitData(const DataOptions &opt, const DataRange &range,
0070 unsigned int maxpoints = 0, unsigned int dim = 1);
0071
0072
0073 FitData(unsigned int n, const double *dataX);
0074
0075
0076 FitData(unsigned int n, const double *dataX, const double *dataY);
0077
0078
0079 FitData(unsigned int n, const double *dataX, const double *dataY,
0080 const double *dataZ);
0081
0082
0083
0084
0085
0086
0087 FitData(const DataRange &range, unsigned int maxpoints, const double *dataX);
0088
0089
0090
0091
0092
0093
0094 FitData(const DataRange &range, unsigned int maxpoints, const double *dataX, const double *dataY);
0095
0096
0097
0098
0099
0100
0101 FitData(const DataRange &range, unsigned int maxpoints, const double *dataX, const double *dataY,
0102 const double *dataZ);
0103
0104
0105
0106
0107
0108
0109
0110
0111 template<class Iterator>
0112 FitData(unsigned int n, unsigned int dim, Iterator dataItr) :
0113 fWrapped(true),
0114 fMaxPoints(n),
0115 fNPoints(fMaxPoints),
0116 fDim(dim),
0117 fCoordsPtr(fDim),
0118 fpTmpCoordVector(nullptr)
0119 {
0120 assert(fDim >= 1);
0121 for (unsigned int i = 0; i < fDim; i++) {
0122 fCoordsPtr[i] = *dataItr++;
0123 }
0124
0125 if (fpTmpCoordVector) {
0126 delete[] fpTmpCoordVector;
0127 fpTmpCoordVector = nullptr;
0128 }
0129
0130 fpTmpCoordVector = new double [fDim];
0131 }
0132
0133
0134
0135
0136
0137
0138 template<class Iterator>
0139 FitData(const DataRange &range, unsigned int maxpoints, unsigned int dim, Iterator dataItr) :
0140 fWrapped(false),
0141 fRange(range),
0142 fMaxPoints(maxpoints),
0143 fNPoints(0),
0144 fDim(dim),
0145 fpTmpCoordVector(nullptr)
0146 {
0147 assert(fDim >= 1);
0148 InitCoordsVector();
0149
0150 InitFromRange(dataItr);
0151 }
0152
0153
0154 virtual ~FitData();
0155
0156 FitData(const FitData &rhs);
0157
0158 FitData &operator= (const FitData &rhs);
0159
0160 void Append(unsigned int newPoints, unsigned int dim = 1);
0161
0162 protected:
0163
0164
0165
0166
0167
0168
0169
0170 void InitCoordsVector()
0171 {
0172 fCoords.resize(fDim);
0173 fCoordsPtr.resize(fDim);
0174
0175 for (unsigned int i = 0; i < fDim; i++) {
0176 fCoords[i].resize(fMaxPoints + VectorPadding(fMaxPoints));
0177 fCoordsPtr[i] = fCoords[i].empty() ? nullptr : &fCoords[i].front();
0178 }
0179
0180 if (fpTmpCoordVector) {
0181 delete[] fpTmpCoordVector;
0182 fpTmpCoordVector = nullptr;
0183 }
0184
0185 fpTmpCoordVector = new double [fDim];
0186 }
0187
0188 template<class Iterator>
0189 void InitFromRange(Iterator dataItr)
0190 {
0191 for (unsigned int i = 0; i < fMaxPoints; i++) {
0192 bool isInside = true;
0193 Iterator tmpItr = dataItr;
0194
0195 for (unsigned int j = 0; j < fDim; j++)
0196 isInside &= fRange.IsInside((*tmpItr++)[i], j);
0197
0198 if (isInside) {
0199 tmpItr = dataItr;
0200
0201 for (unsigned int k = 0; k < fDim; k++)
0202 fpTmpCoordVector[k] = (*tmpItr++)[i];
0203
0204 Add(fpTmpCoordVector);
0205 }
0206 }
0207 }
0208
0209
0210 public:
0211
0212
0213
0214
0215
0216
0217
0218 const double *GetCoordComponent(unsigned int ipoint, unsigned int icoord) const
0219 {
0220 assert(ipoint < fMaxPoints + VectorPadding(fMaxPoints));
0221 assert(icoord < fDim);
0222 assert(fCoordsPtr.size() == fDim);
0223 assert(fCoordsPtr[icoord]);
0224 assert(fCoords.empty() || &fCoords[icoord].front() == fCoordsPtr[icoord]);
0225
0226 return &fCoordsPtr[icoord][ipoint];
0227 }
0228
0229
0230
0231
0232
0233
0234
0235 const double *Coords(unsigned int ipoint) const
0236 {
0237 assert(fpTmpCoordVector);
0238 assert(ipoint < fMaxPoints + VectorPadding(fMaxPoints));
0239
0240 for (unsigned int i = 0; i < fDim; i++) {
0241 assert(fCoordsPtr[i]);
0242 assert(fCoords.empty() || &fCoords[i].front() == fCoordsPtr[i]);
0243
0244 fpTmpCoordVector[i] = fCoordsPtr[i][ipoint];
0245 }
0246
0247 return fpTmpCoordVector;
0248 }
0249
0250
0251
0252
0253 void Add(double x)
0254 {
0255 assert(!fWrapped);
0256 assert(!fCoordsPtr.empty() && fCoordsPtr.size() == 1 && fCoordsPtr[0]);
0257 assert(1 == fDim);
0258 assert(fNPoints < fMaxPoints);
0259
0260 fCoords[0][ fNPoints ] = x;
0261
0262 fNPoints++;
0263 }
0264
0265
0266
0267
0268 void Add(const double *x)
0269 {
0270 assert(!fWrapped);
0271 assert(!fCoordsPtr.empty() && fCoordsPtr.size() == fDim);
0272 assert(fNPoints < fMaxPoints);
0273
0274 for (unsigned int i = 0; i < fDim; i++) {
0275 fCoords[i][ fNPoints ] = x[i];
0276 }
0277
0278 fNPoints++;
0279 }
0280
0281
0282
0283
0284 unsigned int NPoints() const
0285 {
0286 return fNPoints;
0287 }
0288
0289
0290
0291
0292 unsigned int Size() const
0293 {
0294 return fNPoints;
0295 }
0296
0297
0298
0299
0300 unsigned int NDim() const
0301 {
0302 return fDim;
0303 }
0304
0305
0306
0307
0308 const DataOptions &Opt() const
0309 {
0310 return fOptions;
0311 }
0312 DataOptions &Opt()
0313 {
0314 return fOptions;
0315 }
0316
0317
0318
0319
0320 const DataRange &Range() const
0321 {
0322 return fRange;
0323 }
0324
0325
0326
0327
0328 const std::vector< const double * > &GetCoordDataPtrs() const
0329 {
0330 return fCoordsPtr;
0331 }
0332
0333
0334 protected:
0335 void UnWrap()
0336 {
0337 assert(fWrapped);
0338 assert(fCoords.empty());
0339
0340 fCoords.resize(fDim);
0341 for (unsigned int i = 0; i < fDim; i++) {
0342 assert(fCoordsPtr[i]);
0343 unsigned padding = VectorPadding(fNPoints);
0344 fCoords[i].resize(fNPoints + padding);
0345 std::copy(fCoordsPtr[i], fCoordsPtr[i] + fNPoints + padding, fCoords[i].begin());
0346 fCoordsPtr[i] = fCoords[i].empty() ? nullptr : &fCoords[i].front();
0347 }
0348
0349 fWrapped = false;
0350 }
0351
0352 #ifdef R__HAS_STD_EXPERIMENTAL_SIMD
0353
0354
0355
0356
0357 static unsigned VectorPadding(unsigned dataSize)
0358 {
0359 unsigned padding = 0;
0360 unsigned modP = (dataSize) % ROOT::Double_v::size();
0361 if (modP > 0)
0362 padding = ROOT::Double_v::size() - modP;
0363 return padding;
0364 }
0365 #else
0366
0367
0368
0369
0370
0371 static constexpr unsigned VectorPadding(const unsigned) { return 0; }
0372 #endif
0373
0374 protected:
0375 bool fWrapped;
0376
0377 private:
0378
0379 DataOptions fOptions;
0380 DataRange fRange;
0381
0382 protected:
0383 unsigned int fMaxPoints;
0384 unsigned int fNPoints;
0385 unsigned int fDim;
0386
0387 private:
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402 std::vector< std::vector< double > > fCoords;
0403 std::vector< const double * > fCoordsPtr;
0404
0405 double *fpTmpCoordVector;
0406
0407 };
0408
0409 }
0410
0411 }
0412
0413
0414
0415 #endif