forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpline1DHelper.h
More file actions
150 lines (113 loc) · 5.82 KB
/
Spline1DHelper.h
File metadata and controls
150 lines (113 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file Spline1DHelper.h
/// \brief Definition of Spline1DHelper class
/// \author Sergey Gorbunov <sergey.gorbunov@cern.ch>
#ifndef ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_Spline1DHelper_H
#define ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_Spline1DHelper_H
#include <cmath>
#include <vector>
#include "GPUCommonDef.h"
#include "GPUCommonRtypes.h"
#include "Spline1D.h"
#include <functional>
#include <string>
namespace GPUCA_NAMESPACE
{
namespace gpu
{
///
/// The Spline1DHelper class is to initialize parameters for Spline1D class
///
template <typename DataT>
class Spline1DHelper
{
public:
///
/// \brief Helper structure for 1D spline construction
///
struct DataPoint {
double u; ///< u coordinate
double cS0; ///< a coefficient for s0
double cZ0; ///< a coefficient for s'0
double cS1; ///< a coefficient for s1
double cZ1; ///< a coefficient for s'1
int iKnot; ///< index of the left knot of the segment
bool isKnot; ///< is the point placed at a knot
};
/// _____________ Constructors / destructors __________________________
/// Default constructor
Spline1DHelper();
/// Copy constructor: disabled
Spline1DHelper(const Spline1DHelper&) CON_DEFAULT;
/// Assignment operator: disabled
Spline1DHelper& operator=(const Spline1DHelper&) CON_DEFAULT;
/// Destructor
~Spline1DHelper() CON_DEFAULT;
/// _______________ Main functionality ________________________
/// Create best-fit spline parameters for a given input function F
void approximateFunction(Spline1DContainer<DataT>& spline,
double xMin, double xMax, std::function<void(double x, double f[/*spline.getFdimensions()*/])> F,
int nAuxiliaryDataPoints = 4);
/// Create best-fit spline parameters gradually for a given input function F
void approximateFunctionGradually(Spline1DContainer<DataT>& spline,
double xMin, double xMax, std::function<void(double x, double f[/*spline.getFdimensions()*/])> F,
int nAuxiliaryDataPoints = 4);
/// Create classic spline parameters for a given input function F
void approximateFunctionClassic(Spline1DContainer<DataT>& spline,
double xMin, double xMax, std::function<void(double x, double f[/*spline.getFdimensions()*/])> F);
/// _______________ Interface for a step-wise construction of the best-fit spline ________________________
/// precompute everything needed for the construction
int setSpline(const Spline1DContainer<DataT>& spline, int nFdimensions, int nAuxiliaryDataPoints);
/// approximate std::function, output in Fparameters
void approximateFunction(DataT* Fparameters, double xMin, double xMax, std::function<void(double x, double f[])> F) const;
/// approximate std::function gradually, output in Fparameters
void approximateFunctionGradually(DataT* Fparameters, double xMin, double xMax, std::function<void(double x, double f[])> F) const;
/// number of data points
int getNumberOfDataPoints() const { return mDataPoints.size(); }
/// approximate a function given as an array of values at data points
void approximateFunction(DataT* Fparameters, const double DataPointF[/*getNumberOfDataPoints() x nFdim*/]) const;
/// gradually approximate a function given as an array of values at data points
void approximateFunctionGradually(DataT* Fparameters, const double DataPointF[/*getNumberOfDataPoints() x nFdim */]) const;
/// a tool for the gradual approximation: set spline values S_i at knots == function values
void copySfromDataPoints(DataT* Fparameters, const double DataPointF[/*getNumberOfDataPoints() x nFdim*/]) const;
/// a tool for the gradual approximation:
/// calibrate spline derivatives D_i using already calibrated spline values S_i
void approximateDerivatives(DataT* Fparameters, const double DataPointF[/*getNumberOfDataPoints() x nFdim*/]) const;
/// _______________ Utilities ________________________
const Spline1D<double>& getSpline() const { return mSpline; }
int getKnotDataPoint(int iknot) const { return mKnotDataPoints[iknot]; }
const DataPoint& getDataPoint(int ip) const { return mDataPoints[ip]; }
/// Gives error string
const char* getLastError() const { return mError.c_str(); }
#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) && !defined(GPUCA_ALIROOT_LIB) // code invisible on GPU and in the standalone compilation
/// Test the Spline1D class functionality
static int test(const bool draw = 0, const bool drawDataPoints = 1);
#endif
private:
/// Stores an error message
int storeError(int code, const char* msg);
std::string mError = ""; ///< error string
/// helpers for the construction of 1D spline
Spline1D<double> mSpline; ///< copy of the spline
int mFdimensions; ///< n of F dimensions
std::vector<DataPoint> mDataPoints; ///< measurement points
std::vector<int> mKnotDataPoints; ///< which measurement points are at knots
std::vector<double> mLSMmatrixFull; ///< a matrix to convert the measurements into the spline parameters with the LSM method
std::vector<double> mLSMmatrixSderivatives;
std::vector<double> mLSMmatrixSvalues;
#ifndef GPUCA_ALIROOT_LIB
ClassDefNV(Spline1DHelper, 0);
#endif
};
} // namespace gpu
} // namespace GPUCA_NAMESPACE
#endif