39 if(!isdigit(str[
ii]) && str[
ii]!=
'.' && str[
ii]!=
'-' && str[
ii]!=
'+') {
41 if(str[ii] ==
'E' || str[ii] ==
'e' ) {
42 if(numE != 0 || ii == str.length()-1) {
64 std::cout << msg << std::setprecision(8) << vec;
80 out << msg <<
" xx=" << rm.xx() <<
" xy=" << rm.xy() <<
" xz=" << rm.xz() << std::endl;
81 out << msg <<
" yx=" << rm.yx() <<
" yy=" << rm.yy() <<
" yz=" << rm.yz() << std::endl;
82 out << msg <<
" zx=" << rm.zx() <<
" zy=" << rm.zy() <<
" zz=" << rm.zz() << std::endl;
107 if(
ALIUtils::debug >= 6)
std::cout << _LengthValueDimensionFactor <<
" Set Length DimensionFactors " << _LengthSigmaDimensionFactor << std::endl;
132 if(
ALIUtils::debug >= 6)
std::cout << _AngleValueDimensionFactor <<
"Set Angle DimensionFactors" << _AngleSigmaDimensionFactor << std::endl;
160 if(
ALIUtils::debug >= 6)
std::cout << _OutputLengthValueDimensionFactor <<
"Output Length Dimension Factors" << _OutputLengthSigmaDimensionFactor << std::endl;
187 if(
ALIUtils::debug >= 9)
std::cout << _OutputAngleValueDimensionFactor <<
"Output Angle Dimension Factors" << _OutputAngleSigmaDimensionFactor << std::endl;
200 if(internalDim ==
"m" ){
201 if( dimstr ==
"m" ) {
203 }
else if( dimstr ==
"mm" ) {
205 }
else if( dimstr ==
"mum" ) {
207 }
else if( dimstr ==
"cm" ) {
210 std::cerr <<
"!!! UNKNOWN DIMENSION SCALING " << dimstr << std::endl <<
211 "VALUE MUST BE BETWEEN 0 AND 3 " << std::endl;
214 }
else if(internalDim ==
"mm" ){
215 if( dimstr ==
"m" ) {
217 }
else if( dimstr ==
"mm" ) {
219 }
else if( dimstr ==
"mum" ) {
221 }
else if( dimstr ==
"cm" ) {
224 std::cerr <<
"!!! UNKNOWN DIMENSION SCALING: " << dimstr << std::endl <<
225 "VALUE MUST BE A LENGTH DIMENSION " << std::endl;
240 if( dimstr ==
"rad" ) {
243 if( dimstr ==
"mrad" ) {
246 if( dimstr ==
"murad" ) {
249 if( dimstr ==
"deg" ) {
252 if( dimstr ==
"grad" ) {
255 std::cerr <<
"!!! UNKNOWN DIMENSION SCALING: " << dimstr << std::endl <<
256 "VALUE MUST BE AN ANGLE DIMENSION " << std::endl;
283 std::cerr <<
"!!! UNKNOWN DIMENSION SCALING " << ad << std::endl <<
284 "VALUE MUST BE BETWEEN 0 AND 3 " << std::endl;
318 std::cerr <<
"!!! UNKNOWN DIMENSION SCALING " << ad << std::endl <<
319 "VALUE MUST BE BETWEEN 0 AND 3 " << std::endl;
339 fout <<
"DIMENSIONS: lengths = ";
368 fout <<
" angles = ";
408 std::cerr <<
"!!!! EXITING: trying to get the float from a string that is not a number " << str << std::endl;
412 return atof( str.c_str() );
422 std::cerr <<
"!!!! EXITING: trying to get the integer from a string that is not a number " << str << std::endl;
426 bool isFloat =
false;
427 int ch = str.find(
'.');
430 for( ii = ch+1; ii < str.size(); ii++) {
431 if( str[ii] !=
'0' ) isFloat =
true;
436 if(ch != -1 ) ch = str.find(
'e');
438 if(str[ch+1] ==
'-') isFloat =
true;
442 std::cerr <<
"!!!! EXITING: trying to get the integer from a string that is a float: " << str << std::endl;
443 std::cerr << ii <<
" ii " << ch <<std::endl;
447 return int( atof( str.c_str() ) );
459 if( str ==
"ON" || str ==
"TRUE" ) {
461 }
else if( str ==
"OFF" || str ==
"FALSE" ) {
464 std::cerr <<
"!!!! EXITING: trying to get the float from a string that is not 'ON'/'OFF'/'TRUE'/'FALSE' " << str << std::endl;
476 if( str.find(
'"') != 0 || str.rfind(
'"') != str.length()-1 ) {
477 std::cerr <<
"!!!EXITING trying to substract quotes from a word that has no quotes " << str << std::endl;
483 ALIstring strt = str.substr(1,str.size()-2);
487 while( strt[0] ==
' ' ) {
488 strt = strt.substr(1,strt.size()-1);
492 while( strt[strt.size()-1] ==
' ' ) {
493 strt = strt.substr(0,strt.size()-1);
503 outs << msg << std::endl;
506 outs << wl[
ii] <<
" ";
518 if( dimType ==
"Length" ) {
521 }
else if( dim ==
"cm" ) {
523 }
else if( dim ==
"m" ) {
525 }
else if( dim ==
"mum" ) {
527 }
else if( dim ==
"dm" ) {
529 }
else if( dim ==
"nm" ) {
532 std::cerr <<
"!!!!FATAL ERROR: ALIUtils::GetDimensionValue. " << dim <<
" is a dimension not supported for dimension type " << dimType << std::endl;
535 }
else if( dimType ==
"Angle" ) {
538 }
else if( dim ==
"mrad" ) {
540 }
else if( dim ==
"murad" ) {
542 }
else if( dim ==
"deg" ) {
544 }
else if( dim ==
"grad" ) {
547 std::cerr <<
"!!!!FATAL ERROR: ALIUtils::GetDimensionValue. " << dim <<
" is a dimension not supported for dimension type " << dimType << std::endl;
551 std::cerr <<
"!!!!FATAL ERROR: ALIUtils::GetDimensionValue. " << dimType <<
" is a dimension type not supported " << std::endl;
577 int il = oldName.find( subsstr1 );
580 newName = newName.substr( 0, il ) + subsstr2 + newName.substr( il+subsstr1.length(), newName.length() );
582 il = oldName.find( subsstr1, il+1 );
593 double pii = acos(0.)*2;
594 std::vector<double> newang(3);
595 double angleX = origAngleX;
596 double angleY = origAngleY;
597 double angleZ = origAngleZ;
600 std::cout <<
" angles as value entries: X= " << angleX <<
" Y= " << angleY <<
" Z " << angleZ << std::endl;
604 double rotzx =
approxTo0( rmLocal.zx() );
605 double rotzy =
approxTo0( rmLocal.zy() );
606 double rotzz =
approxTo0( rmLocal.zz() );
607 double rotyx =
approxTo0( rmLocal.yx() );
608 double rotxx =
approxTo0( rmLocal.xx() );
609 if( rotzy == 0. && rotzz == 0. ) {
613 if(
eq2ang( rmLocal.zx(), -1. ) ) {
614 double aa = asin( rmLocal.xy() );
615 if(
diff2pi( angleZ, - aa + newang[0] ) <
diff2pi( angleZ, - pii + aa + newang[0] ) ) {
616 newang[2] = -aa + newang[0];
619 newang[2] = -pii + aa + newang[0];
620 if(
ALIUtils::debug >= 5 )
std::cout <<
" newang[0] = -pii + aa + newang[0] " << newang[0] <<
" " << aa <<
" " << newang[2] << std::endl;
623 double aa = asin( -rmLocal.xy() );
624 if(
diff2pi( angleZ, aa - newang[0] ) <
diff2pi( angleZ, pii - aa - newang[0] ) ) {
625 newang[2] = aa - newang[0];
628 newang[2] = pii - aa - newang[0];
629 if(
ALIUtils::debug >= 5 )
std::cout <<
" newang[0] = pii - aa - newang[2] " << newang[0] <<
" " << aa <<
" " << newang[2] << std::endl;
633 newang[0] = atan( rotzy / rotzz );
634 newang[2] = atan( rotyx / rotxx );
639 }
else if( rotzx > 1. ) {
643 newang[1] = -asin( rotzx );
645 <<
" newang[0] " << newang[0] <<
" " << rotzy <<
" " << rotzz << std::endl
646 <<
" newang[1] " << newang[1] <<
" " << rotzx << std::endl
647 <<
" newang[2] " << newang[2] <<
" " << rotyx <<
" " << rotxx << std::endl;
652 double rotnewxx =
cos( newang[1] ) *
cos( newang[2] );
653 double rotnewzz =
cos( newang[0] ) *
cos( newang[1] );
654 double rotnewxy =
sin( newang[0] ) *
sin( newang[1] ) *
cos( newang[2] ) -
cos( newang[0] )*
sin( newang[2] );
655 double rotnewxz =
cos( newang[0] ) *
sin( newang[1] ) *
cos( newang[2] ) +
sin( newang[0] )*
sin( newang[2] );
656 double rotnewyy =
sin( newang[0] ) *
sin( newang[1] ) *
sin( newang[2] ) +
cos( newang[0] )*
cos( newang[2] );
657 double rotnewyz =
cos( newang[0] ) *
sin( newang[1] ) *
sin( newang[2] ) -
sin( newang[0] )*
cos( newang[2] );
659 bool eqxx =
eq2ang( rotnewxx, rmLocal.xx() );
660 bool eqzz =
eq2ang( rotnewzz, rmLocal.zz() );
661 bool eqxy =
eq2ang( rotnewxy, rmLocal.xy() );
662 bool eqxz =
eq2ang( rotnewxz, rmLocal.xz() );
663 bool eqyy =
eq2ang( rotnewyy, rmLocal.yy() );
664 bool eqyz =
eq2ang( rotnewyz, rmLocal.yz() );
668 std::cout <<
" pred rm.xx " << rotnewxx <<
" =? " << rmLocal.xx()
669 <<
" pred rm.zz " << rotnewzz <<
" =? " << rmLocal.zz()
671 std::cout <<
" eqxx " << eqxx <<
" eqzz " << eqzz << std::endl;
676 newang[0] = pii + newang[0];
678 }
else if( !eqxx & !eqzz ) {
679 newang[1] = pii - newang[1];
681 }
else if( !eqxx & eqzz ) {
682 newang[2] = pii + newang[2];
688 std::cout <<
" pred rm.xy " << rotnewxy <<
" =? " << rmLocal.xy()
689 <<
" pred rm.xz " << rotnewxz <<
" =? " << rmLocal.xz()
690 <<
" pred rm.yy " << rotnewyy <<
" =? " << rmLocal.yy()
691 <<
" pred rm.yz " << rotnewyz <<
" =? " << rmLocal.yz()
693 std::cout <<
" eqxy " << eqxy <<
" eqxz " << eqxz <<
" eqyy " << eqyy <<
" eqyz " << eqyz << std::endl;
696 if( !eqxy || !eqxz || !eqyy || !eqyz ) {
699 newang[0] =
addPii( newang[0] );
700 newang[1] = pii - newang[1];
701 newang[2] =
addPii( newang[2] );
702 double rotnewxy = -
sin( newang[0] ) *
sin( newang[1] ) *
cos( newang[2] ) -
cos( newang[0] )*
sin( newang[2] );
703 double rotnewxz = -
cos( newang[0] ) *
sin( newang[1] ) *
cos( newang[2] ) -
sin( newang[0] )*
sin( newang[2] );
705 <<
" rotnewxz " << rotnewxz <<
" = " << rmLocal.xz() << std::endl;
708 >
diff2pi(angleX, pii+newang[0] ) +
diff2pi(angleY, pii-newang[1] ) +
diff2pi(angleZ, pii+newang[2] ) ){
711 newang[0] =
addPii( newang[0] );
712 newang[1] = pii - newang[1];
713 newang[2] =
addPii( newang[2] );
714 double rotnewxy = -
sin( newang[0] ) *
sin( newang[1] ) *
cos( newang[2] ) -
cos( newang[0] )*
sin( newang[2] );
715 double rotnewxz = -
cos( newang[0] ) *
sin( newang[1] ) *
cos( newang[2] ) -
sin( newang[0] )*
sin( newang[2] );
717 <<
" rotnewxz " << rotnewxz <<
" = " << rmLocal.xz() << std::endl;
720 for (
int ii=0;
ii<3;
ii++) {
726 std::cerr <<
" wrong rotation matrix " << newang[0] <<
" " << newang[1] <<
" " << newang[2] << std::endl;
730 std::cout <<
"Final angles: newang[0] " << newang[0] <<
" newang[1] " << newang[1] <<
" newang[2] " << newang[2] << std::endl;
731 CLHEP::HepRotation
rot;
732 rot.rotateX( newang[0] );
734 rot.rotateY( newang[1] );
736 rot.rotateZ( newang[2] );
750 double pii = acos(0.)*2;
751 double diff = fabs( ang1 - ang2 );
752 diff = diff -
int(diff/2./pii) * 2 *pii;
762 double pii = acos(0.)*2;
764 if( diff > 0.00001 ) {
765 if( fabs( diff - 2*pii ) > 0.00001 ) {
781 if( fabs(val) < precision ) val = 0;
802 if( rot ==
nullptr ) {
803 rot =
new CLHEP::HepRotation();
804 rot->rotateX( angleX );
805 rot->rotateY( angleY );
806 rot->rotateZ( angleZ );
808 double sx =
sin(angleX);
809 double cx =
cos(angleX);
810 double sy =
sin(angleY);
811 double cy =
cos(angleY);
812 double sz =
sin(angleZ);
813 double cz =
cos(angleZ);
815 double rotxx = cy*cz;
816 double rotxy = sx*sy*cz-cx*sz;
817 double rotxz = cx*sy*cz+sx*sz;
818 double rotyx = cy*sz;
819 double rotyy = sx*sy*sz+cx*cz;
820 double rotyz = cx*sy*sz-sx*cz;
822 double rotzy = sx*cy;
823 double rotzz = cx*cy;
825 int matrixElemBad = 0;
826 if( !
eq2ang( rot->xx(), rotxx ) ) {
827 std::cerr <<
" EQUATION for xx() IS BAD " << rot->xx() <<
" <> " << rotxx << std::endl;
830 if( !
eq2ang( rot->xy(), rotxy ) ) {
831 std::cerr <<
" EQUATION for xy() IS BAD " << rot->xy() <<
" <> " << rotxy << std::endl;
834 if( !
eq2ang( rot->xz(), rotxz ) ) {
835 std::cerr <<
" EQUATION for xz() IS BAD " << rot->xz() <<
" <> " << rotxz << std::endl;
838 if( !
eq2ang( rot->yx(), rotyx ) ) {
839 std::cerr <<
" EQUATION for yx() IS BAD " << rot->yx() <<
" <> " << rotyx << std::endl;
842 if( !
eq2ang( rot->yy(), rotyy ) ) {
843 std::cerr <<
" EQUATION for yy() IS BAD " << rot->yy() <<
" <> " << rotyy << std::endl;
846 if( !
eq2ang( rot->yz(), rotyz ) ) {
847 std::cerr <<
" EQUATION for yz() IS BAD " << rot->yz() <<
" <> " << rotyz << std::endl;
850 if( !
eq2ang( rot->zx(), rotzx ) ) {
851 std::cerr <<
" EQUATION for zx() IS BAD " << rot->zx() <<
" <> " << rotzx << std::endl;
854 if( !
eq2ang( rot->zy(), rotzy ) ) {
855 std::cerr <<
" EQUATION for zy() IS BAD " << rot->zy() <<
" <> " << rotzy << std::endl;
858 if( !
eq2ang( rot->zz(), rotzz ) ) {
859 std::cerr <<
" EQUATION for zz() IS BAD " << rot->zz() <<
" <> " << rotzz << std::endl;
864 return matrixElemBad;
static ALIdouble maximum_deviation_derivative
static ALIdouble _OutputLengthValueDimensionFactor
static double approxTo0(double val)
static double diff2pi(double ang1, double ang2)
static bool eq2ang(double ang1, double ang2)
Sin< T >::type sin(const T &t)
static void dumprm(const CLHEP::HepRotation &rm, const std::string &msg, std::ostream &out=std::cout)
static void SetOutputLengthDimensionFactors()
static ALIdouble _AngleValueDimensionFactor
static double addPii(double val)
static GlobalOptionMgr * getInstance()
static int checkMatrixEquations(double angleX, double angleY, double angleZ, CLHEP::HepRotation *rot)
static double getFloat(const ALIstring &str)
Convert a string to an float, checking that it is really a number.
static bool getBool(const ALIstring &str)
Convert a bool to an integer, checking that it is really a bool.
static ALIdouble _OutputAngleSigmaDimensionFactor
static ALIdouble _AngleSigmaDimensionFactor
static ALIdouble CalculateAngleDimensionFactorFromString(ALIstring dimstr)
static ALIdouble CalculateLengthDimensionFactorFromInt(ALIint ad)
static int IsNumber(const ALIstring &str)
Cos< T >::type cos(const T &t)
static ALIdouble CalculateLengthDimensionFactorFromString(ALIstring dimstr)
static void SetAngleDimensionFactors()
static void SetOutputAngleDimensionFactors()
static void dump3v(const CLHEP::Hep3Vector &vec, const std::string &msg)
static void SetLengthDimensionFactors()
static std::string changeName(const std::string &oldName, const std::string &subsstr1, const std::string &subsstr2)
static ALIdouble _LengthSigmaDimensionFactor
static void dumpVS(const std::vector< ALIstring > &wl, const std::string &msg, std::ostream &outs=std::cout)
dumps a vector of strings with a message to outs
static ALIdouble getDimensionValue(const ALIstring &dim, const ALIstring &dimType)
static ALIdouble _OutputAngleValueDimensionFactor
static std::vector< double > getRotationAnglesFromMatrix(CLHEP::HepRotation &rmLocal, double origAngleX, double origAngleY, double origAngleZ)
static int getInt(const ALIstring &str)
Convert a string to an integer, checking that it is really an integer.
ALIdouble getGlobalOption(const ALIstring &sstr)
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
static ALIdouble _OutputLengthSigmaDimensionFactor
static void dumpDimensions(std::ofstream &fout)
static ALIstring subQuotes(const ALIstring &str)
static ALIdouble _LengthValueDimensionFactor
static ALIdouble CalculateAngleDimensionFactorFromInt(ALIint ad)