/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/TrackUtil/TrackUtil-00-00-08/src/Bfield.cxx

Go to the documentation of this file.
00001 //
00002 // Bfield class
00003 //
00004 // 27-Mar-1999 : KUNIYA Toshio
00005 //   Enabled QCS compornent
00006 //
00007 // 21-Feb-1999 : KUNIYA Toshio
00008 //   Keeping comatibility, Bfield class is modified.
00009 //   No longer fortran common block is used for bfield map.
00010 //   Access functions are prepared for fortran call.
00011 //
00012 
00013 #include <iostream>
00014 #include "TrackUtil/Bfield.h"
00015 
00016 Bfield *
00017 Bfield::_field[200] = {0};   // All of 200 elements are initialized.
00018 
00019 Bfield *
00020 Bfield::getBfield(int imap) {
00021   if (! _field[imap]) _field[imap] = new Bfield(imap);
00022   return _field[imap];
00023 }
00024 
00025 
00026 Bfield::Bfield(int imap) {
00027   std::cout << std::endl;
00028   std::cout << "***********************************************" << std::endl;
00029   std::cout << "           Bfield class  MAP ID = " << imap << std::endl;
00030   std::cout << "    #### R < 174 cm, -152 < Z < 246 cm ####    " << std::endl;
00031   std::cout << "                C++ version 1.00               " << std::endl;
00032   std::cout << "***********************************************" << std::endl;
00033 
00034   const float uniformBz[10] = {0, 15, 14.5, 14, 13, 12.5, 12, 11, 10, 15.5};
00035 
00036   //...initialization
00037   for(int i=0; i<175; i++)
00038     for(int j=0; j<399; j++) {
00039       _Bz[i][j] = 0;
00040       _Br[i][j] = 0;
00041       _Bz[i][j] = 0;
00042       if(i<101 && j<163) {
00043         _BzQR[i][j] = 0;
00044         _BrQR[i][j] = 0;
00045         _BphiQR[i][j] = 0;
00046       }
00047     }
00048   for(int i=0; i<17; i++)
00049     for(int j=0; j<51; j++)
00050       for(int k=0; k<52; k++) {
00051         _BzQL[i][j][k] = 0;
00052         _BrQL[i][j][k] = 0;
00053         _BphiQL[i][j][k] =0;
00054       }
00055 
00056   //...
00057   _fieldID  = imap;
00058 
00059   //...read B field map 
00060 
00061   if(imap<10){
00062     //
00063     // uniform B field map
00064     //
00065     m_Bx = 0.;
00066     m_By = 0.;
00067     m_Bz = uniformBz[imap];
00068     m_Bfld.setX((double) m_Bx);
00069     m_Bfld.setY((double) m_By);
00070     m_Bfld.setZ((double) m_Bz);
00071     std::cout << "Bfield class >> creating uniform B field with id = " << imap;
00072     std::cout << ", (Bx,By,Bz) = "<<m_Bfld<<std::endl;
00073   } else {
00074     //
00075     // non-uniform B field map
00076     //
00077     /*
00078        std::cout << "Bfield class >> loading non-uniform B field map" << std::endl;
00079        geo_coil_readmap_(&imap, _Bz, _Br, _Bphi);
00080        if( _fieldID == 21 ) {
00081        std::cout << "Bfield class >> loading QCS" << std::endl;
00082        geo_coil_readqcsrmap_(_BzQR,_BrQR, _BphiQR);
00083        geo_coil_readqcslmap_(_BzQL,_BrQL, _BphiQL);
00084        }
00085        updateCache(0., 0., 0.);
00086        */
00087   }
00088   std::cout << std::endl;
00089 
00090 }
00091 
00092 //Bfield::~Bfield(){};
00093 
00094 const Hep3Vector &
00095 Bfield::fieldMap(float x, float y, float z) const {
00096 
00097   if(_fieldID > 10){
00098     if(x != m_x || y != m_y || z != m_z)  updateCache(x, y, z);
00099   }
00100 
00101   return m_Bfld;
00102 }
00103 
00104 const Hep3Vector &
00105 Bfield::fieldMap(const HepPoint3D & xyz) const{
00106 
00107   if(_fieldID > 10){
00108     float x = xyz.x();
00109     float y = xyz.y();
00110     float z = xyz.z();
00111     if(x != m_x || y != m_y || z != m_z)  updateCache(x, y, z);
00112   }
00113 
00114   return m_Bfld;
00115 }
00116 
00117 void
00118 Bfield::fieldMap(float *position, float *field) {
00119   if(_fieldID > 10){
00120     float x = position[0];
00121     float y = position[1];
00122     float z = position[2];
00123     if(x != m_x || y != m_y || z != m_z)  updateCache(x, y, z);
00124   }
00125   field[0] = m_Bx;
00126   field[1] = m_By;
00127   field[2] = m_Bz;
00128   return;
00129 }
00130 
00131 float
00132 Bfield::bx(float x, float y, float z) const {
00133 
00134   if(_fieldID > 10){
00135     if(x != m_x || y != m_y || z != m_z)  updateCache(x, y, z);
00136   }
00137 
00138   return m_Bx;
00139 }
00140 
00141 float
00142 Bfield::by(float x, float y, float z) const {
00143 
00144   if(_fieldID > 10){
00145     if(x != m_x || y != m_y || z != m_z)  updateCache(x, y, z);
00146   }
00147 
00148   return m_By;
00149 }
00150 
00151 float
00152 Bfield::bz(float x, float y, float z) const {
00153 
00154   if(_fieldID > 10){
00155     if(x != m_x || y != m_y || z != m_z)  updateCache(x, y, z);
00156   }
00157 
00158   return m_Bz;
00159 }
00160 
00161 float
00162 Bfield::bx(const HepPoint3D & xyz) const{
00163 
00164   if(_fieldID > 10){
00165     float x = xyz.x();
00166     float y = xyz.y();
00167     float z = xyz.z();
00168     if(x != m_x || y != m_y || z != m_z)  updateCache(x, y, z);
00169   }
00170 
00171   return m_Bx;
00172 }
00173 
00174 float
00175 Bfield::by(const HepPoint3D & xyz) const{
00176 
00177   if(_fieldID > 10){
00178     float x = xyz.x();
00179     float y = xyz.y();
00180     float z = xyz.z();
00181     if(x != m_x || y != m_y || z != m_z)  updateCache(x, y, z);
00182   }
00183 
00184   return m_By;
00185 }
00186 
00187 float
00188 Bfield::bz(const HepPoint3D & xyz) const{
00189 
00190   if(_fieldID > 10){
00191     float x = xyz.x();
00192     float y = xyz.y();
00193     float z = xyz.z();
00194     if(x != m_x || y != m_y || z != m_z)  updateCache(x, y, z);
00195   }
00196   return m_Bz;
00197 }
00198 
00199 void
00200 Bfield::updateCache(float x, float y, float z) const{
00201 
00202   // this function is only for non-uniform B field
00203 
00204   if( _fieldID <= 10 ) return;
00205 
00206   float PI = 3.14159;
00207 
00208   //...
00209   float  r   = (float)sqrt((double)x*(double)x + (double)y*(double)y);
00210   float  phi = (float)atan2((double)y, (double)x);
00211 
00212   //... [cm] --> [mm]
00213   float zmm = z * 10.;
00214   float rmm = r * 10.;
00215   //... make index
00216   int tz = (int) (( zmm + 1520.)/10.);
00217   int tr = (int) (rmm/10.);
00218 
00219   //... 
00220   float bz = 0., br = 0., bphi = 0.;
00221 
00222   if(zmm >= -1520. && zmm < 2460. && rmm >= 0. && rmm < 1740.){
00223     if(_Bz[tr][tz] && _Bz[tr][tz+1]){
00224       float pz = (zmm + 1520.)/10.- (float)tz;
00225       float pr =  rmm/10.- (float)tr;
00226 
00227       //...
00228       bz = (_Bz[tr][tz]*(1.- pz)+_Bz[tr][tz+1]*pz)*(1.-pr)+
00229         (_Bz[tr+1][tz]*(1.-pz)+_Bz[tr+1][tz+1]*pz)*pr;
00230       //...
00231       br = (_Br[tr][tz]*(1.-pz)+_Br[tr][tz+1]*pz)*(1.-pr)+
00232         (_Br[tr+1][tz]*(1.-pz)+_Br[tr+1][tz+1]*pz)*pr;
00233       //...
00234       bphi = (_Bphi[tr][tz]*(1.-pz)+_Bphi[tr][tz+1]*pz)*(1.-pr)+
00235         (_Bphi[tr+1][tz]*(1.-pz)+_Bphi[tr+1][tz+1]*pz)*pr;
00236 
00237       if(_fieldID == 21) {
00238         //
00239         // QCS Right
00240         //
00241         if( zmm>=800. && zmm < 2420. && rmm < 1000. ) {
00242           int tqz = (int)( (zmm-800.)/10. );
00243           bz += (((_BzQR[tr][tqz]*(1.-pz)+_BzQR[tr][tqz+1]*pz)*(1.-pr)
00244                 +(_BzQR[tr+1][tqz]*(1.-pz)+_BzQR[tr+1][tqz+1]*pz)*pr)
00245               *(float)sin((double)(2.*phi+2./180.*(double)PI)));
00246           br += (((_BrQR[tr][tqz]*(1.-pz)+_BrQR[tr][tqz+1]*pz)*(1.-pr)
00247                 +(_BrQR[tr+1][tqz]*(1.-pz)+_BrQR[tr+1][tqz+1]*pz)*pr)
00248               *(float)sin((double)(2.*phi+2./180.*(double)PI)));
00249           bphi += (((_BphiQR[tr][tqz]*(1.-pz)
00250                   +_BphiQR[tr][tqz+1]*pz)*(1.-pr)
00251                 +(_BphiQR[tr+1][tqz]*(1.-pz)
00252                   +_BphiQR[tr+1][tqz+1]*pz)*pr)
00253               *(float)cos((double)(2.*phi+2./180.*(double)PI)));
00254         }
00255         //
00256         // QCS Left
00257         //
00258         if(zmm<=-500. && zmm>-1520. && rmm<1000.) {
00259           int tqz = (int)((-zmm-500.)/20.);
00260           int tqr = (int)(tr/2.);
00261           pz = (pz+(float)( tz-(int)(tz/2.)*2. ))/2.;
00262           pr = ( pr + (float)(tr-tqr*2) )/2.;
00263           float f = 1.;
00264           float phi_tmp = phi;
00265           if( phi_tmp < (PI/2.) && phi_tmp >= (-PI/2.) ) {
00266             phi_tmp = PI-phi_tmp;
00267             f =-1.;
00268           } else if( phi_tmp < -PI/2. ) {
00269             phi_tmp = 2.*PI+phi_tmp;
00270           }
00271           float pphi = ( phi_tmp-PI/2. )/(11.25/180.*PI);
00272           int tphi = (int)pphi;
00273           pphi -= (float)tphi;
00274           if (tphi >= 16) tphi -= 16;
00275 
00276           bz += f*
00277             (((_BzQL[tphi][tqr][tqz]*(1.-pz)+_BzQL[tphi][tqr][tqz+1]*pz)
00278               *(1-pr)+(_BzQL[tphi][tqr+1][tqz]*(1.-pz)
00279                 +_BzQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1.-pphi)
00280              +((_BzQL[tphi+1][tqr][tqz]*(1.-pz)
00281                  +_BzQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
00282                +(_BzQL[tphi+1][tqr+1][tqz]*(1.-pz)
00283                  +_BzQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
00284           br += f*
00285             (((_BrQL[tphi][tqr][tqz]*(1.- pz)
00286                +_BrQL[tphi][tqr][tqz+1]*pz)*(1.-pr)
00287               +(_BrQL[tphi][tqr+1][tqz]*(1.-pz)
00288                 +_BrQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1-pphi)
00289              +((_BrQL[tphi+1][tqr][tqz]*(1.- pz)
00290                  +_BrQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
00291                +(_BrQL[tphi+1][tqr+1][tqz]*(1.-pz)
00292                  +_BrQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
00293           bphi += f*
00294             (((_BphiQL[tphi][tqr][tqz]*(1.- pz)
00295                +_BphiQL[tphi][tqr][tqz+1]*pz)*(1.-pr)
00296               +(_BphiQL[tphi][tqr+1][tqz]*(1.-pz)
00297                 +_BphiQL[tphi][tqr+1][tqz+1]*pz)*pr)*(1.-pphi)
00298              +((_BphiQL[tphi+1][tqr][tqz]*(1.- pz)
00299                  +_BphiQL[tphi+1][tqr][tqz+1]*pz)*(1.-pr)
00300                +(_BphiQL[tphi+1][tqr+1][tqz]*(1.-pz)
00301                  +_BphiQL[tphi+1][tqr+1][tqz+1]*pz)*pr)*pphi);
00302         }
00303       }
00304     }  else {
00305       bz=0.;
00306       br=0.;
00307       bphi=0.;
00308     }
00309   } else if(zmm>=-1520. && zmm<=2460. && rmm<=0. && rmm<=1740.){
00310     if(tz == 246) tz=tz-1;
00311     if(tr == 174) tr=tr-1;
00312     float pz= (zmm + 1520.)/10.- (float)tz;
00313     float pr=  rmm/10.- (float)tr;
00314     bz   = (_Bz[tr][tz]*(1.- pz)+_Bz[tr][tz+1]*pz)*(1.-pr)+
00315       (_Bz[tr+1][tz]*(1.-pz)+_Bz[tr+1][tz+1]*pz)*pr;
00316 
00317     br   = (_Br[tr][tz]*(1.-pz)+_Br[tr][tz+1]*pz)*(1.-pr)+
00318       (_Br[tr+1][tz]*(1.-pz)+_Br[tr+1][tz+1]*pz)*pr;
00319 
00320     bphi = (_Bphi[tr][tz]*(1.-pz)+_Bphi[tr][tz+1]*pz)*(1.-pr)+
00321       (_Bphi[tr+1][tz]*(1.-pz)+_Bphi[tr+1][tz+1]*pz)*pr;
00322   } else {
00323     bz =0.;
00324     br =0.;
00325     bphi =0.;
00326   }
00327 
00328 
00329   //... Set B field
00330   float Bmag_xy = (float)sqrt(br*br + bphi*bphi);
00331   double Bphi_rp = (float)atan2( (double)bphi, (double)br );
00332   m_Bx = Bmag_xy * (float)cos((double)phi + Bphi_rp)/1000.;
00333   m_By = Bmag_xy * (float)sin((double)phi + Bphi_rp)/1000.;   
00334   m_Bz = bz/1000.;
00335   m_x = x;
00336   m_y = y;
00337   m_z = z;
00338   m_Bfld.setX((double) m_Bx);
00339   m_Bfld.setY((double) m_By);
00340   m_Bfld.setZ((double) m_Bz);
00341 }

Generated on Tue Nov 29 23:13:23 2016 for BOSS_7.0.2 by  doxygen 1.4.7