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"
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;
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;
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 map: " << m_filename << endreq;
378 cout <<
"Select field map: " << 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 map: " << 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 map: " << 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 map: " << m_filename << endreq;
668 cout <<
"Select field map: " << 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;
735 cout <<
"The current of run " <<
runNo
736 t <<
" is abnormal in database, please check it! " << endl;
742 if(m_Q.size() == 0) {
744 log << MSG::FATAL <<
"This size of field map vector is ZERO, please check the current of run " <<
runNo <<
" in database!" << endreq;
746 cout <<
"This size of field map vector is ZERO,"
747 <<
" please check the current of run " <<
runNo
748 <<
" in database!" << endl;
753 m_filename_TE = path;
754 if(m_gridDistance == 10) m_filename_TE += std::string(
"/dat/TEMap10cm.dat");
755 if(m_gridDistance == 5) m_filename_TE += std::string(
"/dat/TEMap5cm.dat");
757 log << MSG::INFO <<
"Select field map: " << m_filename_TE << endreq;
759 cout <<
"Select field map: " << m_filename_TE << endl;
761 if((former_m_filename_TE ==
"First Run") || (former_m_filename_TE != m_filename_TE))
763 former_m_filename_TE = m_filename_TE;
764 StatusCode status = parseFile_TE();
766 if ( !status.isSuccess() ) {
767 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
771 cout <<
"Magnetic field parse failled" << endl;
775 if(former_m_filename_TE == m_filename_TE) {
790 for (
int iC = 0; iC< 2; ++iC ){
791 m_min_FL[iC] = -90.0*cm;
792 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
794 m_min_FL_TE[iC] = 0.0*cm;
795 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
797 m_min_FL[2] = -120.0*cm;
798 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
800 m_min_FL_TE[2] = 0.0*cm;
801 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
810 MsgStream log(
msgSvc(), name() );
812 StatusCode status = Service::finalize();
814 if ( status.isSuccess() )
815 log << MSG::INFO <<
"Service finalized successfully" << endreq;
823 void** ppvInterface )
825 StatusCode sc = StatusCode::FAILURE;
826 if ( ppvInterface ) {
829 if ( riid == IID_IMagneticFieldSvc ) {
831 sc = StatusCode::SUCCESS;
835 sc = Service::queryInterface( riid, ppvInterface );
841 MsgStream log( messageService(), name() );
842 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
843 if ( inc.type() !=
"NewRun" ){
846 log << MSG::DEBUG <<
"Begin New Runcc" << endreq;
848 SmartDataPtr<Event::EventHeader> eventHeader(
m_eventSvc,
"/Event/EventHeader");
849 int new_run = eventHeader->runNumber();
851 if(new_run<0) new_run=-new_run;
864 std::vector<double>
current(3,0.);
868 cout<<
"Run:"<<new_run<<
" BeamEnergy is NULL, please check!!"<<endl;
876 cout<<
"Run:"<<new_run<<
" MagnetInfo is NULL, please check!!"<<endl;
888 static int save_run = 0;
889 if( new_run == save_run )
return;
891 cout <<
"Begin New Run " << new_run << endl;
893 if(m_useDB ==
true) {
903StatusCode MagneticFieldSvc::parseFile() {
905 StatusCode sc = StatusCode::FAILURE;
907 MsgStream log(
msgSvc(), name() );
909 StatusCode sc =
false;
913 std::ifstream infile( m_filename.c_str() );
917 sc = StatusCode::SUCCESS;
924 infile.getline( line, 255 );
925 }
while( line[0] !=
'P' );
929 char* token = strtok( line,
" " );
932 if ( token ) { sPar[ip] = token; token = strtok( NULL,
" " );}
935 }
while ( token != NULL );
936 long int npar = atoi( sPar[1].
c_str() );
940 infile.getline( line, 255 );
941 }
while( line[0] !=
'G' );
945 infile.getline( line, 255 );
946 }
while( line[0] !=
'#' );
949 infile.getline( line, 255 );
950 std::string sGeom[7];
951 token = strtok( line,
" " );
954 if ( token ) { sGeom[ig] = token; token = strtok( NULL,
" " );}
957 }
while (token != NULL);
960 m_Dxyz[0] = atof( sGeom[0].
c_str() ) * cm;
961 m_Dxyz[1] = atof( sGeom[1].
c_str() ) * cm;
962 m_Dxyz[2] = atof( sGeom[2].
c_str() ) * cm;
963 m_Nxyz[0] = atoi( sGeom[3].
c_str() );
964 m_Nxyz[1] = atoi( sGeom[4].
c_str() );
965 m_Nxyz[2] = atoi( sGeom[5].
c_str() );
966 m_zOffSet = atof( sGeom[6].
c_str() ) * cm;
968 long int nlines = ( npar - 7 ) / 3;
979 infile.getline( line, 255 );
980 if ( line[0] ==
'#' )
continue;
981 std::string gridx, gridy, gridz, sFx, sFy, sFz;
982 char* token = strtok( line,
" " );
983 if ( token ) { gridx = token; token = strtok( NULL,
" " );}
else continue;
984 if ( token ) { gridy = token; token = strtok( NULL,
" " );}
else continue;
985 if ( token ) { gridz = token; token = strtok( NULL,
" " );}
else continue;
986 if ( token ) { sFx = token; token = strtok( NULL,
" " );}
else continue;
987 if ( token ) { sFy = token; token = strtok( NULL,
" " );}
else continue;
988 if ( token ) { sFz = token; token = strtok( NULL,
" " );}
else continue;
989 if ( token != NULL )
continue;
991 double gx = atof( gridx.c_str() ) * m;
992 double gy = atof( gridy.c_str() ) * m;
993 double gz = atof( gridz.c_str() ) * m;
995 double fx = atof( sFx.c_str() ) * tesla;
996 double fy = atof( sFy.c_str() ) * tesla;
997 double fz = atof( sFz.c_str() ) * tesla;
999 if(m_outlevel == 0) {
1001 log << MSG::DEBUG <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endreq;
1002 log << MSG::DEBUG <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endreq;
1004 cout <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endl;
1005 cout <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endl;
1009 m_P.push_back( gx );
1010 m_P.push_back( gy );
1011 m_P.push_back( gz );
1014 m_Q.push_back( fx );
1015 m_Q.push_back( fy );
1016 m_Q.push_back( fz );
1021 if ( nlines != ncheck) {
1023 log << MSG::ERROR <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1025 return StatusCode::FAILURE;
1027 cout <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1035 log << MSG::ERROR <<
"Unable to open magnetic field file : "
1036 << m_filename << endreq;
1038 cout <<
"Unable to open magnetic field file : "
1039 << m_filename << endl;
1051StatusCode MagneticFieldSvc::parseFile_TE() {
1053 StatusCode sc = StatusCode::FAILURE;
1055 MsgStream log(
msgSvc(), name() );
1057 StatusCode sc =
false;
1061 std::ifstream infile( m_filename_TE.c_str() );
1065 sc = StatusCode::SUCCESS;
1072 infile.getline( line, 255 );
1073 }
while( line[0] !=
'P' );
1076 std::string sPar[2];
1077 char* token = strtok( line,
" " );
1080 if ( token ) { sPar[ip] = token; token = strtok( NULL,
" " );}
1083 }
while ( token != NULL );
1084 long int npar = atoi( sPar[1].
c_str() );
1088 infile.getline( line, 255 );
1089 }
while( line[0] !=
'G' );
1093 infile.getline( line, 255 );
1094 }
while( line[0] !=
'#' );
1097 infile.getline( line, 255 );
1098 std::string sGeom[7];
1099 token = strtok( line,
" " );
1102 if ( token ) { sGeom[ig] = token; token = strtok( NULL,
" " );}
1105 }
while (token != NULL);
1108 m_Dxyz_TE[0] = atof( sGeom[0].
c_str() ) * cm;
1109 m_Dxyz_TE[1] = atof( sGeom[1].
c_str() ) * cm;
1110 m_Dxyz_TE[2] = atof( sGeom[2].
c_str() ) * cm;
1111 m_Nxyz_TE[0] = atoi( sGeom[3].
c_str() );
1112 m_Nxyz_TE[1] = atoi( sGeom[4].
c_str() );
1113 m_Nxyz_TE[2] = atoi( sGeom[5].
c_str() );
1114 m_zOffSet_TE = atof( sGeom[6].
c_str() ) * cm;
1116 long int nlines = ( npar - 7 ) / 3;
1119 long int ncheck = 0;
1127 infile.getline( line, 255 );
1128 if ( line[0] ==
'#' )
continue;
1129 std::string gridx, gridy, gridz, sFx, sFy, sFz;
1130 char* token = strtok( line,
" " );
1131 if ( token ) { gridx = token; token = strtok( NULL,
" " );}
else continue;
1132 if ( token ) { gridy = token; token = strtok( NULL,
" " );}
else continue;
1133 if ( token ) { gridz = token; token = strtok( NULL,
" " );}
else continue;
1134 if ( token ) { sFx = token; token = strtok( NULL,
" " );}
else continue;
1135 if ( token ) { sFy = token; token = strtok( NULL,
" " );}
else continue;
1136 if ( token ) { sFz = token; token = strtok( NULL,
" " );}
else continue;
1137 if ( token != NULL )
continue;
1139 double gx = atof( gridx.c_str() ) * m;
1140 double gy = atof( gridy.c_str() ) * m;
1141 double gz = atof( gridz.c_str() ) * m;
1143 double fx = atof( sFx.c_str() ) * tesla;
1144 double fy = atof( sFy.c_str() ) * tesla;
1145 double fz = atof( sFz.c_str() ) * tesla;
1147 if(m_outlevel == 0) {
1149 log << MSG::DEBUG <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endreq;
1150 log << MSG::DEBUG <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endreq;
1152 cout <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endl;
1153 cout <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endl;
1157 m_P_TE.push_back( gx );
1158 m_P_TE.push_back( gy );
1159 m_P_TE.push_back( gz );
1162 m_Q_TE.push_back( fx );
1163 m_Q_TE.push_back( fy );
1164 m_Q_TE.push_back( fz );
1169 if ( nlines != ncheck) {
1171 log << MSG::ERROR <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1173 return StatusCode::FAILURE;
1175 cout <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1183 log << MSG::ERROR <<
"Unable to open magnetic field file : "
1184 << m_filename_TE << endreq;
1186 cout <<
"Unable to open magnetic field file : "
1187 << m_filename_TE << endl;
1200 if(m_turnOffField ==
true) {
1205 return StatusCode::SUCCESS;
1215 return StatusCode::SUCCESS;
1223 double new_x = -newr.x();
1224 double new_y = newr.y();
1225 double new_z = -newr.z();
1232 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)
1234 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)
1237 this->fieldGrid( r,
b );
1241 this->fieldGrid_TE( r,
b );
1244 if((fabs(r.z())<=1970*mm && sqrt(r.x()*r.x()+r.y()*r.y()) >= 1740*mm) || (fabs(r.z())>=2050*mm))
1248 int part = 0, layer = 0, mat = 0;
1253 theta = atan2(fabs(r.y()),fabs(r.x()));
1254 if(0<=theta&&theta<
pi/8) {
1255 mr[0] = fabs(r.x()); mr[1] = -fabs(r.y()); mr[2] = fabs(r.z());
1256 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm){
1258 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1259 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1260 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1261 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1262 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1263 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1264 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1265 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1266 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1267 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1268 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1269 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1270 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1271 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1272 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1273 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1274 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1281 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1282 part = 0; layer = 0; mat = 0;
1289 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1290 part = 0; layer = 0; mat = 1;
1297 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1298 part = 0; layer = 1; mat = 0;
1305 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1306 part = 0; layer = 1; mat = 1;
1313 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1314 part = 0; layer = 2; mat = 0;
1321 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1322 part = 0; layer = 2; mat = 1;
1329 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1330 part = 0; layer = 3; mat = 0;
1337 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1338 part = 0; layer = 3; mat = 1;
1345 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1346 part = 0; layer = 4; mat = 0;
1353 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1354 part = 0; layer = 4; mat = 1;
1361 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1362 part = 0; layer = 5; mat = 0;
1369 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1370 part = 0; layer = 5; mat =1;
1377 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1378 part = 0; layer = 6; mat = 0;
1385 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1386 part = 0; layer = 6; mat = 1;
1393 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1394 part = 0; layer = 7; mat = 0;
1401 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1402 part = 0; layer = 7; mat = 1;
1409 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1410 part = 0; layer = 8; mat = 0;
1418 if(
pi/8<=theta&&theta<
pi/4) {
1419 mr[0] = fabs(r.x())*
cos(
pi/4)+fabs(r.y())*
sin(
pi/4);
1420 mr[1] = -fabs(r.x())*
sin(
pi/4)+fabs(r.y())*
cos(
pi/4);
1421 mr[2] = fabs(r.z());
1422 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1424 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1425 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1426 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1427 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1428 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1429 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1430 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1431 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1432 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1433 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1434 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1435 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1436 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1437 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1438 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1439 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1440 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1447 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1448 part = 0; layer = 0; mat = 0;
1455 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1456 part = 0; layer = 0; mat = 1;
1463 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1464 part = 0; layer = 1; mat = 0;
1471 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1472 part = 0; layer = 1; mat = 1;
1479 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1480 part = 0; layer = 2; mat = 0;
1487 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1488 part = 0; layer = 2; mat = 1;
1495 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1496 part = 0; layer = 3; mat = 0;
1503 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1504 part = 0; layer = 3; mat = 1;
1511 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1512 part = 0; layer = 4; mat = 0;
1519 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1520 part = 0; layer = 4; mat = 1;
1527 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1528 part = 0; layer = 5; mat = 0;
1535 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1536 part = 0; layer = 5; mat =1;
1543 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1544 part = 0; layer = 6; mat = 0;
1551 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1552 part = 0; layer = 6; mat = 1;
1559 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1560 part = 0; layer = 7; mat = 0;
1567 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1568 part = 0; layer = 7; mat = 1;
1575 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1576 part = 0; layer = 8; mat = 0;
1584 if(
pi/4<=theta&&theta<3*
pi/8) {
1585 mr[0] = fabs(r.x())*
cos(
pi/4)+fabs(r.y())*
sin(
pi/4);
1586 mr[1] = fabs(r.x())*
sin(
pi/4)-fabs(r.y())*
cos(
pi/4);
1587 mr[2] = fabs(r.z());
1588 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1590 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1591 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1592 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1593 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1594 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1595 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1596 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1597 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1598 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1599 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1600 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1601 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1602 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1603 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1604 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1605 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1606 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1613 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1614 part = 0; layer = 0; mat = 0;
1621 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1622 part = 0; layer = 0; mat = 1;
1629 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1630 part = 0; layer = 1; mat = 0;
1637 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1638 part = 0; layer = 1; mat = 1;
1645 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1646 part = 0; layer = 2; mat = 0;
1653 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1654 part = 0; layer = 2; mat = 1;
1661 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1662 part = 0; layer = 3; mat = 0;
1669 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1670 part = 0; layer = 3; mat = 1;
1677 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1678 part = 0; layer = 4; mat = 0;
1685 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1686 part = 0; layer = 4; mat = 1;
1693 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1694 part = 0; layer = 5; mat = 0;
1701 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1702 part = 0; layer = 5; mat =1;
1709 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1710 part = 0; layer = 6; mat = 0;
1717 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1718 part = 0; layer = 6; mat = 1;
1725 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1726 part = 0; layer = 7; mat = 0;
1733 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1734 part = 0; layer = 7; mat = 1;
1741 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1742 part = 0; layer = 8; mat = 0;
1750 if(3*
pi/8<=theta&&theta<
pi/2) {
1751 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1752 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1754 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1755 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1756 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1757 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1758 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1759 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1760 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1761 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1762 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1763 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1764 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1765 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1766 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1767 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1768 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1769 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1770 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1777 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1778 part = 0; layer = 0; mat = 0;
1785 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1786 part = 0; layer = 0; mat = 1;
1793 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1794 part = 0; layer = 1; mat = 0;
1801 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1802 part = 0; layer = 1; mat = 1;
1809 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1810 part = 0; layer = 2; mat = 0;
1817 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1818 part = 0; layer = 2; mat = 1;
1825 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1826 part = 0; layer = 3; mat = 0;
1833 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1834 part = 0; layer = 3; mat = 1;
1841 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1842 part = 0; layer = 4; mat = 0;
1849 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1850 part = 0; layer = 4; mat = 1;
1857 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1858 part = 0; layer = 5; mat = 0;
1865 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1866 part = 0; layer = 5; mat =1;
1873 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1874 part = 0; layer = 6; mat = 0;
1881 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1882 part = 0; layer = 6; mat = 1;
1889 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1890 part = 0; layer = 7; mat = 0;
1897 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1898 part = 0; layer = 7; mat = 1;
1905 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1906 part = 0; layer = 8; mat = 0;
1916 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1917 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1919 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1920 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1921 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1922 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1923 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1924 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1925 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1926 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1927 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1928 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1929 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1930 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1931 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1932 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1933 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1934 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1935 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1942 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1943 part = 0; layer = 0; mat = 0;
1950 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1951 part = 0; layer = 0; mat = 1;
1958 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1959 part = 0; layer = 1; mat = 0;
1966 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1967 part = 0; layer = 1; mat = 1;
1974 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1975 part = 0; layer = 2; mat = 0;
1982 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1983 part = 0; layer = 2; mat = 1;
1990 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1991 part = 0; layer = 3; mat = 0;
1998 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1999 part = 0; layer = 3; mat = 1;
2006 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
2007 part = 0; layer = 4; mat = 0;
2014 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
2015 part = 0; layer = 4; mat = 1;
2022 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
2023 part = 0; layer = 5; mat = 0;
2030 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
2031 part = 0; layer = 5; mat =1;
2038 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
2039 part = 0; layer = 6; mat = 0;
2046 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
2047 part = 0; layer = 6; mat = 1;
2054 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
2055 part = 0; layer = 7; mat = 0;
2062 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
2063 part = 0; layer = 7; mat = 1;
2070 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
2071 part = 0; layer = 8; mat = 0;
2079 if(ifbar==
true||ifend==
true) {
2080 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
2083 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
2087 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
2090 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
2094 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
2097 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
2101 else if( r.x() > 0. && r.y() <= 0. && r.z() < 0. ){
2108 newb[0] = -
b[0] * m_scale;
2109 newb[1] =
b[1] * m_scale;
2110 newb[2] = -
b[2] * m_scale;
2125 return StatusCode::SUCCESS;
2134 if(m_runmode == 8 || m_runmode == 7) {
2135 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)
2149 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)
2163 if(m_turnOffField ==
true) {
2173 return StatusCode::SUCCESS;
2181 if(m_useDB ==
false) {
2182 if(m_runmode == 8 || m_runmode == 7) m_zfield = -0.9*tesla;
2183 else m_zfield = -1.0*tesla;
2186 if(m_turnOffField ==
true) {
2189 return m_zfield * m_scale;
2193 return m_ifRealField;
2199void MagneticFieldSvc::fieldGrid (
const HepPoint3D& r,
2207 double z = r.z() - m_zOffSet;
2208 if( z < m_min_FL[2] || z > m_max_FL[2] )
return;
2210 if( x < m_min_FL[0] || x > m_max_FL[0] )
return;
2212 if(
y < m_min_FL[1] ||
y > m_max_FL[1] )
return;
2213 int i = int( (x-m_min_FL[0])/m_Dxyz[0]);
2214 int j = int( (
y-m_min_FL[1])/m_Dxyz[1] );
2215 int k = int( (z-m_min_FL[2])/m_Dxyz[2] );
2217 int ijk000 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j ) + i );
2218 int ijk001 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j ) + i );
2219 int ijk010 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j + 1 ) + i );
2220 int ijk011 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j + 1) + i );
2221 int ijk100 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j) + i + 1 );
2222 int ijk101 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j) + i + 1 );
2223 int ijk110 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j + 1) + i + 1 );
2224 int ijk111 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j + 1 ) + i + 1 );
2244 double cx000 = m_Q[ ijk000 ];
2245 double cx001 = m_Q[ ijk001 ];
2246 double cx010 = m_Q[ ijk010 ];
2247 double cx011 = m_Q[ ijk011 ];
2248 double cx100 = m_Q[ ijk100 ];
2249 double cx101 = m_Q[ ijk101 ];
2250 double cx110 = m_Q[ ijk110 ];
2251 double cx111 = m_Q[ ijk111 ];
2252 double cy000 = m_Q[ ijk000+1 ];
2253 double cy001 = m_Q[ ijk001+1 ];
2254 double cy010 = m_Q[ ijk010+1 ];
2255 double cy011 = m_Q[ ijk011+1 ];
2256 double cy100 = m_Q[ ijk100+1 ];
2257 double cy101 = m_Q[ ijk101+1 ];
2258 double cy110 = m_Q[ ijk110+1 ];
2259 double cy111 = m_Q[ ijk111+1 ];
2260 double cz000 = m_Q[ ijk000+2 ];
2261 double cz001 = m_Q[ ijk001+2 ];
2262 double cz010 = m_Q[ ijk010+2 ];
2263 double cz011 = m_Q[ ijk011+2 ];
2264 double cz100 = m_Q[ ijk100+2 ];
2265 double cz101 = m_Q[ ijk101+2 ];
2266 double cz110 = m_Q[ ijk110+2 ];
2267 double cz111 = m_Q[ ijk111+2 ];
2268 double hx1 = (
x-m_min_FL[0]-i*m_Dxyz[0] )/m_Dxyz[0];
2269 double hy1 = (
y-m_min_FL[1]-j*m_Dxyz[1] )/m_Dxyz[1];
2270 double hz1 = ( z-m_min_FL[2]-k*m_Dxyz[2] )/m_Dxyz[2];
2271 double hx0 = 1.0-hx1;
2272 double hy0 = 1.0-hy1;
2273 double hz0 = 1.0-hz1;
2274 double h000 = hx0*hy0*hz0;
2275 if( fabs(h000) > 0.0 &&
2276 cx000 > 9.0e5 && cy000 > 9.0e5 && cz000 > 9.0e5)
return;
2278 double h001 = hx0*hy0*hz1;
2279 if( fabs(h001) > 0.0 &&
2280 cx001 > 9.0e5 && cy001 > 9.0e5 && cz001 > 9.0e5)
return;
2282 double h010 = hx0*hy1*hz0;
2283 if( fabs(h010) > 0.0 &&
2284 cx010 > 9.0e5 && cy010 > 9.0e5 && cz010 > 9.0e5)
return;
2286 double h011 = hx0*hy1*hz1;
2287 if( fabs(h011) > 0.0 &&
2288 cx011 > 9.0e5 && cy011 > 9.0e5 && cz011 > 9.0e5)
return;
2290 double h100 = hx1*hy0*hz0;
2291 if( fabs(h100) > 0.0 &&
2292 cx100 > 9.0e5 && cy100 > 9.0e5 && cz100 > 9.0e5)
return;
2294 double h101 = hx1*hy0*hz1;
2295 if( fabs(h101) > 0.0 &&
2296 cx101 > 9.0e5 && cy101 > 9.0e5 && cz101 > 9.0e5)
return;
2298 double h110 = hx1*hy1*hz0;
2299 if( fabs(h110) > 0.0 &&
2300 cx110 > 9.0e5 && cy110 > 9.0e5 && cz110 > 9.0e5)
return;
2302 double h111 = hx1*hy1*hz1;
2303 if( fabs(h111) > 0.0 &&
2304 cx111 > 9.0e5 && cy111 > 9.0e5 && cz111 > 9.0e5)
return;
2306 bf(0) = ( cx000*h000 + cx001*h001 + cx010*h010 + cx011*h011 +
2307 cx100*h100 + cx101*h101 + cx110*h110 + cx111*h111);
2308 bf(1) = ( cy000*h000 + cy001*h001 + cy010*h010 + cy011*h011 +
2309 cy100*h100 + cy101*h101 + cy110*h110 + cy111*h111 );
2310 bf(2) = ( cz000*h000 + cz001*h001 + cz010*h010 + cz011*h011 +
2311 cz100*h100 + cz101*h101 + cz110*h110 + cz111*h111 );
2318void MagneticFieldSvc::fieldGrid_TE (
const HepPoint3D& r,
2326 double z = r.z() - m_zOffSet_TE;
2327 if( fabs(z) < m_min_FL_TE[2] || fabs(z) > m_max_FL_TE[2] )
return;
2329 if( fabs(x) < m_min_FL_TE[0] || fabs(x) > m_max_FL_TE[0] )
return;
2331 if( fabs(
y) < m_min_FL_TE[1] || fabs(
y) > m_max_FL_TE[1] )
return;
2332 int i = int( (fabs(x)-m_min_FL_TE[0])/m_Dxyz_TE[0]);
2333 int j = int( (fabs(
y)-m_min_FL_TE[1])/m_Dxyz_TE[1] );
2334 int k = int( (fabs(z)-m_min_FL_TE[2])/m_Dxyz_TE[2] );
2336 int ijk000 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j ) + i );
2337 int ijk001 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j ) + i );
2338 int ijk010 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j + 1 ) + i );
2339 int ijk011 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j + 1) + i );
2340 int ijk100 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j) + i + 1 );
2341 int ijk101 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j) + i + 1 );
2342 int ijk110 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j + 1) + i + 1 );
2343 int ijk111 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j + 1 ) + i + 1 );
2357 double cx000 = m_Q_TE[ ijk000 ];
2358 double cx001 = m_Q_TE[ ijk001 ];
2359 double cx010 = m_Q_TE[ ijk010 ];
2360 double cx011 = m_Q_TE[ ijk011 ];
2361 double cx100 = m_Q_TE[ ijk100 ];
2362 double cx101 = m_Q_TE[ ijk101 ];
2363 double cx110 = m_Q_TE[ ijk110 ];
2364 double cx111 = m_Q_TE[ ijk111 ];
2365 double cy000 = m_Q_TE[ ijk000+1 ];
2366 double cy001 = m_Q_TE[ ijk001+1 ];
2367 double cy010 = m_Q_TE[ ijk010+1 ];
2368 double cy011 = m_Q_TE[ ijk011+1 ];
2369 double cy100 = m_Q_TE[ ijk100+1 ];
2370 double cy101 = m_Q_TE[ ijk101+1 ];
2371 double cy110 = m_Q_TE[ ijk110+1 ];
2372 double cy111 = m_Q_TE[ ijk111+1 ];
2373 double cz000 = m_Q_TE[ ijk000+2 ];
2374 double cz001 = m_Q_TE[ ijk001+2 ];
2375 double cz010 = m_Q_TE[ ijk010+2 ];
2376 double cz011 = m_Q_TE[ ijk011+2 ];
2377 double cz100 = m_Q_TE[ ijk100+2 ];
2378 double cz101 = m_Q_TE[ ijk101+2 ];
2379 double cz110 = m_Q_TE[ ijk110+2 ];
2380 double cz111 = m_Q_TE[ ijk111+2 ];
2381 double hx1 = ( fabs(x)-m_min_FL_TE[0]-i*m_Dxyz_TE[0] )/m_Dxyz_TE[0];
2382 double hy1 = ( fabs(
y)-m_min_FL_TE[1]-j*m_Dxyz_TE[1] )/m_Dxyz_TE[1];
2383 double hz1 = ( fabs(z)-m_min_FL_TE[2]-k*m_Dxyz_TE[2] )/m_Dxyz_TE[2];
2384 double hx0 = 1.0-hx1;
2385 double hy0 = 1.0-hy1;
2386 double hz0 = 1.0-hz1;
2387 double h000 = hx0*hy0*hz0;
2388 if( fabs(h000) > 0.0 &&
2389 cx000 > 9.0e5 && cy000 > 9.0e5 && cz000 > 9.0e5)
return;
2391 double h001 = hx0*hy0*hz1;
2392 if( fabs(h001) > 0.0 &&
2393 cx001 > 9.0e5 && cy001 > 9.0e5 && cz001 > 9.0e5)
return;
2395 double h010 = hx0*hy1*hz0;
2396 if( fabs(h010) > 0.0 &&
2397 cx010 > 9.0e5 && cy010 > 9.0e5 && cz010 > 9.0e5)
return;
2399 double h011 = hx0*hy1*hz1;
2400 if( fabs(h011) > 0.0 &&
2401 cx011 > 9.0e5 && cy011 > 9.0e5 && cz011 > 9.0e5)
return;
2403 double h100 = hx1*hy0*hz0;
2404 if( fabs(h100) > 0.0 &&
2405 cx100 > 9.0e5 && cy100 > 9.0e5 && cz100 > 9.0e5)
return;
2407 double h101 = hx1*hy0*hz1;
2408 if( fabs(h101) > 0.0 &&
2409 cx101 > 9.0e5 && cy101 > 9.0e5 && cz101 > 9.0e5)
return;
2411 double h110 = hx1*hy1*hz0;
2412 if( fabs(h110) > 0.0 &&
2413 cx110 > 9.0e5 && cy110 > 9.0e5 && cz110 > 9.0e5)
return;
2415 double h111 = hx1*hy1*hz1;
2416 if( fabs(h111) > 0.0 &&
2417 cx111 > 9.0e5 && cy111 > 9.0e5 && cz111 > 9.0e5)
return;
2419 bf(0) = ( cx000*h000 + cx001*h001 + cx010*h010 + cx011*h011 +
2420 cx100*h100 + cx101*h101 + cx110*h110 + cx111*h111);
2421 bf(1) = ( cy000*h000 + cy001*h001 + cy010*h010 + cy011*h011 +
2422 cy100*h100 + cy101*h101 + cy110*h110 + cy111*h111 );
2423 bf(2) = ( cz000*h000 + cz001*h001 + cz010*h010 + cz011*h011 +
2424 cz100*h100 + cz101*h101 + cz110*h110 + cz111*h111 );
2427 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
2430 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
2434 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
2438 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
2442 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
2445 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
2449 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)