-
Notifications
You must be signed in to change notification settings - Fork 35
/
hist.go
304 lines (257 loc) · 6.07 KB
/
hist.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// Copyright 2017 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 rootio
import (
"reflect"
)
type th1 struct {
tnamed
attline attline
attfill attfill
attmarker attmarker
ncells int // number of bins + under/over-flows
xaxis taxis // x axis descriptor
yaxis taxis // y axis descriptor
zaxis taxis // z axis descriptor
boffset int16 // (1000*offset) for bar charts or legos
bwidth int16 // (1000*width) for bar charts or legos
entries float64 // number of entries
tsumw float64 // total sum of weights
tsumw2 float64 // total sum of squares of weights
tsumwx float64 // total sum of weight*x
tsumwx2 float64 // total sum of weight*x*x
max float64 // maximum value for plotting
min float64 // minimum value for plotting
norm float64 // normalization factor
contour ArrayD // array to display contour levels
sumw2 ArrayD // array of sum of squares of weights
opt string // histogram options
funcs tlist // list of functions (fits and user)
buffer []float64 // entry buffer
erropt int32 // option for bin statistical errors
}
func (h *th1) Class() string {
return "TH1"
}
// Entries returns the number of entries for this histogram.
func (h *th1) Entries() float64 {
return h.entries
}
// SumW returns the total sum of weights
func (h *th1) SumW() float64 {
return h.tsumw
}
// SumW2 returns the total sum of squares of weights
func (h *th1) SumW2() float64 {
return h.tsumw2
}
// SumWX returns the total sum of weights*x
func (h *th1) SumWX() float64 {
return h.tsumwx
}
// SumWX2 returns the total sum of weights*x*x
func (h *th1) SumWX2() float64 {
return h.tsumwx2
}
// SumW2s returns the array of sum of squares of weights
func (h *th1) SumW2s() []float64 {
return h.sumw2.Data
}
func (h *th1) UnmarshalROOT(r *RBuffer) error {
if r.err != nil {
return r.err
}
beg := r.Pos()
vers, pos, bcnt := r.ReadVersion()
for _, v := range []ROOTUnmarshaler{
&h.tnamed,
&h.attline,
&h.attfill,
&h.attmarker,
} {
if err := v.UnmarshalROOT(r); err != nil {
r.err = err
return r.err
}
}
var i32 int32
r.ReadI32(&i32)
h.ncells = int(i32)
for _, v := range []ROOTUnmarshaler{
&h.xaxis,
&h.yaxis,
&h.zaxis,
} {
if err := v.UnmarshalROOT(r); err != nil {
r.err = err
return r.err
}
}
r.ReadI16(&h.boffset)
r.ReadI16(&h.bwidth)
r.ReadF64(&h.entries)
r.ReadF64(&h.tsumw)
r.ReadF64(&h.tsumw2)
r.ReadF64(&h.tsumwx)
r.ReadF64(&h.tsumwx2)
if vers < 2 {
var f32 float32
r.ReadF32(&f32)
h.max = float64(f32)
r.ReadF32(&f32)
h.min = float64(f32)
r.ReadF32(&f32)
h.norm = float64(f32)
r.ReadI32(&i32)
h.contour.Data = make([]float64, i32)
r.ReadFastArrayF64(h.contour.Data)
} else {
r.ReadF64(&h.max)
r.ReadF64(&h.min)
r.ReadF64(&h.norm)
if err := h.contour.UnmarshalROOT(r); err != nil {
r.err = err
return r.err
}
}
if err := h.sumw2.UnmarshalROOT(r); err != nil {
r.err = err
return r.err
}
r.ReadString(&h.opt)
if err := h.funcs.UnmarshalROOT(r); err != nil {
r.err = err
return r.err
}
r.ReadI32(&i32)
h.buffer = make([]float64, i32)
var i8 int8
r.ReadI8(&i8)
r.ReadFastArrayF64(h.buffer)
r.ReadI32(&h.erropt)
r.CheckByteCount(pos, bcnt, beg, "TH1")
return r.err
}
type th2 struct {
th1
scale float64 // scale factor
tsumwy float64 // total sum of weight*y
tsumwy2 float64 // total sum of weight*y*y
tsumwxy float64 // total sum of weight*x*y
}
func (*th2) Class() string {
return "TH2"
}
func (h *th2) UnmarshalROOT(r *RBuffer) error {
if r.err != nil {
return r.err
}
beg := r.Pos()
vers, pos, bcnt := r.ReadVersion()
if vers < 3 {
return errorf("rootio: TH2 version too old (%d<3)", vers)
}
if err := h.th1.UnmarshalROOT(r); err != nil {
r.err = err
return r.err
}
r.ReadF64(&h.scale)
r.ReadF64(&h.tsumwy)
r.ReadF64(&h.tsumwy2)
r.ReadF64(&h.tsumwxy)
r.CheckByteCount(pos, bcnt, beg, "TH2")
return r.err
}
// SumWY returns the total sum of weights*y
func (h *th2) SumWY() float64 {
return h.tsumwy
}
// SumWY2 returns the total sum of weights*y*y
func (h *th2) SumWY2() float64 {
return h.tsumwy2
}
// SumWXY returns the total sum of weights*x*y
func (h *th2) SumWXY() float64 {
return h.tsumwxy
}
type dist0D struct {
n int64
sumw float64
sumw2 float64
sumwx float64
sumwx2 float64
}
func (d dist0D) Entries() int64 {
return d.n
}
func (d dist0D) SumW() float64 {
return d.sumw
}
func (d dist0D) SumW2() float64 {
return d.sumw2
}
func (d dist0D) SumWX() float64 {
return d.sumwx
}
func (d dist0D) SumWX2() float64 {
return d.sumwx2
}
// dist2D is a 2-dim distribution.
type dist2D struct {
x dist0D // x moments
y dist0D // y moments
sumWXY float64 // 2nd-order cross-term
}
// Entries returns the number of entries in the distribution.
func (d *dist2D) Entries() int64 {
return d.x.Entries()
}
// SumW returns the sum of weights of the distribution.
func (d *dist2D) SumW() float64 {
return d.x.SumW()
}
// SumW2 returns the sum of squared weights of the distribution.
func (d *dist2D) SumW2() float64 {
return d.x.SumW2()
}
// SumWX returns the 1st order weighted x moment
func (d *dist2D) SumWX() float64 {
return d.x.SumWX()
}
// SumWX2 returns the 2nd order weighted x moment
func (d *dist2D) SumWX2() float64 {
return d.x.SumWX2()
}
// SumWY returns the 1st order weighted y moment
func (d *dist2D) SumWY() float64 {
return d.y.SumWX()
}
// SumWY2 returns the 2nd order weighted y moment
func (d *dist2D) SumWY2() float64 {
return d.y.SumWX2()
}
func init() {
{
f := func() reflect.Value {
o := &th1{}
return reflect.ValueOf(o)
}
Factory.add("TH1", f)
Factory.add("*rootio.th1", f)
}
{
f := func() reflect.Value {
o := &th2{}
return reflect.ValueOf(o)
}
Factory.add("TH2", f)
Factory.add("*rootio.th2", f)
}
}
var _ Object = (*th1)(nil)
var _ Named = (*th1)(nil)
var _ ROOTUnmarshaler = (*th1)(nil)
var _ Object = (*th2)(nil)
var _ Named = (*th2)(nil)
var _ ROOTUnmarshaler = (*th2)(nil)