21 template <
class XBinner,
class YBinner,
class Cell>
25 Histogram2D(
typename XBinner::value_type xlow,
typename XBinner::value_type xhigh,
unsigned int xbinc,
26 typename YBinner::value_type ylow,
typename YBinner::value_type yhigh,
unsigned int ybinc )
27 : _xbinner( xlow, xhigh, xbinc ),
28 _ybinner( ylow, yhigh, ybinc )
30 _data.resize( _xbinner.binCount()*_ybinner.binCount(), Cell() );
38 const std::string &title()
const {
return( _title ); }
39 void setTitle(
const std::string &newtitle ) { _title = newtitle; }
41 const std::string &xlabel()
const {
return( _xlabel ); }
42 void setXlabel(
const std::string &newxlabel ) { _xlabel = newxlabel; }
44 const std::string &ylabel()
const {
return( _ylabel ); }
45 void setYlabel(
const std::string &newylabel ) { _ylabel = newylabel; }
47 const std::string &zlabel()
const {
return( _zlabel ); }
48 void setZlabel(
const std::string &newzlabel ) { _zlabel = newzlabel; }
51 void fill(
typename XBinner::value_type xvalue,
52 typename YBinner::value_type yvalue ) {
56 if( _xbinner.isUnderflow(xvalue) )
58 else if( _xbinner.isOverflow(xvalue) )
63 if( _ybinner.isUnderflow(yvalue) )
65 else if( _ybinner.isOverflow(yvalue) )
70 if( validX && validY )
71 ++_data[ _ybinner(yvalue)*_xbinner.binCount()+_xbinner(xvalue) ];
75 void fill(
typename XBinner::value_type xvalue,
76 typename YBinner::value_type yvalue,
81 if( _xbinner.isUnderflow(xvalue) )
83 else if( _xbinner.isOverflow(xvalue) )
88 if( _ybinner.isUnderflow(yvalue) )
90 else if( _ybinner.isOverflow(yvalue) )
95 if( validX && validY )
96 _data[ _ybinner(yvalue)*_xbinner.binCount()+_xbinner(xvalue) ] += amount;
101 std::ostream &exportGnuplotBinary( std::ostream &os )
const {
104 f = _xbinner.binCount();
105 os.write( (
const char *)&f,
sizeof(
float) );
108 for(
unsigned int ix = 0; ix < _xbinner.binCount(); ++ix ) {
109 f = _xbinner.binCenter( ix );
110 os.write( (
const char *)&f,
sizeof(
float) );
114 for(
unsigned int iy = 0; iy < _ybinner.binCount(); ++iy ) {
115 f = _ybinner.binCenter( iy );
116 os.write( (
const char *)&f,
sizeof(
float) );
117 for(
unsigned int ix = 0; ix < _xbinner.binCount(); ++ix ) {
118 f = _data[ iy*_xbinner.binCount()+ix ];
119 os.write( (
const char *)&f,
sizeof(
float) );
126 nlohmann::json getAsJSON()
const {
128 j[
"type"] =
"Histogram2D";
130 j[
"xlabel"] = _xlabel;
131 j[
"ylabel"] = _ylabel;
132 j[
"zlabel"] = _zlabel;
135 b[
"low"] = _xbinner.low();
136 b[
"high"] = _xbinner.high();
137 b[
"bincount"] = _xbinner.binCount();
138 b[
"binwidth"] = _xbinner.binWidth();
139 j[
"xbinner"] = std::move(b);
143 b[
"low"] = _ybinner.low();
144 b[
"high"] = _ybinner.high();
145 b[
"bincount"] = _ybinner.binCount();
146 b[
"binwidth"] = _ybinner.binWidth();
147 j[
"ybinner"] = std::move(b);
156 std::vector<Cell> _data;
157 Cell _xunderflows = 0;
158 Cell _xoverflows = 0;
159 Cell _yunderflows = 0;
160 Cell _yoverflows = 0;
Simple 2D histogram.
Definition: Histogram2D.hpp:22
Definition: mainpage.dox:6