package hbook
import "go-hep.org/x/hep/hbook"
Package hbook is a set of data analysis tools for HEP (histograms (1D, 2D, 3D), profiles and ntuples). hbook is a work in progress of a concurrent friendly histogram filling toolkit. It is loosely based on AIDA interfaces and concepts as well as the "simplicity" of HBOOK and the previous work of YODA.
Index ¶
- Constants
- type Annotation
- func (ann *Annotation) MarshalBinary() ([]byte, error)
- func (ann Annotation) MarshalYODA() ([]byte, error)
- func (ann *Annotation) UnmarshalBinary(data []byte) error
- func (ann *Annotation) UnmarshalYODA(data []byte) error
- type Bin
- type Bin1D
- func (b *Bin1D) EffEntries() float64
- func (b *Bin1D) Entries() int64
- func (b *Bin1D) ErrW() float64
- func (o *Bin1D) MarshalBinary() (data []byte, err error)
- func (Bin1D) Rank() int
- func (b *Bin1D) SumW() float64
- func (b *Bin1D) SumW2() float64
- func (o *Bin1D) UnmarshalBinary(data []byte) (err error)
- func (b *Bin1D) XEdges() Range
- func (b *Bin1D) XFocus() float64
- func (b *Bin1D) XMax() float64
- func (b *Bin1D) XMean() float64
- func (b *Bin1D) XMid() float64
- func (b *Bin1D) XMin() float64
- func (b *Bin1D) XRMS() float64
- func (b *Bin1D) XStdDev() float64
- func (b *Bin1D) XStdErr() float64
- func (b *Bin1D) XVariance() float64
- func (b *Bin1D) XWidth() float64
- type Bin1Ds
- func (p Bin1Ds) IndexOf(v float64) int
- func (p Bin1Ds) Len() int
- func (p Bin1Ds) Less(i, j int) bool
- func (p Bin1Ds) Swap(i, j int)
- type Bin2D
- func (b *Bin2D) EffEntries() float64
- func (b *Bin2D) Entries() int64
- func (o *Bin2D) MarshalBinary() (data []byte, err error)
- func (Bin2D) Rank() int
- func (b *Bin2D) SumW() float64
- func (b *Bin2D) SumW2() float64
- func (o *Bin2D) UnmarshalBinary(data []byte) (err error)
- func (b *Bin2D) XEdges() Range
- func (b *Bin2D) XFocus() float64
- func (b *Bin2D) XMax() float64
- func (b *Bin2D) XMean() float64
- func (b *Bin2D) XMid() float64
- func (b *Bin2D) XMin() float64
- func (b *Bin2D) XRMS() float64
- func (b *Bin2D) XStdDev() float64
- func (b *Bin2D) XStdErr() float64
- func (b *Bin2D) XVariance() float64
- func (b *Bin2D) XWidth() float64
- func (b *Bin2D) XYFocus() (float64, float64)
- func (b *Bin2D) XYMid() (float64, float64)
- func (b *Bin2D) XYWidth() (float64, float64)
- func (b *Bin2D) YEdges() Range
- func (b *Bin2D) YFocus() float64
- func (b *Bin2D) YMax() float64
- func (b *Bin2D) YMean() float64
- func (b *Bin2D) YMid() float64
- func (b *Bin2D) YMin() float64
- func (b *Bin2D) YRMS() float64
- func (b *Bin2D) YStdDev() float64
- func (b *Bin2D) YStdErr() float64
- func (b *Bin2D) YVariance() float64
- func (b *Bin2D) YWidth() float64
- type BinP1D
- func (b *BinP1D) EffEntries() float64
- func (b *BinP1D) Entries() int64
- func (o *BinP1D) MarshalBinary() (data []byte, err error)
- func (BinP1D) Rank() int
- func (b *BinP1D) SumW() float64
- func (b *BinP1D) SumW2() float64
- func (o *BinP1D) UnmarshalBinary(data []byte) (err error)
- func (b *BinP1D) XEdges() Range
- func (b *BinP1D) XFocus() float64
- func (b *BinP1D) XMax() float64
- func (b *BinP1D) XMean() float64
- func (b *BinP1D) XMid() float64
- func (b *BinP1D) XMin() float64
- func (b *BinP1D) XRMS() float64
- func (b *BinP1D) XStdDev() float64
- func (b *BinP1D) XStdErr() float64
- func (b *BinP1D) XVariance() float64
- func (b *BinP1D) XWidth() float64
- type Binning1D
- func (o *Binning1D) MarshalBinary() (data []byte, err error)
- func (bng *Binning1D) Overflow() *Dist1D
- func (bng *Binning1D) Underflow() *Dist1D
- func (o *Binning1D) UnmarshalBinary(data []byte) (err error)
- type Binning2D
- func (o *Binning2D) MarshalBinary() (data []byte, err error)
- func (o *Binning2D) UnmarshalBinary(data []byte) (err error)
- type Count
- type Dist0D
- func (d *Dist0D) EffEntries() float64
- func (d *Dist0D) Entries() int64
- func (o *Dist0D) MarshalBinary() (data []byte, err error)
- func (*Dist0D) Rank() int
- func (o *Dist0D) UnmarshalBinary(data []byte) (err error)
- type Dist1D
- func (d *Dist1D) EffEntries() float64
- func (d *Dist1D) Entries() int64
- func (o *Dist1D) MarshalBinary() (data []byte, err error)
- func (*Dist1D) Rank() int
- func (d *Dist1D) SumW() float64
- func (d *Dist1D) SumW2() float64
- func (d *Dist1D) SumWX() float64
- func (d *Dist1D) SumWX2() float64
- func (o *Dist1D) UnmarshalBinary(data []byte) (err error)
- type Dist2D
- func (d *Dist2D) EffEntries() float64
- func (d *Dist2D) Entries() int64
- func (o *Dist2D) MarshalBinary() (data []byte, err error)
- func (*Dist2D) Rank() int
- func (d *Dist2D) SumW() float64
- func (d *Dist2D) SumW2() float64
- func (d *Dist2D) SumWX() float64
- func (d *Dist2D) SumWX2() float64
- func (d *Dist2D) SumWXY() float64
- func (d *Dist2D) SumWY() float64
- func (d *Dist2D) SumWY2() float64
- func (o *Dist2D) UnmarshalBinary(data []byte) (err error)
- type DivOptions
- type H1D
- func AddH1D(h1, h2 *H1D) *H1D
- func AddScaledH1D(h1 *H1D, alpha float64, h2 *H1D) *H1D
- func NewH1D(n int, xmin, xmax float64) *H1D
- func NewH1DFromBins(bins ...Range) *H1D
- func NewH1DFromEdges(edges []float64) *H1D
- func SubH1D(h1, h2 *H1D) *H1D
- func (h *H1D) Annotation() Annotation
- func (h *H1D) Bin(x float64) *Bin1D
- func (h *H1D) Clone() *H1D
- func (h *H1D) Counts() []Count
- func (h *H1D) DataRange() (xmin, xmax, ymin, ymax float64)
- func (h *H1D) EffEntries() float64
- func (h *H1D) Entries() int64
- func (h *H1D) Error(i int) float64
- func (h *H1D) Fill(x, w float64)
- func (h *H1D) FillN(xs, ws []float64)
- func (h *H1D) Integral(args ...float64) float64
- func (h *H1D) Len() int
- func (o *H1D) MarshalBinary() (data []byte, err error)
- func (h *H1D) MarshalYODA() ([]byte, error)
- func (h *H1D) Name() string
- func (h *H1D) Rank() int
- func (h *H1D) RioMarshal(w io.Writer) error
- func (h *H1D) RioUnmarshal(r io.Reader) error
- func (h *H1D) RioVersion() rio.Version
- func (h *H1D) Scale(factor float64)
- func (h *H1D) SumW() float64
- func (h *H1D) SumW2() float64
- func (h *H1D) SumWX() float64
- func (h *H1D) SumWX2() float64
- func (o *H1D) UnmarshalBinary(data []byte) (err error)
- func (h *H1D) UnmarshalYODA(data []byte) error
- func (h *H1D) Value(i int) float64
- func (h *H1D) XMax() float64
- func (h *H1D) XMean() float64
- func (h *H1D) XMin() float64
- func (h *H1D) XRMS() float64
- func (h *H1D) XStdDev() float64
- func (h *H1D) XStdErr() float64
- func (h *H1D) XVariance() float64
- func (h *H1D) XY(i int) (float64, float64)
- type H2D
- func NewH2D(nx int, xlow, xhigh float64, ny int, ylow, yhigh float64) *H2D
- func NewH2DFromEdges(xedges []float64, yedges []float64) *H2D
- func (h *H2D) Annotation() Annotation
- func (h *H2D) Bin(x, y float64) *Bin2D
- func (h *H2D) EffEntries() float64
- func (h *H2D) Entries() int64
- func (h *H2D) Fill(x, y, w float64)
- func (h *H2D) FillN(xs, ys, ws []float64)
- func (h *H2D) GridXYZ() h2dGridXYZ
- func (h *H2D) Integral() float64
- func (o *H2D) MarshalBinary() (data []byte, err error)
- func (h *H2D) MarshalYODA() ([]byte, error)
- func (h *H2D) Name() string
- func (h *H2D) Rank() int
- func (h *H2D) SumW() float64
- func (h *H2D) SumW2() float64
- func (h *H2D) SumWX() float64
- func (h *H2D) SumWX2() float64
- func (h *H2D) SumWXY() float64
- func (h *H2D) SumWY() float64
- func (h *H2D) SumWY2() float64
- func (o *H2D) UnmarshalBinary(data []byte) (err error)
- func (h *H2D) UnmarshalYODA(data []byte) error
- func (h *H2D) XMax() float64
- func (h *H2D) XMean() float64
- func (h *H2D) XMin() float64
- func (h *H2D) XRMS() float64
- func (h *H2D) XStdDev() float64
- func (h *H2D) XStdErr() float64
- func (h *H2D) XVariance() float64
- func (h *H2D) YMax() float64
- func (h *H2D) YMean() float64
- func (h *H2D) YMin() float64
- func (h *H2D) YRMS() float64
- func (h *H2D) YStdDev() float64
- func (h *H2D) YStdErr() float64
- func (h *H2D) YVariance() float64
- type Histogram
- type Object
- type P1D
- func NewP1D(n int, xmin, xmax float64) *P1D
- func NewP1DFromH1D(h *H1D) *P1D
- func (p *P1D) Annotation() Annotation
- func (p *P1D) Binning() *binningP1D
- func (p *P1D) EffEntries() float64
- func (p *P1D) Entries() int64
- func (p *P1D) Fill(x, y, w float64)
- func (o *P1D) MarshalBinary() (data []byte, err error)
- func (p *P1D) MarshalYODA() ([]byte, error)
- func (p *P1D) Name() string
- func (p *P1D) Rank() int
- func (p *P1D) Scale(factor float64)
- func (p *P1D) SumW() float64
- func (p *P1D) SumW2() float64
- func (o *P1D) UnmarshalBinary(data []byte) (err error)
- func (p *P1D) UnmarshalYODA(data []byte) error
- func (p *P1D) XMax() float64
- func (p *P1D) XMean() float64
- func (p *P1D) XMin() float64
- func (p *P1D) XRMS() float64
- func (p *P1D) XStdDev() float64
- func (p *P1D) XStdErr() float64
- func (p *P1D) XVariance() float64
- type Point2D
- func (o *Point2D) MarshalBinary() (data []byte, err error)
- func (p *Point2D) ScaleX(f float64)
- func (p *Point2D) ScaleXY(f float64)
- func (p *Point2D) ScaleY(f float64)
- func (o *Point2D) UnmarshalBinary(data []byte) (err error)
- func (p Point2D) XMax() float64
- func (p Point2D) XMin() float64
- func (p Point2D) YMax() float64
- func (p Point2D) YMin() float64
- type Rand1D
- func NewRand1D(h *H1D, src rand.Source) Rand1D
- func (d *Rand1D) CDF(x float64) float64
- func (d *Rand1D) Rand() float64
- type Range
- func (o *Range) MarshalBinary() (data []byte, err error)
- func (o *Range) UnmarshalBinary(data []byte) (err error)
- func (r Range) Width() float64
- type S2D
- func DivideH1D(num, den *H1D, opts ...DivOptions) (*S2D, error)
- func NewS2D(pts ...Point2D) *S2D
- func NewS2DFrom(x, y []float64) *S2D
- func NewS2DFromH1D(h *H1D, opts ...S2DOpts) *S2D
- func NewS2DFromP1D(p *P1D, opts ...S2DOpts) *S2D
- func (s *S2D) Annotation() Annotation
- func (s *S2D) DataRange() (xmin, xmax, ymin, ymax float64)
- func (s *S2D) Entries() int64
- func (s *S2D) Fill(pts ...Point2D)
- func (s *S2D) Len() int
- func (o *S2D) MarshalBinary() (data []byte, err error)
- func (s *S2D) MarshalYODA() ([]byte, error)
- func (s *S2D) Name() string
- func (s *S2D) Point(i int) Point2D
- func (s *S2D) Points() []Point2D
- func (*S2D) Rank() int
- func (s *S2D) ScaleX(f float64)
- func (s *S2D) ScaleXY(f float64)
- func (s *S2D) ScaleY(f float64)
- func (s *S2D) Sort()
- func (o *S2D) UnmarshalBinary(data []byte) (err error)
- func (s *S2D) UnmarshalYODA(data []byte) error
- func (s *S2D) XError(i int) (float64, float64)
- func (s *S2D) XY(i int) (x, y float64)
- func (s *S2D) YError(i int) (float64, float64)
- type S2DOpts
Examples ¶
- AddH1D
- AddScaledH1D
- Count
- Count (WithH1D)
- DivideH1D
- H1D
- H2D
- P1D
- Rand1D
- S2D
- S2D (NewS2DFrom)
- S2D (NewS2DFromH1D)
- SubH1D
Constants ¶
const ( UnderflowBin1D = -1 OverflowBin1D = -2 )
Indices for the under- and over-flow 1-dim bins.
indices for the 2D-binning overflows
Types ¶
type Annotation ¶
Annotation is a bag of attributes that are attached to a histogram.
func (*Annotation) MarshalBinary ¶
func (ann *Annotation) MarshalBinary() ([]byte, error)
MarshalBinary implements encoding.BinaryMarshaler
func (Annotation) MarshalYODA ¶
func (ann Annotation) MarshalYODA() ([]byte, error)
MarshalYODA implements the YODAMarshaler interface.
func (*Annotation) UnmarshalBinary ¶
func (ann *Annotation) UnmarshalBinary(data []byte) error
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (*Annotation) UnmarshalYODA ¶
func (ann *Annotation) UnmarshalYODA(data []byte) error
UnmarshalYODA implements the YODAUnmarshaler interface.
type Bin ¶
type Bin interface { Rank() int // Number of dimensions of the bin Entries() int64 // Number of entries in the bin EffEntries() float64 // Effective number of entries in the bin SumW() float64 // sum of weights SumW2() float64 // sum of squared weights }
Bin models 1D, 2D, ... bins.
type Bin1D ¶
Bin1D models a bin in a 1-dim space.
func (*Bin1D) EffEntries ¶
EffEntries returns the effective number of entries \f$ = (\sum w)^2 / \sum w^2 \f$
func (*Bin1D) Entries ¶
Entries returns the number of entries in this bin.
func (*Bin1D) ErrW ¶
ErrW returns the absolute error on SumW()
func (*Bin1D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (Bin1D) Rank ¶
Rank returns the number of dimensions for this bin.
func (*Bin1D) SumW ¶
SumW returns the sum of weights in this bin.
func (*Bin1D) SumW2 ¶
SumW2 returns the sum of squared weights in this bin.
func (*Bin1D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (*Bin1D) XEdges ¶
XEdges returns the [low,high] edges of this bin.
func (*Bin1D) XFocus ¶
XFocus returns the mean position in the bin, or the midpoint (if the sum of weights for this bin is 0).
func (*Bin1D) XMax ¶
XMax returns the upper limit of the bin (exclusive).
func (*Bin1D) XMean ¶
XMean returns the mean X.
func (*Bin1D) XMid ¶
XMid returns the geometric center of the bin. i.e.: 0.5*(high+low)
func (*Bin1D) XMin ¶
XMin returns the lower limit of the bin (inclusive).
func (*Bin1D) XRMS ¶
XRMS returns the RMS in X.
func (*Bin1D) XStdDev ¶
XStdDev returns the standard deviation in X.
func (*Bin1D) XStdErr ¶
XStdErr returns the standard error in X.
func (*Bin1D) XVariance ¶
XVariance returns the variance in X.
func (*Bin1D) XWidth ¶
XWidth returns the (signed) width of the bin
type Bin1Ds ¶
type Bin1Ds []Bin1D
Bin1Ds is a sorted slice of Bin1D implementing sort.Interface.
func (Bin1Ds) IndexOf ¶
IndexOf returns the index of the Bin1D containing the value v. It returns UndeflowBin if v is smaller than the smallest bin value. It returns OverflowBin if v is greater than the greatest bin value. It returns len(bins) if v falls within a bins gap.
func (Bin1Ds) Len ¶
func (Bin1Ds) Less ¶
func (Bin1Ds) Swap ¶
type Bin2D ¶
Bin2D models a bin in a 2-dim space.
func (*Bin2D) EffEntries ¶
EffEntries returns the effective number of entries \f$ = (\sum w)^2 / \sum w^2 \f$
func (*Bin2D) Entries ¶
Entries returns the number of entries in this bin.
func (*Bin2D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (Bin2D) Rank ¶
Rank returns the number of dimensions for this bin.
func (*Bin2D) SumW ¶
SumW returns the sum of weights in this bin.
func (*Bin2D) SumW2 ¶
SumW2 returns the sum of squared weights in this bin.
func (*Bin2D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (*Bin2D) XEdges ¶
XEdges returns the [low,high] edges of this bin.
func (*Bin2D) XFocus ¶
XFocus returns the mean position in the bin, or the midpoint (if the sum of weights for this bin is 0).
func (*Bin2D) XMax ¶
XMax returns the upper limit of the bin (exclusive).
func (*Bin2D) XMean ¶
XMean returns the mean X.
func (*Bin2D) XMid ¶
XMid returns the geometric center of the bin. i.e.: 0.5*(high+low)
func (*Bin2D) XMin ¶
XMin returns the lower limit of the bin (inclusive).
func (*Bin2D) XRMS ¶
XRMS returns the RMS in X.
func (*Bin2D) XStdDev ¶
XStdDev returns the standard deviation in X.
func (*Bin2D) XStdErr ¶
XStdErr returns the standard error in X.
func (*Bin2D) XVariance ¶
XVariance returns the variance in X.
func (*Bin2D) XWidth ¶
XWidth returns the (signed) width of the bin
func (*Bin2D) XYFocus ¶
XYFocus returns the mean position in the bin, or the midpoint (if the sum of weights for this bin is 0).
func (*Bin2D) XYMid ¶
XYMid returns the (x,y) coordinates of the geometric center of the bin. i.e.: 0.5*(high+low)
func (*Bin2D) XYWidth ¶
XYWidth returns the (signed) (x,y) widths of the bin
func (*Bin2D) YEdges ¶
YEdges returns the [low,high] edges of this bin.
func (*Bin2D) YFocus ¶
YFocus returns the mean position in the bin, or the midpoint (if the sum of weights for this bin is 0).
func (*Bin2D) YMax ¶
YMax returns the upper limit of the bin (exclusive).
func (*Bin2D) YMean ¶
YMean returns the mean Y.
func (*Bin2D) YMid ¶
YMid returns the geometric center of the bin. i.e.: 0.5*(high+low)
func (*Bin2D) YMin ¶
YMin returns the lower limit of the bin (inclusive).
func (*Bin2D) YRMS ¶
YRMS returns the RMS in Y.
func (*Bin2D) YStdDev ¶
YStdDev returns the standard deviation in Y.
func (*Bin2D) YStdErr ¶
YStdErr returns the standard error in Y.
func (*Bin2D) YVariance ¶
YVariance returns the variance in Y.
func (*Bin2D) YWidth ¶
YWidth returns the (signed) width of the bin
type BinP1D ¶
type BinP1D struct {
// contains filtered or unexported fields
}
BinP1D models a bin in a 1-dim space.
func (*BinP1D) EffEntries ¶
EffEntries returns the effective number of entries \f$ = (\sum w)^2 / \sum w^2 \f$
func (*BinP1D) Entries ¶
Entries returns the number of entries in this bin.
func (*BinP1D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (BinP1D) Rank ¶
Rank returns the number of dimensions for this bin.
func (*BinP1D) SumW ¶
SumW returns the sum of weights in this bin.
func (*BinP1D) SumW2 ¶
SumW2 returns the sum of squared weights in this bin.
func (*BinP1D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (*BinP1D) XEdges ¶
XEdges returns the [low,high] edges of this bin.
func (*BinP1D) XFocus ¶
XFocus returns the mean position in the bin, or the midpoint (if the sum of weights for this bin is 0).
func (*BinP1D) XMax ¶
XMax returns the upper limit of the bin (exclusive).
func (*BinP1D) XMean ¶
XMean returns the mean X.
func (*BinP1D) XMid ¶
XMid returns the geometric center of the bin. i.e.: 0.5*(high+low)
func (*BinP1D) XMin ¶
XMin returns the lower limit of the bin (inclusive).
func (*BinP1D) XRMS ¶
XRMS returns the RMS in X.
func (*BinP1D) XStdDev ¶
XStdDev returns the standard deviation in X.
func (*BinP1D) XStdErr ¶
XStdErr returns the standard error in X.
func (*BinP1D) XVariance ¶
XVariance returns the variance in X.
func (*BinP1D) XWidth ¶
XWidth returns the (signed) width of the bin
type Binning1D ¶
Binning1D is a 1-dim binning of the x-axis.
func (*Binning1D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*Binning1D) Overflow ¶
func (*Binning1D) Underflow ¶
func (*Binning1D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
type Binning2D ¶
type Binning2D struct { Bins []Bin2D Dist Dist2D Outflows [8]Dist2D XRange Range YRange Range Nx int Ny int XEdges []Bin1D YEdges []Bin1D }
func (*Binning2D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*Binning2D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
type Count ¶
Count is a 1-dim binned information, made of
a X range, a value and its uncertainties.
Code:play
Output: Code:play
Output:Example¶
package main
import (
"fmt"
"go-hep.org/x/hep/hbook"
)
func main() {
c := hbook.Count{}
c.XRange = hbook.Range{Min: 0, Max: 1}
c.Val = 10
c.Err.Low = 2
c.Err.High = 3
fmt.Printf("[%v, %v] -> %v +%v -%v",
c.XRange.Min, c.XRange.Max,
c.Val, c.Err.High, c.Err.Low)
}
[0, 1] -> 10 +3 -2
Example (WithH1D)¶
package main
import (
"fmt"
"go-hep.org/x/hep/hbook"
)
func main() {
h := hbook.NewH1D(6, 0, 6)
h.Fill(-0.5, 1)
h.Fill(0, 1.5)
h.Fill(0.5, 1)
h.Fill(1.2, 1)
h.Fill(2.1, 2)
h.Fill(4.2, 1)
h.Fill(5.9, 1)
h.Fill(6, 0.5)
for _, c := range h.Counts() {
fmt.Printf("[%v, %v] -> %v +%.1f -%.1f\n",
c.XRange.Min, c.XRange.Max,
c.Val, c.Err.High, c.Err.Low)
}
}
[0, 1] -> 2.5 +0.9 -0.9
[1, 2] -> 1 +0.5 -0.5
[2, 3] -> 2 +1.0 -1.0
[3, 4] -> 0 +0.0 -0.0
[4, 5] -> 1 +0.5 -0.5
[5, 6] -> 1 +0.5 -0.5
type Dist0D ¶
type Dist0D struct { N int64 // number of entries SumW float64 // sum of weights SumW2 float64 // sum of squared weights }
Dist0D is a 0-dim distribution.
func (*Dist0D) EffEntries ¶
EffEntries returns the number of weighted entries, such as:
(\sum w)^2 / \sum w^2
func (*Dist0D) Entries ¶
Entries returns the number of entries in the distribution.
func (*Dist0D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*Dist0D) Rank ¶
Rank returns the number of dimensions of the distribution.
func (*Dist0D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
type Dist1D ¶
type Dist1D struct { Dist Dist0D // weight moments Stats struct { SumWX float64 // 1st order weighted x moment SumWX2 float64 // 2nd order weighted x moment } }
Dist1D is a 1-dim distribution.
func (*Dist1D) EffEntries ¶
EffEntries returns the effective number of entries in the distribution.
func (*Dist1D) Entries ¶
Entries returns the number of entries in the distribution.
func (*Dist1D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*Dist1D) Rank ¶
Rank returns the number of dimensions of the distribution.
func (*Dist1D) SumW ¶
SumW returns the sum of weights of the distribution.
func (*Dist1D) SumW2 ¶
SumW2 returns the sum of squared weights of the distribution.
func (*Dist1D) SumWX ¶
SumWX returns the 1st order weighted x moment.
func (*Dist1D) SumWX2 ¶
SumWX2 returns the 2nd order weighted x moment.
func (*Dist1D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
type Dist2D ¶
type Dist2D struct { X Dist1D // x moments Y Dist1D // y moments Stats struct { SumWXY float64 // 2nd-order cross-term } }
Dist2D is a 2-dim distribution.
func (*Dist2D) EffEntries ¶
EffEntries returns the effective number of entries in the distribution.
func (*Dist2D) Entries ¶
Entries returns the number of entries in the distribution.
func (*Dist2D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*Dist2D) Rank ¶
Rank returns the number of dimensions of the distribution.
func (*Dist2D) SumW ¶
SumW returns the sum of weights of the distribution.
func (*Dist2D) SumW2 ¶
SumW2 returns the sum of squared weights of the distribution.
func (*Dist2D) SumWX ¶
SumWX returns the 1st order weighted x moment
func (*Dist2D) SumWX2 ¶
SumWX2 returns the 2nd order weighted x moment
func (*Dist2D) SumWXY ¶
SumWXY returns the 2nd-order cross-term.
func (*Dist2D) SumWY ¶
SumWY returns the 1st order weighted y moment
func (*Dist2D) SumWY2 ¶
SumWY2 returns the 2nd order weighted y moment
func (*Dist2D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
type DivOptions ¶
type DivOptions func(c *divConfig)
DivOptions allows to customize the behaviour of DivideH1D
func DivIgnoreNaNs ¶
func DivIgnoreNaNs() DivOptions
DivIgnoreNaNs function configures DivideH1D to ignore data points with NaNs.
func DivReplaceNaNs ¶
func DivReplaceNaNs(v float64) DivOptions
DivReplaceNaNs function configures DivideH1D to replace NaN raised during divisions with the provided value.
type H1D ¶
type H1D struct { Binning Binning1D Ann Annotation }
H1D is a 1-dim histogram with weighted entries.
Code:
Output:Example¶
{
const npoints = 10000
// Create a normal distribution.
dist := distuv.Normal{
Mu: 0,
Sigma: 1,
Src: rand.New(rand.NewPCG(0, 0)),
}
// Draw some random values from the standard
// normal distribution.
h := hbook.NewH1D(20, -4, +4)
for range npoints {
v := dist.Rand()
h.Fill(v, 1)
}
// fill h with a slice of values and their weights
h.FillN([]float64{1, 2, 3}, []float64{1, 1, 1})
h.FillN([]float64{1, 2, 3}, nil) // all weights are 1.
fmt.Printf("mean: %.12f\n", h.XMean())
fmt.Printf("rms: %.12f\n", h.XRMS())
fmt.Printf("std-dev: %.12f\n", h.XStdDev())
fmt.Printf("std-err: %.12f\n", h.XStdErr())
// Output:
// mean: 0.002104228518
// rms: 1.000617135827
// std-dev: 1.000664927794
// std-err: 0.010003648633
}
mean: 0.002104228518
rms: 1.000617135827
std-dev: 1.000664927794
std-err: 0.010003648633
func AddH1D ¶
AddH1D returns the bin-by-bin summed histogram of h1 and h2
assuming their statistical uncertainties are uncorrelated.
Code:play
Output:Example¶
package main
import (
"fmt"
"math"
"go-hep.org/x/hep/hbook"
)
func main() {
h1 := hbook.NewH1D(6, 0, 6)
h1.Fill(-0.5, 1)
h1.Fill(0, 1.5)
h1.Fill(0.5, 1)
h1.Fill(1.2, 1)
h1.Fill(2.1, 2)
h1.Fill(4.2, 1)
h1.Fill(5.9, 1)
h1.Fill(6, 0.5)
h2 := hbook.NewH1D(6, 0, 6)
h2.Fill(-0.5, 0.7)
h2.Fill(0.2, 1)
h2.Fill(0.7, 1.2)
h2.Fill(1.5, 0.8)
h2.Fill(2.2, 0.7)
h2.Fill(4.3, 1.3)
h2.Fill(5.2, 2)
h2.Fill(6.8, 1)
hsum := hbook.AddH1D(h1, h2)
fmt.Printf("Under: %.1f +/- %.1f\n", hsum.Binning.Outflows[0].SumW(), math.Sqrt(hsum.Binning.Outflows[0].SumW2()))
for i := range hsum.Len() {
fmt.Printf("Bin %v: %.1f +/- %.1f\n", i, hsum.Binning.Bins[i].SumW(), math.Sqrt(hsum.Binning.Bins[i].SumW2()))
}
fmt.Printf("Over : %.1f +/- %.1f\n", hsum.Binning.Outflows[1].SumW(), math.Sqrt(hsum.Binning.Outflows[1].SumW2()))
}
Under: 1.7 +/- 1.2
Bin 0: 4.7 +/- 2.4
Bin 1: 1.8 +/- 1.3
Bin 2: 2.7 +/- 2.1
Bin 3: 0.0 +/- 0.0
Bin 4: 2.3 +/- 1.6
Bin 5: 3.0 +/- 2.2
Over : 1.5 +/- 1.1
func AddScaledH1D ¶
AddScaledH1D returns the histogram with the bin-by-bin h1+alpha*h2
operation, assuming statistical uncertainties are uncorrelated.
Code:play
Output:Example¶
package main
import (
"fmt"
"math"
"go-hep.org/x/hep/hbook"
)
func main() {
h1 := hbook.NewH1D(6, 0, 6)
h1.Fill(-0.5, 1)
h1.Fill(0, 1.5)
h1.Fill(0.5, 1)
h1.Fill(1.2, 1)
h1.Fill(2.1, 2)
h1.Fill(4.2, 1)
h1.Fill(5.9, 1)
h1.Fill(6, 0.5)
h2 := hbook.NewH1D(6, 0, 6)
h2.Fill(-0.5, 0.7)
h2.Fill(0.2, 1)
h2.Fill(0.7, 1.2)
h2.Fill(1.5, 0.8)
h2.Fill(2.2, 0.7)
h2.Fill(4.3, 1.3)
h2.Fill(5.2, 2)
h2.Fill(6.8, 1)
hsum := hbook.AddScaledH1D(h1, 10, h2)
fmt.Printf("Under: %.1f +/- %.1f\n", hsum.Binning.Outflows[0].SumW(), math.Sqrt(hsum.Binning.Outflows[0].SumW2()))
for i := range hsum.Len() {
fmt.Printf("Bin %v: %.1f +/- %.1f\n", i, hsum.Binning.Bins[i].SumW(), math.Sqrt(hsum.Binning.Bins[i].SumW2()))
}
fmt.Printf("Over : %.1f +/- %.1f\n", hsum.Binning.Outflows[1].SumW(), math.Sqrt(hsum.Binning.Outflows[1].SumW2()))
}
Under: 8.0 +/- 7.1
Bin 0: 24.5 +/- 15.7
Bin 1: 9.0 +/- 8.1
Bin 2: 9.0 +/- 7.3
Bin 3: 0.0 +/- 0.0
Bin 4: 14.0 +/- 13.0
Bin 5: 21.0 +/- 20.0
Over : 10.5 +/- 10.0
func NewH1D ¶
NewH1D returns a 1-dim histogram with n bins between xmin and xmax.
func NewH1DFromBins ¶
NewH1DFromBins returns a 1-dim histogram given a slice of 1-dim bins. It panics if the length of bins is < 1. It panics if the bins overlap.
func NewH1DFromEdges ¶
NewH1DFromEdges returns a 1-dim histogram given a slice of edges. The number of bins is thus len(edges)-1. It panics if the length of edges is <= 1. It panics if the edges are not sorted. It panics if there are duplicate edge values.
func SubH1D ¶
SubH1D returns the bin-by-bin subtracted histogram of h1 and h2
assuming their statistical uncertainties are uncorrelated.
Code:play
Output:Example¶
package main
import (
"fmt"
"math"
"go-hep.org/x/hep/hbook"
)
func main() {
h1 := hbook.NewH1D(6, 0, 6)
h1.Fill(-0.5, 1)
h1.Fill(0, 1.5)
h1.Fill(0.5, 1)
h1.Fill(1.2, 1)
h1.Fill(2.1, 2)
h1.Fill(4.2, 1)
h1.Fill(5.9, 1)
h1.Fill(6, 0.5)
h2 := hbook.NewH1D(6, 0, 6)
h2.Fill(-0.5, 0.7)
h2.Fill(0.2, 1)
h2.Fill(0.7, 1.2)
h2.Fill(1.5, 0.8)
h2.Fill(2.2, 0.7)
h2.Fill(4.3, 1.3)
h2.Fill(5.2, 2)
h2.Fill(6.8, 1)
hsub := hbook.SubH1D(h1, h2)
under := hsub.Binning.Outflows[0]
fmt.Printf("Under: %.1f +/- %.1f\n", under.SumW(), math.Sqrt(under.SumW2()))
for i, bin := range hsub.Binning.Bins {
fmt.Printf("Bin %v: %.1f +/- %.1f\n", i, bin.SumW(), math.Sqrt(bin.SumW2()))
}
over := hsub.Binning.Outflows[1]
fmt.Printf("Over : %.1f +/- %.1f\n", over.SumW(), math.Sqrt(over.SumW2()))
}
Under: 0.3 +/- 1.2
Bin 0: 0.3 +/- 2.4
Bin 1: 0.2 +/- 1.3
Bin 2: 1.3 +/- 2.1
Bin 3: 0.0 +/- 0.0
Bin 4: -0.3 +/- 1.6
Bin 5: -1.0 +/- 2.2
Over : -0.5 +/- 1.1
func (*H1D) Annotation ¶
func (h *H1D) Annotation() Annotation
Annotation returns the annotations attached to this histogram
func (*H1D) Bin ¶
Bin returns the bin at coordinates (x) for this 1-dim histogram. Bin returns nil for under/over flow bins.
func (*H1D) Clone ¶
Clone returns a deep copy of this 1-dim histogram.
func (*H1D) Counts ¶
Counts return a slice of Count, ignoring outerflow. The low and high error is equal to 0.5 * sqrt(sum(w^2)).
func (*H1D) DataRange ¶
DataRange implements the gonum/plot.DataRanger interface
func (*H1D) EffEntries ¶
EffEntries returns the number of effective entries in this histogram
func (*H1D) Entries ¶
Entries returns the number of entries in this histogram
func (*H1D) Error ¶
Error returns the error, defined as sqrt(sumW2), of the idx-th bin.
func (*H1D) Fill ¶
Fill fills this histogram with x and weight w.
func (*H1D) FillN ¶
FillN fills this histogram with the provided slices of xs and weight ws. if ws is nil, the histogram will be filled with entries of weight 1. Otherwise, FillN panics if the slices lengths differ.
func (*H1D) Integral ¶
Integral computes the integral of the histogram.
The number of parameters can be 0 or 2. If 0, overflows are included. If 2, the first parameter must be the lower bound of the range in which the integral is computed and the second one the upper range.
If the lower bound is math.Inf(-1) then the underflow bin is included. If the upper bound is math.Inf(+1) then the overflow bin is included.
Examples:
// integral of all in-range bins + overflows v := h.Integral() // integral of all in-range bins, underflow and overflow bins included. v := h.Integral(math.Inf(-1), math.Inf(+1)) // integrall of all in-range bins, overflow bin included v := h.Integral(h.Binning.XRange.Min, math.Inf(+1)) // integrall of all bins for which the lower edge is in [0.5, 5.5) v := h.Integral(0.5, 5.5)
func (*H1D) Len ¶
Len returns the number of bins for this histogram
Len implements gonum/plot/plotter.Valuer
func (*H1D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*H1D) MarshalYODA ¶
MarshalYODA implements the YODAMarshaler interface.
func (*H1D) Name ¶
Name returns the name of this histogram, if any
func (*H1D) Rank ¶
Rank returns the number of dimensions for this histogram
func (*H1D) RioMarshal ¶
RioMarshal implements rio.RioMarshaler
func (*H1D) RioUnmarshal ¶
RioUnmarshal implements rio.RioUnmarshaler
func (*H1D) RioVersion ¶
RioVersion implements rio.RioStreamer
func (*H1D) Scale ¶
Scale scales the content of each bin by the given factor.
func (*H1D) SumW ¶
SumW returns the sum of weights in this histogram. Overflows are included in the computation.
func (*H1D) SumW2 ¶
SumW2 returns the sum of squared weights in this histogram. Overflows are included in the computation.
func (*H1D) SumWX ¶
SumWX returns the 1st order weighted x moment
func (*H1D) SumWX2 ¶
SumWX2 returns the 2nd order weighted x moment
func (*H1D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (*H1D) UnmarshalYODA ¶
UnmarshalYODA implements the YODAUnmarshaler interface.
func (*H1D) Value ¶
Value returns the content of the idx-th bin.
Value implements gonum/plot/plotter.Valuer
func (*H1D) XMax ¶
XMax returns the high edge of the X-axis of this histogram.
func (*H1D) XMean ¶
XMean returns the mean X. Overflows are included in the computation.
func (*H1D) XMin ¶
XMin returns the low edge of the X-axis of this histogram.
func (*H1D) XRMS ¶
XRMS returns the XRMS in X. Overflows are included in the computation.
func (*H1D) XStdDev ¶
XStdDev returns the standard deviation in X. Overflows are included in the computation.
func (*H1D) XStdErr ¶
XStdErr returns the standard error in X. Overflows are included in the computation.
func (*H1D) XVariance ¶
XVariance returns the variance in X. Overflows are included in the computation.
func (*H1D) XY ¶
XY returns the x,y values for the i-th bin
XY implements gonum/plot/plotter.XYer
type H2D ¶
type H2D struct { Binning Binning2D Ann Annotation }
H2D is a 2-dim histogram with weighted entries.
Code:
Example¶
{
h := hbook.NewH2D(100, -10, 10, 100, -10, 10)
const npoints = 10000
dist, ok := distmv.NewNormal(
[]float64{0, 1},
mat.NewSymDense(2, []float64{4, 0, 0, 2}),
rand.New(rand.NewPCG(1234, 1234)),
)
if !ok {
log.Fatalf("error creating distmv.Normal")
}
v := make([]float64, 2)
// Draw some random values from the standard
// normal distribution.
for range npoints {
v = dist.Rand(v)
h.Fill(v[0], v[1], 1)
}
// fill h with slices of values and their weights
h.FillN(
[]float64{1, 2, 3}, // xs
[]float64{1, 2, 3}, // ys
[]float64{1, 1, 1}, // ws
)
// fill h with slices of values. all weights are 1.
h.FillN(
[]float64{1, 2, 3}, // xs
[]float64{1, 2, 3}, // ys
nil, // ws
)
}
func NewH2D ¶
NewH2D creates a new 2-dim histogram.
func NewH2DFromEdges ¶
NewH2DFromEdges creates a new 2-dim histogram from slices of edges in x and y. The number of bins in x and y is thus len(edges)-1. It panics if the length of edges is <=1 (in any dimension.) It panics if the edges are not sorted (in any dimension.) It panics if there are duplicate edge values (in any dimension.)
func (*H2D) Annotation ¶
func (h *H2D) Annotation() Annotation
Annotation returns the annotations attached to this histogram
func (*H2D) Bin ¶
Bin returns the bin at coordinates (x,y) for this 2-dim histogram. Bin returns nil for under/over flow bins.
func (*H2D) EffEntries ¶
EffEntries returns the number of effective entries in this histogram
func (*H2D) Entries ¶
Entries returns the number of entries in this histogram
func (*H2D) Fill ¶
Fill fills this histogram with (x,y) and weight w.
func (*H2D) FillN ¶
FillN fills this histogram with the provided slices (xs,ys) and weights ws. if ws is nil, the histogram will be filled with entries of weight 1. Otherwise, FillN panics if the slices lengths differ.
func (*H2D) GridXYZ ¶
func (h *H2D) GridXYZ() h2dGridXYZ
GridXYZ returns an anonymous struct value that implements gonum/plot/plotter.GridXYZ and is ready to plot.
func (*H2D) Integral ¶
Integral computes the integral of the histogram.
Overflows are included in the computation.
func (*H2D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*H2D) MarshalYODA ¶
MarshalYODA implements the YODAMarshaler interface.
func (*H2D) Name ¶
Name returns the name of this histogram, if any
func (*H2D) Rank ¶
Rank returns the number of dimensions for this histogram
func (*H2D) SumW ¶
SumW returns the sum of weights in this histogram. Overflows are included in the computation.
func (*H2D) SumW2 ¶
SumW2 returns the sum of squared weights in this histogram. Overflows are included in the computation.
func (*H2D) SumWX ¶
SumWX returns the 1st order weighted x moment Overflows are included in the computation.
func (*H2D) SumWX2 ¶
SumWX2 returns the 2nd order weighted x moment Overflows are included in the computation.
func (*H2D) SumWXY ¶
SumWXY returns the 1st order weighted x*y moment Overflows are included in the computation.
func (*H2D) SumWY ¶
SumWY returns the 1st order weighted y moment Overflows are included in the computation.
func (*H2D) SumWY2 ¶
SumWY2 returns the 2nd order weighted y moment Overflows are included in the computation.
func (*H2D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (*H2D) UnmarshalYODA ¶
UnmarshalYODA implements the YODAUnmarshaler interface.
func (*H2D) XMax ¶
XMax returns the high edge of the X-axis of this histogram.
func (*H2D) XMean ¶
XMean returns the mean X. Overflows are included in the computation.
func (*H2D) XMin ¶
XMin returns the low edge of the X-axis of this histogram.
func (*H2D) XRMS ¶
XRMS returns the RMS in X. Overflows are included in the computation.
func (*H2D) XStdDev ¶
XStdDev returns the standard deviation in X. Overflows are included in the computation.
func (*H2D) XStdErr ¶
XStdErr returns the standard error in X. Overflows are included in the computation.
func (*H2D) XVariance ¶
XVariance returns the variance in X. Overflows are included in the computation.
func (*H2D) YMax ¶
YMax returns the high edge of the Y-axis of this histogram.
func (*H2D) YMean ¶
YMean returns the mean Y. Overflows are included in the computation.
func (*H2D) YMin ¶
YMin returns the low edge of the Y-axis of this histogram.
func (*H2D) YRMS ¶
YRMS returns the RMS in Y. Overflows are included in the computation.
func (*H2D) YStdDev ¶
YStdDev returns the standard deviation in Y. Overflows are included in the computation.
func (*H2D) YStdErr ¶
YStdErr returns the standard error in Y. Overflows are included in the computation.
func (*H2D) YVariance ¶
YVariance returns the variance in Y. Overflows are included in the computation.
type Histogram ¶
type Histogram interface { // Annotation returns the annotations attached to the // histogram. (e.g. name, title, ...) Annotation() Annotation // Name returns the name of this histogram Name() string // Rank returns the number of dimensions of this histogram. Rank() int // Entries returns the number of entries of this histogram. Entries() int64 }
Histogram is an n-dim histogram (with weighted entries)
type Object ¶
type Object interface { Annotation() Annotation Name() string }
Object is the general handle to any hbook data analysis object.
type P1D ¶
type P1D struct {
// contains filtered or unexported fields
}
P1D is a 1-dim profile histogram.
Code:
Output:Example¶
{
const npoints = 1000
p := hbook.NewP1D(100, -10, 10)
dist, ok := distmv.NewNormal(
[]float64{0, 1},
mat.NewSymDense(2, []float64{4, 0, 0, 2}),
rand.New(rand.NewPCG(1234, 1234)),
)
if !ok {
log.Fatalf("error creating distmv.Normal")
}
v := make([]float64, 2)
// Draw some random values from the standard
// normal distribution.
for range npoints {
v = dist.Rand(v)
p.Fill(v[0], v[1], 1)
}
fmt.Printf("mean: %v\n", p.XMean())
fmt.Printf("rms: %v\n", p.XRMS())
fmt.Printf("std-dev: %v\n", p.XStdDev())
fmt.Printf("std-err: %v\n", p.XStdErr())
// Output:
// mean: 0.0965063103552738
// rms: 2.0024868956390707
// std-dev: 2.0011608991313086
// std-err: 0.06328226405725404
}
mean: 0.0965063103552738
rms: 2.0024868956390707
std-dev: 2.0011608991313086
std-err: 0.06328226405725404
func NewP1D ¶
NewP1D returns a 1-dim profile histogram with n bins between xmin and xmax.
func NewP1DFromH1D ¶
NewP1DFromH1D creates a 1-dim profile histogram from a 1-dim histogram's binning.
func (*P1D) Annotation ¶
func (p *P1D) Annotation() Annotation
Annotation returns the annotations attached to this profile histogram
func (*P1D) Binning ¶
func (p *P1D) Binning() *binningP1D
Binning returns the binning of this profile histogram
func (*P1D) EffEntries ¶
EffEntries returns the number of effective entries in this profile histogram
func (*P1D) Entries ¶
Entries returns the number of entries in this profile histogram
func (*P1D) Fill ¶
Fill fills this histogram with x,y and weight w.
func (*P1D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*P1D) MarshalYODA ¶
MarshalYODA implements the YODAMarshaler interface.
func (*P1D) Name ¶
Name returns the name of this profile histogram, if any
func (*P1D) Rank ¶
Rank returns the number of dimensions for this profile histogram
func (*P1D) Scale ¶
Scale scales the content of each bin by the given factor.
func (*P1D) SumW ¶
SumW returns the sum of weights in this profile histogram. Overflows are included in the computation.
func (*P1D) SumW2 ¶
SumW2 returns the sum of squared weights in this profile histogram. Overflows are included in the computation.
func (*P1D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (*P1D) UnmarshalYODA ¶
UnmarshalYODA implements the YODAUnmarshaler interface.
func (*P1D) XMax ¶
XMax returns the high edge of the X-axis of this profile histogram.
func (*P1D) XMean ¶
XMean returns the mean X. Overflows are included in the computation.
func (*P1D) XMin ¶
XMin returns the low edge of the X-axis of this profile histogram.
func (*P1D) XRMS ¶
XRMS returns the XRMS in X. Overflows are included in the computation.
func (*P1D) XStdDev ¶
XStdDev returns the standard deviation in X. Overflows are included in the computation.
func (*P1D) XStdErr ¶
XStdErr returns the standard error in X. Overflows are included in the computation.
func (*P1D) XVariance ¶
XVariance returns the variance in X. Overflows are included in the computation.
type Point2D ¶
type Point2D struct { X float64 // x-position Y float64 // y-position ErrX Range // error on x-position ErrY Range // error on y-position }
Point2D is a position in a 2-dim space
func (*Point2D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*Point2D) ScaleX ¶
ScaleX rescales the X value by a factor f.
func (*Point2D) ScaleXY ¶
ScaleXY rescales the X and Y values by a factor f.
func (*Point2D) ScaleY ¶
ScaleY rescales the Y value by a factor f.
func (*Point2D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (Point2D) XMax ¶
XMax returns the X value plus positive X-error
func (Point2D) XMin ¶
XMin returns the X value minus negative X-error
func (Point2D) YMax ¶
YMax returns the Y value plus positive Y-error
func (Point2D) YMin ¶
YMin returns the Y value minus negative Y-error
type Rand1D ¶
type Rand1D struct {
// contains filtered or unexported fields
}
Rand1D represents a 1D distribution created from a hbook.H1D histogram.
Code:
Output:Example¶
{
const N = 10000
var (
h1 = hbook.NewH1D(100, -10, 10)
src = rand.New(rand.NewPCG(1234, 1234))
rnd = distuv.Normal{
Mu: 0,
Sigma: 2,
Src: src,
}
)
for range N {
h1.Fill(rnd.Rand(), 1)
}
var (
h2 = hbook.NewH1D(100, -10, 10)
hr = hbook.NewRand1D(h1, rand.NewPCG(5678, 5678))
)
for range N {
h2.Fill(hr.Rand(), 1)
}
fmt.Printf(
"h1: mean=%+8f std-dev=%+8f +/- %8f\n",
h1.XMean(), h1.XStdDev(), h1.XStdErr(),
)
fmt.Printf(
"cdf(0)= %+1.1f\ncdf(1)= %+1.1f\n",
rnd.CDF(0), rnd.CDF(1),
)
fmt.Printf(
"h2: mean=%+8f std-dev=%+8f +/- %8f\n",
h2.XMean(), h2.XStdDev(), h2.XStdErr(),
)
fmt.Printf(
"cdf(0)= %+1.1f\ncdf(1)= %+1.1f\n",
hr.CDF(0), hr.CDF(1),
)
h1.Scale(1. / h1.Integral(h1.XMin(), h1.XMax()))
h2.Scale(1. / h2.Integral(h2.XMin(), h2.XMax()))
{
rp := hplot.NewRatioPlot()
rp.Ratio = 0.3
rp.Top.Title.Text = "Distributions"
rp.Top.Y.Label.Text = "Y"
hh1 := hplot.NewH1D(h1)
hh1.FillColor = color.NRGBA{R: 255, A: 100}
hh2 := hplot.NewH1D(h2)
hh2.FillColor = color.NRGBA{B: 255, A: 100}
rp.Top.Add(
hh1, hh2,
hplot.NewGrid(),
)
rp.Top.Legend.Add("template", hh1)
rp.Top.Legend.Add("monte-carlo", hh2)
rp.Top.Legend.Top = true
rp.Bottom.X.Label.Text = "X"
rp.Bottom.Y.Label.Text = "Diff"
rp.Bottom.Add(
hplot.NewH1D(hbook.SubH1D(h1, h2)),
hplot.NewGrid(),
)
err := hplot.Save(rp, 15*vg.Centimeter, -1, "testdata/rand_h1d.png")
if err != nil {
log.Fatal(err)
}
}
// Output:
// h1: mean=+0.011317 std-dev=+2.027279 +/- 0.020273
// cdf(0)= +0.5
// cdf(1)= +0.7
// h2: mean=-0.026749 std-dev=+2.022967 +/- 0.020230
// cdf(0)= +0.5
// cdf(1)= +0.7
}
h1: mean=+0.011317 std-dev=+2.027279 +/- 0.020273
cdf(0)= +0.5
cdf(1)= +0.7
h2: mean=-0.026749 std-dev=+2.022967 +/- 0.020230
cdf(0)= +0.5
cdf(1)= +0.7
func NewRand1D ¶
NewRand1D creates a Rand1D from the provided histogram. If src is nil, the global x/exp/rand source will be used.
func (*Rand1D) CDF ¶
CDF computes the value of the cumulative density function at x.
func (*Rand1D) Rand ¶
Rand returns a random sample drawn from the distribution.
type Range ¶
Range is a 1-dim interval [Min, Max].
func (*Range) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*Range) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (Range) Width ¶
Width returns the size of the range.
type S2D ¶
type S2D struct {
// contains filtered or unexported fields
}
S2D is a collection of 2-dim data points with errors.
Code:play
Output: Code:play
Output: Code:play
Output:Example¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/hbook"
)
func main() {
s := hbook.NewS2D(hbook.Point2D{X: 1, Y: 1}, hbook.Point2D{X: 2, Y: 1.5}, hbook.Point2D{X: -1, Y: +2})
if s == nil {
log.Fatal("nil pointer to S2D")
}
fmt.Printf("len=%d\n", s.Len())
s.Fill(hbook.Point2D{X: 10, Y: -10, ErrX: hbook.Range{Min: 5, Max: 5}, ErrY: hbook.Range{Min: 6, Max: 6}})
fmt.Printf("len=%d\n", s.Len())
fmt.Printf("pt[%d]=%+v\n", 3, s.Point(3))
}
len=3
len=4
pt[3]={X:10 Y:-10 ErrX:{Min:5 Max:5} ErrY:{Min:6 Max:6}}
Example (NewS2DFrom)¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/hbook"
)
func main() {
s := hbook.NewS2DFrom([]float64{1, 2, -1}, []float64{1, 1.5, 2})
if s == nil {
log.Fatal("nil pointer to S2D")
}
fmt.Printf("len=%d\n", s.Len())
s.Fill(hbook.Point2D{X: 10, Y: -10, ErrX: hbook.Range{Min: 5, Max: 5}, ErrY: hbook.Range{Min: 6, Max: 6}})
fmt.Printf("len=%d\n", s.Len())
fmt.Printf("pt[%d]=%+v\n", 3, s.Point(3))
}
len=3
len=4
pt[3]={X:10 Y:-10 ErrX:{Min:5 Max:5} ErrY:{Min:6 Max:6}}
Example (NewS2DFromH1D)¶
package main
import (
"fmt"
"go-hep.org/x/hep/hbook"
)
func main() {
h := hbook.NewH1D(20, -4, +4)
h.Fill(1.1, 2)
h.Fill(2.1, 3)
h.Fill(3.1, 1)
h.Fill(1.1, 1)
h.Fill(-2.1, 1)
h.Fill(-3.1, 1)
s := hbook.NewS2DFromH1D(h)
s.Sort()
for _, pt := range s.Points() {
fmt.Printf("point=(%+3.2f +/- (%+3.2f,%+3.2f), %+3.2f +/- (%+3.2f, %+3.2f))\n", pt.X, pt.ErrX.Min, pt.ErrX.Max, pt.Y, pt.ErrY.Min, pt.ErrY.Max)
}
}
point=(-3.80 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(-3.40 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(-3.00 +/- (+0.20,+0.20), +2.50 +/- (+2.50, +2.50))
point=(-2.60 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(-2.20 +/- (+0.20,+0.20), +2.50 +/- (+2.50, +2.50))
point=(-1.80 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(-1.40 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(-1.00 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(-0.60 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(-0.20 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(+0.20 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(+0.60 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(+1.00 +/- (+0.20,+0.20), +7.50 +/- (+5.59, +5.59))
point=(+1.40 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(+1.80 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(+2.20 +/- (+0.20,+0.20), +7.50 +/- (+7.50, +7.50))
point=(+2.60 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(+3.00 +/- (+0.20,+0.20), +2.50 +/- (+2.50, +2.50))
point=(+3.40 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
point=(+3.80 +/- (+0.20,+0.20), +0.00 +/- (+0.00, +0.00))
func DivideH1D ¶
func DivideH1D(num, den *H1D, opts ...DivOptions) (*S2D, error)
DivideH1D divides 2 1D-histograms and returns a 2D scatter.
DivideH1D returns an error if the binning of the 1D histograms are not compatible.
If no DivOptions is passed, NaN raised during division are kept.
Code:
Output:Example¶
{
h1 := NewH1D(5, 0, 5)
h1.Fill(0, 1)
h1.Fill(1, 2)
h1.Fill(2, 3)
h1.Fill(3, 3)
h1.Fill(4, 4)
h2 := NewH1D(5, 0, 5)
h2.Fill(0, 11)
h2.Fill(1, 22)
h2.Fill(2, 0)
h2.Fill(3, 33)
h2.Fill(4, 44)
s0, err := DivideH1D(h1, h2)
if err != nil {
panic(err)
}
s1, err := DivideH1D(h1, h2, DivIgnoreNaNs())
if err != nil {
panic(err)
}
s2, err := DivideH1D(h1, h2, DivReplaceNaNs(1.0))
if err != nil {
panic(err)
}
fmt.Println("Default:")
for i, pt := range s0.Points() {
fmt.Printf("Point %v: %.2f + %.2f - %.2f\n", i, pt.Y, pt.ErrY.Min, pt.ErrY.Min)
}
fmt.Println("\nDivIgnoreNaNs:")
for i, pt := range s1.Points() {
fmt.Printf("Point %v: %.2f + %.2f - %.2f\n", i, pt.Y, pt.ErrY.Min, pt.ErrY.Min)
}
fmt.Println("\nDivReplaceNaNs with v=1.0:")
for i, pt := range s2.Points() {
fmt.Printf("Point %v: %.2f + %.2f - %.2f\n", i, pt.Y, pt.ErrY.Min, pt.ErrY.Min)
}
// Output:
// Default:
// Point 0: 0.09 + 0.13 - 0.13
// Point 1: 0.09 + 0.13 - 0.13
// Point 2: NaN + 0.00 - 0.00
// Point 3: 0.09 + 0.13 - 0.13
// Point 4: 0.09 + 0.13 - 0.13
//
// DivIgnoreNaNs:
// Point 0: 0.09 + 0.13 - 0.13
// Point 1: 0.09 + 0.13 - 0.13
// Point 2: 0.09 + 0.13 - 0.13
// Point 3: 0.09 + 0.13 - 0.13
//
// DivReplaceNaNs with v=1.0:
// Point 0: 0.09 + 0.13 - 0.13
// Point 1: 0.09 + 0.13 - 0.13
// Point 2: 1.00 + 0.00 - 0.00
// Point 3: 0.09 + 0.13 - 0.13
// Point 4: 0.09 + 0.13 - 0.13
}
Default:
Point 0: 0.09 + 0.13 - 0.13
Point 1: 0.09 + 0.13 - 0.13
Point 2: NaN + 0.00 - 0.00
Point 3: 0.09 + 0.13 - 0.13
Point 4: 0.09 + 0.13 - 0.13
DivIgnoreNaNs:
Point 0: 0.09 + 0.13 - 0.13
Point 1: 0.09 + 0.13 - 0.13
Point 2: 0.09 + 0.13 - 0.13
Point 3: 0.09 + 0.13 - 0.13
DivReplaceNaNs with v=1.0:
Point 0: 0.09 + 0.13 - 0.13
Point 1: 0.09 + 0.13 - 0.13
Point 2: 1.00 + 0.00 - 0.00
Point 3: 0.09 + 0.13 - 0.13
Point 4: 0.09 + 0.13 - 0.13
func NewS2D ¶
NewS2D creates a new 2-dim scatter with pts as an optional initial set of data points.
If n <= 0, the initial capacity is 0.
func NewS2DFrom ¶
NewS2DFrom creates a new 2-dim scatter with x,y data slices.
It panics if the lengths of the 2 slices don't match.
func NewS2DFromH1D ¶
NewS2DFromH1D creates a new 2-dim scatter from the given H1D. NewS2DFromH1D optionally takes a S2DOpts slice: only the first element is considered.
func NewS2DFromP1D ¶
NewS2DFromP1D creates a new 2-dim scatter from the given P1D. NewS2DFromP1D optionally takes a S2DOpts slice: only the first element is considered.
func (*S2D) Annotation ¶
func (s *S2D) Annotation() Annotation
Annotation returns the annotations attached to the scatter. (e.g. name, title, ...)
func (*S2D) DataRange ¶
DataRange returns the minimum and maximum x and y values, implementing the gonum/plot.DataRanger interface.
func (*S2D) Entries ¶
Entries returns the number of entries of this histogram.
func (*S2D) Fill ¶
Fill adds new points to the scatter.
func (*S2D) Len ¶
Len returns the number of points in the scatter.
Len implements the gonum/plot/plotter.XYer interface.
func (*S2D) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*S2D) MarshalYODA ¶
MarshalYODA implements the YODAMarshaler interface.
func (*S2D) Name ¶
Name returns the name of this scatter
func (*S2D) Point ¶
Point returns the point at index i.
Point panics if i is out of bounds.
func (*S2D) Points ¶
Points returns the points of the scatter.
Users may not modify the returned slice. Users may not rely on the stability of the indices as the slice of points may be re-sorted at any point in time.
func (*S2D) Rank ¶
Rank returns the number of dimensions of this scatter.
func (*S2D) ScaleX ¶
ScaleX rescales the X values by a factor f.
func (*S2D) ScaleXY ¶
ScaleXY rescales the X and Y values by a factor f.
func (*S2D) ScaleY ¶
ScaleY rescales the Y values by a factor f.
func (*S2D) Sort ¶
func (s *S2D) Sort()
Sort sorts the data points by x,y and x-err,y-err.
func (*S2D) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (*S2D) UnmarshalYODA ¶
UnmarshalYODA implements the YODAUnmarshaler interface.
func (*S2D) XError ¶
XError returns the two error values for X data.
XError implements the gonum/plot/plotter.XErrorer interface.
func (*S2D) XY ¶
XY returns the x, y pair at index i.
XY panics if i is out of bounds. XY implements the gonum/plot/plotter.XYer interface.
func (*S2D) YError ¶
YError returns the two error values for Y data.
YError implements the gonum/plot/plotter.YErrorer interface.
type S2DOpts ¶
S2DOpts controls how S2D scatters are created from H1D and P1D.
Source Files ¶
ann.go bin1d.go bin2d.go binning1d.go binning2d.go binning_brio.go dist.go dist_brio.go doc.go h1d.go h2d.go hbook.go hbook_brio.go io.go object.go ops.go p1d.go points.go points_brio.go rand_h1d.go s2d.go yoda.go
Directories ¶
Path | Synopsis |
---|---|
hbook/ntup | Package ntup provides a way to create, open and iterate over n-tuple data. |
hbook/ntup/ntcsv | Package ntcsv provides a convenient access to CSV files as n-tuple data. |
hbook/ntup/ntroot | Package ntroot provides convenience functions to access ROOT trees as n-tuple data. |
hbook/rootcnv | Package rootcnv provides tools to convert ROOT histograms and graphs to go-hep/hbook ones. |
hbook/yodacnv | Package yodacnv provides tools to read/write YODA archive files. |
- Version
- v0.37.0 (latest)
- Published
- May 20, 2025
- Platform
- linux/amd64
- Imports
- 15 packages
- Last checked
- 3 days ago –
Tools for package owners.