BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MagFieldReader Class Reference

#include <MagFieldReader.h>

Inheritance diagram for MagFieldReader:

Public Member Functions

 MagFieldReader (const std::string &name, ISvcLocator *pSvcLocator)
 Standard constructor.
virtual ~MagFieldReader ()
virtual StatusCode initialize ()
 Destructor.
virtual StatusCode execute ()
 Algorithm execution.
virtual StatusCode finalize ()
 Algorithm finalization.

Detailed Description

Parameters
AnAlgorithm to read and plot magnetic filed maps
forx and y kept constant and varying z. The x, y
positionsand the z range can be set in job options.

Definition at line 23 of file MagFieldReader.h.

Constructor & Destructor Documentation

◆ MagFieldReader()

MagFieldReader::MagFieldReader ( const std::string & name,
ISvcLocator * pSvcLocator )

Standard constructor.

Definition at line 44 of file MagFieldReader.cxx.

45 : Algorithm( name, pSvcLocator ), m_pIMF( 0 ) {
46 declareProperty( "Zmin", m_zMin = -1200.0 * mm );
47 declareProperty( "Zmax", m_zMax = 1200.0 * mm );
48 declareProperty( "Step", m_step = 50.0 * mm );
49 declareProperty( "Xmin", m_xMin = -900.0 * mm );
50 declareProperty( "Xmax", m_xMax = 900.0 * mm );
51 declareProperty( "Ymin", m_yMin = -900.0 * mm );
52 declareProperty( "Ymax", m_yMax = 900.0 * mm );
53 declareProperty( "filename", m_filename = "rawmode3_out.dat" );
54}

◆ ~MagFieldReader()

virtual MagFieldReader::~MagFieldReader ( )
inlinevirtual

Definition at line 28 of file MagFieldReader.h.

28{}; ///< Destructor

Member Function Documentation

◆ execute()

StatusCode MagFieldReader::execute ( )
virtual

Algorithm execution.

Definition at line 171 of file MagFieldReader.cxx.

171 {
172
173 MsgStream msg( msgSvc(), name() );
174
175 msg << MSG::DEBUG << "==> Execute MagFieldReader" << endmsg;
176 /*
177 //calculate the error of Bfield
178 std::ifstream infile( m_filename.c_str() );
179 if(!infile.good()) msg << MSG::FATAL << "Unable to read the file: " << m_filename <<
180 endmsg; int nLine = 0; char line[ 255 ]; while( infile ) {
181 // parse each line of the file,
182 // comment lines begin with '#' in the cdf file
183 infile.getline( line, 255 );
184 if ( line[0] == '#' ) continue;
185 std::string gridx, gridy, gridz, sFx, sFy, sFz;
186 char* token = strtok( line, " " );
187 if ( token ) { gridx = token; token = strtok( NULL, " " );} else continue;
188 if ( token ) { gridy = token; token = strtok( NULL, " " );} else continue;
189 if ( token ) { gridz = token; token = strtok( NULL, " " );} else continue;
190 if ( token ) { sFx = token; token = strtok( NULL, " " );} else continue;
191 if ( token ) { sFy = token; token = strtok( NULL, " " );} else continue;
192 if ( token ) { sFz = token; token = strtok( NULL, " " );} else continue;
193 if ( token != NULL ) continue;
194 nLine++;
195 double x,y,z,bx,by,bz;
196 //Grid position
197 x = atof( gridx.c_str() );
198 y = atof( gridy.c_str() );
199 z = atof( gridz.c_str() );
200 // Field values are given in tesla in CDF file. Convert to CLHEP units
201 bx = atof( sFx.c_str() );
202 by = atof( sFy.c_str() );
203 bz = atof( sFz.c_str() );
204 //std::cout<<"x,y,z: "<<x<<" "<<y<<" "<<z<<" "<<"bx,by,bz: "<<bx<<" "<<by<<"
205 "<<bz<<std::endl; x = -x*m; y = y*m; z = -z*m;
206
207 HepPoint3D r(x,y,z);
208 HepVector3D b;
209 m_pIMF->fieldVector(r,b);
210 m_Bx = b.x()/tesla;
211 m_By = b.y()/tesla;
212 m_Bz = b.z()/tesla;
213 m_sigma_bx = (b.x()/tesla + bx)*10000.;
214 m_sigma_by = (b.y()/tesla - by)*10000.;
215 m_sigma_bz = (b.z()/tesla + bz)*10000.;
216 m_r = std::sqrt(x/m*x/m+y/m*y/m);
217 m_x = x/m;
218 m_y = y/m;
219 m_z = z/m;
220 m_tuple1->write();
221 }
222 infile.close();
223 std::cout<<"Totally "<<nLine<<" in file "<<m_filename<<std::endl;
224
225 for(int k = 0; k < 5; k++) {
226 double rr;
227 if(k==0) rr = 0;
228 if(k==1) rr = 200;
229 if(k==2) rr = 400;
230 if(k==3) rr = 600;
231 if(k==4) rr = 800;
232 for(int zz = -1195; zz <1200; zz+=50) {
233 double bxt = 0.,byt= 0.,bzt = 0.;
234 for(int i = 0; i < 100000; i++) {
235 double phi = CLHEP::twopi*CLHEP::RandFlat::shoot();
236 double xx = rr*std::cos(phi);
237 double yy = rr*std::sin(phi);
238 HepPoint3D r(xx,yy,double(zz));
239 HepVector3D b;
240 m_pIMF->fieldVector(r,b);
241 bxt+=b.x()/tesla;
242 byt+=b.y()/tesla;
243 bzt+=b.z()/tesla;
244 }
245 m_z2 = zz;
246 m_r2 = rr;
247 m_Bx2 = bxt/100000;
248 m_By2 = byt/100000;
249 m_Bz2 = bzt/100000;
250 m_tuple2->write();
251 }
252 }
253
254 for(int k = 0; k < 3; k++) {
255 double zz;
256 if(k==0) zz = 0;
257 if(k==1) zz = -800;
258 if(k==2) zz = 800;
259 for(int rr = 200; rr <=600; rr+=400) {
260 for(double phi = 0; phi <= 2*3.14159; phi+=0.1745) {
261 //double phi = CLHEP::twopi*CLHEP::RandFlat::shoot();
262 double xx = rr*std::cos(phi);
263 double yy = rr*std::sin(phi);
264 HepPoint3D r(xx,yy,double(zz));
265 HepVector3D b;
266 m_pIMF->fieldVector(r,b);
267 m_Bx3 = b.x()/tesla;
268 m_By3 = b.y()/tesla;
269 m_Bz3 = b.z()/tesla;
270 m_phi3 = phi*180/CLHEP::pi;
271 m_x3 = xx;
272 m_y3 = yy;
273 m_z3 = zz;
274 m_r3 = rr;
275 m_tuple3->write();
276 }
277 }
278 }
279 */
280 m_timer->start();
281 for ( int i = 0; i < 20000; i++ )
282 {
283 double px, py, pz, bx, by, bz;
284 double max_x = 1.8 * m, min_x = -1.8 * m, max_y = 1.8 * m, min_y = -1.8 * m,
285 max_z = 2.1 * m, min_z = -2.1 * m;
286 px = min_x + ( max_x - min_x ) * RandFlat::shoot();
287 py = min_y + ( max_y - min_y ) * RandFlat::shoot();
288 pz = min_z + ( max_z - min_z ) * RandFlat::shoot();
289 HepPoint3D r( px, py, pz );
290 HepVector3D b;
291 m_pIMF->fieldVector( r, b );
292 bx = b.x() / tesla;
293 by = b.y() / tesla;
294 bz = b.z() / tesla;
295 }
296 m_timer->stop();
297 m_time = m_timer->elapsed();
298 m_tuple4->write();
299 /*
300 StatusCode sc = this->readField();
301 if( sc.isFailure() ) {
302 msg << MSG::FATAL << "Unable to execute MagFieldReader"
303 << endmsg;
304 return sc;
305 }
306 */
307 msg << MSG::INFO << "MagFieldReader executed" << endmsg;
308 return StatusCode::SUCCESS;
309}
HepGeom::Vector3D< double > HepVector3D
HepGeom::Point3D< double > HepPoint3D
IMessageSvc * msgSvc()

◆ finalize()

StatusCode MagFieldReader::finalize ( )
virtual

Algorithm finalization.

Definition at line 314 of file MagFieldReader.cxx.

314 {
315
316 MsgStream msg( msgSvc(), name() );
317 msg << MSG::DEBUG << "==> Finalize MagFieldReader" << endmsg;
318
319 return StatusCode::SUCCESS;
320}

◆ initialize()

StatusCode MagFieldReader::initialize ( )
virtual

Destructor.

Algorithm initialization

Definition at line 59 of file MagFieldReader.cxx.

59 {
60
61 MsgStream msg( msgSvc(), name() );
62
63 msg << MSG::INFO << "FieldReader intialize() has been called" << endmsg;
64 StatusCode status = service( "MagneticFieldSvc", m_pIMF, true );
65 if ( !status.isSuccess() )
66 {
67 msg << MSG::FATAL << "Unable to open Magnetic field service" << endmsg;
68 return StatusCode::FAILURE;
69 }
70
71 msg << MSG::DEBUG << " Book ntuple" << endmsg;
72
73 NTuplePtr nt1( ntupleSvc(), "FILE1/n1" );
74 if ( nt1 ) m_tuple1 = nt1;
75 else
76 {
77 m_tuple1 = ntupleSvc()->book( "FILE1/n1", CLID_ColumnWiseTuple, "Field" );
78 if ( m_tuple1 )
79 {
80 status = m_tuple1->addItem( "x", m_x );
81 status = m_tuple1->addItem( "y", m_y );
82 status = m_tuple1->addItem( "z", m_z );
83 status = m_tuple1->addItem( "r", m_r );
84 status = m_tuple1->addItem( "Bx", m_Bx );
85 status = m_tuple1->addItem( "By", m_By );
86 status = m_tuple1->addItem( "Bz", m_Bz );
87 status = m_tuple1->addItem( "SigmaBx", m_sigma_bx );
88 status = m_tuple1->addItem( "SigmaBy", m_sigma_by );
89 status = m_tuple1->addItem( "SigmaBz", m_sigma_bz );
90 }
91 else
92 {
93 msg << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple1 ) << endmsg;
94 return StatusCode::FAILURE;
95 }
96 }
97
98 NTuplePtr nt2( ntupleSvc(), "FILE1/n2" );
99 if ( nt2 ) m_tuple2 = nt2;
100 else
101 {
102 m_tuple2 = ntupleSvc()->book( "FILE1/n2", CLID_ColumnWiseTuple, "Field" );
103 if ( m_tuple2 )
104 {
105 status = m_tuple2->addItem( "x", m_x2 );
106 status = m_tuple2->addItem( "y", m_y2 );
107 status = m_tuple2->addItem( "z", m_z2 );
108 status = m_tuple2->addItem( "r", m_r2 );
109 status = m_tuple2->addItem( "Bx", m_Bx2 );
110 status = m_tuple2->addItem( "By", m_By2 );
111 status = m_tuple2->addItem( "Bz", m_Bz2 );
112 }
113 else
114 {
115 msg << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple2 ) << endmsg;
116 return StatusCode::FAILURE;
117 }
118 }
119
120 NTuplePtr nt3( ntupleSvc(), "FILE1/n3" );
121 if ( nt3 ) m_tuple3 = nt3;
122 else
123 {
124 m_tuple3 = ntupleSvc()->book( "FILE1/n3", CLID_ColumnWiseTuple, "Field" );
125 if ( m_tuple3 )
126 {
127 status = m_tuple3->addItem( "x", m_x3 );
128 status = m_tuple3->addItem( "y", m_y3 );
129 status = m_tuple3->addItem( "z", m_z3 );
130 status = m_tuple3->addItem( "r", m_r3 );
131 status = m_tuple3->addItem( "phi", m_phi3 );
132 status = m_tuple3->addItem( "Bx", m_Bx3 );
133 status = m_tuple3->addItem( "By", m_By3 );
134 status = m_tuple3->addItem( "Bz", m_Bz3 );
135 }
136 else
137 {
138 msg << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple3 ) << endmsg;
139 return StatusCode::FAILURE;
140 }
141 }
142
143 NTuplePtr nt4( ntupleSvc(), "FILE1/n4" );
144 if ( nt4 ) m_tuple4 = nt4;
145 else
146 {
147 m_tuple4 = ntupleSvc()->book( "FILE1/n4", CLID_ColumnWiseTuple, "Field" );
148 if ( m_tuple4 ) { status = m_tuple4->addItem( "time", m_time ); }
149 else
150 {
151 msg << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple4 ) << endmsg;
152 return StatusCode::FAILURE;
153 }
154 }
155
156 status = service( "BesTimerSvc", m_timersvc );
157 if ( status.isFailure() )
158 {
159 msg << MSG::ERROR << name() << ": Unable to locate BesTimer Service" << endmsg;
160 return StatusCode::FAILURE;
161 }
162 m_timer = m_timersvc->addItem( "Read field Time" );
163
164 msg << MSG::INFO << "MagFieldReader initialized" << endmsg;
165 return StatusCode::SUCCESS;
166}
INTupleSvc * ntupleSvc()

The documentation for this class was generated from the following files: