00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "EGS.h"
00014 #include "PEGSData.h"
00015 #include "Random.h"
00016
00017 inline int ilog2(float x)
00018 {
00019 return (int)(1.44269*log(x));
00020 }
00021
00022 static float ai2ln2=0.7213475;
00023
00024 #define MAXPWR2I 50
00025 float pwr2i[MAXPWR2I]={0};
00026
00027
00028 static double set_brem_rejection_function(double input, double RJARG1,
00029 double RJARG2, double RJARG3, double ZTARG, double ESEDEI);
00030
00031
00032 void EGS::brems(const PEGSData & mat)
00033 {
00034 if (pwr2i[0]==0){float p=2.; for(int i=0;i<MAXPWR2I;i++)pwr2i[i]=(p/=2.);}
00035
00036 float eie = this->e;
00037
00038
00039
00040
00041
00042
00043
00044
00045 int lvx=1, lvl0=3, lvl;
00046 if (eie < 50.0){lvx=0;lvl0=0;}
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 float abrems=float(ilog2( eie/mat.ap));
00057
00058
00059
00060
00061 float esg, ese, br;
00062
00063 for(;;)
00064 {
00065
00066
00067
00068
00069 float rnno06 = Random::flat();
00070 if (0.5 < ((abrems*mat.alphi(lvx)+0.5)*rnno06))
00071 {
00072
00073 float rnno07 = Random::flat();
00074 int idistr =(int)(abrems*rnno07);
00075
00076
00077
00078 float p= pwr2i[idistr];
00079
00080
00081
00082
00083
00084
00085
00086 lvl=lvl0;
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 float rnno08 = Random::flat();
00097
00098 if (rnno08>=ai2ln2)
00099 {
00100 for(;;)
00101 { float rnno09 = Random::flat(),
00102 rnno10 = Random::flat(),
00103 rnno11 = Random::flat(),
00104 h=std::max(rnno10,rnno11);
00105 br=1.0-0.5*h;
00106
00107 if ( rnno09 <= 0.5/br) break;
00108 }
00109
00110 }
00111 else
00112 {
00113
00114 float rnno12 = Random::flat();
00115 br=rnno12*0.5;
00116 }
00117
00118
00119 br=br*p;
00120 }
00121 else
00122 {
00123
00124 float rnno13 = Random::flat();
00125 float rnno14 = Random::flat();
00126 br=std::max(rnno13,rnno14);
00127 lvl=lvl0+1;
00128 }
00129
00130
00131
00132 esg=eie*br;
00133
00134
00135
00136
00137
00138
00139 if (esg < mat.ap )continue;
00140
00141 ese=(double)eie-(double)esg;
00142
00143
00144
00145 if (ese < rm ) continue;
00146
00147
00148
00149
00150
00151
00152
00153
00154 float del = br/ese;
00155
00156 float rejf = mat.screening(del, lvx, lvl);
00157 if (rejf == 0) continue;
00158
00159 float rnscrn = Random::flat();
00160 if (rnscrn <= rejf) break;
00161 }
00162
00163 this->e = ese;
00164
00165
00166
00167 double theta;
00168
00169
00170
00171
00172
00173
00174
00175 int IBRDST = 1;
00176 if (IBRDST == 0){
00177 theta = rm / eie;
00178 }
00179 if (IBRDST == 1){
00180 double rm2,test,HPI,ZTARG,TTEIE,TTESE,ESEDEI,Y2MAX;
00181 double RJARG1,RJARG2,RJARG3,REJMIN,REJMID,REJMAX,REJTOP;
00182 double Y2TST,REJTST,RTEST;
00183
00184 rm2 = 0.51100340;
00185 HPI = 3.141593;
00186 ZTARG = (double) mat.hzbrang();
00187 TTEIE = (double) eie / rm2;
00188 TTESE = (double) ese / rm2;
00189 ESEDEI = TTESE/TTEIE;
00190 Y2MAX = pow((HPI*TTEIE),2);
00191 RJARG1 = (1.0+pow(ESEDEI,2));
00192 RJARG2 = 3.0 * RJARG1 - 2.0*ESEDEI;
00193 RJARG3 = pow(((1.0-ESEDEI)/(2.0*TTEIE*ESEDEI)),2);
00194 REJMIN = set_brem_rejection_function(0.0E0,RJARG1,RJARG2,RJARG3,ZTARG,ESEDEI);
00195 REJMID = set_brem_rejection_function(1.0E0,RJARG1,RJARG2,RJARG3,ZTARG,ESEDEI);
00196 REJMAX = set_brem_rejection_function(Y2MAX,RJARG1,RJARG2,RJARG3,ZTARG,ESEDEI);
00197 test = REJMIN;
00198 if (test <= REJMID) test = REJMID;
00199 if (test <= REJMAX) test = REJMAX;
00200 REJTOP = test;
00201 do {
00202 Y2TST = (double) Random::flat();
00203 Y2TST = Y2TST/(1.0-Y2TST+1.0/Y2MAX);
00204 REJTST = set_brem_rejection_function(Y2TST,RJARG1,RJARG2,RJARG3,ZTARG,ESEDEI);
00205 RTEST = (double) Random::flat();
00206 } while(RTEST > (REJTST/REJTOP));
00207 if (Y2TST < 0){
00208 Y2TST = 0;
00209 }
00210
00211 theta = sqrt(Y2TST)/TTEIE;
00212
00213
00214 }
00215
00216 EGS *photon = new EGS(this);
00217 photon->iq = 0;
00218 photon->e = esg;
00219 photon->rotate( cos(theta), Random::flat(2.*M_PI) );
00220
00221 }
00222
00223 static double set_brem_rejection_function(double input, double RJARG1,
00224 double RJARG2, double RJARG3, double ZTARG, double ESEDEI)
00225 {
00226 double Y2TST1, result;
00227 Y2TST1 = pow((1.0 + input),2);
00228 result = (4.0 + log(RJARG3+ZTARG/Y2TST1))*(4.0*ESEDEI*input/Y2TST1-RJARG1)+RJARG2;
00229 return result;
00230 }
00231