Geant4  10.02.p01
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 // $Id: pyMedicalBeam.cc 76884 2013-11-18 12:54:03Z gcosmo $
27 // ====================================================================
28 // pyMedicalBeam.cc
29 //
30 // [MedicalBeam]
31 // a site-module of Geant4Py
32 //
33 // primary generator action for medical beam
34 //
35 // 2005 Q
36 // ====================================================================
37 #include <boost/python.hpp>
38 #include "MedicalBeam.hh"
39 #include "G4ParticleTable.hh"
40 #include "G4RunManager.hh"
41 
42 using namespace boost::python;
43 
44 // ====================================================================
45 // thin wrappers
46 // ====================================================================
47 namespace pyMedicalBeam {
48 
50 {
52 
53  MedicalBeam* medicalbeam= new MedicalBeam();
54  runMgr-> SetUserAction(medicalbeam);
55 
56  return medicalbeam;
57 }
58 
59 
61 void SetParticleByName(MedicalBeam* beam, const std::string& pname)
63 {
65  G4ParticleDefinition* pd= particleTable-> FindParticle(pname);
66  if (pd != 0) {
67  beam-> SetParticleDefinition(pd);
68  } else {
69  G4cout << "*** \"" << pname << "\" is not registered "
70  << "in available particle list" << G4endl;
71  }
72 }
73 
75 std::string GetParticleByName(MedicalBeam* beam)
77 {
78  const G4ParticleDefinition* pd= beam-> GetParticleDefinition();
79 
80  if(pd==0) return std::string("None");
81  else return (pd-> GetParticleName()).c_str();
82 }
83 
85 void f_SetFieldXY(MedicalBeam* beam, const list& listXY)
87 {
88  G4double fx= extract<double>(listXY[0]);
89  G4double fy= extract<double>(listXY[1]);
90  beam-> SetFieldXY(fx, fy);
91 }
92 
93 
97 {
98  list listFieldXY;
99 
100  listFieldXY.append(beam-> GetFieldX());
101  listFieldXY.append(beam-> GetFieldY());
102 
103  return listFieldXY;
104 }
105 
106 }
107 
108 using namespace pyMedicalBeam;
109 
110 // ====================================================================
111 // Expose to Python
112 // ====================================================================
113 
115  class_<MedicalBeam, MedicalBeam*,
116  bases<G4VUserPrimaryGeneratorAction> >
117  ("MedicalBeam", "primary generator action with medical beam")
118  // ---
119  .add_property("particle", GetParticleByName, SetParticleByName)
120  .def("SetParticleByName", SetParticleByName)
121  .def("GetParticleByName", GetParticleByName)
122  // ---
123  .add_property("kineticE", &MedicalBeam::GetKineticE,
125  .def("SetKineticE", &MedicalBeam::SetKineticE)
126  .def("GetKineticE", &MedicalBeam::GetKineticE)
127  // ---
128  .add_property("sourcePosition", &MedicalBeam::GetSourcePosition,
130  .def("SetSourcePosition", &MedicalBeam::SetSourcePosition)
131  .def("GetSourcePosition", &MedicalBeam::GetSourcePosition)
132  // ---
133  .add_property("fieldShape", &MedicalBeam::GetFieldShape,
135  .def("SetFieldShape", &MedicalBeam::SetFieldShape)
136  .def("GetFieldShape", &MedicalBeam::GetFieldShape)
137  // ---
138  .add_property("SSD", &MedicalBeam::GetSSD, &MedicalBeam::SetSSD)
139  .def("SetSSD", &MedicalBeam::SetSSD)
140  .def("GetSSD", &MedicalBeam::GetSSD)
141  // ----
142  .add_property("fieldXY", f_GetFieldXY, f_SetFieldXY)
143  .def("SetFieldXY", f_SetFieldXY)
144  .def("GetFieldXY", f_GetFieldXY)
145  .def("GetFieldX", &MedicalBeam::GetFieldX)
146  .def("GetFieldY", &MedicalBeam::GetFieldY)
147  // ---
148  .add_property("fieldR", &MedicalBeam::GetFieldR, &MedicalBeam::SetFieldR)
149  .def("SetFieldR", &MedicalBeam::SetFieldR)
150  .def("GetFieldR", &MedicalBeam::GetFieldR)
151  ;
152 
153  // enums...
154  enum_<MedicalBeam::FieldShape>("FieldShape")
155  .value("SQUARE", MedicalBeam::SQUARE)
156  .value("CIRCLE", MedicalBeam::CIRCLE)
157  ;
158 
159  // ---
160  def("Construct", Construct,
161  return_value_policy<reference_existing_object>());
162 }
163 
MedicalBeam * Construct()
G4double GetFieldR() const
Definition: MedicalBeam.hh:140
void SetParticleByName(MedicalBeam *beam, const std::string &pname)
std::string GetParticleByName(MedicalBeam *beam)
void SetSSD(G4double ssd)
Definition: MedicalBeam.hh:122
G4double GetKineticE() const
Definition: MedicalBeam.hh:107
list f_GetFieldXY(MedicalBeam *beam)
FieldShape GetFieldShape() const
Definition: MedicalBeam.hh:119
G4double GetFieldY() const
Definition: MedicalBeam.hh:134
void SetFieldR(G4double r)
Definition: MedicalBeam.hh:137
void SetSourcePosition(const G4ThreeVector &pos)
Definition: MedicalBeam.hh:110
G4GLOB_DLL std::ostream G4cout
BOOST_PYTHON_MODULE(MedicalBeam)
G4ThreeVector GetSourcePosition() const
Definition: MedicalBeam.hh:113
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4double GetSSD() const
Definition: MedicalBeam.hh:125
void SetFieldShape(FieldShape shape)
Definition: MedicalBeam.hh:116
static G4ParticleTable * GetParticleTable()
void SetKineticE(G4double e)
Definition: MedicalBeam.hh:104
#define G4endl
Definition: G4ios.hh:61
void f_SetFieldXY(MedicalBeam *beam, const list &listXY)
double G4double
Definition: G4Types.hh:76
G4double GetFieldX() const
Definition: MedicalBeam.hh:131