43 G4int nofParticles = 1;
44 fParticleGun =
new G4ParticleGun(nofParticles);
48 auto particleDefinition = G4ParticleTable::GetParticleTable()->FindParticle(
"e-");
49 fParticleGun->SetParticleDefinition(particleDefinition);
50 fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.));
51 fParticleGun->SetParticleEnergy(300. * MeV);
67 G4double worldZHalfLength = 0.;
68 auto worldLV = G4LogicalVolumeStore::GetInstance()->GetVolume(
"World");
71 G4Box* worldBox =
nullptr;
73 worldBox =
dynamic_cast<G4Box*
>(worldLV->GetSolid());
77 worldZHalfLength = worldBox->GetZHalfLength();
79 G4ExceptionDescription msg;
80 msg <<
"World volume of box shape not found." << G4endl;
81 msg <<
"Perhaps you have changed geometry." << G4endl;
82 msg <<
"The gun will be place in the center.";
83 G4Exception(
"PrimaryGeneratorAction::GeneratePrimaries()",
"MyCode0002", JustWarning, msg);
87 fParticleGun->SetParticlePosition(G4ThreeVector(0., 0., -worldZHalfLength));
89 fParticleGun->GeneratePrimaryVertex(event);