Geant4-11
pyMedicalBeam.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// ====================================================================
27// pyMedicalBeam.cc
28//
29// [MedicalBeam]
30// a site-module of Geant4Py
31//
32// primary generator action for medical beam
33//
34// 2005 Q
35// ====================================================================
36#include <boost/python.hpp>
37#include "MedicalBeam.hh"
38#include "G4ParticleTable.hh"
39#include "G4RunManager.hh"
40
41using namespace boost::python;
42
43// ====================================================================
44// thin wrappers
45// ====================================================================
46namespace pyMedicalBeam {
47
48MedicalBeam* Construct()
49{
51
52 MedicalBeam* medicalbeam= new MedicalBeam();
53 runMgr-> SetUserAction(medicalbeam);
54
55 return medicalbeam;
56}
57
58
60void SetParticleByName(MedicalBeam* beam, const std::string& pname)
62{
64 G4ParticleDefinition* pd= particleTable-> FindParticle(pname);
65 if (pd != 0) {
66 beam-> SetParticleDefinition(pd);
67 } else {
68 G4cout << "*** \"" << pname << "\" is not registered "
69 << "in available particle list" << G4endl;
70 }
71}
72
74std::string GetParticleByName(MedicalBeam* beam)
76{
77 const G4ParticleDefinition* pd= beam-> GetParticleDefinition();
78
79 if(pd==0) return std::string("None");
80 else return (pd-> GetParticleName()).c_str();
81}
82
84void f_SetFieldXY(MedicalBeam* beam, const list& listXY)
86{
87 G4double fx= extract<double>(listXY[0]);
88 G4double fy= extract<double>(listXY[1]);
89 beam-> SetFieldXY(fx, fy);
90}
91
92
94list f_GetFieldXY(MedicalBeam* beam)
96{
97 list listFieldXY;
98
99 listFieldXY.append(beam-> GetFieldX());
100 listFieldXY.append(beam-> GetFieldY());
101
102 return listFieldXY;
103}
104
105}
106
107using namespace pyMedicalBeam;
108
109// ====================================================================
110// Expose to Python
111// ====================================================================
112
113BOOST_PYTHON_MODULE(_MedicalBeam) {
114 class_<MedicalBeam, MedicalBeam*,
115 bases<G4VUserPrimaryGeneratorAction> >
116 ("MedicalBeam", "primary generator action with medical beam")
117 // ---
118 .add_property("particle", GetParticleByName, SetParticleByName)
119 .def("SetParticleByName", SetParticleByName)
120 .def("GetParticleByName", GetParticleByName)
121 // ---
122 .add_property("kineticE", &MedicalBeam::GetKineticE,
124 .def("SetKineticE", &MedicalBeam::SetKineticE)
125 .def("GetKineticE", &MedicalBeam::GetKineticE)
126 // ---
127 .add_property("sourcePosition", &MedicalBeam::GetSourcePosition,
129 .def("SetSourcePosition", &MedicalBeam::SetSourcePosition)
130 .def("GetSourcePosition", &MedicalBeam::GetSourcePosition)
131 // ---
132 .add_property("fieldShape", &MedicalBeam::GetFieldShape,
134 .def("SetFieldShape", &MedicalBeam::SetFieldShape)
135 .def("GetFieldShape", &MedicalBeam::GetFieldShape)
136 // ---
137 .add_property("SSD", &MedicalBeam::GetSSD, &MedicalBeam::SetSSD)
138 .def("SetSSD", &MedicalBeam::SetSSD)
139 .def("GetSSD", &MedicalBeam::GetSSD)
140 // ----
141 .add_property("fieldXY", f_GetFieldXY, f_SetFieldXY)
142 .def("SetFieldXY", f_SetFieldXY)
143 .def("GetFieldXY", f_GetFieldXY)
144 .def("GetFieldX", &MedicalBeam::GetFieldX)
145 .def("GetFieldY", &MedicalBeam::GetFieldY)
146 // ---
147 .add_property("fieldR", &MedicalBeam::GetFieldR, &MedicalBeam::SetFieldR)
148 .def("SetFieldR", &MedicalBeam::SetFieldR)
149 .def("GetFieldR", &MedicalBeam::GetFieldR)
150 ;
151
152 // enums...
153 enum_<MedicalBeam::FieldShape>("FieldShape")
154 .value("SQUARE", MedicalBeam::SQUARE)
155 .value("CIRCLE", MedicalBeam::CIRCLE)
156 ;
157
158 // ---
159 def("Construct", Construct,
160 return_value_policy<reference_existing_object>());
161}
162
double G4double
Definition: G4Types.hh:83
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4ParticleTable * GetParticleTable()
static G4RunManager * GetRunManager()
void SetFieldR(G4double r)
Definition: MedicalBeam.hh:136
G4double GetSSD() const
Definition: MedicalBeam.hh:124
G4double GetKineticE() const
Definition: MedicalBeam.hh:106
void SetSSD(G4double ssd)
Definition: MedicalBeam.hh:121
void SetKineticE(G4double e)
Definition: MedicalBeam.hh:103
G4double GetFieldR() const
Definition: MedicalBeam.hh:139
G4double GetFieldX() const
Definition: MedicalBeam.hh:130
void SetFieldShape(FieldShape shape)
Definition: MedicalBeam.hh:115
G4double GetFieldY() const
Definition: MedicalBeam.hh:133
FieldShape GetFieldShape() const
Definition: MedicalBeam.hh:118
void SetSourcePosition(const G4ThreeVector &pos)
Definition: MedicalBeam.hh:109
G4ThreeVector GetSourcePosition() const
Definition: MedicalBeam.hh:112
string pname
Definition: eplot.py:33
void f_SetFieldXY(MedicalBeam *beam, const list &listXY)
std::string GetParticleByName(MedicalBeam *beam)
MedicalBeam * Construct()
void SetParticleByName(MedicalBeam *beam, const std::string &pname)
list f_GetFieldXY(MedicalBeam *beam)
BOOST_PYTHON_MODULE(_MedicalBeam)