Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ PYBIND11_MODULE(_core, m) {
METH(set_units, GenEvent)
METH(event_pos, GenEvent)
PROP_RO_OL(beams, GenEvent, std::vector<ConstGenParticlePtr>)
METH(add_tree, GenEvent)
METH_OL(add_vertex, GenEvent, void, GenVertexPtr)
METH_OL(add_particle, GenEvent, void, GenParticlePtr)
METH(set_beam_particles, GenEvent)
Expand Down
70 changes: 52 additions & 18 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np


def make_evt():
def create_event_components():
r"""
In this example we will generate the following event by hand

Expand All @@ -29,12 +29,7 @@ def make_evt():
v2__p4 \
/ p6
p2

Finally, the event gets a weight.
"""
evt = hep.GenEvent(hep.Units.GEV, hep.Units.MM)
evt.event_number = 1

# px py pz e pdgid status
p1 = hep.GenParticle((0.0, 0.0, 7000.0, 7000.0), 2212, 1)
p1.generated_mass = 0.938
Expand All @@ -52,41 +47,69 @@ def make_evt():
p7.generated_mass = 0.01
p8 = hep.GenParticle((3.962, -49.498, -26.687, 56.373), -2, 8)
p8.generated_mass = 0.006
evt.add_particle(p1)
evt.add_particle(p2)
evt.add_particle(p3)
evt.add_particle(p4)
evt.add_particle(p5)
evt.add_particle(p6)
evt.add_particle(p7)
evt.add_particle(p8)

# make sure vertex is not optimized away by WriterAscii
v1 = hep.GenVertex((1.0, 1.0, 1.0, 1.0))
v1.add_particle_in(p1)
v1.add_particle_out(p3)
evt.add_vertex(v1)

# make sure vertex is not optimized away by WriterAscii
v2 = hep.GenVertex((2.0, 2.0, 2.0, 2.0))
v2.add_particle_in(p2)
v2.add_particle_out(p4)
evt.add_vertex(v2)

# make sure vertex is not optimized away by WriterAscii
v3 = hep.GenVertex((3.0, 3.0, 3.0, 3.0))
v3.add_particle_in(p3)
v3.add_particle_in(p4)
v3.add_particle_out(p5)
v3.add_particle_out(p6)
evt.add_vertex(v3)

# make sure vertex is not optimized away by WriterAscii
v4 = hep.GenVertex((4.0, 4.0, 4.0, 4.0))
v4.add_particle_in(p5)
v4.add_particle_out(p7)
v4.add_particle_out(p8)
evt.add_vertex(v4)

return [p1, p2, p3, p4, p5, p6, p7, p8], [v1, v2, v3, v4]


def make_evt():
r"""
In this example we will generate the following event by hand

name status pdg_id parent Px Py Pz Energy Mass
1 !p+! 1 2212 0,0 0.000 0.000 7000.000 7000.000 0.938
2 !He4! 2 1000020040 0,0 0.000 0.000 -7000.000 7000.000 3.756
=============================================================================
3 !d! 3 1 1,1 0.750 -1.569 32.191 32.238 0.000
4 !u~! 4 -2 2,2 -3.047 -19.000 -54.629 57.920 0.000
5 !W-! 5 -24 3,4 1.517 -20.68 -20.605 85.925 80.799
6 !gamma! 6 22 3,4 -3.813 0.113 -1.833 4.233 0.000
7 !d! 7 1 5,5 -2.445 28.816 6.082 29.552 0.010
8 !u~! 8 -2 5,5 3.962 -49.498 -26.687 56.373 0.006

The corresponding graph looks like this

p7
p1 /
\v1__p3 p5---v4
\_v3_/ \
/ \ p8
v2__p4 \
/ p6
p2

Finally, the event gets a weight.
"""
evt = hep.GenEvent(hep.Units.GEV, hep.Units.MM)
evt.event_number = 1

particles, vertices = create_event_components()
for p in particles:
evt.add_particle(p)
for v in vertices:
evt.add_vertex(v)

evt.weights = [1.0]

Expand All @@ -104,6 +127,17 @@ def evt():
return make_evt()


def test_GenEvent_add_tree():
evt1 = make_evt()
particles, _ = create_event_components()
evt2 = hep.GenEvent(hep.Units.GEV, hep.Units.MM)
evt2.add_tree(particles)
assert len(evt2.particles) == len(evt1.particles)
assert hep.equal_particle_sets(evt2.particles, evt1.particles)
assert len(evt2.vertices) == len(evt1.vertices)
assert hep.equal_vertex_sets(evt2.vertices, evt1.vertices)


def test_GenHeavyIon():
hi = hep.GenHeavyIon()
assert hi == hep.GenHeavyIon()
Expand Down