17#include "CLHEP/Matrix/Vector.h"
18#include "CLHEP/Matrix/Matrix.h"
19#include "CLHEP/Matrix/SymMatrix.h"
20#include "CLHEP/Vector/ThreeVector.h"
21#include "CLHEP/Geometry/Point3D.h"
22#ifndef ENABLE_BACKWARDS_COMPATIBILITY
28using CLHEP::HepVector;
29using CLHEP::Hep3Vector;
30using CLHEP::HepMatrix;
31using CLHEP::HepSymMatrix;
49Bfield::_field[200] = {0};
53 if (! _field[imap]) _field[imap] =
new Bfield(imap);
59 std::cout << std::endl;
60 std::cout <<
"***********************************************" << std::endl;
61 std::cout <<
" Bfield class MAP ID = " << imap << std::endl;
62 std::cout <<
" #### R < 174 cm, -152 < Z < 246 cm #### " << std::endl;
63 std::cout <<
" C++ version 1.00 " << std::endl;
64 std::cout <<
"***********************************************" << std::endl;
66 const double uniformBz[10] = {0, 15, 14.5, 14, 13, 12.5, 12, 11, 10, 15.5};
69 for(
int i=0; i<175; i++)
70 for(
int j=0; j<399; j++) {
80 for(
int i=0; i<17; i++)
81 for(
int j=0; j<51; j++)
82 for(
int k=0; k<52; k++) {
99 m_Bz = uniformBz[imap];
100 m_Bfld.setX((
double) m_Bx);
101 m_Bfld.setY((
double) m_By);
102 m_Bfld.setZ((
double) m_Bz);
103 std::cout <<
"Bfield class >> creating uniform B field with id = " << imap;
104 std::cout <<
", (Bx,By,Bz) = "<<m_Bfld<<std::endl;
109 std::cout <<
"Bfield class >> loading non-uniform B field map" << std::endl;
118 updateCache(0., 0., 0.);
120 std::cout << std::endl;
130 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
143 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
152 double x = position[0];
153 double y = position[1];
154 double z = position[2];
155 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
167 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
177 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
187 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
200 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
213 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
226 if(
x != m_x ||
y != m_y || z != m_z) updateCache(
x,
y, z);
232Bfield::updateCache(
double x,
double y,
double z)
const{
236 if( _fieldID <= 10 )
return;
241 double r = (double)sqrt((
double)
x*(double)x + (
double)
y*(double)
y);
242 double phi = (double)atan2((
double)
y, (double)x);
245 double zmm = z * 10.;
246 double rmm = r * 10.;
248 int tz = (int) (( zmm + 1520.)/10.);
249 int tr = (int) (rmm/10.);
252 double bz = 0., br = 0., bphi = 0.;
254 if(zmm >= -1520. && zmm < 2460. && rmm >= 0. && rmm < 1740.){
255 if(_Bz[
tr][tz] && _Bz[
tr][tz+1]){
256 double pz = (zmm + 1520.)/10.- (
double)tz;
257 double pr = rmm/10.- (double)
tr;
260 bz = (_Bz[
tr][tz]*(1.- pz)+_Bz[
tr][tz+1]*pz)*(1.-pr)+
261 (_Bz[
tr+1][tz]*(1.-pz)+_Bz[
tr+1][tz+1]*pz)*pr;
263 br = (_Br[
tr][tz]*(1.-pz)+_Br[
tr][tz+1]*pz)*(1.-pr)+
264 (_Br[
tr+1][tz]*(1.-pz)+_Br[
tr+1][tz+1]*pz)*pr;
266 bphi = (_Bphi[
tr][tz]*(1.-pz)+_Bphi[
tr][tz+1]*pz)*(1.-pr)+
267 (_Bphi[
tr+1][tz]*(1.-pz)+_Bphi[
tr+1][tz+1]*pz)*pr;
273 if( zmm>=800. && zmm < 2420. && rmm < 1000. ) {
274 int tqz = (int)( (zmm-800.)/10. );
275 bz += (((_BzQR[
tr][tqz]*(1.-pz)+_BzQR[
tr][tqz+1]*pz)*(1.-pr)
276 +(_BzQR[
tr+1][tqz]*(1.-pz)+_BzQR[
tr+1][tqz+1]*pz)*pr)
277 *(double)
sin((
double)(2.*phi+2./180.*(double)
PI)));
278 br += (((_BrQR[
tr][tqz]*(1.-pz)+_BrQR[
tr][tqz+1]*pz)*(1.-pr)
279 +(_BrQR[
tr+1][tqz]*(1.-pz)+_BrQR[
tr+1][tqz+1]*pz)*pr)
280 *(double)
sin((
double)(2.*phi+2./180.*(double)
PI)));
281 bphi += (((_BphiQR[
tr][tqz]*(1.-pz)
282 +_BphiQR[
tr][tqz+1]*pz)*(1.-pr)
283 +(_BphiQR[
tr+1][tqz]*(1.-pz)
284 +_BphiQR[
tr+1][tqz+1]*pz)*pr)
285 *(double)
cos((
double)(2.*phi+2./180.*(double)
PI)));
290 if(zmm<=-500. && zmm>-1520. && rmm<1000.) {
291 int tqz = (int)((-zmm-500.)/20.);
292 int tqr = (int)(
tr/2.);
293 pz = (pz+(double)( tz-(
int)(tz/2.)*2. ))/2.;
294 pr = ( pr + (double)(
tr-tqr*2) )/2.;
303 double phi_tmp = phi;
304 if( phi_tmp < (
PI/2.) && phi_tmp >= (-
PI/2.) ) {
305 phi_tmp =
PI-phi_tmp;
307 }
else if( phi_tmp < -
PI/2. ) {
308 phi_tmp = 2.*
PI+phi_tmp;
310 double pphi = ( phi_tmp-
PI/2. )/(11.25/180.*
PI);
311 int tphi = (int)pphi;
312 pphi -= (double)tphi;
313 if (tphi >= 16) tphi -= 16;
316 (((_BzQL[tphi][tqr][tqz]*(1.-pz)+_BzQL[tphi][tqr][tqz+1]*pz)
317 *(1-pr)+(_BzQL[tphi][tqr+1][tqz]*(1.-pz)
318 +_BzQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1.-pphi)
319 +((_BzQL[tphi+1][tqr][tqz]*(1.-pz)
320 +_BzQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
321 +(_BzQL[tphi+1][tqr+1][tqz]*(1.-pz)
322 +_BzQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
324 (((_BrQL[tphi][tqr][tqz]*(1.- pz)
325 +_BrQL[tphi][tqr][tqz+1]*pz)*(1.-pr)
326 +(_BrQL[tphi][tqr+1][tqz]*(1.-pz)
327 +_BrQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1-pphi)
328 +((_BrQL[tphi+1][tqr][tqz]*(1.- pz)
329 +_BrQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
330 +(_BrQL[tphi+1][tqr+1][tqz]*(1.-pz)
331 +_BrQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
333 (((_BphiQL[tphi][tqr][tqz]*(1.- pz)
334 +_BphiQL[tphi][tqr][tqz+1]*pz)*(1.-pr)
335 +(_BphiQL[tphi][tqr+1][tqz]*(1.-pz)
336 +_BphiQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1.-pphi)
337 +((_BphiQL[tphi+1][tqr][tqz]*(1.- pz)
338 +_BphiQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
339 +(_BphiQL[tphi+1][tqr+1][tqz]*(1.-pz)
340 +_BphiQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
348 }
else if(zmm>=-1520. && zmm<=2460. && rmm<=0. && rmm<=1740.){
349 if(tz == 246) tz=tz-1;
351 double pz= (zmm + 1520.)/10.- (
double)tz;
352 double pr= rmm/10.- (double)
tr;
353 bz = (_Bz[
tr][tz]*(1.- pz)+_Bz[
tr][tz+1]*pz)*(1.-pr)+
354 (_Bz[
tr+1][tz]*(1.-pz)+_Bz[
tr+1][tz+1]*pz)*pr;
356 br = (_Br[
tr][tz]*(1.-pz)+_Br[
tr][tz+1]*pz)*(1.-pr)+
357 (_Br[
tr+1][tz]*(1.-pz)+_Br[
tr+1][tz+1]*pz)*pr;
359 bphi = (_Bphi[
tr][tz]*(1.-pz)+_Bphi[
tr][tz+1]*pz)*(1.-pr)+
360 (_Bphi[
tr+1][tz]*(1.-pz)+_Bphi[
tr+1][tz+1]*pz)*pr;
369 double Bmag_xy = (double)sqrt(br*br + bphi*bphi);
370 double Bphi_rp = (double)atan2( (
double)bphi, (double)br );
371 m_Bx = Bmag_xy * (double)
cos((
double)phi + Bphi_rp)/1000.;
372 m_By = Bmag_xy * (double)
sin((
double)phi + Bphi_rp)/1000.;
379 m_Bfld.setX((
double) m_Bx);
380 m_Bfld.setY((
double) m_By);
381 m_Bfld.setZ((
double) m_Bz);
403void get_bfield_(
int *imap,
double *pos,
double *field,
int *error) {
double sin(const BesAngle a)
double cos(const BesAngle a)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
HepGeom::Point3D< double > HepPoint3D
void get_bfield_(int *imap, double *pos, double *field, int *error)
void init_bfield_(int *imap)
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.