ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyG4ParticleGun.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file pyG4ParticleGun.cc
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 // pyG4ParticleGun.cc
28 //
29 // 2005 Q
30 // ====================================================================
31 #include <boost/python.hpp>
32 #include "G4Version.hh"
33 #include "G4ParticleGun.hh"
34 #include "G4ParticleTable.hh"
35 #include "G4Event.hh"
36 
37 using namespace boost::python;
38 
39 #if G4VERSION_NUMBER < 910
40 // ====================================================================
41 // miscs
42 // ====================================================================
43 // What a hell!
44 
48 {
49  *this= right;
50 }
51 
55 {
56  NumberOfParticlesToBeGenerated= right.NumberOfParticlesToBeGenerated;
57  particle_definition= right.particle_definition;
58  particle_momentum_direction= right.particle_momentum_direction;
59  particle_energy= right.particle_energy;
60  particle_charge= right.particle_charge;
61  particle_polarization= right.particle_polarization;
62 
63  return *this;
64 }
65 
69 {
70  return false;
71 }
72 
76 {
77  return false;
78 }
79 
80 #endif
81 
82 
83 // ====================================================================
84 // thin wrappers
85 // ====================================================================
86 namespace pyG4ParticleGun {
87 
88 #if G4VERSION_NUMBER >= 910
89 // SetParticleMomentum
90 void (G4ParticleGun::*f1_SetParticleMomentum)(G4double)
92 void (G4ParticleGun::*f2_SetParticleMomentum)(G4ParticleMomentum)
94 #endif
95 
96 
98 void SetParticleByName(G4ParticleGun* gun, const std::string& pname)
100 {
102  G4ParticleDefinition* pd= particleTable-> FindParticle(pname);
103  if (pd != 0) {
104  gun-> SetParticleDefinition(pd);
105  } else {
106  G4cout << "*** \"" << pname << "\" is not registered "
107  << "in available particle list" << G4endl;
108  }
109 }
110 
114 {
115  const G4ParticleDefinition* pd= gun-> GetParticleDefinition();
116  return (pd-> GetParticleName()).c_str();
117 }
118 
119 }
120 
121 using namespace pyG4ParticleGun;
122 
123 // ====================================================================
124 // module definition
125 // ====================================================================
127 {
128 #if G4VERSION_NUMBER < 910
129  class_<G4ParticleGun>
130 #else
131  class_<G4ParticleGun, boost::noncopyable>
132 #endif
133  ("G4ParticleGun", "particle gun")
134  // constructor
135  .def(init<G4int>())
136  .def(init<G4ParticleDefinition*>())
137  .def(init<G4ParticleDefinition*, G4int>())
138  // ---
139  .def("GeneratePrimaryVertex", &G4ParticleGun::GeneratePrimaryVertex)
140  .def("SetParticleDefinition", &G4ParticleGun::SetParticleDefinition)
141  .def("GetParticleDefinition", &G4ParticleGun::GetParticleDefinition,
142  return_value_policy<reference_existing_object>())
143 #if G4VERSION_NUMBER >= 910
144  .def("SetParticleMomentum", f1_SetParticleMomentum)
145  .def("SetParticleMomentum", f2_SetParticleMomentum)
146 #else
147  .def("SetParticleMomentum", &G4ParticleGun::SetParticleMomentum)
148 #endif
149  .def("SetParticleMomentumDirection",
151  .def("GetParticleMomentumDirection",
153  .def("SetParticleEnergy", &G4ParticleGun::SetParticleEnergy)
154  .def("GetParticleEnergy", &G4ParticleGun::GetParticleEnergy)
155  .def("SetParticleCharge", &G4ParticleGun::SetParticleCharge)
156  .def("GetParticleCharge", &G4ParticleGun::GetParticleCharge)
157  .def("SetParticlePolarization", &G4ParticleGun::SetParticlePolarization)
158  .def("GetParticlePolarization", &G4ParticleGun::GetParticlePolarization)
159  .def("SetNumberOfParticles", &G4ParticleGun::SetNumberOfParticles)
160  .def("GetNumberOfParticles", &G4ParticleGun::GetNumberOfParticles)
161  .def("SetParticlePosition", &G4ParticleGun::SetParticlePosition)
162  .def("GetParticlePosition", &G4ParticleGun::GetParticlePosition)
163  .def("SetParticleTime", &G4ParticleGun::SetParticleTime)
164  .def("GetParticleTime", &G4ParticleGun::GetParticleTime)
165  .def("SetParticleByName", SetParticleByName)
166  .def("GetParticleByName", GetParticleByName)
167  ;
168 }