summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2013-03-13 09:02:46 -0400
committertlatorre <tlatorre@uchicago.edu>2021-05-09 08:42:39 -0700
commit347430501637c201b0b04dbd39bb0e7d47cb6f3c (patch)
tree8d00d2e3d82acff5185cb3ce7714612801567c9e
parent485cb10a4033f2044de82ad9ea1e1b74e6e23786 (diff)
downloadchroma-347430501637c201b0b04dbd39bb0e7d47cb6f3c.tar.gz
chroma-347430501637c201b0b04dbd39bb0e7d47cb6f3c.tar.bz2
chroma-347430501637c201b0b04dbd39bb0e7d47cb6f3c.zip
Cast position and direction parameters to appropriately typed ndarrays.
-rw-r--r--chroma/generator/g4gen.py9
-rw-r--r--chroma/generator/vertex.py2
2 files changed, 9 insertions, 2 deletions
diff --git a/chroma/generator/g4gen.py b/chroma/generator/g4gen.py
index 4b0a139..27f1454 100644
--- a/chroma/generator/g4gen.py
+++ b/chroma/generator/g4gen.py
@@ -133,8 +133,13 @@ class G4Generator(object):
mass = G4ParticleTable.GetParticleTable().FindParticle(vertex.particle_name).GetPDGMass()
total_energy = vertex.ke*MeV + mass
self.particle_gun.SetParticleEnergy(total_energy)
- self.particle_gun.SetParticlePosition(G4ThreeVector(*vertex.pos)*mm)
- self.particle_gun.SetParticleMomentumDirection(G4ThreeVector(*vertex.dir).unit())
+
+ # Must be float type to call GEANT4 code
+ pos = np.asarray(vertex.pos, dtype=np.float64)
+ dir = np.asarray(vertex.dir, dtype=np.float64)
+
+ self.particle_gun.SetParticlePosition(G4ThreeVector(*pos)*mm)
+ self.particle_gun.SetParticleMomentumDirection(G4ThreeVector(*dir).unit())
self.particle_gun.SetParticleTime(vertex.t0*ns)
if vertex.pol is not None:
diff --git a/chroma/generator/vertex.py b/chroma/generator/vertex.py
index e8f4139..b49ad90 100644
--- a/chroma/generator/vertex.py
+++ b/chroma/generator/vertex.py
@@ -76,6 +76,8 @@ def pi0_gun(pos_iter, dir_iter, ke_iter, t0_iter=constant(0.0), start_id=0, gamm
def constant_particle_gun(particle_name, pos, dir, ke, t0=0.0, start_id=0):
'''Convenience wrapper around particle gun that assumes all
arguments are constants, rather than generators.'''
+ pos = np.asarray(pos)
+ dir = np.asarray(dir)
if (dir == 0.0).all():
dir_gen = isotropic()
else: