13 #include <nlohmann/json.hpp>
25 template <
class Binner,
class Cell>
32 _data.resize( _binner.binCount(), Cell() );
35 Histogram1D(
typename Binner::value_type low,
typename Binner::value_type high,
unsigned int binc )
36 : _binner( low, high, binc )
38 _data.resize( _binner.binCount(), Cell() );
41 const std::string &title()
const {
return( _title ); }
42 void setTitle(
const std::string &newtitle ) { _title = newtitle; }
44 const std::string &xlabel()
const {
return( _xlabel ); }
45 void setXlabel(
const std::string &newxlabel ) { _xlabel = newxlabel; }
47 const std::string &ylabel()
const {
return( _ylabel ); }
48 void setYlabel(
const std::string &newylabel ) { _ylabel = newylabel; }
50 void fill(
typename Binner::value_type value ) noexcept {
51 if( _binner.isUnderflow(value) )
53 else if( _binner.isOverflow(value) )
56 ++_data[_binner(value)];
59 void fill(
typename Binner::value_type value, Cell amount ) noexcept {
60 if( _binner.isUnderflow(value) )
62 else if( _binner.isOverflow(value) )
65 _data[_binner(value)] += amount;
68 void fillNoRangeTesting(
typename Binner::value_type value ) noexcept {
69 ++_data[_binner(value)];
74 void exportAscii( std::ostream &os )
const {
75 os <<
"# histogram1D\n"
76 <<
"# title = \"" << _title <<
"\"\n"
77 <<
"# xlabel = \"" << _xlabel <<
"\"\n"
78 <<
"# ylabel = \"" << _ylabel <<
"\"\n"
79 <<
"# low = " << _binner.low() <<
"\n"
80 <<
"# high = " << _binner.high() <<
"\n"
81 <<
"# binCount = " << _binner.binCount() <<
"\n"
82 <<
"# binWidth = " << _binner.binWidth() <<
"\n"
83 <<
"# underflows = " << _underflows <<
"\n"
84 <<
"# overflows = " << _overflows <<
"\n"
85 <<
"# Data as (Bin_center,counts): \n";
86 for(
unsigned int i = 0; i < _binner.binCount(); ++i )
87 os << _binner.binCenter(i) <<
"\t" << _data[i] <<
"\n";
90 nlohmann::json getAsJSON()
const {
92 j[
"type"] =
"Histogram1D";
94 j[
"xlabel"] = _xlabel;
95 j[
"ylabel"] = _ylabel;
98 b[
"low"] = _binner.low();
99 b[
"high"] = _binner.high();
100 b[
"bincount"] = _binner.binCount();
101 b[
"binwidth"] = _binner.binWidth();
102 j[
"binner"] = std::move(b);
104 j[
"underflows"] = _underflows;
105 j[
"overflows"] = _overflows;
112 std::vector<Cell> _data;
113 Cell _underflows = 0;
Simple 1D histogram.
Definition: Histogram1D.hpp:26
Definition: mainpage.dox:6