Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add binding for G4MultiSensitiveDetector #28

Merged
merged 2 commits into from
Dec 8, 2024
Merged
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
63 changes: 63 additions & 0 deletions source/digits_hits/pyG4MultiSensitiveDetector.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <G4MultiSensitiveDetector.hh>

#include "typecast.hh"
#include "opaques.hh"

namespace py = pybind11;

class PublicG4MultiSensitiveDetector : public G4MultiSensitiveDetector {
public:
using G4MultiSensitiveDetector::ProcessHits;
};

// Trampolin class
class PyG4MultiSensitiveDetector : public G4MultiSensitiveDetector, public py::trampoline_self_life_support {
public:
using G4MultiSensitiveDetector::G4MultiSensitiveDetector;

void Initialize(G4HCofThisEvent *hCofThisEvent) override
{
PYBIND11_OVERRIDE(void, G4MultiSensitiveDetector, Initialize, hCofThisEvent);
}

void EndOfEvent(G4HCofThisEvent *hCofThisEvent) override
{
PYBIND11_OVERRIDE(void, G4MultiSensitiveDetector, EndOfEvent, hCofThisEvent);
}

void clear() override { PYBIND11_OVERRIDE(void, G4MultiSensitiveDetector, clear, ); }

void DrawAll() override { PYBIND11_OVERRIDE(void, G4MultiSensitiveDetector, DrawAll, ); }

void PrintAll() override { PYBIND11_OVERRIDE(void, G4MultiSensitiveDetector, PrintAll, ); }

G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) override
{
PYBIND11_OVERRIDE(G4bool, G4MultiSensitiveDetector, ProcessHits, aStep, ROhist);
}
};

void export_G4MultiSensitiveDetector(py::module &m)
{
py::class_<G4MultiSensitiveDetector, PyG4MultiSensitiveDetector, G4VSensitiveDetector>(m, "G4MultiSensitiveDetector")

.def(py::init<G4String>())

.def("Initialize", &G4MultiSensitiveDetector::Initialize)
.def("EndOfEvent", &G4MultiSensitiveDetector::EndOfEvent)
.def("clear", &G4MultiSensitiveDetector::clear)
.def("DrawAll", &G4MultiSensitiveDetector::DrawAll)
.def("PrintAll", &G4MultiSensitiveDetector::PrintAll)
.def("ProcessHits", &PublicG4MultiSensitiveDetector::ProcessHits)
.def("GetSD", &G4MultiSensitiveDetector::GetSD, py::arg("i"), py::return_value_policy::reference)
.def("GetSize", &G4MultiSensitiveDetector::GetSize)
.def("ClearSDs", &G4MultiSensitiveDetector::ClearSDs)
.def("AddSD", &G4MultiSensitiveDetector::AddSD, py::arg("sd"))
.def("Clone", &G4MultiSensitiveDetector::Clone)
.def(
"__iter__", [](G4MultiSensitiveDetector &self) { return py::make_iterator(self.GetBegin(), self.GetEnd()); },
py::keep_alive<0, 1>(), py::is_operator(), py::return_value_policy::reference);
}
2 changes: 2 additions & 0 deletions source/digits_hits/pymodG4digits_hits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void export_G4SDManager(py::module &);
void export_G4VHitsCollection(py::module &);
void export_G4HCofThisEvent(py::module &);
void export_G4MultiFunctionalDetector(py::module &);
void export_G4MultiSensitiveDetector(py::module &);
void export_G4VSDFilter(py::module &);
void export_G4SDFilter(py::module &);
void export_G4VPrimitiveScorer(py::module &);
Expand All @@ -26,6 +27,7 @@ void export_modG4digit_hits(py::module &m)
export_G4VHitsCollection(m);
export_G4HCofThisEvent(m);
export_G4MultiFunctionalDetector(m);
export_G4MultiSensitiveDetector(m);
export_G4VSDFilter(m);
export_G4SDFilter(m);
export_G4VPrimitiveScorer(m);
Expand Down
Loading