-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhist.go
176 lines (141 loc) · 3.75 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
package croot
// #include "croot/croot.h"
//
// #include <stdlib.h>
// #include <string.h>
//
import "C"
import (
"reflect"
"unsafe"
)
// H1F
type H1F interface {
Object
AddBinContent(bin int, weight float64)
GetBinContent(bin int) float64
SetBinContent(bin int, value float64)
Fill(value, weight float64) int
FillN(data [][2]float64)
GetBin(bin int) float64
GetBinCenter(bin int) float64
GetBinError(bin int) float64
GetBinErrorLow(bin int) float64
GetBinErrorUp(bin int) float64
GetBinWidth(bin int) float64
GetEntries() float64
GetMean() float64
GetMeanError() float64
GetRMS() float64
GetRMSError() float64
}
func NewH1F(name, title string, nbins int, xlow, xup float64) H1F {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
c := C.CRoot_H1F_new(
cname, ctitle,
C.int32_t(nbins), C.double(xlow), C.double(xup),
)
if c == nil {
return nil
}
h := &h1FImpl{c: c}
return h
}
func NewH1FFrom(name, title string, data []float64) H1F {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
val := reflect.ValueOf(&data)
slice := (*reflect.SliceHeader)(unsafe.Pointer(val.Pointer()))
nbins := C.int32_t(len(data))
cdata := (*C.double)(unsafe.Pointer(slice.Data))
c := C.CRoot_H1F_new2(cname, ctitle, nbins, cdata)
if c == nil {
return nil
}
h := &h1FImpl{c: c}
return h
}
type h1FImpl struct {
c C.CRoot_H1F
}
// -- H1F interface impl --
func (h *h1FImpl) AddBinContent(bin int, weight float64) {
C.CRoot_H1F_AddBinContent(h.c, C.int32_t(bin), C.double(weight))
}
func (h *h1FImpl) GetBinContent(bin int) float64 {
o := C.CRoot_H1F_GetBinContent(h.c, C.int32_t(bin))
return float64(o)
}
func (h *h1FImpl) SetBinContent(bin int, value float64) {
C.CRoot_H1F_SetBinContent(h.c, C.int32_t(bin), C.double(value))
}
func (h *h1FImpl) Fill(value, weight float64) int {
o := C.CRoot_H1F_Fill(h.c, C.double(value), C.double(weight))
return int(o)
}
func (h *h1FImpl) FillN(data [][2]float64) {
x := make([]float64, len(data))
w := make([]float64, len(data))
for i := range data {
x[i] = data[i][0]
w[i] = data[i][1]
}
x_val := reflect.ValueOf(&x)
x_slice := (*reflect.SliceHeader)(unsafe.Pointer(x_val.Pointer()))
cx := (*C.double)(unsafe.Pointer(x_slice.Data))
w_val := reflect.ValueOf(&w)
w_slice := (*reflect.SliceHeader)(unsafe.Pointer(w_val.Pointer()))
cw := (*C.double)(unsafe.Pointer(w_slice.Data))
const stride = 1
C.CRoot_H1F_FillN(h.c, C.int32_t(len(data)), cx, cw, stride)
}
func (h *h1FImpl) GetBin(bin int) float64 {
o := C.CRoot_H1F_GetBin(h.c, C.int32_t(bin))
return float64(o)
}
func (h *h1FImpl) GetBinCenter(bin int) float64 {
o := C.CRoot_H1F_GetBinCenter(h.c, C.int32_t(bin))
return float64(o)
}
func (h *h1FImpl) GetBinError(bin int) float64 {
o := C.CRoot_H1F_GetBinError(h.c, C.int32_t(bin))
return float64(o)
}
func (h *h1FImpl) GetBinErrorLow(bin int) float64 {
o := C.CRoot_H1F_GetBinErrorLow(h.c, C.int32_t(bin))
return float64(o)
}
func (h *h1FImpl) GetBinErrorUp(bin int) float64 {
o := C.CRoot_H1F_GetBinErrorUp(h.c, C.int32_t(bin))
return float64(o)
}
func (h *h1FImpl) GetBinWidth(bin int) float64 {
o := C.CRoot_H1F_GetBinWidth(h.c, C.int32_t(bin))
return float64(o)
}
func (h *h1FImpl) GetEntries() float64 {
o := C.CRoot_H1F_GetEntries(h.c)
return float64(o)
}
func (h *h1FImpl) GetMean() float64 {
o := C.CRoot_H1F_GetMean(h.c)
return float64(o)
}
func (h *h1FImpl) GetMeanError() float64 {
o := C.CRoot_H1F_GetMeanError(h.c)
return float64(o)
}
func (h *h1FImpl) GetRMS() float64 {
o := C.CRoot_H1F_GetRMS(h.c)
return float64(o)
}
func (h *h1FImpl) GetRMSError() float64 {
o := C.CRoot_H1F_GetRMSError(h.c)
return float64(o)
}
// EOF