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

A one-dimensional histogram. More...

#include <Histo1D.h>

Inheritance diagram for YODA::Histo1D:
YODA::AnalysisObject YODA::Binned YODA::Fillable

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...
 
size_t fillDim () 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 (not counting under/overflow) More...
 
size_t numBinsX () const
 Number of bins on the x (only) 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...
 
bool sameBinning (const Histo1D &h1)
 check if binning is the same as different Histo1D 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...
 
Bin adding and removing
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 rmBin (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...
 
void parseVariations ()
 
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...
 
- Public Member Functions inherited from YODA::Binned
virtual ~Binned ()=default
 Virtual destructor for inheritance. More...
 
void eraseBin (size_t index)
 
- Public Member Functions inherited from YODA::Fillable
virtual ~Fillable ()=default
 Virtual destructor for inheritance. More...
 

Detailed Description

A one-dimensional histogram.

Definition at line 28 of file Histo1D.h.

Member Typedef Documentation

◆ Axis

Convenience typedefs.

Definition at line 32 of file Histo1D.h.

◆ Bin

Definition at line 34 of file Histo1D.h.

◆ Bins

Definition at line 33 of file Histo1D.h.

◆ BinType

Definition at line 37 of file Histo1D.h.

◆ FillType

typedef double YODA::Histo1D::FillType

Definition at line 36 of file Histo1D.h.

◆ Ptr

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

Definition at line 38 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 44 of file Histo1D.h.

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

45  : AnalysisObject("Histo1D", path, title),
46  _axis()
47  { }
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 51 of file Histo1D.h.

53  : AnalysisObject("Histo1D", path, title),
54  _axis(nbins, lower, upper)
55  { }
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 62 of file Histo1D.h.

64  : AnalysisObject("Histo1D", path, title),
65  _axis(binedges)
66  { }
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 70 of file Histo1D.h.

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

72  : AnalysisObject("Histo1D", path, title),
73  _axis(bins)
74  { }
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:224
Axis1D< HistoBin1D, Dbn1D > Histo1DAxis
Convenience typedef.
Definition: Histo1D.h:25
Point2D Point
Type of the native Point2D collection.
Definition: Scatter2D.h:29

◆ 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:224
Axis1D< HistoBin1D, Dbn1D > Histo1DAxis
Convenience typedef.
Definition: Histo1D.h:25

◆ 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 95 of file Histo1D.h.

98  : AnalysisObject("Histo1D", path, title),
99  _axis(bins, dbn_tot, dbn_uflow, dbn_oflow)
100  { }
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 275 of file Histo1D.h.

275 { _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 286 of file Histo1D.h.

286 { _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 278 of file Histo1D.h.

278 { _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 291 of file Histo1D.h.

291  {
292  _axis.addBins(bins);
293  }
std::vector< YODA::HistoBin1D > & bins()
Access the bin vector.
Definition: Histo1D.h:224

◆ bin() [1/2]

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

Access a bin by index (non-const version)

Definition at line 230 of file Histo1D.h.

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

230 { 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 232 of file Histo1D.h.

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

◆ binAt()

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

Access a bin by coordinate (const version)

Definition at line 242 of file Histo1D.h.

Referenced by YODA::toTH1D().

242 { 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 237 of file Histo1D.h.

237  {
238  return _axis.binIndexAt(x);
239  }

◆ bins() [1/2]

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

Access the bin vector.

Definition at line 224 of file Histo1D.h.

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

224 { 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 226 of file Histo1D.h.

226 { return _axis.bins(); }

◆ clone()

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

Make a copy on the stack.

Definition at line 111 of file Histo1D.h.

References Histo1D().

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

◆ dim()

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

Fill dimension of this data object.

Todo:
Change this to the total dimension (in v2)

Implements YODA::AnalysisObject.

Definition at line 126 of file Histo1D.h.

126 { return 1; }

◆ effNumEntries()

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

Get the effective number of fills.

Implements YODA::Fillable.

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:224
HistoBin1D Bin
Definition: Histo1D.h:34
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:246

◆ 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:156

◆ 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:230

◆ fillDim()

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

Fill dimension of this data object.

Implements YODA::Fillable.

Definition at line 129 of file Histo1D.h.

129 { return 1; }

◆ integral()

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

Get the total area (sumW) of the histogram.

Definition at line 305 of file Histo1D.h.

References sumW().

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

305 { 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 314 of file Histo1D.h.

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

Referenced by integralTo().

314  {
315  assert(binindex2 >= binindex1);
316  if (binindex1 >= numBins()) throw RangeError("binindex1 is out of range");
317  if (binindex2 >= numBins()) throw RangeError("binindex2 is out of range");
318  double rtn = 0;
319  for (size_t i = binindex1; i <= binindex2; ++i) {
320  rtn += bin(i).sumW();
321  }
322  return rtn;
323  }
HistoBin1D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Histo1D.h:230
size_t numBins() const
Number of bins (not counting under/overflow)
Definition: Histo1D.h:200
double sumW() const
The sum of weights.
Definition: Bin1D.h:226

◆ 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 331 of file Histo1D.h.

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

331  {
332  double rtn = includeunderflow ? underflow().sumW() : 0;
333  rtn += integralRange(0, binindex);
334  return rtn;
335  }
double integralRange(size_t binindex1, size_t binindex2) const
Get the integrated area of the histogram between bins binindex1 and binindex2.
Definition: Histo1D.h:314
double sumW() const
The sum of weights.
Definition: Dbn1D.h:152
Dbn1D & underflow()
Access underflow (non-const version)
Definition: Histo1D.h:254

◆ 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 170 of file Histo1D.h.

170  {
171  _axis.mergeBins(from, to);
172  }

◆ newclone()

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

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

Implements YODA::AnalysisObject.

Definition at line 116 of file Histo1D.h.

References Histo1D().

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

◆ 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 161 of file Histo1D.h.

References integral(), and scaleW().

161  {
162  const double oldintegral = integral(includeoverflows);
163  if (oldintegral == 0) throw WeightError("Attempted to normalize a histogram with null area");
165  scaleW(normto / oldintegral);
166  }
double integral(bool includeoverflows=true) const
Get the total area (sumW) of the histogram.
Definition: Histo1D.h:305
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Histo1D.h:150

◆ numBins()

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

Number of bins (not counting under/overflow)

Implements YODA::Binned.

Definition at line 200 of file Histo1D.h.

References bins().

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

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

◆ numBinsX()

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

Number of bins on the x (only) axis (not counting under/overflow)

Definition at line 203 of file Histo1D.h.

References numBins().

203 { return numBins(); }
size_t numBins() const
Number of bins (not counting under/overflow)
Definition: Histo1D.h:200

◆ numEntries()

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

Get the number of fills.

Implements YODA::Fillable.

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:224
HistoBin1D Bin
Definition: Histo1D.h:34
Dbn1D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Histo1D.h:246

◆ 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 376 of file Histo1D.h.

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

376  {
377  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
378  _axis += toAdd._axis;
379  return *this;
380 
381  // if (!hasAnnotation("ScaledBy") && !toAdd.hasAnnotation("ScaledBy")) {
382  // _axis += toAdd._axis;
383  // } else {
384  // // Undo scaling of both histograms
385  // double scaledBy = annotation<double>("ScaledBy", 1.0);
386  // _axis.scaleW(1.0/scaledBy);
387 
388  // double toAddScaledBy = toAdd.annotation<double>("ScaledBy", 1.0);
389  // Axis1D<HistoBin1D, Dbn1D> toAddAxis = toAdd._axis;
390  // toAddAxis.scaleW(1.0/toAddScaledBy);
391 
392  // _axis += toAddAxis;
393 
394  // // Re-apply combined scaling
395  // double newScaledBy = scaledBy*toAddScaledBy/(scaledBy+toAddScaledBy);
396  // _axis.scaleW(newScaledBy);
397  // setAnnotation("ScaledBy", newScaledBy);
398  // }
400  // return *this;
401  }
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 406 of file Histo1D.h.

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

406  {
407  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
408  _axis -= toSubtract._axis;
409  return *this;
410  }
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 104 of file Histo1D.h.

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

104  {
105  AnalysisObject::operator = (h1); //< AO treatment of paths etc.
106  _axis = h1._axis;
107  return *this;
108  }
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 262 of file Histo1D.h.

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

262 { return _axis.overflow(); }

◆ overflow() [2/2]

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

Access overflow (const version)

Definition at line 264 of file Histo1D.h.

264 { 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 180 of file Histo1D.h.

References rebinBy().

180  {
181  rebinBy(n, begin, end);
182  }
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:176

◆ rebin() [2/2]

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

Overloaded alias for rebinTo.

Definition at line 189 of file Histo1D.h.

References rebinTo().

189  {
190  rebinTo(newedges);
191  }
void rebinTo(const std::vector< double > &newedges)
Rebin to the given list of bin edges.
Definition: Histo1D.h:185

◆ 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 176 of file Histo1D.h.

Referenced by rebin().

176  {
177  _axis.rebinBy(n, begin, end);
178  }

◆ rebinTo()

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

Rebin to the given list of bin edges.

Definition at line 185 of file Histo1D.h.

Referenced by rebin().

185  {
186  _axis.rebinTo(newedges);
187  }

◆ 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 138 of file Histo1D.h.

References fill(), and fillBin().

138  {
139  _axis.reset();
140  }

◆ rmBin()

void YODA::Histo1D::rmBin ( size_t  index)
inlinevirtual

Remove a bin.

Implements YODA::Binned.

Definition at line 296 of file Histo1D.h.

296 { _axis.eraseBin(index); }

◆ sameBinning()

bool YODA::Histo1D::sameBinning ( const Histo1D h1)
inline

check if binning is the same as different Histo1D

Definition at line 212 of file Histo1D.h.

212  {
213  return _axis == h1._axis;
214  }

◆ scaleW()

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

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

Implements YODA::Fillable.

Definition at line 150 of file Histo1D.h.

References YODA::AnalysisObject::setAnnotation().

Referenced by normalize().

150  {
151  setAnnotation("ScaledBy", annotation<double>("ScaledBy", 1.0) * scalefactor);
152  _axis.scaleW(scalefactor);
153  }
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 266 of file Histo1D.h.

266 { _axis.setOverflow(dbn); }

◆ setTotalDbn()

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

Set summary distribution, mainly for persistency: CAREFUL!

Definition at line 250 of file Histo1D.h.

250 { _axis.setTotalDbn(dbn); }

◆ setUnderflow()

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

Set underflow distribution, mainly for persistency: CAREFUL!

Definition at line 258 of file Histo1D.h.

258 { _axis.setUnderflow(dbn); }

◆ sumW()

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

Get sum of weights in histo.

Implements YODA::Fillable.

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:224
HistoBin1D Bin
Definition: Histo1D.h:34

◆ sumW2()

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

Get sum of squared weights in histo.

Implements YODA::Fillable.

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:224
HistoBin1D Bin
Definition: Histo1D.h:34

◆ totalDbn() [1/2]

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

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

Definition at line 246 of file Histo1D.h.

246 { 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 248 of file Histo1D.h.

248 { return _axis.totalDbn(); }

◆ underflow() [1/2]

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

Access underflow (non-const version)

Definition at line 254 of file Histo1D.h.

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

254 { return _axis.underflow(); }

◆ underflow() [2/2]

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

Access underflow (const version)

Definition at line 256 of file Histo1D.h.

256 { 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 220 of file Histo1D.h.

220 { return _axis.xEdges(); }

◆ xMax()

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

High edge of this histo's axis.

Definition at line 209 of file Histo1D.h.

209 { 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:224

◆ xMin()

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

Low edge of this histo's axis.

Definition at line 206 of file Histo1D.h.

206 { 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:224

◆ xStdDev()

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

Get the standard deviation in x.

Definition at line 356 of file Histo1D.h.

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

356  {
357  if (includeoverflows) return _axis.totalDbn().xStdDev();
358  return std::sqrt(xVariance(includeoverflows));
359  }
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:224

◆ 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:224

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