File indexing completed on 2026-05-30 08:08:59
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 #include "MyKleinNishinaCompton.hh"
0030
0031 #include "DetectorConstruction.hh"
0032 #include "MyKleinNishinaMessenger.hh"
0033
0034 #include "G4DataVector.hh"
0035 #include "G4Electron.hh"
0036 #include "G4Gamma.hh"
0037 #include "G4ParticleChangeForGamma.hh"
0038 #include "G4PhysicalConstants.hh"
0039 #include "Randomize.hh"
0040
0041
0042
0043 using namespace std;
0044
0045 MyKleinNishinaCompton::MyKleinNishinaCompton(DetectorConstruction* det, const G4ParticleDefinition*,
0046 const G4String& nam)
0047 : G4KleinNishinaCompton(0, nam), fDetector(det), fMessenger(0)
0048 {
0049 fCrossSectionFactor = 1.;
0050 fMessenger = new MyKleinNishinaMessenger(this);
0051 }
0052
0053
0054
0055 MyKleinNishinaCompton::~MyKleinNishinaCompton()
0056 {
0057 delete fMessenger;
0058 }
0059
0060
0061
0062 G4double MyKleinNishinaCompton::CrossSectionPerVolume(const G4Material* mat,
0063 const G4ParticleDefinition* part,
0064 G4double GammaEnergy, G4double, G4double)
0065 {
0066 G4double xsection = G4VEmModel::CrossSectionPerVolume(mat, part, GammaEnergy);
0067
0068 return xsection * fCrossSectionFactor;
0069 }
0070
0071
0072 void MyKleinNishinaCompton::SampleSecondaries(std::vector<G4DynamicParticle*>* fvect,
0073 const G4MaterialCutsCouple*,
0074 const G4DynamicParticle* aDynamicGamma, G4double,
0075 G4double)
0076 {
0077
0078
0079
0080
0081
0082 G4double gamEnergy0 = aDynamicGamma->GetKineticEnergy();
0083 G4double E0_m = gamEnergy0 / electron_mass_c2;
0084
0085 G4ThreeVector gamDirection0 = aDynamicGamma->GetMomentumDirection();
0086
0087
0088
0089
0090
0091 G4double epsilon, epsilonsq, onecost, sint2, greject;
0092
0093 G4double eps0 = 1. / (1. + 2. * E0_m);
0094 G4double eps0sq = eps0 * eps0;
0095 G4double alpha1 = -log(eps0);
0096 G4double alpha2 = 0.5 * (1. - eps0sq);
0097
0098 do {
0099 if (alpha1 / (alpha1 + alpha2) > G4UniformRand()) {
0100 epsilon = exp(-alpha1 * G4UniformRand());
0101 epsilonsq = epsilon * epsilon;
0102 }
0103 else {
0104 epsilonsq = eps0sq + (1. - eps0sq) * G4UniformRand();
0105 epsilon = sqrt(epsilonsq);
0106 };
0107
0108 onecost = (1. - epsilon) / (epsilon * E0_m);
0109 sint2 = onecost * (2. - onecost);
0110 greject = 1. - epsilon * sint2 / (1. + epsilonsq);
0111
0112 } while (greject < G4UniformRand());
0113
0114
0115
0116
0117
0118 G4double cosTeta = 1. - onecost;
0119 G4double sinTeta = sqrt(sint2);
0120 G4double Phi = twopi * G4UniformRand();
0121 G4double dirx = sinTeta * cos(Phi), diry = sinTeta * sin(Phi), dirz = cosTeta;
0122
0123
0124
0125
0126
0127
0128 G4ThreeVector gamDirection1(dirx, diry, dirz);
0129 gamDirection1.rotateUz(gamDirection0);
0130 G4double gamEnergy1 = epsilon * gamEnergy0;
0131 fParticleChange->SetProposedKineticEnergy(gamEnergy0);
0132 fParticleChange->ProposeMomentumDirection(gamDirection0);
0133
0134
0135
0136
0137
0138 G4double eKinEnergy = gamEnergy0 - gamEnergy1;
0139
0140 if (eKinEnergy > DBL_MIN) {
0141 G4ThreeVector eDirection = gamEnergy0 * gamDirection0 - gamEnergy1 * gamDirection1;
0142 eDirection = eDirection.unit();
0143
0144
0145 G4DynamicParticle* dp = new G4DynamicParticle(theElectron, eDirection, eKinEnergy);
0146 fvect->push_back(dp);
0147 }
0148 }
0149
0150