BOSS 6.6.4.p01
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 24 of file MagFieldReader.h.

Constructor & Destructor Documentation

◆ MagFieldReader()

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

Standard constructor.

Definition at line 47 of file MagFieldReader.cxx.

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

◆ ~MagFieldReader()

virtual MagFieldReader::~MagFieldReader ( )
inlinevirtual

Definition at line 29 of file MagFieldReader.h.

29{ }; ///< Destructor

Member Function Documentation

◆ execute()

StatusCode MagFieldReader::execute ( )
virtual

Algorithm execution.

Definition at line 167 of file MagFieldReader.cxx.

167 {
168
169 MsgStream msg( msgSvc(), name() );
170
171 msg << MSG::DEBUG << "==> Execute MagFieldReader" << endreq;
172/*
173 //calculate the error of Bfield
174 std::ifstream infile( m_filename.c_str() );
175 if(!infile.good()) msg << MSG::FATAL << "Unable to read the file: " << m_filename << endreq;
176 int nLine = 0;
177 char line[ 255 ];
178 while( infile ) {
179 // parse each line of the file,
180 // comment lines begin with '#' in the cdf file
181 infile.getline( line, 255 );
182 if ( line[0] == '#' ) continue;
183 std::string gridx, gridy, gridz, sFx, sFy, sFz;
184 char* token = strtok( line, " " );
185 if ( token ) { gridx = token; token = strtok( NULL, " " );} else continue;
186 if ( token ) { gridy = token; token = strtok( NULL, " " );} else continue;
187 if ( token ) { gridz = token; token = strtok( NULL, " " );} else continue;
188 if ( token ) { sFx = token; token = strtok( NULL, " " );} else continue;
189 if ( token ) { sFy = token; token = strtok( NULL, " " );} else continue;
190 if ( token ) { sFz = token; token = strtok( NULL, " " );} else continue;
191 if ( token != NULL ) continue;
192 nLine++;
193 double x,y,z,bx,by,bz;
194 //Grid position
195 x = atof( gridx.c_str() );
196 y = atof( gridy.c_str() );
197 z = atof( gridz.c_str() );
198 // Field values are given in tesla in CDF file. Convert to CLHEP units
199 bx = atof( sFx.c_str() );
200 by = atof( sFy.c_str() );
201 bz = atof( sFz.c_str() );
202 //std::cout<<"x,y,z: "<<x<<" "<<y<<" "<<z<<" "<<"bx,by,bz: "<<bx<<" "<<by<<" "<<bz<<std::endl;
203 x = -x*m;
204 y = y*m;
205 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, max_z = 2.1*m, min_z = -2.1*m;
285 px = min_x + (max_x - min_x)*RandFlat::shoot();
286 py = min_y + (max_y - min_y)*RandFlat::shoot();
287 pz = min_z + (max_z - min_z)*RandFlat::shoot();
288 HepPoint3D r(px,py,pz);
289 HepVector3D b;
290 m_pIMF->fieldVector(r,b);
291 bx = b.x()/tesla;
292 by = b.y()/tesla;
293 bz = b.z()/tesla;
294 }
295 m_timer->stop();
296 m_time = m_timer->elapsed();
297 m_tuple4->write();
298/*
299 StatusCode sc = this->readField();
300 if( sc.isFailure() ) {
301 msg << MSG::FATAL << "Unable to execute MagFieldReader"
302 << endreq;
303 return sc;
304 }
305*/
306 msg << MSG::INFO << "MagFieldReader executed" << endreq;
307 return StatusCode::SUCCESS;
308}
IMessageSvc * msgSvc()
void start(void)
Definition: BesTimer.cxx:27
float elapsed(void) const
Definition: BesTimer.h:23
void stop(void)
Definition: BesTimer.cxx:39
virtual StatusCode fieldVector(const HepGeom::Point3D< double > &xyz, HepGeom::Vector3D< double > &fvec) const =0

◆ finalize()

StatusCode MagFieldReader::finalize ( )
virtual

Algorithm finalization.

Definition at line 313 of file MagFieldReader.cxx.

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

◆ initialize()

StatusCode MagFieldReader::initialize ( )
virtual

Destructor.

Algorithm initialization

Definition at line 65 of file MagFieldReader.cxx.

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

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