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
24{
25namespace gpu
26{
32{
33 public:
35 {
36 reset(0, -1., 1.);
37 }
38
39 ChebyshevFit1D(int32_t order, double xMin, double xMax)
40 {
41 reset(order, xMin, xMax);
42 }
43
44 ~ChebyshevFit1D() = default;
45
46 void reset(int32_t order, double xMin, double xMax);
47
48 void reset();
49
50 void addMeasurement(double x, double m);
51
52 void fit();
53
54 double eval(double x);
55
56 int32_t getNmeasurements() const { return mM; }
57
58 const std::vector<double>& getCoefficients() const { return mC; }
59
60 void print();
61
62 private:
63 int32_t mN = 0; // n coefficients == polynom order + 1
64 int32_t mM = 0; // number of measurenents
65 double mXmin = -1.; // min of X segment
66 double mXscale = 1; // scaling factor (x-mXmin) to [-1,1]
67 std::vector<double> mA; // fit matiix
68 std::vector<double> mB; // fit vector
69 std::vector<double> mC; // Chebyshev coefficients
70 std::vector<double> mT; // Chebyshev coefficients
71};
72
73inline void ChebyshevFit1D::addMeasurement(double x, double m)
74{
75 x = -1. + (x - mXmin) * mXscale;
76 mT[0] = 1;
77 mT[1] = x;
78 x *= 2.;
79 for (int32_t i = 2; i < mN; i++) {
80 mT[i] = x * mT[i - 1] - mT[i - 2];
81 }
82 double* Ai = mA.data();
83 for (int32_t i = 0; i < mN; i++, Ai += mN) {
84 for (int32_t j = i; j < mN; j++) {
85 Ai[j] += mT[i] * mT[j];
86 }
87 mB[i] += m * mT[i];
88 }
89 mM++;
90}
91
92inline double ChebyshevFit1D::eval(double x)
93{
94 x = -1. + (x - mXmin) * mXscale;
95 double y = mC[0] + mC[1] * x;
96 double f0 = 1.;
97 double f1 = x;
98 x *= 2;
99 for (int32_t i = 2; i < mN; i++) {
100 double f = x * f1 - f0;
101 y += mC[i] * f;
102 f0 = f1;
103 f1 = f;
104 }
105 return y;
106}
107
108} // namespace gpu
109} // namespace o2
110
111#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
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...