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