00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00036
00037
00038 #include "generators/MJGeneratorUtil.hh"
00039
00040 MJGeneratorUtil::MJGeneratorUtil()
00041 {;}
00042
00043 MJGeneratorUtil::~MJGeneratorUtil()
00044 {;}
00045
00046 G4ThreeVector MJGeneratorUtil::pick_isotropic()
00047 {
00048 G4double phi = twopi * G4UniformRand();
00049 G4double cos_theta = -1.0 + 2.0*G4UniformRand();
00050 G4double theta = acos(cos_theta);
00051 G4double sin_theta = sin(theta);
00052 G4double cos_x = sin_theta*cos(phi);
00053 G4double cos_y = sin_theta*sin(phi);
00054 G4double cos_z = cos_theta;
00055
00056 G4ThreeVector direction(cos_x,cos_y,cos_z);
00057
00058 return direction;
00059 }
00060
00061 G4ThreeVector MJGeneratorUtil::pick_point_in_box(G4double x_lo, G4double x_hi,
00062 G4double y_lo, G4double y_hi,
00063 G4double z_lo, G4double z_hi) {
00064 G4double dx = x_hi - x_lo;
00065 G4double dy = y_hi - y_lo;
00066 G4double dz = z_hi - z_lo;
00067
00068 G4double x = x_lo + dx*G4UniformRand();
00069 G4double y = y_lo + dy*G4UniformRand();
00070 G4double z = z_lo + dz*G4UniformRand();
00071
00072 G4ThreeVector pos(x,y,z);
00073
00074 return pos;
00075 }
00076
00077
00078 void MJGeneratorUtil::pick_point_in_circle(G4double Radius, G4double &x, G4double &y) {
00079
00080 G4double b = Radius*Radius;
00081 G4double x_rnd = G4UniformRand();
00082 G4double r = sqrt(b*x_rnd);
00083 G4double phi = twopi * G4UniformRand();
00084
00085 x = r*cos(phi);
00086 y = r*sin(phi);
00087 }
00088
00089
00090 G4ThreeVector MJGeneratorUtil::pick_point_in_annulus(G4double r1, G4double r2, G4double h)
00091 {
00092 G4double a = r1*r1;
00093 G4double b = r2*r2 - a;
00094
00095 G4double x_rnd = G4UniformRand();
00096 G4double r = sqrt(b*x_rnd + a);
00097
00098 G4double phi = twopi * G4UniformRand();
00099
00100 G4double x = r * cos(phi);
00101 G4double y = r * sin(phi);
00102
00103 G4double z = h * (-0.5 + G4UniformRand());
00104
00105 G4ThreeVector pos(x,y,z);
00106
00107 return pos;
00108
00109 }
00110
00111 G4ThreeVector MJGeneratorUtil::pick_point_in_annulus(G4double r1, G4double r2, G4double h,
00112 G4double theta0, G4double dtheta) {
00113
00114 G4double a = r1*r1;
00115 G4double b = r2*r2 - a;
00116
00117 G4double x_rnd = G4UniformRand();
00118 G4double r = sqrt(b*x_rnd + a);
00119
00120 G4double phi = theta0 + dtheta * G4UniformRand();
00121
00122 G4double x = r * cos(phi);
00123 G4double y = r * sin(phi);
00124
00125 G4double z = h * (-0.5 + G4UniformRand());
00126
00127 G4ThreeVector pos(x,y,z);
00128
00129 return pos;
00130
00131 }
00132
00133
00134 G4ThreeVector MJGeneratorUtil::pick_point_in_cylinder(G4double R, G4double L) {
00135
00136 return pick_point_in_annulus(0.0, R, L);
00137
00138 }
00139
00140
00141 G4ThreeVector MJGeneratorUtil::pick_point_on_cylinder(G4double R, G4double L)
00142 {
00143 G4double phi = twopi * G4UniformRand();
00144 G4double x = R*cos(phi);
00145 G4double y = R*sin(phi);
00146
00147 G4double z = L * (-0.5 + G4UniformRand());
00148
00149 G4ThreeVector pos(x,y,z);
00150
00151 return pos;
00152 }
00153
00154
00155
00156 G4ThreeVector MJGeneratorUtil::pick_point_in_shell(G4double r1, G4double r2)
00157 {
00158 const G4double ONE_THIRD = 1.0/3.0;
00159
00160 G4double r1_3 = pow(r1,3);
00161 G4double r2_3 = pow(r2,3);
00162 G4double d = r2_3 - r1_3;
00163
00164 G4double x_rnd = r1_3 + d * G4UniformRand();
00165 G4double r = pow(x_rnd,ONE_THIRD);
00166
00167 return r*pick_isotropic();
00168 }
00169
00170
00171 G4ThreeVector MJGeneratorUtil::pick_point_in_sphere(G4double r)
00172 {
00173 return pick_point_in_shell(0.0, r);
00174 }
00175
00176
00177 G4ThreeVector MJGeneratorUtil::pick_point_on_sphere(G4double r)
00178 {
00179 return r*pick_isotropic();
00180 }
00181