6 #include "G4LogicalVolumeStore.hh"
7 #include "G4LogicalVolume.hh"
9 #include "G4RunManager.hh"
10 #include "G4ParticleGun.hh"
11 #include "G4ParticleTable.hh"
12 #include "G4ParticleDefinition.hh"
13 #include "G4SystemOfUnits.hh"
14 #include "Randomize.hh"
24 : G4VUserPrimaryGeneratorAction(),
31 fParticleGun =
new G4ParticleGun(n_particle);
35 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
36 G4String particleName;
37 G4ParticleDefinition* particle
38 = particleTable->FindParticle(particleName=
"gamma");
43 fParticleGun->SetParticleDefinition(particle);
44 fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
45 fParticleGun->SetParticleEnergy(6.*MeV);
76 G4double envSizeXY = 0;
77 G4double envSizeZ = 0;
84 G4LogicalVolume* envLV
85 = G4LogicalVolumeStore::GetInstance()->GetVolume(
"Envelope");
87 if ( envLV ) fEnvelopeBox =
dynamic_cast<G4Box*
>(envLV->GetSolid());
96 envSizeXY = fEnvelopeBox->GetXHalfLength()*2.;
98 envSizeZ = fEnvelopeBox->GetZHalfLength()*2.;
104 G4ExceptionDescription msg;
105 msg <<
"Envelope volume of box shape not found.\n";
106 msg <<
"Perhaps you have changed geometry.\n";
107 msg <<
"The gun will be place at the center.";
108 G4Exception(
"B1PrimaryGeneratorAction::GeneratePrimaries()",
109 "MyCode0002",JustWarning,msg);
118 G4double x0 = size * envSizeXY * (G4UniformRand()-0.5);
119 G4double y0 = size * envSizeXY * (G4UniformRand()-0.5);
120 G4double z0 = -0.5 * envSizeZ;
123 fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
131 fParticleGun->GeneratePrimaryVertex(anEvent);
virtual void GeneratePrimaries(G4Event *)
setup the gamma's location to get the width and height of the 'Envelope' phyisclogic volume...
B1PrimaryGeneratorAction()
set up our gamma beamIt is 6MeV gamma, moving toward (0,0,1) direction. gamma's location will be se...
Definition of the B1PrimaryGeneratorAction class.
virtual ~B1PrimaryGeneratorAction()
we must delete the fParticleGun when the B1PrimaryGeneratorAction obj is deleted. ...