1 #ifndef GUARD_GGEMS_PHYSICS_GGEMSCOMPTONSCATTERINGMODELS_HH
2 #define GUARD_GGEMS_PHYSICS_GGEMSCOMPTONSCATTERINGMODELS_HH
34 #ifdef __OPENCL_C_VERSION__
47 inline void KleinNishinaComptonSampleSecondaries(
50 GGint const particle_id
54 GGfloat kE0 = primary_particle->E_[particle_id];
59 primary_particle->dx_[particle_id],
60 primary_particle->dy_[particle_id],
61 primary_particle->dz_[particle_id]
65 GGfloat kEps0 = 1.0f / (1.0f + 2.0f*kE0_MeC2);
66 GGfloat kEps0Eps0 = kEps0*kEps0;
68 GGfloat kAlpha2 = kAlpha1 + 0.5f*(1.0f-kEps0Eps0);
71 if (particle_id == primary_particle->particle_tracking_id) {
73 printf(
"[GGEMS OpenCL function KleinNishinaComptonSampleSecondaries] Photon energy: %e keV\n", kE0/
keV);
74 printf(
"[GGEMS OpenCL function KleinNishinaComptonSampleSecondaries] Photon direction: %e %e %e\n", kGammaDirection.x, kGammaDirection.y, kGammaDirection.z);
75 printf(
"[GGEMS OpenCL function KleinNishinaComptonSampleSecondaries] Min. photon energy (back scattering): %e keV\n", kE0*kEps0/
keV);
82 GGfloat epsilon, epsilonsq, onecost, sint2, greject, costheta, sintheta, phi;
87 if (nloop > 1000)
return;
90 rndm.x = KissUniform(random, particle_id);
91 rndm.y = KissUniform(random, particle_id);
92 rndm.z = KissUniform(random, particle_id);
94 if (kAlpha1 > kAlpha2*rndm.x) {
95 epsilon = exp(-kAlpha1*rndm.y);
96 epsilonsq = epsilon*epsilon;
99 epsilonsq = kEps0Eps0 + (1.0f - kEps0Eps0)*rndm.y;
100 epsilon = sqrt(epsilonsq);
103 onecost = (1.0f - epsilon)/(epsilon*kE0_MeC2);
104 sint2 = onecost*(2.0f-onecost);
105 greject = 1.0f - epsilon*sint2/(1.0f+ epsilonsq);
106 }
while (greject < rndm.z);
109 if (sint2 < 0.0f) sint2 = 0.0f;
110 costheta = 1.0f - onecost;
111 sintheta = sqrt(sint2);
112 phi = KissUniform(random, particle_id) *
TWO_PI;
115 GGfloat3 gamma_direction = {sintheta*cos(phi), sintheta*sin(phi), costheta};
116 gamma_direction = RotateUnitZ(&gamma_direction, &kGammaDirection);
117 gamma_direction = normalize(gamma_direction);
120 #ifdef GGEMS_TRACKING
121 if (particle_id == primary_particle->particle_tracking_id) {
122 printf(
"[GGEMS OpenCL function KleinNishinaComptonSampleSecondaries] Scattered photon energy: %e keV\n", kE1/
keV);
123 printf(
"[GGEMS OpenCL function KleinNishinaComptonSampleSecondaries] Scattered photon direction: %e %e %e\n", gamma_direction.x, gamma_direction.y, gamma_direction.z);
127 primary_particle->E_[particle_id] = kE1;
129 primary_particle->dx_[particle_id] = gamma_direction.x;
130 primary_particle->dy_[particle_id] = gamma_direction.y;
131 primary_particle->dz_[particle_id] = gamma_direction.z;
136 #endif // GUARD_GGEMS_PHYSICS_GGEMSCOMPTONSCATTERINGMODELS_HH