3#include "GaudiKernel/AlgFactory.h"
4#include "GaudiKernel/SvcFactory.h"
5#include "GaudiKernel/ISvcLocator.h"
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/Incident.h"
8#include "GaudiKernel/IIncidentSvc.h"
9#include "GaudiKernel/IDataProviderSvc.h"
10#include "GaudiKernel/DataObject.h"
11#include "GaudiKernel/SmartDataPtr.h"
13#include "MagneticField/IMagneticFieldSvc.h"
16#include "MagneticField/MagneticFieldSvc.h"
17#include "MagneticField/MucMagneticField.h"
19#include "CLHEP/Units/PhysicalConstants.h"
22#include "EventModel/EventModel.h"
23#include "EventModel/EventHeader.h"
48 ISvcLocator* svc ) : Service( name, svc )
50 declareProperty(
"TurnOffField", m_turnOffField =
false);
51 declareProperty(
"FieldMapFile", m_filename );
52 declareProperty(
"GridDistance", m_gridDistance = 5);
53 declareProperty(
"RunMode", m_runmode = 2);
54 declareProperty(
"IfRealField", m_ifRealField =
true);
55 declareProperty(
"OutLevel", m_outlevel = 1);
56 declareProperty(
"Scale", m_scale = 1.0);
57 declareProperty(
"UniField", m_uniField =
false);
59 declareProperty(
"Cur_SCQ1_55", m_Cur_SCQ1_55 = 349.4);
60 declareProperty(
"Cur_SCQ1_89", m_Cur_SCQ1_89 = 426.2);
61 declareProperty(
"Cur_SCQ2_10", m_Cur_SCQ2_10 = 474.2);
63 declareProperty(
"UseDBFlag", m_useDB =
true);
65 declareProperty(
"RunFrom",
m_runFrom=8093);
66 declareProperty(
"RunTo",
m_runTo=9025);
69 if(!m_Mucfield) cout<<
"error: can not get MucMagneticField pointer"<<endl;
71 m_zfield = -1.0*tesla;
73 if(getenv(
"MAGNETICFIELDROOT") != NULL) {
74 path = std::string(getenv(
"MAGNETICFIELDROOT" ));
76 std::cerr<<
"Couldn't find MAGNETICFIELDROOT"<<std::endl;
96 m_Cur_SCQ1_55 = 349.4;
97 m_Cur_SCQ1_89 = 426.2;
98 m_Cur_SCQ2_10 = 474.2;
105 m_zfield = -1.0*tesla;
114 if(m_Mucfield)
delete m_Mucfield;
121bool init_mucMagneticField()
125 if( m_Mucfield->getPath() == path )
return true;
131 cout<<
"error: can not get MucMagneticField pointer"<<endl;
142 MsgStream log(
msgSvc(), name());
143 StatusCode status = Service::initialize();
144 former_m_filename_TE =
"First Run";
145 former_m_filename =
"First Run";
148 IIncidentSvc* incsvc;
149 status = service(
"IncidentSvc", incsvc);
151 if( status.isSuccess() ){
152 incsvc -> addListener(
this,
"NewRun", priority);
155 status = serviceLocator()->service(
"EventDataSvc",
m_eventSvc,
true);
156 if (status.isFailure() ) {
157 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
161 if( !init_mucMagneticField() )
return false;
162 StatusCode status =
true;
164 if(m_useDB ==
false) {
165 if(m_gridDistance == 5) {
168 m_Q_TE.reserve(176608);
169 m_P_TE.reserve(176608);
171 if(m_gridDistance == 10) {
174 m_Q_TE.reserve(23833);
175 m_P_TE.reserve(23833);
179 m_filename_TE = path;
180 if(m_gridDistance == 10) {
181 m_filename_TE += std::string(
"/dat/TEMap10cm.dat");
183 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode2.dat");
184 else if(m_runmode == 4)
185 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode4.dat");
186 else if(m_runmode == 6)
187 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode6.dat");
188 else if(m_runmode == 7)
189 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode7.dat");
191 m_filename += std::string(
"/dat/2007-08-28BESIII-field.dat");
192 std::cout<<
"WARNING: YOU ARE USING OLD FIELD MAP!!!!"<<std::endl;
195 if(m_gridDistance == 5) {
196 m_filename_TE += std::string(
"/dat/TEMap5cm.dat");
198 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode1.dat");
199 else if(m_runmode == 2)
200 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode2.dat");
201 else if(m_runmode == 3)
202 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
203 else if(m_runmode == 4)
204 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode4.dat");
205 else if(m_runmode == 5)
206 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode5.dat");
207 else if(m_runmode == 6)
208 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode6.dat");
209 else if(m_runmode == 7)
210 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode7.dat");
211 else if(m_runmode == 8)
212 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode8.dat");
214 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode2.dat");
215 std::cout<<
"WARNING: NO RUN MODE, YOU ARE USING DEFAULT FIELD MAP!!!!"<<std::endl;
218 cout<<
"*** Read field map00: "<<m_filename<<endl;
219 cout<<
"*** Read field map11: "<<m_filename_TE<<endl;
220 if((former_m_filename_TE ==
"First Run") || (former_m_filename_TE != m_filename_TE))
222 former_m_filename_TE = m_filename_TE;
223 status = parseFile_TE();
225 if ( status.isSuccess() ) {
226 log << MSG::DEBUG <<
"Magnetic field parsed successfully" << endreq;
229 cout <<
"Magnetic field parsed successfully" << endl;
234 if(former_m_filename_TE == m_filename_TE) {
237 if((former_m_filename ==
"First Run") || (former_m_filename != m_filename))
239 former_m_filename = m_filename;
240 status = parseFile();
249 if(former_m_filename == m_filename) {
256 if ( status.isSuccess() ) {
257 log << MSG::DEBUG <<
"Magnetic field parsed successfully" << endreq;
260 cout <<
"Magnetic field parsed successfully" << endl;
263 for (
int iC = 0; iC< 2; ++iC ){
264 m_min_FL[iC] = -90.0*cm;
265 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
267 m_min_FL_TE[iC] = 0.0*cm;
268 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
270 m_min_FL[2] = -120.0*cm;
271 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
273 m_min_FL_TE[2] = 0.0*cm;
274 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
278 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
280 cout <<
"Magnetic field parse failled" << endl;
293 log << MSG::ERROR <<
"Could not open connection to database" << endreq;
304 MsgStream log(
msgSvc(), name());
308 if( !init_mucMagneticField() ) {
309 cerr <<
" STOP! " << endl;
323 if(m_gridDistance == 5) {
326 m_Q_1.reserve(201250);
327 m_P_1.reserve(201250);
328 m_Q_2.reserve(201250);
329 m_P_2.reserve(201250);
330 m_Q_TE.reserve(176608);
331 m_P_TE.reserve(176608);
333 if(m_gridDistance == 10) {
336 m_Q_1.reserve(27082);
337 m_P_1.reserve(27082);
338 m_Q_2.reserve(27082);
339 m_P_2.reserve(27082);
340 m_Q_TE.reserve(23833);
341 m_P_TE.reserve(23833);
348 setenv(
"BEPCII_INFO.BPR_PRB", BPR_PRB, 1);
349 setenv(
"BEPCII_INFO.BER_PRB", BER_PRB, 1);
350 int ssm_curr = int (
current[0]);
358 log << MSG::INFO <<
"SSM current: " <<
current[0] <<
" SCQL current: " <<
current[1] <<
" SCQR current: " <<
current[2] <<
" in Run " <<
runNo << endreq;
362 cout <<
"SSM current11: " <<
current[0] <<
" SCQL current: " <<
current[1]
363 <<
" SCQR current: " <<
current[2] <<
" in Run " <<
runNo << endl;
371 if((ssm_curr >= 3367) && (ssm_curr <= 3370) && ((scql_curr+scqr_curr)/2 < m_Cur_SCQ1_89)) {
372 m_zfield = -1.0*tesla;
374 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode2.dat");
376 log << MSG::INFO <<
"Select field map22: " << m_filename << endreq;
378 cout <<
"Select field map33: " << m_filename << endl;
381 if((former_m_filename ==
"First Run") || (former_m_filename != m_filename))
383 former_m_filename = m_filename;
384 StatusCode status = parseFile();
386 if ( !status.isSuccess() ) {
387 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
391 cout <<
"Magnetic field parse failled" << endl;
395 if(former_m_filename == m_filename) {
415 if(m_gridDistance == 5) {
419 if(m_gridDistance == 10) {
425 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
427 log << MSG::INFO <<
"Select field map44: " << m_filename << endreq;
429 cout <<
"Select field map55: " << m_filename << endl;
432if((former_m_filename ==
"First Run") || (former_m_filename != m_filename))
434 former_m_filename = m_filename;
435 StatusCode status = parseFile();
437 if ( !status.isSuccess() ) {
438 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
442 cout <<
"Magnetic field parse failled" << endl;
446 if(former_m_filename == m_filename) {
467 if(m_gridDistance == 5) {
471 if(m_gridDistance == 10) {
476 if(m_Q_2.size() != m_Q_1.size()) {
478 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
480 cout <<
"The two field maps used in this run are wrong!!!" << endl;
485 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
486 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];
487 m_Q.push_back(fieldvalue);
488 m_P.push_back(m_P_2[iQ]);
492 if((ssm_curr >= 3367) && (ssm_curr <= 3370) && ((scql_curr+scqr_curr)/2 >= m_Cur_SCQ1_89)) {
493 m_zfield = -1.0*tesla;
495 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
497 log << MSG::INFO <<
"Select field map66: " << m_filename << endreq;
499 cout <<
"Select field map77: " << m_filename << endl;
501 if((former_m_filename ==
"First Run") || (former_m_filename != m_filename))
503 former_m_filename = m_filename;
504 StatusCode status = parseFile();
506 if ( !status.isSuccess() ) {
507 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
511 cout <<
"Magnetic field parse failled" << endl;
515 if(former_m_filename == m_filename) {
535 if(m_gridDistance == 5) {
539 if(m_gridDistance == 10) {
545 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode4.dat");
547 log << MSG::INFO <<
"Select field map88: " << m_filename << endreq;
549 cout <<
"Select field map99: " << m_filename << endl;
552 if((former_m_filename ==
"First Run") || (former_m_filename != m_filename))
554 former_m_filename = m_filename;
555 StatusCode status = parseFile();
557 if ( !status.isSuccess() ) {
558 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
562 cout <<
"Magnetic field parse failled" << endl;
566 if(former_m_filename == m_filename) {
586 if(m_gridDistance == 5) {
590 if(m_gridDistance == 10) {
595 if(m_Q_2.size() != m_Q_1.size()) {
597 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
599 cout <<
"The two field maps used in this run are wrong!!!" << endl;
604 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
605 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];
606 m_Q.push_back(fieldvalue);
607 m_P.push_back(m_P_2[iQ]);
610 if((ssm_curr >= 3033) && (ssm_curr <= 3035)) {
611 m_zfield = -0.9*tesla;
613 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode7.dat");
615 log << MSG::INFO <<
"Select field map100: " << m_filename << endreq;
617 cout <<
"Select field map200: " << m_filename << endl;
620 if((former_m_filename ==
"First Run") || (former_m_filename != m_filename))
622 former_m_filename = m_filename;
623 StatusCode status = parseFile();
625 if ( !status.isSuccess() ) {
626 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
630 cout <<
"Magnetic field parse failled" << endl;
634 if(former_m_filename == m_filename) {
654 if(m_gridDistance == 5) {
658 if(m_gridDistance == 10) {
664 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode8.dat");
666 log << MSG::INFO <<
"Select field map300: " << m_filename << endreq;
668 cout <<
"Select field map400: " << m_filename << endl;
671 if((former_m_filename ==
"First Run") || (former_m_filename != m_filename))
673 former_m_filename = m_filename;
674 StatusCode status = parseFile();
676 if ( !status.isSuccess() ) {
677 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
681 cout <<
"Magnetic field parse failled" << endl;
685 if(former_m_filename == m_filename) {
705 if(m_gridDistance == 5) {
709 if(m_gridDistance == 10) {
714 if(m_Q_2.size() != m_Q_1.size()) {
716 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
718 cout <<
"The two field maps used in this run are wrong!!!" << endl;
723 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
724 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];
725 m_Q.push_back(fieldvalue);
726 m_P.push_back(m_P_2[iQ]);
730 if((!((ssm_curr >= 3367) && (ssm_curr <= 3370)) && !((ssm_curr >= 3033) && (ssm_curr <= 3035))) || scql_curr == 0 || scqr_curr == 0) {
732 log << MSG::FATAL <<
"The current of run " <<
runNo <<
" is abnormal in database, please check it! " << endreq;
733 log << MSG::FATAL <<
"The current of SSM is " << ssm_curr <<
", SCQR is " << scqr_curr <<
", SCQL is " << scql_curr << endreq;
735 cout <<
"The current of run " <<
runNo
736 t <<
" is abnormal in database, please check it! " << endl;
737 cout <<
"The current of SSM is " << ssm_curr
738 <<
", SCQR is " << scqr_curr <<
", SCQL is " << scql_curr << endl;
743 if(m_Q.size() == 0) {
745 log << MSG::FATAL <<
"This size of field map vector is ZERO, please check the current of run " <<
runNo <<
" in database!" << endreq;
747 cout <<
"This size of field map vector is ZERO,"
748 <<
" please check the current of run " <<
runNo
749 <<
" in database!" << endl;
754 m_filename_TE = path;
755 if(m_gridDistance == 10) m_filename_TE += std::string(
"/dat/TEMap10cm.dat");
756 if(m_gridDistance == 5) m_filename_TE += std::string(
"/dat/TEMap5cm.dat");
758 log << MSG::INFO <<
"Select field map11: " << m_filename_TE << endreq;
760 cout <<
"Select field map00: " << m_filename_TE << endl;
762 if((former_m_filename_TE ==
"First Run") || (former_m_filename_TE != m_filename_TE))
764 former_m_filename_TE = m_filename_TE;
765 StatusCode status = parseFile_TE();
767 if ( !status.isSuccess() ) {
768 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
772 cout <<
"Magnetic field parse failled" << endl;
776 if(former_m_filename_TE == m_filename_TE) {
791 for (
int iC = 0; iC< 2; ++iC ){
792 m_min_FL[iC] = -90.0*cm;
793 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
795 m_min_FL_TE[iC] = 0.0*cm;
796 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
798 m_min_FL[2] = -120.0*cm;
799 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
801 m_min_FL_TE[2] = 0.0*cm;
802 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
811 MsgStream log(
msgSvc(), name() );
813 StatusCode status = Service::finalize();
815 if ( status.isSuccess() )
816 log << MSG::INFO <<
"Service finalized successfully" << endreq;
824 void** ppvInterface )
826 StatusCode sc = StatusCode::FAILURE;
827 if ( ppvInterface ) {
830 if ( riid == IID_IMagneticFieldSvc ) {
832 sc = StatusCode::SUCCESS;
836 sc = Service::queryInterface( riid, ppvInterface );
842 MsgStream log( messageService(), name() );
843 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
844 if ( inc.type() !=
"NewRun" ){
847 log << MSG::DEBUG <<
"Begin New Runcc" << endreq;
849 SmartDataPtr<Event::EventHeader> eventHeader(
m_eventSvc,
"/Event/EventHeader");
850 int new_run = eventHeader->runNumber();
852 if(new_run<0) new_run=-new_run;
865 std::vector<double>
current(3,0.);
869 cout<<
"Run:"<<new_run<<
" BeamEnergy is NULL, please check!!"<<endl;
877 cout<<
"Run:"<<new_run<<
" MagnetInfo is NULL, please check!!"<<endl;
889 static int save_run = 0;
890 if( new_run == save_run )
return;
892 cout <<
"Begin New Run " << new_run << endl;
894 if(m_useDB ==
true) {
904StatusCode MagneticFieldSvc::parseFile() {
906 StatusCode sc = StatusCode::FAILURE;
908 MsgStream log(
msgSvc(), name() );
910 StatusCode sc =
false;
914 std::ifstream infile( m_filename.c_str() );
918 sc = StatusCode::SUCCESS;
925 infile.getline( line, 255 );
926 }
while( line[0] !=
'P' );
930 char* token = strtok( line,
" " );
933 if ( token ) { sPar[ip] = token; token = strtok( NULL,
" " );}
936 }
while ( token != NULL );
937 long int npar = atoi( sPar[1].
c_str() );
941 infile.getline( line, 255 );
942 }
while( line[0] !=
'G' );
946 infile.getline( line, 255 );
947 }
while( line[0] !=
'#' );
950 infile.getline( line, 255 );
951 std::string sGeom[7];
952 token = strtok( line,
" " );
955 if ( token ) { sGeom[ig] = token; token = strtok( NULL,
" " );}
958 }
while (token != NULL);
961 m_Dxyz[0] = atof( sGeom[0].
c_str() ) * cm;
962 m_Dxyz[1] = atof( sGeom[1].
c_str() ) * cm;
963 m_Dxyz[2] = atof( sGeom[2].
c_str() ) * cm;
964 m_Nxyz[0] = atoi( sGeom[3].
c_str() );
965 m_Nxyz[1] = atoi( sGeom[4].
c_str() );
966 m_Nxyz[2] = atoi( sGeom[5].
c_str() );
967 m_zOffSet = atof( sGeom[6].
c_str() ) * cm;
969 long int nlines = ( npar - 7 ) / 3;
980 infile.getline( line, 255 );
981 if ( line[0] ==
'#' )
continue;
982 std::string gridx, gridy, gridz, sFx, sFy, sFz;
983 char* token = strtok( line,
" " );
984 if ( token ) { gridx = token; token = strtok( NULL,
" " );}
else continue;
985 if ( token ) { gridy = token; token = strtok( NULL,
" " );}
else continue;
986 if ( token ) { gridz = token; token = strtok( NULL,
" " );}
else continue;
987 if ( token ) { sFx = token; token = strtok( NULL,
" " );}
else continue;
988 if ( token ) { sFy = token; token = strtok( NULL,
" " );}
else continue;
989 if ( token ) { sFz = token; token = strtok( NULL,
" " );}
else continue;
990 if ( token != NULL )
continue;
992 double gx = atof( gridx.c_str() ) * m;
993 double gy = atof( gridy.c_str() ) * m;
994 double gz = atof( gridz.c_str() ) * m;
996 double fx = atof( sFx.c_str() ) * tesla;
997 double fy = atof( sFy.c_str() ) * tesla;
998 double fz = atof( sFz.c_str() ) * tesla;
1000 if(m_outlevel == 0) {
1002 log << MSG::DEBUG <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endreq;
1003 log << MSG::DEBUG <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endreq;
1005 cout <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endl;
1006 cout <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endl;
1010 m_P.push_back( gx );
1011 m_P.push_back( gy );
1012 m_P.push_back( gz );
1015 m_Q.push_back( fx );
1016 m_Q.push_back( fy );
1017 m_Q.push_back( fz );
1022 if ( nlines != ncheck) {
1024 log << MSG::ERROR <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1026 return StatusCode::FAILURE;
1028 cout <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1036 log << MSG::ERROR <<
"Unable to open magnetic field file : "
1037 << m_filename << endreq;
1039 cout <<
"Unable to open magnetic field file : "
1040 << m_filename << endl;
1052StatusCode MagneticFieldSvc::parseFile_TE() {
1054 StatusCode sc = StatusCode::FAILURE;
1056 MsgStream log(
msgSvc(), name() );
1058 StatusCode sc =
false;
1062 std::ifstream infile( m_filename_TE.c_str() );
1066 sc = StatusCode::SUCCESS;
1073 infile.getline( line, 255 );
1074 }
while( line[0] !=
'P' );
1077 std::string sPar[2];
1078 char* token = strtok( line,
" " );
1081 if ( token ) { sPar[ip] = token; token = strtok( NULL,
" " );}
1084 }
while ( token != NULL );
1085 long int npar = atoi( sPar[1].
c_str() );
1089 infile.getline( line, 255 );
1090 }
while( line[0] !=
'G' );
1094 infile.getline( line, 255 );
1095 }
while( line[0] !=
'#' );
1098 infile.getline( line, 255 );
1099 std::string sGeom[7];
1100 token = strtok( line,
" " );
1103 if ( token ) { sGeom[ig] = token; token = strtok( NULL,
" " );}
1106 }
while (token != NULL);
1109 m_Dxyz_TE[0] = atof( sGeom[0].
c_str() ) * cm;
1110 m_Dxyz_TE[1] = atof( sGeom[1].
c_str() ) * cm;
1111 m_Dxyz_TE[2] = atof( sGeom[2].
c_str() ) * cm;
1112 m_Nxyz_TE[0] = atoi( sGeom[3].
c_str() );
1113 m_Nxyz_TE[1] = atoi( sGeom[4].
c_str() );
1114 m_Nxyz_TE[2] = atoi( sGeom[5].
c_str() );
1115 m_zOffSet_TE = atof( sGeom[6].
c_str() ) * cm;
1117 long int nlines = ( npar - 7 ) / 3;
1120 long int ncheck = 0;
1128 infile.getline( line, 255 );
1129 if ( line[0] ==
'#' )
continue;
1130 std::string gridx, gridy, gridz, sFx, sFy, sFz;
1131 char* token = strtok( line,
" " );
1132 if ( token ) { gridx = token; token = strtok( NULL,
" " );}
else continue;
1133 if ( token ) { gridy = token; token = strtok( NULL,
" " );}
else continue;
1134 if ( token ) { gridz = token; token = strtok( NULL,
" " );}
else continue;
1135 if ( token ) { sFx = token; token = strtok( NULL,
" " );}
else continue;
1136 if ( token ) { sFy = token; token = strtok( NULL,
" " );}
else continue;
1137 if ( token ) { sFz = token; token = strtok( NULL,
" " );}
else continue;
1138 if ( token != NULL )
continue;
1140 double gx = atof( gridx.c_str() ) * m;
1141 double gy = atof( gridy.c_str() ) * m;
1142 double gz = atof( gridz.c_str() ) * m;
1144 double fx = atof( sFx.c_str() ) * tesla;
1145 double fy = atof( sFy.c_str() ) * tesla;
1146 double fz = atof( sFz.c_str() ) * tesla;
1148 if(m_outlevel == 0) {
1150 log << MSG::DEBUG <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endreq;
1151 log << MSG::DEBUG <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endreq;
1153 cout <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endl;
1154 cout <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endl;
1158 m_P_TE.push_back( gx );
1159 m_P_TE.push_back( gy );
1160 m_P_TE.push_back( gz );
1163 m_Q_TE.push_back( fx );
1164 m_Q_TE.push_back( fy );
1165 m_Q_TE.push_back( fz );
1170 if ( nlines != ncheck) {
1172 log << MSG::ERROR <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1174 return StatusCode::FAILURE;
1176 cout <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1184 log << MSG::ERROR <<
"Unable to open magnetic field file : "
1185 << m_filename_TE << endreq;
1187 cout <<
"Unable to open magnetic field file : "
1188 << m_filename_TE << endl;
1201 if(m_turnOffField ==
true) {
1206 return StatusCode::SUCCESS;
1216 return StatusCode::SUCCESS;
1224 double new_x = -newr.x();
1225 double new_y = newr.y();
1226 double new_z = -newr.z();
1233 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)
1235 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)
1238 this->fieldGrid( r,
b );
1242 this->fieldGrid_TE( r,
b );
1245 if((fabs(r.z())<=1970*mm && sqrt(r.x()*r.x()+r.y()*r.y()) >= 1740*mm) || (fabs(r.z())>=2050*mm))
1249 int part = 0, layer = 0, mat = 0;
1254 theta = atan2(fabs(r.y()),fabs(r.x()));
1255 if(0<=theta&&theta<
pi/8) {
1256 mr[0] = fabs(r.x()); mr[1] = -fabs(r.y()); mr[2] = fabs(r.z());
1257 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm){
1259 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1260 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1261 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1262 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1263 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1264 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1265 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1266 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1267 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1268 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1269 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1270 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1271 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1272 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1273 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1274 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1275 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1282 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1283 part = 0; layer = 0; mat = 0;
1290 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1291 part = 0; layer = 0; mat = 1;
1298 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1299 part = 0; layer = 1; mat = 0;
1306 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1307 part = 0; layer = 1; mat = 1;
1314 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1315 part = 0; layer = 2; mat = 0;
1322 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1323 part = 0; layer = 2; mat = 1;
1330 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1331 part = 0; layer = 3; mat = 0;
1338 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1339 part = 0; layer = 3; mat = 1;
1346 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1347 part = 0; layer = 4; mat = 0;
1354 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1355 part = 0; layer = 4; mat = 1;
1362 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1363 part = 0; layer = 5; mat = 0;
1370 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1371 part = 0; layer = 5; mat =1;
1378 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1379 part = 0; layer = 6; mat = 0;
1386 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1387 part = 0; layer = 6; mat = 1;
1394 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1395 part = 0; layer = 7; mat = 0;
1402 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1403 part = 0; layer = 7; mat = 1;
1410 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1411 part = 0; layer = 8; mat = 0;
1419 if(
pi/8<=theta&&theta<
pi/4) {
1420 mr[0] = fabs(r.x())*
cos(
pi/4)+fabs(r.y())*
sin(
pi/4);
1421 mr[1] = -fabs(r.x())*
sin(
pi/4)+fabs(r.y())*
cos(
pi/4);
1422 mr[2] = fabs(r.z());
1423 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1425 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1426 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1427 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1428 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1429 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1430 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1431 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1432 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1433 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1434 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1435 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1436 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1437 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1438 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1439 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1440 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1441 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1448 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1449 part = 0; layer = 0; mat = 0;
1456 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1457 part = 0; layer = 0; mat = 1;
1464 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1465 part = 0; layer = 1; mat = 0;
1472 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1473 part = 0; layer = 1; mat = 1;
1480 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1481 part = 0; layer = 2; mat = 0;
1488 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1489 part = 0; layer = 2; mat = 1;
1496 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1497 part = 0; layer = 3; mat = 0;
1504 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1505 part = 0; layer = 3; mat = 1;
1512 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1513 part = 0; layer = 4; mat = 0;
1520 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1521 part = 0; layer = 4; mat = 1;
1528 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1529 part = 0; layer = 5; mat = 0;
1536 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1537 part = 0; layer = 5; mat =1;
1544 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1545 part = 0; layer = 6; mat = 0;
1552 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1553 part = 0; layer = 6; mat = 1;
1560 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1561 part = 0; layer = 7; mat = 0;
1568 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1569 part = 0; layer = 7; mat = 1;
1576 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1577 part = 0; layer = 8; mat = 0;
1585 if(
pi/4<=theta&&theta<3*
pi/8) {
1586 mr[0] = fabs(r.x())*
cos(
pi/4)+fabs(r.y())*
sin(
pi/4);
1587 mr[1] = fabs(r.x())*
sin(
pi/4)-fabs(r.y())*
cos(
pi/4);
1588 mr[2] = fabs(r.z());
1589 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1591 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1592 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1593 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1594 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1595 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1596 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1597 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1598 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1599 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1600 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1601 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1602 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1603 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1604 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1605 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1606 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1607 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1614 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1615 part = 0; layer = 0; mat = 0;
1622 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1623 part = 0; layer = 0; mat = 1;
1630 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1631 part = 0; layer = 1; mat = 0;
1638 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1639 part = 0; layer = 1; mat = 1;
1646 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1647 part = 0; layer = 2; mat = 0;
1654 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1655 part = 0; layer = 2; mat = 1;
1662 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1663 part = 0; layer = 3; mat = 0;
1670 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1671 part = 0; layer = 3; mat = 1;
1678 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1679 part = 0; layer = 4; mat = 0;
1686 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1687 part = 0; layer = 4; mat = 1;
1694 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1695 part = 0; layer = 5; mat = 0;
1702 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1703 part = 0; layer = 5; mat =1;
1710 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1711 part = 0; layer = 6; mat = 0;
1718 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1719 part = 0; layer = 6; mat = 1;
1726 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1727 part = 0; layer = 7; mat = 0;
1734 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1735 part = 0; layer = 7; mat = 1;
1742 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1743 part = 0; layer = 8; mat = 0;
1751 if(3*
pi/8<=theta&&theta<
pi/2) {
1752 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1753 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1755 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1756 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1757 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1758 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1759 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1760 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1761 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1762 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1763 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1764 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1765 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1766 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1767 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1768 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1769 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1770 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1771 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1778 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1779 part = 0; layer = 0; mat = 0;
1786 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1787 part = 0; layer = 0; mat = 1;
1794 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1795 part = 0; layer = 1; mat = 0;
1802 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1803 part = 0; layer = 1; mat = 1;
1810 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1811 part = 0; layer = 2; mat = 0;
1818 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1819 part = 0; layer = 2; mat = 1;
1826 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1827 part = 0; layer = 3; mat = 0;
1834 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1835 part = 0; layer = 3; mat = 1;
1842 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1843 part = 0; layer = 4; mat = 0;
1850 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1851 part = 0; layer = 4; mat = 1;
1858 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1859 part = 0; layer = 5; mat = 0;
1866 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1867 part = 0; layer = 5; mat =1;
1874 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1875 part = 0; layer = 6; mat = 0;
1882 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1883 part = 0; layer = 6; mat = 1;
1890 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1891 part = 0; layer = 7; mat = 0;
1898 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1899 part = 0; layer = 7; mat = 1;
1906 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1907 part = 0; layer = 8; mat = 0;
1917 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1918 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1920 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1921 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1922 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1923 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1924 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1925 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1926 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1927 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1928 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1929 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1930 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1931 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1932 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1933 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1934 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1935 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1936 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1943 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1944 part = 0; layer = 0; mat = 0;
1951 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1952 part = 0; layer = 0; mat = 1;
1959 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1960 part = 0; layer = 1; mat = 0;
1967 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1968 part = 0; layer = 1; mat = 1;
1975 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1976 part = 0; layer = 2; mat = 0;
1983 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1984 part = 0; layer = 2; mat = 1;
1991 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1992 part = 0; layer = 3; mat = 0;
1999 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
2000 part = 0; layer = 3; mat = 1;
2007 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
2008 part = 0; layer = 4; mat = 0;
2015 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
2016 part = 0; layer = 4; mat = 1;
2023 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
2024 part = 0; layer = 5; mat = 0;
2031 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
2032 part = 0; layer = 5; mat =1;
2039 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
2040 part = 0; layer = 6; mat = 0;
2047 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
2048 part = 0; layer = 6; mat = 1;
2055 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
2056 part = 0; layer = 7; mat = 0;
2063 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
2064 part = 0; layer = 7; mat = 1;
2071 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
2072 part = 0; layer = 8; mat = 0;
2080 if(ifbar==
true||ifend==
true) {
2081 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
2084 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
2088 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
2091 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
2095 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
2098 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
2102 else if( r.x() > 0. && r.y() <= 0. && r.z() < 0. ){
2109 newb[0] = -
b[0] * m_scale;
2110 newb[1] =
b[1] * m_scale;
2111 newb[2] = -
b[2] * m_scale;
2126 return StatusCode::SUCCESS;
2135 if(m_runmode == 8 || m_runmode == 7) {
2136 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)
2150 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)
2164 if(m_turnOffField ==
true) {
2174 return StatusCode::SUCCESS;
2182 if(m_useDB ==
false) {
2183 if(m_runmode == 8 || m_runmode == 7) m_zfield = -0.9*tesla;
2184 else m_zfield = -1.0*tesla;
2187 if(m_turnOffField ==
true) {
2190 return m_zfield * m_scale;
2194 return m_ifRealField;
2200void MagneticFieldSvc::fieldGrid (
const HepPoint3D& r,
2208 double z = r.z() - m_zOffSet;
2209 if( z < m_min_FL[2] || z > m_max_FL[2] )
return;
2211 if( x < m_min_FL[0] || x > m_max_FL[0] )
return;
2213 if(
y < m_min_FL[1] ||
y > m_max_FL[1] )
return;
2214 int i = int( (x-m_min_FL[0])/m_Dxyz[0]);
2215 int j = int( (
y-m_min_FL[1])/m_Dxyz[1] );
2216 int k = int( (z-m_min_FL[2])/m_Dxyz[2] );
2218 int ijk000 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j ) + i );
2219 int ijk001 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j ) + i );
2220 int ijk010 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j + 1 ) + i );
2221 int ijk011 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j + 1) + i );
2222 int ijk100 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j) + i + 1 );
2223 int ijk101 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j) + i + 1 );
2224 int ijk110 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j + 1) + i + 1 );
2225 int ijk111 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j + 1 ) + i + 1 );
2245 double cx000 = m_Q[ ijk000 ];
2246 double cx001 = m_Q[ ijk001 ];
2247 double cx010 = m_Q[ ijk010 ];
2248 double cx011 = m_Q[ ijk011 ];
2249 double cx100 = m_Q[ ijk100 ];
2250 double cx101 = m_Q[ ijk101 ];
2251 double cx110 = m_Q[ ijk110 ];
2252 double cx111 = m_Q[ ijk111 ];
2253 double cy000 = m_Q[ ijk000+1 ];
2254 double cy001 = m_Q[ ijk001+1 ];
2255 double cy010 = m_Q[ ijk010+1 ];
2256 double cy011 = m_Q[ ijk011+1 ];
2257 double cy100 = m_Q[ ijk100+1 ];
2258 double cy101 = m_Q[ ijk101+1 ];
2259 double cy110 = m_Q[ ijk110+1 ];
2260 double cy111 = m_Q[ ijk111+1 ];
2261 double cz000 = m_Q[ ijk000+2 ];
2262 double cz001 = m_Q[ ijk001+2 ];
2263 double cz010 = m_Q[ ijk010+2 ];
2264 double cz011 = m_Q[ ijk011+2 ];
2265 double cz100 = m_Q[ ijk100+2 ];
2266 double cz101 = m_Q[ ijk101+2 ];
2267 double cz110 = m_Q[ ijk110+2 ];
2268 double cz111 = m_Q[ ijk111+2 ];
2269 double hx1 = (
x-m_min_FL[0]-i*m_Dxyz[0] )/m_Dxyz[0];
2270 double hy1 = (
y-m_min_FL[1]-j*m_Dxyz[1] )/m_Dxyz[1];
2271 double hz1 = ( z-m_min_FL[2]-k*m_Dxyz[2] )/m_Dxyz[2];
2272 double hx0 = 1.0-hx1;
2273 double hy0 = 1.0-hy1;
2274 double hz0 = 1.0-hz1;
2275 double h000 = hx0*hy0*hz0;
2276 if( fabs(h000) > 0.0 &&
2277 cx000 > 9.0e5 && cy000 > 9.0e5 && cz000 > 9.0e5)
return;
2279 double h001 = hx0*hy0*hz1;
2280 if( fabs(h001) > 0.0 &&
2281 cx001 > 9.0e5 && cy001 > 9.0e5 && cz001 > 9.0e5)
return;
2283 double h010 = hx0*hy1*hz0;
2284 if( fabs(h010) > 0.0 &&
2285 cx010 > 9.0e5 && cy010 > 9.0e5 && cz010 > 9.0e5)
return;
2287 double h011 = hx0*hy1*hz1;
2288 if( fabs(h011) > 0.0 &&
2289 cx011 > 9.0e5 && cy011 > 9.0e5 && cz011 > 9.0e5)
return;
2291 double h100 = hx1*hy0*hz0;
2292 if( fabs(h100) > 0.0 &&
2293 cx100 > 9.0e5 && cy100 > 9.0e5 && cz100 > 9.0e5)
return;
2295 double h101 = hx1*hy0*hz1;
2296 if( fabs(h101) > 0.0 &&
2297 cx101 > 9.0e5 && cy101 > 9.0e5 && cz101 > 9.0e5)
return;
2299 double h110 = hx1*hy1*hz0;
2300 if( fabs(h110) > 0.0 &&
2301 cx110 > 9.0e5 && cy110 > 9.0e5 && cz110 > 9.0e5)
return;
2303 double h111 = hx1*hy1*hz1;
2304 if( fabs(h111) > 0.0 &&
2305 cx111 > 9.0e5 && cy111 > 9.0e5 && cz111 > 9.0e5)
return;
2307 bf(0) = ( cx000*h000 + cx001*h001 + cx010*h010 + cx011*h011 +
2308 cx100*h100 + cx101*h101 + cx110*h110 + cx111*h111);
2309 bf(1) = ( cy000*h000 + cy001*h001 + cy010*h010 + cy011*h011 +
2310 cy100*h100 + cy101*h101 + cy110*h110 + cy111*h111 );
2311 bf(2) = ( cz000*h000 + cz001*h001 + cz010*h010 + cz011*h011 +
2312 cz100*h100 + cz101*h101 + cz110*h110 + cz111*h111 );
2319void MagneticFieldSvc::fieldGrid_TE (
const HepPoint3D& r,
2327 double z = r.z() - m_zOffSet_TE;
2328 if( fabs(z) < m_min_FL_TE[2] || fabs(z) > m_max_FL_TE[2] )
return;
2330 if( fabs(x) < m_min_FL_TE[0] || fabs(x) > m_max_FL_TE[0] )
return;
2332 if( fabs(
y) < m_min_FL_TE[1] || fabs(
y) > m_max_FL_TE[1] )
return;
2333 int i = int( (fabs(x)-m_min_FL_TE[0])/m_Dxyz_TE[0]);
2334 int j = int( (fabs(
y)-m_min_FL_TE[1])/m_Dxyz_TE[1] );
2335 int k = int( (fabs(z)-m_min_FL_TE[2])/m_Dxyz_TE[2] );
2337 int ijk000 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j ) + i );
2338 int ijk001 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j ) + i );
2339 int ijk010 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j + 1 ) + i );
2340 int ijk011 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j + 1) + i );
2341 int ijk100 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j) + i + 1 );
2342 int ijk101 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j) + i + 1 );
2343 int ijk110 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j + 1) + i + 1 );
2344 int ijk111 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j + 1 ) + i + 1 );
2358 double cx000 = m_Q_TE[ ijk000 ];
2359 double cx001 = m_Q_TE[ ijk001 ];
2360 double cx010 = m_Q_TE[ ijk010 ];
2361 double cx011 = m_Q_TE[ ijk011 ];
2362 double cx100 = m_Q_TE[ ijk100 ];
2363 double cx101 = m_Q_TE[ ijk101 ];
2364 double cx110 = m_Q_TE[ ijk110 ];
2365 double cx111 = m_Q_TE[ ijk111 ];
2366 double cy000 = m_Q_TE[ ijk000+1 ];
2367 double cy001 = m_Q_TE[ ijk001+1 ];
2368 double cy010 = m_Q_TE[ ijk010+1 ];
2369 double cy011 = m_Q_TE[ ijk011+1 ];
2370 double cy100 = m_Q_TE[ ijk100+1 ];
2371 double cy101 = m_Q_TE[ ijk101+1 ];
2372 double cy110 = m_Q_TE[ ijk110+1 ];
2373 double cy111 = m_Q_TE[ ijk111+1 ];
2374 double cz000 = m_Q_TE[ ijk000+2 ];
2375 double cz001 = m_Q_TE[ ijk001+2 ];
2376 double cz010 = m_Q_TE[ ijk010+2 ];
2377 double cz011 = m_Q_TE[ ijk011+2 ];
2378 double cz100 = m_Q_TE[ ijk100+2 ];
2379 double cz101 = m_Q_TE[ ijk101+2 ];
2380 double cz110 = m_Q_TE[ ijk110+2 ];
2381 double cz111 = m_Q_TE[ ijk111+2 ];
2382 double hx1 = ( fabs(x)-m_min_FL_TE[0]-i*m_Dxyz_TE[0] )/m_Dxyz_TE[0];
2383 double hy1 = ( fabs(
y)-m_min_FL_TE[1]-j*m_Dxyz_TE[1] )/m_Dxyz_TE[1];
2384 double hz1 = ( fabs(z)-m_min_FL_TE[2]-k*m_Dxyz_TE[2] )/m_Dxyz_TE[2];
2385 double hx0 = 1.0-hx1;
2386 double hy0 = 1.0-hy1;
2387 double hz0 = 1.0-hz1;
2388 double h000 = hx0*hy0*hz0;
2389 if( fabs(h000) > 0.0 &&
2390 cx000 > 9.0e5 && cy000 > 9.0e5 && cz000 > 9.0e5)
return;
2392 double h001 = hx0*hy0*hz1;
2393 if( fabs(h001) > 0.0 &&
2394 cx001 > 9.0e5 && cy001 > 9.0e5 && cz001 > 9.0e5)
return;
2396 double h010 = hx0*hy1*hz0;
2397 if( fabs(h010) > 0.0 &&
2398 cx010 > 9.0e5 && cy010 > 9.0e5 && cz010 > 9.0e5)
return;
2400 double h011 = hx0*hy1*hz1;
2401 if( fabs(h011) > 0.0 &&
2402 cx011 > 9.0e5 && cy011 > 9.0e5 && cz011 > 9.0e5)
return;
2404 double h100 = hx1*hy0*hz0;
2405 if( fabs(h100) > 0.0 &&
2406 cx100 > 9.0e5 && cy100 > 9.0e5 && cz100 > 9.0e5)
return;
2408 double h101 = hx1*hy0*hz1;
2409 if( fabs(h101) > 0.0 &&
2410 cx101 > 9.0e5 && cy101 > 9.0e5 && cz101 > 9.0e5)
return;
2412 double h110 = hx1*hy1*hz0;
2413 if( fabs(h110) > 0.0 &&
2414 cx110 > 9.0e5 && cy110 > 9.0e5 && cz110 > 9.0e5)
return;
2416 double h111 = hx1*hy1*hz1;
2417 if( fabs(h111) > 0.0 &&
2418 cx111 > 9.0e5 && cy111 > 9.0e5 && cz111 > 9.0e5)
return;
2420 bf(0) = ( cx000*h000 + cx001*h001 + cx010*h010 + cx011*h011 +
2421 cx100*h100 + cx101*h101 + cx110*h110 + cx111*h111);
2422 bf(1) = ( cy000*h000 + cy001*h001 + cy010*h010 + cy011*h011 +
2423 cy100*h100 + cy101*h101 + cy110*h110 + cy111*h111 );
2424 bf(2) = ( cz000*h000 + cz001*h001 + cz010*h010 + cz011*h011 +
2425 cz100*h100 + cz101*h101 + cz110*h110 + cz111*h111 );
2428 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
2431 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
2435 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
2439 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
2443 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
2446 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
2450 else if( r.x() > 0. && r.y() <= 0. && r.z() < 0. ){
double sin(const BesAngle a)
double cos(const BesAngle a)
ConnectionDB::eRet getReadSC_MagnetInfo(std::vector< double > ¤t, int runNo)
ConnectionDB::eRet getBeamEnergy(std::vector< double > &beamE, int runNo)
std::vector< double > current
FieldDBUtil::ConnectionDB * m_connect_run
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)
void handle(const Incident &)
std::map< int, std::vector< double > > m_mapMagnetInfo
IDataProviderSvc * m_eventSvc
virtual StatusCode uniFieldVector(const HepPoint3D &xyz, HepVector3D &fvec) const
MagneticFieldSvc(const std::string &name, ISvcLocator *svc)
std::map< int, std::vector< double > > m_mapBeamEnergy
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
void getMucField(int part, int layer, int mat, HepPoint3D &r, HepVector3D &b)
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)