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);
64 declareProperty(
"ReadOneTime", m_readOneTime=
false);
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 map: "<<m_filename<<endl;
219 cout<<
"*** Read field map "<<m_filename_TE<<endl;
221 status = parseFile();
222 status = parseFile_TE();
224 if ( status.isSuccess() ) {
225 log << MSG::DEBUG <<
"Magnetic field parsed successfully" << endreq;
228 cout <<
"Magnetic field parsed successfully" << endl;
231 for (
int iC = 0; iC< 2; ++iC ){
232 m_min_FL[iC] = -90.0*cm;
233 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
235 m_min_FL_TE[iC] = 0.0*cm;
236 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
238 m_min_FL[2] = -120.0*cm;
239 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
241 m_min_FL_TE[2] = 0.0*cm;
242 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
246 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
248 cout <<
"Magnetic field parse failled" << endl;
260 log << MSG::ERROR <<
"Could not open connection to database" << endreq;
271 MsgStream log(
msgSvc(), name());
275 if( !init_mucMagneticField() ) {
276 cerr <<
" STOP! " << endl;
290 if(m_gridDistance == 5) {
293 m_Q_1.reserve(201250);
294 m_P_1.reserve(201250);
295 m_Q_2.reserve(201250);
296 m_P_2.reserve(201250);
297 m_Q_TE.reserve(176608);
298 m_P_TE.reserve(176608);
300 if(m_gridDistance == 10) {
303 m_Q_1.reserve(27082);
304 m_P_1.reserve(27082);
305 m_Q_2.reserve(27082);
306 m_P_2.reserve(27082);
307 m_Q_TE.reserve(23833);
308 m_P_TE.reserve(23833);
315 setenv(
"BEPCII_INFO.BPR_PRB", BPR_PRB, 1);
316 setenv(
"BEPCII_INFO.BER_PRB", BER_PRB, 1);
317 int ssm_curr = int (
current[0]);
325 log << MSG::INFO <<
"SSM current: " <<
current[0] <<
" SCQL current: " <<
current[1] <<
" SCQR current: " <<
current[2] <<
" in Run " <<
runNo << endreq;
329 cout <<
"SSM current: " <<
current[0] <<
" SCQL current: " <<
current[1]
330 <<
" SCQR current: " <<
current[2] <<
" in Run " <<
runNo << endl;
338 if(((ssm_curr >= 3367) && (ssm_curr <= 3370) && ((scql_curr+scqr_curr)/2 < m_Cur_SCQ1_89))) {
339 m_zfield = -1.0*tesla;
341 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode2.dat");
343 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
345 cout <<
"Select field map: " << m_filename << endl;
348 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true))
350 former_m_filename = m_filename;
354 StatusCode status = parseFile();
356 if ( !status.isSuccess() ) {
357 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
361 cout <<
"Magnetic field parse failled" << endl;
370 if(m_gridDistance == 5) {
374 if(m_gridDistance == 10) {
380 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
382 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
384 cout <<
"Select field map: " << m_filename << endl;
387 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true))
389 former_m_filename = m_filename;
393 status = parseFile();
395 if ( !status.isSuccess() ) {
396 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
400 cout <<
"Magnetic field parse failled" << endl;
409 if(m_gridDistance == 5) {
413 if(m_gridDistance == 10) {
418 if(m_Q_2.size() != m_Q_1.size()) {
420 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
422 cout <<
"The two field maps used in this run are wrong!!!" << endl;
427 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
428 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];
429 m_Q.push_back(fieldvalue);
430 m_P.push_back(m_P_2[iQ]);
434 if(((ssm_curr >= 3367) && (ssm_curr <= 3370) && ((scql_curr+scqr_curr)/2 >= m_Cur_SCQ1_89))){
435 m_zfield = -1.0*tesla;
437 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
439 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
441 cout <<
"Select field map: " << m_filename << endl;
443 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true))
445 former_m_filename = m_filename;
449 StatusCode status = parseFile();
451 if ( !status.isSuccess() ) {
452 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
456 cout <<
"Magnetic field parse failled" << endl;
465 if(m_gridDistance == 5) {
469 if(m_gridDistance == 10) {
475 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode4.dat");
477 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
479 cout <<
"Select field map: " << m_filename << endl;
482 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true))
484 former_m_filename = m_filename;
488 status = parseFile();
490 if ( !status.isSuccess() ) {
491 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
495 cout <<
"Magnetic field parse failled" << endl;
504 if(m_gridDistance == 5) {
508 if(m_gridDistance == 10) {
514 if(m_Q_2.size() != m_Q_1.size()) {
517 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
521 cout <<
"The two field maps used in this run are wrong!!!" << endl;
527 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
528 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];
529 m_Q.push_back(fieldvalue);
530 m_P.push_back(m_P_2[iQ]);
533 if((ssm_curr >= 3033) && (ssm_curr <= 3035)) {
534 m_zfield = -0.9*tesla;
536 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode7.dat");
538 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
540 cout <<
"Select field map: " << m_filename << endl;
543 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true))
545 former_m_filename = m_filename;
549 StatusCode status = parseFile();
551 if ( !status.isSuccess() ) {
552 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
556 cout <<
"Magnetic field parse failled" << endl;
565 if(m_gridDistance == 5) {
569 if(m_gridDistance == 10) {
575 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode8.dat");
577 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
579 cout <<
"Select field map: " << m_filename << endl;
582 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true)){
583 former_m_filename = m_filename;
587 status = parseFile();
589 if ( !status.isSuccess() ) {
590 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
594 cout <<
"Magnetic field parse failled" << endl;
603 if(m_gridDistance == 5) {
607 if(m_gridDistance == 10) {
612 if(m_Q_2.size() != m_Q_1.size()) {
614 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
616 cout <<
"The two field maps used in this run are wrong!!!" << endl;
621 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
622 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];
623 m_Q.push_back(fieldvalue);
624 m_P.push_back(m_P_2[iQ]);
627 if((!((ssm_curr >= 3367) && (ssm_curr <= 3370)) && !((ssm_curr >= 3033) && (ssm_curr <= 3035))) || scql_curr == 0 || scqr_curr == 0) {
629 log << MSG::FATAL <<
"The current of run " <<
runNo <<
" is abnormal in database, please check it! " << endreq;
630 log << MSG::FATAL <<
"The current of SSM is " << ssm_curr <<
", SCQR is " << scqr_curr <<
", SCQL is " << scql_curr << endreq;
632 cout <<
"The current of run " <<
runNo
633 <<
" is abnormal in database, please check it! " << endl;
634 cout <<
"The current of SSM is " << ssm_curr
635 <<
", SCQR is " << scqr_curr <<
", SCQL is " << scql_curr << endl;
640 if(m_Q.size() == 0) {
642 log << MSG::FATAL <<
"This size of field map vector is ZERO, please check the current of run " <<
runNo <<
" in database!" << endreq;
644 cout <<
"This size of field map vector is ZERO,"
645 <<
" please check the current of run " <<
runNo
646 <<
" in database!" << endl;
651 m_filename_TE = path;
652 if(m_gridDistance == 10) m_filename_TE += std::string(
"/dat/TEMap10cm.dat");
653 if(m_gridDistance == 5) m_filename_TE += std::string(
"/dat/TEMap5cm.dat");
655 log << MSG::INFO <<
"Select field map: " << m_filename_TE << endreq;
657 cout <<
"Select field map: " << m_filename_TE << endl;
659 if(((former_m_filename_TE ==
"First Run") || (former_m_filename_TE != m_filename_TE))&&(
m_readOneTime ==
true))
661 former_m_filename_TE = m_filename_TE;
665 StatusCode status = parseFile_TE();
667 if ( !status.isSuccess() ) {
668 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
672 cout <<
"Magnetic field parse failled" << endl;
676 for (
int iC = 0; iC< 2; ++iC ){
677 m_min_FL[iC] = -90.0*cm;
678 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
680 m_min_FL_TE[iC] = 0.0*cm;
681 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
683 m_min_FL[2] = -120.0*cm;
684 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
686 m_min_FL_TE[2] = 0.0*cm;
687 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
696 MsgStream log(
msgSvc(), name() );
698 StatusCode status = Service::finalize();
700 if ( status.isSuccess() )
701 log << MSG::INFO <<
"Service finalized successfully" << endreq;
709 void** ppvInterface )
711 StatusCode sc = StatusCode::FAILURE;
712 if ( ppvInterface ) {
715 if ( riid == IID_IMagneticFieldSvc ) {
717 sc = StatusCode::SUCCESS;
721 sc = Service::queryInterface( riid, ppvInterface );
727 MsgStream log( messageService(), name() );
728 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
729 if ( inc.type() !=
"NewRun" ){
732 log << MSG::DEBUG <<
"Begin New Runcc" << endreq;
734 SmartDataPtr<Event::EventHeader> eventHeader(
m_eventSvc,
"/Event/EventHeader");
735 int new_run = eventHeader->runNumber();
736 if(new_run<0) new_run=-new_run;
748 std::vector<double>
current(3,0.);
752 cout<<
"Run:"<<new_run<<
" BeamEnergy is NULL, please check!!"<<endl;
760 cout<<
"Run:"<<new_run<<
" MagnetInfo is NULL, please check!!"<<endl;
772 static int save_run = 0;
773 if( new_run == save_run )
return;
775 cout <<
"Begin New Run " << new_run << endl;
777 if(m_useDB ==
true) {
787StatusCode MagneticFieldSvc::parseFile() {
789 StatusCode sc = StatusCode::FAILURE;
791 MsgStream log(
msgSvc(), name() );
793 StatusCode sc =
false;
797 std::ifstream infile( m_filename.c_str() );
800 sc = StatusCode::SUCCESS;
807 infile.getline( line, 255 );
808 }
while( line[0] !=
'P' );
812 char* token = strtok( line,
" " );
815 if ( token ) { sPar[ip] = token; token = strtok( NULL,
" " );}
818 }
while ( token != NULL );
819 long int npar = atoi( sPar[1].
c_str() );
823 infile.getline( line, 255 );
824 }
while( line[0] !=
'G' );
828 infile.getline( line, 255 );
829 }
while( line[0] !=
'#' );
832 infile.getline( line, 255 );
833 std::string sGeom[7];
834 token = strtok( line,
" " );
837 if ( token ) { sGeom[ig] = token; token = strtok( NULL,
" " );}
840 }
while (token != NULL);
843 m_Dxyz[0] = atof( sGeom[0].
c_str() ) * cm;
844 m_Dxyz[1] = atof( sGeom[1].
c_str() ) * cm;
845 m_Dxyz[2] = atof( sGeom[2].
c_str() ) * cm;
846 m_Nxyz[0] = atoi( sGeom[3].
c_str() );
847 m_Nxyz[1] = atoi( sGeom[4].
c_str() );
848 m_Nxyz[2] = atoi( sGeom[5].
c_str() );
849 m_zOffSet = atof( sGeom[6].
c_str() ) * cm;
851 long int nlines = ( npar - 7 ) / 3;
862 infile.getline( line, 255 );
863 if ( line[0] ==
'#' )
continue;
864 std::string gridx, gridy, gridz, sFx, sFy, sFz;
865 char* token = strtok( line,
" " );
866 if ( token ) { gridx = token; token = strtok( NULL,
" " );}
else continue;
867 if ( token ) { gridy = token; token = strtok( NULL,
" " );}
else continue;
868 if ( token ) { gridz = token; token = strtok( NULL,
" " );}
else continue;
869 if ( token ) { sFx = token; token = strtok( NULL,
" " );}
else continue;
870 if ( token ) { sFy = token; token = strtok( NULL,
" " );}
else continue;
871 if ( token ) { sFz = token; token = strtok( NULL,
" " );}
else continue;
872 if ( token != NULL )
continue;
874 double gx = atof( gridx.c_str() ) * m;
875 double gy = atof( gridy.c_str() ) * m;
876 double gz = atof( gridz.c_str() ) * m;
878 double fx = atof( sFx.c_str() ) * tesla;
879 double fy = atof( sFy.c_str() ) * tesla;
880 double fz = atof( sFz.c_str() ) * tesla;
882 if(m_outlevel == 0) {
884 log << MSG::DEBUG <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endreq;
885 log << MSG::DEBUG <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endreq;
887 cout <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endl;
888 cout <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endl;
904 if ( nlines != ncheck) {
906 log << MSG::ERROR <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
908 return StatusCode::FAILURE;
910 cout <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
918 log << MSG::ERROR <<
"Unable to open magnetic field file : "
919 << m_filename << endreq;
921 cout <<
"Unable to open magnetic field file : "
922 << m_filename << endl;
934StatusCode MagneticFieldSvc::parseFile_TE() {
936 StatusCode sc = StatusCode::FAILURE;
938 MsgStream log(
msgSvc(), name() );
940 StatusCode sc =
false;
944 std::ifstream infile( m_filename_TE.c_str() );
948 sc = StatusCode::SUCCESS;
955 infile.getline( line, 255 );
956 }
while( line[0] !=
'P' );
960 char* token = strtok( line,
" " );
963 if ( token ) { sPar[ip] = token; token = strtok( NULL,
" " );}
966 }
while ( token != NULL );
967 long int npar = atoi( sPar[1].
c_str() );
971 infile.getline( line, 255 );
972 }
while( line[0] !=
'G' );
976 infile.getline( line, 255 );
977 }
while( line[0] !=
'#' );
980 infile.getline( line, 255 );
981 std::string sGeom[7];
982 token = strtok( line,
" " );
985 if ( token ) { sGeom[ig] = token; token = strtok( NULL,
" " );}
988 }
while (token != NULL);
991 m_Dxyz_TE[0] = atof( sGeom[0].
c_str() ) * cm;
992 m_Dxyz_TE[1] = atof( sGeom[1].
c_str() ) * cm;
993 m_Dxyz_TE[2] = atof( sGeom[2].
c_str() ) * cm;
994 m_Nxyz_TE[0] = atoi( sGeom[3].
c_str() );
995 m_Nxyz_TE[1] = atoi( sGeom[4].
c_str() );
996 m_Nxyz_TE[2] = atoi( sGeom[5].
c_str() );
997 m_zOffSet_TE = atof( sGeom[6].
c_str() ) * cm;
999 long int nlines = ( npar - 7 ) / 3;
1002 long int ncheck = 0;
1010 infile.getline( line, 255 );
1011 if ( line[0] ==
'#' )
continue;
1012 std::string gridx, gridy, gridz, sFx, sFy, sFz;
1013 char* token = strtok( line,
" " );
1014 if ( token ) { gridx = token; token = strtok( NULL,
" " );}
else continue;
1015 if ( token ) { gridy = token; token = strtok( NULL,
" " );}
else continue;
1016 if ( token ) { gridz = token; token = strtok( NULL,
" " );}
else continue;
1017 if ( token ) { sFx = token; token = strtok( NULL,
" " );}
else continue;
1018 if ( token ) { sFy = token; token = strtok( NULL,
" " );}
else continue;
1019 if ( token ) { sFz = token; token = strtok( NULL,
" " );}
else continue;
1020 if ( token != NULL )
continue;
1022 double gx = atof( gridx.c_str() ) * m;
1023 double gy = atof( gridy.c_str() ) * m;
1024 double gz = atof( gridz.c_str() ) * m;
1026 double fx = atof( sFx.c_str() ) * tesla;
1027 double fy = atof( sFy.c_str() ) * tesla;
1028 double fz = atof( sFz.c_str() ) * tesla;
1030 if(m_outlevel == 0) {
1032 log << MSG::DEBUG <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endreq;
1033 log << MSG::DEBUG <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endreq;
1035 cout <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endl;
1036 cout <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endl;
1040 m_P_TE.push_back( gx );
1041 m_P_TE.push_back( gy );
1042 m_P_TE.push_back( gz );
1045 m_Q_TE.push_back( fx );
1046 m_Q_TE.push_back( fy );
1047 m_Q_TE.push_back( fz );
1052 if ( nlines != ncheck) {
1054 log << MSG::ERROR <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1056 return StatusCode::FAILURE;
1058 cout <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1066 log << MSG::ERROR <<
"Unable to open magnetic field file : "
1067 << m_filename_TE << endreq;
1069 cout <<
"Unable to open magnetic field file : "
1070 << m_filename_TE << endl;
1083 if(m_turnOffField ==
true) {
1088 return StatusCode::SUCCESS;
1098 return StatusCode::SUCCESS;
1106 double new_x = -newr.x();
1107 double new_y = newr.y();
1108 double new_z = -newr.z();
1115 if(-2.1*m<r.z() && r.z()<2.1*m && -1.8*m<r.x() && r.x()<1.8*m && -1.8*m<r.y() && r.y()<1.8*m)
1117 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)
1120 this->fieldGrid( r,
b );
1124 this->fieldGrid_TE( r,
b );
1127 if((fabs(r.z())<=1970*mm && sqrt(r.x()*r.x()+r.y()*r.y()) >= 1740*mm) || (fabs(r.z())>=2050*mm))
1131 int part = 0, layer = 0, mat = 0;
1136 theta = atan2(fabs(r.y()),fabs(r.x()));
1137 if(0<=theta&&theta<
pi/8) {
1138 mr[0] = fabs(r.x()); mr[1] = -fabs(r.y()); mr[2] = fabs(r.z());
1139 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm){
1141 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1142 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1143 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1144 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1145 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1146 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1147 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1148 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1149 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1150 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1151 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1152 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1153 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1154 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1155 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1156 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1157 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1164 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1165 part = 0; layer = 0; mat = 0;
1172 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1173 part = 0; layer = 0; mat = 1;
1180 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1181 part = 0; layer = 1; mat = 0;
1188 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1189 part = 0; layer = 1; mat = 1;
1196 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1197 part = 0; layer = 2; mat = 0;
1204 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1205 part = 0; layer = 2; mat = 1;
1212 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1213 part = 0; layer = 3; mat = 0;
1220 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1221 part = 0; layer = 3; mat = 1;
1228 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1229 part = 0; layer = 4; mat = 0;
1236 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1237 part = 0; layer = 4; mat = 1;
1244 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1245 part = 0; layer = 5; mat = 0;
1252 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1253 part = 0; layer = 5; mat =1;
1260 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1261 part = 0; layer = 6; mat = 0;
1268 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1269 part = 0; layer = 6; mat = 1;
1276 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1277 part = 0; layer = 7; mat = 0;
1284 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1285 part = 0; layer = 7; mat = 1;
1292 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1293 part = 0; layer = 8; mat = 0;
1301 if(
pi/8<=theta&&theta<
pi/4) {
1302 mr[0] = fabs(r.x())*
cos(
pi/4)+fabs(r.y())*
sin(
pi/4);
1303 mr[1] = -fabs(r.x())*
sin(
pi/4)+fabs(r.y())*
cos(
pi/4);
1304 mr[2] = fabs(r.z());
1305 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1307 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1308 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1309 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1310 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1311 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1312 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1313 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1314 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1315 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1316 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1317 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1318 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1319 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1320 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1321 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1322 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1323 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1330 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1331 part = 0; layer = 0; mat = 0;
1338 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1339 part = 0; layer = 0; mat = 1;
1346 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1347 part = 0; layer = 1; mat = 0;
1354 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1355 part = 0; layer = 1; mat = 1;
1362 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1363 part = 0; layer = 2; mat = 0;
1370 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1371 part = 0; layer = 2; mat = 1;
1378 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1379 part = 0; layer = 3; mat = 0;
1386 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1387 part = 0; layer = 3; mat = 1;
1394 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1395 part = 0; layer = 4; mat = 0;
1402 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1403 part = 0; layer = 4; mat = 1;
1410 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1411 part = 0; layer = 5; mat = 0;
1418 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1419 part = 0; layer = 5; mat =1;
1426 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1427 part = 0; layer = 6; mat = 0;
1434 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1435 part = 0; layer = 6; mat = 1;
1442 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1443 part = 0; layer = 7; mat = 0;
1450 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1451 part = 0; layer = 7; mat = 1;
1458 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1459 part = 0; layer = 8; mat = 0;
1467 if(
pi/4<=theta&&theta<3*
pi/8) {
1468 mr[0] = fabs(r.x())*
cos(
pi/4)+fabs(r.y())*
sin(
pi/4);
1469 mr[1] = fabs(r.x())*
sin(
pi/4)-fabs(r.y())*
cos(
pi/4);
1470 mr[2] = fabs(r.z());
1471 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1473 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1474 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1475 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1476 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1477 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1478 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1479 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1480 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1481 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1482 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1483 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1484 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1485 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1486 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1487 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1488 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1489 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1496 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1497 part = 0; layer = 0; mat = 0;
1504 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1505 part = 0; layer = 0; mat = 1;
1512 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1513 part = 0; layer = 1; mat = 0;
1520 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1521 part = 0; layer = 1; mat = 1;
1528 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1529 part = 0; layer = 2; mat = 0;
1536 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1537 part = 0; layer = 2; mat = 1;
1544 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1545 part = 0; layer = 3; mat = 0;
1552 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1553 part = 0; layer = 3; mat = 1;
1560 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1561 part = 0; layer = 4; mat = 0;
1568 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1569 part = 0; layer = 4; mat = 1;
1576 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1577 part = 0; layer = 5; mat = 0;
1584 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1585 part = 0; layer = 5; mat =1;
1592 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1593 part = 0; layer = 6; mat = 0;
1600 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1601 part = 0; layer = 6; mat = 1;
1608 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1609 part = 0; layer = 7; mat = 0;
1616 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1617 part = 0; layer = 7; mat = 1;
1624 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1625 part = 0; layer = 8; mat = 0;
1633 if(3*
pi/8<=theta&&theta<
pi/2) {
1634 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1635 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1637 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1638 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1639 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1640 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1641 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1642 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1643 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1644 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1645 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1646 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1647 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1648 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1649 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1650 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1651 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1652 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1653 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1660 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1661 part = 0; layer = 0; mat = 0;
1668 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1669 part = 0; layer = 0; mat = 1;
1676 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1677 part = 0; layer = 1; mat = 0;
1684 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1685 part = 0; layer = 1; mat = 1;
1692 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1693 part = 0; layer = 2; mat = 0;
1700 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1701 part = 0; layer = 2; mat = 1;
1708 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1709 part = 0; layer = 3; mat = 0;
1716 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1717 part = 0; layer = 3; mat = 1;
1724 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1725 part = 0; layer = 4; mat = 0;
1732 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1733 part = 0; layer = 4; mat = 1;
1740 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1741 part = 0; layer = 5; mat = 0;
1748 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1749 part = 0; layer = 5; mat =1;
1756 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1757 part = 0; layer = 6; mat = 0;
1764 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1765 part = 0; layer = 6; mat = 1;
1772 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1773 part = 0; layer = 7; mat = 0;
1780 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1781 part = 0; layer = 7; mat = 1;
1788 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1789 part = 0; layer = 8; mat = 0;
1799 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1800 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1802 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1803 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1804 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1805 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1806 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1807 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1808 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1809 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1810 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1811 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1812 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1813 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1814 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1815 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1816 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1817 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1818 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1825 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1826 part = 0; layer = 0; mat = 0;
1833 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1834 part = 0; layer = 0; mat = 1;
1841 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1842 part = 0; layer = 1; mat = 0;
1849 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1850 part = 0; layer = 1; mat = 1;
1857 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1858 part = 0; layer = 2; mat = 0;
1865 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1866 part = 0; layer = 2; mat = 1;
1873 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1874 part = 0; layer = 3; mat = 0;
1881 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1882 part = 0; layer = 3; mat = 1;
1889 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1890 part = 0; layer = 4; mat = 0;
1897 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1898 part = 0; layer = 4; mat = 1;
1905 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1906 part = 0; layer = 5; mat = 0;
1913 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1914 part = 0; layer = 5; mat =1;
1921 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1922 part = 0; layer = 6; mat = 0;
1929 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1930 part = 0; layer = 6; mat = 1;
1937 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1938 part = 0; layer = 7; mat = 0;
1945 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1946 part = 0; layer = 7; mat = 1;
1953 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1954 part = 0; layer = 8; mat = 0;
1962 if(ifbar==
true||ifend==
true) {
1963 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
1966 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
1970 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
1973 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
1977 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
1980 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
1984 else if( r.x() > 0. && r.y() <= 0. && r.z() < 0. ){
1991 newb[0] = -
b[0] * m_scale;
1992 newb[1] =
b[1] * m_scale;
1993 newb[2] = -
b[2] * m_scale;
2008 return StatusCode::SUCCESS;
2017 if(m_runmode == 8 || m_runmode == 7) {
2018 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)
2032 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)
2046 if(m_turnOffField ==
true) {
2056 return StatusCode::SUCCESS;
2064 if(m_useDB ==
false) {
2065 if(m_runmode == 8 || m_runmode == 7) m_zfield = -0.9*tesla;
2066 else m_zfield = -1.0*tesla;
2069 if(m_turnOffField ==
true) {
2072 return m_zfield * m_scale;
2076 return m_ifRealField;
2082void MagneticFieldSvc::fieldGrid (
const HepPoint3D& r,
2090 double z = r.z() - m_zOffSet;
2091 if( z < m_min_FL[2] || z > m_max_FL[2] )
return;
2093 if( x < m_min_FL[0] || x > m_max_FL[0] )
return;
2095 if(
y < m_min_FL[1] ||
y > m_max_FL[1] )
return;
2096 int i = int( (x-m_min_FL[0])/m_Dxyz[0]);
2097 int j = int( (
y-m_min_FL[1])/m_Dxyz[1] );
2098 int k = int( (z-m_min_FL[2])/m_Dxyz[2] );
2100 int ijk000 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j ) + i );
2101 int ijk001 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j ) + i );
2102 int ijk010 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j + 1 ) + i );
2103 int ijk011 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j + 1) + i );
2104 int ijk100 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j) + i + 1 );
2105 int ijk101 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j) + i + 1 );
2106 int ijk110 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j + 1) + i + 1 );
2107 int ijk111 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j + 1 ) + i + 1 );
2127 double cx000 = m_Q[ ijk000 ];
2128 double cx001 = m_Q[ ijk001 ];
2129 double cx010 = m_Q[ ijk010 ];
2130 double cx011 = m_Q[ ijk011 ];
2131 double cx100 = m_Q[ ijk100 ];
2132 double cx101 = m_Q[ ijk101 ];
2133 double cx110 = m_Q[ ijk110 ];
2134 double cx111 = m_Q[ ijk111 ];
2135 double cy000 = m_Q[ ijk000+1 ];
2136 double cy001 = m_Q[ ijk001+1 ];
2137 double cy010 = m_Q[ ijk010+1 ];
2138 double cy011 = m_Q[ ijk011+1 ];
2139 double cy100 = m_Q[ ijk100+1 ];
2140 double cy101 = m_Q[ ijk101+1 ];
2141 double cy110 = m_Q[ ijk110+1 ];
2142 double cy111 = m_Q[ ijk111+1 ];
2143 double cz000 = m_Q[ ijk000+2 ];
2144 double cz001 = m_Q[ ijk001+2 ];
2145 double cz010 = m_Q[ ijk010+2 ];
2146 double cz011 = m_Q[ ijk011+2 ];
2147 double cz100 = m_Q[ ijk100+2 ];
2148 double cz101 = m_Q[ ijk101+2 ];
2149 double cz110 = m_Q[ ijk110+2 ];
2150 double cz111 = m_Q[ ijk111+2 ];
2151 double hx1 = (
x-m_min_FL[0]-i*m_Dxyz[0] )/m_Dxyz[0];
2152 double hy1 = (
y-m_min_FL[1]-j*m_Dxyz[1] )/m_Dxyz[1];
2153 double hz1 = ( z-m_min_FL[2]-k*m_Dxyz[2] )/m_Dxyz[2];
2154 double hx0 = 1.0-hx1;
2155 double hy0 = 1.0-hy1;
2156 double hz0 = 1.0-hz1;
2157 double h000 = hx0*hy0*hz0;
2158 if( fabs(h000) > 0.0 &&
2159 cx000 > 9.0e5 && cy000 > 9.0e5 && cz000 > 9.0e5)
return;
2161 double h001 = hx0*hy0*hz1;
2162 if( fabs(h001) > 0.0 &&
2163 cx001 > 9.0e5 && cy001 > 9.0e5 && cz001 > 9.0e5)
return;
2165 double h010 = hx0*hy1*hz0;
2166 if( fabs(h010) > 0.0 &&
2167 cx010 > 9.0e5 && cy010 > 9.0e5 && cz010 > 9.0e5)
return;
2169 double h011 = hx0*hy1*hz1;
2170 if( fabs(h011) > 0.0 &&
2171 cx011 > 9.0e5 && cy011 > 9.0e5 && cz011 > 9.0e5)
return;
2173 double h100 = hx1*hy0*hz0;
2174 if( fabs(h100) > 0.0 &&
2175 cx100 > 9.0e5 && cy100 > 9.0e5 && cz100 > 9.0e5)
return;
2177 double h101 = hx1*hy0*hz1;
2178 if( fabs(h101) > 0.0 &&
2179 cx101 > 9.0e5 && cy101 > 9.0e5 && cz101 > 9.0e5)
return;
2181 double h110 = hx1*hy1*hz0;
2182 if( fabs(h110) > 0.0 &&
2183 cx110 > 9.0e5 && cy110 > 9.0e5 && cz110 > 9.0e5)
return;
2185 double h111 = hx1*hy1*hz1;
2186 if( fabs(h111) > 0.0 &&
2187 cx111 > 9.0e5 && cy111 > 9.0e5 && cz111 > 9.0e5)
return;
2189 bf(0) = ( cx000*h000 + cx001*h001 + cx010*h010 + cx011*h011 +
2190 cx100*h100 + cx101*h101 + cx110*h110 + cx111*h111);
2191 bf(1) = ( cy000*h000 + cy001*h001 + cy010*h010 + cy011*h011 +
2192 cy100*h100 + cy101*h101 + cy110*h110 + cy111*h111 );
2193 bf(2) = ( cz000*h000 + cz001*h001 + cz010*h010 + cz011*h011 +
2194 cz100*h100 + cz101*h101 + cz110*h110 + cz111*h111 );
2201void MagneticFieldSvc::fieldGrid_TE (
const HepPoint3D& r,
2209 double z = r.z() - m_zOffSet_TE;
2210 if( fabs(z) < m_min_FL_TE[2] || fabs(z) > m_max_FL_TE[2] )
return;
2212 if( fabs(x) < m_min_FL_TE[0] || fabs(x) > m_max_FL_TE[0] )
return;
2214 if( fabs(
y) < m_min_FL_TE[1] || fabs(
y) > m_max_FL_TE[1] )
return;
2215 int i = int( (fabs(x)-m_min_FL_TE[0])/m_Dxyz_TE[0]);
2216 int j = int( (fabs(
y)-m_min_FL_TE[1])/m_Dxyz_TE[1] );
2217 int k = int( (fabs(z)-m_min_FL_TE[2])/m_Dxyz_TE[2] );
2219 int ijk000 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j ) + i );
2220 int ijk001 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j ) + i );
2221 int ijk010 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j + 1 ) + i );
2222 int ijk011 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j + 1) + i );
2223 int ijk100 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j) + i + 1 );
2224 int ijk101 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j) + i + 1 );
2225 int ijk110 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j + 1) + i + 1 );
2226 int ijk111 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j + 1 ) + i + 1 );
2240 double cx000 = m_Q_TE[ ijk000 ];
2241 double cx001 = m_Q_TE[ ijk001 ];
2242 double cx010 = m_Q_TE[ ijk010 ];
2243 double cx011 = m_Q_TE[ ijk011 ];
2244 double cx100 = m_Q_TE[ ijk100 ];
2245 double cx101 = m_Q_TE[ ijk101 ];
2246 double cx110 = m_Q_TE[ ijk110 ];
2247 double cx111 = m_Q_TE[ ijk111 ];
2248 double cy000 = m_Q_TE[ ijk000+1 ];
2249 double cy001 = m_Q_TE[ ijk001+1 ];
2250 double cy010 = m_Q_TE[ ijk010+1 ];
2251 double cy011 = m_Q_TE[ ijk011+1 ];
2252 double cy100 = m_Q_TE[ ijk100+1 ];
2253 double cy101 = m_Q_TE[ ijk101+1 ];
2254 double cy110 = m_Q_TE[ ijk110+1 ];
2255 double cy111 = m_Q_TE[ ijk111+1 ];
2256 double cz000 = m_Q_TE[ ijk000+2 ];
2257 double cz001 = m_Q_TE[ ijk001+2 ];
2258 double cz010 = m_Q_TE[ ijk010+2 ];
2259 double cz011 = m_Q_TE[ ijk011+2 ];
2260 double cz100 = m_Q_TE[ ijk100+2 ];
2261 double cz101 = m_Q_TE[ ijk101+2 ];
2262 double cz110 = m_Q_TE[ ijk110+2 ];
2263 double cz111 = m_Q_TE[ ijk111+2 ];
2264 double hx1 = ( fabs(x)-m_min_FL_TE[0]-i*m_Dxyz_TE[0] )/m_Dxyz_TE[0];
2265 double hy1 = ( fabs(
y)-m_min_FL_TE[1]-j*m_Dxyz_TE[1] )/m_Dxyz_TE[1];
2266 double hz1 = ( fabs(z)-m_min_FL_TE[2]-k*m_Dxyz_TE[2] )/m_Dxyz_TE[2];
2267 double hx0 = 1.0-hx1;
2268 double hy0 = 1.0-hy1;
2269 double hz0 = 1.0-hz1;
2270 double h000 = hx0*hy0*hz0;
2271 if( fabs(h000) > 0.0 &&
2272 cx000 > 9.0e5 && cy000 > 9.0e5 && cz000 > 9.0e5)
return;
2274 double h001 = hx0*hy0*hz1;
2275 if( fabs(h001) > 0.0 &&
2276 cx001 > 9.0e5 && cy001 > 9.0e5 && cz001 > 9.0e5)
return;
2278 double h010 = hx0*hy1*hz0;
2279 if( fabs(h010) > 0.0 &&
2280 cx010 > 9.0e5 && cy010 > 9.0e5 && cz010 > 9.0e5)
return;
2282 double h011 = hx0*hy1*hz1;
2283 if( fabs(h011) > 0.0 &&
2284 cx011 > 9.0e5 && cy011 > 9.0e5 && cz011 > 9.0e5)
return;
2286 double h100 = hx1*hy0*hz0;
2287 if( fabs(h100) > 0.0 &&
2288 cx100 > 9.0e5 && cy100 > 9.0e5 && cz100 > 9.0e5)
return;
2290 double h101 = hx1*hy0*hz1;
2291 if( fabs(h101) > 0.0 &&
2292 cx101 > 9.0e5 && cy101 > 9.0e5 && cz101 > 9.0e5)
return;
2294 double h110 = hx1*hy1*hz0;
2295 if( fabs(h110) > 0.0 &&
2296 cx110 > 9.0e5 && cy110 > 9.0e5 && cz110 > 9.0e5)
return;
2298 double h111 = hx1*hy1*hz1;
2299 if( fabs(h111) > 0.0 &&
2300 cx111 > 9.0e5 && cy111 > 9.0e5 && cz111 > 9.0e5)
return;
2302 bf(0) = ( cx000*h000 + cx001*h001 + cx010*h010 + cx011*h011 +
2303 cx100*h100 + cx101*h101 + cx110*h110 + cx111*h111);
2304 bf(1) = ( cy000*h000 + cy001*h001 + cy010*h010 + cy011*h011 +
2305 cy100*h100 + cy101*h101 + cy110*h110 + cy111*h111 );
2306 bf(2) = ( cz000*h000 + cz001*h001 + cz010*h010 + cz011*h011 +
2307 cz100*h100 + cz101*h101 + cz110*h110 + cz111*h111 );
2310 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
2313 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
2317 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
2321 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
2325 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
2328 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
2332 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)