-
Notifications
You must be signed in to change notification settings - Fork 35
/
axis.go
151 lines (129 loc) · 2.97 KB
/
axis.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
// 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 (
"fmt"
"reflect"
)
type taxis struct {
rvers int16
tnamed
attaxis attaxis
nbins int // number of bins
xmin float64 // low edge of first bin
xmax float64 // upper edge of last bin
xbins ArrayD // bin edges array in X
first int // first bin to display
last int // last bin to display
bits2 uint16 // second bit status word
time bool // on/off displaying time values instead of numerics
tfmt string // date&time format
labels *thashList // list of labels
modlabs *tlist // list of modified labels
}
func (a *taxis) Class() string {
return "TAxis"
}
func (a *taxis) XMin() float64 {
return a.xmin
}
func (a *taxis) XMax() float64 {
return a.xmax
}
func (a *taxis) NBins() int {
return a.nbins
}
func (a *taxis) XBins() []float64 {
return a.xbins.Data
}
func (a *taxis) BinCenter(i int) float64 {
if len(a.xbins.Data) == 0 || i < 1 || i > a.nbins {
width := (a.xmax - a.xmin) / float64(a.nbins)
return a.xmin + (float64(i)-0.5)*width
}
width := a.xbins.Data[i] - a.xbins.Data[i-1]
return a.xbins.Data[i-1] + 0.5*width
}
func (a *taxis) BinLowEdge(i int) float64 {
if len(a.xbins.Data) == 0 || i < 1 || i > a.nbins {
width := (a.xmax - a.xmin) / float64(a.nbins)
return a.xmin + float64(i-1)*width
}
return a.xbins.Data[i-1]
}
func (a *taxis) BinWidth(i int) float64 {
if a.nbins <= 0 {
return 0
}
if len(a.xbins.Data) <= 0 {
return (a.xmax - a.xmin) / float64(a.nbins)
}
if i > a.nbins {
i = a.nbins
}
if i < 1 {
i = 1
}
return a.xbins.Data[i] - a.xbins.Data[i-1]
}
func (a *taxis) UnmarshalROOT(r *RBuffer) error {
if r.err != nil {
return r.err
}
beg := r.Pos()
vers, pos, bcnt := r.ReadVersion()
a.rvers = vers
if vers < 9 {
return fmt.Errorf("rootio: TAxis version too old (%d<9)", vers)
}
for _, v := range []ROOTUnmarshaler{
&a.tnamed,
&a.attaxis,
} {
if err := v.UnmarshalROOT(r); err != nil {
r.err = err
return r.err
}
}
a.nbins = int(r.ReadI32())
a.xmin = r.ReadF64()
a.xmax = r.ReadF64()
if err := a.xbins.UnmarshalROOT(r); err != nil {
r.err = err
return r.err
}
a.first = int(r.ReadI32())
a.last = int(r.ReadI32())
a.bits2 = r.ReadU16()
a.time = r.ReadBool()
a.tfmt = r.ReadString()
a.labels = nil
labels := r.ReadObjectAny()
if labels != nil {
a.labels = labels.(*thashList)
}
a.modlabs = nil
if vers >= 10 {
modlabs := r.ReadObjectAny()
if modlabs != nil {
a.modlabs = modlabs.(*tlist)
}
}
r.CheckByteCount(pos, bcnt, beg, "TAxis")
return r.err
}
func init() {
{
f := func() reflect.Value {
o := &taxis{}
return reflect.ValueOf(o)
}
Factory.add("TAxis", f)
Factory.add("*rootio.taxis", f)
}
}
var _ Object = (*taxis)(nil)
var _ Named = (*taxis)(nil)
var _ Axis = (*taxis)(nil)
var _ ROOTUnmarshaler = (*taxis)(nil)