File indexing completed on 2026-04-17 07:51:38
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 #include "PrimaryGeneratorAction.hh"
0029 #include "PrimaryGeneratorMessenger.hh"
0030 #include "G4IAEAphspReader.hh"
0031
0032 #include "globals.hh"
0033 #include "Randomize.hh"
0034 #include "G4SystemOfUnits.hh"
0035 #include "G4ParticleGun.hh"
0036 #include "G4ParticleTable.hh"
0037 #include "G4ParticleDefinition.hh"
0038 #include "G4Gamma.hh"
0039 #include "G4RunManager.hh"
0040
0041 #include <vector>
0042
0043
0044
0045
0046 PrimaryGeneratorAction::PrimaryGeneratorAction(const G4int threads)
0047 :fThreads(threads)
0048 {
0049 fIAEAphspReaderName = "";
0050 fVerbose = 0;
0051 fMessenger = new PrimaryGeneratorMessenger(this);
0052 fParticleGun = new G4ParticleGun();
0053 fParticleGun->SetParticleDefinition(G4Gamma::Definition());
0054
0055 fCounter = 0;
0056 fKinE = 50.0*MeV;
0057 fDE = 0.0;
0058 fX0 = 0.0;
0059 fY0 = 0.0;
0060 fZ0 = 0.0;
0061 fDX = 0.0;
0062 fDY = 0.0;
0063 fDZ = 0.0;
0064 }
0065
0066
0067
0068
0069 PrimaryGeneratorAction::~PrimaryGeneratorAction()
0070 {
0071 if (fVerbose > 0) G4cout << "Destroying PrimaryGeneratorAction" << G4endl;
0072 delete fParticleGun;
0073 delete fMessenger;
0074
0075 if (fIAEAphspReader) delete fIAEAphspReader;
0076 if (fVerbose > 0) G4cout << "PrimaryGeneratorAction destroyed" << G4endl;
0077 }
0078
0079
0080
0081
0082 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0083 {
0084 if (fIAEAphspReader) {
0085 fIAEAphspReader->GeneratePrimaryVertex(anEvent);
0086 }
0087
0088 else {
0089
0090 fCounter++ ;
0091
0092
0093 G4double kinEnergy = fKinE;
0094 if(fDE > 0.0)
0095 kinEnergy = G4RandFlat::shoot(fKinE-fDE/2., fKinE+fDE/2.);
0096
0097 fParticleGun->SetParticleEnergy(kinEnergy);
0098
0099
0100 G4double x = fX0;
0101 G4double y = fY0;
0102 G4double z = fZ0;
0103 if (fDX > 0.0)
0104 x = G4RandFlat::shoot(fX0-fDX/2., fX0+fDX/2.);
0105 if (fDY > 0.0)
0106 y = G4RandFlat::shoot(fY0-fDY/2., fY0+fDY/2.);
0107 if (fDZ > 0.0)
0108 z = G4RandFlat::shoot(fZ0-fDZ/2., fZ0+fDZ/2.);
0109
0110 fParticleGun->SetParticlePosition( G4ThreeVector(x,y,z) );
0111
0112
0113 G4double ux = 0.0;
0114 G4double uy = 0.0;
0115 G4double uz = 1.0;
0116
0117
0118
0119 if(G4UniformRand() < 0.5)
0120 uz = -uz;
0121
0122 fParticleGun->SetParticleMomentumDirection( G4ThreeVector(ux,uy,uz) );
0123
0124 if(fVerbose > 1) {
0125 G4ParticleDefinition* particle = fParticleGun->GetParticleDefinition();
0126 G4String particleName = particle->GetParticleName();
0127 G4cout << G4endl
0128 << "Event # " << fCounter
0129 << " ParticleGun vertex: "
0130 << "ParticleName = " << particleName
0131 << " PDGcode = " << particle->GetPDGEncoding()
0132 << G4endl;
0133 G4cout << std::setprecision(6)
0134 << "\t\t KinEnergy (MeV) = " << kinEnergy/MeV
0135 << " weight = " << fParticleGun->GetParticleWeight()
0136 << G4endl
0137 << "\t\t x (cm) = " << x/cm
0138 << " y (cm) = " << y/cm
0139 << " z (cm) = " << z/cm
0140 << " ux = " << ux << " uy = " << uy << " uz = " << uz
0141 << G4endl;
0142 }
0143
0144 fParticleGun->GeneratePrimaryVertex(anEvent);
0145 }
0146 }
0147
0148
0149
0150
0151 void PrimaryGeneratorAction::SetIAEAphspReader(const G4String filename)
0152 {
0153 fIAEAphspReaderName = filename;
0154 fIAEAphspReader = new G4IAEAphspReader(filename, fThreads);
0155 }