45 if (choiceModel==1)
G4cout<<
"-> Square quadrupole field"<<
G4endl;
46 if (choiceModel==2)
G4cout<<
"-> 3D quadrupole field"<<
G4endl;
47 if (choiceModel==3)
G4cout<<
"-> Enge quadrupole field"<<
G4endl;
61 const char * filename =
"OM50.grid";
64 G4cout <<
"\n-----------------------------------------------------------"
65 <<
"\n 3D Magnetic field from OPERA software "
66 <<
"\n-----------------------------------------------------------";
68 G4cout <<
"\n ---> " "Reading the field grid from " << filename <<
" ... " << endl;
69 ifstream file( filename );
72 file >> fNx >> fNy >> fNz;
74 G4cout <<
" [ Number of values x,y,z: "
75 << fNx <<
" " << fNy <<
" " << fNz <<
" ] "
79 fXField.resize( fNx );
80 fYField.resize( fNx );
81 fZField.resize( fNx );
83 for (ix=0; ix<fNx; ix++) {
84 fXField[ix].resize(fNy);
85 fYField[ix].resize(fNy);
86 fZField[ix].resize(fNy);
87 for (iy=0; iy<fNy; iy++) {
88 fXField[ix][iy].resize(fNz);
89 fYField[ix][iy].resize(fNz);
90 fZField[ix][iy].resize(fNz);
95 double xval,yval,zval,bx,by,bz;
97 for (ix=0; ix<fNx; ix++) {
98 for (iy=0; iy<fNy; iy++) {
99 for (iz=0; iz<fNz; iz++) {
100 file >> xval >> yval >> zval >> bx >> by >> bz >> permeability;
101 if ( ix==0 && iy==0 && iz==0 ) {
102 fMinix = xval * lenUnit;
103 fMiniy = yval * lenUnit;
104 fMiniz = zval * lenUnit;
106 fXField[ix][iy][iz] = bx ;
107 fYField[ix][iy][iz] = by ;
108 fZField[ix][iy][iz] = bz ;
114 fMaxix = xval * lenUnit;
115 fMaxiy = yval * lenUnit;
116 fMaxiz = zval * lenUnit;
118 G4cout <<
"\n ---> ... done reading " << endl;
121 G4cout <<
" ---> assumed the order: x, y, z, Bx, By, Bz "
122 <<
"\n ---> Min values x,y,z: "
123 << fMinix/
cm <<
" " << fMiniy/
cm <<
" " << fMiniz/
cm <<
" cm "
124 <<
"\n ---> Max values x,y,z: "
125 << fMaxix/
cm <<
" " << fMaxiy/
cm <<
" " << fMaxiz/
cm <<
" cm " << endl;
127 fDx = fMaxix - fMinix;
128 fDy = fMaxiy - fMiniy;
129 fDz = fMaxiz - fMiniz;
130 G4cout <<
"\n ---> Dif values x,y,z (range): "
131 << fDx/
cm <<
" " << fDy/
cm <<
" " << fDz/
cm <<
" cm in z "
132 <<
"\n-----------------------------------------------------------" << endl;
136 for (ix=0; ix<fNx; ix++)
138 for (iy=0; iy<fNy; iy++)
140 for (iz=0; iz<fNz; iz++)
143 fXField[ix][iy][iz] = (fXField[ix][iy][iz]/197.736);
144 fYField[ix][iy][iz] = (fYField[ix][iy][iz]/197.736);
145 fZField[ix][iy][iz] = (fZField[ix][iy][iz]/197.736);
159 double *Bfield )
const
187 gradient[0]=fGradient1*(
tesla/
m)/coef;
188 gradient[1]=fGradient2*(
tesla/
m)/coef;
189 gradient[2]=fGradient3*(
tesla/
m)/coef;
190 gradient[3]=fGradient4*(
tesla/
m)/coef;
191 gradient[4]=-fGradient3*(
tesla/
m)/coef;
193 for (quad=0; quad<=4; quad++)
195 if ((quad+1)==1) {z = point[2] + 3720 *
mm;}
196 if ((quad+1)==2) {z = point[2] + 3580 *
mm;}
197 if ((quad+1)==3) {z = point[2] + 330 *
mm;}
198 if ((quad+1)==4) {z = point[2] + 190 *
mm;}
199 if ((quad+1)==5) {z = point[2] + 50 *
mm;}
205 x>=fMinix && x<=fMaxix &&
206 y>=fMiniy && y<=fMaxiy &&
207 z>=fMiniz && z<=fMaxiz
212 double xfraction = (x - fMinix) / fDx;
213 double yfraction = (y - fMiniy) / fDy;
214 double zfraction = (z - fMiniz) / fDz;
218 double xdindex, ydindex, zdindex;
222 double xlocal = ( std::modf(xfraction*(fNx-1), &xdindex));
223 double ylocal = ( std::modf(yfraction*(fNy-1), &ydindex));
224 double zlocal = ( std::modf(zfraction*(fNz-1), &zdindex));
228 int xindex =
static_cast<int>(xdindex);
229 int yindex =
static_cast<int>(ydindex);
230 int zindex =
static_cast<int>(zdindex);
234 (fXField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
235 fXField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
236 fXField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
237 fXField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
238 fXField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
239 fXField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
240 fXField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
241 fXField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal)*gradient[quad]
245 (fYField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
246 fYField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
247 fYField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
248 fYField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
249 fYField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
250 fYField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
251 fYField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
252 fYField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal)*gradient[quad]
256 (fZField[xindex ][yindex ][zindex ] * (1-xlocal) * (1-ylocal) * (1-zlocal) +
257 fZField[xindex ][yindex ][zindex+1] * (1-xlocal) * (1-ylocal) * zlocal +
258 fZField[xindex ][yindex+1][zindex ] * (1-xlocal) * ylocal * (1-zlocal) +
259 fZField[xindex ][yindex+1][zindex+1] * (1-xlocal) * ylocal * zlocal +
260 fZField[xindex+1][yindex ][zindex ] * xlocal * (1-ylocal) * (1-zlocal) +
261 fZField[xindex+1][yindex ][zindex+1] * xlocal * (1-ylocal) * zlocal +
262 fZField[xindex+1][yindex+1][zindex ] * xlocal * ylocal * (1-zlocal) +
263 fZField[xindex+1][yindex+1][zindex+1] * xlocal * ylocal * zlocal)*gradient[quad]
294 if (z>=-3770*
mm && z<=-3670*
mm) G0 = (fGradient1/coef)*
tesla/
m;
295 if (z>=-3630*
mm && z<=-3530*
mm) G0 = (fGradient2/coef)*
tesla/
m;
297 if (z>=-380*
mm && z<=-280*
mm) G0 = (fGradient3/coef)*
tesla/
m;
298 if (z>=-240*
mm && z<=-140*
mm) G0 = (fGradient4/coef)*
tesla/
m;
299 if (z>=-100*
mm && z<=0*
mm) G0 = (-fGradient3/coef)*
tesla/
m;
331 G4double Grad1, Grad2, Grad3, Grad4, Grad5;
349 if ( (z>=-3900*
mm && z<-3470*
mm) || (z>=-490*
mm && z<100*
mm) )
367 gradient[0] =Grad1*(
tesla/
m)/coef;
376 gradient[1] =Grad2*(
tesla/
m)/coef;
387 gradient[2] = Grad3*(
tesla/
m)/coef;
396 gradient[3] = Grad4*(
tesla/
m)/coef;
405 gradient[4] = Grad5*(
tesla/
m)/coef;
408 G4double Bx_local,By_local,Bz_local;
409 Bx_local = 0; By_local = 0; Bz_local = 0;
413 x_local= 0; y_local=0; z_local=0;
435 for (
G4int i=0;i<5; i++)
440 zoprime = lineZ + i*140*
mm;
443 z_local = (z - zoprime);
447 zoprime = lineZ + i*140*mm +(3150-40)*mm;
451 z_local = (z - zoprime);
455 if ( z_local < -z2[i] || z_local > z2[i])
463 if ( (z_local>=-z1[i]) && (z_local<=z1[i]) )
471 if ( ((z_local>=-z2[i]) && (z_local<-z1[i])) || ((z_local>z1[i]) && (z_local<=z2[i])) )
474 myVars = ( z_local - z1[i]) / a0[i];
475 if (z_local<-z1[i]) myVars = ( - z_local - z1[i]) / a0[i];
478 P0 = c0[i]+c1[i]*myVars+c2[i]*myVars*myVars;
480 P1 = c1[i]/a0[i]+2*c2[i]*(z_local-z1[i])/a0[i]/a0[i];
481 if (z_local<-z1[i]) P1 = -c1[i]/a0[i]+2*c2[i]*(z_local+z1[i])/a0[i]/a0[i];
483 P2 = 2*c2[i]/a0[i]/a0[i];
485 cte = 1 +
G4Exp(c0[i]);
489 K2 = -cte*
G4Exp(P0)*(
491 +2*P1*K1/(1+
G4Exp(P0))/cte
495 K3 = -cte*
G4Exp(P0)*(
497 +4*K1*(P1*P1+P2)/(1+
G4Exp(P0))/cte
498 +2*P1*(K1*K1/cte/cte+K2/(1+
G4Exp(P0))/cte)
501 G0 = gradient[i]*cte/(1+
G4Exp(P0));
508 Bx_local = y_local*(G0-(1./12)*(3*x_local*x_local+y_local*y_local)*G2);
509 By_local = x_local*(G0-(1./12)*(3*y_local*y_local+x_local*x_local)*G2);
510 Bz_local = x_local*y_local*(G1-(1./12)*(x_local*x_local+y_local*y_local)*G3);
static constexpr double tesla
static c2_factory< G4double > c2
static constexpr double mm
static const G4double * P1[nN]
void GetFieldValue(const double Point[4], double *Bfield) const
static const G4double * P0[nN]
TabulatedField3D(G4float gr1, G4float gr2, G4float gr3, G4float gr4, G4int quadModel)
G4GLOB_DLL std::ostream G4cout
static constexpr double m
static constexpr double cm
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
static const G4double * P2[nN]