44 if (choiceModel==1)
G4cout<<
"-> Square quadrupole field"<<
G4endl;
45 if (choiceModel==2)
G4cout<<
"-> 3D quadrupole field"<<
G4endl;
46 if (choiceModel==3)
G4cout<<
"-> Enge quadrupole field"<<
G4endl;
60 const char * filename =
"OM50.grid";
63 G4cout <<
"\n-----------------------------------------------------------"
64 <<
"\n 3D Magnetic field from OPERA software "
65 <<
"\n-----------------------------------------------------------";
67 G4cout <<
"\n ---> " "Reading the field grid from " << filename <<
" ... " << endl;
68 ifstream
file( filename );
71 file >> nx >> ny >> nz;
73 G4cout <<
" [ Number of values x,y,z: "
74 << nx <<
" " << ny <<
" " << nz <<
" ] "
82 for (ix=0; ix<nx; ix++) {
83 xField[ix].resize(ny);
84 yField[ix].resize(ny);
85 zField[ix].resize(ny);
86 for (iy=0; iy<ny; iy++) {
87 xField[ix][iy].resize(nz);
88 yField[ix][iy].resize(nz);
89 zField[ix][iy].resize(nz);
94 double xval,yval,zval,bx,by,bz;
96 for (ix=0; ix<nx; ix++) {
97 for (iy=0; iy<ny; iy++) {
98 for (iz=0; iz<nz; iz++) {
99 file >> xval >> yval >> zval >> bx >> by >> bz >> permeability;
100 if ( ix==0 && iy==0 && iz==0 ) {
101 minx = xval * lenUnit;
102 miny = yval * lenUnit;
103 minz = zval * lenUnit;
105 xField[ix][iy][
iz] = bx ;
106 yField[ix][iy][
iz] = by ;
107 zField[ix][iy][
iz] = bz ;
113 maxx = xval * lenUnit;
114 maxy = yval * lenUnit;
115 maxz = zval * lenUnit;
117 G4cout <<
"\n ---> ... done reading " << endl;
120 G4cout <<
" ---> assumed the order: x, y, z, Bx, By, Bz "
121 <<
"\n ---> Min values x,y,z: "
122 << minx/
cm <<
" " << miny/
cm <<
" " << minz/
cm <<
" cm "
123 <<
"\n ---> Max values x,y,z: "
124 << maxx/
cm <<
" " << maxy/
cm <<
" " << maxz/
cm <<
" cm " << endl;
129 G4cout <<
"\n ---> Dif values x,y,z (range): "
130 << dx/
cm <<
" " << dy/
cm <<
" " << dz/
cm <<
" cm in z "
131 <<
"\n-----------------------------------------------------------" << endl;
135 for (ix=0; ix<nx; ix++)
137 for (iy=0; iy<ny; iy++)
139 for (iz=0; iz<nz; iz++)
142 xField[ix][iy][
iz] = (xField[ix][iy][
iz]/197.736);
143 yField[ix][iy][
iz] = (yField[ix][iy][
iz]/197.736);
144 zField[ix][iy][
iz] = (zField[ix][iy][
iz]/197.736);
158 double *Bfield )
const
186 gradient[0]=gradient1*(
tesla/
m)/coef;
187 gradient[1]=gradient2*(
tesla/
m)/coef;
188 gradient[2]=gradient3*(
tesla/
m)/coef;
189 gradient[3]=gradient4*(
tesla/
m)/coef;
190 gradient[4]=-gradient3*(
tesla/
m)/coef;
192 for (quad=0; quad<=4; quad++)
194 if ((quad+1)==1) {z = point[2] + 3720 *
mm;}
195 if ((quad+1)==2) {z = point[2] + 3580 *
mm;}
196 if ((quad+1)==3) {z = point[2] + 330 *
mm;}
197 if ((quad+1)==4) {z = point[2] + 190 *
mm;}
198 if ((quad+1)==5) {z = point[2] + 50 *
mm;}
204 x>=minx && x<=maxx &&
205 y>=miny && y<=maxy &&
211 double xfraction = (x - minx) / dx;
212 double yfraction = (y - miny) / dy;
213 double zfraction = (z - minz) / dz;
217 double xdindex, ydindex, zdindex;
221 double xlocal = ( std::modf(xfraction*(nx-1), &xdindex));
222 double ylocal = ( std::modf(yfraction*(ny-1), &ydindex));
223 double zlocal = ( std::modf(zfraction*(nz-1), &zdindex));
227 int xindex =
static_cast<int>(xdindex);
228 int yindex =
static_cast<int>(ydindex);
229 int zindex =
static_cast<int>(zdindex);
233 (xField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
234 xField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
235 xField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
236 xField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
237 xField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
238 xField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
239 xField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
240 xField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal)*gradient[quad]
244 (yField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
245 yField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
246 yField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
247 yField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
248 yField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
249 yField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
250 yField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
251 yField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal)*gradient[quad]
255 (zField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
256 zField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
257 zField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
258 zField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
259 zField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
260 zField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
261 zField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
262 zField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal)*gradient[quad]
293 if (z>=-3770*
mm && z<=-3670*
mm) G0 = (gradient1/coef)*
tesla/
m;
294 if (z>=-3630*
mm && z<=-3530*
mm) G0 = (gradient2/coef)*
tesla/
m;
296 if (z>=-380*
mm && z<=-280*
mm) G0 = (gradient3/coef)*
tesla/
m;
297 if (z>=-240*
mm && z<=-140*
mm) G0 = (gradient4/coef)*
tesla/
m;
298 if (z>=-100*
mm && z<=0*
mm) G0 = (-gradient3/coef)*
tesla/
m;
330 G4double Grad1, Grad2, Grad3, Grad4, Grad5;
348 if ( (z>=-3900*
mm && z<-3470*
mm) || (z>=-490*
mm && z<100*
mm) )
355 G4double c0[5],
c1[5], c2[5], z1[5], z2[5], a0[5], gradient[5];
365 gradient[0] =Grad1*(
tesla/
m)/coef;
374 gradient[1] =Grad2*(
tesla/
m)/coef;
384 gradient[2] = Grad3*(
tesla/
m)/coef;
393 gradient[3] = Grad4*(
tesla/
m)/coef;
402 gradient[4] = Grad5*(
tesla/
m)/coef;
405 G4double Bx_local,By_local,Bz_local;
406 Bx_local = 0; By_local = 0; Bz_local = 0;
414 x_local= 0; y_local=0; z_local=0;
437 for (
G4int i=0;i<5; i++)
442 zoprime = lineZ + i*140*
mm;
445 z_local = (z - zoprime);
449 zoprime = lineZ + i*140*mm +(3150-40)*mm;
453 z_local = (z - zoprime);
458 if ( z_local < -z2[i] || z_local > z2[i])
467 if ( (z_local>=-z1[i]) & (z_local<=z1[i]) )
475 if ( ((z_local>=-z2[i]) & (z_local<-z1[i])) || ((z_local>z1[i]) & (z_local<=z2[i])) )
482 P0 = c0[i]+c1[i]*
s+c2[i]*
s*
s;
484 P1 = c1[i]/a0[i]+2*c2[i]*(z_local-z1[i])/a0[i]/a0[i];
485 if (z_local<-z1[i]) P1 = -c1[i]/a0[i]+2*c2[i]*(z_local+z1[i])/a0[i]/a0[i];
487 P2 = 2*c2[i]/a0[i]/a0[i];
491 cte = 1 + std::exp(c0[i]);
493 K1 = -cte*P1*std::exp(P0)/( (1+std::exp(P0))*(1+std::exp(P0)) );
495 K2 = -cte*std::exp(P0)*(
496 P2/( (1+std::exp(P0))*(1+std::exp(P0)) )
497 +2*P1*K1/(1+std::exp(P0))/cte
498 +P1*P1/(1+std::exp(P0))/(1+std::exp(P0))
501 K3 = -cte*std::exp(P0)*(
502 (3*P2*P1+P1*P1*P1)/(1+std::exp(P0))/(1+std::exp(P0))
503 +4*K1*(P1*P1+P2)/(1+std::exp(P0))/cte
504 +2*P1*(K1*K1/cte/cte+K2/(1+std::exp(P0))/cte)
507 G0 = gradient[i]*cte/(1+std::exp(P0));
514 Bx_local = y_local*(G0-(1./12)*(3*x_local*x_local+y_local*y_local)*G2);
515 By_local = x_local*(G0-(1./12)*(3*y_local*y_local+x_local*x_local)*G2);
516 Bz_local = x_local*y_local*(G1-(1./12)*(x_local*x_local+y_local*y_local)*G3);