1 #ifndef __RAT_ROOTINTERPOLATOR_HH__
2 #define __RAT_ROOTINTERPOLATOR_HH__
17 enum class extrapolation_t {
25 extrapolation_t extrapolation = extrapolation_t::kExtrapolate,
double fillvalue = 0.0)
26 : fGraph(std::make_unique<TGraph>(g)), fKind(kind), fExtrapolation(extrapolation), fFillValue(fillvalue) {
30 extrapolation_t extrapolation = extrapolation_t::kExtrapolate,
double fillvalue = 0.0) noexcept
31 : fGraph(std::make_unique<TGraph>(std::move(graph))),
33 fExtrapolation(extrapolation),
34 fFillValue(fillvalue) {
39 fGraph = std::make_unique<TGraph>(*other.fGraph);
43 fExtrapolation = other.fExtrapolation;
44 fFillValue = other.fFillValue;
50 fGraph = std::move(other.fGraph);
54 fExtrapolation = other.fExtrapolation;
55 fFillValue = other.fFillValue;
60 ROOTInterpolator(
const std::vector<double>& x,
const std::vector<double>& y, kind_t kind = kind_t::kLinear,
61 extrapolation_t extrapolation = extrapolation_t::kExtrapolate,
double fillvalue = 0.0)
62 : fGraph(std::make_unique<TGraph>(x.size(), x.data(), y.data())),
64 fExtrapolation(extrapolation),
65 fFillValue(fillvalue) {
69 void SetGraph(
const TGraph& g) {
70 fGraph = std::make_unique<TGraph>(g);
73 void SetGraph(TGraph&& graph) noexcept {
74 fGraph = std::make_unique<TGraph>(std::move(graph));
77 void SetData(
const std::vector<double>& x,
const std::vector<double>& y) {
78 fGraph = std::make_unique<TGraph>(x.size(), x.data(), y.data());
82 void SetFillValue(
double fillValue) { fFillValue = fillValue; }
83 void SetKind(kind_t kind) { fKind = kind; }
84 void SetExtrapolation(extrapolation_t extrapolation) { fExtrapolation = extrapolation; }
85 double GetFillValue()
const {
return fFillValue; }
86 kind_t GetKind()
const {
return fKind; }
87 extrapolation_t GetExtrapolation()
const {
return fExtrapolation; }
88 const TGraph* GetGraph()
const {
return fGraph.get(); }
90 double operator()(
double xx)
const {
92 Log::Die(
"Interpolator has no graph set.");
95 if (xx > fMinX && xx < fMaxX) {
98 result = fGraph->Eval(xx);
101 result = fGraph->Eval(xx, 0,
"S");
105 switch (fExtrapolation) {
106 case extrapolation_t::kError:
107 Log::Die(
"Interpolator called with out-of-bound value: %f", xx);
109 case extrapolation_t::kExtrapolate:
110 return fGraph->Eval(xx);
112 case extrapolation_t::kClamp:
114 result = fGraph->Eval(fMinX);
116 result = fGraph->Eval(fMaxX);
119 case extrapolation_t::kConstant:
128 std::unique_ptr<TGraph> fGraph;
130 kind_t fKind = kind_t::kLinear;
131 extrapolation_t fExtrapolation = extrapolation_t::kExtrapolate;
132 double fFillValue = 0.0;
133 void prepareGraph() {
135 Log::Die(
"Interpolator has no graph set.");
138 fMinX = fGraph->GetX()[0];
139 fMaxX = fGraph->GetX()[fGraph->GetN() - 1];
static void Die(std::string message, int return_code=1)
Definition: Log.cc:90
Definition: ROOTInterpolator.hh:11
Definition: CCCrossSecMessenger.hh:29