37 if (!isdigit(str[
ii]) && str[
ii] !=
'.' && str[
ii] !=
'-' && str[
ii] !=
'+') {
39 if (str[ii] ==
'E' || str[ii] ==
'e') {
40 if (numE != 0 || ii == str.length() - 1) {
60 std::cout << msg << std::setprecision(8) << vec;
72 out << msg <<
" xx=" << rm.xx() <<
" xy=" << rm.xy() <<
" xz=" << rm.xz() << std::endl;
73 out << msg <<
" yx=" << rm.yx() <<
" yy=" << rm.yy() <<
" yz=" << rm.yz() << std::endl;
74 out << msg <<
" zx=" << rm.zx() <<
" zy=" << rm.zy() <<
" zz=" << rm.zz() << std::endl;
96 std::cout << _LengthValueDimensionFactor <<
" Set Length DimensionFactors " << _LengthSigmaDimensionFactor
119 std::cout << _AngleValueDimensionFactor <<
"Set Angle DimensionFactors" << _AngleSigmaDimensionFactor << std::endl;
145 std::cout << _OutputLengthValueDimensionFactor <<
"Output Length Dimension Factors"
146 << _OutputLengthSigmaDimensionFactor << std::endl;
172 std::cout << _OutputAngleValueDimensionFactor <<
"Output Angle Dimension Factors"
173 << _OutputAngleSigmaDimensionFactor << std::endl;
182 if (internalDim ==
"m") {
185 }
else if (dimstr ==
"mm") {
187 }
else if (dimstr ==
"mum") {
189 }
else if (dimstr ==
"cm") {
192 std::cerr <<
"!!! UNKNOWN DIMENSION SCALING " << dimstr << std::endl
193 <<
"VALUE MUST BE BETWEEN 0 AND 3 " << std::endl;
196 }
else if (internalDim ==
"mm") {
199 }
else if (dimstr ==
"mm") {
201 }
else if (dimstr ==
"mum") {
203 }
else if (dimstr ==
"cm") {
206 std::cerr <<
"!!! UNKNOWN DIMENSION SCALING: " << dimstr << std::endl
207 <<
"VALUE MUST BE A LENGTH DIMENSION " << std::endl;
220 if (dimstr ==
"rad") {
222 }
else if (dimstr ==
"mrad") {
224 }
else if (dimstr ==
"murad") {
226 }
else if (dimstr ==
"deg") {
227 valsig =
M_PI / 180.;
228 }
else if (dimstr ==
"grad") {
229 valsig =
M_PI / 200.;
231 std::cerr <<
"!!! UNKNOWN DIMENSION SCALING: " << dimstr << std::endl
232 <<
"VALUE MUST BE AN ANGLE DIMENSION " << std::endl;
258 std::cerr <<
"!!! UNKNOWN DIMENSION SCALING " << ad << std::endl <<
"VALUE MUST BE BETWEEN 0 AND 3 " << std::endl;
290 std::cerr <<
"!!! UNKNOWN DIMENSION SCALING " << ad << std::endl <<
"VALUE MUST BE BETWEEN 0 AND 3 " << std::endl;
309 fout <<
"DIMENSIONS: lengths = ";
338 fout <<
" angles = ";
376 std::cerr <<
"!!!! EXITING: trying to get the float from a string that is not a number " << str << std::endl;
380 return atof(str.c_str());
388 std::cerr <<
"!!!! EXITING: trying to get the integer from a string that is not a number " << str << std::endl;
392 bool isFloat =
false;
393 int ch = str.find(
'.');
396 for (ii = ch + 1; ii < str.size(); ii++) {
406 if (str[ch + 1] ==
'-')
411 std::cerr <<
"!!!! EXITING: trying to get the integer from a string that is a float: " << str << std::endl;
412 std::cerr << ii <<
" ii " << ch << std::endl;
416 return int(atof(str.c_str()));
425 if (str ==
"ON" || str ==
"TRUE") {
427 }
else if (str ==
"OFF" || str ==
"FALSE") {
430 std::cerr <<
"!!!! EXITING: trying to get the float from a string that is not 'ON'/'OFF'/'TRUE'/'FALSE' " << str
441 if (str.find(
'"') != 0 || str.rfind(
'"') != str.length() - 1) {
442 std::cerr <<
"!!!EXITING trying to substract quotes from a word that has no quotes " << str << std::endl;
448 ALIstring strt = str.substr(1, str.size() - 2);
452 while (strt[0] ==
' ') {
453 strt = strt.substr(1, strt.size() - 1);
457 while (strt[strt.size() - 1] ==
' ') {
458 strt = strt.substr(0, strt.size() - 1);
466 outs << msg << std::endl;
469 outs << wl[
ii] <<
" ";
479 if (dimType ==
"Length") {
482 }
else if (dim ==
"cm") {
484 }
else if (dim ==
"m") {
486 }
else if (dim ==
"mum") {
488 }
else if (dim ==
"dm") {
490 }
else if (dim ==
"nm") {
493 std::cerr <<
"!!!!FATAL ERROR: ALIUtils::GetDimensionValue. " << dim
494 <<
" is a dimension not supported for dimension type " << dimType << std::endl;
497 }
else if (dimType ==
"Angle") {
500 }
else if (dim ==
"mrad") {
502 }
else if (dim ==
"murad") {
504 }
else if (dim ==
"deg") {
506 }
else if (dim ==
"grad") {
509 std::cerr <<
"!!!!FATAL ERROR: ALIUtils::GetDimensionValue. " << dim
510 <<
" is a dimension not supported for dimension type " << dimType << std::endl;
514 std::cerr <<
"!!!!FATAL ERROR: ALIUtils::GetDimensionValue. " << dimType <<
" is a dimension type not supported "
537 int il = oldName.find(subsstr1);
540 newName = newName.substr(0, il) + subsstr2 + newName.substr(il + subsstr1.length(), newName.length());
542 il = oldName.find(subsstr1, il + 1);
553 double pii = acos(0.) * 2;
554 std::vector<double> newang(3);
555 double angleX = origAngleX;
556 double angleY = origAngleY;
557 double angleZ = origAngleZ;
560 std::cout <<
" angles as value entries: X= " << angleX <<
" Y= " << angleY <<
" Z " << angleZ << std::endl;
569 if (rotzy == 0. && rotzz == 0.) {
573 if (
eq2ang(rmLocal.zx(), -1.)) {
574 double aa = asin(rmLocal.xy());
575 if (
diff2pi(angleZ, -aa + newang[0]) <
diff2pi(angleZ, -pii + aa + newang[0])) {
576 newang[2] = -aa + newang[0];
578 std::cout <<
" newang[0] = -aa + newang[0] " << std::endl;
580 newang[2] = -pii + aa + newang[0];
582 std::cout <<
" newang[0] = -pii + aa + newang[0] " << newang[0] <<
" " << aa <<
" " << newang[2] << std::endl;
585 double aa = asin(-rmLocal.xy());
586 if (
diff2pi(angleZ, aa - newang[0]) <
diff2pi(angleZ, pii - aa - newang[0])) {
587 newang[2] = aa - newang[0];
589 std::cout <<
" newang[0] = aa - newang[2] " << std::endl;
591 newang[2] = pii - aa - newang[0];
593 std::cout <<
" newang[0] = pii - aa - newang[2] " << newang[0] <<
" " << aa <<
" " << newang[2] << std::endl;
597 newang[0] = atan(rotzy / rotzz);
598 newang[2] = atan(rotyx / rotxx);
603 }
else if (rotzx > 1.) {
607 newang[1] = -asin(rotzx);
609 std::cout <<
"First calculation of angles: " << std::endl
610 <<
" newang[0] " << newang[0] <<
" " << rotzy <<
" " << rotzz << std::endl
611 <<
" newang[1] " << newang[1] <<
" " << rotzx << std::endl
612 <<
" newang[2] " << newang[2] <<
" " << rotyx <<
" " << rotxx << std::endl;
617 double rotnewxx =
cos(newang[1]) *
cos(newang[2]);
618 double rotnewzz =
cos(newang[0]) *
cos(newang[1]);
619 double rotnewxy =
sin(newang[0]) *
sin(newang[1]) *
cos(newang[2]) -
cos(newang[0]) *
sin(newang[2]);
620 double rotnewxz =
cos(newang[0]) *
sin(newang[1]) *
cos(newang[2]) +
sin(newang[0]) *
sin(newang[2]);
621 double rotnewyy =
sin(newang[0]) *
sin(newang[1]) *
sin(newang[2]) +
cos(newang[0]) *
cos(newang[2]);
622 double rotnewyz =
cos(newang[0]) *
sin(newang[1]) *
sin(newang[2]) -
sin(newang[0]) *
cos(newang[2]);
624 bool eqxx =
eq2ang(rotnewxx, rmLocal.xx());
625 bool eqzz =
eq2ang(rotnewzz, rmLocal.zz());
626 bool eqxy =
eq2ang(rotnewxy, rmLocal.xy());
627 bool eqxz =
eq2ang(rotnewxz, rmLocal.xz());
628 bool eqyy =
eq2ang(rotnewyy, rmLocal.yy());
629 bool eqyz =
eq2ang(rotnewyz, rmLocal.yz());
633 std::cout <<
" pred rm.xx " << rotnewxx <<
" =? " << rmLocal.xx() <<
" pred rm.zz " << rotnewzz <<
" =? "
634 << rmLocal.zz() << std::endl;
635 std::cout <<
" eqxx " << eqxx <<
" eqzz " << eqzz << std::endl;
640 newang[0] = pii + newang[0];
642 std::cout <<
" change newang[0] " << newang[0] << std::endl;
643 }
else if (!eqxx & !eqzz) {
644 newang[1] = pii - newang[1];
646 std::cout <<
" change newang[1] " << newang[1] << std::endl;
647 }
else if (!eqxx & eqzz) {
648 newang[2] = pii + newang[2];
650 std::cout <<
" change newang[2] " << newang[2] << std::endl;
655 std::cout <<
" pred rm.xy " << rotnewxy <<
" =? " << rmLocal.xy() <<
" pred rm.xz " << rotnewxz <<
" =? "
656 << rmLocal.xz() <<
" pred rm.yy " << rotnewyy <<
" =? " << rmLocal.yy() <<
" pred rm.yz " << rotnewyz
657 <<
" =? " << rmLocal.yz() << std::endl;
658 std::cout <<
" eqxy " << eqxy <<
" eqxz " << eqxz <<
" eqyy " << eqyy <<
" eqyz " << eqyz << std::endl;
661 if (!eqxy || !eqxz || !eqyy || !eqyz) {
664 std::cout <<
" change the 3 newang " << std::endl;
665 newang[0] =
addPii(newang[0]);
666 newang[1] = pii - newang[1];
667 newang[2] =
addPii(newang[2]);
668 double rotnewxy = -
sin(newang[0]) *
sin(newang[1]) *
cos(newang[2]) -
cos(newang[0]) *
sin(newang[2]);
669 double rotnewxz = -
cos(newang[0]) *
sin(newang[1]) *
cos(newang[2]) -
sin(newang[0]) *
sin(newang[2]);
671 std::cout <<
" rotnewxy " << rotnewxy <<
" = " << rmLocal.xy() <<
" rotnewxz " << rotnewxz <<
" = "
672 << rmLocal.xz() << std::endl;
675 diff2pi(angleX, pii + newang[0]) +
diff2pi(angleY, pii - newang[1]) +
diff2pi(angleZ, pii + newang[2])) {
678 std::cout <<
" change the 3 newang " << std::endl;
679 newang[0] =
addPii(newang[0]);
680 newang[1] = pii - newang[1];
681 newang[2] =
addPii(newang[2]);
682 double rotnewxy = -
sin(newang[0]) *
sin(newang[1]) *
cos(newang[2]) -
cos(newang[0]) *
sin(newang[2]);
683 double rotnewxz = -
cos(newang[0]) *
sin(newang[1]) *
cos(newang[2]) -
sin(newang[0]) *
sin(newang[2]);
685 std::cout <<
" rotnewxy " << rotnewxy <<
" = " << rmLocal.xy() <<
" rotnewxz " << rotnewxz <<
" = "
686 << rmLocal.xz() << std::endl;
689 for (
int ii = 0;
ii < 3;
ii++) {
695 std::cerr <<
" wrong rotation matrix " << newang[0] <<
" " << newang[1] <<
" " << newang[2] << std::endl;
699 std::cout <<
"Final angles: newang[0] " << newang[0] <<
" newang[1] " << newang[1] <<
" newang[2] " << newang[2]
701 CLHEP::HepRotation
rot;
702 rot.rotateX(newang[0]);
704 rot.rotateY(newang[1]);
706 rot.rotateZ(newang[2]);
718 double pii = acos(0.) * 2;
719 double diff = fabs(ang1 - ang2);
720 diff = diff - int(diff / 2. / pii) * 2 * pii;
728 double pii = acos(0.) * 2;
730 if (diff > 0.00001) {
731 if (fabs(diff - 2 * pii) > 0.00001) {
744 double precision = 1.e-9;
745 if (fabs(val) < precision)
763 double sx =
sin(angleX);
764 double cx =
cos(angleX);
765 double sy =
sin(angleY);
766 double cy =
cos(angleY);
767 double sz =
sin(angleZ);
768 double cz =
cos(angleZ);
770 double rotxx = cy * cz;
771 double rotxy = sx * sy * cz - cx * sz;
772 double rotxz = cx * sy * cz + sx * sz;
773 double rotyx = cy * sz;
774 double rotyy = sx * sy * sz + cx * cz;
775 double rotyz = cx * sy * sz - sx * cz;
777 double rotzy = sx * cy;
778 double rotzz = cx * cy;
780 int matrixElemBad = 0;
783 !
eq2ang(rot.zz(), rotzz)) {
787 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)
static std::vector< double > getRotationAnglesFromMatrix(const CLHEP::HepRotation &rmLocal, double origAngleX, double origAngleY, double origAngleZ)
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 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 int checkMatrixEquations(double angleX, double angleY, double angleZ, const CLHEP::HepRotation &rot)
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)
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
static ALIdouble _OutputAngleValueDimensionFactor
static int getInt(const ALIstring &str)
Convert a string to an integer, checking that it is really an integer.
ALIdouble getGlobalOption(const ALIstring &sstr)
static ALIdouble _OutputLengthSigmaDimensionFactor
static void dumpDimensions(std::ofstream &fout)
static ALIstring subQuotes(const ALIstring &str)
static ALIdouble _LengthValueDimensionFactor
static ALIdouble CalculateAngleDimensionFactorFromInt(ALIint ad)