17Bfield::_field[200] = {0};
21 if (! _field[imap]) _field[imap] =
new Bfield(imap);
27 std::cout << std::endl;
28 std::cout <<
"***********************************************" << std::endl;
29 std::cout <<
" Bfield class MAP ID = " << imap << std::endl;
30 std::cout <<
" #### R < 174 cm, -152 < Z < 246 cm #### " << std::endl;
31 std::cout <<
" C++ version 1.00 " << std::endl;
32 std::cout <<
"***********************************************" << std::endl;
34 const float uniformBz[10] = {0, 15, 14.5, 14, 13, 12.5, 12, 11, 10, 15.5};
37 for(
int i=0; i<175; i++)
38 for(
int j=0; j<399; j++) {
48 for(
int i=0; i<17; i++)
49 for(
int j=0; j<51; j++)
50 for(
int k=0; k<52; k++) {
67 m_Bz = uniformBz[imap];
68 m_Bfld.setX((
double) m_Bx);
69 m_Bfld.setY((
double) m_By);
70 m_Bfld.setZ((
double) m_Bz);
71 std::cout <<
"Bfield class >> creating uniform B field with id = " << imap;
72 std::cout <<
", (Bx,By,Bz) = "<<m_Bfld<<std::endl;
88 std::cout << std::endl;
98 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
111 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
120 float x = position[0];
121 float y = position[1];
122 float z = position[2];
123 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
135 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
145 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
155 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
168 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
181 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
194 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
200Bfield::updateCache(
float x,
float y,
float z)
const{
204 if( _fieldID <= 10 )
return;
209 float r = (float)sqrt((
double)
x*(double)x + (
double)
y*(double)
y);
210 float phi = (float)atan2((
double)
y, (double)x);
216 int tz = (int) (( zmm + 1520.)/10.);
217 int tr = (int) (rmm/10.);
220 float bz = 0., br = 0., bphi = 0.;
222 if(zmm >= -1520. && zmm < 2460. && rmm >= 0. && rmm < 1740.){
223 if(_Bz[
tr][tz] && _Bz[
tr][tz+1]){
224 float pz = (zmm + 1520.)/10.- (
float)tz;
225 float pr = rmm/10.- (float)
tr;
228 bz = (_Bz[
tr][tz]*(1.- pz)+_Bz[
tr][tz+1]*pz)*(1.-pr)+
229 (_Bz[
tr+1][tz]*(1.-pz)+_Bz[
tr+1][tz+1]*pz)*pr;
231 br = (_Br[
tr][tz]*(1.-pz)+_Br[
tr][tz+1]*pz)*(1.-pr)+
232 (_Br[
tr+1][tz]*(1.-pz)+_Br[
tr+1][tz+1]*pz)*pr;
234 bphi = (_Bphi[
tr][tz]*(1.-pz)+_Bphi[
tr][tz+1]*pz)*(1.-pr)+
235 (_Bphi[
tr+1][tz]*(1.-pz)+_Bphi[
tr+1][tz+1]*pz)*pr;
241 if( zmm>=800. && zmm < 2420. && rmm < 1000. ) {
242 int tqz = (int)( (zmm-800.)/10. );
243 bz += (((_BzQR[
tr][tqz]*(1.-pz)+_BzQR[
tr][tqz+1]*pz)*(1.-pr)
244 +(_BzQR[
tr+1][tqz]*(1.-pz)+_BzQR[
tr+1][tqz+1]*pz)*pr)
245 *(float)
sin((
double)(2.*phi+2./180.*(double)
PI)));
246 br += (((_BrQR[
tr][tqz]*(1.-pz)+_BrQR[
tr][tqz+1]*pz)*(1.-pr)
247 +(_BrQR[
tr+1][tqz]*(1.-pz)+_BrQR[
tr+1][tqz+1]*pz)*pr)
248 *(float)
sin((
double)(2.*phi+2./180.*(double)
PI)));
249 bphi += (((_BphiQR[
tr][tqz]*(1.-pz)
250 +_BphiQR[
tr][tqz+1]*pz)*(1.-pr)
251 +(_BphiQR[
tr+1][tqz]*(1.-pz)
252 +_BphiQR[
tr+1][tqz+1]*pz)*pr)
253 *(float)
cos((
double)(2.*phi+2./180.*(double)
PI)));
258 if(zmm<=-500. && zmm>-1520. && rmm<1000.) {
259 int tqz = (int)((-zmm-500.)/20.);
260 int tqr = (int)(
tr/2.);
261 pz = (pz+(float)( tz-(
int)(tz/2.)*2. ))/2.;
262 pr = ( pr + (float)(
tr-tqr*2) )/2.;
265 if( phi_tmp < (
PI/2.) && phi_tmp >= (-
PI/2.) ) {
266 phi_tmp =
PI-phi_tmp;
268 }
else if( phi_tmp < -
PI/2. ) {
269 phi_tmp = 2.*
PI+phi_tmp;
271 float pphi = ( phi_tmp-
PI/2. )/(11.25/180.*
PI);
272 int tphi = (int)pphi;
274 if (tphi >= 16) tphi -= 16;
277 (((_BzQL[tphi][tqr][tqz]*(1.-pz)+_BzQL[tphi][tqr][tqz+1]*pz)
278 *(1-pr)+(_BzQL[tphi][tqr+1][tqz]*(1.-pz)
279 +_BzQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1.-pphi)
280 +((_BzQL[tphi+1][tqr][tqz]*(1.-pz)
281 +_BzQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
282 +(_BzQL[tphi+1][tqr+1][tqz]*(1.-pz)
283 +_BzQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
285 (((_BrQL[tphi][tqr][tqz]*(1.- pz)
286 +_BrQL[tphi][tqr][tqz+1]*pz)*(1.-pr)
287 +(_BrQL[tphi][tqr+1][tqz]*(1.-pz)
288 +_BrQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1-pphi)
289 +((_BrQL[tphi+1][tqr][tqz]*(1.- pz)
290 +_BrQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
291 +(_BrQL[tphi+1][tqr+1][tqz]*(1.-pz)
292 +_BrQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
294 (((_BphiQL[tphi][tqr][tqz]*(1.- pz)
295 +_BphiQL[tphi][tqr][tqz+1]*pz)*(1.-pr)
296 +(_BphiQL[tphi][tqr+1][tqz]*(1.-pz)
297 +_BphiQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1.-pphi)
298 +((_BphiQL[tphi+1][tqr][tqz]*(1.- pz)
299 +_BphiQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
300 +(_BphiQL[tphi+1][tqr+1][tqz]*(1.-pz)
301 +_BphiQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
309 }
else if(zmm>=-1520. && zmm<=2460. && rmm<=0. && rmm<=1740.){
310 if(tz == 246) tz=tz-1;
312 float pz= (zmm + 1520.)/10.- (
float)tz;
313 float pr= rmm/10.- (float)
tr;
314 bz = (_Bz[
tr][tz]*(1.- pz)+_Bz[
tr][tz+1]*pz)*(1.-pr)+
315 (_Bz[
tr+1][tz]*(1.-pz)+_Bz[
tr+1][tz+1]*pz)*pr;
317 br = (_Br[
tr][tz]*(1.-pz)+_Br[
tr][tz+1]*pz)*(1.-pr)+
318 (_Br[
tr+1][tz]*(1.-pz)+_Br[
tr+1][tz+1]*pz)*pr;
320 bphi = (_Bphi[
tr][tz]*(1.-pz)+_Bphi[
tr][tz+1]*pz)*(1.-pr)+
321 (_Bphi[
tr+1][tz]*(1.-pz)+_Bphi[
tr+1][tz+1]*pz)*pr;
330 float Bmag_xy = (float)sqrt(br*br + bphi*bphi);
331 double Bphi_rp = (float)atan2( (
double)bphi, (double)br );
332 m_Bx = Bmag_xy * (float)
cos((
double)phi + Bphi_rp)/1000.;
333 m_By = Bmag_xy * (float)
sin((
double)phi + Bphi_rp)/1000.;
338 m_Bfld.setX((
double) m_Bx);
339 m_Bfld.setY((
double) m_By);
340 m_Bfld.setZ((
double) m_Bz);
double sin(const BesAngle a)
double cos(const BesAngle a)
Bfield(int)
Constructor, Destructor.
double bz(double x, double y, double z) const
const Hep3Vector & fieldMap(double x, double y, double z) const
returns B field
double by(double x, double y, double z) const
double bx(double x, double y, double z) const
returns an element of B field
static Bfield * getBfield(int)
returns Bfield object.
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")