-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4987b5f
commit 5494cf6
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "pybind.hpp" | ||
#include <HepMC3/Data/GenEventData.h> | ||
#include <HepMC3/Data/GenParticleData.h> | ||
#include <HepMC3/Data/GenVertexData.h> | ||
#include <vector> | ||
|
||
struct FourPos { | ||
double x, y, z, t; | ||
}; | ||
|
||
struct VertexData { | ||
int status; | ||
FourPos position; | ||
}; | ||
|
||
struct FourMom { | ||
double px, py, pz, e; | ||
}; | ||
|
||
struct ParticleData { | ||
int pid; | ||
int status; | ||
bool is_mass_set; | ||
double mass; | ||
FourMom momentum; | ||
}; | ||
|
||
namespace HepMC3 { | ||
|
||
py::object particledata_asarray(std::vector<GenParticleData>& self) { | ||
PYBIND11_NUMPY_DTYPE(FourMom, px, py, pz, e); | ||
PYBIND11_NUMPY_DTYPE(ParticleData, pid, status, is_mass_set, mass, momentum); | ||
auto dt = py::dtype::of<ParticleData>(); | ||
ssize_t shape[1] = {static_cast<ssize_t>(self.size())}; | ||
return py::array(dt, shape, self.data()); | ||
} | ||
|
||
py::object vertexdata_asarray(std::vector<GenVertexData>& self) { | ||
PYBIND11_NUMPY_DTYPE(FourPos, x, y, z, t); | ||
PYBIND11_NUMPY_DTYPE(VertexData, status, position); | ||
auto dt = py::dtype::of<VertexData>(); | ||
ssize_t shape[1] = {static_cast<ssize_t>(self.size())}; | ||
return py::array(dt, shape, self.data()); | ||
} | ||
|
||
} // namespace HepMC3 |