OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
PyBoostField.cpp
Go to the documentation of this file.
1#include <Python.h>
2#include <structmember.h>
3
4#include <exception>
5#include <iostream>
6#include <boost/python.hpp>
7
10#include "AbsBeamline/Ring.h"
12
13//using namespace boost::python;
14
16std::string("Get the field value at a point in the field map.\n\n")+
17std::string(" x: x position [m]\n")+
18std::string(" y: y position [m]\n")+
19std::string(" z: z position [m]\n")+
20std::string(" t: time [ns]\n")+
21std::string("Returns a tuple containing 6 values:\n")+
22std::string(" out of bounds: 1 if the event was out of the field map\n")+
23std::string(" boundary, else 0.\n")+
24std::string(" Bx: x magnetic field [T]\n")+
25std::string(" By: y magnetic field [T]\n")+
26std::string(" Bz: z magnetic field [T]\n")+
27std::string(" Ex: x electric field\n")+
28std::string(" Ey: y electric field\n")+
29std::string(" Ez: z electric field\n");
30
31boost::python::object get_field_value(double x, double y, double z, double t) {
32 Ring* ring = const_cast<Ring*>(Ring::getLastLockedRing());
33 if (ring == NULL) {
34 std::string err = "Could not find a ring object - maybe a "+
35 std::string("RingDefinition was not defined or KeepAlive was False");
36 // need to define proper exception handling
37 throw(err);
38 }
39 Vector_t R(x, y, z);
40 Vector_t P(0, 0, 0);
41 Vector_t E, B;
42 int outOfBounds = ring->apply(R, P, t, E, B);
43 boost::python::tuple value = boost::python::make_tuple(outOfBounds,
44 B[0]/10., B[1]/10., B[2]/10.,
45 E[0], E[1], E[2]);
46 return value;
47}
48
49const char* module_docstring = "field module returns the field";
50
51BOOST_PYTHON_MODULE(boost_field) {
52 boost::python::def("get_field_value",
54 boost::python::args("x", "y", "z", "t"),
56}
const char * module_docstring
BOOST_PYTHON_MODULE(boost_field)
std::string get_field_value_docstring
boost::python::object get_field_value(double x, double y, double z, double t)
Ring describes a ring type geometry for tracking.
Definition: Ring.h:64
virtual bool apply(const size_t &id, const double &t, Vector_t &E, Vector_t &B) override
Definition: Ring.cpp:99