Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyG4ParticleGun.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: pyG4ParticleGun.cc,v 1.7 2007-11-08 06:42:03 kmura Exp $
27 // $Name: not supported by cvs2svn $
28 // ====================================================================
29 // pyG4ParticleGun.cc
30 //
31 // 2005 Q
32 // ====================================================================
33 #include <boost/python.hpp>
34 #include "G4Version.hh"
35 #include "G4ParticleGun.hh"
36 #include "G4ParticleTable.hh"
37 #include "G4Event.hh"
38 
39 using namespace boost::python;
40 
41 #if G4VERSION_NUMBER < 910
42 // ====================================================================
43 // miscs
44 // ====================================================================
45 // What a hell!
46 
50 {
51  *this= right;
52 }
53 
55 const G4ParticleGun& G4ParticleGun::operator=(const G4ParticleGun &right)
57 {
58  NumberOfParticlesToBeGenerated= right.NumberOfParticlesToBeGenerated;
59  particle_definition= right.particle_definition;
60  particle_momentum_direction= right.particle_momentum_direction;
61  particle_energy= right.particle_energy;
62  particle_charge= right.particle_charge;
63  particle_polarization= right.particle_polarization;
64 
65  return *this;
66 }
67 
69 G4int G4ParticleGun::operator==(const G4ParticleGun &right) const
71 {
72  return 0;
73 }
74 
76 G4int G4ParticleGun::operator!=(const G4ParticleGun &right) const
78 {
79  return 0;
80 }
81 
82 #endif
83 
84 
85 // ====================================================================
86 // thin wrappers
87 // ====================================================================
88 namespace pyG4ParticleGun {
89 
90 #if G4VERSION_NUMBER >= 910
91 // SetParticleMomentum
92 void (G4ParticleGun::*f1_SetParticleMomentum)(G4double)
94 void (G4ParticleGun::*f2_SetParticleMomentum)(G4ParticleMomentum)
96 #endif
97 
98 
100 void SetParticleByName(G4ParticleGun* gun, const std::string& pname)
102 {
104  G4ParticleDefinition* pd= particleTable-> FindParticle(pname);
105  if (pd != 0) {
106  gun-> SetParticleDefinition(pd);
107  } else {
108  G4cout << "*** \"" << pname << "\" is not registered "
109  << "in available particle list" << G4endl;
110  }
111 }
112 
116 {
117  const G4ParticleDefinition* pd= gun-> GetParticleDefinition();
118  return (pd-> GetParticleName()).c_str();
119 }
120 
121 };
122 
123 using namespace pyG4ParticleGun;
124 
125 // ====================================================================
126 // module definition
127 // ====================================================================
129 {
130 #if G4VERSION_NUMBER < 910
131  class_<G4ParticleGun>
132 #else
133  class_<G4ParticleGun, boost::noncopyable>
134 #endif
135  ("G4ParticleGun", "particle gun")
136  // constructor
137  .def(init<G4int>())
138  .def(init<G4ParticleDefinition*>())
139  .def(init<G4ParticleDefinition*, G4int>())
140  // ---
141  .def("GeneratePrimaryVertex", &G4ParticleGun::GeneratePrimaryVertex)
142  .def("SetParticleDefinition", &G4ParticleGun::SetParticleDefinition)
143  .def("GetParticleDefinition", &G4ParticleGun::GetParticleDefinition,
144  return_value_policy<reference_existing_object>())
145 #if G4VERSION_NUMBER >= 910
146  .def("SetParticleMomentum", f1_SetParticleMomentum)
147  .def("SetParticleMomentum", f2_SetParticleMomentum)
148 #else
149  .def("SetParticleMomentum", &G4ParticleGun::SetParticleMomentum)
150 #endif
151  .def("SetParticleMomentumDirection",
153  .def("GetParticleMomentumDirection",
155  .def("SetParticleEnergy", &G4ParticleGun::SetParticleEnergy)
156  .def("GetParticleEnergy", &G4ParticleGun::GetParticleEnergy)
157  .def("SetParticleCharge", &G4ParticleGun::SetParticleCharge)
158  .def("GetParticleCharge", &G4ParticleGun::GetParticleCharge)
159  .def("SetParticlePolarization", &G4ParticleGun::SetParticlePolarization)
160  .def("GetParticlePolarization", &G4ParticleGun::GetParticlePolarization)
161  .def("SetNumberOfParticles", &G4ParticleGun::SetNumberOfParticles)
162  .def("GetNumberOfParticles", &G4ParticleGun::GetNumberOfParticles)
163  .def("SetParticlePosition", &G4ParticleGun::SetParticlePosition)
164  .def("GetParticlePosition", &G4ParticleGun::GetParticlePosition)
165  .def("SetParticleTime", &G4ParticleGun::SetParticleTime)
166  .def("GetParticleTime", &G4ParticleGun::GetParticleTime)
167  .def("SetParticleByName", SetParticleByName)
168  .def("GetParticleByName", GetParticleByName)
169  ;
170 }