00001 #include <cassert>
00002
00003 #ifndef BEAN
00004 #include "GaudiKernel/MsgStream.h"
00005 #include "GaudiKernel/ISvcLocator.h"
00006 #include "GaudiKernel/IDataProviderSvc.h"
00007 #include "GaudiKernel/Bootstrap.h"
00008 #endif
00009
00010 #include "VertexFit/BField.h"
00011 #include "CLHEP/Geometry/Vector3D.h"
00012 #ifndef ENABLE_BACKWARDS_COMPATIBILITY
00013 typedef HepGeom::Vector3D<double> HepVector3D;
00014 #endif
00015
00016 using namespace std;
00017
00018 const double VertexFitBField::alpha = -0.00299792458;
00019
00020 VertexFitBField* VertexFitBField::s_bfield = 0;
00021
00022 VertexFitBField::VertexFitBField() {
00023 #ifndef BEAN
00024 ISvcLocator* svcLocator = Gaudi::svcLocator();
00025 m_pIMF = NULL;
00026 StatusCode sc = svcLocator->service("MagneticFieldSvc",m_pIMF);
00027 assert(m_pIMF != NULL);
00028 if (sc != StatusCode::SUCCESS) {
00029 std::cout << "ERROR : Unable to open Magnetic field service" << std::endl;
00030
00031 }
00032 #else
00033 m_pIMF = MagneticFieldSvc::instance();
00034 assert( m_pIMF != 0 );
00035 if( (m_pIMF->GetPath()).empty() ) {
00036 cout << " VertexFitBField::ERROR "
00037 "You MUST set path to directory with magnetic fields tables" << endl;
00038 exit(1);
00039 }
00040 if( !m_pIMF->initialize() ) {
00041 cout << "ERROR : Can not initialize MagneticField. Stop." << endl;
00042 exit(1);
00043 }
00044 #endif
00045 }
00046
00047 double VertexFitBField::getBFieldZ(const HepPoint3D& vtx) {
00048 HepVector3D vector(0.0, 0.0, 0.0);
00049
00050 double radius = sqrt(vtx.x()*vtx.x() + vtx.y()*vtx.y());
00051 if (radius < 150 && abs(vtx.z()) < 150) {
00052 m_pIMF->fieldVector(10.0*vtx, vector);
00053 return 1000 * vector.z();
00054 } else {
00055 return 1000 * m_pIMF->getReferField();
00056 }
00057 }
00058
00059 double VertexFitBField::getBFieldZRef() {
00060 return 1000 * m_pIMF->getReferField();
00061 }
00062
00063 double VertexFitBField::getCBz(const HepVector& vtx, const HepVector& trackPosition) {
00064 HepPoint3D Vtx(vtx[0], vtx[1], vtx[2]);
00065 HepPoint3D TrkPosition(trackPosition[0], trackPosition[1], trackPosition[2]);
00066
00067 HepVector3D vector_vtx(0.0, 0.0, 0.0);
00068 HepVector3D vector_trk(0.0, 0.0, 0.0);
00069 double radius = sqrt(vtx[0]*vtx[0] + vtx[1]*vtx[1]);
00070 if (radius < 150 && abs(vtx[2]) < 150) {
00071 m_pIMF->fieldVector(10.0*Vtx, vector_vtx);
00072 m_pIMF->fieldVector(10.0*TrkPosition, vector_trk);
00073 return 1000 * alpha * (vector_vtx.z() + vector_trk.z())/2;
00074 } else {
00075 return 1000 * alpha* m_pIMF->getReferField();
00076 }
00077 }