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"
19#include "CLHEP/Units/PhysicalConstants.h"
49 ISvcLocator* svc ) : base_class( name, svc )
51 declareProperty(
"TurnOffField", m_turnOffField =
false);
52 declareProperty(
"FieldMapFile", m_filename );
53 declareProperty(
"GridDistance", m_gridDistance = 5);
54 declareProperty(
"RunMode", m_runmode = 2);
55 declareProperty(
"IfRealField", m_ifRealField =
true);
56 declareProperty(
"OutLevel", m_outlevel = 1);
57 declareProperty(
"Scale", m_scale = 1.0);
58 declareProperty(
"UniField", m_uniField =
false);
60 declareProperty(
"Cur_SCQ1_55", m_Cur_SCQ1_55 = 349.4);
61 declareProperty(
"Cur_SCQ1_89", m_Cur_SCQ1_89 = 426.2);
62 declareProperty(
"Cur_SCQ2_10", m_Cur_SCQ2_10 = 474.2);
64 declareProperty(
"UseDBFlag", m_useDB =
true);
65 declareProperty(
"ReadOneTime", m_readOneTime=
false);
66 declareProperty(
"RunFrom", m_runFrom=8093);
67 declareProperty(
"RunTo",m_runTo=9025);
70 if(!m_Mucfield) cout<<
"error: can not get MucMagneticField pointer"<<endl;
72 m_zfield = -1.0*tesla;
74 if(getenv(
"MAGNETICFIELDROOT") !=
NULL) {
75 path = std::string(getenv(
"MAGNETICFIELDROOT" ));
77 std::cerr<<
"Couldn't find MAGNETICFIELDROOT"<<std::endl;
97 m_Cur_SCQ1_55 = 349.4;
98 m_Cur_SCQ1_89 = 426.2;
99 m_Cur_SCQ2_10 = 474.2;
106 m_zfield = -1.0*tesla;
115 if(m_Mucfield)
delete m_Mucfield;
122bool init_mucMagneticField()
126 if( m_Mucfield->getPath() == path )
return true;
132 cout<<
"error: can not get MucMagneticField pointer"<<endl;
143 MsgStream log(
msgSvc(), name());
144 StatusCode status = Service::initialize();
145 former_m_filename_TE =
"First Run";
146 former_m_filename =
"First Run";
149 IIncidentSvc* incsvc;
150 status = service(
"IncidentSvc", incsvc);
152 if( status.isSuccess() ){
153 incsvc -> addListener(
this,
"NewRun", priority);
156 status = serviceLocator()->service(
"EventDataSvc",
m_eventSvc,
true);
157 if (status.isFailure() ) {
158 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
162 if( !init_mucMagneticField() )
return false;
163 StatusCode status =
true;
165 if(m_useDB ==
false) {
166 if(m_gridDistance == 5) {
169 m_Q_TE.reserve(176608);
170 m_P_TE.reserve(176608);
172 if(m_gridDistance == 10) {
175 m_Q_TE.reserve(23833);
176 m_P_TE.reserve(23833);
180 m_filename_TE = path;
181 if(m_gridDistance == 10) {
182 m_filename_TE += std::string(
"/dat/TEMap10cm.dat");
184 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode2.dat");
185 else if(m_runmode == 4)
186 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode4.dat");
187 else if(m_runmode == 6)
188 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode6.dat");
189 else if(m_runmode == 7)
190 m_filename += std::string(
"/dat/2008-04-03BESIII-field-Mode7.dat");
192 m_filename += std::string(
"/dat/2007-08-28BESIII-field.dat");
193 std::cout<<
"WARNING: YOU ARE USING OLD FIELD MAP!!!!"<<std::endl;
196 if(m_gridDistance == 5) {
197 m_filename_TE += std::string(
"/dat/TEMap5cm.dat");
199 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode1.dat");
200 else if(m_runmode == 2)
201 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode2.dat");
202 else if(m_runmode == 3)
203 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
204 else if(m_runmode == 4)
205 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode4.dat");
206 else if(m_runmode == 5)
207 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode5.dat");
208 else if(m_runmode == 6)
209 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode6.dat");
210 else if(m_runmode == 7)
211 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode7.dat");
212 else if(m_runmode == 8)
213 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode8.dat");
215 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode2.dat");
216 std::cout<<
"WARNING: NO RUN MODE, YOU ARE USING DEFAULT FIELD MAP!!!!"<<std::endl;
219 cout<<
"*** Read field map: "<<m_filename<<endl;
220 cout<<
"*** Read field map "<<m_filename_TE<<endl;
222 status = parseFile();
223 status = parseFile_TE();
225 if ( status.isSuccess() ) {
226 log << MSG::DEBUG <<
"Magnetic field parsed successfully" << endreq;
229 cout <<
"Magnetic field parsed successfully" << endl;
232 for (
int iC = 0; iC< 2; ++iC ){
233 m_min_FL[iC] = -90.0*cm;
234 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
236 m_min_FL_TE[iC] = 0.0*cm;
237 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
239 m_min_FL[2] = -120.0*cm;
240 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
242 m_min_FL_TE[2] = 0.0*cm;
243 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
247 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
249 cout <<
"Magnetic field parse failled" << endl;
261 log << MSG::ERROR <<
"Could not open connection to database" << endreq;
272 MsgStream log(
msgSvc(), name());
276 if( !init_mucMagneticField() ) {
277 cerr <<
" STOP! " << endl;
291 if(m_gridDistance == 5) {
294 m_Q_1.reserve(201250);
295 m_P_1.reserve(201250);
296 m_Q_2.reserve(201250);
297 m_P_2.reserve(201250);
298 m_Q_TE.reserve(176608);
299 m_P_TE.reserve(176608);
301 if(m_gridDistance == 10) {
304 m_Q_1.reserve(27082);
305 m_P_1.reserve(27082);
306 m_Q_2.reserve(27082);
307 m_P_2.reserve(27082);
308 m_Q_TE.reserve(23833);
309 m_P_TE.reserve(23833);
316 setenv(
"BEPCII_INFO.BPR_PRB", BPR_PRB, 1);
317 setenv(
"BEPCII_INFO.BER_PRB", BER_PRB, 1);
318 int ssm_curr = int (
current[0]);
326 log << MSG::INFO <<
"SSM current: " <<
current[0] <<
" SCQL current: " <<
current[1] <<
" SCQR current: " <<
current[2] <<
" in Run " <<
runNo << endreq;
330 cout <<
"SSM current: " <<
current[0] <<
" SCQL current: " <<
current[1]
331 <<
" SCQR current: " <<
current[2] <<
" in Run " <<
runNo << endl;
339 if(((ssm_curr >= 3367) && (ssm_curr <= 3370) && ((scql_curr+scqr_curr)/2 < m_Cur_SCQ1_89))) {
340 m_zfield = -1.0*tesla;
342 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode2.dat");
344 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
346 cout <<
"Select field map: " << m_filename << endl;
349 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true))
351 former_m_filename = m_filename;
355 StatusCode status = parseFile();
357 if ( !status.isSuccess() ) {
358 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
362 cout <<
"Magnetic field parse failled" << endl;
371 if(m_gridDistance == 5) {
375 if(m_gridDistance == 10) {
381 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
383 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
385 cout <<
"Select field map: " << m_filename << endl;
388 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true))
390 former_m_filename = m_filename;
394 status = parseFile();
396 if ( !status.isSuccess() ) {
397 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
401 cout <<
"Magnetic field parse failled" << endl;
410 if(m_gridDistance == 5) {
414 if(m_gridDistance == 10) {
419 if(m_Q_2.size() != m_Q_1.size()) {
421 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
423 cout <<
"The two field maps used in this run are wrong!!!" << endl;
428 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
429 double fieldvalue = (m_Q_1[iQ] - m_Q_2[iQ])/(m_Cur_SCQ1_55 - m_Cur_SCQ1_89)*((scql_curr+scqr_curr)/2 - m_Cur_SCQ1_89) + m_Q_2[iQ];
430 m_Q.push_back(fieldvalue);
431 m_P.push_back(m_P_2[iQ]);
435 if(((ssm_curr >= 3367) && (ssm_curr <= 3370) && ((scql_curr+scqr_curr)/2 >= m_Cur_SCQ1_89))){
436 m_zfield = -1.0*tesla;
438 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode3.dat");
440 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
442 cout <<
"Select field map: " << m_filename << endl;
444 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true))
446 former_m_filename = m_filename;
450 StatusCode status = parseFile();
452 if ( !status.isSuccess() ) {
453 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
457 cout <<
"Magnetic field parse failled" << endl;
466 if(m_gridDistance == 5) {
470 if(m_gridDistance == 10) {
476 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode4.dat");
478 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
480 cout <<
"Select field map: " << m_filename << endl;
483 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true))
485 former_m_filename = m_filename;
489 status = parseFile();
491 if ( !status.isSuccess() ) {
492 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
496 cout <<
"Magnetic field parse failled" << endl;
505 if(m_gridDistance == 5) {
509 if(m_gridDistance == 10) {
515 if(m_Q_2.size() != m_Q_1.size()) {
518 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
522 cout <<
"The two field maps used in this run are wrong!!!" << endl;
528 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
529 double fieldvalue = (m_Q_1[iQ] - m_Q_2[iQ])/(m_Cur_SCQ1_89 - m_Cur_SCQ2_10)*((scql_curr+scqr_curr)/2 - m_Cur_SCQ2_10) + m_Q_2[iQ];
530 m_Q.push_back(fieldvalue);
531 m_P.push_back(m_P_2[iQ]);
534 if((ssm_curr >= 3033) && (ssm_curr <= 3035)) {
535 m_zfield = -0.9*tesla;
537 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode7.dat");
539 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
541 cout <<
"Select field map: " << m_filename << endl;
544 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true))
546 former_m_filename = m_filename;
550 StatusCode status = parseFile();
552 if ( !status.isSuccess() ) {
553 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
557 cout <<
"Magnetic field parse failled" << endl;
566 if(m_gridDistance == 5) {
570 if(m_gridDistance == 10) {
576 m_filename += std::string(
"/dat/2008-05-27BESIII-field-Mode8.dat");
578 log << MSG::INFO <<
"Select field map: " << m_filename << endreq;
580 cout <<
"Select field map: " << m_filename << endl;
583 if(((former_m_filename ==
"First Run") || (former_m_filename != m_filename))&&(
m_readOneTime ==
true)){
584 former_m_filename = m_filename;
588 status = parseFile();
590 if ( !status.isSuccess() ) {
591 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
595 cout <<
"Magnetic field parse failled" << endl;
604 if(m_gridDistance == 5) {
608 if(m_gridDistance == 10) {
613 if(m_Q_2.size() != m_Q_1.size()) {
615 log << MSG::FATAL <<
"The two field maps used in this run are wrong!!!" << endreq;
617 cout <<
"The two field maps used in this run are wrong!!!" << endl;
622 for(
unsigned int iQ = 0; iQ < m_Q_1.size(); iQ++) {
623 double fieldvalue = (m_Q_1[iQ] - m_Q_2[iQ])/(m_Cur_SCQ1_55 - m_Cur_SCQ1_89)*((scql_curr+scqr_curr)/2 - m_Cur_SCQ1_89) + m_Q_2[iQ];
624 m_Q.push_back(fieldvalue);
625 m_P.push_back(m_P_2[iQ]);
628 if((!((ssm_curr >= 3367) && (ssm_curr <= 3370)) && !((ssm_curr >= 3033) && (ssm_curr <= 3035))) || scql_curr == 0 || scqr_curr == 0) {
630 log << MSG::FATAL <<
"The current of run " <<
runNo <<
" is abnormal in database, please check it! " << endreq;
631 log << MSG::FATAL <<
"The current of SSM is " << ssm_curr <<
", SCQR is " << scqr_curr <<
", SCQL is " << scql_curr << endreq;
633 cout <<
"The current of run " <<
runNo
634 <<
" is abnormal in database, please check it! " << endl;
635 cout <<
"The current of SSM is " << ssm_curr
636 <<
", SCQR is " << scqr_curr <<
", SCQL is " << scql_curr << endl;
641 if(m_Q.size() == 0) {
643 log << MSG::FATAL <<
"This size of field map vector is ZERO, please check the current of run " <<
runNo <<
" in database!" << endreq;
645 cout <<
"This size of field map vector is ZERO,"
646 <<
" please check the current of run " <<
runNo
647 <<
" in database!" << endl;
652 m_filename_TE = path;
653 if(m_gridDistance == 10) m_filename_TE += std::string(
"/dat/TEMap10cm.dat");
654 if(m_gridDistance == 5) m_filename_TE += std::string(
"/dat/TEMap5cm.dat");
656 log << MSG::INFO <<
"Select field map: " << m_filename_TE << endreq;
658 cout <<
"Select field map: " << m_filename_TE << endl;
660 if(((former_m_filename_TE ==
"First Run") || (former_m_filename_TE != m_filename_TE))&&(
m_readOneTime ==
true))
662 former_m_filename_TE = m_filename_TE;
666 StatusCode status = parseFile_TE();
668 if ( !status.isSuccess() ) {
669 log << MSG::DEBUG <<
"Magnetic field parse failled" << endreq;
673 cout <<
"Magnetic field parse failled" << endl;
677 for (
int iC = 0; iC< 2; ++iC ){
678 m_min_FL[iC] = -90.0*cm;
679 m_max_FL[iC] = m_min_FL[iC]+( m_Nxyz[iC]-1 )* m_Dxyz[iC];
681 m_min_FL_TE[iC] = 0.0*cm;
682 m_max_FL_TE[iC] = m_min_FL_TE[iC]+( m_Nxyz_TE[iC]-1 )* m_Dxyz_TE[iC];
684 m_min_FL[2] = -120.0*cm;
685 m_max_FL[2] = m_min_FL[2]+( m_Nxyz[2]-1 )* m_Dxyz[2];
687 m_min_FL_TE[2] = 0.0*cm;
688 m_max_FL_TE[2] = m_min_FL_TE[2]+( m_Nxyz_TE[2]-1 )* m_Dxyz_TE[2];
697 MsgStream log(
msgSvc(), name() );
699 StatusCode status = Service::finalize();
701 if ( status.isSuccess() )
702 log << MSG::INFO <<
"Service finalized successfully" << endreq;
728 MsgStream log( messageService(), name() );
729 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
730 if ( inc.type() !=
"NewRun" ){
733 log << MSG::DEBUG <<
"Begin New Runcc" << endreq;
735 SmartDataPtr<Event::EventHeader> eventHeader(
m_eventSvc,
"/Event/EventHeader");
736 int new_run = eventHeader->runNumber();
737 if(new_run<0) new_run=-new_run;
749 std::vector<double>
current(3,0.);
753 cout<<
"Run:"<<new_run<<
" BeamEnergy is NULL, please check!!"<<endl;
761 cout<<
"Run:"<<new_run<<
" MagnetInfo is NULL, please check!!"<<endl;
773 static int save_run = 0;
774 if( new_run == save_run )
return;
776 cout <<
"Begin New Run " << new_run << endl;
778 if(m_useDB ==
true) {
788StatusCode MagneticFieldSvc::parseFile() {
790 StatusCode sc = StatusCode::FAILURE;
792 MsgStream log(
msgSvc(), name() );
794 StatusCode sc =
false;
798 std::ifstream infile( m_filename.c_str() );
801 sc = StatusCode::SUCCESS;
808 infile.getline( line, 255 );
809 }
while( line[0] !=
'P' );
813 char* token = strtok( line,
" " );
816 if ( token ) { sPar[ip] = token; token = strtok(
NULL,
" " );}
819 }
while ( token !=
NULL );
820 long int npar = atoi( sPar[1].
c_str() );
824 infile.getline( line, 255 );
825 }
while( line[0] !=
'G' );
829 infile.getline( line, 255 );
830 }
while( line[0] !=
'#' );
833 infile.getline( line, 255 );
834 std::string sGeom[7];
835 token = strtok( line,
" " );
838 if ( token ) { sGeom[ig] = token; token = strtok(
NULL,
" " );}
841 }
while (token !=
NULL);
844 m_Dxyz[0] = atof( sGeom[0].
c_str() ) * cm;
845 m_Dxyz[1] = atof( sGeom[1].
c_str() ) * cm;
846 m_Dxyz[2] = atof( sGeom[2].
c_str() ) * cm;
847 m_Nxyz[0] = atoi( sGeom[3].
c_str() );
848 m_Nxyz[1] = atoi( sGeom[4].
c_str() );
849 m_Nxyz[2] = atoi( sGeom[5].
c_str() );
850 m_zOffSet = atof( sGeom[6].
c_str() ) * cm;
852 long int nlines = ( npar - 7 ) / 3;
863 infile.getline( line, 255 );
864 if ( line[0] ==
'#' )
continue;
865 std::string gridx, gridy, gridz, sFx, sFy, sFz;
866 char* token = strtok( line,
" " );
867 if ( token ) { gridx = token; token = strtok(
NULL,
" " );}
else continue;
868 if ( token ) { gridy = token; token = strtok(
NULL,
" " );}
else continue;
869 if ( token ) { gridz = token; token = strtok(
NULL,
" " );}
else continue;
870 if ( token ) { sFx = token; token = strtok(
NULL,
" " );}
else continue;
871 if ( token ) { sFy = token; token = strtok(
NULL,
" " );}
else continue;
872 if ( token ) { sFz = token; token = strtok(
NULL,
" " );}
else continue;
873 if ( token !=
NULL )
continue;
875 double gx = atof( gridx.c_str() ) * m;
876 double gy = atof( gridy.c_str() ) * m;
877 double gz = atof( gridz.c_str() ) * m;
879 double fx = atof( sFx.c_str() ) * tesla;
880 double fy = atof( sFy.c_str() ) * tesla;
881 double fz = atof( sFz.c_str() ) * tesla;
883 if(m_outlevel == 0) {
885 log << MSG::DEBUG <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endreq;
886 log << MSG::DEBUG <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endreq;
888 cout <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endl;
889 cout <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endl;
905 if ( nlines != ncheck) {
907 log << MSG::ERROR <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
909 return StatusCode::FAILURE;
911 cout <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
919 log << MSG::ERROR <<
"Unable to open magnetic field file : "
920 << m_filename << endreq;
922 cout <<
"Unable to open magnetic field file : "
923 << m_filename << endl;
935StatusCode MagneticFieldSvc::parseFile_TE() {
937 StatusCode sc = StatusCode::FAILURE;
939 MsgStream log(
msgSvc(), name() );
941 StatusCode sc =
false;
945 std::ifstream infile( m_filename_TE.c_str() );
949 sc = StatusCode::SUCCESS;
956 infile.getline( line, 255 );
957 }
while( line[0] !=
'P' );
961 char* token = strtok( line,
" " );
964 if ( token ) { sPar[ip] = token; token = strtok(
NULL,
" " );}
967 }
while ( token !=
NULL );
968 long int npar = atoi( sPar[1].
c_str() );
972 infile.getline( line, 255 );
973 }
while( line[0] !=
'G' );
977 infile.getline( line, 255 );
978 }
while( line[0] !=
'#' );
981 infile.getline( line, 255 );
982 std::string sGeom[7];
983 token = strtok( line,
" " );
986 if ( token ) { sGeom[ig] = token; token = strtok(
NULL,
" " );}
989 }
while (token !=
NULL);
992 m_Dxyz_TE[0] = atof( sGeom[0].
c_str() ) * cm;
993 m_Dxyz_TE[1] = atof( sGeom[1].
c_str() ) * cm;
994 m_Dxyz_TE[2] = atof( sGeom[2].
c_str() ) * cm;
995 m_Nxyz_TE[0] = atoi( sGeom[3].
c_str() );
996 m_Nxyz_TE[1] = atoi( sGeom[4].
c_str() );
997 m_Nxyz_TE[2] = atoi( sGeom[5].
c_str() );
998 m_zOffSet_TE = atof( sGeom[6].
c_str() ) * cm;
1000 long int nlines = ( npar - 7 ) / 3;
1003 long int ncheck = 0;
1011 infile.getline( line, 255 );
1012 if ( line[0] ==
'#' )
continue;
1013 std::string gridx, gridy, gridz, sFx, sFy, sFz;
1014 char* token = strtok( line,
" " );
1015 if ( token ) { gridx = token; token = strtok(
NULL,
" " );}
else continue;
1016 if ( token ) { gridy = token; token = strtok(
NULL,
" " );}
else continue;
1017 if ( token ) { gridz = token; token = strtok(
NULL,
" " );}
else continue;
1018 if ( token ) { sFx = token; token = strtok(
NULL,
" " );}
else continue;
1019 if ( token ) { sFy = token; token = strtok(
NULL,
" " );}
else continue;
1020 if ( token ) { sFz = token; token = strtok(
NULL,
" " );}
else continue;
1021 if ( token !=
NULL )
continue;
1023 double gx = atof( gridx.c_str() ) * m;
1024 double gy = atof( gridy.c_str() ) * m;
1025 double gz = atof( gridz.c_str() ) * m;
1027 double fx = atof( sFx.c_str() ) * tesla;
1028 double fy = atof( sFy.c_str() ) * tesla;
1029 double fz = atof( sFz.c_str() ) * tesla;
1031 if(m_outlevel == 0) {
1033 log << MSG::DEBUG <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endreq;
1034 log << MSG::DEBUG <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endreq;
1036 cout <<
"grid x, y, z is "<< gx <<
", " << gy <<
", " << gz << endl;
1037 cout <<
"field x, y, z is "<< fx <<
", " << fy <<
", " << fz << endl;
1041 m_P_TE.push_back( gx );
1042 m_P_TE.push_back( gy );
1043 m_P_TE.push_back( gz );
1046 m_Q_TE.push_back( fx );
1047 m_Q_TE.push_back( fy );
1048 m_Q_TE.push_back( fz );
1053 if ( nlines != ncheck) {
1055 log << MSG::ERROR <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1057 return StatusCode::FAILURE;
1059 cout <<
"nline is " << nlines <<
"; ncheck is " << ncheck <<
" Number of points in field map does not match!"
1067 log << MSG::ERROR <<
"Unable to open magnetic field file : "
1068 << m_filename_TE << endreq;
1070 cout <<
"Unable to open magnetic field file : "
1071 << m_filename_TE << endl;
1084 if(m_turnOffField ==
true) {
1089 return StatusCode::SUCCESS;
1099 return StatusCode::SUCCESS;
1107 double new_x = -newr.x();
1108 double new_y = newr.y();
1109 double new_z = -newr.z();
1116 if(-2.1*m<r.z() && r.z()<2.1*m && -1.8*m<r.x() && r.x()<1.8*m && -1.8*m<r.y() && r.y()<1.8*m)
1118 if(-1.2*m<r.z()&&r.z()<1.2*m&&0*m<=std::sqrt(r.x()*r.x()+r.y()*r.y())&&std::sqrt(r.x()*r.x()+r.y()*r.y())<0.9*m)
1121 this->fieldGrid( r,
b );
1125 this->fieldGrid_TE( r,
b );
1128 if((fabs(r.z())<=1970*mm && sqrt(r.x()*r.x()+r.y()*r.y()) >= 1740*mm) || (fabs(r.z())>=2050*mm))
1132 int part = 0, layer = 0, mat = 0;
1137 theta = atan2(fabs(r.y()),fabs(r.x()));
1138 if(0<=theta&&theta<
pi/8) {
1139 mr[0] = fabs(r.x()); mr[1] = -fabs(r.y()); mr[2] = fabs(r.z());
1140 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm){
1142 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1143 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1144 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1145 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1146 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1147 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1148 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1149 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1150 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1151 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1152 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1153 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1154 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1155 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1156 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1157 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1158 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1165 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1166 part = 0; layer = 0; mat = 0;
1173 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1174 part = 0; layer = 0; mat = 1;
1181 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1182 part = 0; layer = 1; mat = 0;
1189 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1190 part = 0; layer = 1; mat = 1;
1197 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1198 part = 0; layer = 2; mat = 0;
1205 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1206 part = 0; layer = 2; mat = 1;
1213 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1214 part = 0; layer = 3; mat = 0;
1221 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1222 part = 0; layer = 3; mat = 1;
1229 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1230 part = 0; layer = 4; mat = 0;
1237 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1238 part = 0; layer = 4; mat = 1;
1245 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1246 part = 0; layer = 5; mat = 0;
1253 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1254 part = 0; layer = 5; mat =1;
1261 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1262 part = 0; layer = 6; mat = 0;
1269 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1270 part = 0; layer = 6; mat = 1;
1277 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1278 part = 0; layer = 7; mat = 0;
1285 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1286 part = 0; layer = 7; mat = 1;
1293 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1294 part = 0; layer = 8; mat = 0;
1302 if(
pi/8<=theta&&theta<
pi/4) {
1303 mr[0] = fabs(r.x())*
cos(
pi/4)+fabs(r.y())*
sin(
pi/4);
1304 mr[1] = -fabs(r.x())*
sin(
pi/4)+fabs(r.y())*
cos(
pi/4);
1305 mr[2] = fabs(r.z());
1306 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1308 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1309 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1310 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1311 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1312 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1313 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1314 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1315 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1316 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1317 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1318 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1319 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1320 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1321 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1322 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1323 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1324 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1331 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1332 part = 0; layer = 0; mat = 0;
1339 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1340 part = 0; layer = 0; mat = 1;
1347 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1348 part = 0; layer = 1; mat = 0;
1355 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1356 part = 0; layer = 1; mat = 1;
1363 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1364 part = 0; layer = 2; mat = 0;
1371 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1372 part = 0; layer = 2; mat = 1;
1379 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1380 part = 0; layer = 3; mat = 0;
1387 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1388 part = 0; layer = 3; mat = 1;
1395 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1396 part = 0; layer = 4; mat = 0;
1403 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1404 part = 0; layer = 4; mat = 1;
1411 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1412 part = 0; layer = 5; mat = 0;
1419 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1420 part = 0; layer = 5; mat =1;
1427 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1428 part = 0; layer = 6; mat = 0;
1435 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1436 part = 0; layer = 6; mat = 1;
1443 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1444 part = 0; layer = 7; mat = 0;
1451 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1452 part = 0; layer = 7; mat = 1;
1459 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1460 part = 0; layer = 8; mat = 0;
1468 if(
pi/4<=theta&&theta<3*
pi/8) {
1469 mr[0] = fabs(r.x())*
cos(
pi/4)+fabs(r.y())*
sin(
pi/4);
1470 mr[1] = fabs(r.x())*
sin(
pi/4)-fabs(r.y())*
cos(
pi/4);
1471 mr[2] = fabs(r.z());
1472 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1474 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1475 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1476 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1477 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1478 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1479 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1480 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1481 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1482 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1483 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1484 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1485 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1486 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1487 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1488 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1489 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1490 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1497 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1498 part = 0; layer = 0; mat = 0;
1505 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1506 part = 0; layer = 0; mat = 1;
1513 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1514 part = 0; layer = 1; mat = 0;
1521 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1522 part = 0; layer = 1; mat = 1;
1529 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1530 part = 0; layer = 2; mat = 0;
1537 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1538 part = 0; layer = 2; mat = 1;
1545 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1546 part = 0; layer = 3; mat = 0;
1553 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1554 part = 0; layer = 3; mat = 1;
1561 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1562 part = 0; layer = 4; mat = 0;
1569 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1570 part = 0; layer = 4; mat = 1;
1577 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1578 part = 0; layer = 5; mat = 0;
1585 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1586 part = 0; layer = 5; mat =1;
1593 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1594 part = 0; layer = 6; mat = 0;
1601 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1602 part = 0; layer = 6; mat = 1;
1609 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1610 part = 0; layer = 7; mat = 0;
1617 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1618 part = 0; layer = 7; mat = 1;
1625 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1626 part = 0; layer = 8; mat = 0;
1634 if(3*
pi/8<=theta&&theta<
pi/2) {
1635 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1636 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1638 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1639 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1640 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1641 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1642 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1643 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1644 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1645 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1646 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1647 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1648 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1649 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1650 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1651 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1652 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1653 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1654 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1661 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1662 part = 0; layer = 0; mat = 0;
1669 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1670 part = 0; layer = 0; mat = 1;
1677 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1678 part = 0; layer = 1; mat = 0;
1685 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1686 part = 0; layer = 1; mat = 1;
1693 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1694 part = 0; layer = 2; mat = 0;
1701 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1702 part = 0; layer = 2; mat = 1;
1709 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1710 part = 0; layer = 3; mat = 0;
1717 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1718 part = 0; layer = 3; mat = 1;
1725 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1726 part = 0; layer = 4; mat = 0;
1733 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1734 part = 0; layer = 4; mat = 1;
1741 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1742 part = 0; layer = 5; mat = 0;
1749 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1750 part = 0; layer = 5; mat =1;
1757 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1758 part = 0; layer = 6; mat = 0;
1765 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1766 part = 0; layer = 6; mat = 1;
1773 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1774 part = 0; layer = 7; mat = 0;
1781 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1782 part = 0; layer = 7; mat = 1;
1789 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1790 part = 0; layer = 8; mat = 0;
1800 mr[0] = fabs(r.y()); mr[1] = -fabs(r.x()); mr[2] = fabs(r.z());
1801 if(mr[2]<=1970*mm&&1740*mm<=mr[0]&&mr[0]<=2620*mm) {
1803 if(1740*mm<=mr[0]&&mr[0]<1770*mm) { layer = 0; mat = 0; }
1804 if(1770*mm<=mr[0]&&mr[0]<1810*mm) { layer = 0; mat = 1; }
1805 if(1810*mm<=mr[0]&&mr[0]<1840*mm) { layer = 1; mat = 0; }
1806 if(1840*mm<=mr[0]&&mr[0]<1880*mm) { layer = 1; mat = 1; }
1807 if(1880*mm<=mr[0]&&mr[0]<1910*mm) { layer = 2; mat = 0; }
1808 if(1910*mm<=mr[0]&&mr[0]<1950*mm) { layer = 2; mat = 1; }
1809 if(1950*mm<=mr[0]&&mr[0]<1990*mm) { layer = 3; mat = 0; }
1810 if(1990*mm<=mr[0]&&mr[0]<2030*mm) { layer = 3; mat = 1; }
1811 if(2030*mm<=mr[0]&&mr[0]<2070*mm) { layer = 4; mat = 0; }
1812 if(2070*mm<=mr[0]&&mr[0]<2110*mm) { layer = 4; mat = 1; }
1813 if(2110*mm<=mr[0]&&mr[0]<2190*mm) { layer = 5; mat = 0; }
1814 if(2190*mm<=mr[0]&&mr[0]<2230*mm) { layer = 5; mat = 1; }
1815 if(2230*mm<=mr[0]&&mr[0]<2310*mm) { layer = 6; mat = 0; }
1816 if(2310*mm<=mr[0]&&mr[0]<2350*mm) { layer = 6; mat = 1; }
1817 if(2350*mm<=mr[0]&&mr[0]<2430*mm) { layer = 7; mat = 0; }
1818 if(2430*mm<=mr[0]&&mr[0]<2470*mm) { layer = 7; mat = 1; }
1819 if(2470*mm<=mr[0]&&mr[0]<=2620*mm) { layer = 8; mat = 0; }
1826 if(2050*mm<=mr[2]&&mr[2]<2090*mm&&1034*mm<=mr[0]&&mr[0]<=2500*mm){
1827 part = 0; layer = 0; mat = 0;
1834 if(2090*mm<=mr[2]&&mr[2]<2130*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1835 part = 0; layer = 0; mat = 1;
1842 if(2130*mm<=mr[2]&&mr[2]<2170*mm&&1067*mm<=mr[0]&&mr[0]<=2500*mm) {
1843 part = 0; layer = 1; mat = 0;
1850 if(2170*mm<=mr[2]&&mr[2]<2210*mm&&1100*mm<=mr[0]&&mr[0]<=2500*mm) {
1851 part = 0; layer = 1; mat = 1;
1858 if(2210*mm<=mr[2]&&mr[2]<2240*mm&&1100*mm<mr[0]&&mr[0]<=2500*mm) {
1859 part = 0; layer = 2; mat = 0;
1866 if(2240*mm<=mr[2]&&mr[2]<2280*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1867 part = 0; layer = 2; mat = 1;
1874 if(2280*mm<=mr[2]&&mr[2]<2310*mm&&1133*mm<=mr[0]&&mr[0]<=2500*mm) {
1875 part = 0; layer = 3; mat = 0;
1882 if(2310*mm<=mr[2]&&mr[2]<2350*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1883 part = 0; layer = 3; mat = 1;
1890 if(2350*mm<=mr[2]&&mr[2]<2380*mm&&1167*mm<=mr[0]&&mr[0]<=2500*mm) {
1891 part = 0; layer = 4; mat = 0;
1898 if(2380*mm<=mr[2]&&mr[2]<2420*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1899 part = 0; layer = 4; mat = 1;
1906 if(2420*mm<=mr[2]&&mr[2]<2470*mm&&1203*mm<=mr[0]&&mr[0]<=2500*mm) {
1907 part = 0; layer = 5; mat = 0;
1914 if(2470*mm<=mr[2]&&mr[2]<2510*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1915 part = 0; layer = 5; mat =1;
1922 if(2510*mm<=mr[2]&&mr[2]<2590*mm&&1241*mm<=mr[0]&&mr[0]<=2500*mm) {
1923 part = 0; layer = 6; mat = 0;
1930 if(2590*mm<=mr[2]&&mr[2]<2630*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1931 part = 0; layer = 6; mat = 1;
1938 if(2630*mm<=mr[2]&&mr[2]<2710*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1939 part = 0; layer = 7; mat = 0;
1946 if(2710*mm<=mr[2]&&mr[2]<2750*mm&&1362*mm<=mr[0]&&mr[0]<=2500*mm) {
1947 part = 0; layer = 7; mat = 1;
1954 if(2750*mm<=mr[2]&&mr[2]<=2800*mm&&1302*mm<=mr[0]&&mr[0]<=2500*mm) {
1955 part = 0; layer = 8; mat = 0;
1963 if(ifbar==
true||ifend==
true) {
1964 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
1967 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
1971 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
1974 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
1978 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
1981 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
1985 else if( r.x() > 0. && r.y() <= 0. && r.z() < 0. ){
1992 newb[0] = -
b[0] * m_scale;
1993 newb[1] =
b[1] * m_scale;
1994 newb[2] = -
b[2] * m_scale;
2009 return StatusCode::SUCCESS;
2018 if(m_runmode == 8 || m_runmode == 7) {
2019 if(-1.5*m<=r.z()&&r.z()<=1.5*m&&0*m<=std::sqrt(r.x()*r.x()+r.y()*r.y())&&std::sqrt(r.x()*r.x()+r.y()*r.y())<=1.5*m)
2033 if(-1.5*m<=r.z()&&r.z()<=1.5*m&&0*m<=std::sqrt(r.x()*r.x()+r.y()*r.y())&&std::sqrt(r.x()*r.x()+r.y()*r.y())<=1.5*m)
2047 if(m_turnOffField ==
true) {
2057 return StatusCode::SUCCESS;
2065 if(m_useDB ==
false) {
2066 if(m_runmode == 8 || m_runmode == 7) m_zfield = -0.9*tesla;
2067 else m_zfield = -1.0*tesla;
2070 if(m_turnOffField ==
true) {
2073 return m_zfield * m_scale;
2077 return m_ifRealField;
2083void MagneticFieldSvc::fieldGrid (
const HepPoint3D& r,
2091 double z = r.z() - m_zOffSet;
2092 if( z < m_min_FL[2] || z > m_max_FL[2] )
return;
2094 if( x < m_min_FL[0] || x > m_max_FL[0] )
return;
2096 if(
y < m_min_FL[1] ||
y > m_max_FL[1] )
return;
2097 int i = int( (x-m_min_FL[0])/m_Dxyz[0]);
2098 int j = int( (
y-m_min_FL[1])/m_Dxyz[1] );
2099 int k = int( (z-m_min_FL[2])/m_Dxyz[2] );
2101 int ijk000 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j ) + i );
2102 int ijk001 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j ) + i );
2103 int ijk010 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j + 1 ) + i );
2104 int ijk011 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j + 1) + i );
2105 int ijk100 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j) + i + 1 );
2106 int ijk101 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j) + i + 1 );
2107 int ijk110 = 3*( m_Nxyz[0]*( m_Nxyz[1]*k + j + 1) + i + 1 );
2108 int ijk111 = 3*( m_Nxyz[0]*( m_Nxyz[1]*(k+1) + j + 1 ) + i + 1 );
2128 double cx000 = m_Q[ ijk000 ];
2129 double cx001 = m_Q[ ijk001 ];
2130 double cx010 = m_Q[ ijk010 ];
2131 double cx011 = m_Q[ ijk011 ];
2132 double cx100 = m_Q[ ijk100 ];
2133 double cx101 = m_Q[ ijk101 ];
2134 double cx110 = m_Q[ ijk110 ];
2135 double cx111 = m_Q[ ijk111 ];
2136 double cy000 = m_Q[ ijk000+1 ];
2137 double cy001 = m_Q[ ijk001+1 ];
2138 double cy010 = m_Q[ ijk010+1 ];
2139 double cy011 = m_Q[ ijk011+1 ];
2140 double cy100 = m_Q[ ijk100+1 ];
2141 double cy101 = m_Q[ ijk101+1 ];
2142 double cy110 = m_Q[ ijk110+1 ];
2143 double cy111 = m_Q[ ijk111+1 ];
2144 double cz000 = m_Q[ ijk000+2 ];
2145 double cz001 = m_Q[ ijk001+2 ];
2146 double cz010 = m_Q[ ijk010+2 ];
2147 double cz011 = m_Q[ ijk011+2 ];
2148 double cz100 = m_Q[ ijk100+2 ];
2149 double cz101 = m_Q[ ijk101+2 ];
2150 double cz110 = m_Q[ ijk110+2 ];
2151 double cz111 = m_Q[ ijk111+2 ];
2152 double hx1 = (
x-m_min_FL[0]-i*m_Dxyz[0] )/m_Dxyz[0];
2153 double hy1 = (
y-m_min_FL[1]-j*m_Dxyz[1] )/m_Dxyz[1];
2154 double hz1 = ( z-m_min_FL[2]-k*m_Dxyz[2] )/m_Dxyz[2];
2155 double hx0 = 1.0-hx1;
2156 double hy0 = 1.0-hy1;
2157 double hz0 = 1.0-hz1;
2158 double h000 = hx0*hy0*hz0;
2159 if( fabs(h000) > 0.0 &&
2160 cx000 > 9.0e5 && cy000 > 9.0e5 && cz000 > 9.0e5)
return;
2162 double h001 = hx0*hy0*hz1;
2163 if( fabs(h001) > 0.0 &&
2164 cx001 > 9.0e5 && cy001 > 9.0e5 && cz001 > 9.0e5)
return;
2166 double h010 = hx0*hy1*hz0;
2167 if( fabs(h010) > 0.0 &&
2168 cx010 > 9.0e5 && cy010 > 9.0e5 && cz010 > 9.0e5)
return;
2170 double h011 = hx0*hy1*hz1;
2171 if( fabs(h011) > 0.0 &&
2172 cx011 > 9.0e5 && cy011 > 9.0e5 && cz011 > 9.0e5)
return;
2174 double h100 = hx1*hy0*hz0;
2175 if( fabs(h100) > 0.0 &&
2176 cx100 > 9.0e5 && cy100 > 9.0e5 && cz100 > 9.0e5)
return;
2178 double h101 = hx1*hy0*hz1;
2179 if( fabs(h101) > 0.0 &&
2180 cx101 > 9.0e5 && cy101 > 9.0e5 && cz101 > 9.0e5)
return;
2182 double h110 = hx1*hy1*hz0;
2183 if( fabs(h110) > 0.0 &&
2184 cx110 > 9.0e5 && cy110 > 9.0e5 && cz110 > 9.0e5)
return;
2186 double h111 = hx1*hy1*hz1;
2187 if( fabs(h111) > 0.0 &&
2188 cx111 > 9.0e5 && cy111 > 9.0e5 && cz111 > 9.0e5)
return;
2190 bf(0) = ( cx000*h000 + cx001*h001 + cx010*h010 + cx011*h011 +
2191 cx100*h100 + cx101*h101 + cx110*h110 + cx111*h111);
2192 bf(1) = ( cy000*h000 + cy001*h001 + cy010*h010 + cy011*h011 +
2193 cy100*h100 + cy101*h101 + cy110*h110 + cy111*h111 );
2194 bf(2) = ( cz000*h000 + cz001*h001 + cz010*h010 + cz011*h011 +
2195 cz100*h100 + cz101*h101 + cz110*h110 + cz111*h111 );
2202void MagneticFieldSvc::fieldGrid_TE (
const HepPoint3D& r,
2210 double z = r.z() - m_zOffSet_TE;
2211 if( fabs(z) < m_min_FL_TE[2] || fabs(z) > m_max_FL_TE[2] )
return;
2213 if( fabs(x) < m_min_FL_TE[0] || fabs(x) > m_max_FL_TE[0] )
return;
2215 if( fabs(
y) < m_min_FL_TE[1] || fabs(
y) > m_max_FL_TE[1] )
return;
2216 int i = int( (fabs(x)-m_min_FL_TE[0])/m_Dxyz_TE[0]);
2217 int j = int( (fabs(
y)-m_min_FL_TE[1])/m_Dxyz_TE[1] );
2218 int k = int( (fabs(z)-m_min_FL_TE[2])/m_Dxyz_TE[2] );
2220 int ijk000 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j ) + i );
2221 int ijk001 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j ) + i );
2222 int ijk010 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j + 1 ) + i );
2223 int ijk011 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j + 1) + i );
2224 int ijk100 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j) + i + 1 );
2225 int ijk101 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j) + i + 1 );
2226 int ijk110 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*k + j + 1) + i + 1 );
2227 int ijk111 = 3*( m_Nxyz_TE[0]*( m_Nxyz_TE[1]*(k+1) + j + 1 ) + i + 1 );
2241 double cx000 = m_Q_TE[ ijk000 ];
2242 double cx001 = m_Q_TE[ ijk001 ];
2243 double cx010 = m_Q_TE[ ijk010 ];
2244 double cx011 = m_Q_TE[ ijk011 ];
2245 double cx100 = m_Q_TE[ ijk100 ];
2246 double cx101 = m_Q_TE[ ijk101 ];
2247 double cx110 = m_Q_TE[ ijk110 ];
2248 double cx111 = m_Q_TE[ ijk111 ];
2249 double cy000 = m_Q_TE[ ijk000+1 ];
2250 double cy001 = m_Q_TE[ ijk001+1 ];
2251 double cy010 = m_Q_TE[ ijk010+1 ];
2252 double cy011 = m_Q_TE[ ijk011+1 ];
2253 double cy100 = m_Q_TE[ ijk100+1 ];
2254 double cy101 = m_Q_TE[ ijk101+1 ];
2255 double cy110 = m_Q_TE[ ijk110+1 ];
2256 double cy111 = m_Q_TE[ ijk111+1 ];
2257 double cz000 = m_Q_TE[ ijk000+2 ];
2258 double cz001 = m_Q_TE[ ijk001+2 ];
2259 double cz010 = m_Q_TE[ ijk010+2 ];
2260 double cz011 = m_Q_TE[ ijk011+2 ];
2261 double cz100 = m_Q_TE[ ijk100+2 ];
2262 double cz101 = m_Q_TE[ ijk101+2 ];
2263 double cz110 = m_Q_TE[ ijk110+2 ];
2264 double cz111 = m_Q_TE[ ijk111+2 ];
2265 double hx1 = ( fabs(x)-m_min_FL_TE[0]-i*m_Dxyz_TE[0] )/m_Dxyz_TE[0];
2266 double hy1 = ( fabs(
y)-m_min_FL_TE[1]-j*m_Dxyz_TE[1] )/m_Dxyz_TE[1];
2267 double hz1 = ( fabs(z)-m_min_FL_TE[2]-k*m_Dxyz_TE[2] )/m_Dxyz_TE[2];
2268 double hx0 = 1.0-hx1;
2269 double hy0 = 1.0-hy1;
2270 double hz0 = 1.0-hz1;
2271 double h000 = hx0*hy0*hz0;
2272 if( fabs(h000) > 0.0 &&
2273 cx000 > 9.0e5 && cy000 > 9.0e5 && cz000 > 9.0e5)
return;
2275 double h001 = hx0*hy0*hz1;
2276 if( fabs(h001) > 0.0 &&
2277 cx001 > 9.0e5 && cy001 > 9.0e5 && cz001 > 9.0e5)
return;
2279 double h010 = hx0*hy1*hz0;
2280 if( fabs(h010) > 0.0 &&
2281 cx010 > 9.0e5 && cy010 > 9.0e5 && cz010 > 9.0e5)
return;
2283 double h011 = hx0*hy1*hz1;
2284 if( fabs(h011) > 0.0 &&
2285 cx011 > 9.0e5 && cy011 > 9.0e5 && cz011 > 9.0e5)
return;
2287 double h100 = hx1*hy0*hz0;
2288 if( fabs(h100) > 0.0 &&
2289 cx100 > 9.0e5 && cy100 > 9.0e5 && cz100 > 9.0e5)
return;
2291 double h101 = hx1*hy0*hz1;
2292 if( fabs(h101) > 0.0 &&
2293 cx101 > 9.0e5 && cy101 > 9.0e5 && cz101 > 9.0e5)
return;
2295 double h110 = hx1*hy1*hz0;
2296 if( fabs(h110) > 0.0 &&
2297 cx110 > 9.0e5 && cy110 > 9.0e5 && cz110 > 9.0e5)
return;
2299 double h111 = hx1*hy1*hz1;
2300 if( fabs(h111) > 0.0 &&
2301 cx111 > 9.0e5 && cy111 > 9.0e5 && cz111 > 9.0e5)
return;
2303 bf(0) = ( cx000*h000 + cx001*h001 + cx010*h010 + cx011*h011 +
2304 cx100*h100 + cx101*h101 + cx110*h110 + cx111*h111);
2305 bf(1) = ( cy000*h000 + cy001*h001 + cy010*h010 + cy011*h011 +
2306 cy100*h100 + cy101*h101 + cy110*h110 + cy111*h111 );
2307 bf(2) = ( cz000*h000 + cz001*h001 + cz010*h010 + cz011*h011 +
2308 cz100*h100 + cz101*h101 + cz110*h110 + cz111*h111 );
2311 if( r.x() < 0. && r.y() >= 0. && r.z() > 0. ){
2314 else if( r.x() <= 0. && r.y() < 0. && r.z() > 0. ){
2318 else if( r.x() > 0. && r.y() < 0. && r.z() > 0. ){
2322 else if( r.x() >= 0. && r.y() > 0. && r.z() < 0. ){
2326 else if( r.x() < 0. && r.y() >= 0. && r.z() < 0. ){
2329 else if( r.x() <= 0. && r.y() < 0. && r.z() < 0. ){
2333 else if( r.x() > 0. && r.y() <= 0. && r.z() < 0. ){
double sin(const BesAngle a)
double cos(const BesAngle a)
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)
ConnectionDB::eRet getReadSC_MagnetInfo(std::vector< double > ¤t, int runNo)
ConnectionDB::eRet getBeamEnergy(std::vector< double > &beamE, int runNo)
FieldDBUtil::ConnectionDB * m_connect_run
std::map< int, std::vector< double > > m_mapMagnetInfo
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)
std::map< int, std::vector< double > > m_mapBeamEnergy
void handle(const Incident &)
virtual StatusCode uniFieldVector(const HepPoint3D &xyz, HepVector3D &fvec) const
MagneticFieldSvc(const std::string &name, ISvcLocator *svc)
std::vector< double > current
IDataProviderSvc * m_eventSvc
void getMucField(int part, int layer, int mat, HepPoint3D &r, HepVector3D &b)