added randomised x-y position within 15 cm window

This commit is contained in:
Jan Kieseler
2024-08-22 15:56:31 +02:00
parent d8f3a3720a
commit 88b03ecfa3
+12 -4
View File
@@ -121,10 +121,18 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
G4Exception("PrimaryGeneratorAction::GeneratePrimaries()",
"MyCode0002", JustWarning, msg);
}
// Set gun position
fParticleGun
->SetParticlePosition(G4ThreeVector(0., 0., -worldZHalfLength));
//draw particle position from a unit distribution in x-y with +-5 cm around the center
G4double x = -1000;
G4double y = -1000;
G4double x_width = 15;
G4double y_width = 15;
while(x < -x_width/2. || x > x_width/2. || y < -y_width/2. || y > y_width/2.){
x = G4INCL::Random::shoot()*x_width - x_width/2;
y = G4INCL::Random::shoot()*y_width - y_width/2;
}
fParticleGun->SetParticlePosition(G4ThreeVector(x*cm, y*cm, -worldZHalfLength));
//printout for checking
G4cout << "shooting at " << x << " " << y << " " << -worldZHalfLength << G4endl;
fParticleGun->GeneratePrimaryVertex(anEvent);