/
recparticle.go
199 lines (172 loc) · 4.73 KB
/
recparticle.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
// 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 lcio
import (
"fmt"
"strings"
"go-hep.org/x/hep/sio"
)
// RecParticleContainer is a collection of RecParticles.
type RecParticleContainer struct {
Flags Flags
Params Params
Parts []RecParticle
}
type RecParticle struct {
Type int32
P [3]float32 // momentum (Px,PyPz)
Energy float32 // energy of particle
Cov [10]float32 // covariance matrix for 4-vector (Px,Py,Pz,E)
Mass float32 // mass of object used for 4-vector
Charge float32 // charge of particle
Ref [3]float32 // reference point of 4-vector
PIDs []ParticleID
PIDUsed *ParticleID
GoodnessOfPID float32 // overall quality of the particle identification
Recs []*RecParticle
Tracks []*Track
Clusters []*Cluster
StartVtx *Vertex // start vertex associated to the particle
}
type ParticleID struct {
Likelihood float32
Type int32
PDG int32
AlgType int32
Params []float32
}
func (recs *RecParticleContainer) String() string {
o := new(strings.Builder)
fmt.Fprintf(o, "%[1]s print out of ReconstructedParticle collection %[1]s\n\n", strings.Repeat("-", 15))
fmt.Fprintf(o, " flag: 0x%x\n%v", recs.Flags, recs.Params)
fmt.Fprintf(o, "\n")
const (
head = " [ id ] |com|type| momentum( px,py,pz) | energy | mass | charge | position ( x,y,z) | pidUsed |GoodnessOfPID|\n"
tail = "------------|---|----|-------------------------------|--------|--------|---------|-------------------------------|---------|-------------|\n"
)
o.WriteString(head)
o.WriteString(tail)
for i := range recs.Parts {
rec := &recs.Parts[i]
compound := 0
if len(rec.Recs) > 0 {
compound = 1
}
fmt.Fprintf(o,
"[%09d] |%3d|%4d|%+.2e, %+.2e, %+.2e|%.2e|%.2e|%+.2e|%+.2e, %+.2e, %+.2e|%09d|%+.2e| \n",
ID(rec),
compound, rec.Type,
rec.P[0], rec.P[1], rec.P[2], rec.Energy, rec.Mass, rec.Charge,
rec.Ref[0], rec.Ref[1], rec.Ref[2],
ID(rec.PIDUsed),
rec.GoodnessOfPID,
)
}
return o.String()
}
func (*RecParticleContainer) VersionSio() uint32 {
return Version
}
func (recs *RecParticleContainer) MarshalSio(w sio.Writer) error {
enc := sio.NewEncoder(w)
enc.Encode(&recs.Flags)
enc.Encode(&recs.Params)
enc.Encode(int32(len(recs.Parts)))
for i := range recs.Parts {
rec := &recs.Parts[i]
enc.Encode(&rec.Type)
enc.Encode(&rec.P)
enc.Encode(&rec.Energy)
enc.Encode(&rec.Cov)
enc.Encode(&rec.Mass)
enc.Encode(&rec.Charge)
enc.Encode(&rec.Ref)
enc.Encode(int32(len(rec.PIDs)))
for i := range rec.PIDs {
pid := &rec.PIDs[i]
enc.Encode(&pid.Likelihood)
enc.Encode(&pid.Type)
enc.Encode(&pid.PDG)
enc.Encode(&pid.AlgType)
enc.Encode(&pid.Params)
enc.Tag(pid)
}
enc.Pointer(&rec.PIDUsed)
enc.Encode(&rec.GoodnessOfPID)
enc.Encode(int32(len(rec.Recs)))
for i := range rec.Recs {
enc.Pointer(&rec.Recs[i])
}
enc.Encode(int32(len(rec.Tracks)))
for i := range rec.Tracks {
enc.Pointer(&rec.Tracks[i])
}
enc.Encode(int32(len(rec.Clusters)))
for i := range rec.Clusters {
enc.Pointer(&rec.Clusters[i])
}
enc.Pointer(&rec.StartVtx)
enc.Tag(rec)
}
return enc.Err()
}
func (recs *RecParticleContainer) UnmarshalSio(r sio.Reader) error {
dec := sio.NewDecoder(r)
dec.Decode(&recs.Flags)
dec.Decode(&recs.Params)
var n int32
dec.Decode(&n)
recs.Parts = make([]RecParticle, int(n))
if r.VersionSio() <= 1002 {
return fmt.Errorf("lcio: too old file (%d)", r.VersionSio())
}
for i := range recs.Parts {
rec := &recs.Parts[i]
dec.Decode(&rec.Type)
dec.Decode(&rec.P)
dec.Decode(&rec.Energy)
dec.Decode(&rec.Cov)
dec.Decode(&rec.Mass)
dec.Decode(&rec.Charge)
dec.Decode(&rec.Ref)
var n int32
dec.Decode(&n)
rec.PIDs = make([]ParticleID, int(n))
for i := range rec.PIDs {
pid := &rec.PIDs[i]
dec.Decode(&pid.Likelihood)
dec.Decode(&pid.Type)
dec.Decode(&pid.PDG)
dec.Decode(&pid.AlgType)
dec.Decode(&pid.Params)
dec.Tag(pid)
}
dec.Pointer(&rec.PIDUsed)
dec.Decode(&rec.GoodnessOfPID)
dec.Decode(&n)
rec.Recs = make([]*RecParticle, int(n))
for i := range rec.Recs {
dec.Pointer(&rec.Recs[i])
}
dec.Decode(&n)
rec.Tracks = make([]*Track, int(n))
for i := range rec.Tracks {
dec.Pointer(&rec.Tracks[i])
}
dec.Decode(&n)
rec.Clusters = make([]*Cluster, int(n))
for i := range rec.Clusters {
dec.Pointer(&rec.Clusters[i])
}
if r.VersionSio() > 1007 {
dec.Pointer(&rec.StartVtx)
}
dec.Tag(rec)
}
return dec.Err()
}
var (
_ sio.Versioner = (*RecParticleContainer)(nil)
_ sio.Codec = (*RecParticleContainer)(nil)
)