23#include <TGraphErrors.h>
30namespace owned = ::mist::hep::owned;
54 const TGraph& reference,
58 const int n_ref = reference.GetN();
59 if (n_ref == 0)
return out;
61 const double x_lo = reference.GetPointX(0);
62 const double x_hi = reference.GetPointX(n_ref - 1);
64 for (
int i = 0; i < subject.GetN(); ++i) {
65 const double x = subject.GetPointX(i);
66 const double y = subject.GetPointY(i);
67 const bool in_range = (x >= x_lo && x <= x_hi);
75 const double ref = reference.Eval(x);
76 value = (ref == 0.0) ? std::nan(
"") : (y - ref) / ref;
78 out->SetPoint(out->GetN(), x, value);
90 if (source.GetN() == 0)
return out;
91 const double x0 = source.GetPointX(0);
92 for (
int i = 0; i < source.GetN(); ++i)
93 out->SetPoint(i, source.GetPointX(i) - x0, source.GetPointY(i));
104 for (
int i = 0; i < source.GetN(); ++i)
105 out->SetPoint(i, source.GetPointX(i), -source.GetPointY(i));
113 for (
int i = 0; i < source.GetN(); ++i)
114 out->SetPoint(i, -source.GetPointX(i), source.GetPointY(i));
122 for (
int i = 0; i < source.GetN(); ++i)
123 out->SetPoint(i, -source.GetPointX(i), -source.GetPointY(i));
135scale(
const TGraph& source,
double scale_x,
double scale_y)
138 for (
int i = 0; i < source.GetN(); ++i)
139 out->SetPoint(i, scale_x * source.GetPointX(i),
140 scale_y * source.GetPointY(i));
145scale(
const TGraphErrors& source,
double scale_x,
double scale_y)
148 for (
int i = 0; i < source.GetN(); ++i) {
149 out->SetPoint(i, scale_x * source.GetPointX(i),
150 scale_y * source.GetPointY(i));
151 out->SetPointError(i, std::fabs(scale_x) * source.GetErrorX(i),
152 std::fabs(scale_y) * source.GetErrorY(i));
169 for (
int i = 0; i < source.GetN(); ++i)
170 out->SetPoint(i, source.GetPointY(i), source.GetPointX(i));
179 for (
int i = 0; i < source.GetN(); ++i) {
180 out->SetPoint(i, source.GetPointY(i), source.GetPointX(i));
181 out->SetPointError(i, source.GetErrorY(i), source.GetErrorX(i));
194 for (
int i = 0; i < source.GetN(); ++i) {
195 out->SetPoint(i, source.GetPointX(i), source.GetPointY(i));
196 out->SetPointError(i, 0.0, 0.0);
211 for (
int i = 1; i <= source.GetNbinsX(); ++i) {
212 const int n = out->GetN();
213 out->SetPoint(n, source.GetBinCenter(i), source.GetBinContent(i));
214 out->SetPointError(n, source.GetBinWidth(i) * 0.5, source.GetBinError(i));
owned::root_ptr< TGraph > negate_x(const TGraph &source)
Definition transforms.h:110
out_of_range
Definition transforms.h:36
@ skip
Drop the point (the graphutils-original behaviour).
@ extrapolate
Use TGraph::Eval's linear extrapolation regardless.
@ nan
Emit the point with a NaN y-value.
owned::root_ptr< TGraph > swap_xy(const TGraph &source)
Definition transforms.h:166
owned::root_ptr< TGraph > negate_xy(const TGraph &source)
Definition transforms.h:119
owned::root_ptr< TGraph > shift_x_to_origin(const TGraph &source)
Definition transforms.h:87
owned::root_ptr< TGraph > scale(const TGraph &source, double scale_x, double scale_y)
Definition transforms.h:135
owned::root_ptr< TGraphErrors > from_profile(const TProfile &source)
Definition transforms.h:208
owned::root_ptr< TGraph > negate_y(const TGraph &source)
Definition transforms.h:101
owned::root_ptr< TGraphErrors > to_graph_errors(const TGraph &source)
Definition transforms.h:191
owned::root_ptr< TGraph > relative_diff(const TGraph &subject, const TGraph &reference, out_of_range policy=out_of_range::skip)
Definition transforms.h:53
std::unique_ptr< T, root_deleter > root_ptr
Definition owned.h:60
root_ptr< T > make(Args &&... args)
Definition owned.h:67