/
bin2d.go
186 lines (151 loc) · 4.16 KB
/
bin2d.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Copyright ©2016 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package hbook
// Bin2D models a bin in a 2-dim space.
type Bin2D struct {
XRange Range
YRange Range
Dist Dist2D
}
// Rank returns the number of dimensions for this bin.
func (Bin2D) Rank() int { return 2 }
// func (b *Bin2D) scaleW(f float64) {
// b.Dist.scaleW(f)
// }
func (b *Bin2D) fill(x, y, w float64) {
b.Dist.fill(x, y, w)
}
// Entries returns the number of entries in this bin.
func (b *Bin2D) Entries() int64 {
return b.Dist.Entries()
}
// EffEntries returns the effective number of entries \f$ = (\sum w)^2 / \sum w^2 \f$
func (b *Bin2D) EffEntries() float64 {
return b.Dist.EffEntries()
}
// SumW returns the sum of weights in this bin.
func (b *Bin2D) SumW() float64 {
return b.Dist.SumW()
}
// SumW2 returns the sum of squared weights in this bin.
func (b *Bin2D) SumW2() float64 {
return b.Dist.SumW2()
}
// XEdges returns the [low,high] edges of this bin.
func (b *Bin2D) XEdges() Range {
return b.XRange
}
// YEdges returns the [low,high] edges of this bin.
func (b *Bin2D) YEdges() Range {
return b.YRange
}
// XMin returns the lower limit of the bin (inclusive).
func (b *Bin2D) XMin() float64 {
return b.XRange.Min
}
// YMin returns the lower limit of the bin (inclusive).
func (b *Bin2D) YMin() float64 {
return b.YRange.Min
}
// XMax returns the upper limit of the bin (exclusive).
func (b *Bin2D) XMax() float64 {
return b.XRange.Max
}
// YMax returns the upper limit of the bin (exclusive).
func (b *Bin2D) YMax() float64 {
return b.YRange.Max
}
// XMid returns the geometric center of the bin.
// i.e.: 0.5*(high+low)
func (b *Bin2D) XMid() float64 {
return 0.5 * (b.XRange.Min + b.XRange.Max)
}
// YMid returns the geometric center of the bin.
// i.e.: 0.5*(high+low)
func (b *Bin2D) YMid() float64 {
return 0.5 * (b.YRange.Min + b.YRange.Max)
}
// XYMid returns the (x,y) coordinates of the geometric center of the bin.
// i.e.: 0.5*(high+low)
func (b *Bin2D) XYMid() (float64, float64) {
return b.XMid(), b.YMid()
}
// XWidth returns the (signed) width of the bin
func (b *Bin2D) XWidth() float64 {
return b.XRange.Max - b.XRange.Min
}
// YWidth returns the (signed) width of the bin
func (b *Bin2D) YWidth() float64 {
return b.YRange.Max - b.YRange.Min
}
// XYWidth returns the (signed) (x,y) widths of the bin
func (b *Bin2D) XYWidth() (float64, float64) {
return b.XWidth(), b.YWidth()
}
// XFocus returns the mean position in the bin, or the midpoint (if the
// sum of weights for this bin is 0).
func (b *Bin2D) XFocus() float64 {
if b.SumW() == 0 {
return b.XMid()
}
return b.XMean()
}
// YFocus returns the mean position in the bin, or the midpoint (if the
// sum of weights for this bin is 0).
func (b *Bin2D) YFocus() float64 {
if b.SumW() == 0 {
return b.YMid()
}
return b.YMean()
}
// XYFocus returns the mean position in the bin, or the midpoint (if the
// sum of weights for this bin is 0).
func (b *Bin2D) XYFocus() (float64, float64) {
if b.SumW() == 0 {
return b.XMid(), b.YMid()
}
return b.XMean(), b.YMean()
}
// XMean returns the mean X.
func (b *Bin2D) XMean() float64 {
return b.Dist.xMean()
}
// YMean returns the mean Y.
func (b *Bin2D) YMean() float64 {
return b.Dist.yMean()
}
// XVariance returns the variance in X.
func (b *Bin2D) XVariance() float64 {
return b.Dist.xVariance()
}
// YVariance returns the variance in Y.
func (b *Bin2D) YVariance() float64 {
return b.Dist.yVariance()
}
// XStdDev returns the standard deviation in X.
func (b *Bin2D) XStdDev() float64 {
return b.Dist.xStdDev()
}
// YStdDev returns the standard deviation in Y.
func (b *Bin2D) YStdDev() float64 {
return b.Dist.yStdDev()
}
// XStdErr returns the standard error in X.
func (b *Bin2D) XStdErr() float64 {
return b.Dist.xStdErr()
}
// YStdErr returns the standard error in Y.
func (b *Bin2D) YStdErr() float64 {
return b.Dist.yStdErr()
}
// XRMS returns the RMS in X.
func (b *Bin2D) XRMS() float64 {
return b.Dist.xRMS()
}
// YRMS returns the RMS in Y.
func (b *Bin2D) YRMS() float64 {
return b.Dist.yRMS()
}
// check Bin2D implements interfaces
var _ Bin = (*Bin2D)(nil)