yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
YODA::Histo2D Class Reference

A two-dimensional histogram. More...

#include <Histo2D.h>

Inheritance diagram for YODA::Histo2D:
YODA::AnalysisObject

Public Types

typedef Histo2DAxis Axis
 Convenience typedefs. More...
 
typedef Axis::Bins Bins
 
typedef HistoBin2D Bin
 
typedef Axis::Outflows Outflows
 
typedef std::tuple< double, double > FillType
 
typedef FillType BinType
 
typedef std::shared_ptr< Histo2DPtr
 
- Public Types inherited from YODA::AnalysisObject
typedef std::map< std::string, std::string > Annotations
 Collection type for annotations, as a string-string map. More...
 

Public Member Functions

size_t dim () const
 Fill dimension of this data object. More...
 
Constructors
 Histo2D (const std::string &path="", const std::string &title="")
 Default constructor. More...
 
 Histo2D (size_t nbinsX, double lowerX, double upperX, size_t nbinsY, double lowerY, double upperY, const std::string &path="", const std::string &title="")
 Constructor giving range and number of bins. More...
 
 Histo2D (const std::vector< double > &xedges, const std::vector< double > &yedges, const std::string &path="", const std::string &title="")
 Constructor accepting the bin edges on X and Y axis. More...
 
 Histo2D (const std::vector< Bin > &bins, const std::string &path="", const std::string &title="")
 Constructor accepting an explicit collection of bins. More...
 
 Histo2D (const Histo2D &h, const std::string &path="")
 Copy constructor with optional new path. More...
 
 Histo2D (const Scatter3D &s, const std::string &path="")
 Constructor from a Scatter3D's binning, with optional new path. More...
 
 Histo2D (const Profile2D &h, const std::string &path="")
 Constructor from a Profile2D's binning, with optional new path. More...
 
 Histo2D (const std::vector< HistoBin2D > &bins, const Dbn2D &totalDbn, const Outflows &outflows, const std::string &path="", const std::string &title="")
 State-setting constructor. More...
 
Histo2Doperator= (const Histo2D &h2)
 Assignment operator. More...
 
Histo2D clone () const
 Make a copy on the stack. More...
 
Histo2Dnewclone () const
 Make a copy on the heap, via 'new'. More...
 
Modifiers
virtual void fill (double x, double y, double weight=1.0, double fraction=1.0)
 Fill histo with weight at (x,y) More...
 
virtual void fill (const FillType &xs, double weight=1.0, double fraction=1.0)
 
virtual void fillBin (size_t i, double weight=1.0, double fraction=1.0)
 Fill histo x-y bin i with the given weight. More...
 
void reset ()
 Reset the histogram. More...
 
void scaleW (double scalefactor)
 Rescale as if all fill weights had been different by factor scalefactor. More...
 
void normalize (double normto=1.0, bool includeoverflows=true)
 
void scaleXY (double scaleX=1.0, double scaleY=1.0)
 Scale the dimensions. More...
 
void addBin (Axis::EdgePair1D xrange, Axis::EdgePair1D yrange)
 Bin addition operator. More...
 
void addBin (const Bin &bin)
 Bin addition operator. More...
 
void addBins (const Axis::Edges &xcuts, const Axis::Edges &ycuts)
 Bins addition operator. More...
 
void addBins (const Bins &bins)
 Bins addition operator. More...
 
void eraseBin (size_t index)
 
Bin accessors
double xMin () const
 Low x edge of this histo's axis. More...
 
double xMax () const
 High x edge of this histo's axis. More...
 
double yMin () const
 Low y edge of this histo's axis. More...
 
double yMax () const
 High y edge of this histo's axis. More...
 
std::vector< YODA::HistoBin2D > & bins ()
 Access the bin vector (non-const version) More...
 
const std::vector< YODA::HistoBin2D > & bins () const
 Access the bin vector (const version) More...
 
HistoBin2Dbin (size_t index)
 Access a bin by index (non-const version) More...
 
const HistoBin2Dbin (size_t index) const
 Access a bin by index (const version) More...
 
int binIndexAt (double x, double y)
 Access a bin index by coordinate. More...
 
int binIndexAt (const BinType &t)
 
const HistoBin2DbinAt (double x, double y) const
 Access a bin by coordinate (const version) More...
 
const HistoBin2DbinAt (const BinType &t)
 
size_t numBins () const
 Number of bins. More...
 
size_t numBinsX () const
 Number of bins along the x axis. More...
 
size_t numBinsY () const
 Number of bins along the y axis. More...
 
Dbn2DtotalDbn ()
 Access summary distribution, including gaps and overflows (non-const version) More...
 
const Dbn2DtotalDbn () const
 Access summary distribution, including gaps and overflows (const version) More...
 
void setTotalDbn (const Dbn2D &dbn)
 Set summary distribution, including gaps and overflows. More...
 
Whole histo data
double integral (bool includeoverflows=true) const
 Get the total volume of the histogram. More...
 
double numEntries (bool includeoverflows=true) const
 Get the number of fills (fractional fills are possible) More...
 
double effNumEntries (bool includeoverflows=true) const
 Get the effective number of fills. More...
 
double sumW (bool includeoverflows=true) const
 Get the sum of weights in histo. More...
 
double sumW2 (bool includeoverflows=true) const
 Get the sum of squared weights in histo. More...
 
double xMean (bool includeoverflows=true) const
 Get the mean x. More...
 
double yMean (bool includeoverflows=true) const
 Get the mean y. More...
 
double xVariance (bool includeoverflows=true) const
 Get the variance in x. More...
 
double yVariance (bool includeoverflows=true) const
 Get the variance in y. More...
 
double xStdDev (bool includeoverflows=true) const
 Get the standard deviation in x. More...
 
double yStdDev (bool includeoverflows=true) const
 Get the standard deviation in y. More...
 
double xStdErr (bool includeoverflows=true) const
 Get the standard error in x. More...
 
double yStdErr (bool includeoverflows=true) const
 Get the standard error in y. More...
 
double xRMS (bool includeoverflows=true) const
 Get the RMS in x. More...
 
double yRMS (bool includeoverflows=true) const
 Get the RMS in y. More...
 
Adding and subtracting histograms
Histo2Doperator+= (const Histo2D &toAdd)
 Add another histogram to this one. More...
 
Histo2Doperator-= (const Histo2D &toSubtract)
 Subtract another histogram from this one. More...
 
bool operator== (const Histo2D &other) const
 
bool operator!= (const Histo2D &other) const
 
- Public Member Functions inherited from YODA::AnalysisObject
 AnalysisObject ()
 Default constructor. More...
 
 AnalysisObject (const std::string &type, const std::string &path, const std::string &title="")
 Constructor giving a type, a path and an optional title. More...
 
 AnalysisObject (const std::string &type, const std::string &path, const AnalysisObject &ao, const std::string &title="")
 Constructor giving a type, a path, another AO to copy annotation from, and an optional title. More...
 
virtual ~AnalysisObject ()
 Default destructor. More...
 
virtual AnalysisObjectoperator= (const AnalysisObject &ao)
 Default copy assignment operator. More...
 
std::vector< std::string > annotations () const
 
bool hasAnnotation (const std::string &name) const
 Check if an annotation is defined. More...
 
const std::string & annotation (const std::string &name) const
 Get an annotation by name (as a string) More...
 
const std::string & annotation (const std::string &name, const std::string &defaultreturn) const
 Get an annotation by name (as a string) with a default in case the annotation is not found. More...
 
template<typename T >
const T annotation (const std::string &name) const
 Get an annotation by name (copied to another type) More...
 
template<typename T >
const T annotation (const std::string &name, const T &defaultreturn) const
 Get an annotation by name (copied to another type) with a default in case the annotation is not found. More...
 
void setAnnotation (const std::string &name, const std::string &value)
 Add or set a string-valued annotation by name. More...
 
void setAnnotation (const std::string &name, double value)
 Add or set a double-valued annotation by name. More...
 
void setAnnotation (const std::string &name, float value)
 Add or set a float-valued annotation by name. More...
 
void setAnnotation (const std::string &name, long double value)
 Add or set a long-double-valued annotation by name. More...
 
template<typename T >
void setAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name (templated for remaining types) More...
 
void setAnnotations (const Annotations &anns)
 Set all annotations at once. More...
 
template<typename T >
void addAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name. More...
 
void rmAnnotation (const std::string &name)
 Delete an annotation by name. More...
 
void clearAnnotations ()
 Delete an annotation by name. More...
 
const std::string title () const
 Get the AO title. More...
 
void setTitle (const std::string &title)
 Set the AO title. More...
 
const std::string path () const
 Get the AO path. More...
 
void setPath (const std::string &path)
 
const std::string name () const
 
virtual std::string type () const
 Get name of the analysis object type. More...
 

Detailed Description

A two-dimensional histogram.

Definition at line 31 of file Histo2D.h.

Member Typedef Documentation

◆ Axis

Convenience typedefs.

Definition at line 35 of file Histo2D.h.

◆ Bin

Definition at line 37 of file Histo2D.h.

◆ Bins

Definition at line 36 of file Histo2D.h.

◆ BinType

Definition at line 41 of file Histo2D.h.

◆ FillType

typedef std::tuple<double, double> YODA::Histo2D::FillType

Definition at line 40 of file Histo2D.h.

◆ Outflows

Definition at line 38 of file Histo2D.h.

◆ Ptr

typedef std::shared_ptr<Histo2D> YODA::Histo2D::Ptr

Definition at line 42 of file Histo2D.h.

Constructor & Destructor Documentation

◆ Histo2D() [1/8]

YODA::Histo2D::Histo2D ( const std::string &  path = "",
const std::string &  title = "" 
)
inline

Default constructor.

Definition at line 49 of file Histo2D.h.

Referenced by clone(), Histo2D(), and newclone().

50  : AnalysisObject("Histo2D", path, title),
51  _axis()
52  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.

◆ Histo2D() [2/8]

YODA::Histo2D::Histo2D ( size_t  nbinsX,
double  lowerX,
double  upperX,
size_t  nbinsY,
double  lowerY,
double  upperY,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor giving range and number of bins.

Definition at line 56 of file Histo2D.h.

59  : AnalysisObject("Histo2D", path, title),
60  _axis(nbinsX, std::make_pair(lowerX, upperX), nbinsY, std::make_pair(lowerY, upperY))
61  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.

◆ Histo2D() [3/8]

YODA::Histo2D::Histo2D ( const std::vector< double > &  xedges,
const std::vector< double > &  yedges,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor accepting the bin edges on X and Y axis.

Definition at line 65 of file Histo2D.h.

67  : AnalysisObject("Histo2D", path, title),
68  _axis(xedges, yedges)
69  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.

◆ Histo2D() [4/8]

YODA::Histo2D::Histo2D ( const std::vector< Bin > &  bins,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor accepting an explicit collection of bins.

Definition at line 73 of file Histo2D.h.

References Histo2D(), and YODA::AnalysisObject::path().

75  : AnalysisObject("Histo2D", path, title),
76  _axis(bins)
77  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.

◆ Histo2D() [5/8]

YODA::Histo2D::Histo2D ( const Histo2D h,
const std::string &  path = "" 
)

Copy constructor with optional new path.

Copy constructor with optional new path

Todo:
Also allow title setting from the constructor?

Definition at line 17 of file Histo2D.cc.

18  : AnalysisObject("Histo2D", (path.size() == 0) ? h.path() : path, h, h.title()),
19  _axis(h._axis)
20  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.

◆ Histo2D() [6/8]

YODA::Histo2D::Histo2D ( const Scatter3D s,
const std::string &  path = "" 
)

Constructor from a Scatter3D's binning, with optional new path.

A constructor from a Scatter3D's binning, with optional new path

Todo:
Also allow title setting from the constructor?

Definition at line 24 of file Histo2D.cc.

References bins(), and YODA::Scatter3D::points().

25  : AnalysisObject("Histo2D", (path.size() == 0) ? s.path() : path, s, s.title())
26  {
27  std::vector<HistoBin2D> bins;
28  for (const Scatter3D::Point& p : s.points()) {
29  bins.push_back(HistoBin2D(p.xMin(), p.xMax(), p.yMin(), p.yMax()));
30  }
31  _axis = Histo2DAxis(bins);
32  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
Axis2D< HistoBin2D, Dbn2D > Histo2DAxis
Convenience typedef.
Definition: Histo2D.h:24
Point3D Point
Types of the native Point3D collection.
Definition: Scatter3D.h:28

◆ Histo2D() [7/8]

YODA::Histo2D::Histo2D ( const Profile2D h,
const std::string &  path = "" 
)

Constructor from a Profile2D's binning, with optional new path.

Constructor from a Profile2D's binning, with optional new path

Todo:
Also allow title setting from the constructor?

Definition at line 36 of file Histo2D.cc.

References YODA::Profile2D::bins(), and bins().

37  : AnalysisObject("Histo2D", (path.size() == 0) ? p.path() : path, p, p.title())
38  {
39  std::vector<HistoBin2D> bins;
40  for (const ProfileBin2D& b : p.bins()) {
41  bins.push_back(HistoBin2D(b.xMin(), b.xMax(), b.yMin(), b.yMax()));
42  }
43  _axis = Histo2DAxis(bins);
44  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
Axis2D< HistoBin2D, Dbn2D > Histo2DAxis
Convenience typedef.
Definition: Histo2D.h:24

◆ Histo2D() [8/8]

YODA::Histo2D::Histo2D ( const std::vector< HistoBin2D > &  bins,
const Dbn2D totalDbn,
const Outflows outflows,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

State-setting constructor.

Mainly intended for internal persistency use.

Definition at line 95 of file Histo2D.h.

99  : AnalysisObject("Histo2D", path, title),
100  _axis(bins, totalDbn, outflows)
101  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.
Dbn2D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo2D.h:293

Member Function Documentation

◆ addBin() [1/2]

void YODA::Histo2D::addBin ( Axis::EdgePair1D  xrange,
Axis::EdgePair1D  yrange 
)
inline

Bin addition operator.

Add a bin to an axis described by its x and y ranges.

Definition at line 180 of file Histo2D.h.

180  {
181  _axis.addBin(xrange, yrange);
182  }

◆ addBin() [2/2]

void YODA::Histo2D::addBin ( const Bin bin)
inline

Bin addition operator.

Add a bin, possibly already populated

Definition at line 187 of file Histo2D.h.

187  {
188  _axis.addBin(bin);
189  }
HistoBin2D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo2D.h:266

◆ addBins() [1/2]

void YODA::Histo2D::addBins ( const Axis::Edges xcuts,
const Axis::Edges ycuts 
)
inline

Bins addition operator.

Add multiple bins from edge cuts without resetting

Definition at line 195 of file Histo2D.h.

195  {
196  _axis.addBins(xcuts, ycuts);
197  }

◆ addBins() [2/2]

void YODA::Histo2D::addBins ( const Bins bins)
inline

Bins addition operator.

Add multiple bins without resetting

Definition at line 202 of file Histo2D.h.

202  {
203  _axis.addBins(bins);
204  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260

◆ bin() [1/2]

HistoBin2D& YODA::Histo2D::bin ( size_t  index)
inline

Access a bin by index (non-const version)

Definition at line 266 of file Histo2D.h.

Referenced by YODA::divide(), YODA::efficiency(), fillBin(), YODA::mkScatter(), and YODA::toTH2D().

266 { return _axis.bin(index); }

◆ bin() [2/2]

const HistoBin2D& YODA::Histo2D::bin ( size_t  index) const
inline

Access a bin by index (const version)

Definition at line 268 of file Histo2D.h.

268 { return _axis.bin(index); }

◆ binAt() [1/2]

const HistoBin2D& YODA::Histo2D::binAt ( double  x,
double  y 
) const
inline

Access a bin by coordinate (const version)

Definition at line 277 of file Histo2D.h.

Referenced by YODA::toTH2D().

277 { return _axis.binAt(x, y); }

◆ binAt() [2/2]

const HistoBin2D& YODA::Histo2D::binAt ( const BinType t)
inline

Definition at line 279 of file Histo2D.h.

279 { return _axis.binAt(std::get<0>(t), std::get<1>(t)); }

◆ binIndexAt() [1/2]

int YODA::Histo2D::binIndexAt ( double  x,
double  y 
)
inline

Access a bin index by coordinate.

Definition at line 272 of file Histo2D.h.

272 { return _axis.binIndexAt(x, y); }

◆ binIndexAt() [2/2]

int YODA::Histo2D::binIndexAt ( const BinType t)
inline

Definition at line 274 of file Histo2D.h.

274 { return _axis.binIndexAt(std::get<0>(t), std::get<1>(t)); }

◆ bins() [1/2]

std::vector<YODA::HistoBin2D>& YODA::Histo2D::bins ( )
inline

Access the bin vector (non-const version)

Definition at line 260 of file Histo2D.h.

Referenced by effNumEntries(), Histo2D(), numEntries(), YODA::Profile2D::Profile2D(), sumW(), sumW2(), xMean(), xRMS(), xStdErr(), xVariance(), yMean(), yRMS(), yStdErr(), and yVariance().

260 { return _axis.bins(); }

◆ bins() [2/2]

const std::vector<YODA::HistoBin2D>& YODA::Histo2D::bins ( ) const
inline

Access the bin vector (const version)

Definition at line 262 of file Histo2D.h.

262 { return _axis.bins(); }

◆ clone()

Histo2D YODA::Histo2D::clone ( ) const
inline

Make a copy on the stack.

Definition at line 113 of file Histo2D.h.

References Histo2D().

113  {
114  return Histo2D(*this);
115  }
Histo2D(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Histo2D.h:49

◆ dim()

size_t YODA::Histo2D::dim ( ) const
inlinevirtual

Fill dimension of this data object.

Implements YODA::AnalysisObject.

Definition at line 126 of file Histo2D.h.

References fill().

126 { return 2; }

◆ effNumEntries()

double YODA::Histo2D::effNumEntries ( bool  includeoverflows = true) const

Get the effective number of fills.

Definition at line 95 of file Histo2D.cc.

References bins(), YODA::Dbn2D::effNumEntries(), and totalDbn().

Referenced by integral().

95  {
96  if (includeoverflows) return totalDbn().effNumEntries();
97  double n = 0;
98  for (const Bin& b : bins()) n += b.effNumEntries();
99  return n;
100  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260
double effNumEntries() const
Effective number of entries .
Definition: Dbn2D.h:171
HistoBin2D Bin
Definition: Histo2D.h:37
Dbn2D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo2D.h:293

◆ eraseBin()

void YODA::Histo2D::eraseBin ( size_t  index)
inline
Todo:
TODO
Todo:
TODO
Todo:
TODO

Rebin the whole histo by a factorX in the X direction and factorY in the Y direction

Todo:
TODO

Definition at line 233 of file Histo2D.h.

233  {
234  _axis.eraseBin(index);
235  }

◆ fill() [1/2]

void YODA::Histo2D::fill ( double  x,
double  y,
double  weight = 1.0,
double  fraction = 1.0 
)
virtual

Fill histo with weight at (x,y)

Unify this with Profile2D's version, when binning and inheritance are reworked

Todo:
Replace try block with a check that there is a bin at x, y
Todo:
Reinstate! With outflow axis bin lookup

Definition at line 50 of file Histo2D.cc.

References YODA::inRange().

Referenced by dim(), fill(), and fillBin().

50  {
51  if ( std::isnan(x) ) throw RangeError("X is NaN");
52  if ( std::isnan(y) ) throw RangeError("Y is NaN");
53 
54  // Fill the overall distribution
55  _axis.totalDbn().fill(x, y, weight, fraction);
56 
57  // Fill the bins and overflows
59  if (inRange(x, _axis.xMin(), _axis.xMax()) && inRange(y, _axis.yMin(), _axis.yMax())) {
60  try {
62  _binAt(x, y).fill(x, y, weight, fraction);
63  } catch (const RangeError& re) { }
64  }
66  // else {
67  // size_t ix(0), iy(0);
68  // if (x < _axis.xMin()) ix = -1; else if (x >= _axis.xMax()) ix = 1;
69  // if (y < _axis.yMin()) iy = -1; else if (y >= _axis.yMax()) iy = 1;
70  // _axis.outflow(ix, iy).fill(x, y, weight, fraction);
71  // }
72 
73  // Lock the axis now that a fill has happened
74  _axis._setLock(true);
75  }
bool inRange(NUM value, NUM low, NUM high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
Determine if value is in the range low to high, for floating point numbers.
Definition: MathUtils.h:155

◆ fill() [2/2]

virtual void YODA::Histo2D::fill ( const FillType xs,
double  weight = 1.0,
double  fraction = 1.0 
)
inlinevirtual

Definition at line 136 of file Histo2D.h.

References fill(), and fillBin().

136  {
137  fill(std::get<0>(xs), std::get<1>(xs), weight, fraction);
138  }
virtual void fill(double x, double y, double weight=1.0, double fraction=1.0)
Fill histo with weight at (x,y)
Definition: Histo2D.cc:50

◆ fillBin()

void YODA::Histo2D::fillBin ( size_t  i,
double  weight = 1.0,
double  fraction = 1.0 
)
virtual

Fill histo x-y bin i with the given weight.

Definition at line 78 of file Histo2D.cc.

References bin(), fill(), and YODA::Bin2D< DBN >::xyMid().

Referenced by fill().

78  {
79  pair<double, double> mid = bin(i).xyMid();
80  fill(mid.first, mid.second, weight, fraction);
81  }
std::pair< double, double > xyMid() const
The geometric centre of the bin.
Definition: Bin2D.h:179
virtual void fill(double x, double y, double weight=1.0, double fraction=1.0)
Fill histo with weight at (x,y)
Definition: Histo2D.cc:50
HistoBin2D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo2D.h:266

◆ integral()

double YODA::Histo2D::integral ( bool  includeoverflows = true) const
inline

Get the total volume of the histogram.

Definition at line 324 of file Histo2D.h.

References effNumEntries(), numEntries(), sumW(), sumW2(), xMean(), xVariance(), yMean(), and yVariance().

Referenced by normalize().

324 { return sumW(includeoverflows); }
double sumW(bool includeoverflows=true) const
Get the sum of weights in histo.
Definition: Histo2D.cc:103

◆ newclone()

Histo2D* YODA::Histo2D::newclone ( ) const
inlinevirtual

Make a copy on the heap, via 'new'.

Implements YODA::AnalysisObject.

Definition at line 118 of file Histo2D.h.

References Histo2D().

118  {
119  return new Histo2D(*this);
120  }
Histo2D(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Histo2D.h:49

◆ normalize()

void YODA::Histo2D::normalize ( double  normto = 1.0,
bool  includeoverflows = true 
)
inline

Normalize the (visible) histo "volume" to the normto value.

If includeoverflows is true, the original normalisation is computed with the overflow bins included, so that the resulting visible normalisation can be less than normto. This is probably what you want.

Definition at line 164 of file Histo2D.h.

References integral(), and scaleW().

164  {
165  const double oldintegral = integral(includeoverflows);
166  if (oldintegral == 0) throw WeightError("Attempted to normalize a histogram with null area");
167  scaleW(normto / oldintegral);
168  }
double integral(bool includeoverflows=true) const
Get the total volume of the histogram.
Definition: Histo2D.h:324
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Histo2D.h:153

◆ numBins()

size_t YODA::Histo2D::numBins ( ) const
inline

Number of bins.

Definition at line 283 of file Histo2D.h.

Referenced by YODA::divide(), YODA::efficiency(), YODA::mkScatter(), and YODA::toTH2D().

283 { return _axis.numBins(); }

◆ numBinsX()

size_t YODA::Histo2D::numBinsX ( ) const
inline

Number of bins along the x axis.

Definition at line 286 of file Histo2D.h.

286 { return _axis.numBinsX(); }

◆ numBinsY()

size_t YODA::Histo2D::numBinsY ( ) const
inline

Number of bins along the y axis.

Definition at line 289 of file Histo2D.h.

289 { return _axis.numBinsY(); }

◆ numEntries()

double YODA::Histo2D::numEntries ( bool  includeoverflows = true) const

Get the number of fills (fractional fills are possible)

Definition at line 87 of file Histo2D.cc.

References bins(), YODA::Dbn2D::numEntries(), and totalDbn().

Referenced by integral().

87  {
88  if (includeoverflows) return totalDbn().numEntries();
89  unsigned long n = 0;
90  for (const Bin& b : bins()) n += b.numEntries();
91  return n;
92  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260
HistoBin2D Bin
Definition: Histo2D.h:37
Dbn2D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo2D.h:293
double numEntries() const
Number of entries (number of times fill was called, ignoring weights)
Definition: Dbn2D.h:166

◆ operator!=()

bool YODA::Histo2D::operator!= ( const Histo2D other) const
inline

Definition at line 400 of file Histo2D.h.

References operator==().

400  {
401  return ! operator == (other);
402  }
bool operator==(const Histo2D &other) const
Definition: Histo2D.h:396

◆ operator+=()

Histo2D& YODA::Histo2D::operator+= ( const Histo2D toAdd)
inline

Add another histogram to this one.

Note
Adding histograms will unset any ScaledBy attribute from prevous calls to scaleW or normalize.

Definition at line 381 of file Histo2D.h.

References YODA::AnalysisObject::hasAnnotation(), and YODA::AnalysisObject::rmAnnotation().

381  {
382  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
383  _axis += toAdd._axis;
384  return *this;
385  }
void rmAnnotation(const std::string &name)
Delete an annotation by name.
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.

◆ operator-=()

Histo2D& YODA::Histo2D::operator-= ( const Histo2D toSubtract)
inline

Subtract another histogram from this one.

Note
Subtracting histograms will unset any ScaledBy attribute from prevous calls to scaleW or normalize.

Definition at line 390 of file Histo2D.h.

References YODA::AnalysisObject::hasAnnotation(), and YODA::AnalysisObject::rmAnnotation().

390  {
391  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
392  _axis -= toSubtract._axis;
393  return *this;
394  }
void rmAnnotation(const std::string &name)
Delete an annotation by name.
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.

◆ operator=()

Histo2D& YODA::Histo2D::operator= ( const Histo2D h2)
inline

Assignment operator.

Definition at line 105 of file Histo2D.h.

References YODA::AnalysisObject::operator=().

105  {
106  AnalysisObject::operator = (h2); //< AO treatment of paths etc.
107  _axis = h2._axis;
108  return *this;
109  }
virtual AnalysisObject & operator=(const AnalysisObject &ao)
Default copy assignment operator.

◆ operator==()

bool YODA::Histo2D::operator== ( const Histo2D other) const
inline

Definition at line 396 of file Histo2D.h.

Referenced by operator!=().

396  {
397  return _axis == other._axis;
398  }

◆ reset()

void YODA::Histo2D::reset ( )
inlinevirtual

Reset the histogram.

Keep the binning but set all bin contents and related quantities to zero

Implements YODA::AnalysisObject.

Definition at line 148 of file Histo2D.h.

148  {
149  _axis.reset();
150  }

◆ scaleW()

void YODA::Histo2D::scaleW ( double  scalefactor)
inline

Rescale as if all fill weights had been different by factor scalefactor.

Definition at line 153 of file Histo2D.h.

References YODA::AnalysisObject::setAnnotation().

Referenced by normalize().

153  {
154  setAnnotation("ScaledBy", annotation<double>("ScaledBy", 1.0) * scalefactor);
155  _axis.scaleW(scalefactor);
156  }
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.

◆ scaleXY()

void YODA::Histo2D::scaleXY ( double  scaleX = 1.0,
double  scaleY = 1.0 
)
inline

Scale the dimensions.

Definition at line 172 of file Histo2D.h.

172  {
173  _axis.scaleXY(scaleX, scaleY);
174  }

◆ setTotalDbn()

void YODA::Histo2D::setTotalDbn ( const Dbn2D dbn)
inline

Set summary distribution, including gaps and overflows.

Definition at line 297 of file Histo2D.h.

297 { _axis.setTotalDbn(dbn); }

◆ sumW()

double YODA::Histo2D::sumW ( bool  includeoverflows = true) const

Get the sum of weights in histo.

Definition at line 103 of file Histo2D.cc.

References bins().

Referenced by integral().

103  {
104  if (includeoverflows) return _axis.totalDbn().sumW();
105  double sumw = 0;
106  for (const Bin& b : bins()) sumw += b.sumW();
107  return sumw;
108  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260
HistoBin2D Bin
Definition: Histo2D.h:37

◆ sumW2()

double YODA::Histo2D::sumW2 ( bool  includeoverflows = true) const

Get the sum of squared weights in histo.

Definition at line 111 of file Histo2D.cc.

References bins().

Referenced by integral().

111  {
112  if (includeoverflows) return _axis.totalDbn().sumW2();
113  double sumw2 = 0;
114  for (const Bin& b : bins()) sumw2 += b.sumW2();
115  return sumw2;
116  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260
HistoBin2D Bin
Definition: Histo2D.h:37

◆ totalDbn() [1/2]

Dbn2D& YODA::Histo2D::totalDbn ( )
inline

Access summary distribution, including gaps and overflows (non-const version)

Definition at line 293 of file Histo2D.h.

Referenced by effNumEntries(), and numEntries().

293 { return _axis.totalDbn(); }

◆ totalDbn() [2/2]

const Dbn2D& YODA::Histo2D::totalDbn ( ) const
inline

Access summary distribution, including gaps and overflows (const version)

Definition at line 295 of file Histo2D.h.

295 { return _axis.totalDbn(); }

◆ xMax()

double YODA::Histo2D::xMax ( ) const
inline

High x edge of this histo's axis.

Definition at line 249 of file Histo2D.h.

249 { return _axis.xMax(); }

◆ xMean()

double YODA::Histo2D::xMean ( bool  includeoverflows = true) const

Get the mean x.

Definition at line 122 of file Histo2D.cc.

References bins(), and YODA::Dbn2D::xMean().

Referenced by integral().

122  {
123  if (includeoverflows) return _axis.totalDbn().xMean();
124  Dbn2D dbn;
125  for (const HistoBin2D& b : bins()) dbn += b.dbn();
126  return dbn.xMean();
127  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260

◆ xMin()

double YODA::Histo2D::xMin ( ) const
inline

Low x edge of this histo's axis.

Definition at line 246 of file Histo2D.h.

246 { return _axis.xMin(); }

◆ xRMS()

double YODA::Histo2D::xRMS ( bool  includeoverflows = true) const

Get the RMS in x.

Definition at line 170 of file Histo2D.cc.

References bins(), and YODA::Dbn2D::xRMS().

Referenced by yStdDev().

170  {
171  if (includeoverflows) return _axis.totalDbn().xRMS();
172  Dbn2D dbn;
173  for (const HistoBin2D& b : bins()) dbn += b.dbn();
174  return dbn.xRMS();
175  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260

◆ xStdDev()

double YODA::Histo2D::xStdDev ( bool  includeoverflows = true) const
inline

Get the standard deviation in x.

Definition at line 351 of file Histo2D.h.

References xVariance().

351  {
352  return std::sqrt(xVariance(includeoverflows));
353  }
double xVariance(bool includeoverflows=true) const
Get the variance in x.
Definition: Histo2D.cc:138

◆ xStdErr()

double YODA::Histo2D::xStdErr ( bool  includeoverflows = true) const

Get the standard error in x.

Definition at line 154 of file Histo2D.cc.

References bins(), and YODA::Dbn2D::xStdErr().

Referenced by yStdDev().

154  {
155  if (includeoverflows) return _axis.totalDbn().xStdErr();
156  Dbn2D dbn;
157  for (const HistoBin2D& b : bins()) dbn += b.dbn();
158  return dbn.xStdErr();
159  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260

◆ xVariance()

double YODA::Histo2D::xVariance ( bool  includeoverflows = true) const

Get the variance in x.

Definition at line 138 of file Histo2D.cc.

References bins(), and YODA::Dbn2D::xVariance().

Referenced by integral(), and xStdDev().

138  {
139  if (includeoverflows) return _axis.totalDbn().xVariance();
140  Dbn2D dbn;
141  for (const HistoBin2D& b : bins()) dbn += b.dbn();
142  return dbn.xVariance();
143  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260

◆ yMax()

double YODA::Histo2D::yMax ( ) const
inline

High y edge of this histo's axis.

Definition at line 256 of file Histo2D.h.

256 { return _axis.yMax(); }

◆ yMean()

double YODA::Histo2D::yMean ( bool  includeoverflows = true) const

Get the mean y.

Definition at line 130 of file Histo2D.cc.

References bins(), and YODA::Dbn2D::yMean().

Referenced by integral().

130  {
131  if (includeoverflows) return _axis.totalDbn().yMean();
132  Dbn2D dbn;
133  for (const HistoBin2D& b : bins()) dbn += b.dbn();
134  return dbn.yMean();
135  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260

◆ yMin()

double YODA::Histo2D::yMin ( ) const
inline

Low y edge of this histo's axis.

Definition at line 253 of file Histo2D.h.

253 { return _axis.yMin(); }

◆ yRMS()

double YODA::Histo2D::yRMS ( bool  includeoverflows = true) const

Get the RMS in y.

Definition at line 178 of file Histo2D.cc.

References bins(), and YODA::Dbn2D::yRMS().

Referenced by yStdDev().

178  {
179  if (includeoverflows) return _axis.totalDbn().yRMS();
180  Dbn2D dbn;
181  for (const HistoBin2D& b : bins()) dbn += b.dbn();
182  return dbn.yRMS();
183  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260

◆ yStdDev()

double YODA::Histo2D::yStdDev ( bool  includeoverflows = true) const
inline

Get the standard deviation in y.

Definition at line 356 of file Histo2D.h.

References xRMS(), xStdErr(), yRMS(), yStdErr(), and yVariance().

356  {
357  return std::sqrt(yVariance(includeoverflows));
358  }
double yVariance(bool includeoverflows=true) const
Get the variance in y.
Definition: Histo2D.cc:146

◆ yStdErr()

double YODA::Histo2D::yStdErr ( bool  includeoverflows = true) const

Get the standard error in y.

Definition at line 162 of file Histo2D.cc.

References bins(), and YODA::Dbn2D::yStdErr().

Referenced by yStdDev().

162  {
163  if (includeoverflows) return _axis.totalDbn().yStdErr();
164  Dbn2D dbn;
165  for (const HistoBin2D& b : bins()) dbn += b.dbn();
166  return dbn.yStdErr();
167  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260

◆ yVariance()

double YODA::Histo2D::yVariance ( bool  includeoverflows = true) const

Get the variance in y.

Definition at line 146 of file Histo2D.cc.

References bins(), and YODA::Dbn2D::yVariance().

Referenced by integral(), and yStdDev().

146  {
147  if (includeoverflows) return _axis.totalDbn().yVariance();
148  Dbn2D dbn;
149  for (const HistoBin2D& b : bins()) dbn += b.dbn();
150  return dbn.yVariance();
151  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:260

The documentation for this class was generated from the following files: