92 G4double fieldBoundary, wc0, wc1, wc2, wc3, limitMinEntrance, limitMaxEntrance, limitMinExit, limitMaxExit;
94 limitMinEntrance = beamStart+zS-4*
D;
95 limitMaxEntrance = beamStart+zS+4*
D;
106 G4double ws, largeS,
h, dhdlargeS, dhds, dlargeSds, dsdz, dsdx, zs0, Rs0, xcenter, zcenter;
110 if ( (z >= limitMinEntrance) && (z < limitMaxEntrance) )
112 zs0 = fieldBoundary*
D;
113 ws = (-z+beamStart+zS-zs0)/D;
117 largeS = wc0 + wc1*ws + wc2*ws*ws + wc3*ws*ws*ws;
118 h = 1./(1.+
G4Exp(largeS));
119 dhdlargeS = -
G4Exp(largeS)*h*
h;
120 dlargeSds = wc1+ 2*wc2*ws + 3*wc3*ws*ws;
121 dhds = dhdlargeS * dlargeSds;
123 By = switchingField *
h ;
124 Bx = y*switchingField*dhds*dsdx;
125 Bz = y*switchingField*dhds*dsdz;
132 (z >= limitMaxEntrance)
133 && (( x*x + (z -(beamStart+zS))*(z -(beamStart+zS)) < limitMinExit*limitMinExit))
144 (z >= limitMaxEntrance)
145 && (( x*x + (z -(beamStart+zS))*(z -(beamStart+zS))) >= limitMinExit*limitMinExit)
146 && (( x*x + (z -(beamStart+zS))*(z -(beamStart+zS))) < limitMaxExit*limitMaxExit)
152 zcenter = beamStart+zS;
154 Rs0 = Rp + D*fieldBoundary;
155 ws = (std::sqrt((z-zcenter)*(z-zcenter)+(x-xcenter)*(x-xcenter)) - Rs0)/D;
157 dsdz = (1/
D)*(z-zcenter)/std::sqrt((z-zcenter)*(z-zcenter)+(x-xcenter)*(x-xcenter));
158 dsdx = (1/
D)*(x-xcenter)/std::sqrt((z-zcenter)*(z-zcenter)+(x-xcenter)*(x-xcenter));
160 largeS = wc0 + wc1*ws + wc2*ws*ws + wc3*ws*ws*ws;
161 h = 1./(1.+
G4Exp(largeS));
162 dhdlargeS = -
G4Exp(largeS)*h*
h;
163 dlargeSds = wc1+ 2*wc2*ws + 3*wc3*ws*ws;
164 dhds = dhdlargeS * dlargeSds;
166 By = switchingField *
h ;
167 Bx = y*switchingField*dhds*dsdx;
168 Bz = y*switchingField*dhds*dsdz;
186 lineX = lineX + 5.24*
micrometer*std::cos(-lineAngle);
187 lineZ = lineZ + 5.24*
micrometer*std::sin(-lineAngle);
198 if (z>=-1400*
mm && z <-200*
mm)
212 gradient[0] = 3.406526 *
tesla/
m;
221 gradient[1] = -8.505263 *
tesla/
m;
230 gradient[2] = 8.505263 *
tesla/
m;
239 gradient[3] = -3.406526*
tesla/
m;
242 G4double Bx_local,By_local,Bz_local;
243 Bx_local = 0; By_local = 0; Bz_local = 0;
247 Bx_quad = 0; By_quad=0; Bz_quad=0;
251 x_local= 0; y_local=0; z_local=0;
270 G4bool largeScattering=
false;
272 for (
G4int i=0;i<4; i++)
276 { xoprime = lineX + quadHalfLength*std::sin(lineAngle);
277 zoprime = lineZ + quadHalfLength*std::cos(lineAngle);
279 x_local = (x - xoprime) * std::cos (lineAngle) - (z - zoprime) * std::sin (lineAngle);
281 z_local = (z - zoprime) * std::cos (lineAngle) + (x - xoprime) * std::sin (lineAngle);
282 if (std::sqrt(x_local*x_local+y_local*y_local)>a0[i]) largeScattering=
true;
287 { xoprime = lineX + (3*quadHalfLength+quadSpacing)*std::sin(lineAngle);
288 zoprime = lineZ + (3*quadHalfLength+quadSpacing)*std::cos(lineAngle);
290 x_local = (x - xoprime) * std::cos (lineAngle) - (z - zoprime) * std::sin (lineAngle);
292 z_local = (z - zoprime) * std::cos (lineAngle) + (x - xoprime) * std::sin (lineAngle);
293 if (std::sqrt(x_local*x_local+y_local*y_local)>a0[i]) largeScattering=
true;
297 { xoprime = lineX + (5*quadHalfLength+2*quadSpacing)*std::sin(lineAngle);
298 zoprime = lineZ + (5*quadHalfLength+2*quadSpacing)*std::cos(lineAngle);
300 x_local = (x - xoprime) * std::cos (lineAngle) - (z - zoprime) * std::sin (lineAngle);
302 z_local = (z - zoprime) * std::cos (lineAngle) + (x - xoprime) * std::sin (lineAngle);
303 if (std::sqrt(x_local*x_local+y_local*y_local)>a0[i]) largeScattering=
true;
307 { xoprime = lineX + (7*quadHalfLength+3*quadSpacing)*std::sin(lineAngle);
308 zoprime = lineZ + (7*quadHalfLength+3*quadSpacing)*std::cos(lineAngle);
310 x_local = (x - xoprime) * std::cos (lineAngle) - (z - zoprime) * std::sin (lineAngle);
312 z_local = (z - zoprime) * std::cos (lineAngle) + (x - xoprime) * std::sin (lineAngle);
313 if (std::sqrt(x_local*x_local+y_local*y_local)>a0[i]) largeScattering=
true;
317 if ( z_local < -z2[i] )
325 if ( z_local > z2[i] )
333 if ( (z_local>=-z1[i]) & (z_local<=z1[i]) )
341 if ( ((z_local>=-z2[i]) & (z_local<-z1[i])) || ((z_local>z1[i]) & (z_local<=z2[i])) )
344 vars = ( z_local - z1[i]) / a0[i] ;
345 if (z_local<-z1[i]) vars = ( - z_local - z1[i]) / a0[i] ;
348 P0 = c0[i]+c1[i]*vars+c2[i]*vars*vars;
350 P1 = c1[i]/a0[i]+2*c2[i]*(z_local-z1[i])/a0[i]/a0[i];
351 if (z_local<-z1[i]) P1 = -c1[i]/a0[i]+2*c2[i]*(z_local+z1[i])/a0[i]/a0[i];
353 P2 = 2*c2[i]/a0[i]/a0[i];
355 cte = 1 +
G4Exp(c0[i]);
359 K2 = -cte*
G4Exp(P0)*(
361 +2*P1*K1/(1+
G4Exp(P0))/cte
365 K3 = -cte*
G4Exp(P0)*(
367 +4*K1*(P1*P1+P2)/(1+
G4Exp(P0))/cte
368 +2*P1*(K1*K1/cte/cte+K2/(1+
G4Exp(P0))/cte)
371 G0 = gradient[i]*cte/(1+
G4Exp(P0));
380 if ( largeScattering )
390 Bx_local = y_local*(G0-(1./12)*(3*x_local*x_local+y_local*y_local)*G2);
391 By_local = x_local*(G0-(1./12)*(3*y_local*y_local+x_local*x_local)*G2);
392 Bz_local = x_local*y_local*(G1-(1./12)*(x_local*x_local+y_local*y_local)*G3);
394 Bx_quad = Bz_local*std::sin(lineAngle)+Bx_local*std::cos(lineAngle);
396 Bz_quad = Bz_local*std::cos(lineAngle)-Bx_local*std::sin(lineAngle);
435 G4double electricFieldPlate1 = electricPlateVoltage1 / electricPlateSpacing1 ;
436 G4double electricFieldPlate2 = electricPlateVoltage2 / electricPlateSpacing2 ;
438 G4double beginFirstZoneX = lineX + (8*quadHalfLength+3*quadSpacing)*std::sin(lineAngle);
439 G4double beginFirstZoneZ = lineZ + (8*quadHalfLength+3*quadSpacing)*std::cos(lineAngle);
441 G4double beginSecondZoneX = lineX + (8*quadHalfLength+3*quadSpacing+electricPlateLength1+electricPlateGap)*std::sin(lineAngle);
442 G4double beginSecondZoneZ = lineZ + (8*quadHalfLength+3*quadSpacing+electricPlateLength1+electricPlateGap)*std::cos(lineAngle);
444 G4double xA, zA, xB, zB, xC, zC, xD, zD;
445 G4double slope1, cte1, slope2, cte2, slope3, cte3, slope4, cte4;
451 xA = beginFirstZoneX + std::cos(lineAngle)*electricPlateSpacing1/2;
452 zA = beginFirstZoneZ - std::sin(lineAngle)*electricPlateSpacing1/2;
454 xB = xA + std::sin(lineAngle)*electricPlateLength1;
455 zB = zA + std::cos(lineAngle)*electricPlateLength1;
457 xC = xB - std::cos(lineAngle)*electricPlateSpacing1;
458 zC = zB + std::sin(lineAngle)*electricPlateSpacing1;
460 xD = xC - std::sin(lineAngle)*electricPlateLength1;
461 zD = zC - std::cos(lineAngle)*electricPlateLength1;
463 slope1 = (xB-xA)/(zB-zA);
464 cte1 = xA - slope1 * zA;
466 slope2 = (xC-xB)/(zC-zB);
467 cte2 = xB - slope2 * zB;
469 slope3 = (xD-xC)/(zD-zC);
470 cte3 = xC - slope3 * zC;
472 slope4 = (xA-xD)/(zA-zD);
473 cte4 = xD - slope4 * zD;
478 x <= slope1 * z + cte1
479 && x >= slope3 * z + cte3
480 && x <= slope4 * z + cte4
481 && x >= slope2 * z + cte2
482 &&
std::abs(y)<=electricPlateWidth1/2
486 Bfield[3] = electricFieldPlate1*std::cos(lineAngle);
488 Bfield[5] = -electricFieldPlate1*std::sin(lineAngle);
494 xA = beginSecondZoneX + std::cos(lineAngle)*electricPlateWidth2/2;
495 zA = beginSecondZoneZ - std::sin(lineAngle)*electricPlateWidth2/2;
497 xB = xA + std::sin(lineAngle)*electricPlateLength2;
498 zB = zA + std::cos(lineAngle)*electricPlateLength2;
500 xC = xB - std::cos(lineAngle)*electricPlateWidth2;
501 zC = zB + std::sin(lineAngle)*electricPlateWidth2;
503 xD = xC - std::sin(lineAngle)*electricPlateLength2;
504 zD = zC - std::cos(lineAngle)*electricPlateLength2;
506 slope1 = (xB-xA)/(zB-zA);
507 cte1 = xA - slope1 * zA;
509 slope2 = (xC-xB)/(zC-zB);
510 cte2 = xB - slope2 * zB;
512 slope3 = (xD-xC)/(zD-zC);
513 cte3 = xC - slope3 * zC;
515 slope4 = (xA-xD)/(zA-zD);
516 cte4 = xD - slope4 * zD;
520 x <= slope1 * z + cte1
521 && x >= slope3 * z + cte3
522 && x <= slope4 * z + cte4
523 && x >= slope2 * z + cte2
524 &&
std::abs(y)<=electricPlateSpacing2/2
529 Bfield[4] = electricFieldPlate2;