BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Analysis/VertexFit/src/BField.cxx
Go to the documentation of this file.
1#include <cassert>
2
3#ifndef BEAN
4# include "GaudiKernel/Bootstrap.h"
5# include "GaudiKernel/IDataProviderSvc.h"
6# include "GaudiKernel/ISvcLocator.h"
7# include "GaudiKernel/MsgStream.h"
8#endif
9
10#include "CLHEP/Geometry/Vector3D.h"
11#include "VertexFit/BField.h"
12#ifndef ENABLE_BACKWARDS_COMPATIBILITY
13typedef HepGeom::Vector3D<double> HepVector3D;
14#endif
15
16using namespace std;
17
18const double VertexFitBField::alpha = -0.00299792458;
19
20VertexFitBField* VertexFitBField::s_bfield = 0;
21
22VertexFitBField::VertexFitBField() {
23#ifndef BEAN
24 ISvcLocator* svcLocator = Gaudi::svcLocator();
25 m_pIMF = NULL;
26 StatusCode sc = svcLocator->service( "MagneticFieldSvc", m_pIMF );
27 assert( m_pIMF != NULL );
28 if ( sc != StatusCode::SUCCESS )
29 {
30 std::cout << "ERROR : Unable to open Magnetic field service" << std::endl;
31 // assert(false);
32 }
33#else
34 m_pIMF = MagneticFieldSvc::instance();
35 assert( m_pIMF != 0 );
36 if ( ( m_pIMF->GetPath() ).empty() )
37 {
38 cout << " VertexFitBField::ERROR "
39 "You MUST set path to directory with magnetic fields tables"
40 << endl;
41 exit( 1 );
42 }
43 if ( !m_pIMF->initialize() )
44 {
45 cout << "ERROR : Can not initialize MagneticField. Stop." << endl;
46 exit( 1 );
47 }
48#endif
49}
50
52 HepVector3D vector( 0.0, 0.0, 0.0 );
53 // fixed 2008-8-1
54 double radius = sqrt( vtx.x() * vtx.x() + vtx.y() * vtx.y() );
55 if ( radius < 150 && abs( vtx.z() ) < 150 )
56 {
57 m_pIMF->fieldVector( 10.0 * vtx, vector );
58 return 1000 * vector.z(); // unit of m_BFieldZ is Tesla
59 }
60 else { return 1000 * m_pIMF->getReferField(); }
61}
62
63double VertexFitBField::getBFieldZRef() { return 1000 * m_pIMF->getReferField(); }
64
65double VertexFitBField::getCBz( const HepVector& vtx, const HepVector& trackPosition ) {
66 HepPoint3D Vtx( vtx[0], vtx[1], vtx[2] );
67 HepPoint3D TrkPosition( trackPosition[0], trackPosition[1], trackPosition[2] );
68
69 HepVector3D vector_vtx( 0.0, 0.0, 0.0 );
70 HepVector3D vector_trk( 0.0, 0.0, 0.0 );
71 double radius = sqrt( vtx[0] * vtx[0] + vtx[1] * vtx[1] );
72 if ( radius < 150 && abs( vtx[2] ) < 150 )
73 {
74 m_pIMF->fieldVector( 10.0 * Vtx, vector_vtx );
75 m_pIMF->fieldVector( 10.0 * TrkPosition, vector_trk );
76 return 1000 * alpha * ( vector_vtx.z() + vector_trk.z() ) / 2; // unit of m_BFieldZ is
77 // Tesla
78 }
79 else { return 1000 * alpha * m_pIMF->getReferField(); }
80}
HepGeom::Vector3D< double > HepVector3D
HepGeom::Point3D< double > HepPoint3D
double getCBz(const HepVector &vtx, const HepVector &trackPosition)
double getBFieldZ(const HepPoint3D &vtx)