mist-hep 0.1.0
ROOT-backed analysis helpers built on mist
Loading...
Searching...
No Matches
smoothing.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2//
3// mist/hep/graph/smoothing.h — sliding-window smoothing over a TGraph.
4//
5// Thin adapter over <mist/algo/smoothing.h>: the X and Y coordinate arrays
6// are pulled from the TGraph, smoothed by mist::algo::moving_mean, and
7// zipped back into a new TGraph.
8//
9// Header-only. Returns an owning mist::hep::owned::root_ptr<TGraph>.
10//
11// Port / rewrite of:
12// - graphutils `moving_average` -> moving_average (F-16)
13//
14#pragma once
15
16#include <TGraph.h>
17
18#include <mist/algo/smoothing.h>
19#include <mist/hep/graph/binning.h> // detail::graph_x / graph_y / zip, owned alias
20
21namespace mist::hep::graph {
22
23// ---------------------------------------------------------------------------
24// moving_average: sliding window of `window_size`, advancing one point at a
25// time. Output length is N - window_size + 1 for input length N. Each output
26// point is (window-mean x, window-mean y).
27// ---------------------------------------------------------------------------
28[[nodiscard]] inline owned::root_ptr<TGraph>
29moving_average(const TGraph& source, std::size_t window_size)
30{
31 const auto mean_x = mist::algo::moving_mean(detail::graph_x(source),
32 window_size);
33 const auto mean_y = mist::algo::moving_mean(detail::graph_y(source),
34 window_size);
35 return detail::zip(mean_x, mean_y);
36}
37
38} // namespace mist::hep::graph
std::vector< double > graph_x(const TGraph &g)
Definition binning.h:31
owned::root_ptr< TGraph > zip(const std::vector< double > &xs, const std::vector< double > &ys)
Definition binning.h:48
std::vector< double > graph_y(const TGraph &g)
Definition binning.h:39
Definition algebra.h:32
owned::root_ptr< TGraph > moving_average(const TGraph &source, std::size_t window_size)
Definition smoothing.h:29
std::unique_ptr< T, root_deleter > root_ptr
Definition owned.h:60