BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MagneticFieldSvc.h
Go to the documentation of this file.
1#ifndef MAGNETICFIELDSVC_H
2#define MAGNETICFIELDSVC_H
3
4// Include files
5#include "CLHEP/Geometry/Point3D.h"
6#include "CLHEP/Geometry/Vector3D.h"
7#include <string>
8#include <vector>
9#ifndef ENABLE_BACKWARDS_COMPATIBILITY
10// backwards compatibility will be enabled ONLY in CLHEP 1.9
11typedef HepGeom::Point3D<double> HepPoint3D;
12typedef HepGeom::Vector3D<double> HepVector3D;
13#endif
14#include "ConnectionDB.h"
15
16#ifndef BEAN
17# include "GaudiKernel/IIncidentListener.h"
18# include "GaudiKernel/Service.h"
19# include "MagneticFieldSvc/IBesMagFieldSvc.h"
20using namespace CLHEP;
21
22// Forward declarations
23template <class TYPE> class SvcFactory;
24
25class IBesMagFieldSvc;
27class IDataProviderSvc;
28#else
30typedef bool StatusCode;
31#endif
32
33/** @class MagneticFieldSvc MagneticFieldSvc.h
34 * A service for finding the magnetic field vector at a given
35 * point in space.
36 *
37 */
38
39#ifndef BEAN
40class MagneticFieldSvc : public extends<Service, IBesMagFieldSvc>,
41 virtual public IIncidentListener {
42 // protected:
43public:
44 /// Standard Constructor.
45 /// @param name String with service name
46 /// @param svc Pointer to service locator interface
47 MagneticFieldSvc( const std::string& name, ISvcLocator* svc );
48
49 /// Virtual destructor.
50 virtual ~MagneticFieldSvc();
51
52public:
53 /// Initialise the service (Inherited Service overrides)
54 virtual StatusCode initialize();
55
57 void init_params( std::vector<double> current, std::vector<double> beamEnergy, int runNo );
58 /// Finalise the service.
59 virtual StatusCode finalize();
60
61 /** Query the available interfaces.
62 * @param riid Requested interface ID
63 * @param ppvInterface Pointer to requested interface
64 * @return StatusCode indicating SUCCESS or FAILURE.
65 */
66 // virtual StatusCode queryInterface( const InterfaceID& riid,
67 // void** ppvInterface );
68
69 /// Service type.
70 virtual const InterfaceID& type() const { return IBesMagFieldSvc::interfaceID(); };
71
72 // Incident handler
73 void handle( const Incident& );
74
75#else
76// -------------------------- BEAN ------------------------------------
77class MagneticFieldSvc {
78
79public:
80 static MagneticFieldSvc* instance() {
81 return ( m_field ) ? m_field : ( m_field = new ( std::nothrow ) MagneticFieldSvc() );
82 }
83
84private:
86 virtual ~MagneticFieldSvc();
87
88public:
89 void SetPath( std::string new_path ) { path = new_path; }
90 std::string GetPath() { return path; }
91
92 void GridDistance( int gridDistance = 5 ) { m_gridDistance = gridDistance; }
93 void RunMode( int runmode = 2 ) { m_runmode = runmode; }
94 void IfRealField( bool ifRealField = true ) { m_ifRealField = ifRealField; }
95 void OutLevel( int outlevel = 1 ) { m_outlevel = outlevel; }
96
97 void Cur_SCQ1_55( double Cur_SCQ1_55 = 349.4 ) { m_Cur_SCQ1_55 = Cur_SCQ1_55; }
98 void Cur_SCQ1_89( double Cur_SCQ1_89 = 426.2 ) { m_Cur_SCQ1_89 = Cur_SCQ1_89; }
99 void Cur_SCQ2_10( double Cur_SCQ2_10 = 474.2 ) { m_Cur_SCQ2_10 = Cur_SCQ2_10; }
100
101 void UseDBFlag( bool useDB = true ) { m_useDB = useDB; }
102
103 /// Initialize
104 bool init_mucMagneticField();
105 virtual StatusCode initialize();
106 void init_params( int run );
107 void test( int run );
108 // void init_params(std::vector<double> current, std::vector<double> beamEnergy, int runNo);
109
110 // handler for new run
111 void handle( int new_run );
112#endif
113
114 /** IBesMagFieldSvc interface.
115 * @param[in] xyz Point at which magnetic field vector will be given
116 * @param[out] fvec Magnectic field vector.
117 * @return StatusCode SUCCESS if calculation was performed.
118 */
119 virtual StatusCode fieldVector( const HepPoint3D& xyz, HepVector3D& fvec ) const;
120
121 virtual StatusCode uniFieldVector( const HepPoint3D& xyz, HepVector3D& fvec ) const;
122
123 virtual double getReferField();
124
125 virtual bool ifRealField() const;
126
127private:
128#ifndef BEAN
129 /// Allow SvcFactory to instantiate the service.
130 // friend class SvcFactory<MagneticFieldSvc>;
131#else
132 static MagneticFieldSvc* m_field;
133#endif
134
135 /// Fills Q, the field vector
136 void fieldGrid( const HepPoint3D& xyz, HepVector3D& fvec ) const;
137 void fieldGrid_TE( const HepPoint3D& xyz, HepVector3D& fvec ) const;
138
139 StatusCode parseFile(); ///< Reads the field map from file
140 StatusCode parseFile_TE(); ///< Reads the field map from file
141
142 std::string path; // path to data files
143
144 std::string m_filename; ///< Magnetic field file name
145 std::string m_filename_TE; ///< Magnetic field file name
146 // Not open map files for every run
147 std::string former_m_filename_TE; //("First Run");
148 std::string former_m_filename; //="First Run";
149
150 int m_runmode; ///< Run mode
151 int m_gridDistance; ///< grid distance of field map
152 int m_outlevel;
153 double m_scale;
154
155 double m_Cur_SCQ1_55;
156 double m_Cur_SCQ1_89;
157 double m_Cur_SCQ2_10;
158
159 std::vector<double> m_Q; ///< Field vector
160 std::vector<double> m_P; ///< Grid position
161 std::vector<double> m_Q_TE; ///< Field vector
162 std::vector<double> m_P_TE; ///< Grid position
163 std::vector<double> m_Q_1; ///< Field vector
164 std::vector<double> m_P_1; ///< Grid position
165 std::vector<double> m_Q_2; ///< Field vector
166 std::vector<double> m_P_2; ///< Grid position
167 double m_Dxyz[3]; ///< Steps in x, y and z
168 int m_Nxyz[3]; ///< Number of steps in x, y and z
169 double m_max_FL[3];
170 double m_min_FL[3];
171 // for tof and emc
172 double m_Dxyz_TE[3]; ///< Steps in x, y and z
173 int m_Nxyz_TE[3]; ///< Number of steps in x, y and z
174 double m_max_FL_TE[3];
175 double m_min_FL_TE[3];
176
177 double m_zOffSet; ///< The z offset
178 double m_zOffSet_TE; ///< The z offset
179 MucMagneticField* m_Mucfield;
180 double m_zfield;
181 bool m_ifRealField;
182
183 // property
184 bool m_useDB;
185
186 bool m_turnOffField;
187 bool m_uniField;
188
189public:
193 int runNo;
194
195#ifndef BEAN
196 IDataProviderSvc* m_eventSvc;
197#endif
198 // database
200 std::map<int, std::vector<double>> m_mapMagnetInfo;
201 std::map<int, std::vector<double>> m_mapBeamEnergy;
202 std::vector<double> beamEnergy;
203 std::vector<double> current;
204};
205
206#endif // MAGNETICFIELDSVC_H
HepGeom::Vector3D< double > HepVector3D
std::string test
HepGeom::Point3D< double > HepPoint3D
RunMode
Definition Goofy.h:11
HepGeom::Point3D< double > HepPoint3D
HepGeom::Vector3D< double > HepVector3D
FieldDBUtil::ConnectionDB * m_connect_run
virtual const InterfaceID & type() const
Service type.
std::map< int, std::vector< double > > m_mapMagnetInfo
virtual double getReferField()
virtual StatusCode fieldVector(const HepPoint3D &xyz, HepVector3D &fvec) const
virtual ~MagneticFieldSvc()
Virtual destructor.
virtual StatusCode finalize()
Finalise the service.
virtual bool ifRealField() const
std::vector< double > beamEnergy
virtual StatusCode initialize()
Initialise the service (Inherited Service overrides).
std::map< int, std::vector< double > > m_mapBeamEnergy
void handle(const Incident &)
virtual StatusCode uniFieldVector(const HepPoint3D &xyz, HepVector3D &fvec) const
MagneticFieldSvc(const std::string &name, ISvcLocator *svc)
std::vector< double > current
IDataProviderSvc * m_eventSvc
Forward and external declarations.