BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
AkimaFunction.h
Go to the documentation of this file.
1
#ifndef AKIMAFUNCTION_H
2
#define AKIMAFUNCTION_H
3
4
#include "
Math/Interpolator.h
"
5
#include "
TNamed.h
"
6
7
#include <algorithm>
8
#include <iostream>
9
#include <memory>
10
#include <vector>
11
12
class
AkimaFunction
:
public
TNamed
13
{
14
public
:
15
std::vector<double>
x
;
16
std::vector<double>
y
;
17
18
std::unique_ptr<ROOT::Math::Interpolator>
interpolator
;
//!
19
20
AkimaFunction
()
21
:
TNamed
()
22
{}
23
24
AkimaFunction
(
const
char
* name,
const
std::vector<double>& xVals,
const
std::vector<double>& yVals)
25
:
TNamed
(name, name)
26
,
x
(xVals)
27
,
y
(yVals)
28
{
29
SortPoints
();
30
BuildInterpolator
();
31
}
32
33
virtual
~AkimaFunction
() {}
34
35
void
SortPoints
()
36
{
37
if
(
x
.size() !=
y
.size())
38
return
;
39
40
std::vector<std::pair<double, double>> pairs;
41
pairs.reserve(
x
.size());
42
43
for
(
size_t
i
= 0;
i
<
x
.size(); ++
i
) {
44
pairs.emplace_back(
x
[
i
],
y
[
i
]);
45
}
46
47
std::sort(pairs.begin(), pairs.end());
48
49
for
(
size_t
i
= 0;
i
< pairs.size(); ++
i
) {
50
x
[
i
] = pairs[
i
].first;
51
y
[
i
] = pairs[
i
].second;
52
}
53
}
54
55
void
BuildInterpolator
()
56
{
57
if
(
x
.size() < 2)
58
return
;
59
60
try
{
61
auto
type = (
x
.size() < 5) ?
ROOT::Math::Interpolation::kLINEAR
:
ROOT::Math::Interpolation::kAKIMA
;
62
63
interpolator
= std::make_unique<ROOT::Math::Interpolator>(
x
,
y
, type);
64
}
catch
(...) {
65
std::cerr <<
"Interpolator build failed for "
<<
GetName
() << std::endl;
66
interpolator
.reset();
67
}
68
}
69
70
void
Init
()
71
{
72
if
(!
interpolator
) {
73
BuildInterpolator
();
74
}
75
}
76
77
double
Eval
(
double
xx)
78
{
79
if
(
x
.empty())
80
return
0.0;
81
82
if
(!
interpolator
) {
83
Init
();
84
}
85
86
if
(!
interpolator
) {
87
return
0.0;
88
}
89
90
if
(xx <=
x
.front())
91
return
y
.front();
92
if
(xx >=
x
.back())
93
return
y
.back();
94
95
return
interpolator
->Eval(xx);
96
}
97
98
void
Print
(
Option_t
* option =
""
)
const override
99
{
100
std::cout <<
"AkimaFunction: "
<<
GetName
() <<
" | N points = "
<<
x
.size() << std::endl;
101
}
102
103
ClassDefOverride
(
AkimaFunction
, 1);
104
};
105
106
#endif
// AKIMAFUNCTION_H
Interpolator.h
i
int i
Definition
P4_F32vec4.h:22
Option_t
const char Option_t
ClassDefOverride
#define ClassDefOverride(name, id)
TNamed.h
AkimaFunction
Definition
AkimaFunction.h:13
AkimaFunction::interpolator
std::unique_ptr< ROOT::Math::Interpolator > interpolator
Definition
AkimaFunction.h:18
AkimaFunction::AkimaFunction
AkimaFunction()
Definition
AkimaFunction.h:20
AkimaFunction::SortPoints
void SortPoints()
Definition
AkimaFunction.h:35
AkimaFunction::~AkimaFunction
virtual ~AkimaFunction()
Definition
AkimaFunction.h:33
AkimaFunction::AkimaFunction
AkimaFunction(const char *name, const std::vector< double > &xVals, const std::vector< double > &yVals)
Definition
AkimaFunction.h:24
AkimaFunction::x
std::vector< double > x
Definition
AkimaFunction.h:15
AkimaFunction::y
std::vector< double > y
Definition
AkimaFunction.h:16
AkimaFunction::BuildInterpolator
void BuildInterpolator()
Definition
AkimaFunction.h:55
AkimaFunction::Init
void Init()
Definition
AkimaFunction.h:70
AkimaFunction::Print
void Print(Option_t *option="") const override
Definition
AkimaFunction.h:98
AkimaFunction::Eval
double Eval(double xx)
Definition
AkimaFunction.h:77
TNamed
TNamed::GetName
const char * GetName() const override
TNamed::TNamed
TNamed()
ROOT::Math::Interpolation::kLINEAR
kLINEAR
ROOT::Math::Interpolation::kAKIMA
kAKIMA
reconstruction
globaltracking
AkimaFunction.h
Generated on
for BmnRoot by
1.17.0