Project
Loading...
Searching...
No Matches
ChebyshevFit1D.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#ifndef ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_CHEBYSHEVFIT1D_H
18#define ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_CHEBYSHEVFIT1D_H
19
20#include "GPUCommonDef.h"
21#include <vector>
22
23namespace o2::gpu
24{
30{
31 public:
33 {
34 reset(0, -1., 1.);
35 }
36
37 ChebyshevFit1D(int32_t order, double xMin, double xMax)
38 {
39 reset(order, xMin, xMax);
40 }
41
42 ~ChebyshevFit1D() = default;
43
44 void reset(int32_t order, double xMin, double xMax);
45
46 void reset();
47
48 void addMeasurement(double x, double m);
49
50 void fit();
51
52 double eval(double x);
53
54 int32_t getNmeasurements() const { return mM; }
55
56 const std::vector<double>& getCoefficients() const { return mC; }
57
58 void print();
59
60 private:
61 int32_t mN = 0; // n coefficients == polynom order + 1
62 int32_t mM = 0; // number of measurenents
63 double mXmin = -1.; // min of X segment
64 double mXscale = 1; // scaling factor (x-mXmin) to [-1,1]
65 std::vector<double> mA; // fit matiix
66 std::vector<double> mB; // fit vector
67 std::vector<double> mC; // Chebyshev coefficients
68 std::vector<double> mT; // Chebyshev coefficients
69};
70
71inline void ChebyshevFit1D::addMeasurement(double x, double m)
72{
73 x = -1. + (x - mXmin) * mXscale;
74 mT[0] = 1;
75 mT[1] = x;
76 x *= 2.;
77 for (int32_t i = 2; i < mN; i++) {
78 mT[i] = x * mT[i - 1] - mT[i - 2];
79 }
80 double* Ai = mA.data();
81 for (int32_t i = 0; i < mN; i++, Ai += mN) {
82 for (int32_t j = i; j < mN; j++) {
83 Ai[j] += mT[i] * mT[j];
84 }
85 mB[i] += m * mT[i];
86 }
87 mM++;
88}
89
90inline double ChebyshevFit1D::eval(double x)
91{
92 x = -1. + (x - mXmin) * mXscale;
93 double y = mC[0] + mC[1] * x;
94 double f0 = 1.;
95 double f1 = x;
96 x *= 2;
97 for (int32_t i = 2; i < mN; i++) {
98 double f = x * f1 - f0;
99 y += mC[i] * f;
100 f0 = f1;
101 f1 = f;
102 }
103 return y;
104}
105
106} // namespace o2::gpu
107
108#endif
int32_t i
uint32_t j
Definition RawData.h:0
void addMeasurement(double x, double m)
double eval(double x)
const std::vector< double > & getCoefficients() const
int32_t getNmeasurements() const
ChebyshevFit1D(int32_t order, double xMin, double xMax)
GLint GLenum GLint x
Definition glcorearb.h:403
const GLfloat * m
Definition glcorearb.h:4066
GLdouble f
Definition glcorearb.h:310
GLint y
Definition glcorearb.h:270