Skip to content

Commit dc718ad

Browse files
authored
fix: Proper Awkward Array typing (real vs integer) (#326)
* fix: use proper integer type for awkward where it is not a real, also eliminate slow loops * trigger ci * keep same weights if
1 parent d0503a0 commit dc718ad

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/pylhe/awkward.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ def to_awkward(event_iterable: Iterable[LHEEvent]) -> ak.Array:
3636
with builder.record(name="Event"):
3737
builder.field("eventinfo")
3838
with builder.record(name="EventInfo"):
39-
for fname in event.eventinfo.fieldnames:
40-
builder.field(fname).real(getattr(event.eventinfo, fname))
39+
ei = event.eventinfo
40+
builder.field("nparticles").integer(ei.nparticles)
41+
builder.field("pid").integer(ei.pid)
42+
builder.field("weight").real(ei.weight)
43+
builder.field("scale").real(ei.scale)
44+
builder.field("aqed").real(ei.aqed)
45+
builder.field("aqcd").real(ei.aqcd)
4146
if event.weights != {}:
4247
builder.field("weights")
4348
with builder.record(name="Weights"):
@@ -49,12 +54,20 @@ def to_awkward(event_iterable: Iterable[LHEEvent]) -> ak.Array:
4954
with builder.record(name="Particle"):
5055
builder.field("vector")
5156
with builder.record(name="Momentum4D"):
52-
for fname in ["px", "py", "pz", "e"]:
53-
builder.field(fname).real(getattr(particle, fname))
54-
for fname in particle.fieldnames:
55-
if fname not in ["px", "py", "pz", "e"]:
56-
builder.field(fname).real(getattr(particle, fname))
57-
return builder.snapshot() # awkward array
57+
builder.field("px").real(particle.px)
58+
builder.field("py").real(particle.py)
59+
builder.field("pz").real(particle.pz)
60+
builder.field("e").real(particle.e)
61+
builder.field("id").integer(particle.id)
62+
builder.field("status").integer(particle.status)
63+
builder.field("mother1").integer(particle.mother1)
64+
builder.field("mother2").integer(particle.mother2)
65+
builder.field("color1").integer(particle.color1)
66+
builder.field("color2").integer(particle.color2)
67+
builder.field("m").real(particle.m)
68+
builder.field("lifetime").real(particle.lifetime)
69+
builder.field("spin").real(particle.spin)
70+
return builder.snapshot() # build the final awkward array
5871

5972

6073
# Used to register Awkward behaviors

0 commit comments

Comments
 (0)