13#include "TrackUtil/Bfield.h"
16Bfield* Bfield::_field[200] = { 0 };
19 if ( !_field[imap] ) _field[imap] =
new Bfield( imap );
24 std::cout << std::endl;
25 std::cout <<
"***********************************************" << std::endl;
26 std::cout <<
" Bfield class MAP ID = " << imap << std::endl;
27 std::cout <<
" #### R < 174 cm, -152 < Z < 246 cm #### " << std::endl;
28 std::cout <<
" C++ version 1.00 " << std::endl;
29 std::cout <<
"***********************************************" << std::endl;
31 const float uniformBz[10] = { 0, 15, 14.5, 14, 13, 12.5, 12, 11, 10, 15.5 };
34 for (
int i = 0; i < 175; i++ )
35 for (
int j = 0; j < 399; j++ )
40 if ( i < 101 && j < 163 )
47 for (
int i = 0; i < 17; i++ )
48 for (
int j = 0; j < 51; j++ )
49 for (
int k = 0; k < 52; k++ )
68 m_Bz = uniformBz[imap];
69 m_Bfld.setX( (
double)m_Bx );
70 m_Bfld.setY( (
double)m_By );
71 m_Bfld.setZ( (
double)m_Bz );
72 std::cout <<
"Bfield class >> creating uniform B field with id = " << imap;
73 std::cout <<
", (Bx,By,Bz) = " << m_Bfld << std::endl;
91 std::cout << std::endl;
100 if ( x != m_x || y != m_y || z != m_z ) updateCache( x, y, z );
113 if ( x != m_x || y != m_y || z != m_z ) updateCache( x, y, z );
122 float x = position[0];
123 float y = position[1];
124 float z = position[2];
125 if ( x != m_x || y != m_y || z != m_z ) updateCache( x, y, z );
137 if ( x != m_x || y != m_y || z != m_z ) updateCache( x, y, z );
147 if ( x != m_x || y != m_y || z != m_z ) updateCache( x, y, z );
157 if ( x != m_x || y != m_y || z != m_z ) updateCache( x, y, z );
170 if ( x != m_x || y != m_y || z != m_z ) updateCache( x, y, z );
183 if ( x != m_x || y != m_y || z != m_z ) updateCache( x, y, z );
196 if ( x != m_x || y != m_y || z != m_z ) updateCache( x, y, z );
201void Bfield::updateCache(
float x,
float y,
float z )
const {
205 if ( _fieldID <= 10 )
return;
210 float r = (float)sqrt( (
double)x * (
double)x + (
double)y * (
double)y );
211 float phi = (float)atan2( (
double)y, (
double)x );
217 int tz = (int)( ( zmm + 1520. ) / 10. );
218 int tr = (int)( rmm / 10. );
221 float bz = 0., br = 0., bphi = 0.;
223 if ( zmm >= -1520. && zmm < 2460. && rmm >= 0. && rmm < 1740. )
225 if ( _Bz[
tr][tz] && _Bz[
tr][tz + 1] )
227 float pz = ( zmm + 1520. ) / 10. - (
float)tz;
228 float pr = rmm / 10. - (float)
tr;
231 bz = ( _Bz[
tr][tz] * ( 1. - pz ) + _Bz[
tr][tz + 1] * pz ) * ( 1. - pr ) +
232 ( _Bz[
tr + 1][tz] * ( 1. - pz ) + _Bz[
tr + 1][tz + 1] * pz ) * pr;
234 br = ( _Br[
tr][tz] * ( 1. - pz ) + _Br[
tr][tz + 1] * pz ) * ( 1. - pr ) +
235 ( _Br[
tr + 1][tz] * ( 1. - pz ) + _Br[
tr + 1][tz + 1] * pz ) * pr;
237 bphi = ( _Bphi[
tr][tz] * ( 1. - pz ) + _Bphi[
tr][tz + 1] * pz ) * ( 1. - pr ) +
238 ( _Bphi[
tr + 1][tz] * ( 1. - pz ) + _Bphi[
tr + 1][tz + 1] * pz ) * pr;
240 if ( _fieldID == 21 )
245 if ( zmm >= 800. && zmm < 2420. && rmm < 1000. )
247 int tqz = (int)( ( zmm - 800. ) / 10. );
248 bz += ( ( ( _BzQR[
tr][tqz] * ( 1. - pz ) + _BzQR[
tr][tqz + 1] * pz ) * ( 1. - pr ) +
249 ( _BzQR[
tr + 1][tqz] * ( 1. - pz ) + _BzQR[
tr + 1][tqz + 1] * pz ) * pr ) *
250 (float)
sin( (
double)( 2. * phi + 2. / 180. * (
double)
PI ) ) );
251 br += ( ( ( _BrQR[
tr][tqz] * ( 1. - pz ) + _BrQR[
tr][tqz + 1] * pz ) * ( 1. - pr ) +
252 ( _BrQR[
tr + 1][tqz] * ( 1. - pz ) + _BrQR[
tr + 1][tqz + 1] * pz ) * pr ) *
253 (float)
sin( (
double)( 2. * phi + 2. / 180. * (
double)
PI ) ) );
254 bphi += ( ( ( _BphiQR[
tr][tqz] * ( 1. - pz ) + _BphiQR[
tr][tqz + 1] * pz ) *
256 ( _BphiQR[
tr + 1][tqz] * ( 1. - pz ) + _BphiQR[
tr + 1][tqz + 1] * pz ) *
258 (float)
cos( (
double)( 2. * phi + 2. / 180. * (
double)
PI ) ) );
263 if ( zmm <= -500. && zmm > -1520. && rmm < 1000. )
265 int tqz = (int)( ( -zmm - 500. ) / 20. );
266 int tqr = (int)(
tr / 2. );
267 pz = ( pz + (float)( tz - (int)( tz / 2. ) * 2. ) ) / 2.;
268 pr = ( pr + (float)(
tr - tqr * 2 ) ) / 2.;
271 if ( phi_tmp < (
PI / 2. ) && phi_tmp >= ( -
PI / 2. ) )
273 phi_tmp =
PI - phi_tmp;
276 else if ( phi_tmp < -
PI / 2. ) { phi_tmp = 2. *
PI + phi_tmp; }
277 float pphi = ( phi_tmp -
PI / 2. ) / ( 11.25 / 180. *
PI );
278 int tphi = (int)pphi;
280 if ( tphi >= 16 ) tphi -= 16;
283 ( ( ( _BzQL[tphi][tqr][tqz] * ( 1. - pz ) + _BzQL[tphi][tqr][tqz + 1] * pz ) *
285 ( _BzQL[tphi][tqr + 1][tqz] * ( 1. - pz ) +
286 _BzQL[tphi][tqr + 1][tqz + 1] * pz ) *
289 ( ( _BzQL[tphi + 1][tqr][tqz] * ( 1. - pz ) +
290 _BzQL[tphi + 1][tqr][tqz + 1] * pz ) *
292 ( _BzQL[tphi + 1][tqr + 1][tqz] * ( 1. - pz ) +
293 _BzQL[tphi + 1][tqr + 1][tqz + 1] * pz ) *
297 ( ( ( _BrQL[tphi][tqr][tqz] * ( 1. - pz ) + _BrQL[tphi][tqr][tqz + 1] * pz ) *
299 ( _BrQL[tphi][tqr + 1][tqz] * ( 1. - pz ) +
300 _BrQL[tphi][tqr + 1][tqz + 1] * pz ) *
303 ( ( _BrQL[tphi + 1][tqr][tqz] * ( 1. - pz ) +
304 _BrQL[tphi + 1][tqr][tqz + 1] * pz ) *
306 ( _BrQL[tphi + 1][tqr + 1][tqz] * ( 1. - pz ) +
307 _BrQL[tphi + 1][tqr + 1][tqz + 1] * pz ) *
310 bphi +=
f * ( ( ( _BphiQL[tphi][tqr][tqz] * ( 1. - pz ) +
311 _BphiQL[tphi][tqr][tqz + 1] * pz ) *
313 ( _BphiQL[tphi][tqr + 1][tqz] * ( 1. - pz ) +
314 _BphiQL[tphi][tqr + 1][tqz + 1] * pz ) *
317 ( ( _BphiQL[tphi + 1][tqr][tqz] * ( 1. - pz ) +
318 _BphiQL[tphi + 1][tqr][tqz + 1] * pz ) *
320 ( _BphiQL[tphi + 1][tqr + 1][tqz] * ( 1. - pz ) +
321 _BphiQL[tphi + 1][tqr + 1][tqz + 1] * pz ) *
334 else if ( zmm >= -1520. && zmm <= 2460. && rmm <= 0. && rmm <= 1740. )
336 if ( tz == 246 ) tz = tz - 1;
337 if (
tr == 174 )
tr =
tr - 1;
338 float pz = ( zmm + 1520. ) / 10. - (
float)tz;
339 float pr = rmm / 10. - (float)
tr;
340 bz = ( _Bz[
tr][tz] * ( 1. - pz ) + _Bz[
tr][tz + 1] * pz ) * ( 1. - pr ) +
341 ( _Bz[
tr + 1][tz] * ( 1. - pz ) + _Bz[
tr + 1][tz + 1] * pz ) * pr;
343 br = ( _Br[
tr][tz] * ( 1. - pz ) + _Br[
tr][tz + 1] * pz ) * ( 1. - pr ) +
344 ( _Br[
tr + 1][tz] * ( 1. - pz ) + _Br[
tr + 1][tz + 1] * pz ) * pr;
346 bphi = ( _Bphi[
tr][tz] * ( 1. - pz ) + _Bphi[
tr][tz + 1] * pz ) * ( 1. - pr ) +
347 ( _Bphi[
tr + 1][tz] * ( 1. - pz ) + _Bphi[
tr + 1][tz + 1] * pz ) * pr;
357 float Bmag_xy = (float)sqrt( br * br + bphi * bphi );
358 double Bphi_rp = (float)atan2( (
double)bphi, (
double)br );
359 m_Bx = Bmag_xy * (float)
cos( (
double)phi + Bphi_rp ) / 1000.;
360 m_By = Bmag_xy * (float)
sin( (
double)phi + Bphi_rp ) / 1000.;
365 m_Bfld.setX( (
double)m_Bx );
366 m_Bfld.setY( (
double)m_By );
367 m_Bfld.setZ( (
double)m_Bz );
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
double sin(const BesAngle a)
double cos(const BesAngle a)
HepGeom::Point3D< double > HepPoint3D
Bfield(int)
Constructor, Destructor.
float by(float x, float y, float z) const
float bz(float x, float y, float z) const
float bx(float x, float y, float z) const
returns an element of B field
static Bfield * getBfield(int)
returns Bfield object.
const Hep3Vector & fieldMap(float x, float y, float z) const
returns B field