Skip to content

Commit a5196f1

Browse files
committed
Change Primary Generator
1 parent d0199c8 commit a5196f1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/actions/PrimaryGeneratorAction.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ PrimaryGeneratorAction::PrimaryGeneratorAction()
1313

1414
void PrimaryGeneratorAction::GeneratePrimaries(G4Event* event)
1515
{
16-
mom.setRThetaPhi(1., pi * G4UniformRand(), twopi * G4UniformRand());
17-
gun.SetParticleMomentumDirection(mom);
16+
const G4double phi = twopi * G4UniformRand();
17+
const G4double cos_theta = 2. * G4UniformRand() - 1.;
18+
const G4double sin_theta = std::sqrt(1. - cos_theta * cos_theta);
19+
20+
const G4double x = sin_theta * std::cos(phi);
21+
const G4double y = sin_theta * std::sin(phi);
22+
const G4double z = cos_theta;
23+
24+
gun.SetParticleMomentumDirection(G4ThreeVector(x, y, z));
1825
gun.GeneratePrimaryVertex(event);
1926
}

src/actions/PrimaryGeneratorAction.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction {
1212

1313
private:
1414
G4ParticleGun gun;
15-
G4ParticleMomentum mom;
1615
};

0 commit comments

Comments
 (0)