20 #include <TProfile2D.h>
21 #include <TProfile3D.h>
25 template <
typename RootHisto,
unsigned int N>
27 static constexpr
unsigned int Dimension{
N };
30 return std::make_from_tuple<RootHisto>(
32 std::tuple{ std::get<index>( axis ).nBins, std::get<index>( axis ).minValue,
33 std::get<index>( axis ).maxValue }... ) );
35 template <
typename... Axis>
37 return create(
name, title,
std::make_tuple( axis... ), std::make_index_sequence<
sizeof...( Axis )>() );
39 static void fillMetaData( RootHisto&
histo,
nlohmann::json const& jsonAxis,
unsigned int nentries ) {
40 auto try_set_bin_labels = [&
histo, &jsonAxis](
auto idx ) {
41 if ( jsonAxis[idx].contains(
"labels" ) ) {
42 TAxis* axis =
nullptr;
45 axis =
histo.GetXaxis();
48 axis =
histo.GetYaxis();
51 axis =
histo.GetZaxis();
57 const auto labels = jsonAxis[idx].at(
"labels" );
58 for (
unsigned int i = 0; i < labels.size(); i++ ) {
59 axis->SetBinLabel( i + 1, labels[i].
template get<std::string>().c_str() );
64 for (
unsigned int i = 0; i < jsonAxis.size(); i++ ) try_set_bin_labels( i );
66 histo.SetEntries( nentries );
70 template <
bool isProfile,
typename RootHisto,
unsigned int N>
73 template <
typename RootHisto,
unsigned int N>
74 struct Traits<false, RootHisto,
N> : TraitsBase<RootHisto, N> {
75 using Histo = RootHisto;
76 using WeightType = double;
77 static void fill( Histo&
histo,
unsigned int i,
const WeightType& weight ) {
histo.SetBinContent( i, weight ); }
80 template <
typename TP>
81 struct ProfileWrapper : TP {
82 template <
typename... Args>
90 void setBinNEntries( Int_t i, Int_t
n ) { this->fBinEntries.fArray[i] =
n; }
91 void setBinW2( Int_t i, Double_t
v ) { this->fSumw2.fArray[i] =
v; }
93 template <
typename RootHisto,
unsigned int N>
94 struct Traits<true, RootHisto,
N> : TraitsBase<ProfileWrapper<RootHisto>, N> {
95 using Histo = ProfileWrapper<RootHisto>;
97 static constexpr
void fill( Histo&
histo,
unsigned int i,
const WeightType& weight ) {
98 auto [
c, sumWeight2] = weight;
101 histo.SetBinContent( i, sumWeight );
102 histo.setBinW2( i, sumWeight2 );
110 using namespace std::string_literals;
112 template <
unsigned int N,
bool isProfile,
typename ROOTHisto>
121 HistoRegistry
registry = { { {
"histogram:Histogram"s, 1 }, &saveRootHisto<1, false, TH1D> },
122 { {
"histogram:WeightedHistogram"s, 1 }, &saveRootHisto<1, false, TH1D> },
123 { {
"histogram:Histogram"s, 2 }, &saveRootHisto<2, false, TH2D> },
124 { {
"histogram:WeightedHistogram"s, 2 }, &saveRootHisto<2, false, TH2D> },
125 { {
"histogram:Histogram"s, 3 }, &saveRootHisto<3, false, TH3D> },
126 { {
"histogram:WeightedHistogram"s, 3 }, &saveRootHisto<3, false, TH3D> },
127 { {
"histogram:ProfileHistogram"s, 1 }, &saveRootHisto<1, true, TProfile> },
128 { {
"histogram:WeightedProfileHistogram"s, 1 }, &saveRootHisto<1, true, TProfile> },
129 { {
"histogram:ProfileHistogram"s, 2 }, &saveRootHisto<2, true, TProfile2D> },
130 { {
"histogram:WeightedProfileHistogram"s, 2 }, &saveRootHisto<2, true, TProfile2D> },
131 { {
"histogram:ProfileHistogram"s, 3 }, &saveRootHisto<3, true, TProfile3D> },
132 { {
"histogram:WeightedProfileHistogram"s, 3 }, &saveRootHisto<3, true, TProfile3D> } };