From 88b03ecfa36960487624e171e4194d3191056504 Mon Sep 17 00:00:00 2001 From: Jan Kieseler Date: Thu, 22 Aug 2024 15:56:31 +0200 Subject: [PATCH] added randomised x-y position within 15 cm window --- src/PrimaryGeneratorAction.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/PrimaryGeneratorAction.cc b/src/PrimaryGeneratorAction.cc index b6cde79..01d876b 100644 --- a/src/PrimaryGeneratorAction.cc +++ b/src/PrimaryGeneratorAction.cc @@ -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);