R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandCommonFunc.h
Go to the documentation of this file.
1#pragma once
2
3#include <R3BException.h>
4#include <algorithm>
5#include <array>
6#include <boost/algorithm/string/classification.hpp>
7#include <boost/algorithm/string/split.hpp>
8#include <boost/algorithm/string/trim.hpp>
9#include <fairlogger/Logger.h>
10#include <fmt/format.h>
11#include <root/TH1.h>
12#include <string>
13#include <utility>
14#include <vector>
15
16namespace R3B::Neuland
17{
18 template <typename Option>
19 void parse_io_branch_names(const Option& option,
20 std::vector<std::string>& read,
21 int read_num,
22 std::vector<std::string>& write,
23 int write_num)
24 {
25 LOGP(info, "Task {:?} is enabled", option.name);
26 auto resolve_branch_names = [](const std::string& input, std::vector<std::string>& output)
27 {
28 output.clear();
29 boost::split(output, input, boost::is_any_of(";"));
30 // trim the empty spaces
31 std::for_each(output.begin(), output.end(), [](auto& name) { boost::trim(name); });
32 // remove empty names
33 output.erase(std::remove(output.begin(), output.end(), ""), output.end());
34 };
35
36 resolve_branch_names(option.read, read);
37 if (read.size() != read_num)
38 {
39 throw R3B::logic_error(fmt::format(
40 "Task {:?} requires {} read branch(es) but only received {} branch(es)! Parsed string: {:?}",
41 option.name,
42 read_num,
43 read.size(),
44 option.read));
45 }
46 resolve_branch_names(option.write, write);
47 if (write.size() != write_num)
48 {
49 throw R3B::logic_error(fmt::format(
50 "Task {:?} requires {} write branch(es) but only received {} branch(es)! Parsed string: {:?}",
51 option.name,
52 read_num,
53 write.size(),
54 option.write));
55 }
56 }
57
58 inline auto calculate_cdf(TH1* histogram) -> TH1*
59 {
60 histogram->Scale(1 / histogram->GetEntries());
61 auto* cumulative = histogram->GetCumulative();
62 histogram->Scale(histogram->GetEntries());
63 return cumulative;
64 }
65
66 inline auto calculate_hist_quantiles(TH1* histogram, double quantile_ratio) -> std::array<double, 2>
67 {
68 static constexpr auto QUANTILES_NUM = 2;
69 const auto quantiles =
70 std::array<double, QUANTILES_NUM>{ 0.5 - (quantile_ratio / 2.), 0.5 + (quantile_ratio / 2.) };
71 auto x_pos = std::array<double, QUANTILES_NUM>{};
72 histogram->GetQuantiles(QUANTILES_NUM, x_pos.data(), quantiles.data());
73 return x_pos;
74 }
75
76 inline auto calculate_CDF_with_quantiles(TH1* histogram, double ratio) -> std::pair<TH1*, std::array<double, 2>>
77 {
78 if (histogram == nullptr)
79 {
80 return {};
81 }
83 }
84
85} // namespace R3B::Neuland
Simulation of NeuLAND Bar/Paddle.
auto calculate_hist_quantiles(TH1 *histogram, double quantile_ratio) -> std::array< double, 2 >
auto calculate_CDF_with_quantiles(TH1 *histogram, double ratio) -> std::pair< TH1 *, std::array< double, 2 > >
auto calculate_cdf(TH1 *histogram) -> TH1 *
void parse_io_branch_names(const Option &option, std::vector< std::string > &read, int read_num, std::vector< std::string > &write, int write_num)