diff options
-rw-r--r-- | chroma/generator/g4gen.py | 9 | ||||
-rw-r--r-- | chroma/generator/vertex.py | 2 |
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: |