21 #include <TProfile2D.h>
22 #include <TProfile3D.h>
24 #include <fmt/format.h>
39 return {jAxis.
at(
"nBins" ).get<
unsigned int>(), jAxis.at(
"minValue" ).get<
double>(),
40 jAxis.at(
"maxValue" ).get<
double>(),
46 std::index_sequence<index...> ) {
49 auto jsonAxis = j.at(
"axis" );
50 auto axis =
std::array{toAxis( jsonAxis[index] )...};
54 title += ( axis[index].title + ... );
56 auto totNBins = ( ( axis[index].nBins + 2 ) * ... );
57 assert( weights.size() == totNBins );
59 auto histo = std::make_from_tuple<typename Traits::Histo>(
61 std::tuple{axis[index].nBins, axis[index].minValue, axis[index].maxValue}... ) );
63 for (
unsigned int i = 0; i < totNBins; i++ )
Traits::fill(
histo, i, weights[i] );
68 template <
bool isProfile,
typename RootHisto>
71 template <
typename RootHisto>
72 struct Traits<false, RootHisto> {
73 using Histo = RootHisto;
74 using WeightType = double;
75 static auto fill( Histo&
histo,
unsigned int i,
const WeightType& weight ) {
histo.SetBinContent( i, weight ); }
77 template <
typename RootHisto>
78 struct Traits<true, RootHisto> {
80 template <
typename TP>
81 struct ProfileWrapper : TP {
83 void setBinNEntries( Int_t i, Int_t
n ) { this->fBinEntries.fArray[i] =
n; }
84 void setBinW2( Int_t i, Double_t
v ) { this->fSumw2.fArray[i] =
v; }
86 using Histo = ProfileWrapper<RootHisto>;
88 static constexpr
auto fill( Histo&
histo,
unsigned int i,
const WeightType& weight ) {
89 auto [
c, sumWeight2] = weight;
92 histo.SetBinContent( i, sumWeight );
93 histo.setBinW2( i, sumWeight2 );
97 template <
unsigned int N,
bool isProfile,
typename ROOTHisto>
99 saveRootHistoInternal<Traits<isProfile, ROOTHisto>>( component,
name, j, std::make_index_sequence<N>() );
102 using namespace std::string_literals;
111 std::pair{
std::pair{
"histogram:WeightedProfileHistogram"s, 1}, &saveRootHisto<1, true, TProfile>},
112 std::pair{
std::pair{
"histogram:ProfileHistogram"s, 2}, &saveRootHisto<2, true, TProfile2D>},
113 std::pair{
std::pair{
"histogram:WeightedProfileHistogram"s, 2}, &saveRootHisto<2, true, TProfile2D>},
114 std::pair{
std::pair{
"histogram:ProfileHistogram"s, 3}, &saveRootHisto<3, true, TProfile3D>},
115 std::pair{
std::pair{
"histogram:WeightedProfileHistogram"s, 3}, &saveRootHisto<3, true, TProfile3D>}};
131 if ( !ok )
return ok;
137 auto j = ent.toJSON();
138 auto dim = j.at(
"dimension" ).
template get<unsigned int>();
139 auto type = j.at(
"type" ).
template get<std::string>();
143 auto saver =
registry.find( {type, dim} );
147 ( *saver->second )( ent.component, ent.name, j );
153 if ( std::string_view( ent.
type ).substr( 0, 10 ) ==
"histogram:" ) {
167 "Name of file where to save histograms"};