BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
MagneticFieldSvc Class Reference

#include <MagneticFieldSvc.h>

+ Inheritance diagram for MagneticFieldSvc:

Public Member Functions

 MagneticFieldSvc (const std::string &name, ISvcLocator *svc)
 
virtual ~MagneticFieldSvc ()
 Virtual destructor.
 
virtual StatusCode initialize ()
 Initialise the service (Inherited Service overrides)
 
void init_params ()
 
void init_params (std::vector< double > current, std::vector< double > beamEnergy, int runNo)
 
virtual StatusCode finalize ()
 Finalise the service.
 
virtual const InterfaceID & type () const
 Service type.
 
void handle (const Incident &)
 
virtual StatusCode fieldVector (const HepPoint3D &xyz, HepVector3D &fvec) const
 
virtual StatusCode uniFieldVector (const HepPoint3D &xyz, HepVector3D &fvec) const
 
virtual double getReferField ()
 
virtual bool ifRealField () const
 

Public Attributes

bool m_readOneTime
 
int m_runFrom
 
int m_runTo
 
int runNo
 
IDataProviderSvc * m_eventSvc
 
FieldDBUtil::ConnectionDBm_connect_run
 
std::map< int, std::vector< double > > m_mapMagnetInfo
 
std::map< int, std::vector< double > > m_mapBeamEnergy
 
std::vector< double > beamEnergy
 
std::vector< double > current
 

Detailed Description

A service for finding the magnetic field vector at a given point in space.

Definition at line 41 of file MagneticFieldSvc.h.

Constructor & Destructor Documentation

◆ MagneticFieldSvc()

MagneticFieldSvc::MagneticFieldSvc ( const std::string & name,
ISvcLocator * svc )

Standard Constructor.

Parameters
nameString with service name
svcPointer to service locator interface

Definition at line 48 of file MagneticFieldSvc.cxx.

49 : base_class( name, svc )
50{
51 declareProperty( "TurnOffField", m_turnOffField = false);
52 declareProperty( "FieldMapFile", m_filename );
53 declareProperty( "GridDistance", m_gridDistance = 5);
54 declareProperty( "RunMode", m_runmode = 2);
55 declareProperty( "IfRealField", m_ifRealField = true);
56 declareProperty( "OutLevel", m_outlevel = 1);
57 declareProperty( "Scale", m_scale = 1.0);
58 declareProperty( "UniField", m_uniField = false);
59
60 declareProperty( "Cur_SCQ1_55", m_Cur_SCQ1_55 = 349.4);
61 declareProperty( "Cur_SCQ1_89", m_Cur_SCQ1_89 = 426.2);
62 declareProperty( "Cur_SCQ2_10", m_Cur_SCQ2_10 = 474.2);
63
64 declareProperty( "UseDBFlag", m_useDB = true);
65 declareProperty( "ReadOneTime", m_readOneTime=false);
66 declareProperty( "RunFrom", m_runFrom=8093);
67 declareProperty("RunTo",m_runTo=9025);
68
69 m_Mucfield = new MucMagneticField();
70 if(!m_Mucfield) cout<<"error: can not get MucMagneticField pointer"<<endl;
71
72 m_zfield = -1.0*tesla;
73
74 if(getenv("MAGNETICFIELDROOT") != NULL) {
75 path = std::string(getenv( "MAGNETICFIELDROOT" ));
76 } else {
77 std::cerr<<"Couldn't find MAGNETICFIELDROOT"<<std::endl;
78 }
79
80}
#define NULL

◆ ~MagneticFieldSvc()

MagneticFieldSvc::~MagneticFieldSvc ( )
virtual

Virtual destructor.

Definition at line 113 of file MagneticFieldSvc.cxx.

114{
115 if(m_Mucfield) delete m_Mucfield;
116}

Member Function Documentation

◆ fieldVector()

StatusCode MagneticFieldSvc::fieldVector ( const HepPoint3D & xyz,
HepVector3D & fvec ) const
virtual

IMagneticFieldSvc interface.

Parameters
[in]xyzPoint at which magnetic field vector will be given
[out]fvecMagnectic field vector.
Returns
StatusCode SUCCESS if calculation was performed.

Definition at line 1080 of file MagneticFieldSvc.cxx.

1082{
1083
1084 if(m_turnOffField == true) {
1085 newb[0] = 0.;
1086 newb[1] = 0.;
1087 newb[2] = 0.;
1088#ifndef BEAN
1089 return StatusCode::SUCCESS;
1090#else
1091 return true;
1092#endif
1093 }
1094
1095 // wll added 2012-08-27
1096 if(m_uniField) {
1097 uniFieldVector(newr,newb);
1098#ifndef BEAN
1099 return StatusCode::SUCCESS;
1100#else
1101 return true;
1102#endif
1103 }
1104
1105
1106 //reference frames defined by simulation and SCM are different. In simulation: x--south to north, y--down to up, but in SCM: x--north to south, y--down to up
1107 double new_x = -newr.x();
1108 double new_y = newr.y();
1109 double new_z = -newr.z();
1110 HepPoint3D r(new_x,new_y,new_z);
1111 HepVector3D b;
1112 b[0]=0.0*tesla;
1113 b[1]=0.0*tesla;
1114 b[2]=0.0*tesla;
1115 // This routine is now dummy. Was previously converting to/from CLHEP units
1116 if(-2.1*m<r.z() && r.z()<2.1*m && -1.8*m<r.x() && r.x()<1.8*m && -1.8*m<r.y() && r.y()<1.8*m)
1117 {
1118 if(-1.2*m<r.z()&&r.z()<1.2*m&&0*m<=std::sqrt(r.x()*r.x()+r.y()*r.y())&&std::sqrt(r.x()*r.x()+r.y()*r.y())<0.9*m)
1119 //if(std::abs(r.z())<1.2*m&&std::abs(r.x())<=0.9*m&&std::abs(r.y())<=0.9*m)
1120 {
1121 this->fieldGrid( r, b );
1122 }
1123 else
1124 {
1125 this->fieldGrid_TE( r, b );
1126 }
1127 }
1128 if((fabs(r.z())<=1970*mm && sqrt(r.x()*r.x()+r.y()*r.y()) >= 1740*mm) || (fabs(r.z())>=2050*mm))
1129 {
1130 HepPoint3D mr;
1131 HepVector3D tb;
1132 int part = 0, layer = 0, mat = 0;
1133 double theta;
1134 bool ifbar = false;
1135 bool ifend = false;
1136 if(r.x()!=0.){
1137 theta = atan2(fabs(r.y()),fabs(r.x()));
1138 if(0<=theta&&theta<pi/8) {
1139 mr[0] = fabs(r.x()); mr[1] = -fabs(r.y()); mr[2] = fabs(r.z());
1140 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm){
1141 part = 1;
1142 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1143 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1144 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1145 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1146 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1147 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1148 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1149 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1150 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1151 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1152 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1153 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1154 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1155 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1156 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1157 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1158 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1159 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1160 b[0] = tb[0];
1161 b[1] = -tb[1];
1162 b[2] = tb[2];
1163 ifbar = true;
1164 }
1165 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1166 part = 0; layer = 0; mat = 0;
1167 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1168 b[0] = tb[0];
1169 b[1] = -tb[1];
1170 b[2] = tb[2];
1171 ifend = true;
1172 }
1173 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1174 part = 0; layer = 0; mat = 1;
1175 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1176 b[0] = tb[0];
1177 b[1] = -tb[1];
1178 b[2] = tb[2];
1179 ifend = true;
1180 }
1181 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1182 part = 0; layer = 1; mat = 0;
1183 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1184 b[0] = tb[0];
1185 b[1] = -tb[1];
1186 b[2] = tb[2];
1187 ifend = true;
1188 }
1189 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1190 part = 0; layer = 1; mat = 1;
1191 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1192 b[0] = tb[0];
1193 b[1] = -tb[1];
1194 b[2] = tb[2];
1195 ifend = true;
1196 }
1197 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1198 part = 0; layer = 2; mat = 0;
1199 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1200 b[0] = tb[0];
1201 b[1] = -tb[1];
1202 b[2] = tb[2];
1203 ifend = true;
1204 }
1205 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1206 part = 0; layer = 2; mat = 1;
1207 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1208 b[0] = tb[0];
1209 b[1] = -tb[1];
1210 b[2] = tb[2];
1211 ifend = true;
1212 }
1213 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1214 part = 0; layer = 3; mat = 0;
1215 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1216 b[0] = tb[0];
1217 b[1] = -tb[1];
1218 b[2] = tb[2];
1219 ifend = true;
1220 }
1221 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1222 part = 0; layer = 3; mat = 1;
1223 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1224 b[0] = tb[0];
1225 b[1] = -tb[1];
1226 b[2] = tb[2];
1227 ifend = true;
1228 }
1229 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1230 part = 0; layer = 4; mat = 0;
1231 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1232 b[0] = tb[0];
1233 b[1] = -tb[1];
1234 b[2] = tb[2];
1235 ifend = true;
1236 }
1237 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1238 part = 0; layer = 4; mat = 1;
1239 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1240 b[0] = tb[0];
1241 b[1] = -tb[1];
1242 b[2] = tb[2];
1243 ifend = true;
1244 }
1245 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1246 part = 0; layer = 5; mat = 0;
1247 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1248 b[0] = tb[0];
1249 b[1] = -tb[1];
1250 b[2] = tb[2];
1251 ifend = true;
1252 }
1253 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1254 part = 0; layer = 5; mat =1;
1255 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1256 b[0] = tb[0];
1257 b[1] = -tb[1];
1258 b[2] = tb[2];
1259 ifend = true;
1260 }
1261 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1262 part = 0; layer = 6; mat = 0;
1263 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1264 b[0] = tb[0];
1265 b[1] = -tb[1];
1266 b[2] = tb[2];
1267 ifend = true;
1268 }
1269 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1270 part = 0; layer = 6; mat = 1;
1271 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1272 b[0] = tb[0];
1273 b[1] = -tb[1];
1274 b[2] = tb[2];
1275 ifend = true;
1276 }
1277 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1278 part = 0; layer = 7; mat = 0;
1279 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1280 b[0] = tb[0];
1281 b[1] = -tb[1];
1282 b[2] = tb[2];
1283 ifend = true;
1284 }
1285 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1286 part = 0; layer = 7; mat = 1;
1287 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1288 b[0] = tb[0];
1289 b[1] = -tb[1];
1290 b[2] = tb[2];
1291 ifend = true;
1292 }
1293 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1294 part = 0; layer = 8; mat = 0;
1295 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1296 b[0] = tb[0];
1297 b[1] = -tb[1];
1298 b[2] = tb[2];
1299 ifend = true;
1300 }
1301 }
1302 if(pi/8<=theta&&theta<pi/4) {
1303 mr[0] = fabs(r.x())*cos(pi/4)+fabs(r.y())*sin(pi/4);
1304 mr[1] = -fabs(r.x())*sin(pi/4)+fabs(r.y())*cos(pi/4);
1305 mr[2] = fabs(r.z());
1306 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1307 part = 1;
1308 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1309 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1310 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1311 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1312 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1313 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1314 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1315 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1316 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1317 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1318 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1319 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1320 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1321 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1322 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1323 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1324 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1325 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1326 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1327 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1328 b[2] = tb[2];
1329 ifbar = true;
1330 }
1331 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1332 part = 0; layer = 0; mat = 0;
1333 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1334 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1335 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1336 b[2] = tb[2];
1337 ifend = true;
1338 }
1339 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1340 part = 0; layer = 0; mat = 1;
1341 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1342 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1343 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1344 b[2] = tb[2];
1345 ifend = true;
1346 }
1347 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1348 part = 0; layer = 1; mat = 0;
1349 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1350 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1351 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1352 b[2] = tb[2];
1353 ifend = true;
1354 }
1355 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1356 part = 0; layer = 1; mat = 1;
1357 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1358 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1359 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1360 b[2] = tb[2];
1361 ifend = true;
1362 }
1363 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1364 part = 0; layer = 2; mat = 0;
1365 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1366 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1367 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1368 b[2] = tb[2];
1369 ifend = true;
1370 }
1371 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1372 part = 0; layer = 2; mat = 1;
1373 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1374 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1375 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1376 b[2] = tb[2];
1377 ifend = true;
1378 }
1379 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1380 part = 0; layer = 3; mat = 0;
1381 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1382 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1383 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1384 b[2] = tb[2];
1385 ifend = true;
1386 }
1387 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1388 part = 0; layer = 3; mat = 1;
1389 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1390 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1391 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1392 b[2] = tb[2];
1393 ifend = true;
1394 }
1395 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1396 part = 0; layer = 4; mat = 0;
1397 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1398 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1399 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1400 b[2] = tb[2];
1401 ifend = true;
1402 }
1403 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1404 part = 0; layer = 4; mat = 1;
1405 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1406 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1407 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1408 b[2] = tb[2];
1409 ifend = true;
1410 }
1411 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1412 part = 0; layer = 5; mat = 0;
1413 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1414 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1415 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1416 b[2] = tb[2];
1417 ifend = true;
1418 }
1419 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1420 part = 0; layer = 5; mat =1;
1421 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1422 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1423 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1424 b[2] = tb[2];
1425 ifend = true;
1426 }
1427 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1428 part = 0; layer = 6; mat = 0;
1429 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1430 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1431 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1432 b[2] = tb[2];
1433 ifend = true;
1434 }
1435 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1436 part = 0; layer = 6; mat = 1;
1437 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1438 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1439 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1440 b[2] = tb[2];
1441 ifend = true;
1442 }
1443 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1444 part = 0; layer = 7; mat = 0;
1445 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1446 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1447 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1448 b[2] = tb[2];
1449 ifend = true;
1450 }
1451 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1452 part = 0; layer = 7; mat = 1;
1453 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1454 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1455 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1456 b[2] = tb[2];
1457 ifend = true;
1458 }
1459 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1460 part = 0; layer = 8; mat = 0;
1461 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1462 b[0] = tb[0]*cos(pi/4)-tb[1]*sin(pi/4);
1463 b[1] = tb[0]*sin(pi/4)+tb[1]*cos(pi/4);
1464 b[2] = tb[2];
1465 ifend = true;
1466 }
1467 }
1468 if(pi/4<=theta&&theta<3*pi/8) {
1469 mr[0] = fabs(r.x())*cos(pi/4)+fabs(r.y())*sin(pi/4);
1470 mr[1] = fabs(r.x())*sin(pi/4)-fabs(r.y())*cos(pi/4);
1471 mr[2] = fabs(r.z());
1472 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1473 part = 1;
1474 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1475 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1476 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1477 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1478 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1479 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1480 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1481 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1482 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1483 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1484 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1485 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1486 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1487 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1488 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1489 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1490 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1491 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1492 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1493 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1494 b[2] = tb[2];
1495 ifbar = true;
1496 }
1497 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1498 part = 0; layer = 0; mat = 0;
1499 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1500 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1501 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1502 b[2] = tb[2];
1503 ifend = true;
1504 }
1505 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1506 part = 0; layer = 0; mat = 1;
1507 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1508 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1509 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1510 b[2] = tb[2];
1511 ifend = true;
1512 }
1513 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1514 part = 0; layer = 1; mat = 0;
1515 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1516 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1517 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1518 b[2] = tb[2];
1519 ifend = true;
1520 }
1521 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1522 part = 0; layer = 1; mat = 1;
1523 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1524 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1525 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1526 b[2] = tb[2];
1527 ifend = true;
1528 }
1529 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1530 part = 0; layer = 2; mat = 0;
1531 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1532 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1533 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1534 b[2] = tb[2];
1535 ifend = true;
1536 }
1537 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1538 part = 0; layer = 2; mat = 1;
1539 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1540 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1541 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1542 b[2] = tb[2];
1543 ifend = true;
1544 }
1545 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1546 part = 0; layer = 3; mat = 0;
1547 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1548 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1549 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1550 b[2] = tb[2];
1551 ifend = true;
1552 }
1553 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1554 part = 0; layer = 3; mat = 1;
1555 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1556 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1557 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1558 b[2] = tb[2];
1559 ifend = true;
1560 }
1561 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1562 part = 0; layer = 4; mat = 0;
1563 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1564 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1565 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1566 b[2] = tb[2];
1567 ifend = true;
1568 }
1569 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1570 part = 0; layer = 4; mat = 1;
1571 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1572 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1573 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1574 b[2] = tb[2];
1575 ifend = true;
1576 }
1577 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1578 part = 0; layer = 5; mat = 0;
1579 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1580 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1581 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1582 b[2] = tb[2];
1583 ifend = true;
1584 }
1585 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1586 part = 0; layer = 5; mat =1;
1587 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1588 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1589 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1590 b[2] = tb[2];
1591 ifend = true;
1592 }
1593 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1594 part = 0; layer = 6; mat = 0;
1595 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1596 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1597 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1598 b[2] = tb[2];
1599 ifend = true;
1600 }
1601 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1602 part = 0; layer = 6; mat = 1;
1603 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1604 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1605 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1606 b[2] = tb[2];
1607 ifend = true;
1608 }
1609 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1610 part = 0; layer = 7; mat = 0;
1611 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1612 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1613 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1614 b[2] = tb[2];
1615 ifend = true;
1616 }
1617 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1618 part = 0; layer = 7; mat = 1;
1619 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1620 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1621 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1622 b[2] = tb[2];
1623 ifend = true;
1624 }
1625 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1626 part = 0; layer = 8; mat = 0;
1627 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1628 b[0] = tb[0]*cos(pi/4)+tb[1]*sin(pi/4);
1629 b[1] = tb[0]*sin(pi/4)-tb[1]*cos(pi/4);
1630 b[2] = tb[2];
1631 ifend = true;
1632 }
1633 }
1634 if(3*pi/8<=theta&&theta<pi/2) {
1635 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1636 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1637 part = 1;
1638 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1639 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1640 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1641 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1642 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1643 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1644 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1645 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1646 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1647 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1648 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1649 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1650 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1651 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1652 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1653 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1654 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1655 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1656 b[0] = -tb[1];
1657 b[1] = tb[0];
1658 b[2] = tb[2];
1659 ifbar = true;
1660 }
1661 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1662 part = 0; layer = 0; mat = 0;
1663 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1664 b[0] = -tb[1];
1665 b[1] = tb[0];
1666 b[2] = tb[2];
1667 ifend = true;
1668 }
1669 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1670 part = 0; layer = 0; mat = 1;
1671 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1672 b[0] = -tb[1];
1673 b[1] = tb[0];
1674 b[2] = tb[2];
1675 ifend = true;
1676 }
1677 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1678 part = 0; layer = 1; mat = 0;
1679 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1680 b[0] = -tb[1];
1681 b[1] = tb[0];
1682 b[2] = tb[2];
1683 ifend = true;
1684 }
1685 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1686 part = 0; layer = 1; mat = 1;
1687 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1688 b[0] = -tb[1];
1689 b[1] = tb[0];
1690 b[2] = tb[2];
1691 ifend = true;
1692 }
1693 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1694 part = 0; layer = 2; mat = 0;
1695 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1696 b[0] = -tb[1];
1697 b[1] = tb[0];
1698 b[2] = tb[2];
1699 ifend = true;
1700 }
1701 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1702 part = 0; layer = 2; mat = 1;
1703 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1704 b[0] = -tb[1];
1705 b[1] = tb[0];
1706 b[2] = tb[2];
1707 ifend = true;
1708 }
1709 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1710 part = 0; layer = 3; mat = 0;
1711 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1712 b[0] = -tb[1];
1713 b[1] = tb[0];
1714 b[2] = tb[2];
1715 ifend = true;
1716 }
1717 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1718 part = 0; layer = 3; mat = 1;
1719 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1720 b[0] = -tb[1];
1721 b[1] = tb[0];
1722 b[2] = tb[2];
1723 ifend = true;
1724 }
1725 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1726 part = 0; layer = 4; mat = 0;
1727 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1728 b[0] = -tb[1];
1729 b[1] = tb[0];
1730 b[2] = tb[2];
1731 ifend = true;
1732 }
1733 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1734 part = 0; layer = 4; mat = 1;
1735 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1736 b[0] = -tb[1];
1737 b[1] = tb[0];
1738 b[2] = tb[2];
1739 ifend = true;
1740 }
1741 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1742 part = 0; layer = 5; mat = 0;
1743 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1744 b[0] = -tb[1];
1745 b[1] = tb[0];
1746 b[2] = tb[2];
1747 ifend = true;
1748 }
1749 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1750 part = 0; layer = 5; mat =1;
1751 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1752 b[0] = -tb[1];
1753 b[1] = tb[0];
1754 b[2] = tb[2];
1755 ifend = true;
1756 }
1757 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1758 part = 0; layer = 6; mat = 0;
1759 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1760 b[0] = -tb[1];
1761 b[1] = tb[0];
1762 b[2] = tb[2];
1763 ifend = true;
1764 }
1765 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1766 part = 0; layer = 6; mat = 1;
1767 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1768 b[0] = -tb[1];
1769 b[1] = tb[0];
1770 b[2] = tb[2];
1771 ifend = true;
1772 }
1773 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1774 part = 0; layer = 7; mat = 0;
1775 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1776 b[0] = -tb[1];
1777 b[1] = tb[0];
1778 b[2] = tb[2];
1779 ifend = true;
1780 }
1781 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1782 part = 0; layer = 7; mat = 1;
1783 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1784 b[0] = -tb[1];
1785 b[1] = tb[0];
1786 b[2] = tb[2];
1787 ifend = true;
1788 }
1789 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1790 part = 0; layer = 8; mat = 0;
1791 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1792 b[0] = -tb[1];
1793 b[1] = tb[0];
1794 b[2] = tb[2];
1795 ifend = true;
1796 }
1797 }
1798 }
1799 if(r.x()==0.) {
1800 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1801 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1802 part = 1;
1803 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1804 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1805 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1806 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1807 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1808 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1809 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1810 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1811 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1812 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1813 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1814 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1815 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1816 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1817 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1818 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1819 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1820 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1821 b[0] = -tb[1];
1822 b[1] = tb[0];
1823 b[2] = tb[2];
1824 ifbar = true;
1825 }
1826 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1827 part = 0; layer = 0; mat = 0;
1828 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1829 b[0] = -tb[1];
1830 b[1] = tb[0];
1831 b[2] = tb[2];
1832 ifend = true;
1833 }
1834 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1835 part = 0; layer = 0; mat = 1;
1836 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1837 b[0] = -tb[1];
1838 b[1] = tb[0];
1839 b[2] = tb[2];
1840 ifend = true;
1841 }
1842 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1843 part = 0; layer = 1; mat = 0;
1844 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1845 b[0] = -tb[1];
1846 b[1] = tb[0];
1847 b[2] = tb[2];
1848 ifend = true;
1849 }
1850 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1851 part = 0; layer = 1; mat = 1;
1852 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1853 b[0] = -tb[1];
1854 b[1] = tb[0];
1855 b[2] = tb[2];
1856 ifend = true;
1857 }
1858 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1859 part = 0; layer = 2; mat = 0;
1860 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1861 b[0] = -tb[1];
1862 b[1] = tb[0];
1863 b[2] = tb[2];
1864 ifend = true;
1865 }
1866 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1867 part = 0; layer = 2; mat = 1;
1868 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1869 b[0] = -tb[1];
1870 b[1] = tb[0];
1871 b[2] = tb[2];
1872 ifend = true;
1873 }
1874 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1875 part = 0; layer = 3; mat = 0;
1876 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1877 b[0] = -tb[1];
1878 b[1] = tb[0];
1879 b[2] = tb[2];
1880 ifend = true;
1881 }
1882 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1883 part = 0; layer = 3; mat = 1;
1884 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1885 b[0] = -tb[1];
1886 b[1] = tb[0];
1887 b[2] = tb[2];
1888 ifend = true;
1889 }
1890 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1891 part = 0; layer = 4; mat = 0;
1892 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1893 b[0] = -tb[1];
1894 b[1] = tb[0];
1895 b[2] = tb[2];
1896 ifend = true;
1897 }
1898 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1899 part = 0; layer = 4; mat = 1;
1900 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1901 b[0] = -tb[1];
1902 b[1] = tb[0];
1903 b[2] = tb[2];
1904 ifend = true;
1905 }
1906 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1907 part = 0; layer = 5; mat = 0;
1908 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1909 b[0] = -tb[1];
1910 b[1] = tb[0];
1911 b[2] = tb[2];
1912 ifend = true;
1913 }
1914 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1915 part = 0; layer = 5; mat =1;
1916 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1917 b[0] = -tb[1];
1918 b[1] = tb[0];
1919 b[2] = tb[2];
1920 ifend = true;
1921 }
1922 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1923 part = 0; layer = 6; mat = 0;
1924 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1925 b[0] = -tb[1];
1926 b[1] = tb[0];
1927 b[2] = tb[2];
1928 ifend = true;
1929 }
1930 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1931 part = 0; layer = 6; mat = 1;
1932 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1933 b[0] = -tb[1];
1934 b[1] = tb[0];
1935 b[2] = tb[2];
1936 ifend = true;
1937 }
1938 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1939 part = 0; layer = 7; mat = 0;
1940 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1941 b[0] = -tb[1];
1942 b[1] = tb[0];
1943 b[2] = tb[2];
1944 ifend = true;
1945 }
1946 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1947 part = 0; layer = 7; mat = 1;
1948 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1949 b[0] = -tb[1];
1950 b[1] = tb[0];
1951 b[2] = tb[2];
1952 ifend = true;
1953 }
1954 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1955 part = 0; layer = 8; mat = 0;
1956 m_Mucfield->getMucField(part,layer,mat,mr,tb);
1957 b[0] = -tb[1];
1958 b[1] = tb[0];
1959 b[2] = tb[2];
1960 ifend = true;
1961 }
1962 }
1963 if(ifbar==true||ifend==true) {
1964 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
1965 b[0] = -b[0];
1966 }
1967 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
1968 b[0] = -b[0];
1969 b[1] = -b[1];
1970 }
1971 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
1972 b[1] = -b[1];
1973 }
1974 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
1975 b[0] = -b[0];
1976 b[1] = -b[1];
1977 }
1978 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
1979 b[1] = -b[1];
1980 }
1981 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
1982 b[0] = b[0];
1983 b[1] = b[1];
1984 }
1985 else if( r.x() > 0. && r.y() <= 0. && r.z() < 0. ){
1986 b[0] = -b[0];
1987 }
1988 }
1989 }
1990
1991 //reference frames defined by simulation and SCM are different.
1992 newb[0] = -b[0] * m_scale;
1993 newb[1] = b[1] * m_scale;
1994 newb[2] = -b[2] * m_scale;
1995/* if(-1.2*m<r.z()&&r.z()<1.2*m&&0*m<=std::sqrt(r.x()*r.x()+r.y()*r.y())&&std::sqrt(r.x()*r.x()+r.y()*r.y())<0.9*m) {
1996 return StatusCode::SUCCESS;
1997 }
1998 else {
1999 newb[0] = newb[0] - 0.10*tesla;
2000 newb[1] = newb[1] + 0.10*tesla;
2001 newb[2] = newb[2] - 0.10*tesla;
2002 }*/
2003
2004 //newb[0] = b[0];
2005 //newb[1] = b[1];
2006 //newb[2] = b[2];
2007
2008#ifndef BEAN
2009 return StatusCode::SUCCESS;
2010#else
2011 return true;
2012#endif
2013}
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
virtual StatusCode uniFieldVector(const HepPoint3D &xyz, HepVector3D &fvec) const
void getMucField(int part, int layer, int mat, HepPoint3D &r, HepVector3D &b)
const double b
Definition slope.cxx:9
const float pi
Definition vector3.h:133

◆ finalize()

StatusCode MagneticFieldSvc::finalize ( )
virtual

Finalise the service.

Definition at line 695 of file MagneticFieldSvc.cxx.

696{
697 MsgStream log( msgSvc(), name() );
698 //if(m_connect_run) delete m_connect_run;
699 StatusCode status = Service::finalize();
700
701 if ( status.isSuccess() )
702 log << MSG::INFO << "Service finalized successfully" << endreq;
703 return status;
704}
IMessageSvc * msgSvc()

◆ getReferField()

double MagneticFieldSvc::getReferField ( )
virtual

Definition at line 2063 of file MagneticFieldSvc.cxx.

2064{
2065 if(m_useDB == false) {
2066 if(m_runmode == 8 || m_runmode == 7) m_zfield = -0.9*tesla;
2067 else m_zfield = -1.0*tesla;
2068 }
2069
2070 if(m_turnOffField == true) {
2071 m_zfield = 0.;
2072 }
2073 return m_zfield * m_scale;
2074}

◆ handle()

void MagneticFieldSvc::handle ( const Incident & inc)

Definition at line 727 of file MagneticFieldSvc.cxx.

727 {
728 MsgStream log( messageService(), name() );
729 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
730 if ( inc.type() != "NewRun" ){
731 return;
732 }
733 log << MSG::DEBUG << "Begin New Runcc" << endreq;
734
735 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
736 int new_run = eventHeader->runNumber();
737 if(new_run<0) new_run=-new_run;
738
739
740 if((m_useDB == true)&&(m_readOneTime == false)) {
742 ConnectionDB::eRet e = m_connect_run->getReadSC_MagnetInfo(current,std::abs(new_run));
743 e = m_connect_run->getBeamEnergy(beamEnergy, std::abs(new_run));
745 }
746 else if ((m_useDB == true)&&(m_readOneTime == true))
747 {
748 std::vector<double> beamEnergy;
749 std::vector<double> current(3,0.);
750 //if (m_mapBeamEnergy == NULL ||m_mapBeamEnergy.size() == 0))
751 if (m_mapBeamEnergy.size() == 0)
752 {
753 cout<<"Run:"<<new_run<<" BeamEnergy is NULL, please check!!"<<endl;
754 exit(1);
755 }
756 beamEnergy.push_back((m_mapBeamEnergy[new_run])[0]);
757 beamEnergy.push_back((m_mapBeamEnergy[new_run])[1]);
758 //if (m_mapMagnetInfo.size()<1||m_mapMagnetInfo.isEmpty())
759 if(m_mapMagnetInfo.size() == 0)
760 {
761 cout<<"Run:"<<new_run<<" MagnetInfo is NULL, please check!!"<<endl;
762 exit(1);
763 }
764 current[0]=(m_mapMagnetInfo[new_run])[0];
765 current[1]=(m_mapMagnetInfo[new_run])[1];
766 current[2]=(m_mapMagnetInfo[new_run])[2];
768 }
769}
ConnectionDB::eRet getReadSC_MagnetInfo(std::vector< double > &current, int runNo)
ConnectionDB::eRet getBeamEnergy(std::vector< double > &beamE, int runNo)
FieldDBUtil::ConnectionDB * m_connect_run
std::map< int, std::vector< double > > m_mapMagnetInfo
std::vector< double > beamEnergy
std::map< int, std::vector< double > > m_mapBeamEnergy
std::vector< double > current
IDataProviderSvc * m_eventSvc

◆ ifRealField()

bool MagneticFieldSvc::ifRealField ( ) const
virtual

Definition at line 2076 of file MagneticFieldSvc.cxx.

2076 {
2077 return m_ifRealField;
2078}

◆ init_params() [1/2]

void MagneticFieldSvc::init_params ( )

Referenced by handle(), and init_params().

◆ init_params() [2/2]

void MagneticFieldSvc::init_params ( std::vector< double > current,
std::vector< double > beamEnergy,
int runNo )

Definition at line 270 of file MagneticFieldSvc.cxx.

271{
272 MsgStream log(msgSvc(), name());
273#else
274void init_params(int runNo)
275{
276 if( !init_mucMagneticField() ) {
277 cerr << " STOP! " << endl;
278 exit(1);
279 }
280#endif
281
282 m_Q.clear();
283 m_P.clear();
284 m_Q_1.clear();
285 m_P_1.clear();
286 m_Q_2.clear();
287 m_P_2.clear();
288 m_P_TE.clear();
289 m_Q_TE.clear();
290
291 if(m_gridDistance == 5) {
292 m_Q.reserve(201250);
293 m_P.reserve(201250);
294 m_Q_1.reserve(201250);
295 m_P_1.reserve(201250);
296 m_Q_2.reserve(201250);
297 m_P_2.reserve(201250);
298 m_Q_TE.reserve(176608);
299 m_P_TE.reserve(176608);
300 }
301 if(m_gridDistance == 10) {
302 m_Q.reserve(27082);
303 m_P.reserve(27082);
304 m_Q_1.reserve(27082);
305 m_P_1.reserve(27082);
306 m_Q_2.reserve(27082);
307 m_P_2.reserve(27082);
308 m_Q_TE.reserve(23833);
309 m_P_TE.reserve(23833);
310 }
311
312 char BPR_PRB[200];
313 char BER_PRB[200];
314 sprintf(BPR_PRB,"%f ",beamEnergy[0]);
315 sprintf(BER_PRB,"%f ",beamEnergy[1]);
316 setenv("BEPCII_INFO.BPR_PRB", BPR_PRB, 1);
317 setenv("BEPCII_INFO.BER_PRB", BER_PRB, 1);
318 int ssm_curr = int (current[0]);
319 double scql_curr = current[1];
320 double scqr_curr = current[2];
321// cout<<"curent is:"<<ssm_curr<<"scql_curr is:"<<scql_curr<<"scqr_curr is:"<<scqr_currendl;
322
323
324
325#ifndef BEAN
326 log << MSG::INFO << "SSM current: " << current[0] << " SCQL current: " << current[1] << " SCQR current: " << current[2] << " in Run " << runNo << endreq;
327 log << MSG::INFO << "beamEnergy is:"<< beamEnergy[0] <<" BER_PRB:"<< beamEnergy[1] << " in Run " << runNo << endreq;
328#else
329
330 cout << "SSM current: " << current[0] << " SCQL current: " << current[1]
331 << " SCQR current: " << current[2] << " in Run " << runNo << endl;
332 log << MSG::INFO << "beamEnergy is:"<< beamEnergy[0] <<" BER_PRB:"<< beamEnergy[1] << " in Run " << runNo << endreq;
333#endif
334
335 //int ssm_curr = 3369;
336 //double scql_curr = 426.2;
337 //double scqr_curr = 426.2;
338 //for the energy less than 1.89GeV
339 if(((ssm_curr >= 3367) && (ssm_curr <= 3370) && ((scql_curr+scqr_curr)/2 < m_Cur_SCQ1_89))) {
340 m_zfield = -1.0*tesla;
341 m_filename = path;
342 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode2.dat");
343#ifndef BEAN
344 log << MSG::INFO << "Select field map: " << m_filename << endreq;
345#else
346 cout << "Select field map: " << m_filename << endl;
347#endif
348
349 if(((former_m_filename == "First Run") || (former_m_filename != m_filename))&&(m_readOneTime == true))
350 {
351 former_m_filename = m_filename;
352 }
353 else if(m_readOneTime == false) {
354 }
355 StatusCode status = parseFile();
356#ifndef BEAN
357 if ( !status.isSuccess() ) {
358 log << MSG::DEBUG << "Magnetic field parse failled" << endreq;
359 }
360#else
361 if ( !status ) {
362 cout << "Magnetic field parse failled" << endl;
363 }
364#endif
365
366 m_Q_1 = m_Q;
367 m_P_1 = m_P;
368
369 m_Q.clear();
370 m_P.clear();
371 if(m_gridDistance == 5) {
372 m_Q.reserve(201250);
373 m_P.reserve(201250);
374 }
375 if(m_gridDistance == 10) {
376 m_Q.reserve(27082);
377 m_P.reserve(27082);
378 }
379
380 m_filename = path;
381 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode3.dat");
382#ifndef BEAN
383 log << MSG::INFO << "Select field map: " << m_filename << endreq;
384#else
385 cout << "Select field map: " << m_filename << endl;
386#endif
387
388 if(((former_m_filename == "First Run") || (former_m_filename != m_filename))&&(m_readOneTime == true))
389 {
390 former_m_filename = m_filename;
391 }
392 else if(m_readOneTime == false){
393 }
394 status = parseFile();
395#ifndef BEAN
396 if ( !status.isSuccess() ) {
397 log << MSG::DEBUG << "Magnetic field parse failled" << endreq;
398 }
399#else
400 if ( !status ) {
401 cout << "Magnetic field parse failled" << endl;
402 }
403#endif
404
405 m_Q_2 = m_Q;
406 m_P_2 = m_P;
407
408 m_Q.clear();
409 m_P.clear();
410 if(m_gridDistance == 5) {
411 m_Q.reserve(201250);
412 m_P.reserve(201250);
413 }
414 if(m_gridDistance == 10) {
415 m_Q.reserve(27082);
416 m_P.reserve(27082);
417 }
418 //check
419 if(m_Q_2.size() != m_Q_1.size()) {
420#ifndef BEAN
421 log << MSG::FATAL << "The two field maps used in this run are wrong!!!" << endreq;
422#else
423 cout << "The two field maps used in this run are wrong!!!" << endl;
424#endif
425 exit(1);
426 }
427
428 for(unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
429 double fieldvalue = (m_Q_1[iQ] - m_Q_2[iQ])/(m_Cur_SCQ1_55 - m_Cur_SCQ1_89)*((scql_curr+scqr_curr)/2 - m_Cur_SCQ1_89) + m_Q_2[iQ];
430 m_Q.push_back(fieldvalue);
431 m_P.push_back(m_P_2[iQ]);
432 }
433 }
434 //for the energy greater than 1.89GeV
435 if(((ssm_curr >= 3367) && (ssm_curr <= 3370) && ((scql_curr+scqr_curr)/2 >= m_Cur_SCQ1_89))){
436 m_zfield = -1.0*tesla;
437 m_filename = path;
438 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode3.dat");
439#ifndef BEAN
440 log << MSG::INFO << "Select field map: " << m_filename << endreq;
441#else
442 cout << "Select field map: " << m_filename << endl;
443#endif
444 if(((former_m_filename == "First Run") || (former_m_filename != m_filename))&&(m_readOneTime == true))
445 {
446 former_m_filename = m_filename;
447 }
448 else if(m_readOneTime == false){
449 }
450 StatusCode status = parseFile();
451#ifndef BEAN
452 if ( !status.isSuccess() ) {
453 log << MSG::DEBUG << "Magnetic field parse failled" << endreq;
454 }
455#else
456 if ( !status ) {
457 cout << "Magnetic field parse failled" << endl;
458 }
459#endif
460
461 m_Q_1 = m_Q;
462 m_P_1 = m_P;
463
464 m_Q.clear();
465 m_P.clear();
466 if(m_gridDistance == 5) {
467 m_Q.reserve(201250);
468 m_P.reserve(201250);
469 }
470 if(m_gridDistance == 10) {
471 m_Q.reserve(27082);
472 m_P.reserve(27082);
473 }
474
475 m_filename = path;
476 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode4.dat");
477#ifndef BEAN
478 log << MSG::INFO << "Select field map: " << m_filename << endreq;
479#else
480 cout << "Select field map: " << m_filename << endl;
481#endif
482
483 if(((former_m_filename == "First Run") || (former_m_filename != m_filename))&&(m_readOneTime == true))
484 {
485 former_m_filename = m_filename;
486 }
487 else if(m_readOneTime == false){
488 }
489 status = parseFile();
490#ifndef BEAN
491 if ( !status.isSuccess() ) {
492 log << MSG::DEBUG << "Magnetic field parse failled" << endreq;
493 }
494#else
495 if ( !status ) {
496 cout << "Magnetic field parse failled" << endl;
497 }
498#endif
499
500 m_Q_2 = m_Q;
501 m_P_2 = m_P;
502
503 m_Q.clear();
504 m_P.clear();
505 if(m_gridDistance == 5) {
506 m_Q.reserve(201250);
507 m_P.reserve(201250);
508 }
509 if(m_gridDistance == 10) {
510 m_Q.reserve(27082);
511 m_P.reserve(27082);
512 }
513
514 //check
515 if(m_Q_2.size() != m_Q_1.size()) {
516#ifndef BEAN
517
518 log << MSG::FATAL << "The two field maps used in this run are wrong!!!" << endreq;
519
520#else
521
522 cout << "The two field maps used in this run are wrong!!!" << endl;
523
524#endif
525 exit(1);
526 }
527
528 for(unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
529 double fieldvalue = (m_Q_1[iQ] - m_Q_2[iQ])/(m_Cur_SCQ1_89 - m_Cur_SCQ2_10)*((scql_curr+scqr_curr)/2 - m_Cur_SCQ2_10) + m_Q_2[iQ];
530 m_Q.push_back(fieldvalue);
531 m_P.push_back(m_P_2[iQ]);
532 }
533 }
534 if((ssm_curr >= 3033) && (ssm_curr <= 3035)) {
535 m_zfield = -0.9*tesla;
536 m_filename = path;
537 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode7.dat");
538#ifndef BEAN
539 log << MSG::INFO << "Select field map: " << m_filename << endreq;
540#else
541 cout << "Select field map: " << m_filename << endl;
542#endif
543
544 if(((former_m_filename == "First Run") || (former_m_filename != m_filename))&&(m_readOneTime == true))
545 {
546 former_m_filename = m_filename;
547 }
548 else if(m_readOneTime == false){
549 }
550 StatusCode status = parseFile();
551#ifndef BEAN
552 if ( !status.isSuccess() ) {
553 log << MSG::DEBUG << "Magnetic field parse failled" << endreq;
554 }
555#else
556 if ( !status ) {
557 cout << "Magnetic field parse failled" << endl;
558 }
559#endif
560
561 m_Q_1 = m_Q;
562 m_P_1 = m_P;
563
564 m_Q.clear();
565 m_P.clear();
566 if(m_gridDistance == 5) {
567 m_Q.reserve(201250);
568 m_P.reserve(201250);
569 }
570 if(m_gridDistance == 10) {
571 m_Q.reserve(27082);
572 m_P.reserve(27082);
573 }
574
575 m_filename = path;
576 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode8.dat");
577#ifndef BEAN
578 log << MSG::INFO << "Select field map: " << m_filename << endreq;
579#else
580 cout << "Select field map: " << m_filename << endl;
581#endif
582
583 if(((former_m_filename == "First Run") || (former_m_filename != m_filename))&&(m_readOneTime == true)){
584 former_m_filename = m_filename;
585 }
586 else if(m_readOneTime == false){
587 }
588 status = parseFile();
589#ifndef BEAN
590 if ( !status.isSuccess() ) {
591 log << MSG::DEBUG << "Magnetic field parse failled" << endreq;
592 }
593#else
594 if ( !status ) {
595 cout << "Magnetic field parse failled" << endl;
596 }
597#endif
598
599 m_Q_2 = m_Q;
600 m_P_2 = m_P;
601
602 m_Q.clear();
603 m_P.clear();
604 if(m_gridDistance == 5) {
605 m_Q.reserve(201250);
606 m_P.reserve(201250);
607 }
608 if(m_gridDistance == 10) {
609 m_Q.reserve(27082);
610 m_P.reserve(27082);
611 }
612 //check
613 if(m_Q_2.size() != m_Q_1.size()) {
614#ifndef BEAN
615 log << MSG::FATAL << "The two field maps used in this run are wrong!!!" << endreq;
616#else
617 cout << "The two field maps used in this run are wrong!!!" << endl;
618#endif
619 exit(1);
620 }
621
622 for(unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
623 double fieldvalue = (m_Q_1[iQ] - m_Q_2[iQ])/(m_Cur_SCQ1_55 - m_Cur_SCQ1_89)*((scql_curr+scqr_curr)/2 - m_Cur_SCQ1_89) + m_Q_2[iQ];
624 m_Q.push_back(fieldvalue);
625 m_P.push_back(m_P_2[iQ]);
626 }
627 }
628 if((!((ssm_curr >= 3367) && (ssm_curr <= 3370)) && !((ssm_curr >= 3033) && (ssm_curr <= 3035))) || scql_curr == 0 || scqr_curr == 0) {
629#ifndef BEAN
630 log << MSG::FATAL << "The current of run " << runNo << " is abnormal in database, please check it! " << endreq;
631 log << MSG::FATAL << "The current of SSM is " << ssm_curr << ", SCQR is " << scqr_curr << ", SCQL is " << scql_curr << endreq;
632#else
633 cout << "The current of run " << runNo
634 << " is abnormal in database, please check it! " << endl;
635 cout << "The current of SSM is " << ssm_curr
636 << ", SCQR is " << scqr_curr << ", SCQL is " << scql_curr << endl;
637#endif
638 exit(1);
639
640 }
641 if(m_Q.size() == 0) {
642#ifndef BEAN
643 log << MSG::FATAL << "This size of field map vector is ZERO, please check the current of run " << runNo << " in database!" << endreq;
644#else
645 cout << "This size of field map vector is ZERO,"
646 << " please check the current of run " << runNo
647 << " in database!" << endl;
648#endif
649 exit(1);
650 }
651
652 m_filename_TE = path;
653 if(m_gridDistance == 10) m_filename_TE += std::string( "/dat/TEMap10cm.dat");
654 if(m_gridDistance == 5) m_filename_TE += std::string( "/dat/TEMap5cm.dat");
655#ifndef BEAN
656 log << MSG::INFO << "Select field map: " << m_filename_TE << endreq;
657#else
658 cout << "Select field map: " << m_filename_TE << endl;
659#endif
660 if(((former_m_filename_TE == "First Run") || (former_m_filename_TE != m_filename_TE))&&(m_readOneTime == true))
661 {
662 former_m_filename_TE = m_filename_TE;
663 }
664 else if (m_readOneTime == false)
665 {}
666 StatusCode status = parseFile_TE();
667#ifndef BEAN
668 if ( !status.isSuccess() ) {
669 log << MSG::DEBUG << "Magnetic field parse failled" << endreq;
670 }
671#else
672 if ( !status ) {
673 cout << "Magnetic field parse failled" << endl;
674 }
675#endif
676
677 for (int iC = 0; iC< 2; ++iC ){
678 m_min_FL[iC] = -90.0*cm;
679 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
680 //for tof and emc
681 m_min_FL_TE[iC] = 0.0*cm;
682 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
683 } // iC
684 m_min_FL[2] = -120.0*cm;
685 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
686 //for tof and emc
687 m_min_FL_TE[2] = 0.0*cm;
688 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
689}
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)

◆ initialize()

StatusCode MagneticFieldSvc::initialize ( )
virtual

Initialise the service (Inherited Service overrides)

Definition at line 140 of file MagneticFieldSvc.cxx.

141{
142#ifndef BEAN
143 MsgStream log(msgSvc(), name());
144 StatusCode status = Service::initialize();
145 former_m_filename_TE = "First Run";
146 former_m_filename = "First Run";
147 //cout<<"former_m_filename_TE is:"<<former_m_filename_TE<<":former_m_filename is:"<<former_m_filename<<endl;
148 // Get the references to the services that are needed by the ApplicationMgr itself
149 IIncidentSvc* incsvc;
150 status = service("IncidentSvc", incsvc);
151 int priority = 100;
152 if( status.isSuccess() ){
153 incsvc -> addListener(this, "NewRun", priority);
154 }
155
156 status = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
157 if (status.isFailure() ) {
158 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
159 return status;
160 }
161#else
162 if( !init_mucMagneticField() ) return false;
163 StatusCode status = true;
164#endif
165 if(m_useDB == false) {
166 if(m_gridDistance == 5) {
167 m_Q.reserve(201250);
168 m_P.reserve(201250);
169 m_Q_TE.reserve(176608);
170 m_P_TE.reserve(176608);
171 }
172 if(m_gridDistance == 10) {
173 m_Q.reserve(27082);
174 m_P.reserve(27082);
175 m_Q_TE.reserve(23833);
176 m_P_TE.reserve(23833);
177 }
178
179 m_filename = path;
180 m_filename_TE = path;
181 if(m_gridDistance == 10) {
182 m_filename_TE += std::string("/dat/TEMap10cm.dat");
183 if(m_runmode == 2)
184 m_filename += std::string( "/dat/2008-04-03BESIII-field-Mode2.dat");
185 else if(m_runmode == 4)
186 m_filename += std::string( "/dat/2008-04-03BESIII-field-Mode4.dat");
187 else if(m_runmode == 6)
188 m_filename += std::string( "/dat/2008-04-03BESIII-field-Mode6.dat");
189 else if(m_runmode == 7)
190 m_filename += std::string( "/dat/2008-04-03BESIII-field-Mode7.dat");
191 else {
192 m_filename += std::string( "/dat/2007-08-28BESIII-field.dat");
193 std::cout<<"WARNING: YOU ARE USING OLD FIELD MAP!!!!"<<std::endl;
194 }
195 }
196 if(m_gridDistance == 5) {
197 m_filename_TE += std::string("/dat/TEMap5cm.dat");
198 if(m_runmode == 1)
199 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode1.dat");
200 else if(m_runmode == 2)
201 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode2.dat");
202 else if(m_runmode == 3)
203 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode3.dat");
204 else if(m_runmode == 4)
205 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode4.dat");
206 else if(m_runmode == 5)
207 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode5.dat");
208 else if(m_runmode == 6)
209 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode6.dat");
210 else if(m_runmode == 7)
211 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode7.dat");
212 else if(m_runmode == 8)
213 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode8.dat");
214 else {
215 m_filename += std::string( "/dat/2008-05-27BESIII-field-Mode2.dat");
216 std::cout<<"WARNING: NO RUN MODE, YOU ARE USING DEFAULT FIELD MAP!!!!"<<std::endl;
217 }
218 }
219 cout<<"*** Read field map: "<<m_filename<<endl;
220 cout<<"*** Read field map "<<m_filename_TE<<endl;
221
222 status = parseFile();
223 status = parseFile_TE();
224#ifndef BEAN
225 if ( status.isSuccess() ) {
226 log << MSG::DEBUG << "Magnetic field parsed successfully" << endreq;
227#else
228 if ( status ) {
229 cout << "Magnetic field parsed successfully" << endl;
230#endif
231
232 for (int iC = 0; iC< 2; ++iC ){
233 m_min_FL[iC] = -90.0*cm;
234 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
235 //for tof and emc
236 m_min_FL_TE[iC] = 0.0*cm;
237 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
238 } // iC
239 m_min_FL[2] = -120.0*cm;
240 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
241 //for tof and emc
242 m_min_FL_TE[2] = 0.0*cm;
243 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
244 }
245 else {
246#ifndef BEAN
247 log << MSG::DEBUG << "Magnetic field parse failled" << endreq;
248#else
249 cout << "Magnetic field parse failled" << endl;
250#endif
251 }
252 }
253 else {
255 if (m_readOneTime == true){
258 }
259#ifndef BEAN
260 if (!m_connect_run) {
261 log << MSG::ERROR << "Could not open connection to database" << endreq;
262 }
263#endif
264 }
265 return status;
266}

◆ type()

virtual const InterfaceID & MagneticFieldSvc::type ( ) const
inlinevirtual

Service type.

Query the available interfaces.

Parameters
riidRequested interface ID
ppvInterfacePointer to requested interface
Returns
StatusCode indicating SUCCESS or FAILURE.

Definition at line 72 of file MagneticFieldSvc.h.

72{ return IMagneticFieldSvc::interfaceID(); };

◆ uniFieldVector()

StatusCode MagneticFieldSvc::uniFieldVector ( const HepPoint3D & xyz,
HepVector3D & fvec ) const
virtual

Definition at line 2015 of file MagneticFieldSvc.cxx.

2017{
2018 if(m_runmode == 8 || m_runmode == 7) {
2019 if(-1.5*m<=r.z()&&r.z()<=1.5*m&&0*m<=std::sqrt(r.x()*r.x()+r.y()*r.y())&&std::sqrt(r.x()*r.x()+r.y()*r.y())<=1.5*m)
2020 {
2021 b[0]=0.0;
2022 b[1]=0.0;
2023 b[2]=-0.9*tesla;
2024 }
2025 else
2026 {
2027 b[0]=0.0;
2028 b[1]=0.0;
2029 b[2]=0.0;
2030 }
2031 }
2032 else {
2033 if(-1.5*m<=r.z()&&r.z()<=1.5*m&&0*m<=std::sqrt(r.x()*r.x()+r.y()*r.y())&&std::sqrt(r.x()*r.x()+r.y()*r.y())<=1.5*m)
2034 {
2035 b[0]=0.0;
2036 b[1]=0.0;
2037 b[2]=-1.0*tesla;
2038 }
2039 else
2040 {
2041 b[0]=0.0;
2042 b[1]=0.0;
2043 b[2]=0.0;
2044 }
2045 }
2046
2047 if(m_turnOffField == true) {
2048 b[0] = 0.;
2049 b[1] = 0.;
2050 b[2] = 0.;
2051 }
2052 //yzhang add 2012-04-25
2053 b[0] *= m_scale;
2054 b[1] *= m_scale;
2055 b[2] *= m_scale;
2056#ifndef BEAN
2057 return StatusCode::SUCCESS;
2058#else
2059 return true;
2060#endif
2061}

Referenced by fieldVector().

Member Data Documentation

◆ beamEnergy

std::vector<double> MagneticFieldSvc::beamEnergy

Definition at line 207 of file MagneticFieldSvc.h.

Referenced by handle(), and init_params().

◆ current

std::vector<double> MagneticFieldSvc::current

Definition at line 208 of file MagneticFieldSvc.h.

Referenced by handle(), and init_params().

◆ m_connect_run

FieldDBUtil::ConnectionDB* MagneticFieldSvc::m_connect_run

Definition at line 204 of file MagneticFieldSvc.h.

Referenced by handle(), and initialize().

◆ m_eventSvc

IDataProviderSvc* MagneticFieldSvc::m_eventSvc

Definition at line 201 of file MagneticFieldSvc.h.

Referenced by handle(), and initialize().

◆ m_mapBeamEnergy

std::map<int, std::vector<double> > MagneticFieldSvc::m_mapBeamEnergy

Definition at line 206 of file MagneticFieldSvc.h.

Referenced by handle(), and initialize().

◆ m_mapMagnetInfo

std::map<int, std::vector<double> > MagneticFieldSvc::m_mapMagnetInfo

Definition at line 205 of file MagneticFieldSvc.h.

Referenced by handle(), and initialize().

◆ m_readOneTime

bool MagneticFieldSvc::m_readOneTime

Definition at line 195 of file MagneticFieldSvc.h.

Referenced by handle(), init_params(), and initialize().

◆ m_runFrom

int MagneticFieldSvc::m_runFrom

Definition at line 196 of file MagneticFieldSvc.h.

Referenced by initialize().

◆ m_runTo

int MagneticFieldSvc::m_runTo

Definition at line 197 of file MagneticFieldSvc.h.

Referenced by initialize().

◆ runNo

int MagneticFieldSvc::runNo

Definition at line 198 of file MagneticFieldSvc.h.

Referenced by init_params().


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