File indexing completed on 2025-02-23 09:21:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #include "F01PrimaryGeneratorAction.hh"
0036
0037 #include "F01DetectorConstruction.hh"
0038 #include "F01PrimaryGeneratorMessenger.hh"
0039
0040 #include "G4Event.hh"
0041 #include "G4ParticleDefinition.hh"
0042 #include "G4ParticleGun.hh"
0043 #include "G4ParticleTable.hh"
0044 #include "G4PhysicalConstants.hh"
0045 #include "G4SystemOfUnits.hh"
0046 #include "Randomize.hh"
0047
0048
0049
0050 G4ParticleDefinition* F01PrimaryGeneratorAction::fgPrimaryParticle = nullptr;
0051
0052
0053
0054 F01PrimaryGeneratorAction::F01PrimaryGeneratorAction(F01DetectorConstruction* det) : fDetector(det)
0055 {
0056 G4int n_particle = 1;
0057 fParticleGun = new G4ParticleGun(n_particle);
0058
0059
0060 fGunMessenger = new F01PrimaryGeneratorMessenger(this);
0061
0062
0063
0064 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
0065 G4String particleName;
0066 G4ParticleDefinition* particle = particleTable->FindParticle(particleName = "e-");
0067 fParticleGun->SetParticleDefinition(particle);
0068
0069 fgPrimaryParticle = particle;
0070
0071 fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0., 0., -1.));
0072 fParticleGun->SetParticleEnergy(0.5 * GeV);
0073
0074 fZVertex = fDetector->GetAbsorberZpos() - 0.5 * (fDetector->GetAbsorberThickness());
0075 fParticleGun->SetParticlePosition(G4ThreeVector(fXVertex, fYVertex, fZVertex));
0076 }
0077
0078
0079
0080 F01PrimaryGeneratorAction::~F01PrimaryGeneratorAction()
0081 {
0082 delete fParticleGun;
0083 delete fGunMessenger;
0084 }
0085
0086
0087
0088 void F01PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0089 {
0090
0091
0092 fgPrimaryParticle = fParticleGun->GetParticleDefinition();
0093
0094 G4double x0, y0, z0;
0095 if (fVertexDefined) {
0096 x0 = fXVertex;
0097 y0 = fYVertex;
0098 z0 = fZVertex;
0099 }
0100 else {
0101 x0 = 0.;
0102 y0 = 0.;
0103 z0 = fDetector->GetAbsorberZpos() - 0.5 * (fDetector->GetAbsorberThickness());
0104 }
0105
0106 G4double r0, phi0;
0107 if (fRndmFlag == "on") {
0108 r0 = (fDetector->GetAbsorberRadius()) * std::sqrt(G4UniformRand());
0109 phi0 = twopi * G4UniformRand();
0110 x0 = r0 * std::cos(phi0);
0111 y0 = r0 * std::sin(phi0);
0112 }
0113
0114 fParticleGun->SetParticlePosition(G4ThreeVector(x0, y0, z0));
0115 fParticleGun->GeneratePrimaryVertex(anEvent);
0116 }
0117
0118
0119
0120 G4String F01PrimaryGeneratorAction::GetPrimaryName()
0121 {
0122 return fgPrimaryParticle->GetParticleName();
0123 }
0124
0125
0126
0127 void F01PrimaryGeneratorAction::SetZVertex(G4double z)
0128 {
0129 fVertexDefined = true;
0130 fZVertex = z;
0131 G4cout << " Z coordinate of the primary vertex = " << fZVertex / mm << " mm." << G4endl;
0132 }
0133
0134
0135
0136 void F01PrimaryGeneratorAction::SetXVertex(G4double x)
0137 {
0138 fVertexDefined = true;
0139 fXVertex = x;
0140 G4cout << " X coordinate of the primary vertex = " << fXVertex / mm << " mm." << G4endl;
0141 }
0142
0143
0144
0145 void F01PrimaryGeneratorAction::SetYVertex(G4double y)
0146 {
0147 fVertexDefined = true;
0148 fYVertex = y;
0149 G4cout << " Y coordinate of the primary vertex = " << fYVertex / mm << " mm." << G4endl;
0150 }
0151
0152