Skip to content

Commit 484ccb8

Browse files
yu22malYury MalyshkinHaarigerHarald
authored
Basic support for optical physics: Cherenkov light emission and photon transport in homogeneous media without boundaries (#7)
* Clean commit to merge with the mother project * Format PR changes Co-authored-by: Yury Malyshkin <yum@jinr.ru> Co-authored-by: HaarigerHarald <haarigerharald@gmx.at>
1 parent 751f750 commit 484ccb8

File tree

6 files changed

+238
-1
lines changed

6 files changed

+238
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <pybind11/pybind11.h>
2+
#include <pybind11/stl.h>
3+
4+
#include <G4PhysicsFreeVector.hh>
5+
6+
#include "typecast.hh"
7+
#include "opaques.hh"
8+
9+
namespace py = pybind11;
10+
11+
class PyG4PhysicsFreeVector : public G4PhysicsFreeVector, public py::trampoline_self_life_support {
12+
public:
13+
using G4PhysicsFreeVector::G4PhysicsFreeVector;
14+
15+
void Initialise() override { PYBIND11_OVERRIDE(void, G4PhysicsFreeVector, Initialise, ); }
16+
};
17+
18+
void export_G4PhysicsFreeVector(py::module &m)
19+
{
20+
py::class_<G4PhysicsFreeVector, PyG4PhysicsFreeVector, G4PhysicsVector>(m, "G4PhysicsFreeVector")
21+
22+
.def("__copy__", [](const PyG4PhysicsFreeVector &self) { return new PyG4PhysicsFreeVector(self); })
23+
.def("__deepcopy__", [](const PyG4PhysicsFreeVector &self, py::dict) { return new PyG4PhysicsFreeVector(self); })
24+
.def("__copy__", [](const G4PhysicsFreeVector &self) { return new G4PhysicsFreeVector(self); })
25+
.def("__deepcopy__", [](const G4PhysicsFreeVector &self, py::dict) { return new G4PhysicsFreeVector(self); })
26+
.def(py::init<G4bool>(), py::arg("spline") = false)
27+
.def(py::init<G4int>(), py::arg("length"))
28+
.def(py::init<size_t, G4bool>(), py::arg("length"), py::arg("spline") = false)
29+
.def(py::init<size_t, G4double, G4double, G4bool>(), py::arg("length"), py::arg("emin"), py::arg("emax"),
30+
py::arg("spline") = false)
31+
32+
.def(py::init<const std::vector<double> &, const std::vector<double> &, G4bool>(), py::arg("energies"),
33+
py::arg("values"), py::arg("spline") = false)
34+
35+
.def(py::init<const G4double *, const G4double *, size_t, G4bool>(), py::arg("energies"), py::arg("values"),
36+
py::arg("length"), py::arg("spline") = false)
37+
38+
.def("InsertValues", &G4PhysicsFreeVector::InsertValues, py::arg("energy"), py::arg("value"))
39+
.def("PutValue", &G4PhysicsFreeVector::PutValue, py::arg("index"), py::arg("e"), py::arg("value"))
40+
.def("PutValues", &G4PhysicsFreeVector::PutValues, py::arg("index"), py::arg("energy"), py::arg("value"));
41+
}

source/global/pyG4PhysicsVector.cc

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <pybind11/pybind11.h>
2+
#include <pybind11/stl.h>
3+
4+
#include <G4PhysicsVector.hh>
5+
6+
#include <limits>
7+
8+
#include "typecast.hh"
9+
#include "opaques.hh"
10+
11+
namespace py = pybind11;
12+
13+
class PyG4PhysicsVector : public G4PhysicsVector, public py::trampoline_self_life_support {
14+
public:
15+
using G4PhysicsVector::G4PhysicsVector;
16+
17+
void Initialise() override { PYBIND11_OVERRIDE(void, G4PhysicsVector, Initialise, ); }
18+
};
19+
20+
void export_G4PhysicsVector(py::module &m)
21+
{
22+
py::class_<G4PhysicsVector, PyG4PhysicsVector>(m, "G4PhysicsVector")
23+
24+
.def(py::init<G4bool>(), py::arg("spline") = false)
25+
.def("__copy__", [](const PyG4PhysicsVector &self) { return new PyG4PhysicsVector(self); })
26+
.def("__deepcopy__", [](const PyG4PhysicsVector &self, py::dict) { return new PyG4PhysicsVector(self); })
27+
.def("__copy__", [](const G4PhysicsVector &self) { return new G4PhysicsVector(self); })
28+
.def("__deepcopy__", [](const G4PhysicsVector &self, py::dict) { return new G4PhysicsVector(self); })
29+
.def("ComputeLogVectorBin", &G4PhysicsVector::ComputeLogVectorBin, py::arg("logenergy"))
30+
.def("DumpValues", &G4PhysicsVector::DumpValues, py::arg("unitE") = 1., py::arg("unitV") = 1.)
31+
.def("Energy", &G4PhysicsVector::Energy, py::arg("index"))
32+
//.def("FillSecondDerivatives", &G4PhysicsVector::FillSecondDerivatives, py::arg("arg0") = Base, py::arg("dir1") =
33+
//0., py::arg("dir2") = 0.)
34+
35+
.def("FindBin", &G4PhysicsVector::FindBin, py::arg("energy"), py::arg("idx"))
36+
.def("FindLinearEnergy", &G4PhysicsVector::FindLinearEnergy, py::arg("rand"))
37+
.def("GetEnergy", &G4PhysicsVector::GetEnergy, py::arg("value"))
38+
.def("GetLowEdgeEnergy", &G4PhysicsVector::GetLowEdgeEnergy, py::arg("index"))
39+
.def("GetMaxEnergy", &G4PhysicsVector::GetMaxEnergy)
40+
.def("GetMaxValue", &G4PhysicsVector::GetMaxValue)
41+
.def("GetMinEnergy", &G4PhysicsVector::GetMinEnergy)
42+
.def("GetMinValue", &G4PhysicsVector::GetMinValue)
43+
.def("GetSpline", &G4PhysicsVector::GetSpline)
44+
.def("GetType", &G4PhysicsVector::GetType)
45+
.def(
46+
"GetValue",
47+
[](const G4PhysicsVector &self, const G4double energy, G4bool &isOutRange) {
48+
return std::make_tuple(self.GetValue(energy, isOutRange), isOutRange);
49+
},
50+
py::arg("energy"), py::arg("isOutRange"))
51+
52+
.def("GetVectorLength", &G4PhysicsVector::GetVectorLength)
53+
.def("LogVectorValue", &G4PhysicsVector::LogVectorValue, py::arg("energy"), py::arg("theLogEnergy"))
54+
.def("PutValue", &G4PhysicsVector::PutValue, py::arg("index"), py::arg("value"))
55+
.def("Retrieve", &G4PhysicsVector::Retrieve, py::arg("fIn"), py::arg("ascii") = false)
56+
.def("ScaleVector", &G4PhysicsVector::ScaleVector, py::arg("factorE"), py::arg("factorV"))
57+
.def("SetVerboseLevel", &G4PhysicsVector::SetVerboseLevel, py::arg("value"))
58+
.def("Store", &G4PhysicsVector::Store, py::arg("fOut"), py::arg("ascii") = false)
59+
.def(
60+
"Value",
61+
[](const G4PhysicsVector &self, const G4double energy, size_t &lastidx) {
62+
return std::make_tuple(self.Value(energy, lastidx), lastidx);
63+
},
64+
py::arg("energy"), py::arg("lastidx"))
65+
66+
.def("Value", py::overload_cast<const G4double>(&G4PhysicsVector::Value, py::const_), py::arg("energy"))
67+
.def("__call__", &G4PhysicsVector::operator(), py::arg("index"), py::is_operator())
68+
.def("__getitem__", &G4PhysicsVector::operator[], py::is_operator())
69+
.def(
70+
"__str__",
71+
[](const G4PhysicsVector &self) {
72+
std::stringstream ss;
73+
ss << std::setprecision(std::numeric_limits<G4double>::digits10 + 1) << self;
74+
return ss.str();
75+
},
76+
py::is_operator());
77+
}

source/global/pymodG4global.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ void export_G4GeometryTolerance(py::module &);
2828
void export_G4SystemOfUnits(py::module &);
2929
void export_G4PhysicalConstants(py::module &);
3030
void export_G4StatAnalysis(py::module &);
31+
void export_G4PhysicsVector(py::module &);
32+
void export_G4PhysicsFreeVector(py::module &);
3133

3234
void export_modG4global(py::module &m)
3335
{
@@ -52,5 +54,7 @@ void export_modG4global(py::module &m)
5254
export_G4SystemOfUnits(m);
5355
export_G4PhysicalConstants(m);
5456
export_G4StatAnalysis(m);
57+
export_G4PhysicsVector(m);
58+
export_G4PhysicsFreeVector(m);
5559
export_globals(m);
5660
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include <pybind11/pybind11.h>
2+
#include <pybind11/stl.h>
3+
#include "pybind11/stl_bind.h"
4+
5+
#include <G4MaterialPropertiesTable.hh>
6+
7+
#include "typecast.hh"
8+
#include "opaques.hh"
9+
10+
namespace py = pybind11;
11+
12+
void export_G4MaterialPropertiesTable(py::module &m)
13+
{
14+
py::class_<G4MaterialPropertiesTable, py::nodelete>(m, "G4MaterialPropertiesTable",
15+
"material properties table class")
16+
17+
.def(py::init<>())
18+
19+
.def("AddConstProperty",
20+
py::overload_cast<const G4String &, G4double, G4bool>(&G4MaterialPropertiesTable::AddConstProperty),
21+
py::arg("key"), py::arg("propertyValue"), py::arg("createNewKey") = false)
22+
23+
.def("AddConstProperty",
24+
py::overload_cast<const char *, G4double, G4bool>(&G4MaterialPropertiesTable::AddConstProperty),
25+
py::arg("key"), py::arg("propertyValue"), py::arg("createNewKey") = false)
26+
27+
.def("AddEntry", py::overload_cast<const G4String &, G4double, G4double>(&G4MaterialPropertiesTable::AddEntry),
28+
py::arg("key"), py::arg("aPhotonEnergy"), py::arg("aPropertyValue"))
29+
30+
.def("AddEntry", py::overload_cast<const char *, G4double, G4double>(&G4MaterialPropertiesTable::AddEntry),
31+
py::arg("key"), py::arg("aPhotonEnergy"), py::arg("aPropertyValue"))
32+
33+
.def(
34+
"AddProperty",
35+
py::overload_cast<const G4String &, const std::vector<double> &, const std::vector<double> &, G4bool, G4bool>(
36+
&G4MaterialPropertiesTable::AddProperty),
37+
py::arg("key"), py::arg("photonEnergies"), py::arg("propertyValues"), py::arg("createNewKey") = false,
38+
py::arg("spline") = false, py::return_value_policy::reference)
39+
40+
.def(
41+
"AddProperty",
42+
[](G4MaterialPropertiesTable &self, const char *key, G4double *photonEnergies, G4double *propertyValues,
43+
G4int numEntries, G4bool createNewKey, G4bool spline) {
44+
return std::make_tuple(
45+
self.AddProperty(key, photonEnergies, propertyValues, numEntries, createNewKey, spline), photonEnergies,
46+
propertyValues);
47+
},
48+
py::arg("key"), py::arg("photonEnergies"), py::arg("propertyValues"), py::arg("numEntries"),
49+
py::arg("createNewKey") = false, py::arg("spline") = false, py::return_value_policy::automatic_reference)
50+
51+
.def("AddProperty",
52+
py::overload_cast<const G4String &, G4MaterialPropertyVector *, G4bool>(
53+
&G4MaterialPropertiesTable::AddProperty),
54+
py::arg("key"), py::arg("opv"), py::arg("createNewKey") = false)
55+
56+
.def("AddProperty",
57+
py::overload_cast<const char *, G4MaterialPropertyVector *, G4bool>(&G4MaterialPropertiesTable::AddProperty),
58+
py::arg("key"), py::arg("opv"), py::arg("createNewKey") = false)
59+
60+
.def("AddProperty",
61+
py::overload_cast<const G4String &, const G4String &>(&G4MaterialPropertiesTable::AddProperty),
62+
py::arg("key"), py::arg("mat"))
63+
64+
.def("ConstPropertyExists",
65+
py::overload_cast<const G4String &>(&G4MaterialPropertiesTable::ConstPropertyExists, py::const_),
66+
py::arg("key"))
67+
68+
.def("ConstPropertyExists",
69+
py::overload_cast<const char *>(&G4MaterialPropertiesTable::ConstPropertyExists, py::const_), py::arg("key"))
70+
71+
.def("ConstPropertyExists",
72+
py::overload_cast<const G4int>(&G4MaterialPropertiesTable::ConstPropertyExists, py::const_),
73+
py::arg("index"))
74+
75+
.def("DumpTable", &G4MaterialPropertiesTable::DumpTable)
76+
.def("GetConstProperties", &G4MaterialPropertiesTable::GetConstProperties)
77+
.def("GetConstProperty",
78+
py::overload_cast<const G4String &>(&G4MaterialPropertiesTable::GetConstProperty, py::const_),
79+
py::arg("key"))
80+
81+
.def("GetConstProperty",
82+
py::overload_cast<const char *>(&G4MaterialPropertiesTable::GetConstProperty, py::const_), py::arg("key"))
83+
84+
.def("GetConstProperty", py::overload_cast<const G4int>(&G4MaterialPropertiesTable::GetConstProperty, py::const_),
85+
py::arg("index"))
86+
87+
.def("GetConstPropertyIndex", &G4MaterialPropertiesTable::GetConstPropertyIndex, py::arg("key"))
88+
.def("GetMaterialConstPropertyNames", &G4MaterialPropertiesTable::GetMaterialConstPropertyNames)
89+
.def("GetMaterialPropertyNames", &G4MaterialPropertiesTable::GetMaterialPropertyNames)
90+
.def("GetProperties", &G4MaterialPropertiesTable::GetProperties)
91+
.def("GetProperty", py::overload_cast<const char *>(&G4MaterialPropertiesTable::GetProperty, py::const_),
92+
py::arg("key"), py::return_value_policy::reference)
93+
94+
.def("GetProperty", py::overload_cast<const G4String &>(&G4MaterialPropertiesTable::GetProperty, py::const_),
95+
py::arg("key"), py::return_value_policy::reference)
96+
97+
.def("GetProperty", py::overload_cast<const G4int>(&G4MaterialPropertiesTable::GetProperty, py::const_),
98+
py::arg("index"), py::return_value_policy::reference)
99+
100+
.def("GetPropertyIndex", &G4MaterialPropertiesTable::GetPropertyIndex, py::arg("key"))
101+
.def("RemoveConstProperty", py::overload_cast<const G4String &>(&G4MaterialPropertiesTable::RemoveConstProperty),
102+
py::arg("key"))
103+
104+
.def("RemoveConstProperty", py::overload_cast<const char *>(&G4MaterialPropertiesTable::RemoveConstProperty),
105+
py::arg("key"))
106+
107+
.def("RemoveProperty", py::overload_cast<const G4String &>(&G4MaterialPropertiesTable::RemoveProperty),
108+
py::arg("key"))
109+
110+
.def("RemoveProperty", py::overload_cast<const char *>(&G4MaterialPropertiesTable::RemoveProperty),
111+
py::arg("key"));
112+
}

source/materials/pymodG4materials.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ void export_G4ElementTable(py::module &);
1313
void export_G4Isotope(py::module &);
1414
void export_G4NistManager(py::module &);
1515
void export_G4AtomicShells(py::module &);
16+
void export_G4MaterialPropertiesTable(py::module &);
1617

1718
void export_modG4materials(py::module &m)
1819
{
@@ -23,4 +24,5 @@ void export_modG4materials(py::module &m)
2324
export_G4Isotope(m);
2425
export_G4NistManager(m);
2526
export_G4AtomicShells(m);
27+
export_G4MaterialPropertiesTable(m);
2628
}

source/track/pyG4Track.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ void export_G4Track(py::module &m)
4444
.def("GetLogicalVolumeAtVertex", &G4Track::GetLogicalVolumeAtVertex, py::return_value_policy::reference)
4545
.def("GetCreatorProcess", &G4Track::GetCreatorProcess, py::return_value_policy::reference)
4646
.def("GetWeight", &G4Track::GetWeight)
47-
.def("SetWeight", &G4Track::SetWeight);
47+
.def("SetWeight", &G4Track::SetWeight)
48+
.def("GetDefinition", &G4Track::GetDefinition, py::return_value_policy::reference);
4849
}

0 commit comments

Comments
 (0)