3 #include <cp3_llbb/Framework/interface/Histogram.h>
4 #include <cp3_llbb/Framework/interface/BinnedValues.h>
6 #include <boost/property_tree/ptree.hpp>
20 return std::move(m_values);
24 void parse_file(
const std::string& file);
26 std::vector<float> get_array(boost::property_tree::ptree& ptree) {
27 std::vector<float> vector;
28 for (
auto& value: ptree) {
29 vector.push_back(std::stof(value.second.data()));
35 std::vector<std::string> get_string_array(boost::property_tree::ptree& ptree) {
36 std::vector<std::string> vector;
37 for (
auto& value: ptree) {
38 vector.push_back(value.second.data());
44 template <
class T,
typename _Value>
45 void fillHistogram(T& h,
const std::vector<float>& bins,
const _Value& value,
const _Value& error_low,
const _Value& error_high) {
46 std::size_t bin = h.findBin(bins);
48 h.setBinContent(bin, value);
49 h.setBinErrorLow(bin, error_low);
50 h.setBinErrorHigh(bin, error_high);
53 void fillHistogram(
BinnedValues& val,
const std::vector<float>& bins,
const float& value,
const float& error_low,
const float& error_high) {
54 fillHistogram(*val.binned.get(), bins, value, error_low, error_high);
57 void fillHistogram(
BinnedValues& val,
const std::vector<float>& bins,
const std::string& value,
const std::string& error_low,
const std::string& error_high) {
58 std::shared_ptr<TFormula> value_formula(
new TFormula(
"", value.c_str()));
59 std::shared_ptr<TFormula> error_low_formula(
new TFormula(
"", error_low.c_str()));
60 std::shared_ptr<TFormula> error_high_formula(
new TFormula(
"", error_high.c_str()));
61 fillHistogram(*val.formula.get(), bins, value_formula, error_low_formula, error_high_formula);
64 template <
typename _Content>
65 void parse_data(boost::property_tree::ptree& ptree, std::size_t dimension) {
66 for (
auto& data_x: ptree.get_child(
"data")) {
67 std::vector<float> binning_x = get_array(data_x.second.get_child(
"bin"));
68 float mean_x = (binning_x[0] + binning_x[1]) / 2.;
72 for (
auto& data_y: data_x.second.get_child(
"values")) {
73 std::vector<float> binning_y = get_array(data_y.second.get_child(
"bin"));
74 float mean_y = (binning_y[0] + binning_y[1]) / 2.;
78 for (
auto& data_z: data_y.second.get_child(
"values")) {
79 std::vector<float> binning_z = get_array(data_z.second.get_child(
"bin"));
80 float mean_z = (binning_z[0] + binning_z[1]) / 2.;
81 _Content value = data_z.second.get<_Content>(
"value");
82 _Content error_low = data_z.second.get<_Content>(
"error_low");
83 _Content error_high = data_z.second.get<_Content>(
"error_high");
85 fillHistogram(m_values, {mean_x, mean_y, mean_z}, value, error_low, error_high);
90 _Content value = data_y.second.get<_Content>(
"value");
91 _Content error_low = data_y.second.get<_Content>(
"error_low");
92 _Content error_high = data_y.second.get<_Content>(
"error_high");
94 fillHistogram(m_values, {mean_x, mean_y}, value, error_low, error_high);
101 _Content value = data_x.second.get<_Content>(
"value");
102 _Content error_low = data_x.second.get<_Content>(
"error_low");
103 _Content error_high = data_x.second.get<_Content>(
"error_high");
105 fillHistogram(m_values, {mean_x}, value, error_low, error_high);
Definition: BinnedValuesJSONParser.h:12
Definition: BinnedValues.h:88