File indexing completed on 2026-03-31 07:50:08
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
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 #include "FFPrimaryGeneratorAction.hh"
0051
0052 #include "G4Event.hh"
0053 #include "G4LogicalVolume.hh"
0054 #include "G4LogicalVolumeStore.hh"
0055 #include "G4Neutron.hh"
0056 #include "G4ParticleGun.hh"
0057 #include "G4PhysicalVolumeStore.hh"
0058 #include "G4SystemOfUnits.hh"
0059 #include "G4Tubs.hh"
0060 #include "G4VPhysicalVolume.hh"
0061 #include "Randomize.hh"
0062 #include "globals.hh"
0063
0064
0065 FFPrimaryGeneratorAction::FFPrimaryGeneratorAction()
0066 : G4VUserPrimaryGeneratorAction(),
0067 #ifndef NDEBUG
0068 fEventNumber(0),
0069 #endif
0070 fH2OPhysical(NULL),
0071 fNeutronPhysical(NULL),
0072 fNeutronSolid(NULL),
0073 fParticleGun(new G4ParticleGun(1)),
0074 fTankPhysical(NULL)
0075 {
0076 fParticleGun->SetParticleDefinition(G4Neutron::Definition());
0077 fParticleGun->SetParticleEnergy(4.5 * MeV);
0078 }
0079
0080
0081 void FFPrimaryGeneratorAction::GeneratePrimaries(G4Event* event)
0082 {
0083 #ifndef NDEBUG
0084 G4cout << "Shooting event " << ++fEventNumber << G4endl;
0085 #endif
0086 const G4ThreeVector sourceCenter = GetNeutronSourceCenter();
0087
0088
0089 const G4double radius = fNeutronSolid->GetOuterRadius();
0090 const G4double z = fNeutronSolid->GetZHalfLength() * 2;
0091 G4ThreeVector randomLocation;
0092 randomLocation.setRThetaPhi(radius * std::sqrt(G4UniformRand()), G4UniformRand() * 180 * deg, 0);
0093 randomLocation.setZ(z * (G4UniformRand() - 0.5));
0094 G4ThreeVector location(randomLocation.x() + sourceCenter.x(),
0095 randomLocation.y() + sourceCenter.y(),
0096 randomLocation.z() + sourceCenter.z());
0097 #ifndef NDEBUG
0098 G4cout << "Emission Location: r: " << location << G4endl;
0099 #endif
0100
0101
0102 G4ThreeVector direction;
0103 direction.setRThetaPhi(1.0, std::acos(G4UniformRand() * 2 - 1),
0104 (G4UniformRand() * 2 - 1) * 180 * deg);
0105 #ifndef NDEBUG
0106 G4cout << "Emission Direction: r: " << direction << G4endl;
0107 #endif
0108
0109
0110 fParticleGun->SetParticlePosition(location);
0111 fParticleGun->SetParticleMomentumDirection(direction);
0112 fParticleGun->GeneratePrimaryVertex(event);
0113 }
0114
0115
0116 G4ThreeVector FFPrimaryGeneratorAction::GetNeutronSourceCenter(void)
0117 {
0118
0119 if (fNeutronSolid == NULL) {
0120 G4LogicalVolume* temp = G4LogicalVolumeStore::GetInstance()->GetVolume("NeutronSource");
0121 if (temp != NULL) {
0122 fNeutronSolid = dynamic_cast<G4Tubs*>(temp->GetSolid());
0123 }
0124
0125 if (fNeutronSolid == NULL) {
0126 G4Exception(
0127 "FFPrimaryGeneratorAction::"
0128 "GeneratePrimaries(G4Event*)",
0129 "Neutron source solid volume not found", EventMustBeAborted, "This run will be aborted");
0130 }
0131 }
0132
0133
0134 if (fNeutronPhysical == NULL) {
0135 fNeutronPhysical = G4PhysicalVolumeStore::GetInstance()->GetVolume("NeutronSource");
0136 }
0137
0138 if (fNeutronPhysical == NULL) {
0139 G4Exception("FFPrimaryGeneratorAction::GetNeutronSourceCenter(void)",
0140 "Neutron source physical volume not found", EventMustBeAborted,
0141 "This run will be aborted");
0142 }
0143
0144
0145 if (fH2OPhysical == NULL) {
0146 fH2OPhysical = G4PhysicalVolumeStore::GetInstance()->GetVolume("Tank_H2O");
0147
0148 if (fH2OPhysical == NULL) {
0149 G4Exception(
0150 "FFPrimaryGeneratorAction::"
0151 "GetNeutronSourceCenter(void)",
0152 "Tank H2O physical volume not found", EventMustBeAborted, "This run will be aborted");
0153 }
0154 }
0155
0156
0157 if (fTankPhysical == NULL) {
0158 fTankPhysical = G4PhysicalVolumeStore::GetInstance()->GetVolume("Tank_Wall");
0159
0160 if (fTankPhysical == NULL) {
0161 G4Exception(
0162 "FFPrimaryGeneratorAction::"
0163 "GetNeutronSourceCenter(void)",
0164 "Tank physical volume not found", EventMustBeAborted, "This run will be aborted");
0165 }
0166 }
0167
0168 return fNeutronPhysical->GetTranslation() + fH2OPhysical->GetTranslation()
0169 + fTankPhysical->GetTranslation();
0170 }
0171
0172
0173 FFPrimaryGeneratorAction::~FFPrimaryGeneratorAction()
0174 {
0175 delete fParticleGun;
0176 }