Skip to content
Snippets Groups Projects
Commit 75c16496 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Added title to each axis of histograms. Default is empty

parent 29aafe27
No related branches found
No related tags found
1 merge request!1113New (counter based) histograms
......@@ -32,12 +32,14 @@ namespace {
unsigned int nBins;
double minValue;
double maxValue;
std::string title;
};
Axis toAxis( nlohmann::json& jAxis ) {
return { jAxis.at("nBins").get<unsigned int>(),
jAxis.at("minValue").get<double>(),
jAxis.at("maxValue").get<double>() };
jAxis.at("maxValue").get<double>(),
";" + jAxis.at("title").get<std::string>() }; // ";" to prepare concatenations of titles
}
template <typename Traits, std::size_t... index>
......@@ -49,6 +51,8 @@ namespace {
auto axis = std::array{toAxis( jsonAxis[index] )...};
auto weights = j.at( "bins" ).get<std::vector<typename Traits::WeightType>>();
auto title = j.at("title").get<std::string>();
// weird way ROOT has to give titles to axis
title += (axis[index].title + ...);
// compute total number of bins, multiplying bins per axis
auto totNBins = ((axis[index].nBins+2) * ...);
assert(weights.size() == totNBins);
......
......@@ -141,11 +141,11 @@ namespace Gaudi {
// "default" case, that is bins containing doubles and atomic
mutable Gaudi::Accumulators::Histogram<1> m_gauss{
this, "Gauss", "Gaussian mean=0, sigma=1, atomic", {100, -5, 5}};
this, "Gauss", "Gaussian mean=0, sigma=1, atomic", {100, -5, 5, "X"}};
mutable Gaudi::Accumulators::Histogram<2> m_gaussVflat{
this, "GaussFlat", "Gaussian V Flat, atomic", {{50, -5, 5}, {50, -5, 5}}};
this, "GaussFlat", "Gaussian V Flat, atomic", {{50, -5, 5, "X"}, {50, -5, 5, "Y"}}};
mutable Gaudi::Accumulators::Histogram<3> m_gaussVflatVgauss{
this, "GaussFlatGauss", "Gaussian V Flat V Gaussian, atomic", {{10, -5, 5}, {10, -5, 5}, {10, -5, 5}}};
this, "GaussFlatGauss", "Gaussian V Flat V Gaussian, atomic", {{10, -5, 5, "X"}, {10, -5, 5, "Y"}, {10, -5, 5, "Z"}}};
// non atomic versions
mutable Gaudi::Accumulators::Histogram<1, Gaudi::Accumulators::atomicity::none> m_gauss_noato{
......
......@@ -113,12 +113,14 @@ namespace Gaudi::Accumulators {
*/
template <typename Arithmetic>
struct Axis {
Axis( unsigned int _nBins, Arithmetic _minValue, Arithmetic _maxValue )
: nBins( _nBins ), minValue( _minValue ), maxValue( _maxValue ), ratio( _nBins / ( _maxValue - _minValue ) ){};
Axis( unsigned int _nBins, Arithmetic _minValue, Arithmetic _maxValue, const std::string& _title="" )
: nBins( _nBins ), minValue( _minValue ), maxValue( _maxValue ), title(_title), ratio( _nBins / ( _maxValue - _minValue ) ){};
/// number of bins for this Axis
unsigned int nBins;
/// min and max values on this axis
Arithmetic minValue, maxValue;
/// title of this axis
std::string title;
/**
* precomputed ratio to convert a value into bin number
* equal to nBins/(maxValue-minValue)
......@@ -129,7 +131,7 @@ namespace Gaudi::Accumulators {
/// automatic conversion of the Axis type to json
template <typename Arithmetic>
void to_json(nlohmann::json& j, const Axis<Arithmetic>& axis) {
j = nlohmann::json{{"nBins", axis.nBins}, {"minValue", axis.minValue}, {"maxValue", axis.maxValue}};
j = nlohmann::json{{"nBins", axis.nBins}, {"minValue", axis.minValue}, {"maxValue", axis.maxValue}, {"title", axis.title}};
}
/// small class used as InputType for regular Histograms
......@@ -322,7 +324,7 @@ namespace Gaudi::Accumulators {
* All these types have the same fields, namely :
* dimension(integer), title(string), empty(bool), nEntries(integer), axis(array), bins(array)
* where :
* + axis is an array of triplets, one per dimension, with content (nBins(integer), minValue(number), maxValue(number))
* + axis is an array of tuples, one per dimension, with content (nBins(integer), minValue(number), maxValue(number), title(string))
* + bins is an array of values. The length of the array is the product of (nBins+2) for all axis
* the +2 is because the bin 0 is the one for values below minValue and bin nBins+1 is the one for values above maxValue
* bins are stored row first, so we iterate first on highest dimension
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment