00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "EGS.h"
00016 #include "Random.h"
00017 #include <cmath>
00018 #include <algorithm>
00019
00020
00021 void EGS::annih()
00022 {
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 double avip = this->e + (double)rm;
00036 double a = avip/rm,
00037 ai = 1.0/a,
00038 g = a-1.0,
00039 t = std::max(0.,g-1.0),
00040 p = sqrt(a*t),
00041 ep0= 1.0/(a+p),
00042 ep;
00043
00044
00045 if( ::fabs(ep0-0.5) > 1e-5)
00046 for(;;)
00047 { float rnno01= Random::flat();
00048 ep=ep0*exp(rnno01*log((1.0-ep0)/ep0));
00049
00050 float rnno02= Random::flat();
00051 float rejf=1.0-ep+ai*ai*(2.0*g-1.0/ep);
00052 if (rnno02 <=rejf) break ;
00053 }
00054 else
00055 ep = ep0;
00056
00057
00058
00059
00060 if (ep>0.5) ep=1.0-ep;
00061
00062
00063 double pesg1 = avip*ep;
00064 double pesg2 = avip - pesg1;
00065
00066 EGS& g1 = *this;
00067 EGS& g2 = *new EGS(this);
00068
00069 g1.e = pesg1; g1.iq = 0;
00070 g2.e = pesg2; g2.iq = 0;
00071
00072
00073 float phi = Random::flat(2.*M_PI);
00074 float costh1, costh2;
00075
00076 if (t<=0.)
00077 { costh1 = Random::flat(-1.,1.);
00078 costh2 = -costh1;
00079 }
00080 else
00081 {
00082 costh1 = std::min(1.0,(pesg1-rm)*p/t/pesg1);
00083 costh2 = std::min(1.0,(pesg2-rm)*p/t/pesg2);
00084 }
00085 g1.rotate(costh1, phi);
00086
00087 g2.rotate(costh2, phi+M_PI);
00088
00089 }
00090