40Bfield::_field[200] = {0};
44 if (! _field[imap]) _field[imap] =
new Bfield(imap);
50 std::cout << std::endl;
51 std::cout <<
"***********************************************" << std::endl;
52 std::cout <<
" Bfield class MAP ID = " << imap << std::endl;
53 std::cout <<
" #### R < 174 cm, -152 < Z < 246 cm #### " << std::endl;
54 std::cout <<
" C++ version 1.00 " << std::endl;
55 std::cout <<
"***********************************************" << std::endl;
57 const float uniformBz[10] = {0, 15, 14.5, 14, 13, 12.5, 12, 11, 10, 15.5};
60 for(
int i=0; i<175; i++)
61 for(
int j=0; j<399; j++) {
71 for(
int i=0; i<17; i++)
72 for(
int j=0; j<51; j++)
73 for(
int k=0; k<52; k++) {
90 m_Bz = uniformBz[imap];
91 m_Bfld.setX((
double) m_Bx);
92 m_Bfld.setY((
double) m_By);
93 m_Bfld.setZ((
double) m_Bz);
94 std::cout <<
"Bfield class >> creating uniform B field with id = " << imap;
95 std::cout <<
", (Bx,By,Bz) = "<<m_Bfld<<std::endl;
111 std::cout << std::endl;
121 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
134 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
143 float x = position[0];
144 float y = position[1];
145 float z = position[2];
146 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
158 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);
178 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
191 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
204 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
217 if(x != m_x ||
y != m_y || z != m_z) updateCache(x,
y, z);
223Bfield::updateCache(
float x,
float y,
float z)
const{
227 if( _fieldID <= 10 )
return;
232 float r = (float)sqrt((
double)x*(
double)x + (
double)
y*(
double)
y);
233 float phi = (float)atan2((
double)
y, (
double)x);
239 int tz = (int) (( zmm + 1520.)/10.);
240 int tr = (int) (rmm/10.);
243 float bz = 0., br = 0., bphi = 0.;
245 if(zmm >= -1520. && zmm < 2460. && rmm >= 0. && rmm < 1740.){
246 if(_Bz[
tr][tz] && _Bz[
tr][tz+1]){
247 float pz = (zmm + 1520.)/10.- (
float)tz;
248 float pr = rmm/10.- (float)
tr;
251 bz = (_Bz[
tr][tz]*(1.- pz)+_Bz[
tr][tz+1]*pz)*(1.-pr)+
252 (_Bz[
tr+1][tz]*(1.-pz)+_Bz[
tr+1][tz+1]*pz)*pr;
254 br = (_Br[
tr][tz]*(1.-pz)+_Br[
tr][tz+1]*pz)*(1.-pr)+
255 (_Br[
tr+1][tz]*(1.-pz)+_Br[
tr+1][tz+1]*pz)*pr;
257 bphi = (_Bphi[
tr][tz]*(1.-pz)+_Bphi[
tr][tz+1]*pz)*(1.-pr)+
258 (_Bphi[
tr+1][tz]*(1.-pz)+_Bphi[
tr+1][tz+1]*pz)*pr;
264 if( zmm>=800. && zmm < 2420. && rmm < 1000. ) {
265 int tqz = (int)( (zmm-800.)/10. );
266 bz += (((_BzQR[
tr][tqz]*(1.-pz)+_BzQR[
tr][tqz+1]*pz)*(1.-pr)
267 +(_BzQR[
tr+1][tqz]*(1.-pz)+_BzQR[
tr+1][tqz+1]*pz)*pr)
268 *(float)
sin((
double)(2.*phi+2./180.*(
double)
PI)));
269 br += (((_BrQR[
tr][tqz]*(1.-pz)+_BrQR[
tr][tqz+1]*pz)*(1.-pr)
270 +(_BrQR[
tr+1][tqz]*(1.-pz)+_BrQR[
tr+1][tqz+1]*pz)*pr)
271 *(float)
sin((
double)(2.*phi+2./180.*(
double)
PI)));
272 bphi += (((_BphiQR[
tr][tqz]*(1.-pz)
273 +_BphiQR[
tr][tqz+1]*pz)*(1.-pr)
274 +(_BphiQR[
tr+1][tqz]*(1.-pz)
275 +_BphiQR[
tr+1][tqz+1]*pz)*pr)
276 *(float)
cos((
double)(2.*phi+2./180.*(
double)
PI)));
281 if(zmm<=-500. && zmm>-1520. && rmm<1000.) {
282 int tqz = (int)((-zmm-500.)/20.);
283 int tqr = (int)(
tr/2.);
284 pz = (pz+(float)( tz-(int)(tz/2.)*2. ))/2.;
285 pr = ( pr + (float)(
tr-tqr*2) )/2.;
295 if( phi_tmp < (
PI/2.) && phi_tmp >= (-
PI/2.) ) {
296 phi_tmp =
PI-phi_tmp;
298 }
else if( phi_tmp < -
PI/2. ) {
299 phi_tmp = 2.*
PI+phi_tmp;
301 float pphi = ( phi_tmp-
PI/2. )/(11.25/180.*
PI);
302 int tphi = (int)pphi;
304 if (tphi >= 16) tphi -= 16;
307 (((_BzQL[tphi][tqr][tqz]*(1.-pz)+_BzQL[tphi][tqr][tqz+1]*pz)
308 *(1-pr)+(_BzQL[tphi][tqr+1][tqz]*(1.-pz)
309 +_BzQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1.-pphi)
310 +((_BzQL[tphi+1][tqr][tqz]*(1.-pz)
311 +_BzQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
312 +(_BzQL[tphi+1][tqr+1][tqz]*(1.-pz)
313 +_BzQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
315 (((_BrQL[tphi][tqr][tqz]*(1.- pz)
316 +_BrQL[tphi][tqr][tqz+1]*pz)*(1.-pr)
317 +(_BrQL[tphi][tqr+1][tqz]*(1.-pz)
318 +_BrQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1-pphi)
319 +((_BrQL[tphi+1][tqr][tqz]*(1.- pz)
320 +_BrQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
321 +(_BrQL[tphi+1][tqr+1][tqz]*(1.-pz)
322 +_BrQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
324 (((_BphiQL[tphi][tqr][tqz]*(1.- pz)
325 +_BphiQL[tphi][tqr][tqz+1]*pz)*(1.-pr)
326 +(_BphiQL[tphi][tqr+1][tqz]*(1.-pz)
327 +_BphiQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1.-pphi)
328 +((_BphiQL[tphi+1][tqr][tqz]*(1.- pz)
329 +_BphiQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
330 +(_BphiQL[tphi+1][tqr+1][tqz]*(1.-pz)
331 +_BphiQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
339 }
else if(zmm>=-1520. && zmm<=2460. && rmm<=0. && rmm<=1740.){
340 if(tz == 246) tz=tz-1;
342 float pz= (zmm + 1520.)/10.- (
float)tz;
343 float pr= rmm/10.- (float)
tr;
344 bz = (_Bz[
tr][tz]*(1.- pz)+_Bz[
tr][tz+1]*pz)*(1.-pr)+
345 (_Bz[
tr+1][tz]*(1.-pz)+_Bz[
tr+1][tz+1]*pz)*pr;
347 br = (_Br[
tr][tz]*(1.-pz)+_Br[
tr][tz+1]*pz)*(1.-pr)+
348 (_Br[
tr+1][tz]*(1.-pz)+_Br[
tr+1][tz+1]*pz)*pr;
350 bphi = (_Bphi[
tr][tz]*(1.-pz)+_Bphi[
tr][tz+1]*pz)*(1.-pr)+
351 (_Bphi[
tr+1][tz]*(1.-pz)+_Bphi[
tr+1][tz+1]*pz)*pr;
360 float Bmag_xy = (float)sqrt(br*br + bphi*bphi);
361 double Bphi_rp = (float)atan2( (
double)bphi, (
double)br );
362 m_Bx = Bmag_xy * (float)
cos((
double)phi + Bphi_rp)/1000.;
363 m_By = Bmag_xy * (float)
sin((
double)phi + Bphi_rp)/1000.;
370 m_Bfld.setX((
double) m_Bx);
371 m_Bfld.setY((
double) m_By);
372 m_Bfld.setZ((
double) m_Bz);
double sin(const BesAngle a)
double cos(const BesAngle a)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
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.