hep: go-hep.org/x/hep/hbook Index | Examples | Files | Directories

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

Examples

Package Files

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 object.go ops.go p1d.go points.go points_brio.go s2d.go yoda.go

Constants

const (
    UnderflowBin1D = -1
    OverflowBin1D  = -2
)

Indices for the under- and over-flow 1-dim bins.

const (
    BngNW int = 1 + iota
    BngN
    BngNE
    BngE
    BngSE
    BngS
    BngSW
    BngW
)

indices for the 2D-binning overflows

type Annotation Uses

type Annotation map[string]interface{}

Annotation is a bag of attributes that are attached to a histogram.

func (*Annotation) MarshalBinary Uses

func (ann *Annotation) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

func (Annotation) MarshalYODA Uses

func (ann Annotation) MarshalYODA() ([]byte, error)

MarshalYODA implements the YODAMarshaler interface.

func (*Annotation) UnmarshalBinary Uses

func (ann *Annotation) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*Annotation) UnmarshalYODA Uses

func (ann *Annotation) UnmarshalYODA(data []byte) error

UnmarshalYODA implements the YODAUnmarshaler interface.

type Bin Uses

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 Uses

type Bin1D struct {
    Range Range
    Dist  Dist1D
}

Bin1D models a bin in a 1-dim space.

func (*Bin1D) EffEntries Uses

func (b *Bin1D) EffEntries() float64

EffEntries returns the effective number of entries \f$ = (\sum w)^2 / \sum w^2 \f$

func (*Bin1D) Entries Uses

func (b *Bin1D) Entries() int64

Entries returns the number of entries in this bin.

func (*Bin1D) ErrW Uses

func (b *Bin1D) ErrW() float64

ErrW returns the absolute error on SumW()

func (*Bin1D) MarshalBinary Uses

func (o *Bin1D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (Bin1D) Rank Uses

func (Bin1D) Rank() int

Rank returns the number of dimensions for this bin.

func (*Bin1D) SumW Uses

func (b *Bin1D) SumW() float64

SumW returns the sum of weights in this bin.

func (*Bin1D) SumW2 Uses

func (b *Bin1D) SumW2() float64

SumW2 returns the sum of squared weights in this bin.

func (*Bin1D) UnmarshalBinary Uses

func (o *Bin1D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*Bin1D) XEdges Uses

func (b *Bin1D) XEdges() Range

XEdges returns the [low,high] edges of this bin.

func (*Bin1D) XFocus Uses

func (b *Bin1D) XFocus() float64

XFocus returns the mean position in the bin, or the midpoint (if the sum of weights for this bin is 0).

func (*Bin1D) XMax Uses

func (b *Bin1D) XMax() float64

XMax returns the upper limit of the bin (exclusive).

func (*Bin1D) XMean Uses

func (b *Bin1D) XMean() float64

XMean returns the mean X.

func (*Bin1D) XMid Uses

func (b *Bin1D) XMid() float64

XMid returns the geometric center of the bin. i.e.: 0.5*(high+low)

func (*Bin1D) XMin Uses

func (b *Bin1D) XMin() float64

XMin returns the lower limit of the bin (inclusive).

func (*Bin1D) XRMS Uses

func (b *Bin1D) XRMS() float64

XRMS returns the RMS in X.

func (*Bin1D) XStdDev Uses

func (b *Bin1D) XStdDev() float64

XStdDev returns the standard deviation in X.

func (*Bin1D) XStdErr Uses

func (b *Bin1D) XStdErr() float64

XStdErr returns the standard error in X.

func (*Bin1D) XVariance Uses

func (b *Bin1D) XVariance() float64

XVariance returns the variance in X.

func (*Bin1D) XWidth Uses

func (b *Bin1D) XWidth() float64

XWidth returns the (signed) width of the bin

type Bin1Ds Uses

type Bin1Ds []Bin1D

Bin1Ds is a sorted slice of Bin1D implementing sort.Interface.

func (Bin1Ds) IndexOf Uses

func (p Bin1Ds) IndexOf(v float64) int

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 Uses

func (p Bin1Ds) Len() int

func (Bin1Ds) Less Uses

func (p Bin1Ds) Less(i, j int) bool

func (Bin1Ds) Swap Uses

func (p Bin1Ds) Swap(i, j int)

type Bin2D Uses

type Bin2D struct {
    XRange Range
    YRange Range
    Dist   Dist2D
}

Bin2D models a bin in a 2-dim space.

func (*Bin2D) EffEntries Uses

func (b *Bin2D) EffEntries() float64

EffEntries returns the effective number of entries \f$ = (\sum w)^2 / \sum w^2 \f$

func (*Bin2D) Entries Uses

func (b *Bin2D) Entries() int64

Entries returns the number of entries in this bin.

func (*Bin2D) MarshalBinary Uses

func (o *Bin2D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (Bin2D) Rank Uses

func (Bin2D) Rank() int

Rank returns the number of dimensions for this bin.

func (*Bin2D) SumW Uses

func (b *Bin2D) SumW() float64

SumW returns the sum of weights in this bin.

func (*Bin2D) SumW2 Uses

func (b *Bin2D) SumW2() float64

SumW2 returns the sum of squared weights in this bin.

func (*Bin2D) UnmarshalBinary Uses

func (o *Bin2D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*Bin2D) XEdges Uses

func (b *Bin2D) XEdges() Range

XEdges returns the [low,high] edges of this bin.

func (*Bin2D) XFocus Uses

func (b *Bin2D) XFocus() float64

XFocus returns the mean position in the bin, or the midpoint (if the sum of weights for this bin is 0).

func (*Bin2D) XMax Uses

func (b *Bin2D) XMax() float64

XMax returns the upper limit of the bin (exclusive).

func (*Bin2D) XMean Uses

func (b *Bin2D) XMean() float64

XMean returns the mean X.

func (*Bin2D) XMid Uses

func (b *Bin2D) XMid() float64

XMid returns the geometric center of the bin. i.e.: 0.5*(high+low)

func (*Bin2D) XMin Uses

func (b *Bin2D) XMin() float64

XMin returns the lower limit of the bin (inclusive).

func (*Bin2D) XRMS Uses

func (b *Bin2D) XRMS() float64

XRMS returns the RMS in X.

func (*Bin2D) XStdDev Uses

func (b *Bin2D) XStdDev() float64

XStdDev returns the standard deviation in X.

func (*Bin2D) XStdErr Uses

func (b *Bin2D) XStdErr() float64

XStdErr returns the standard error in X.

func (*Bin2D) XVariance Uses

func (b *Bin2D) XVariance() float64

XVariance returns the variance in X.

func (*Bin2D) XWidth Uses

func (b *Bin2D) XWidth() float64

XWidth returns the (signed) width of the bin

func (*Bin2D) XYFocus Uses

func (b *Bin2D) XYFocus() (float64, float64)

XYFocus returns the mean position in the bin, or the midpoint (if the sum of weights for this bin is 0).

func (*Bin2D) XYMid Uses

func (b *Bin2D) XYMid() (float64, float64)

XYMid returns the (x,y) coordinates of the geometric center of the bin. i.e.: 0.5*(high+low)

func (*Bin2D) XYWidth Uses

func (b *Bin2D) XYWidth() (float64, float64)

XYWidth returns the (signed) (x,y) widths of the bin

func (*Bin2D) YEdges Uses

func (b *Bin2D) YEdges() Range

YEdges returns the [low,high] edges of this bin.

func (*Bin2D) YFocus Uses

func (b *Bin2D) YFocus() float64

YFocus returns the mean position in the bin, or the midpoint (if the sum of weights for this bin is 0).

func (*Bin2D) YMax Uses

func (b *Bin2D) YMax() float64

YMax returns the upper limit of the bin (exclusive).

func (*Bin2D) YMean Uses

func (b *Bin2D) YMean() float64

YMean returns the mean Y.

func (*Bin2D) YMid Uses

func (b *Bin2D) YMid() float64

YMid returns the geometric center of the bin. i.e.: 0.5*(high+low)

func (*Bin2D) YMin Uses

func (b *Bin2D) YMin() float64

YMin returns the lower limit of the bin (inclusive).

func (*Bin2D) YRMS Uses

func (b *Bin2D) YRMS() float64

YRMS returns the RMS in Y.

func (*Bin2D) YStdDev Uses

func (b *Bin2D) YStdDev() float64

YStdDev returns the standard deviation in Y.

func (*Bin2D) YStdErr Uses

func (b *Bin2D) YStdErr() float64

YStdErr returns the standard error in Y.

func (*Bin2D) YVariance Uses

func (b *Bin2D) YVariance() float64

YVariance returns the variance in Y.

func (*Bin2D) YWidth Uses

func (b *Bin2D) YWidth() float64

YWidth returns the (signed) width of the bin

type BinP1D Uses

type BinP1D struct {
    // contains filtered or unexported fields
}

BinP1D models a bin in a 1-dim space.

func (*BinP1D) EffEntries Uses

func (b *BinP1D) EffEntries() float64

EffEntries returns the effective number of entries \f$ = (\sum w)^2 / \sum w^2 \f$

func (*BinP1D) Entries Uses

func (b *BinP1D) Entries() int64

Entries returns the number of entries in this bin.

func (*BinP1D) MarshalBinary Uses

func (o *BinP1D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (BinP1D) Rank Uses

func (BinP1D) Rank() int

Rank returns the number of dimensions for this bin.

func (*BinP1D) SumW Uses

func (b *BinP1D) SumW() float64

SumW returns the sum of weights in this bin.

func (*BinP1D) SumW2 Uses

func (b *BinP1D) SumW2() float64

SumW2 returns the sum of squared weights in this bin.

func (*BinP1D) UnmarshalBinary Uses

func (o *BinP1D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*BinP1D) XEdges Uses

func (b *BinP1D) XEdges() Range

XEdges returns the [low,high] edges of this bin.

func (*BinP1D) XFocus Uses

func (b *BinP1D) XFocus() float64

XFocus returns the mean position in the bin, or the midpoint (if the sum of weights for this bin is 0).

func (*BinP1D) XMax Uses

func (b *BinP1D) XMax() float64

XMax returns the upper limit of the bin (exclusive).

func (*BinP1D) XMean Uses

func (b *BinP1D) XMean() float64

XMean returns the mean X.

func (*BinP1D) XMid Uses

func (b *BinP1D) XMid() float64

XMid returns the geometric center of the bin. i.e.: 0.5*(high+low)

func (*BinP1D) XMin Uses

func (b *BinP1D) XMin() float64

XMin returns the lower limit of the bin (inclusive).

func (*BinP1D) XRMS Uses

func (b *BinP1D) XRMS() float64

XRMS returns the RMS in X.

func (*BinP1D) XStdDev Uses

func (b *BinP1D) XStdDev() float64

XStdDev returns the standard deviation in X.

func (*BinP1D) XStdErr Uses

func (b *BinP1D) XStdErr() float64

XStdErr returns the standard error in X.

func (*BinP1D) XVariance Uses

func (b *BinP1D) XVariance() float64

XVariance returns the variance in X.

func (*BinP1D) XWidth Uses

func (b *BinP1D) XWidth() float64

XWidth returns the (signed) width of the bin

type Binning1D Uses

type Binning1D struct {
    Bins     []Bin1D
    Dist     Dist1D
    Outflows [2]Dist1D
    XRange   Range
}

Binning1D is a 1-dim binning of the x-axis.

func (*Binning1D) MarshalBinary Uses

func (o *Binning1D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Binning1D) Overflow Uses

func (bng *Binning1D) Overflow() *Dist1D

func (*Binning1D) Underflow Uses

func (bng *Binning1D) Underflow() *Dist1D

func (*Binning1D) UnmarshalBinary Uses

func (o *Binning1D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type Binning2D Uses

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 Uses

func (o *Binning2D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Binning2D) UnmarshalBinary Uses

func (o *Binning2D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type Dist0D Uses

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 Uses

func (d *Dist0D) EffEntries() float64

EffEntries returns the number of weighted entries, such as:

(\sum w)^2 / \sum w^2

func (*Dist0D) Entries Uses

func (d *Dist0D) Entries() int64

Entries returns the number of entries in the distribution.

func (*Dist0D) MarshalBinary Uses

func (o *Dist0D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Dist0D) Rank Uses

func (*Dist0D) Rank() int

Rank returns the number of dimensions of the distribution.

func (*Dist0D) UnmarshalBinary Uses

func (o *Dist0D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type Dist1D Uses

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 Uses

func (d *Dist1D) EffEntries() float64

EffEntries returns the effective number of entries in the distribution.

func (*Dist1D) Entries Uses

func (d *Dist1D) Entries() int64

Entries returns the number of entries in the distribution.

func (*Dist1D) MarshalBinary Uses

func (o *Dist1D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Dist1D) Rank Uses

func (*Dist1D) Rank() int

Rank returns the number of dimensions of the distribution.

func (*Dist1D) SumW Uses

func (d *Dist1D) SumW() float64

SumW returns the sum of weights of the distribution.

func (*Dist1D) SumW2 Uses

func (d *Dist1D) SumW2() float64

SumW2 returns the sum of squared weights of the distribution.

func (*Dist1D) SumWX Uses

func (d *Dist1D) SumWX() float64

SumWX returns the 1st order weighted x moment.

func (*Dist1D) SumWX2 Uses

func (d *Dist1D) SumWX2() float64

SumWX2 returns the 2nd order weighted x moment.

func (*Dist1D) UnmarshalBinary Uses

func (o *Dist1D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type Dist2D Uses

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 Uses

func (d *Dist2D) EffEntries() float64

EffEntries returns the effective number of entries in the distribution.

func (*Dist2D) Entries Uses

func (d *Dist2D) Entries() int64

Entries returns the number of entries in the distribution.

func (*Dist2D) MarshalBinary Uses

func (o *Dist2D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Dist2D) Rank Uses

func (*Dist2D) Rank() int

Rank returns the number of dimensions of the distribution.

func (*Dist2D) SumW Uses

func (d *Dist2D) SumW() float64

SumW returns the sum of weights of the distribution.

func (*Dist2D) SumW2 Uses

func (d *Dist2D) SumW2() float64

SumW2 returns the sum of squared weights of the distribution.

func (*Dist2D) SumWX Uses

func (d *Dist2D) SumWX() float64

SumWX returns the 1st order weighted x moment

func (*Dist2D) SumWX2 Uses

func (d *Dist2D) SumWX2() float64

SumWX2 returns the 2nd order weighted x moment

func (*Dist2D) SumWXY Uses

func (d *Dist2D) SumWXY() float64

SumWXY returns the 2nd-order cross-term.

func (*Dist2D) SumWY Uses

func (d *Dist2D) SumWY() float64

SumWY returns the 1st order weighted y moment

func (*Dist2D) SumWY2 Uses

func (d *Dist2D) SumWY2() float64

SumWY2 returns the 2nd order weighted y moment

func (*Dist2D) UnmarshalBinary Uses

func (o *Dist2D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type H1D Uses

type H1D struct {
    Binning Binning1D
    Ann     Annotation
}

H1D is a 1-dim histogram with weighted entries.

Code:

const npoints = 10000

// Create a normal distribution.
dist := distuv.Normal{
    Mu:    0,
    Sigma: 1,
    Src:   rand.New(rand.NewSource(0)),
}

// Draw some random values from the standard
// normal distribution.
h := hbook.NewH1D(20, -4, +4)
for i := 0; i < npoints; i++ {
    v := dist.Rand()
    h.Fill(v, 1)
}

fmt.Printf("mean:    %v\n", h.XMean())
fmt.Printf("rms:     %v\n", h.XRMS())
fmt.Printf("std-dev: %v\n", h.XStdDev())
fmt.Printf("std-err: %v\n", h.XStdErr())

Output:

mean:    0.004393321492241603
rms:     1.0051696196105504
std-dev: 1.0052102803319578
std-err: 0.010052102803319578

func NewH1D Uses

func NewH1D(n int, xmin, xmax float64) *H1D

NewH1D returns a 1-dim histogram with n bins between xmin and xmax.

func NewH1DFromBins Uses

func NewH1DFromBins(bins ...Range) *H1D

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 Uses

func NewH1DFromEdges(edges []float64) *H1D

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 (*H1D) Annotation Uses

func (h *H1D) Annotation() Annotation

Annotation returns the annotations attached to this histogram

func (*H1D) Bin Uses

func (h *H1D) Bin(x float64) *Bin1D

Bin returns the bin at coordinates (x) for this 1-dim histogram. Bin returns nil for under/over flow bins.

func (*H1D) DataRange Uses

func (h *H1D) DataRange() (xmin, xmax, ymin, ymax float64)

DataRange implements the gonum/plot.DataRanger interface

func (*H1D) EffEntries Uses

func (h *H1D) EffEntries() float64

EffEntries returns the number of effective entries in this histogram

func (*H1D) Entries Uses

func (h *H1D) Entries() int64

Entries returns the number of entries in this histogram

func (*H1D) Fill Uses

func (h *H1D) Fill(x, w float64)

Fill fills this histogram with x and weight w.

func (*H1D) Integral Uses

func (h *H1D) Integral(args ...float64) float64

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().LowerEdge(), 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 Uses

func (h *H1D) Len() int

Len returns the number of bins for this histogram

Len implements gonum/plot/plotter.Valuer

func (*H1D) MarshalBinary Uses

func (o *H1D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*H1D) MarshalYODA Uses

func (h *H1D) MarshalYODA() ([]byte, error)

MarshalYODA implements the YODAMarshaler interface.

func (*H1D) Name Uses

func (h *H1D) Name() string

Name returns the name of this histogram, if any

func (*H1D) Rank Uses

func (h *H1D) Rank() int

Rank returns the number of dimensions for this histogram

func (*H1D) RioMarshal Uses

func (h *H1D) RioMarshal(w io.Writer) error

RioMarshal implements rio.RioMarshaler

func (*H1D) RioUnmarshal Uses

func (h *H1D) RioUnmarshal(r io.Reader) error

RioUnmarshal implements rio.RioUnmarshaler

func (*H1D) RioVersion Uses

func (h *H1D) RioVersion() rio.Version

RioVersion implements rio.RioStreamer

func (*H1D) Scale Uses

func (h *H1D) Scale(factor float64)

Scale scales the content of each bin by the given factor.

func (*H1D) SumW Uses

func (h *H1D) SumW() float64

SumW returns the sum of weights in this histogram. Overflows are included in the computation.

func (*H1D) SumW2 Uses

func (h *H1D) SumW2() float64

SumW2 returns the sum of squared weights in this histogram. Overflows are included in the computation.

func (*H1D) SumWX Uses

func (h *H1D) SumWX() float64

SumWX returns the 1st order weighted x moment

func (*H1D) SumWX2 Uses

func (h *H1D) SumWX2() float64

SumWX2 returns the 2nd order weighted x moment

func (*H1D) UnmarshalBinary Uses

func (o *H1D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*H1D) UnmarshalYODA Uses

func (h *H1D) UnmarshalYODA(data []byte) error

UnmarshalYODA implements the YODAUnmarshaler interface.

func (*H1D) Value Uses

func (h *H1D) Value(i int) float64

Value returns the content of the idx-th bin.

Value implements gonum/plot/plotter.Valuer

func (*H1D) XMax Uses

func (h *H1D) XMax() float64

XMax returns the high edge of the X-axis of this histogram.

func (*H1D) XMean Uses

func (h *H1D) XMean() float64

XMean returns the mean X. Overflows are included in the computation.

func (*H1D) XMin Uses

func (h *H1D) XMin() float64

XMin returns the low edge of the X-axis of this histogram.

func (*H1D) XRMS Uses

func (h *H1D) XRMS() float64

XRMS returns the XRMS in X. Overflows are included in the computation.

func (*H1D) XStdDev Uses

func (h *H1D) XStdDev() float64

XStdDev returns the standard deviation in X. Overflows are included in the computation.

func (*H1D) XStdErr Uses

func (h *H1D) XStdErr() float64

XStdErr returns the standard error in X. Overflows are included in the computation.

func (*H1D) XVariance Uses

func (h *H1D) XVariance() float64

XVariance returns the variance in X. Overflows are included in the computation.

func (*H1D) XY Uses

func (h *H1D) XY(i int) (float64, float64)

XY returns the x,y values for the i-th bin

XY implements gonum/plot/plotter.XYer

type H2D Uses

type H2D struct {
    Binning Binning2D
    Ann     Annotation
}

H2D is a 2-dim histogram with weighted entries.

Code:

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.NewSource(1234)),
)
if !ok {
    log.Fatalf("error creating distmv.Normal")
}

v := make([]float64, 2)
// Draw some random values from the standard
// normal distribution.
for i := 0; i < npoints; i++ {
    v = dist.Rand(v)
    h.Fill(v[0], v[1], 1)
}

func NewH2D Uses

func NewH2D(nx int, xlow, xhigh float64, ny int, ylow, yhigh float64) *H2D

NewH2D creates a new 2-dim histogram.

func NewH2DFromEdges Uses

func NewH2DFromEdges(xedges []float64, yedges []float64) *H2D

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 Uses

func (h *H2D) Annotation() Annotation

Annotation returns the annotations attached to this histogram

func (*H2D) Bin Uses

func (h *H2D) Bin(x, y float64) *Bin2D

Bin returns the bin at coordinates (x,y) for this 2-dim histogram. Bin returns nil for under/over flow bins.

func (*H2D) EffEntries Uses

func (h *H2D) EffEntries() float64

EffEntries returns the number of effective entries in this histogram

func (*H2D) Entries Uses

func (h *H2D) Entries() int64

Entries returns the number of entries in this histogram

func (*H2D) Fill Uses

func (h *H2D) Fill(x, y, w float64)

Fill fills this histogram with (x,y) and weight w.

func (*H2D) GridXYZ Uses

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 Uses

func (h *H2D) Integral() float64

Integral computes the integral of the histogram.

Overflows are included in the computation.

func (*H2D) MarshalBinary Uses

func (o *H2D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*H2D) MarshalYODA Uses

func (h *H2D) MarshalYODA() ([]byte, error)

MarshalYODA implements the YODAMarshaler interface.

func (*H2D) Name Uses

func (h *H2D) Name() string

Name returns the name of this histogram, if any

func (*H2D) Rank Uses

func (h *H2D) Rank() int

Rank returns the number of dimensions for this histogram

func (*H2D) SumW Uses

func (h *H2D) SumW() float64

SumW returns the sum of weights in this histogram. Overflows are included in the computation.

func (*H2D) SumW2 Uses

func (h *H2D) SumW2() float64

SumW2 returns the sum of squared weights in this histogram. Overflows are included in the computation.

func (*H2D) SumWX Uses

func (h *H2D) SumWX() float64

SumWX returns the 1st order weighted x moment Overflows are included in the computation.

func (*H2D) SumWX2 Uses

func (h *H2D) SumWX2() float64

SumWX2 returns the 2nd order weighted x moment Overflows are included in the computation.

func (*H2D) SumWXY Uses

func (h *H2D) SumWXY() float64

SumWXY returns the 1st order weighted x*y moment Overflows are included in the computation.

func (*H2D) SumWY Uses

func (h *H2D) SumWY() float64

SumWY returns the 1st order weighted y moment Overflows are included in the computation.

func (*H2D) SumWY2 Uses

func (h *H2D) SumWY2() float64

SumWY2 returns the 2nd order weighted y moment Overflows are included in the computation.

func (*H2D) UnmarshalBinary Uses

func (o *H2D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*H2D) UnmarshalYODA Uses

func (h *H2D) UnmarshalYODA(data []byte) error

UnmarshalYODA implements the YODAUnmarshaler interface.

func (*H2D) XMax Uses

func (h *H2D) XMax() float64

XMax returns the high edge of the X-axis of this histogram.

func (*H2D) XMean Uses

func (h *H2D) XMean() float64

XMean returns the mean X. Overflows are included in the computation.

func (*H2D) XMin Uses

func (h *H2D) XMin() float64

XMin returns the low edge of the X-axis of this histogram.

func (*H2D) XRMS Uses

func (h *H2D) XRMS() float64

XRMS returns the RMS in X. Overflows are included in the computation.

func (*H2D) XStdDev Uses

func (h *H2D) XStdDev() float64

XStdDev returns the standard deviation in X. Overflows are included in the computation.

func (*H2D) XStdErr Uses

func (h *H2D) XStdErr() float64

XStdErr returns the standard error in X. Overflows are included in the computation.

func (*H2D) XVariance Uses

func (h *H2D) XVariance() float64

XVariance returns the variance in X. Overflows are included in the computation.

func (*H2D) YMax Uses

func (h *H2D) YMax() float64

YMax returns the high edge of the Y-axis of this histogram.

func (*H2D) YMean Uses

func (h *H2D) YMean() float64

YMean returns the mean Y. Overflows are included in the computation.

func (*H2D) YMin Uses

func (h *H2D) YMin() float64

YMin returns the low edge of the Y-axis of this histogram.

func (*H2D) YRMS Uses

func (h *H2D) YRMS() float64

YRMS returns the RMS in Y. Overflows are included in the computation.

func (*H2D) YStdDev Uses

func (h *H2D) YStdDev() float64

YStdDev returns the standard deviation in Y. Overflows are included in the computation.

func (*H2D) YStdErr Uses

func (h *H2D) YStdErr() float64

YStdErr returns the standard error in Y. Overflows are included in the computation.

func (*H2D) YVariance Uses

func (h *H2D) YVariance() float64

YVariance returns the variance in Y. Overflows are included in the computation.

type Histogram Uses

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 Uses

type Object interface {
    Annotation() Annotation
    Name() string
}

Object is the general handle to any hbook data analysis object.

type P1D Uses

type P1D struct {
    // contains filtered or unexported fields
}

P1D is a 1-dim profile histogram.

Code:

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.NewSource(1234)),
)
if !ok {
    log.Fatalf("error creating distmv.Normal")
}

v := make([]float64, 2)
// Draw some random values from the standard
// normal distribution.
for i := 0; i < npoints; i++ {
    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.11198383683853215
rms:     2.0240892891977125
std-dev: 2.0220003848882695
std-err: 0.06394126645984038

func NewP1D Uses

func NewP1D(n int, xmin, xmax float64) *P1D

NewP1D returns a 1-dim profile histogram with n bins between xmin and xmax.

func NewP1DFromH1D Uses

func NewP1DFromH1D(h *H1D) *P1D

NewP1DFromH1D creates a 1-dim profile histogram from a 1-dim histogram's binning.

func (*P1D) Annotation Uses

func (p *P1D) Annotation() Annotation

Annotation returns the annotations attached to this profile histogram

func (*P1D) Binning Uses

func (p *P1D) Binning() *binningP1D

Binning returns the binning of this profile histogram

func (*P1D) EffEntries Uses

func (p *P1D) EffEntries() float64

EffEntries returns the number of effective entries in this profile histogram

func (*P1D) Entries Uses

func (p *P1D) Entries() int64

Entries returns the number of entries in this profile histogram

func (*P1D) Fill Uses

func (p *P1D) Fill(x, y, w float64)

Fill fills this histogram with x,y and weight w.

func (*P1D) MarshalBinary Uses

func (o *P1D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*P1D) MarshalYODA Uses

func (p *P1D) MarshalYODA() ([]byte, error)

MarshalYODA implements the YODAMarshaler interface.

func (*P1D) Name Uses

func (p *P1D) Name() string

Name returns the name of this profile histogram, if any

func (*P1D) Rank Uses

func (p *P1D) Rank() int

Rank returns the number of dimensions for this profile histogram

func (*P1D) Scale Uses

func (p *P1D) Scale(factor float64)

Scale scales the content of each bin by the given factor.

func (*P1D) SumW Uses

func (p *P1D) SumW() float64

SumW returns the sum of weights in this profile histogram. Overflows are included in the computation.

func (*P1D) SumW2 Uses

func (p *P1D) SumW2() float64

SumW2 returns the sum of squared weights in this profile histogram. Overflows are included in the computation.

func (*P1D) UnmarshalBinary Uses

func (o *P1D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*P1D) UnmarshalYODA Uses

func (p *P1D) UnmarshalYODA(data []byte) error

UnmarshalYODA implements the YODAUnmarshaler interface.

func (*P1D) XMax Uses

func (p *P1D) XMax() float64

XMax returns the high edge of the X-axis of this profile histogram.

func (*P1D) XMean Uses

func (p *P1D) XMean() float64

XMean returns the mean X. Overflows are included in the computation.

func (*P1D) XMin Uses

func (p *P1D) XMin() float64

XMin returns the low edge of the X-axis of this profile histogram.

func (*P1D) XRMS Uses

func (p *P1D) XRMS() float64

XRMS returns the XRMS in X. Overflows are included in the computation.

func (*P1D) XStdDev Uses

func (p *P1D) XStdDev() float64

XStdDev returns the standard deviation in X. Overflows are included in the computation.

func (*P1D) XStdErr Uses

func (p *P1D) XStdErr() float64

XStdErr returns the standard error in X. Overflows are included in the computation.

func (*P1D) XVariance Uses

func (p *P1D) XVariance() float64

XVariance returns the variance in X. Overflows are included in the computation.

type Point2D Uses

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 Uses

func (o *Point2D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Point2D) ScaleX Uses

func (p *Point2D) ScaleX(f float64)

ScaleX rescales the X value by a factor f.

func (*Point2D) ScaleXY Uses

func (p *Point2D) ScaleXY(f float64)

ScaleXY rescales the X and Y values by a factor f.

func (*Point2D) ScaleY Uses

func (p *Point2D) ScaleY(f float64)

ScaleY rescales the Y value by a factor f.

func (*Point2D) UnmarshalBinary Uses

func (o *Point2D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (Point2D) XMax Uses

func (p Point2D) XMax() float64

XMax returns the X value plus positive X-error

func (Point2D) XMin Uses

func (p Point2D) XMin() float64

XMin returns the X value minus negative X-error

func (Point2D) YMax Uses

func (p Point2D) YMax() float64

YMax returns the Y value plus positive Y-error

func (Point2D) YMin Uses

func (p Point2D) YMin() float64

YMin returns the Y value minus negative Y-error

type Range Uses

type Range struct {
    Min float64
    Max float64
}

Range is a 1-dim interval [Min, Max].

func (*Range) MarshalBinary Uses

func (o *Range) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Range) UnmarshalBinary Uses

func (o *Range) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (Range) Width Uses

func (r Range) Width() float64

Width returns the size of the range.

type S2D Uses

type S2D struct {
    // contains filtered or unexported fields
}

S2D is a collection of 2-dim data points with errors.

Code:

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))

Output:

len=3
len=4
pt[3]={X:10 Y:-10 ErrX:{Min:5 Max:5} ErrY:{Min:6 Max:6}}

Code:

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))

Output:

len=3
len=4
pt[3]={X:10 Y:-10 ErrX:{Min:5 Max:5} ErrY:{Min:6 Max:6}}

Code:

h := hbook.NewH1D(20, -4, +4)
h.Fill(1, 2)
h.Fill(2, 3)
h.Fill(3, 1)
h.Fill(1, 1)
h.Fill(-2, 1)
h.Fill(-3, 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)
}

Output:

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), +0.00 +/- (+0.00, +0.00))
point=(-1.80 +/- (+0.20,+0.20), +2.50 +/- (+2.50, +2.50))
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 Uses

func DivideH1D(num, den *H1D) (*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.

func NewS2D Uses

func NewS2D(pts ...Point2D) *S2D

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 Uses

func NewS2DFrom(x, y []float64) *S2D

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 Uses

func NewS2DFromH1D(h *H1D, opts ...S2DOpts) *S2D

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 Uses

func NewS2DFromP1D(p *P1D, opts ...S2DOpts) *S2D

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 Uses

func (s *S2D) Annotation() Annotation

Annotation returns the annotations attached to the scatter. (e.g. name, title, ...)

func (*S2D) DataRange Uses

func (s *S2D) DataRange() (xmin, xmax, ymin, ymax float64)

DataRange returns the minimum and maximum x and y values, implementing the gonum/plot.DataRanger interface.

func (*S2D) Entries Uses

func (s *S2D) Entries() int64

Entries returns the number of entries of this histogram.

func (*S2D) Fill Uses

func (s *S2D) Fill(pts ...Point2D)

Fill adds new points to the scatter.

func (*S2D) Len Uses

func (s *S2D) Len() int

Len returns the number of points in the scatter.

Len implements the gonum/plot/plotter.XYer interface.

func (*S2D) MarshalBinary Uses

func (o *S2D) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler

func (*S2D) MarshalYODA Uses

func (s *S2D) MarshalYODA() ([]byte, error)

MarshalYODA implements the YODAMarshaler interface.

func (*S2D) Name Uses

func (s *S2D) Name() string

Name returns the name of this scatter

func (*S2D) Point Uses

func (s *S2D) Point(i int) Point2D

Point returns the point at index i.

Point panics if i is out of bounds.

func (*S2D) Points Uses

func (s *S2D) Points() []Point2D

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 Uses

func (*S2D) Rank() int

Rank returns the number of dimensions of this scatter.

func (*S2D) ScaleX Uses

func (s *S2D) ScaleX(f float64)

ScaleX rescales the X values by a factor f.

func (*S2D) ScaleXY Uses

func (s *S2D) ScaleXY(f float64)

ScaleXY rescales the X and Y values by a factor f.

func (*S2D) ScaleY Uses

func (s *S2D) ScaleY(f float64)

ScaleY rescales the Y values by a factor f.

func (*S2D) Sort Uses

func (s *S2D) Sort()

Sort sorts the data points by x,y and x-err,y-err.

func (*S2D) UnmarshalBinary Uses

func (o *S2D) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*S2D) UnmarshalYODA Uses

func (s *S2D) UnmarshalYODA(data []byte) error

UnmarshalYODA implements the YODAUnmarshaler interface.

func (*S2D) XError Uses

func (s *S2D) XError(i int) (float64, float64)

XError returns the two error values for X data.

XError implements the gonum/plot/plotter.XErrorer interface.

func (*S2D) XY Uses

func (s *S2D) XY(i int) (x, y float64)

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 Uses

func (s *S2D) YError(i int) (float64, float64)

YError returns the two error values for Y data.

YError implements the gonum/plot/plotter.YErrorer interface.

type S2DOpts Uses

type S2DOpts struct {
    UseFocus  bool
    UseStdDev bool
}

S2DOpts controls how S2D scatters are created from H1D and P1D.

Directories

PathSynopsis
ntupPackage ntup provides a way to create, open and iterate over n-tuple data.
ntup/ntcsvPackage ntcsv provides a convenient access to CSV files as n-tuple data.
rootcnvPackage rootcnv provides tools to convert ROOT histograms and graphs to go-hep/hbook ones.
yodacnvPackage yodacnv provides tools to read/write YODA archive files.

Package hbook imports 11 packages (graph) and is imported by 31 packages. Updated 2018-11-17. Refresh now. Tools for package owners.