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

A one-dimensional histogram. More...

#include <Histo1D.h>

Inheritance diagram for YODA::Histo1D:
YODA::AnalysisObject

Public Types

typedef Histo1DAxis Axis
 Convenience typedefs. More...
 
typedef Axis::Bins Bins
 
typedef HistoBin1D Bin
 
typedef double FillType
 
typedef FillType BinType
 
typedef std::shared_ptr< Histo1DPtr
 
- 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
 Histo1D (const std::string &path="", const std::string &title="")
 Default constructor. More...
 
 Histo1D (size_t nbins, double lower, double upper, const std::string &path="", const std::string &title="")
 Constructor giving range and number of bins. More...
 
 Histo1D (const std::vector< double > &binedges, const std::string &path="", const std::string &title="")
 Constructor giving explicit bin edges. More...
 
 Histo1D (const std::vector< Bin > &bins, const std::string &path="", const std::string &title="")
 Constructor accepting an explicit collection of bins. More...
 
 Histo1D (const Histo1D &h, const std::string &path="")
 Copy constructor with optional new path. More...
 
 Histo1D (const Scatter2D &s, const std::string &path="")
 Constructor from a Scatter2D's binning, with optional new path. More...
 
 Histo1D (const Profile1D &p, const std::string &path="")
 Constructor from a Profile1D's binning, with optional new path. More...
 
 Histo1D (const std::vector< HistoBin1D > &bins, const Dbn1D &dbn_tot, const Dbn1D &dbn_uflow, const Dbn1D &dbn_oflow, const std::string &path="", const std::string &title="")
 State-setting constructor. More...
 
Histo1Doperator= (const Histo1D &h1)
 Assignment operator. More...
 
Histo1D clone () const
 Make a copy on the stack. More...
 
Histo1Dnewclone () const
 Make a copy on the heap, via 'new'. More...
 
Modifiers
virtual void reset ()
 Reset the histogram. More...
 
virtual void fill (double x, double weight=1.0, double fraction=1.0)
 Fill histo by value and weight, optionally as a fractional fill. More...
 
virtual void fillBin (size_t i, double weight=1.0, double fraction=1.0)
 Fill histo bin i with the given weight, optionally as a fractional fill. 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 mergeBins (size_t from, size_t to)
 Merge together the bin range with indices from from to to, inclusive. More...
 
void rebinBy (unsigned int n, size_t begin=0, size_t end=UINT_MAX)
 Merge every group of n bins, starting from the LHS. More...
 
void rebin (unsigned int n, size_t begin=0, size_t end=UINT_MAX)
 Overloaded alias for rebinBy. More...
 
void rebinTo (const std::vector< double > &newedges)
 Rebin to the given list of bin edges. More...
 
void rebin (const std::vector< double > &newedges)
 Overloaded alias for rebinTo. More...
 
Bin accessors
size_t numBins () const
 Number of bins on this axis (not counting under/overflow) More...
 
double xMin () const
 Low edge of this histo's axis. More...
 
double xMax () const
 High edge of this histo's axis. More...
 
const std::vector< double > xEdges () const
 
std::vector< YODA::HistoBin1D > & bins ()
 Access the bin vector. More...
 
const std::vector< YODA::HistoBin1D > & bins () const
 Access the bin vector (const version) More...
 
HistoBin1Dbin (size_t index)
 Access a bin by index (non-const version) More...
 
const HistoBin1Dbin (size_t index) const
 Access a bin by index (const version) More...
 
int binIndexAt (double x)
 
const HistoBin1DbinAt (double x) const
 Access a bin by coordinate (const version) More...
 
Dbn1DtotalDbn ()
 Access summary distribution, including gaps and overflows (non-const version) More...
 
const Dbn1DtotalDbn () const
 Access summary distribution, including gaps and overflows (const version) More...
 
void setTotalDbn (const Dbn1D &dbn)
 Set summary distribution, mainly for persistency: CAREFUL! More...
 
Dbn1Dunderflow ()
 Access underflow (non-const version) More...
 
const Dbn1Dunderflow () const
 Access underflow (const version) More...
 
void setUnderflow (const Dbn1D &dbn)
 Set underflow distribution, mainly for persistency: CAREFUL! More...
 
Dbn1Doverflow ()
 Access overflow (non-const version) More...
 
const Dbn1Doverflow () const
 Access overflow (const version) More...
 
void setOverflow (const Dbn1D &dbn)
 Set overflow distribution, mainly for persistency: CAREFUL! More...
 
void addBin (double from, double to)
 Add a new bin specifying its lower and upper bound. More...
 
void addBins (std::vector< double > edges)
 Add new bins by specifying a vector of edges. More...
 
void addBin (const HistoBin1D &b)
 Add a new bin, perhaps already populated: CAREFUL! More...
 
void addBins (const Bins &bins)
 Bins addition operator. More...
 
void eraseBin (size_t index)
 Remove a bin. More...
 
Whole histo data
double integral (bool includeoverflows=true) const
 Get the total area (sumW) of the histogram. More...
 
double integralRange (size_t binindex1, size_t binindex2) const
 Get the integrated area of the histogram between bins binindex1 and binindex2. More...
 
double integralTo (size_t binindex, bool includeunderflow=true) const
 Get the integrated area of the histogram up to bin binindex. More...
 
double numEntries (bool includeoverflows=true) const
 Get the number of fills. More...
 
double effNumEntries (bool includeoverflows=true) const
 Get the effective number of fills. More...
 
double sumW (bool includeoverflows=true) const
 Get sum of weights in histo. More...
 
double sumW2 (bool includeoverflows=true) const
 Get sum of squared weights in histo. More...
 
double xMean (bool includeoverflows=true) const
 Get the mean in x. More...
 
double xVariance (bool includeoverflows=true) const
 Get the variance in x. More...
 
double xStdDev (bool includeoverflows=true) const
 Get the standard deviation in x. More...
 
double xStdErr (bool includeoverflows=true) const
 Get the standard error in x. More...
 
double xRMS (bool includeoverflows=true) const
 Get the RMS in x. More...
 
Adding and subtracting histograms
Histo1Doperator+= (const Histo1D &toAdd)
 Add another histogram to this one. More...
 
Histo1Doperator-= (const Histo1D &toSubtract)
 Subtract another histogram from this one. More...
 
- 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 one-dimensional histogram.

Definition at line 26 of file Histo1D.h.

Member Typedef Documentation

◆ Axis

Convenience typedefs.

Definition at line 30 of file Histo1D.h.

◆ Bin

Definition at line 32 of file Histo1D.h.

◆ Bins

Definition at line 31 of file Histo1D.h.

◆ BinType

Definition at line 35 of file Histo1D.h.

◆ FillType

typedef double YODA::Histo1D::FillType

Definition at line 34 of file Histo1D.h.

◆ Ptr

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

Definition at line 36 of file Histo1D.h.

Constructor & Destructor Documentation

◆ Histo1D() [1/8]

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

Default constructor.

Definition at line 42 of file Histo1D.h.

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

43  : AnalysisObject("Histo1D", path, title),
44  _axis()
45  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.

◆ Histo1D() [2/8]

YODA::Histo1D::Histo1D ( size_t  nbins,
double  lower,
double  upper,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor giving range and number of bins.

Definition at line 49 of file Histo1D.h.

51  : AnalysisObject("Histo1D", path, title),
52  _axis(nbins, lower, upper)
53  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.

◆ Histo1D() [3/8]

YODA::Histo1D::Histo1D ( const std::vector< double > &  binedges,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor giving explicit bin edges.

For n bins, binedges.size() == n+1, the last one being the upper bound of the last bin

Definition at line 60 of file Histo1D.h.

62  : AnalysisObject("Histo1D", path, title),
63  _axis(binedges)
64  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.

◆ Histo1D() [4/8]

YODA::Histo1D::Histo1D ( 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 Histo1D.h.

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

70  : AnalysisObject("Histo1D", path, title),
71  _axis(bins)
72  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.

◆ Histo1D() [5/8]

YODA::Histo1D::Histo1D ( const Histo1D 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 118 of file Histo1D.cc.

119  : AnalysisObject("Histo1D", (path.size() == 0) ? h.path() : path, h, h.title())
120  {
121  _axis = h._axis;
122  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.

◆ Histo1D() [6/8]

YODA::Histo1D::Histo1D ( const Scatter2D s,
const std::string &  path = "" 
)

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

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

Todo:
Also allow title setting from the constructor?

Definition at line 126 of file Histo1D.cc.

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

127  : AnalysisObject("Histo1D", (path.size() == 0) ? s.path() : path, s, s.title())
128  {
129  std::vector<HistoBin1D> bins;
130  for (const Scatter2D::Point& p : s.points()) {
131  bins.push_back(HistoBin1D(p.xMin(), p.xMax()));
132  }
133  _axis = Histo1DAxis(bins);
134  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211
Axis1D< HistoBin1D, Dbn1D > Histo1DAxis
Convenience typedef.
Definition: Histo1D.h:23
Point2D Point
Type of the native Point2D collection.
Definition: Scatter2D.h:28

◆ Histo1D() [7/8]

YODA::Histo1D::Histo1D ( const Profile1D p,
const std::string &  path = "" 
)

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

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

Todo:
Also allow title setting from the constructor?

Definition at line 138 of file Histo1D.cc.

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

139  : AnalysisObject("Histo1D", (path.size() == 0) ? p.path() : path, p, p.title())
140  {
141  std::vector<HistoBin1D> bins;
142  for (const ProfileBin1D& b : p.bins()) {
143  bins.push_back(HistoBin1D(b.xMin(), b.xMax()));
144  }
145  _axis = Histo1DAxis(bins);
146  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211
Axis1D< HistoBin1D, Dbn1D > Histo1DAxis
Convenience typedef.
Definition: Histo1D.h:23

◆ Histo1D() [8/8]

YODA::Histo1D::Histo1D ( const std::vector< HistoBin1D > &  bins,
const Dbn1D dbn_tot,
const Dbn1D dbn_uflow,
const Dbn1D dbn_oflow,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

State-setting constructor.

Intended principally for internal persistency use.

Definition at line 93 of file Histo1D.h.

96  : AnalysisObject("Histo1D", path, title),
97  _axis(bins, dbn_tot, dbn_uflow, dbn_oflow)
98  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.

Member Function Documentation

◆ addBin() [1/2]

void YODA::Histo1D::addBin ( double  from,
double  to 
)
inline

Add a new bin specifying its lower and upper bound.

Definition at line 257 of file Histo1D.h.

257 { _axis.addBin(from, to); }

◆ addBin() [2/2]

void YODA::Histo1D::addBin ( const HistoBin1D b)
inline

Add a new bin, perhaps already populated: CAREFUL!

Definition at line 268 of file Histo1D.h.

268 { _axis.addBin(b); }

◆ addBins() [1/2]

void YODA::Histo1D::addBins ( std::vector< double >  edges)
inline

Add new bins by specifying a vector of edges.

Definition at line 260 of file Histo1D.h.

260 { _axis.addBins(edges); }

◆ addBins() [2/2]

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

Bins addition operator.

Add multiple bins without resetting

Definition at line 273 of file Histo1D.h.

273  {
274  _axis.addBins(bins);
275  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211

◆ bin() [1/2]

HistoBin1D& YODA::Histo1D::bin ( size_t  index)
inline

Access a bin by index (non-const version)

Definition at line 217 of file Histo1D.h.

Referenced by YODA::add(), YODA::chi2(), YODA::divide(), YODA::efficiency(), integralRange(), YODA::multiply(), YODA::subtract(), YODA::toIntegralHisto(), and YODA::toTH1D().

217 { return _axis.bins()[index]; }

◆ bin() [2/2]

const HistoBin1D& YODA::Histo1D::bin ( size_t  index) const
inline

Access a bin by index (const version)

Definition at line 219 of file Histo1D.h.

219 { return _axis.bins()[index]; }

◆ binAt()

const HistoBin1D& YODA::Histo1D::binAt ( double  x) const
inline

Access a bin by coordinate (const version)

Definition at line 229 of file Histo1D.h.

Referenced by YODA::toTH1D().

229 { return _axis.binAt(x); }

◆ binIndexAt()

int YODA::Histo1D::binIndexAt ( double  x)
inline

Access a bin index by coordinate

Todo:
Convert to ssize_t?

Definition at line 224 of file Histo1D.h.

224  {
225  return _axis.binIndexAt(x);
226  }

◆ bins() [1/2]

std::vector<YODA::HistoBin1D>& YODA::Histo1D::bins ( )
inline

Access the bin vector.

Definition at line 211 of file Histo1D.h.

Referenced by Histo1D(), YODA::mkScatter(), numBins(), and YODA::Profile1D::Profile1D().

211 { return _axis.bins(); }

◆ bins() [2/2]

const std::vector<YODA::HistoBin1D>& YODA::Histo1D::bins ( ) const
inline

Access the bin vector (const version)

Definition at line 213 of file Histo1D.h.

213 { return _axis.bins(); }

◆ clone()

Histo1D YODA::Histo1D::clone ( ) const
inline

Make a copy on the stack.

Definition at line 109 of file Histo1D.h.

References Histo1D().

109  {
110  return Histo1D(*this);
111  }
Histo1D(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Histo1D.h:42

◆ dim()

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

Fill dimension of this data object.

Implements YODA::AnalysisObject.

Definition at line 122 of file Histo1D.h.

122 { return 1; }

◆ effNumEntries()

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

Get the effective number of fills.

Definition at line 56 of file Histo1D.cc.

Referenced by integralTo().

56  {
57  if (includeoverflows) return totalDbn().effNumEntries();
58  double n = 0;
59  for (const Bin& b : bins()) n += b.effNumEntries();
60  return n;
61  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211
HistoBin1D Bin
Definition: Histo1D.h:32
double effNumEntries() const
Effective number of entries .
Definition: Dbn1D.h:147
Dbn1D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo1D.h:233

◆ eraseBin()

void YODA::Histo1D::eraseBin ( size_t  index)
inline

Remove a bin.

Definition at line 278 of file Histo1D.h.

278 { _axis.eraseBin(index); }

◆ fill()

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

Fill histo by value and weight, optionally as a fractional fill.

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

Todo:
Replace try block with a check that there is a bin at x

Definition at line 16 of file Histo1D.cc.

References YODA::inRange().

Referenced by reset().

16  {
17  if ( std::isnan(x) ) throw RangeError("X is NaN");
18 
19  // Fill the overall distribution
20  _axis.totalDbn().fill(x, weight, fraction);
21 
22  // Fill the bins and overflows
24  if (inRange(x, _axis.xMin(), _axis.xMax())) {
25  try {
27  _binAt(x).fill(x, weight, fraction);
28  } catch (const RangeError& re) { }
29  } else if (x < _axis.xMin()) {
30  _axis.underflow().fill(x, weight, fraction);
31  } else if (x >= _axis.xMax()) {
32  _axis.overflow().fill(x, weight, fraction);
33  }
34 
35  // Lock the axis now that a fill has happened
36  _axis._setLock(true);
37  }
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

◆ fillBin()

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

Fill histo bin i with the given weight, optionally as a fractional fill.

Definition at line 40 of file Histo1D.cc.

Referenced by reset().

40  {
41  fill(bin(i).xMid(), weight, fraction);
42  }
virtual void fill(double x, double weight=1.0, double fraction=1.0)
Fill histo by value and weight, optionally as a fractional fill.
Definition: Histo1D.cc:16
HistoBin1D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo1D.h:217

◆ integral()

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

Get the total area (sumW) of the histogram.

Definition at line 287 of file Histo1D.h.

References sumW().

Referenced by normalize(), YODA::toIntegralEfficiencyHisto(), and YODA::toIntegralHisto().

287 { return sumW(includeoverflows); }
double sumW(bool includeoverflows=true) const
Get sum of weights in histo.
Definition: Histo1D.cc:64

◆ integralRange()

double YODA::Histo1D::integralRange ( size_t  binindex1,
size_t  binindex2 
) const
inline

Get the integrated area of the histogram between bins binindex1 and binindex2.

Note
The area of bin binindex2 is included in the returned value. To include the underflow and overflow areas, you should add them explicitly with the underflow() and overflow() methods.
Todo:
Allow int bin index args for type compatibility with binIndexAt()?

Definition at line 296 of file Histo1D.h.

References bin(), numBins(), and YODA::Bin1D< DBN >::sumW().

Referenced by integralTo().

296  {
297  assert(binindex2 >= binindex1);
298  if (binindex1 >= numBins()) throw RangeError("binindex1 is out of range");
299  if (binindex2 >= numBins()) throw RangeError("binindex2 is out of range");
300  double rtn = 0;
301  for (size_t i = binindex1; i < binindex2; ++i) {
302  rtn += bin(i).sumW();
303  }
304  return rtn;
305  }
HistoBin1D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo1D.h:217
size_t numBins() const
Number of bins on this axis (not counting under/overflow)
Definition: Histo1D.h:195
double sumW() const
The sum of weights.
Definition: Bin1D.h:218

◆ integralTo()

double YODA::Histo1D::integralTo ( size_t  binindex,
bool  includeunderflow = true 
) const
inline

Get the integrated area of the histogram up to bin binindex.

Note
The area of bin binindex is included in the returned value. To not include the underflow, set includeunderflow=false.
Todo:
Allow int bin index args for type compatibility with binIndexAt()?

Definition at line 313 of file Histo1D.h.

References effNumEntries(), integralRange(), numEntries(), YODA::Dbn1D::sumW(), sumW(), sumW2(), underflow(), xMean(), and xVariance().

313  {
314  double rtn = includeunderflow ? underflow().sumW() : 0;
315  rtn += integralRange(0, binindex);
316  return rtn;
317  }
double integralRange(size_t binindex1, size_t binindex2) const
Get the integrated area of the histogram between bins binindex1 and binindex2.
Definition: Histo1D.h:296
double sumW() const
The sum of weights.
Definition: Dbn1D.h:152
Dbn1D & underflow()
Access underflow (non-const version)
Definition: Histo1D.h:241

◆ mergeBins()

void YODA::Histo1D::mergeBins ( size_t  from,
size_t  to 
)
inline

Merge together the bin range with indices from from to to, inclusive.

Definition at line 163 of file Histo1D.h.

163  {
164  _axis.mergeBins(from, to);
165  }

◆ newclone()

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

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

Implements YODA::AnalysisObject.

Definition at line 114 of file Histo1D.h.

References Histo1D().

114  {
115  return new Histo1D(*this);
116  }
Histo1D(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Histo1D.h:42

◆ normalize()

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

Normalize the (visible) histo area 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 154 of file Histo1D.h.

References integral(), and scaleW().

154  {
155  const double oldintegral = integral(includeoverflows);
156  if (oldintegral == 0) throw WeightError("Attempted to normalize a histogram with null area");
158  scaleW(normto / oldintegral);
159  }
double integral(bool includeoverflows=true) const
Get the total area (sumW) of the histogram.
Definition: Histo1D.h:287
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Histo1D.h:143

◆ numBins()

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

Number of bins on this axis (not counting under/overflow)

Definition at line 195 of file Histo1D.h.

References bins().

Referenced by YODA::add(), YODA::chi2(), YODA::divide(), YODA::efficiency(), integralRange(), YODA::mkScatter(), YODA::multiply(), YODA::subtract(), YODA::toIntegralHisto(), and YODA::toTH1D().

195 { return bins().size(); }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211

◆ numEntries()

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

Get the number of fills.

Definition at line 48 of file Histo1D.cc.

Referenced by integralTo().

48  {
49  if (includeoverflows) return totalDbn().numEntries();
50  unsigned long n = 0;
51  for (const Bin& b : bins()) n += b.numEntries();
52  return n;
53  }
double numEntries() const
Number of entries (number of times fill was called, ignoring weights)
Definition: Dbn1D.h:142
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211
HistoBin1D Bin
Definition: Histo1D.h:32
Dbn1D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo1D.h:233

◆ operator+=()

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

Add another histogram to this one.

Note
Adding histograms will unset any ScaledBy attribute from prevous calls to scaleW or normalize.
Todo:
What about if one histo sets ScaledBy, and the other doesn't?!? Aaaargh

Definition at line 358 of file Histo1D.h.

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

358  {
359  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
360  _axis += toAdd._axis;
361  return *this;
362 
363  // if (!hasAnnotation("ScaledBy") && !toAdd.hasAnnotation("ScaledBy")) {
364  // _axis += toAdd._axis;
365  // } else {
366  // // Undo scaling of both histograms
367  // double scaledBy = annotation<double>("ScaledBy", 1.0);
368  // _axis.scaleW(1.0/scaledBy);
369 
370  // double toAddScaledBy = toAdd.annotation<double>("ScaledBy", 1.0);
371  // Axis1D<HistoBin1D, Dbn1D> toAddAxis = toAdd._axis;
372  // toAddAxis.scaleW(1.0/toAddScaledBy);
373 
374  // _axis += toAddAxis;
375 
376  // // Re-apply combined scaling
377  // double newScaledBy = scaledBy*toAddScaledBy/(scaledBy+toAddScaledBy);
378  // _axis.scaleW(newScaledBy);
379  // setAnnotation("ScaledBy", newScaledBy);
380  // }
382  // return *this;
383  }
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-=()

Histo1D& YODA::Histo1D::operator-= ( const Histo1D 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 388 of file Histo1D.h.

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

388  {
389  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
390  _axis -= toSubtract._axis;
391  return *this;
392  }
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=()

Histo1D& YODA::Histo1D::operator= ( const Histo1D h1)
inline

Assignment operator.

Definition at line 102 of file Histo1D.h.

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

102  {
103  AnalysisObject::operator = (h1); //< AO treatment of paths etc.
104  _axis = h1._axis;
105  return *this;
106  }
virtual AnalysisObject & operator=(const AnalysisObject &ao)
Default copy assignment operator.

◆ overflow() [1/2]

Dbn1D& YODA::Histo1D::overflow ( )
inline

Access overflow (non-const version)

Definition at line 249 of file Histo1D.h.

Referenced by YODA::toIntegralEfficiencyHisto(), and YODA::toTH1D().

249 { return _axis.overflow(); }

◆ overflow() [2/2]

const Dbn1D& YODA::Histo1D::overflow ( ) const
inline

Access overflow (const version)

Definition at line 251 of file Histo1D.h.

251 { return _axis.overflow(); }

◆ rebin() [1/2]

void YODA::Histo1D::rebin ( unsigned int  n,
size_t  begin = 0,
size_t  end = UINT_MAX 
)
inline

Overloaded alias for rebinBy.

Definition at line 173 of file Histo1D.h.

References rebinBy().

173  {
174  rebinBy(n, begin, end);
175  }
void rebinBy(unsigned int n, size_t begin=0, size_t end=UINT_MAX)
Merge every group of n bins, starting from the LHS.
Definition: Histo1D.h:169

◆ rebin() [2/2]

void YODA::Histo1D::rebin ( const std::vector< double > &  newedges)
inline

Overloaded alias for rebinTo.

Definition at line 182 of file Histo1D.h.

References rebinTo().

182  {
183  rebinTo(newedges);
184  }
void rebinTo(const std::vector< double > &newedges)
Rebin to the given list of bin edges.
Definition: Histo1D.h:178

◆ rebinBy()

void YODA::Histo1D::rebinBy ( unsigned int  n,
size_t  begin = 0,
size_t  end = UINT_MAX 
)
inline

Merge every group of n bins, starting from the LHS.

Definition at line 169 of file Histo1D.h.

Referenced by rebin().

169  {
170  _axis.rebinBy(n, begin, end);
171  }

◆ rebinTo()

void YODA::Histo1D::rebinTo ( const std::vector< double > &  newedges)
inline

Rebin to the given list of bin edges.

Definition at line 178 of file Histo1D.h.

Referenced by rebin().

178  {
179  _axis.rebinTo(newedges);
180  }

◆ reset()

virtual void YODA::Histo1D::reset ( )
inlinevirtual

Reset the histogram.

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

Implements YODA::AnalysisObject.

Definition at line 131 of file Histo1D.h.

References fill(), and fillBin().

131  {
132  _axis.reset();
133  }

◆ scaleW()

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

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

Definition at line 143 of file Histo1D.h.

References YODA::AnalysisObject::setAnnotation().

Referenced by normalize().

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

◆ setOverflow()

void YODA::Histo1D::setOverflow ( const Dbn1D dbn)
inline

Set overflow distribution, mainly for persistency: CAREFUL!

Definition at line 253 of file Histo1D.h.

253 { _axis.setOverflow(dbn); }

◆ setTotalDbn()

void YODA::Histo1D::setTotalDbn ( const Dbn1D dbn)
inline

Set summary distribution, mainly for persistency: CAREFUL!

Definition at line 237 of file Histo1D.h.

237 { _axis.setTotalDbn(dbn); }

◆ setUnderflow()

void YODA::Histo1D::setUnderflow ( const Dbn1D dbn)
inline

Set underflow distribution, mainly for persistency: CAREFUL!

Definition at line 245 of file Histo1D.h.

245 { _axis.setUnderflow(dbn); }

◆ sumW()

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

Get sum of weights in histo.

Definition at line 64 of file Histo1D.cc.

Referenced by integral(), and integralTo().

64  {
65  if (includeoverflows) return _axis.totalDbn().sumW();
66  double sumw = 0;
67  for (const Bin& b : bins()) sumw += b.sumW();
68  return sumw;
69  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211
HistoBin1D Bin
Definition: Histo1D.h:32

◆ sumW2()

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

Get sum of squared weights in histo.

Definition at line 72 of file Histo1D.cc.

Referenced by integralTo().

72  {
73  if (includeoverflows) return _axis.totalDbn().sumW2();
74  double sumw2 = 0;
75  for (const Bin& b : bins()) sumw2 += b.sumW2();
76  return sumw2;
77  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211
HistoBin1D Bin
Definition: Histo1D.h:32

◆ totalDbn() [1/2]

Dbn1D& YODA::Histo1D::totalDbn ( )
inline

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

Definition at line 233 of file Histo1D.h.

233 { return _axis.totalDbn(); }

◆ totalDbn() [2/2]

const Dbn1D& YODA::Histo1D::totalDbn ( ) const
inline

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

Definition at line 235 of file Histo1D.h.

235 { return _axis.totalDbn(); }

◆ underflow() [1/2]

Dbn1D& YODA::Histo1D::underflow ( )
inline

Access underflow (non-const version)

Definition at line 241 of file Histo1D.h.

Referenced by integralTo(), YODA::toIntegralHisto(), and YODA::toTH1D().

241 { return _axis.underflow(); }

◆ underflow() [2/2]

const Dbn1D& YODA::Histo1D::underflow ( ) const
inline

Access underflow (const version)

Definition at line 243 of file Histo1D.h.

243 { return _axis.underflow(); }

◆ xEdges()

const std::vector<double> YODA::Histo1D::xEdges ( ) const
inline

All bin edges on this histo's axis

Note
This only returns the finite edges, i.e. -inf and +inf are removed
Todo:
Make the +-inf stripping controllable by a default-valued bool arg

Definition at line 207 of file Histo1D.h.

207 { return _axis.xEdges(); }

◆ xMax()

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

High edge of this histo's axis.

Definition at line 201 of file Histo1D.h.

201 { return _axis.xMax(); }

◆ xMean()

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

Get the mean in x.

Definition at line 82 of file Histo1D.cc.

References YODA::Dbn1D::xMean().

Referenced by integralTo().

82  {
83  if (includeoverflows) return _axis.totalDbn().xMean();
84  Dbn1D dbn;
85  for (const HistoBin1D& b : bins()) dbn += b.dbn();
86  return dbn.xMean();
87  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211

◆ xMin()

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

Low edge of this histo's axis.

Definition at line 198 of file Histo1D.h.

198 { return _axis.xMin(); }

◆ xRMS()

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

Get the RMS in x.

Definition at line 106 of file Histo1D.cc.

References YODA::Dbn1D::xRMS().

Referenced by xStdDev().

106  {
107  if (includeoverflows) return _axis.totalDbn().xRMS();
108  Dbn1D dbn;
109  for (const HistoBin1D& b : bins()) dbn += b.dbn();
110  return dbn.xRMS();
111  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211

◆ xStdDev()

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

Get the standard deviation in x.

Definition at line 338 of file Histo1D.h.

References xRMS(), xStdErr(), and xVariance().

338  {
339  if (includeoverflows) return _axis.totalDbn().xStdDev();
340  return std::sqrt(xVariance(includeoverflows));
341  }
double xVariance(bool includeoverflows=true) const
Get the variance in x.
Definition: Histo1D.cc:90

◆ xStdErr()

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

Get the standard error in x.

Definition at line 98 of file Histo1D.cc.

References YODA::Dbn1D::xStdErr().

Referenced by xStdDev().

98  {
99  if (includeoverflows) return _axis.totalDbn().xStdErr();
100  Dbn1D dbn;
101  for (const HistoBin1D& b : bins()) dbn += b.dbn();
102  return dbn.xStdErr();
103  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211

◆ xVariance()

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

Get the variance in x.

Definition at line 90 of file Histo1D.cc.

References YODA::Dbn1D::xVariance().

Referenced by integralTo(), and xStdDev().

90  {
91  if (includeoverflows) return _axis.totalDbn().xVariance();
92  Dbn1D dbn;
93  for (const HistoBin1D& b : bins()) dbn += b.dbn();
94  return dbn.xVariance();
95  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:211

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