CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
Analysis/VertexFit/VertexFit-00-02-74/src/BField.cxx
Go to the documentation of this file.
1#include <cassert>
2
3#ifndef BEAN
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/ISvcLocator.h"
6#include "GaudiKernel/IDataProviderSvc.h"
7#include "GaudiKernel/Bootstrap.h"
8#endif
9
10#include "VertexFit/BField.h"
11#include "CLHEP/Geometry/Vector3D.h"
12#ifndef ENABLE_BACKWARDS_COMPATIBILITY
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 std::cout << "ERROR : Unable to open Magnetic field service" << std::endl;
30// assert(false);
31 }
32#else
33 m_pIMF = MagneticFieldSvc::instance();
34 assert( m_pIMF != 0 );
35 if( (m_pIMF->GetPath()).empty() ) {
36 cout << " VertexFitBField::ERROR "
37 "You MUST set path to directory with magnetic fields tables" << endl;
38 exit(1);
39 }
40 if( !m_pIMF->initialize() ) {
41 cout << "ERROR : Can not initialize MagneticField. Stop." << endl;
42 exit(1);
43 }
44#endif
45}
46
48 HepVector3D vector(0.0, 0.0, 0.0);
49 // fixed 2008-8-1
50 double radius = sqrt(vtx.x()*vtx.x() + vtx.y()*vtx.y());
51 if (radius < 150 && abs(vtx.z()) < 150) {
52 m_pIMF->fieldVector(10.0*vtx, vector);
53 return 1000 * vector.z(); //unit of m_BFieldZ is Tesla
54 } else {
55 return 1000 * m_pIMF->getReferField();
56 }
57}
58
60 return 1000 * m_pIMF->getReferField();
61}
62
63double VertexFitBField::getCBz(const HepVector& vtx, const HepVector& trackPosition) {
64 HepPoint3D Vtx(vtx[0], vtx[1], vtx[2]);
65 HepPoint3D TrkPosition(trackPosition[0], trackPosition[1], trackPosition[2]);
66
67 HepVector3D vector_vtx(0.0, 0.0, 0.0);
68 HepVector3D vector_trk(0.0, 0.0, 0.0);
69 double radius = sqrt(vtx[0]*vtx[0] + vtx[1]*vtx[1]);
70 if (radius < 150 && abs(vtx[2]) < 150) {
71 m_pIMF->fieldVector(10.0*Vtx, vector_vtx);
72 m_pIMF->fieldVector(10.0*TrkPosition, vector_trk);
73 return 1000 * alpha * (vector_vtx.z() + vector_trk.z())/2;//unit of m_BFieldZ is Tesla
74 } else {
75 return 1000 * alpha* m_pIMF->getReferField();
76 }
77}
HepGeom::Vector3D< double > HepVector3D
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
virtual StatusCode fieldVector(const HepGeom::Point3D< double > &xyz, HepGeom::Vector3D< double > &fvec) const =0
virtual double getReferField()=0
double getCBz(const HepVector &vtx, const HepVector &trackPosition)