85 G4double fieldBoundary, wc0, wc1, wc2, wc3, limitMinEntrance, limitMaxEntrance, limitMinExit, limitMaxExit;
87 limitMinEntrance = beamStart+zS-4*
D;
88 limitMaxEntrance = beamStart+zS+4*
D;
99 G4double ws, largeS, h, dhdlargeS, dhds, dlargeSds, dsdz, dsdx, zs0, Rs0, xcenter, zcenter;
103 if ( (z >= limitMinEntrance) && (z < limitMaxEntrance) )
105 zs0 = fieldBoundary*
D;
106 ws = (-z+beamStart+zS-zs0)/D;
110 largeS = wc0 + wc1*ws + wc2*ws*ws + wc3*ws*ws*ws;
111 h = 1./(1.+
G4Exp(largeS));
112 dhdlargeS = -
G4Exp(largeS)*h*h;
113 dlargeSds = wc1+ 2*wc2*ws + 3*wc3*ws*ws;
114 dhds = dhdlargeS * dlargeSds;
116 By = switchingField * h ;
117 Bx = y*switchingField*dhds*dsdx;
118 Bz = y*switchingField*dhds*dsdz;
125 (z >= limitMaxEntrance)
126 && (( x*x + (z -(beamStart+zS))*(z -(beamStart+zS)) < limitMinExit*limitMinExit))
137 (z >= limitMaxEntrance)
138 && (( x*x + (z -(beamStart+zS))*(z -(beamStart+zS))) >= limitMinExit*limitMinExit)
139 && (( x*x + (z -(beamStart+zS))*(z -(beamStart+zS))) < limitMaxExit*limitMaxExit)
145 zcenter = beamStart+zS;
147 Rs0 = Rp + D*fieldBoundary;
148 ws = (std::sqrt((z-zcenter)*(z-zcenter)+(x-xcenter)*(x-xcenter)) - Rs0)/D;
150 dsdz = (1/
D)*(z-zcenter)/std::sqrt((z-zcenter)*(z-zcenter)+(x-xcenter)*(x-xcenter));
151 dsdx = (1/
D)*(x-xcenter)/std::sqrt((z-zcenter)*(z-zcenter)+(x-xcenter)*(x-xcenter));
153 largeS = wc0 + wc1*ws + wc2*ws*ws + wc3*ws*ws*ws;
154 h = 1./(1.+
G4Exp(largeS));
155 dhdlargeS = -
G4Exp(largeS)*h*h;
156 dlargeSds = wc1+ 2*wc2*ws + 3*wc3*ws*ws;
157 dhds = dhdlargeS * dlargeSds;
159 By = switchingField * h ;
160 Bx = y*switchingField*dhds*dsdx;
161 Bz = y*switchingField*dhds*dsdz;
179 lineX = lineX + 5.24*
micrometer*std::cos(-lineAngle);
180 lineZ = lineZ + 5.24*
micrometer*std::sin(-lineAngle);
191 if (z>=-1400*
mm && z <-200*
mm)
205 gradient[0] = 3.406526 *
tesla/
m;
214 gradient[1] = -8.505263 *
tesla/
m;
223 gradient[2] = 8.505263 *
tesla/
m;
232 gradient[3] = -3.406526*
tesla/
m;
235 G4double Bx_local,By_local,Bz_local;
236 Bx_local = 0; By_local = 0; Bz_local = 0;
240 Bx_quad = 0; By_quad=0; Bz_quad=0;
244 x_local= 0; y_local=0; z_local=0;
263 G4bool largeScattering=
false;
265 for (
G4int i=0;i<4; i++)
269 { xoprime = lineX + quadHalfLength*std::sin(lineAngle);
270 zoprime = lineZ + quadHalfLength*std::cos(lineAngle);
272 x_local = (x - xoprime) * std::cos (lineAngle) - (z - zoprime) * std::sin (lineAngle);
274 z_local = (z - zoprime) * std::cos (lineAngle) + (x - xoprime) * std::sin (lineAngle);
275 if (std::sqrt(x_local*x_local+y_local*y_local)>a0[i]) largeScattering=
true;
280 { xoprime = lineX + (3*quadHalfLength+quadSpacing)*std::sin(lineAngle);
281 zoprime = lineZ + (3*quadHalfLength+quadSpacing)*std::cos(lineAngle);
283 x_local = (x - xoprime) * std::cos (lineAngle) - (z - zoprime) * std::sin (lineAngle);
285 z_local = (z - zoprime) * std::cos (lineAngle) + (x - xoprime) * std::sin (lineAngle);
286 if (std::sqrt(x_local*x_local+y_local*y_local)>a0[i]) largeScattering=
true;
290 { xoprime = lineX + (5*quadHalfLength+2*quadSpacing)*std::sin(lineAngle);
291 zoprime = lineZ + (5*quadHalfLength+2*quadSpacing)*std::cos(lineAngle);
293 x_local = (x - xoprime) * std::cos (lineAngle) - (z - zoprime) * std::sin (lineAngle);
295 z_local = (z - zoprime) * std::cos (lineAngle) + (x - xoprime) * std::sin (lineAngle);
296 if (std::sqrt(x_local*x_local+y_local*y_local)>a0[i]) largeScattering=
true;
300 { xoprime = lineX + (7*quadHalfLength+3*quadSpacing)*std::sin(lineAngle);
301 zoprime = lineZ + (7*quadHalfLength+3*quadSpacing)*std::cos(lineAngle);
303 x_local = (x - xoprime) * std::cos (lineAngle) - (z - zoprime) * std::sin (lineAngle);
305 z_local = (z - zoprime) * std::cos (lineAngle) + (x - xoprime) * std::sin (lineAngle);
306 if (std::sqrt(x_local*x_local+y_local*y_local)>a0[i]) largeScattering=
true;
310 if ( z_local < -z2[i] )
318 if ( z_local > z2[i] )
326 if ( (z_local>=-z1[i]) & (z_local<=z1[i]) )
334 if ( ((z_local>=-z2[i]) & (z_local<-z1[i])) || ((z_local>z1[i]) & (z_local<=z2[i])) )
337 vars = ( z_local - z1[i]) / a0[i] ;
338 if (z_local<-z1[i]) vars = ( - z_local - z1[i]) / a0[i] ;
341 P0 = c0[i]+c1[i]*vars+c2[i]*vars*vars;
343 P1 = c1[i]/a0[i]+2*c2[i]*(z_local-z1[i])/a0[i]/a0[i];
344 if (z_local<-z1[i]) P1 = -c1[i]/a0[i]+2*c2[i]*(z_local+z1[i])/a0[i]/a0[i];
346 P2 = 2*c2[i]/a0[i]/a0[i];
348 cte = 1 +
G4Exp(c0[i]);
352 K2 = -cte*
G4Exp(P0)*(
354 +2*P1*K1/(1+
G4Exp(P0))/cte
358 K3 = -cte*
G4Exp(P0)*(
360 +4*K1*(P1*P1+P2)/(1+
G4Exp(P0))/cte
361 +2*P1*(K1*K1/cte/cte+K2/(1+
G4Exp(P0))/cte)
364 G0 = gradient[i]*cte/(1+
G4Exp(P0));
373 if ( largeScattering )
383 Bx_local = y_local*(G0-(1./12)*(3*x_local*x_local+y_local*y_local)*G2);
384 By_local = x_local*(G0-(1./12)*(3*y_local*y_local+x_local*x_local)*G2);
385 Bz_local = x_local*y_local*(G1-(1./12)*(x_local*x_local+y_local*y_local)*G3);
387 Bx_quad = Bz_local*std::sin(lineAngle)+Bx_local*std::cos(lineAngle);
389 Bz_quad = Bz_local*std::cos(lineAngle)-Bx_local*std::sin(lineAngle);
428 G4double electricFieldPlate1 = electricPlateVoltage1 / electricPlateSpacing1 ;
429 G4double electricFieldPlate2 = electricPlateVoltage2 / electricPlateSpacing2 ;
431 G4double beginFirstZoneX = lineX + (8*quadHalfLength+3*quadSpacing)*std::sin(lineAngle);
432 G4double beginFirstZoneZ = lineZ + (8*quadHalfLength+3*quadSpacing)*std::cos(lineAngle);
434 G4double beginSecondZoneX = lineX + (8*quadHalfLength+3*quadSpacing+electricPlateLength1+electricPlateGap)*std::sin(lineAngle);
435 G4double beginSecondZoneZ = lineZ + (8*quadHalfLength+3*quadSpacing+electricPlateLength1+electricPlateGap)*std::cos(lineAngle);
437 G4double xA, zA, xB, zB, xC, zC, xD, zD;
438 G4double slope1, cte1, slope2, cte2, slope3, cte3, slope4, cte4;
444 xA = beginFirstZoneX + std::cos(lineAngle)*electricPlateSpacing1/2;
445 zA = beginFirstZoneZ - std::sin(lineAngle)*electricPlateSpacing1/2;
447 xB = xA + std::sin(lineAngle)*electricPlateLength1;
448 zB = zA + std::cos(lineAngle)*electricPlateLength1;
450 xC = xB - std::cos(lineAngle)*electricPlateSpacing1;
451 zC = zB + std::sin(lineAngle)*electricPlateSpacing1;
453 xD = xC - std::sin(lineAngle)*electricPlateLength1;
454 zD = zC - std::cos(lineAngle)*electricPlateLength1;
456 slope1 = (xB-xA)/(zB-zA);
457 cte1 = xA - slope1 * zA;
459 slope2 = (xC-xB)/(zC-zB);
460 cte2 = xB - slope2 * zB;
462 slope3 = (xD-xC)/(zD-zC);
463 cte3 = xC - slope3 * zC;
465 slope4 = (xA-xD)/(zA-zD);
466 cte4 = xD - slope4 * zD;
471 x <= slope1 * z + cte1
472 && x >= slope3 * z + cte3
473 && x <= slope4 * z + cte4
474 && x >= slope2 * z + cte2
475 && std::abs(y)<=electricPlateWidth1/2
479 Bfield[3] = electricFieldPlate1*std::cos(lineAngle);
481 Bfield[5] = -electricFieldPlate1*std::sin(lineAngle);
487 xA = beginSecondZoneX + std::cos(lineAngle)*electricPlateWidth2/2;
488 zA = beginSecondZoneZ - std::sin(lineAngle)*electricPlateWidth2/2;
490 xB = xA + std::sin(lineAngle)*electricPlateLength2;
491 zB = zA + std::cos(lineAngle)*electricPlateLength2;
493 xC = xB - std::cos(lineAngle)*electricPlateWidth2;
494 zC = zB + std::sin(lineAngle)*electricPlateWidth2;
496 xD = xC - std::sin(lineAngle)*electricPlateLength2;
497 zD = zC - std::cos(lineAngle)*electricPlateLength2;
499 slope1 = (xB-xA)/(zB-zA);
500 cte1 = xA - slope1 * zA;
502 slope2 = (xC-xB)/(zC-zB);
503 cte2 = xB - slope2 * zB;
505 slope3 = (xD-xC)/(zD-zC);
506 cte3 = xC - slope3 * zC;
508 slope4 = (xA-xD)/(zA-zD);
509 cte4 = xD - slope4 * zD;
513 x <= slope1 * z + cte1
514 && x >= slope3 * z + cte3
515 && x <= slope4 * z + cte4
516 && x >= slope2 * z + cte2
517 && std::abs(y)<=electricPlateSpacing2/2
522 Bfield[4] = electricFieldPlate2;
static constexpr double tesla
static c2_factory< G4double > c2
static constexpr double mm
static const G4double * P1[nN]
static const G4double * P0[nN]
static constexpr double m
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
static const G4double * P2[nN]
static constexpr double volt
static constexpr double deg
static constexpr double micrometer