File indexing completed on 2025-02-23 09:20:36
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 #include "XrayTESdetPrimaryGeneratorAction.hh"
0037 #include "XrayTESdetDetectorConstruction.hh"
0038
0039 #include "G4Event.hh"
0040 #include "G4ParticleGun.hh"
0041 #include "G4ThreeVector.hh"
0042 #include "G4ParticleTable.hh"
0043 #include "G4ParticleDefinition.hh"
0044 #include "Randomize.hh"
0045 #include "globals.hh"
0046 #include "G4NistManager.hh"
0047 #include "G4SystemOfUnits.hh"
0048 #include "G4PhysicalConstants.hh"
0049
0050
0051
0052 XrayTESdetPrimaryGeneratorAction::XrayTESdetPrimaryGeneratorAction()
0053 {
0054 G4int n_particle = 1;
0055 fParticleGun = new G4ParticleGun(n_particle);
0056 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
0057 G4String particleName;
0058
0059
0060 fParticleGun->SetParticleDefinition(particleTable->FindParticle(particleName="proton"));
0061 }
0062
0063
0064
0065 XrayTESdetPrimaryGeneratorAction::~XrayTESdetPrimaryGeneratorAction()
0066 {
0067 delete fParticleGun;
0068 }
0069
0070
0071
0072 void XrayTESdetPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0073 {
0074 G4double ax;
0075 G4double ay;
0076 G4double az;
0077
0078 G4double bx;
0079 G4double by;
0080 G4double bz;
0081
0082 G4double vx;
0083 G4double vy;
0084 G4double vz;
0085
0086 G4double energy = 0;
0087 G4double u;
0088 G4double u1;
0089
0090 G4double theta0;
0091 G4double phi0;
0092 G4double theta1;
0093 G4double phi1;
0094
0095 G4double ene;
0096 G4double flux;
0097 G4double r;
0098
0099
0100 r = 27*cm;
0101
0102
0103 G4double phi = 0.379;
0104 G4double tr = 0.938;
0105 G4double T;
0106
0107 while (true)
0108 {
0109 u = G4UniformRand();
0110 u1 = 0.268*G4UniformRand();
0111 ene = 10.*MeV + u*100000.*MeV;
0112 T = ene*0.001;
0113 flux = 1.9*std::pow(((T + phi)*(T + phi + 2*tr)), -1.39)*T*(T + 2*tr)/((1 + 0.4866*std::pow(((T + phi)*(T + phi + 2*tr)),-1.255))*(T + phi)*(T + phi + 2*tr));
0114 if (u1 <= flux)
0115 {
0116 energy = ene;
0117 break;
0118 }
0119 }
0120
0121 theta0 = std::acos(1. - 2.*G4UniformRand());
0122 theta1 = std::acos(1. - 2.*G4UniformRand());
0123 phi0 = twopi*G4UniformRand();
0124 phi1 = twopi*G4UniformRand();
0125 ax = r*std::sin(theta0)*std::cos(phi0);
0126 ay = r*std::sin(theta0)*std::sin(phi0);
0127 az = r*std::cos(theta0) + 80*mm;
0128
0129 bx = r*std::sin(theta1)*std::cos(phi1);
0130 by = r*std::sin(theta1)*std::sin(phi1);
0131 bz = r*std::cos(theta1) + 80*mm;
0132 vx = bx - ax;
0133 vy = by - ay;
0134 vz = bz - az;
0135
0136 fParticleGun->SetParticleEnergy(energy);
0137 fParticleGun->SetParticlePosition(G4ThreeVector(ax, ay, az));
0138 fParticleGun->SetParticleMomentumDirection(G4ThreeVector(vx,vy,vz));
0139 fParticleGun->GeneratePrimaryVertex(anEvent);
0140 }
0141
0142