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);
66 if(!m_Mucfield) cout<<
"error: can not get MucMagneticField pointer"<<endl;
68 m_zfield = -1.0*tesla;
70 if(getenv(
"MAGNETICFIELDROOT") != NULL) {
71 path = std::string(getenv(
"MAGNETICFIELDROOT" ));
73 std::cerr<<
"Couldn't find MAGNETICFIELDROOT"<<std::endl;
93 m_Cur_SCQ1_55 = 349.4;
94 m_Cur_SCQ1_89 = 426.2;
95 m_Cur_SCQ2_10 = 474.2;
102 m_zfield = -1.0*tesla;
111 if(m_Mucfield)
delete m_Mucfield;
118bool MagneticFieldSvc::init_mucMagneticField()
122 if( m_Mucfield->
getPath() == path )
return true;
128 cout<<
"error: can not get MucMagneticField pointer"<<endl;
139 MsgStream log(
msgSvc(), name());
140 StatusCode status = Service::initialize();
142 IIncidentSvc* incsvc;
143 status = service(
"IncidentSvc", incsvc);
145 if( status.isSuccess() ){
146 incsvc -> addListener(
this,
"NewRun", priority);
149 status = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
150 if (status.isFailure() ) {
151 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
155 if( !init_mucMagneticField() )
return false;
156 StatusCode status =
true;
159 if(m_useDB ==
false) {
160 if(m_gridDistance == 5) {
163 m_Q_TE.reserve(176608);
164 m_P_TE.reserve(176608);
166 if(m_gridDistance == 10) {
169 m_Q_TE.reserve(23833);
170 m_P_TE.reserve(23833);
174 m_filename_TE = path;
175 if(m_gridDistance == 10) {
176 m_filename_TE += std::string(
"/dat/TEMap10cm.dat");
178 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode2.dat");
179 else if(m_runmode == 4)
180 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode4.dat");
181 else if(m_runmode == 6)
182 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode6.dat");
183 else if(m_runmode == 7)
184 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode7.dat");
186 m_filename += std::string(
"/dat/2007-08-28BESIII-field.dat");
187 std::cout<<
"WARNING: YOU ARE USING OLD FIELD MAP!!!!"<<std::endl;
190 if(m_gridDistance == 5) {
191 m_filename_TE += std::string(
"/dat/TEMap5cm.dat");
193 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode1.dat");
194 else if(m_runmode == 2)
195 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode2.dat");
196 else if(m_runmode == 3)
197 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
198 else if(m_runmode == 4)
199 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode4.dat");
200 else if(m_runmode == 5)
201 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode5.dat");
202 else if(m_runmode == 6)
203 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode6.dat");
204 else if(m_runmode == 7)
205 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode7.dat");
206 else if(m_runmode == 8)
207 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode8.dat");
209 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode2.dat");
210 std::cout<<
"WARNING: NO RUN MODE, YOU ARE USING DEFAULT FIELD MAP!!!!"<<std::endl;
213 cout<<
"*** Read field map: "<<m_filename<<endl;
214 cout<<
"*** Read field map: "<<m_filename_TE<<endl;
216 status = parseFile();
217 status = parseFile_TE();
220 if ( status.isSuccess() ) {
221 log << MSG::DEBUG <<
"Magnetic field parsed successfully" << endreq;
224 cout <<
"Magnetic field parsed successfully" << endl;
227 for (
int iC = 0; iC< 2; ++iC ){
228 m_min_FL[iC] = -90.0*cm;
229 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
231 m_min_FL_TE[iC] = 0.0*cm;
232 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
234 m_min_FL[2] = -120.0*cm;
235 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
237 m_min_FL_TE[2] = 0.0*cm;
238 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
242 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
244 cout <<
"Magnetic field parse failled" << endl;
251 if (!m_connect_run) {
252 log << MSG::ERROR <<
"Could not open connection to database" << endreq;
263 MsgStream log(
msgSvc(), name());
267 if( !init_mucMagneticField() ) {
268 cerr <<
" STOP! " << endl;
282 if(m_gridDistance == 5) {
285 m_Q_1.reserve(201250);
286 m_P_1.reserve(201250);
287 m_Q_2.reserve(201250);
288 m_P_2.reserve(201250);
289 m_Q_TE.reserve(176608);
290 m_P_TE.reserve(176608);
292 if(m_gridDistance == 10) {
295 m_Q_1.reserve(27082);
296 m_P_1.reserve(27082);
297 m_Q_2.reserve(27082);
298 m_P_2.reserve(27082);
299 m_Q_TE.reserve(23833);
300 m_P_TE.reserve(23833);
305 SmartDataPtr<Event::EventHeader> evt(m_eventSvc,
"/Event/EventHeader");
307 runNo = evt -> runNumber();
308 log << MSG::INFO <<
"The runNumber of current event is "<<
runNo<<endreq;
311 log << MSG::ERROR <<
"Can not get EventHeader!"<<endreq;
318 std::vector<double> current(3,0.);
321 std::vector<double> beamEnergy;
327 sprintf(BPR_PRB,
"%f ",beamEnergy[0]);
328 sprintf(BER_PRB,
"%f ",beamEnergy[1]);
330 setenv(
"BEPCII_INFO.BPR_PRB", BPR_PRB, 1);
331 setenv(
"BEPCII_INFO.BER_PRB", BER_PRB, 1);
333 int ssm_curr = int (current[0]);
334 double scql_curr = current[1];
335 double scqr_curr = current[2];
338 log << MSG::INFO <<
"SSM current: " << current[0] <<
" SCQL current: " << current[1] <<
" SCQR current: " << current[2] <<
" in Run " <<
runNo << endreq;
340 cout <<
"SSM current: " << current[0] <<
" SCQL current: " << current[1]
341 <<
" SCQR current: " << current[2] <<
" in Run " <<
runNo << endl;
348 if((ssm_curr >= 3367) && (ssm_curr <= 3370) && ((scql_curr+scqr_curr)/2 < m_Cur_SCQ1_89)) {
349 m_zfield = -1.0*tesla;
351 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode2.dat");
353 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
355 cout <<
"Select field map: " << m_filename << endl;
358 StatusCode status = parseFile();
361 if ( !status.isSuccess() ) {
362 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
366 cout <<
"Magnetic field parse failled" << endl;
374 if(m_gridDistance == 5) {
378 if(m_gridDistance == 10) {
384 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
386 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
388 cout <<
"Select field map: " << m_filename << endl;
391 status = parseFile();
394 if ( !status.isSuccess() ) {
395 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
399 cout <<
"Magnetic field parse failled" << endl;
407 if(m_gridDistance == 5) {
411 if(m_gridDistance == 10) {
416 if(m_Q_2.size() != m_Q_1.size()) {
418 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
420 cout <<
"The two field maps used in this run are wrong!!!" << endl;
425 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
426 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];
427 m_Q.push_back(fieldvalue);
428 m_P.push_back(m_P_2[iQ]);
432 if((ssm_curr >= 3367) && (ssm_curr <= 3370) && ((scql_curr+scqr_curr)/2 >= m_Cur_SCQ1_89)) {
433 m_zfield = -1.0*tesla;
435 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
437 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
439 cout <<
"Select field map: " << m_filename << endl;
442 StatusCode status = parseFile();
445 if ( !status.isSuccess() ) {
446 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
450 cout <<
"Magnetic field parse failled" << endl;
458 if(m_gridDistance == 5) {
462 if(m_gridDistance == 10) {
468 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode4.dat");
470 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
472 cout <<
"Select field map: " << m_filename << endl;
475 status = parseFile();
478 if ( !status.isSuccess() ) {
479 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
483 cout <<
"Magnetic field parse failled" << endl;
491 if(m_gridDistance == 5) {
495 if(m_gridDistance == 10) {
500 if(m_Q_2.size() != m_Q_1.size()) {
502 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
504 cout <<
"The two field maps used in this run are wrong!!!" << endl;
509 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
510 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];
511 m_Q.push_back(fieldvalue);
512 m_P.push_back(m_P_2[iQ]);
515 if((ssm_curr >= 3033) && (ssm_curr <= 3035)) {
516 m_zfield = -0.9*tesla;
518 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode7.dat");
520 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
522 cout <<
"Select field map: " << m_filename << endl;
525 StatusCode status = parseFile();
528 if ( !status.isSuccess() ) {
529 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
533 cout <<
"Magnetic field parse failled" << endl;
541 if(m_gridDistance == 5) {
545 if(m_gridDistance == 10) {
551 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode8.dat");
553 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
555 cout <<
"Select field map: " << m_filename << endl;
558 status = parseFile();
561 if ( !status.isSuccess() ) {
562 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
566 cout <<
"Magnetic field parse failled" << endl;
574 if(m_gridDistance == 5) {
578 if(m_gridDistance == 10) {
583 if(m_Q_2.size() != m_Q_1.size()) {
585 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
587 cout <<
"The two field maps used in this run are wrong!!!" << endl;
592 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
593 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];
594 m_Q.push_back(fieldvalue);
595 m_P.push_back(m_P_2[iQ]);
599 if((!((ssm_curr >= 3367) && (ssm_curr <= 3370)) && !((ssm_curr >= 3033) && (ssm_curr <= 3035))) || scql_curr == 0 || scqr_curr == 0) {
601 log << MSG::FATAL <<
"The current of run " <<
runNo <<
" is abnormal in database, please check it! " << endreq;
602 log << MSG::FATAL <<
"The current of SSM is " << ssm_curr <<
", SCQR is " << scqr_curr <<
", SCQL is " << scql_curr << endreq;
604 cout <<
"The current of run " <<
runNo
605 <<
" is abnormal in database, please check it! " << endl;
606 cout <<
"The current of SSM is " << ssm_curr
607 <<
", SCQR is " << scqr_curr <<
", SCQL is " << scql_curr << endl;
612 if(m_Q.size() == 0) {
614 log << MSG::FATAL <<
"This size of field map vector is ZERO, please check the current of run " <<
runNo <<
" in database!" << endreq;
616 cout <<
"This size of field map vector is ZERO,"
617 <<
" please check the current of run " <<
runNo
618 <<
" in database!" << endl;
623 m_filename_TE = path;
624 if(m_gridDistance == 10) m_filename_TE += std::string(
"/dat/TEMap10cm.dat");
625 if(m_gridDistance == 5) m_filename_TE += std::string(
"/dat/TEMap5cm.dat");
627 log << MSG::INFO <<
"Select field map: " << m_filename_TE << endreq;
629 cout <<
"Select field map: " << m_filename_TE << endl;
632 StatusCode status = parseFile_TE();
635 if ( !status.isSuccess() ) {
636 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
640 cout <<
"Magnetic field parse failled" << endl;
644 for (
int iC = 0; iC< 2; ++iC ){
645 m_min_FL[iC] = -90.0*cm;
646 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
648 m_min_FL_TE[iC] = 0.0*cm;
649 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
651 m_min_FL[2] = -120.0*cm;
652 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
654 m_min_FL_TE[2] = 0.0*cm;
655 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
664 MsgStream log(
msgSvc(), name() );
666 StatusCode status = Service::finalize();
668 if ( status.isSuccess() )
669 log << MSG::INFO <<
"Service finalized successfully" << endreq;
677 void** ppvInterface )
679 StatusCode sc = StatusCode::FAILURE;
680 if ( ppvInterface ) {
683 if ( riid == IID_IMagneticFieldSvc ) {
685 sc = StatusCode::SUCCESS;
689 sc = Service::queryInterface( riid, ppvInterface );
695 MsgStream log( messageService(), name() );
696 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
697 if ( inc.type() !=
"NewRun" ){
700 log << MSG::DEBUG <<
"Begin New Run" << endreq;
701 if(m_useDB ==
true) {
708 static int save_run = 0;
709 if( new_run == save_run )
return;
711 cout <<
"Begin New Run " << new_run << endl;
713 if(m_useDB ==
true) {
723StatusCode MagneticFieldSvc::parseFile() {
725 StatusCode sc = StatusCode::FAILURE;
727 MsgStream log(
msgSvc(), name() );
729 StatusCode sc =
false;
733 std::ifstream infile( m_filename.c_str() );
737 sc = StatusCode::SUCCESS;
744 infile.getline( line, 255 );
745 }
while( line[0] !=
'P' );
749 char* token = strtok( line,
" " );
752 if ( token ) { sPar[ip] = token; token = strtok( NULL,
" " );}
755 }
while ( token != NULL );
756 long int npar = atoi( sPar[1].
c_str() );
760 infile.getline( line, 255 );
761 }
while( line[0] !=
'G' );
765 infile.getline( line, 255 );
766 }
while( line[0] !=
'#' );
769 infile.getline( line, 255 );
770 std::string sGeom[7];
771 token = strtok( line,
" " );
774 if ( token ) { sGeom[ig] = token; token = strtok( NULL,
" " );}
777 }
while (token != NULL);
780 m_Dxyz[0] = atof( sGeom[0].
c_str() ) * cm;
781 m_Dxyz[1] = atof( sGeom[1].
c_str() ) * cm;
782 m_Dxyz[2] = atof( sGeom[2].
c_str() ) * cm;
783 m_Nxyz[0] = atoi( sGeom[3].
c_str() );
784 m_Nxyz[1] = atoi( sGeom[4].
c_str() );
785 m_Nxyz[2] = atoi( sGeom[5].
c_str() );
786 m_zOffSet = atof( sGeom[6].
c_str() ) * cm;
788 long int nlines = ( npar - 7 ) / 3;
799 infile.getline( line, 255 );
800 if ( line[0] ==
'#' )
continue;
801 std::string gridx, gridy, gridz, sFx, sFy, sFz;
802 char* token = strtok( line,
" " );
803 if ( token ) { gridx = token; token = strtok( NULL,
" " );}
else continue;
804 if ( token ) { gridy = token; token = strtok( NULL,
" " );}
else continue;
805 if ( token ) { gridz = token; token = strtok( NULL,
" " );}
else continue;
806 if ( token ) { sFx = token; token = strtok( NULL,
" " );}
else continue;
807 if ( token ) { sFy = token; token = strtok( NULL,
" " );}
else continue;
808 if ( token ) { sFz = token; token = strtok( NULL,
" " );}
else continue;
809 if ( token != NULL )
continue;
811 double gx = atof( gridx.c_str() ) * m;
812 double gy = atof( gridy.c_str() ) * m;
813 double gz = atof( gridz.c_str() ) * m;
815 double fx = atof( sFx.c_str() ) * tesla;
816 double fy = atof( sFy.c_str() ) * tesla;
817 double fz = atof( sFz.c_str() ) * tesla;
819 if(m_outlevel == 0) {
821 log << MSG::DEBUG <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endreq;
822 log << MSG::DEBUG <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endreq;
824 cout <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endl;
825 cout <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endl;
841 if ( nlines != ncheck) {
843 log << MSG::ERROR <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
845 return StatusCode::FAILURE;
847 cout <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
855 log << MSG::ERROR <<
"Unable to open magnetic field file : "
856 << m_filename << endreq;
858 cout <<
"Unable to open magnetic field file : "
859 << m_filename << endl;
871StatusCode MagneticFieldSvc::parseFile_TE() {
873 StatusCode sc = StatusCode::FAILURE;
875 MsgStream log(
msgSvc(), name() );
877 StatusCode sc =
false;
881 std::ifstream infile( m_filename_TE.c_str() );
885 sc = StatusCode::SUCCESS;
892 infile.getline( line, 255 );
893 }
while( line[0] !=
'P' );
897 char* token = strtok( line,
" " );
900 if ( token ) { sPar[ip] = token; token = strtok( NULL,
" " );}
903 }
while ( token != NULL );
904 long int npar = atoi( sPar[1].
c_str() );
908 infile.getline( line, 255 );
909 }
while( line[0] !=
'G' );
913 infile.getline( line, 255 );
914 }
while( line[0] !=
'#' );
917 infile.getline( line, 255 );
918 std::string sGeom[7];
919 token = strtok( line,
" " );
922 if ( token ) { sGeom[ig] = token; token = strtok( NULL,
" " );}
925 }
while (token != NULL);
928 m_Dxyz_TE[0] = atof( sGeom[0].
c_str() ) * cm;
929 m_Dxyz_TE[1] = atof( sGeom[1].
c_str() ) * cm;
930 m_Dxyz_TE[2] = atof( sGeom[2].
c_str() ) * cm;
931 m_Nxyz_TE[0] = atoi( sGeom[3].
c_str() );
932 m_Nxyz_TE[1] = atoi( sGeom[4].
c_str() );
933 m_Nxyz_TE[2] = atoi( sGeom[5].
c_str() );
934 m_zOffSet_TE = atof( sGeom[6].
c_str() ) * cm;
936 long int nlines = ( npar - 7 ) / 3;
947 infile.getline( line, 255 );
948 if ( line[0] ==
'#' )
continue;
949 std::string gridx, gridy, gridz, sFx, sFy, sFz;
950 char* token = strtok( line,
" " );
951 if ( token ) { gridx = token; token = strtok( NULL,
" " );}
else continue;
952 if ( token ) { gridy = token; token = strtok( NULL,
" " );}
else continue;
953 if ( token ) { gridz = token; token = strtok( NULL,
" " );}
else continue;
954 if ( token ) { sFx = token; token = strtok( NULL,
" " );}
else continue;
955 if ( token ) { sFy = token; token = strtok( NULL,
" " );}
else continue;
956 if ( token ) { sFz = token; token = strtok( NULL,
" " );}
else continue;
957 if ( token != NULL )
continue;
959 double gx = atof( gridx.c_str() ) * m;
960 double gy = atof( gridy.c_str() ) * m;
961 double gz = atof( gridz.c_str() ) * m;
963 double fx = atof( sFx.c_str() ) * tesla;
964 double fy = atof( sFy.c_str() ) * tesla;
965 double fz = atof( sFz.c_str() ) * tesla;
967 if(m_outlevel == 0) {
969 log << MSG::DEBUG <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endreq;
970 log << MSG::DEBUG <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endreq;
972 cout <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endl;
973 cout <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endl;
977 m_P_TE.push_back( gx );
978 m_P_TE.push_back( gy );
979 m_P_TE.push_back( gz );
982 m_Q_TE.push_back( fx );
983 m_Q_TE.push_back( fy );
984 m_Q_TE.push_back( fz );
989 if ( nlines != ncheck) {
991 log << MSG::ERROR <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
993 return StatusCode::FAILURE;
995 cout <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1003 log << MSG::ERROR <<
"Unable to open magnetic field file : "
1004 << m_filename_TE << endreq;
1006 cout <<
"Unable to open magnetic field file : "
1007 << m_filename_TE << endl;
1020 if(m_turnOffField ==
true) {
1025 return StatusCode::SUCCESS;
1035 return StatusCode::SUCCESS;
1043 double new_x = -newr.x();
1044 double new_y = newr.y();
1045 double new_z = -newr.z();
1052 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)
1054 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)
1057 this->fieldGrid( r, b );
1061 this->fieldGrid_TE( r, b );
1064 if((fabs(r.z())<=1970*mm && sqrt(r.x()*r.x()+r.y()*r.y()) >= 1740*mm) || (fabs(r.z())>=2050*mm))
1068 int part = 0, layer = 0, mat = 0;
1073 theta = atan2(fabs(r.y()),fabs(r.x()));
1074 if(0<=theta&&theta<
pi/8) {
1075 mr[0] = fabs(r.x()); mr[1] = -fabs(r.y()); mr[2] = fabs(r.z());
1076 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm){
1078 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1079 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1080 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1081 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1082 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1083 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1084 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1085 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1086 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1087 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1088 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1089 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1090 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1091 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1092 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1093 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1094 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1101 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1102 part = 0; layer = 0; mat = 0;
1109 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1110 part = 0; layer = 0; mat = 1;
1117 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1118 part = 0; layer = 1; mat = 0;
1125 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1126 part = 0; layer = 1; mat = 1;
1133 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1134 part = 0; layer = 2; mat = 0;
1141 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1142 part = 0; layer = 2; mat = 1;
1149 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1150 part = 0; layer = 3; mat = 0;
1157 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1158 part = 0; layer = 3; mat = 1;
1165 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1166 part = 0; layer = 4; mat = 0;
1173 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1174 part = 0; layer = 4; mat = 1;
1181 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1182 part = 0; layer = 5; mat = 0;
1189 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1190 part = 0; layer = 5; mat =1;
1197 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1198 part = 0; layer = 6; mat = 0;
1205 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1206 part = 0; layer = 6; mat = 1;
1213 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1214 part = 0; layer = 7; mat = 0;
1221 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1222 part = 0; layer = 7; mat = 1;
1229 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1230 part = 0; layer = 8; mat = 0;
1238 if(
pi/8<=theta&&theta<
pi/4) {
1239 mr[0] = fabs(r.x())*
cos(
pi/4)+fabs(r.y())*
sin(
pi/4);
1240 mr[1] = -fabs(r.x())*
sin(
pi/4)+fabs(r.y())*
cos(
pi/4);
1241 mr[2] = fabs(r.z());
1242 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1244 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1245 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1246 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1247 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1248 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1249 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1250 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1251 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1252 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1253 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1254 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1255 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1256 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1257 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1258 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1259 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1260 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1267 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1268 part = 0; layer = 0; mat = 0;
1275 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1276 part = 0; layer = 0; mat = 1;
1283 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1284 part = 0; layer = 1; mat = 0;
1291 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1292 part = 0; layer = 1; mat = 1;
1299 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1300 part = 0; layer = 2; mat = 0;
1307 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1308 part = 0; layer = 2; mat = 1;
1315 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1316 part = 0; layer = 3; mat = 0;
1323 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1324 part = 0; layer = 3; mat = 1;
1331 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1332 part = 0; layer = 4; mat = 0;
1339 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1340 part = 0; layer = 4; mat = 1;
1347 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1348 part = 0; layer = 5; mat = 0;
1355 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1356 part = 0; layer = 5; mat =1;
1363 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1364 part = 0; layer = 6; mat = 0;
1371 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1372 part = 0; layer = 6; mat = 1;
1379 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1380 part = 0; layer = 7; mat = 0;
1387 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1388 part = 0; layer = 7; mat = 1;
1395 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1396 part = 0; layer = 8; mat = 0;
1404 if(
pi/4<=theta&&theta<3*
pi/8) {
1405 mr[0] = fabs(r.x())*
cos(
pi/4)+fabs(r.y())*
sin(
pi/4);
1406 mr[1] = fabs(r.x())*
sin(
pi/4)-fabs(r.y())*
cos(
pi/4);
1407 mr[2] = fabs(r.z());
1408 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1410 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1411 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1412 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1413 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1414 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1415 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1416 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1417 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1418 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1419 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1420 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1421 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1422 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1423 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1424 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1425 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1426 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1433 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1434 part = 0; layer = 0; mat = 0;
1441 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1442 part = 0; layer = 0; mat = 1;
1449 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1450 part = 0; layer = 1; mat = 0;
1457 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1458 part = 0; layer = 1; mat = 1;
1465 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1466 part = 0; layer = 2; mat = 0;
1473 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1474 part = 0; layer = 2; mat = 1;
1481 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1482 part = 0; layer = 3; mat = 0;
1489 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1490 part = 0; layer = 3; mat = 1;
1497 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1498 part = 0; layer = 4; mat = 0;
1505 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1506 part = 0; layer = 4; mat = 1;
1513 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1514 part = 0; layer = 5; mat = 0;
1521 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1522 part = 0; layer = 5; mat =1;
1529 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1530 part = 0; layer = 6; mat = 0;
1537 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1538 part = 0; layer = 6; mat = 1;
1545 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1546 part = 0; layer = 7; mat = 0;
1553 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1554 part = 0; layer = 7; mat = 1;
1561 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1562 part = 0; layer = 8; mat = 0;
1570 if(3*
pi/8<=theta&&theta<
pi/2) {
1571 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1572 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1574 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1575 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1576 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1577 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1578 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1579 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1580 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1581 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1582 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1583 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1584 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1585 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1586 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1587 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1588 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1589 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1590 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1597 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1598 part = 0; layer = 0; mat = 0;
1605 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1606 part = 0; layer = 0; mat = 1;
1613 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1614 part = 0; layer = 1; mat = 0;
1621 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1622 part = 0; layer = 1; mat = 1;
1629 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1630 part = 0; layer = 2; mat = 0;
1637 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1638 part = 0; layer = 2; mat = 1;
1645 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1646 part = 0; layer = 3; mat = 0;
1653 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1654 part = 0; layer = 3; mat = 1;
1661 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1662 part = 0; layer = 4; mat = 0;
1669 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1670 part = 0; layer = 4; mat = 1;
1677 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1678 part = 0; layer = 5; mat = 0;
1685 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1686 part = 0; layer = 5; mat =1;
1693 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1694 part = 0; layer = 6; mat = 0;
1701 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1702 part = 0; layer = 6; mat = 1;
1709 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1710 part = 0; layer = 7; mat = 0;
1717 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1718 part = 0; layer = 7; mat = 1;
1725 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1726 part = 0; layer = 8; mat = 0;
1736 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1737 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1739 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1740 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1741 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1742 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1743 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1744 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1745 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1746 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1747 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1748 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1749 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1750 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1751 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1752 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1753 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1754 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1755 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1762 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1763 part = 0; layer = 0; mat = 0;
1770 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1771 part = 0; layer = 0; mat = 1;
1778 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1779 part = 0; layer = 1; mat = 0;
1786 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1787 part = 0; layer = 1; mat = 1;
1794 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1795 part = 0; layer = 2; mat = 0;
1802 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1803 part = 0; layer = 2; mat = 1;
1810 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1811 part = 0; layer = 3; mat = 0;
1818 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1819 part = 0; layer = 3; mat = 1;
1826 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1827 part = 0; layer = 4; mat = 0;
1834 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1835 part = 0; layer = 4; mat = 1;
1842 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1843 part = 0; layer = 5; mat = 0;
1850 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1851 part = 0; layer = 5; mat =1;
1858 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1859 part = 0; layer = 6; mat = 0;
1866 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1867 part = 0; layer = 6; mat = 1;
1874 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1875 part = 0; layer = 7; mat = 0;
1882 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1883 part = 0; layer = 7; mat = 1;
1890 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1891 part = 0; layer = 8; mat = 0;
1899 if(ifbar==
true||ifend==
true) {
1900 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
1903 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
1907 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
1910 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
1914 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
1917 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
1921 else if( r.x() > 0. && r.y() <= 0. && r.z() < 0. ){
1928 newb[0] = -b[0] * m_scale;
1929 newb[1] = b[1] * m_scale;
1930 newb[2] = -b[2] * m_scale;
1945 return StatusCode::SUCCESS;
1954 if(m_runmode == 8 || m_runmode == 7) {
1955 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)
1969 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)
1983 if(m_turnOffField ==
true) {
1993 return StatusCode::SUCCESS;
2001 if(m_useDB ==
false) {
2002 if(m_runmode == 8 || m_runmode == 7) m_zfield = -0.9*tesla;
2003 else m_zfield = -1.0*tesla;
2006 if(m_turnOffField ==
true) {
2009 return m_zfield * m_scale;
2013 return m_ifRealField;
2019void MagneticFieldSvc::fieldGrid (
const HepPoint3D& r,
2027 double z = r.z() - m_zOffSet;
2028 if( z < m_min_FL[2] || z > m_max_FL[2] )
return;
2030 if( x < m_min_FL[0] || x > m_max_FL[0] )
return;
2032 if( y < m_min_FL[1] || y > m_max_FL[1] )
return;
2033 int i = int( (x-m_min_FL[0])/m_Dxyz[0]);
2034 int j = int( (y-m_min_FL[1])/m_Dxyz[1] );
2035 int k = int( (z-m_min_FL[2])/m_Dxyz[2] );
2037 int ijk000 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j ) + i );
2038 int ijk001 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j ) + i );
2039 int ijk010 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j + 1 ) + i );
2040 int ijk011 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j + 1) + i );
2041 int ijk100 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j) + i + 1 );
2042 int ijk101 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j) + i + 1 );
2043 int ijk110 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j + 1) + i + 1 );
2044 int ijk111 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j + 1 ) + i + 1 );
2064 double cx000 = m_Q[ ijk000 ];
2065 double cx001 = m_Q[ ijk001 ];
2066 double cx010 = m_Q[ ijk010 ];
2067 double cx011 = m_Q[ ijk011 ];
2068 double cx100 = m_Q[ ijk100 ];
2069 double cx101 = m_Q[ ijk101 ];
2070 double cx110 = m_Q[ ijk110 ];
2071 double cx111 = m_Q[ ijk111 ];
2072 double cy000 = m_Q[ ijk000+1 ];
2073 double cy001 = m_Q[ ijk001+1 ];
2074 double cy010 = m_Q[ ijk010+1 ];
2075 double cy011 = m_Q[ ijk011+1 ];
2076 double cy100 = m_Q[ ijk100+1 ];
2077 double cy101 = m_Q[ ijk101+1 ];
2078 double cy110 = m_Q[ ijk110+1 ];
2079 double cy111 = m_Q[ ijk111+1 ];
2080 double cz000 = m_Q[ ijk000+2 ];
2081 double cz001 = m_Q[ ijk001+2 ];
2082 double cz010 = m_Q[ ijk010+2 ];
2083 double cz011 = m_Q[ ijk011+2 ];
2084 double cz100 = m_Q[ ijk100+2 ];
2085 double cz101 = m_Q[ ijk101+2 ];
2086 double cz110 = m_Q[ ijk110+2 ];
2087 double cz111 = m_Q[ ijk111+2 ];
2088 double hx1 = (
x-m_min_FL[0]-i*m_Dxyz[0] )/m_Dxyz[0];
2089 double hy1 = ( y-m_min_FL[1]-j*m_Dxyz[1] )/m_Dxyz[1];
2090 double hz1 = ( z-m_min_FL[2]-k*m_Dxyz[2] )/m_Dxyz[2];
2091 double hx0 = 1.0-hx1;
2092 double hy0 = 1.0-hy1;
2093 double hz0 = 1.0-hz1;
2094 double h000 = hx0*hy0*hz0;
2095 if( fabs(h000) > 0.0 &&
2096 cx000 > 9.0e5 && cy000 > 9.0e5 && cz000 > 9.0e5)
return;
2098 double h001 = hx0*hy0*hz1;
2099 if( fabs(h001) > 0.0 &&
2100 cx001 > 9.0e5 && cy001 > 9.0e5 && cz001 > 9.0e5)
return;
2102 double h010 = hx0*hy1*hz0;
2103 if( fabs(h010) > 0.0 &&
2104 cx010 > 9.0e5 && cy010 > 9.0e5 && cz010 > 9.0e5)
return;
2106 double h011 = hx0*hy1*hz1;
2107 if( fabs(h011) > 0.0 &&
2108 cx011 > 9.0e5 && cy011 > 9.0e5 && cz011 > 9.0e5)
return;
2110 double h100 = hx1*hy0*hz0;
2111 if( fabs(h100) > 0.0 &&
2112 cx100 > 9.0e5 && cy100 > 9.0e5 && cz100 > 9.0e5)
return;
2114 double h101 = hx1*hy0*hz1;
2115 if( fabs(h101) > 0.0 &&
2116 cx101 > 9.0e5 && cy101 > 9.0e5 && cz101 > 9.0e5)
return;
2118 double h110 = hx1*hy1*hz0;
2119 if( fabs(h110) > 0.0 &&
2120 cx110 > 9.0e5 && cy110 > 9.0e5 && cz110 > 9.0e5)
return;
2122 double h111 = hx1*hy1*hz1;
2123 if( fabs(h111) > 0.0 &&
2124 cx111 > 9.0e5 && cy111 > 9.0e5 && cz111 > 9.0e5)
return;
2126 bf(0) = ( cx000*h000 + cx001*h001 + cx010*h010 + cx011*h011 +
2127 cx100*h100 + cx101*h101 + cx110*h110 + cx111*h111);
2128 bf(1) = ( cy000*h000 + cy001*h001 + cy010*h010 + cy011*h011 +
2129 cy100*h100 + cy101*h101 + cy110*h110 + cy111*h111 );
2130 bf(2) = ( cz000*h000 + cz001*h001 + cz010*h010 + cz011*h011 +
2131 cz100*h100 + cz101*h101 + cz110*h110 + cz111*h111 );
2138void MagneticFieldSvc::fieldGrid_TE (
const HepPoint3D& r,
2146 double z = r.z() - m_zOffSet_TE;
2147 if( fabs(z) < m_min_FL_TE[2] || fabs(z) > m_max_FL_TE[2] )
return;
2149 if( fabs(x) < m_min_FL_TE[0] || fabs(x) > m_max_FL_TE[0] )
return;
2151 if( fabs(y) < m_min_FL_TE[1] || fabs(y) > m_max_FL_TE[1] )
return;
2152 int i = int( (fabs(x)-m_min_FL_TE[0])/m_Dxyz_TE[0]);
2153 int j = int( (fabs(y)-m_min_FL_TE[1])/m_Dxyz_TE[1] );
2154 int k = int( (fabs(z)-m_min_FL_TE[2])/m_Dxyz_TE[2] );
2156 int ijk000 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j ) + i );
2157 int ijk001 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j ) + i );
2158 int ijk010 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j + 1 ) + i );
2159 int ijk011 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j + 1) + i );
2160 int ijk100 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j) + i + 1 );
2161 int ijk101 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j) + i + 1 );
2162 int ijk110 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j + 1) + i + 1 );
2163 int ijk111 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j + 1 ) + i + 1 );
2177 double cx000 = m_Q_TE[ ijk000 ];
2178 double cx001 = m_Q_TE[ ijk001 ];
2179 double cx010 = m_Q_TE[ ijk010 ];
2180 double cx011 = m_Q_TE[ ijk011 ];
2181 double cx100 = m_Q_TE[ ijk100 ];
2182 double cx101 = m_Q_TE[ ijk101 ];
2183 double cx110 = m_Q_TE[ ijk110 ];
2184 double cx111 = m_Q_TE[ ijk111 ];
2185 double cy000 = m_Q_TE[ ijk000+1 ];
2186 double cy001 = m_Q_TE[ ijk001+1 ];
2187 double cy010 = m_Q_TE[ ijk010+1 ];
2188 double cy011 = m_Q_TE[ ijk011+1 ];
2189 double cy100 = m_Q_TE[ ijk100+1 ];
2190 double cy101 = m_Q_TE[ ijk101+1 ];
2191 double cy110 = m_Q_TE[ ijk110+1 ];
2192 double cy111 = m_Q_TE[ ijk111+1 ];
2193 double cz000 = m_Q_TE[ ijk000+2 ];
2194 double cz001 = m_Q_TE[ ijk001+2 ];
2195 double cz010 = m_Q_TE[ ijk010+2 ];
2196 double cz011 = m_Q_TE[ ijk011+2 ];
2197 double cz100 = m_Q_TE[ ijk100+2 ];
2198 double cz101 = m_Q_TE[ ijk101+2 ];
2199 double cz110 = m_Q_TE[ ijk110+2 ];
2200 double cz111 = m_Q_TE[ ijk111+2 ];
2201 double hx1 = ( fabs(x)-m_min_FL_TE[0]-i*m_Dxyz_TE[0] )/m_Dxyz_TE[0];
2202 double hy1 = ( fabs(y)-m_min_FL_TE[1]-j*m_Dxyz_TE[1] )/m_Dxyz_TE[1];
2203 double hz1 = ( fabs(z)-m_min_FL_TE[2]-k*m_Dxyz_TE[2] )/m_Dxyz_TE[2];
2204 double hx0 = 1.0-hx1;
2205 double hy0 = 1.0-hy1;
2206 double hz0 = 1.0-hz1;
2207 double h000 = hx0*hy0*hz0;
2208 if( fabs(h000) > 0.0 &&
2209 cx000 > 9.0e5 && cy000 > 9.0e5 && cz000 > 9.0e5)
return;
2211 double h001 = hx0*hy0*hz1;
2212 if( fabs(h001) > 0.0 &&
2213 cx001 > 9.0e5 && cy001 > 9.0e5 && cz001 > 9.0e5)
return;
2215 double h010 = hx0*hy1*hz0;
2216 if( fabs(h010) > 0.0 &&
2217 cx010 > 9.0e5 && cy010 > 9.0e5 && cz010 > 9.0e5)
return;
2219 double h011 = hx0*hy1*hz1;
2220 if( fabs(h011) > 0.0 &&
2221 cx011 > 9.0e5 && cy011 > 9.0e5 && cz011 > 9.0e5)
return;
2223 double h100 = hx1*hy0*hz0;
2224 if( fabs(h100) > 0.0 &&
2225 cx100 > 9.0e5 && cy100 > 9.0e5 && cz100 > 9.0e5)
return;
2227 double h101 = hx1*hy0*hz1;
2228 if( fabs(h101) > 0.0 &&
2229 cx101 > 9.0e5 && cy101 > 9.0e5 && cz101 > 9.0e5)
return;
2231 double h110 = hx1*hy1*hz0;
2232 if( fabs(h110) > 0.0 &&
2233 cx110 > 9.0e5 && cy110 > 9.0e5 && cz110 > 9.0e5)
return;
2235 double h111 = hx1*hy1*hz1;
2236 if( fabs(h111) > 0.0 &&
2237 cx111 > 9.0e5 && cy111 > 9.0e5 && cz111 > 9.0e5)
return;
2239 bf(0) = ( cx000*h000 + cx001*h001 + cx010*h010 + cx011*h011 +
2240 cx100*h100 + cx101*h101 + cx110*h110 + cx111*h111);
2241 bf(1) = ( cy000*h000 + cy001*h001 + cy010*h010 + cy011*h011 +
2242 cy100*h100 + cy101*h101 + cy110*h110 + cy111*h111 );
2243 bf(2) = ( cz000*h000 + cz001*h001 + cz010*h010 + cz011*h011 +
2244 cz100*h100 + cz101*h101 + cz110*h110 + cz111*h111 );
2247 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
2250 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
2254 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
2258 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
2262 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
2265 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
2269 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)
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
virtual StatusCode initialize()
Initialise the service (Inherited Service overrides)
void handle(const Incident &)
virtual StatusCode uniFieldVector(const HepPoint3D &xyz, HepVector3D &fvec) const
MagneticFieldSvc(const std::string &name, ISvcLocator *svc)
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)