1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
* MAUS is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* MAUS is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
20
#include "src/common_cpp/Simulation/GeometryNavigator.hh"
22
#include "src/common_cpp/Utils/Globals.hh"
24
#include "src/py_cpp/PyMaterial.hh"
29
std::string GetMaterialData_DocString =
30
std::string("get_material_data()\n\n")+
31
std::string("Get a python dict containing data on the material found at the")+
32
std::string("current position. The dict has the entries: \"name\", \"A\", \"Z\", ")+
33
std::string("\"radlen\", \"interlen\" and \"density\". Note that if the material ")+
34
std::string("is a mixture of elements, Z and A are not properly defined, hence t")+
35
std::string("hey are set to 0.0 by default.");
36
PyObject* GetMaterialData(PyObject *dummy, PyObject *args) {
44
if (!PyArg_ParseTuple(args, "")) {
45
PyErr_SetString(PyExc_TypeError,
46
"Unexpected get_material_data arguments");
51
GeometryNavigator* nav = Globals::GetInstance()->GetMCGeometryNavigator();
52
name = nav->GetMaterialName();
53
if (nav->IsMixture()) {
60
radlen = nav->GetRadiationLength();
61
interlen = nav->GetNuclearInteractionLength();
62
density = nav->GetDensity();
63
} catch (std::exception& exc) {
64
PyErr_SetString(PyExc_RuntimeError, (&exc)->what());
67
PyObject* py_dict = Py_BuildValue("{s:s,s:d,s:d,s:d,s:d,s:d}", "name", name.c_str(), "A", A,
68
"Z", Z, "radlen", radlen, "interlen", interlen, "density", density );
69
// PyObject* py_dict = Py_BuildValue("{s:s,s:d,s:d,s:d}", "name", name.c_str(),
70
// "radlen", radlen, "interlen", interlen, "density", density );
75
std::string SetPosition_DocString =
76
std::string("set_position(x, y, z)\n\n")+
77
std::string("Set the current position of the geometry navigator.");
78
PyObject* SetPosition(PyObject *dummy, PyObject *args) {
79
double point[] = {0.0, 0.0, 0.0};
81
if (!PyArg_ParseTuple(args, "ddd", &point[0], &point[1], &point[2])) {
82
PyErr_SetString(PyExc_TypeError,
83
"Failed to process arguments of \"set_position\" as x,y,z");
88
ThreeVector pos(point[0], point[1], point[2]);
89
GeometryNavigator* nav = Globals::GetInstance()->GetMCGeometryNavigator();
91
} catch (std::exception& exc) {
92
PyErr_SetString(PyExc_RuntimeError, (&exc)->what());
95
PyObject* none = Py_BuildValue("");
100
std::string GetPosition_DocString =
101
std::string("get_position()\n\n")+
102
std::string("Returns the current position of the geometry navigator.");
103
PyObject* GetPosition(PyObject *dummy, PyObject *args) {
104
double point[] = {0., 0., 0.};
106
if (!PyArg_ParseTuple(args, "")) {
107
PyErr_SetString(PyExc_TypeError, "Unexpected arguments for \"get_position\"");
112
GeometryNavigator* nav = Globals::GetInstance()->GetMCGeometryNavigator();
113
ThreeVector pos = nav->GetCurrentPoint();
117
} catch (std::exception& exc) {
118
PyErr_SetString(PyExc_RuntimeError, (&exc)->what());
121
PyObject* position = Py_BuildValue("ddd", point[0], point[1], point[2]);
126
std::string Step_DocString =
127
std::string("step(x, y, z)\n\n")+
128
std::string("Move the current position of the navigator by the supplied ")+
129
std::string("displacement.");
130
PyObject* Step(PyObject *dummy, PyObject *args) {
131
double point[] = {0.0, 0.0, 0.0};
133
if (!PyArg_ParseTuple(args, "ddd", &point[0], &point[1], &point[2])) {
134
PyErr_SetString(PyExc_TypeError,
135
"Failed to process arguments of \"Step\" as x,y,z");
139
ThreeVector disp(point[0], point[1], point[2]);
140
GeometryNavigator* nav = Globals::GetInstance()->GetMCGeometryNavigator();
142
} catch (std::exception& exc) {
143
PyErr_SetString(PyExc_RuntimeError, (&exc)->what());
146
PyObject* none = Py_BuildValue("");
151
static PyMethodDef methods[] = {
152
{"get_material_data", (PyCFunction)GetMaterialData,
153
METH_VARARGS, GetMaterialData_DocString.c_str()},
154
{"set_position", (PyCFunction)SetPosition,
155
METH_VARARGS, SetPosition_DocString.c_str()},
156
{"get_position", (PyCFunction)GetPosition,
157
METH_VARARGS, GetPosition_DocString.c_str()},
158
{"step", (PyCFunction)Step,
159
METH_VARARGS, Step_DocString.c_str()},
160
{NULL, NULL, 0, NULL}
164
PyMODINIT_FUNC initmaterial(void) {
166
PyObject* maus_module = Py_InitModule("material", methods);
167
if (maus_module == NULL) return;