YODA is hosted by Hepforge, IPPP Durham
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
 
- 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

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
void fill (double x, double y, double weight=1.0)
 Fill histo with weight at (x,y) More...
 
void fillBin (size_t i, double weight=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 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...
 
const HistoBin2DbinAt (double x, double y) const
 Access a bin by coordinate (const version) More...
 
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...
 
Whole histo data
double integral (bool includeoverflows=true) const
 Get the total volume of the histogram. More...
 
double numEntries () const
 Get the number of fills. More...
 
double effNumEntries () 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...
 
const std::vector< std::string > annotations () const
 Get all the annotation names. More...
 
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...
 
template<typename T >
void setAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name. 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
 
void setTitle (const std::string &title)
 Set the AO title. More...
 
const std::string path () const
 
void setPath (const std::string &path)
 Set the AO path. More...
 
virtual std::string type () const
 Get name of the analysis object type, for persistency. More...
 

Protected Member Functions

HistoBin2DbinAt (double x, double y)
 Access a bin by coordinate (non-const version) More...
 

Detailed Description

A two-dimensional histogram.

Definition at line 30 of file Histo2D.h.

Member Typedef Documentation

Convenience typedefs.

Definition at line 34 of file Histo2D.h.

Definition at line 36 of file Histo2D.h.

Definition at line 35 of file Histo2D.h.

Definition at line 37 of file Histo2D.h.

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 44 of file Histo2D.h.

Referenced by clone(), and newclone().

45  : AnalysisObject("Histo2D", path, title),
46  _axis()
47  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
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 51 of file Histo2D.h.

54  : AnalysisObject("Histo2D", path, title),
55  _axis(nbinsX, std::make_pair(lowerX, upperX), nbinsY, std::make_pair(lowerY, upperY))
56  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
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 60 of file Histo2D.h.

62  : AnalysisObject("Histo2D", path, title),
63  _axis(xedges, yedges)
64  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
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 68 of file Histo2D.h.

70  : AnalysisObject("Histo2D", path, title),
71  _axis(bins)
72  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
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 138 of file Histo2D.cc.

139  : AnalysisObject("Histo2D", (path.size() == 0) ? h.path() : path, h, h.title()),
140  _axis(h._axis)
141  { }
AnalysisObject()
Default constructor.
const std::string path() const
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 145 of file Histo2D.cc.

References bins(), YODA::Scatter3D::points(), YODA::Point3D::xMax(), YODA::Point3D::xMin(), YODA::Point3D::yMax(), and YODA::Point3D::yMin().

146  : AnalysisObject("Histo2D", (path.size() == 0) ? s.path() : path, s, s.title())
147  {
148  std::vector<HistoBin2D> bins;
149  BOOST_FOREACH (const Scatter3D::Point& p, s.points()) {
150  bins.push_back(HistoBin2D(p.xMin(), p.xMax(), p.yMin(), p.yMax()));
151  }
152  _axis = Histo2DAxis(bins);
153  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:241
AnalysisObject()
Default constructor.
Axis2D< HistoBin2D, Dbn2D > Histo2DAxis
Convenience typedef.
Definition: Histo2D.h:23
const std::string path() const
Point3D Point
Types of the native Point3D collection.
Definition: Scatter3D.h:27
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 157 of file Histo2D.cc.

References YODA::Profile2D::bins(), bins(), YODA::Bin2D< DBN >::xMax(), YODA::Bin2D< DBN >::xMin(), YODA::Bin2D< DBN >::yMax(), and YODA::Bin2D< DBN >::yMin().

158  : AnalysisObject("Histo2D", (path.size() == 0) ? p.path() : path, p, p.title())
159  {
160  std::vector<HistoBin2D> bins;
161  BOOST_FOREACH (const ProfileBin2D& b, p.bins()) {
162  bins.push_back(HistoBin2D(b.xMin(), b.xMax(), b.yMin(), b.yMax()));
163  }
164  _axis = Histo2DAxis(bins);
165  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:241
AnalysisObject()
Default constructor.
Axis2D< HistoBin2D, Dbn2D > Histo2DAxis
Convenience typedef.
Definition: Histo2D.h:23
const std::string path() const
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 90 of file Histo2D.h.

94  : AnalysisObject("Histo2D", path, title),
95  _axis(bins, totalDbn, outflows)
96  { }
AnalysisObject()
Default constructor.
Dbn2D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo2D.h:270
const std::string path() const
const std::string title() const

Member Function Documentation

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 168 of file Histo2D.h.

168  {
169  _axis.addBin(xrange, yrange);
170  }
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 176 of file Histo2D.h.

176  {
177  _axis.addBins(xcuts, ycuts);
178  }
void YODA::Histo2D::addBins ( const Bins bins)
inline

Bins addition operator.

Add multiple bins without resetting

Definition at line 184 of file Histo2D.h.

184  {
185  _axis.addBins(bins);
186  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:241
HistoBin2D& YODA::Histo2D::bin ( size_t  index)
inline

Access a bin by index (non-const version)

Definition at line 247 of file Histo2D.h.

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

247 { return _axis.bin(index); }
const HistoBin2D& YODA::Histo2D::bin ( size_t  index) const
inline

Access a bin by index (const version)

Definition at line 249 of file Histo2D.h.

249 { return _axis.bin(index); }
const HistoBin2D& YODA::Histo2D::binAt ( double  x,
double  y 
) const
inline

Access a bin by coordinate (const version)

Definition at line 256 of file Histo2D.h.

Referenced by YODA::toTH2D().

256 { return _axis.binAt(x, y); }
HistoBin2D& YODA::Histo2D::binAt ( double  x,
double  y 
)
inlineprotected

Access a bin by coordinate (non-const version)

Definition at line 412 of file Histo2D.h.

412 { return _axis.binAt(x, y); }
int YODA::Histo2D::binIndexAt ( double  x,
double  y 
)
inline

Access a bin index by coordinate.

Definition at line 253 of file Histo2D.h.

253 { return _axis.binIndexAt(x, y); }
std::vector<YODA::HistoBin2D>& YODA::Histo2D::bins ( )
inline

Access the bin vector (non-const version)

Definition at line 241 of file Histo2D.h.

Referenced by Histo2D(), YODA::Profile2D::Profile2D(), and YODA::WriterYODA::writeHisto2D().

241 { return _axis.bins(); }
const std::vector<YODA::HistoBin2D>& YODA::Histo2D::bins ( ) const
inline

Access the bin vector (const version)

Definition at line 243 of file Histo2D.h.

243 { return _axis.bins(); }
Histo2D YODA::Histo2D::clone ( ) const
inline

Make a copy on the stack.

Definition at line 108 of file Histo2D.h.

References Histo2D().

108  {
109  return Histo2D(*this);
110  }
Histo2D(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Histo2D.h:44
double YODA::Histo2D::effNumEntries ( ) const
inline

Get the effective number of fills.

Definition at line 305 of file Histo2D.h.

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

305 { return totalDbn().effNumEntries(); }
double effNumEntries() const
Effective number of entries .
Definition: Dbn2D.h:171
Dbn2D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo2D.h:270
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 214 of file Histo2D.h.

214  {
215  _axis.eraseBin(index);
216  }
void YODA::Histo2D::fill ( double  x,
double  y,
double  weight = 1.0 
)

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 16 of file Histo2D.cc.

References YODA::inRange().

16  {
17  if ( std::isnan(x) ) throw RangeError("X is NaN");
18  if ( std::isnan(y) ) throw RangeError("Y is NaN");
19 
20  // Fill the overall distribution
21  _axis.totalDbn().fill(x, y, weight);
22 
23  // Fill the bins and overflows
25  if (inRange(x, _axis.xMin(), _axis.xMax()) && inRange(y, _axis.yMin(), _axis.yMax())) {
26  try {
28  binAt(x, y).fill(x, y, weight);
29  } catch (const RangeError& re) { }
30  }
32  // else {
33  // size_t ix(0), iy(0);
34  // if (x < _axis.xMin()) ix = -1; else if (x >= _axis.xMax()) ix = 1;
35  // if (y < _axis.yMin()) iy = -1; else if (y >= _axis.yMax()) iy = 1;
36  // _axis.outflow(ix, iy).fill(x, y, weight);
37  // }
38 
39  // Lock the axis now that a fill has happened
40  _axis._setLock(true);
41  }
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:151
const HistoBin2D & binAt(double x, double y) const
Access a bin by coordinate (const version)
Definition: Histo2D.h:256
void fill(double x, double y, double weight=1.0)
Definition: HistoBin2D.h:66
void YODA::Histo2D::fillBin ( size_t  i,
double  weight = 1.0 
)

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

Definition at line 44 of file Histo2D.cc.

44  {
45  pair<double, double> mid = bin(i).xyMid();
46  fill(mid.first, mid.second, weight);
47  }
void fill(double x, double y, double weight=1.0)
Fill histo with weight at (x,y)
Definition: Histo2D.cc:16
std::pair< double, double > xyMid() const
The geometric centre of the bin.
Definition: Bin2D.h:173
HistoBin2D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo2D.h:247
double YODA::Histo2D::integral ( bool  includeoverflows = true) const
inline

Get the total volume of the histogram.

Definition at line 299 of file Histo2D.h.

References sumW().

Referenced by normalize(), and YODA::WriterYODA::writeHisto2D().

299 { return sumW(includeoverflows); }
double sumW(bool includeoverflows=true) const
Get the sum of weights in histo.
Definition: Histo2D.cc:50
Histo2D* YODA::Histo2D::newclone ( ) const
inlinevirtual

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

Implements YODA::AnalysisObject.

Definition at line 113 of file Histo2D.h.

References Histo2D().

113  {
114  return new Histo2D(*this);
115  }
Histo2D(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Histo2D.h:44
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.

Todo:
Check that this is the desired behaviour

Definition at line 151 of file Histo2D.h.

References integral(), and scaleW().

151  {
152  const double oldintegral = integral(includeoverflows);
153  if (oldintegral == 0) throw WeightError("Attempted to normalize a histogram with null area");
155  scaleW(normto / oldintegral);
156  }
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Histo2D.h:140
double integral(bool includeoverflows=true) const
Get the total volume of the histogram.
Definition: Histo2D.h:299
size_t YODA::Histo2D::numBins ( ) const
inline

Number of bins.

Definition at line 260 of file Histo2D.h.

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

260 { return _axis.numBins(); }
size_t YODA::Histo2D::numBinsX ( ) const
inline

Number of bins along the x axis.

Definition at line 263 of file Histo2D.h.

263 { return _axis.numBinsX(); }
size_t YODA::Histo2D::numBinsY ( ) const
inline

Number of bins along the y axis.

Definition at line 266 of file Histo2D.h.

266 { return _axis.numBinsY(); }
double YODA::Histo2D::numEntries ( ) const
inline

Get the number of fills.

Definition at line 302 of file Histo2D.h.

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

302 { return totalDbn().numEntries(); }
unsigned long numEntries() const
Number of entries (number of times fill was called, ignoring weights)
Definition: Dbn2D.h:166
Dbn2D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo2D.h:270
bool YODA::Histo2D::operator!= ( const Histo2D other) const
inline

Definition at line 375 of file Histo2D.h.

References operator==().

375  {
376  return ! operator == (other);
377  }
bool operator==(const Histo2D &other) const
Definition: Histo2D.h:371
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 356 of file Histo2D.h.

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

356  {
357  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
358  _axis += toAdd._axis;
359  return *this;
360  }
void rmAnnotation(const std::string &name)
Delete an annotation by name.
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.
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 365 of file Histo2D.h.

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

365  {
366  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
367  _axis -= toSubtract._axis;
368  return *this;
369  }
void rmAnnotation(const std::string &name)
Delete an annotation by name.
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.
Histo2D& YODA::Histo2D::operator= ( const Histo2D h2)
inline

Assignment operator.

Definition at line 100 of file Histo2D.h.

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

100  {
101  AnalysisObject::operator = (h2); //< AO treatment of paths etc.
102  _axis = h2._axis;
103  return *this;
104  }
virtual AnalysisObject & operator=(const AnalysisObject &ao)
Default copy assignment operator.
bool YODA::Histo2D::operator== ( const Histo2D other) const
inline

Definition at line 371 of file Histo2D.h.

Referenced by operator!=().

371  {
372  return _axis == other._axis;
373  }
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 135 of file Histo2D.h.

135  {
136  _axis.reset();
137  }
void YODA::Histo2D::scaleW ( double  scalefactor)
inline

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

Definition at line 140 of file Histo2D.h.

References YODA::AnalysisObject::setAnnotation().

Referenced by normalize().

140  {
141  setAnnotation("ScaledBy", annotation<double>("ScaledBy", 1.0) * scalefactor);
142  _axis.scaleW(scalefactor);
143  }
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name.
void YODA::Histo2D::scaleXY ( double  scaleX = 1.0,
double  scaleY = 1.0 
)
inline

Scale the dimensions.

Definition at line 160 of file Histo2D.h.

160  {
161  _axis.scaleXY(scaleX, scaleY);
162  }
double YODA::Histo2D::sumW ( bool  includeoverflows = true) const

Get the sum of weights in histo.

Definition at line 50 of file Histo2D.cc.

References YODA::Bin2D< DBN >::sumW().

Referenced by integral().

50  {
51  if (includeoverflows) return _axis.totalDbn().sumW();
52  double sumw = 0;
53  BOOST_FOREACH (const HistoBin2D& b, bins()) sumw += b.sumW();
54  return sumw;
55  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:241
double sumW(bool includeoverflows=true) const
Get the sum of weights in histo.
Definition: Histo2D.cc:50
double YODA::Histo2D::sumW2 ( bool  includeoverflows = true) const

Get the sum of squared weights in histo.

Definition at line 58 of file Histo2D.cc.

References YODA::Bin2D< DBN >::sumW2().

58  {
59  if (includeoverflows) return _axis.totalDbn().sumW2();
60  double sumw2 = 0;
61  BOOST_FOREACH (const HistoBin2D& b, bins()) sumw2 += b.sumW2();
62  return sumw2;
63  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:241
double sumW2(bool includeoverflows=true) const
Get the sum of squared weights in histo.
Definition: Histo2D.cc:58
Dbn2D& YODA::Histo2D::totalDbn ( )
inline

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

Definition at line 270 of file Histo2D.h.

Referenced by effNumEntries(), numEntries(), and YODA::WriterYODA::writeHisto2D().

270 { return _axis.totalDbn(); }
const Dbn2D& YODA::Histo2D::totalDbn ( ) const
inline

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

Definition at line 272 of file Histo2D.h.

272 { return _axis.totalDbn(); }
double YODA::Histo2D::xMax ( ) const
inline

High x edge of this histo's axis.

Definition at line 230 of file Histo2D.h.

230 { return _axis.xMax(); }
double YODA::Histo2D::xMean ( bool  includeoverflows = true) const

Get the mean x.

Definition at line 66 of file Histo2D.cc.

References YODA::Bin2D< DBN >::sumWX().

Referenced by YODA::WriterYODA::writeHisto2D().

66  {
67  if (includeoverflows) return _axis.totalDbn().xMean();
68  double sumwx = 0;
69  BOOST_FOREACH (const HistoBin2D& b, bins()) sumwx += b.sumWX();
70  return sumwx/sumW();
71  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:241
double sumW(bool includeoverflows=true) const
Get the sum of weights in histo.
Definition: Histo2D.cc:50
double YODA::Histo2D::xMin ( ) const
inline

Low x edge of this histo's axis.

Definition at line 227 of file Histo2D.h.

227 { return _axis.xMin(); }
double YODA::Histo2D::xRMS ( bool  includeoverflows = true) const

Get the RMS in x.

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

Get the standard deviation in x.

Definition at line 326 of file Histo2D.h.

References xVariance().

326  {
327  return std::sqrt(xVariance(includeoverflows));
328  }
double xVariance(bool includeoverflows=true) const
Get the variance in x.
Definition: Histo2D.cc:82
double YODA::Histo2D::xStdErr ( bool  includeoverflows = true) const

Get the standard error in x.

Definition at line 108 of file Histo2D.cc.

108  {
109  if (includeoverflows) return _axis.totalDbn().xStdErr();
110  const double effNumEntries = sumW(false)*sumW(false)/sumW2(false);
111  return std::sqrt(xVariance(false) / effNumEntries);
112  }
double effNumEntries() const
Get the effective number of fills.
Definition: Histo2D.h:305
double sumW(bool includeoverflows=true) const
Get the sum of weights in histo.
Definition: Histo2D.cc:50
double xVariance(bool includeoverflows=true) const
Get the variance in x.
Definition: Histo2D.cc:82
double sumW2(bool includeoverflows=true) const
Get the sum of squared weights in histo.
Definition: Histo2D.cc:58
double YODA::Histo2D::xVariance ( bool  includeoverflows = true) const

Get the variance in x.

Todo:
Improve this, by adding the Dbn2Ds and returning the resulting xVariance

Definition at line 82 of file Histo2D.cc.

Referenced by xStdDev().

82  {
83  if (includeoverflows) return _axis.totalDbn().xVariance();
85  double sigma2 = 0;
86  const double xMean = this->xMean();
87  for (size_t i = 0; i < bins().size(); ++i) {
88  const double diff = bin(i).xFocus() - xMean;
89  sigma2 += diff * diff * bin(i).sumW();
90  }
91  return sigma2/sumW();
92  }
double xFocus() const
The mean x position in the bin, or the x midpoint if that is not available.
Definition: Bin2D.h:195
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:241
double xMean(bool includeoverflows=true) const
Get the mean x.
Definition: Histo2D.cc:66
double sumW() const
The sum of weights.
Definition: Bin2D.h:296
double sumW(bool includeoverflows=true) const
Get the sum of weights in histo.
Definition: Histo2D.cc:50
HistoBin2D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo2D.h:247
double YODA::Histo2D::yMax ( ) const
inline

High y edge of this histo's axis.

Definition at line 237 of file Histo2D.h.

237 { return _axis.yMax(); }
double YODA::Histo2D::yMean ( bool  includeoverflows = true) const

Get the mean y.

Definition at line 74 of file Histo2D.cc.

References YODA::Bin2D< DBN >::sumWY().

Referenced by YODA::WriterYODA::writeHisto2D().

74  {
75  if (includeoverflows) return _axis.totalDbn().yMean();
76  double sumwy = 0;
77  BOOST_FOREACH (const HistoBin2D& b, bins()) sumwy += b.sumWY();
78  return sumwy/sumW();
79  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:241
double sumW(bool includeoverflows=true) const
Get the sum of weights in histo.
Definition: Histo2D.cc:50
double YODA::Histo2D::yMin ( ) const
inline

Low y edge of this histo's axis.

Definition at line 234 of file Histo2D.h.

234 { return _axis.yMin(); }
double YODA::Histo2D::yRMS ( bool  includeoverflows = true) const

Get the RMS in y.

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

Get the standard deviation in y.

Definition at line 331 of file Histo2D.h.

References yVariance().

331  {
332  return std::sqrt(yVariance(includeoverflows));
333  }
double yVariance(bool includeoverflows=true) const
Get the variance in y.
Definition: Histo2D.cc:95
double YODA::Histo2D::yStdErr ( bool  includeoverflows = true) const

Get the standard error in y.

Definition at line 115 of file Histo2D.cc.

115  {
116  if (includeoverflows) return _axis.totalDbn().yStdErr();
117  const double effNumEntries = sumW(false)*sumW(false)/sumW2(false);
118  return std::sqrt(yVariance(false) / effNumEntries);
119  }
double effNumEntries() const
Get the effective number of fills.
Definition: Histo2D.h:305
double sumW(bool includeoverflows=true) const
Get the sum of weights in histo.
Definition: Histo2D.cc:50
double sumW2(bool includeoverflows=true) const
Get the sum of squared weights in histo.
Definition: Histo2D.cc:58
double yVariance(bool includeoverflows=true) const
Get the variance in y.
Definition: Histo2D.cc:95
double YODA::Histo2D::yVariance ( bool  includeoverflows = true) const

Get the variance in y.

Todo:
Improve this, by adding the Dbn2Ds and returning the resulting yVariance

Definition at line 95 of file Histo2D.cc.

Referenced by yStdDev().

95  {
96  if (includeoverflows) return _axis.totalDbn().yVariance();
98  double sigma2 = 0;
99  const double yMean = this->yMean();
100  for (size_t i = 0; i < bins().size(); ++i) {
101  const double diff = bin(i).yFocus() - yMean;
102  sigma2 += diff * diff * bin(i).sumW();
103  }
104  return sigma2/sumW();
105  }
std::vector< YODA::HistoBin2D > & bins()
Access the bin vector (non-const version)
Definition: Histo2D.h:241
double yFocus() const
The mean y position in the bin, or the y midpoint if that is not available.
Definition: Bin2D.h:200
double sumW() const
The sum of weights.
Definition: Bin2D.h:296
double sumW(bool includeoverflows=true) const
Get the sum of weights in histo.
Definition: Histo2D.cc:50
HistoBin2D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo2D.h:247
double yMean(bool includeoverflows=true) const
Get the mean y.
Definition: Histo2D.cc:74

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