Skip to content
Snippets Groups Projects
Commit 1c484b75 authored by Dmitry Kalinkin's avatar Dmitry Kalinkin
Browse files

ecal_backwards.org: use pyHepMC3 SWIG bindings that support ROOT formats

parent a3cc33d7
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ import dask_awkward as dak ...@@ -15,7 +15,7 @@ import dask_awkward as dak
import dask_histogram as dh import dask_histogram as dh
import numpy as np import numpy as np
import uproot import uproot
import pyhepmc from pyHepMC3 import HepMC3
#+end_src #+end_src
#+begin_src jupyter-python :results silent #+begin_src jupyter-python :results silent
...@@ -66,47 +66,47 @@ output_dir.mkdir(parents=True, exist_ok=True) ...@@ -66,47 +66,47 @@ output_dir.mkdir(parents=True, exist_ok=True)
#+begin_src jupyter-python :results silent #+begin_src jupyter-python :results silent
builder = ak.ArrayBuilder() builder = ak.ArrayBuilder()
n = 0 n = 0
with pyhepmc.open(PROTON_BEAM_GAS_GEN) as f: f = HepMC3.ReaderPlugin(PROTON_BEAM_GAS_GEN, "libHepMC3rootIO.so", "newReaderRootTreefile")
it = iter(f) event = HepMC3.GenEvent()
for event in f: while f.read_event(event):
builder.begin_list() builder.begin_list()
for vertex in event.vertices: assert event.length_unit().name == "MM"
assert event.length_unit.name == "MM" for vertex in event.vertices():
with builder.record("Vector4D"): with builder.record("Vector4D"):
builder.field("x") builder.field("x")
builder.real(vertex.position.x) builder.real(vertex.position().x())
builder.field("y") builder.field("y")
builder.real(vertex.position.y) builder.real(vertex.position().y())
builder.field("z") builder.field("z")
builder.real(vertex.position.z) builder.real(vertex.position().z())
builder.field("t") builder.field("t")
builder.real(vertex.position.t) builder.real(vertex.position().t())
builder.end_list() builder.end_list()
n += 1 n += 1
if n > 10000: break if n > 10000: break
vertices_proton_beam_gas = builder.snapshot() vertices_proton_beam_gas = builder.snapshot()
builder = ak.ArrayBuilder() builder = ak.ArrayBuilder()
n = 0 n = 0
with pyhepmc.open(ELECTRON_BEAM_GAS_GEN) as f: f = HepMC3.ReaderPlugin(ELECTRON_BEAM_GAS_GEN, "libHepMC3rootIO.so", "newReaderRootTreefile")
it = iter(f) event = HepMC3.GenEvent()
for event in f: while f.read_event(event):
builder.begin_list() builder.begin_list()
for vertex in event.vertices: assert event.length_unit().name == "MM"
assert event.length_unit.name == "MM" for vertex in event.vertices():
with builder.record("Vector3D"): with builder.record("Vector4D"):
builder.field("x") builder.field("x")
builder.real(vertex.position.x) builder.real(vertex.position().x())
builder.field("y") builder.field("y")
builder.real(vertex.position.y) builder.real(vertex.position().y())
builder.field("z") builder.field("z")
builder.real(vertex.position.z) builder.real(vertex.position().z())
builder.field("t") builder.field("t")
builder.real(vertex.position.t) builder.real(vertex.position().t())
builder.end_list() builder.end_list()
n += 1 n += 1
if n > 10000: break if n > 10000: break
vertices_electron_beam_gas = builder.snapshot() vertices_electron_beam_gas = builder.snapshot()
#+end_src #+end_src
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment