00001 #ifndef DD_CLHEPToROOTMath_h 00002 #define DD_CLHEPToROOTMath_h 00003 #include <iostream> 00004 #include <fstream> 00005 #include <iomanip> 00006 00007 #include "DetectorDescription/Core/interface/DDTransform.h" 00008 #include "DetectorDescription/Base/interface/DDTranslation.h" 00009 #include "DetectorDescription/Base/interface/DDRotationMatrix.h" 00010 #include "CLHEP/Vector/Rotation.h" 00011 #include "CLHEP/Vector/ThreeVector.h" 00012 #include "CLHEP/Units/GlobalSystemOfUnits.h" 00013 00015 00016 class HepRotOutput { 00017 public: 00018 HepRotOutput() { } 00019 ~HepRotOutput() { } 00020 void operator() ( const CLHEP::HepRotation& r ) { 00021 std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << r.xx(); 00022 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.xy(); 00023 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.xz() << " ]" << std::endl; 00024 std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << r.yx(); 00025 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.yy(); 00026 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.yz() << " ]" << std::endl; 00027 std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << r.zx(); 00028 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.zy(); 00029 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.zz() << " ]" << std::endl; 00030 } 00031 }; 00032 00033 00034 /* void hepSetAxes( CLHEP::Hep3Vector& x, CLHEP::Hep3Vector& y, CLHEP::Hep3Vector& z */ 00035 /* , double thetaX, double phiX */ 00036 /* , double thetaY, double phiY */ 00037 /* , double thetaZ, double phiZ ) { */ 00038 /* x[0] = sin(thetaX) * cos(phiX); */ 00039 /* x[1] = sin(thetaX) * sin(phiX); */ 00040 /* x[2] = cos(thetaX); */ 00041 /* y[0] = sin(thetaY) * cos(phiY); */ 00042 /* y[1] = sin(thetaY) * sin(phiY); */ 00043 /* y[2] = cos(thetaY); */ 00044 /* z[0] = sin(thetaZ) * cos(phiZ); */ 00045 /* z[1] = sin(thetaZ) * sin(phiZ); */ 00046 /* z[2] = cos(thetaZ); */ 00047 /* } */ 00048 00049 /* void hepOutVecs( const CLHEP::Hep3Vector& x, const CLHEP::Hep3Vector& y, const CLHEP::Hep3Vector& z ) { */ 00050 /* std::cout << "Vectors used in construction:" << std::endl; */ 00051 /* std::cout << "x vector = " << std::setw(12) << std::fixed << std::setprecision(5) << x[0] */ 00052 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << y[0] */ 00053 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << z[0] << std::endl; */ 00054 /* std::cout << "y vector = " << std::setw(12) << std::fixed << std::setprecision(5) << x[1] */ 00055 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << y[1] */ 00056 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << z[1] << std::endl; */ 00057 /* std::cout << "z vector = " << std::setw(12) << std::fixed << std::setprecision(5) << x[2] */ 00058 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << y[2] */ 00059 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << z[2] << std::endl; */ 00060 /* } */ 00061 00062 class DDRotOutput { 00063 public: 00064 DDRotOutput() { } 00065 ~DDRotOutput() { } 00066 void operator() ( const DDRotationMatrix& r ) { 00067 double xx, xy, xz, yx, yy, yz, zx, zy, zz; 00068 r.GetComponents(xx, xy, xz, yx, yy, yz, zx, zy, zz); 00069 std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << xx; 00070 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << xy; 00071 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << xz << " ]" << std::endl; 00072 std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << yx; 00073 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << yy; 00074 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << yz << " ]" << std::endl; 00075 std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << zx; 00076 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << zy; 00077 std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << zz << " ]"<< std::endl; 00078 } 00079 }; 00080 00081 /* void ddSetAxes ( DD3Vector& x, DD3Vector& y, DD3Vector& z */ 00082 /* , double thetaX, double phiX */ 00083 /* , double thetaY, double phiY */ 00084 /* , double thetaZ, double phiZ ) { */ 00085 /* x.SetX(sin(thetaX) * cos(phiX)); */ 00086 /* x.SetY(sin(thetaX) * sin(phiX)); */ 00087 /* x.SetZ(cos(thetaX)); */ 00088 /* y.SetX(sin(thetaY) * cos(phiY)); */ 00089 /* y.SetY(sin(thetaY) * sin(phiY)); */ 00090 /* y.SetZ(cos(thetaY)); */ 00091 /* z.SetX(sin(thetaZ) * cos(phiZ)); */ 00092 /* z.SetY(sin(thetaZ) * sin(phiZ)); */ 00093 /* z.SetZ(cos(thetaZ)); */ 00094 /* } */ 00095 00096 /* void ddOutVecs( const DD3Vector& x, const DD3Vector& y, const DD3Vector& z ) { */ 00097 /* std::cout << "Vectors used in construction:" << std::endl; */ 00098 /* std::cout << "x vector = " << std::setw(12) << std::fixed << std::setprecision(5) << x.X() */ 00099 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << x.Y() */ 00100 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << x.Z() << std::endl; */ 00101 /* std::cout << "y vector = " << std::setw(12) << std::fixed << std::setprecision(5) << y.X() */ 00102 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << y.Y() */ 00103 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << y.Z() << std::endl; */ 00104 /* std::cout << "z vector = " << std::setw(12) << std::fixed << std::setprecision(5) << z.X() */ 00105 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << z.Y() */ 00106 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) <<z.Z() << std::endl; */ 00107 /* } */ 00108 00109 00110 /* void checkNorm ( double check ) { */ 00111 /* double tol = 1.0e-3; */ 00112 /* if (1.0-std::abs(check)>tol) { */ 00113 /* std::cout << "NOT orthonormal!" << std::endl; */ 00114 /* } else if (1.0+check<=tol) { */ 00115 /* std::cout << "IS Left-handed (reflection)" << std::endl; */ 00116 /* } else { */ 00117 /* std::cout << "IS Right-handed (proper)" << std::endl; */ 00118 /* } */ 00119 00120 /* } */ 00121 00122 /* int main(int argc, char *argv[]) { */ 00123 /* std::cout << "====================== CLHEP: ========================" << std::endl; */ 00124 /* // Examples from DD XML */ 00125 /* // <ReflectionRotation name="180R" thetaX="90*deg" phiX="0*deg" thetaY="90*deg" phiY="90*deg" thetaZ="180*deg" phiZ="0*deg" /> */ 00126 /* { */ 00127 /* CLHEP::Hep3Vector x,y,z; */ 00128 /* hepSetAxes ( x, y, z, 90*deg, 0*deg, 90*deg, 90*deg, 180*deg, 0*deg ); */ 00129 /* CLHEP::HepRotation R; */ 00130 /* R.rotateAxes(x, y, z); */ 00131 /* CLHEP::HepRotation ddr(R); */ 00132 /* std::cout << " *** REFLECTION *** " << std::endl; */ 00133 /* checkNorm((x.cross(y))*z); */ 00134 /* hepOutVecs (x, y, z); */ 00135 /* std::cout << "Matrix output built up from vectors:" << std::endl; */ 00136 /* hrmOut(ddr); */ 00137 /* std::cout << "Matrix build from CLHEP::HepRep3x3 to preserve left-handedness:" << std::endl; */ 00138 /* CLHEP::HepRep3x3 temp(x.x(),y.x(),z.x(), */ 00139 /* x.y(),y.y(),z.y(), */ 00140 /* x.z(),y.z(),z.z()); //matrix representation */ 00141 /* CLHEP::HepRotation ddr2(temp); */ 00142 /* hrmOut(ddr2); */ 00143 /* } */ 00144 /* // <Rotation name="RM1509" thetaX="90*deg" phiX="-51.39999*deg" thetaY="90*deg" phiY="38.60001*deg" thetaZ="0*deg" phiZ="0*deg" /> */ 00145 /* { */ 00146 /* CLHEP::Hep3Vector x,y,z; */ 00147 /* hepSetAxes ( x, y, z, 90*deg, -51.39999*deg, 90*deg, 38.60001*deg, 0*deg, 0*deg ); */ 00148 /* CLHEP::HepRotation R; */ 00149 /* R.rotateAxes(x, y, z); */ 00150 /* CLHEP::HepRotation ddr(R); */ 00151 /* std::cout << " *** ROTATION *** " << std::endl; */ 00152 /* checkNorm((x.cross(y))*z); */ 00153 /* hepOutVecs (x, y, z); */ 00154 /* std::cout << "Matrix output built up from vectors:" << std::endl; */ 00155 /* hrmOut(ddr); */ 00156 /* std::cout << "Matrix build from CLHEP::HepRep3x3 to preserve left-handedness:" << std::endl; */ 00157 /* CLHEP::HepRep3x3 temp(x.x(),y.x(),z.x(), */ 00158 /* x.y(),y.y(),z.y(), */ 00159 /* x.z(),y.z(),z.z()); //matrix representation */ 00160 /* CLHEP::HepRotation ddr2(temp); */ 00161 /* hrmOut(ddr2); */ 00162 /* } */ 00163 00164 /* std::cout << "====================== ROOT::Math ========================" << std::endl; */ 00165 /* // <ReflectionRotation name="180R" thetaX="90*deg" phiX="0*deg" thetaY="90*deg" phiY="90*deg" thetaZ="180*deg" phiZ="0*deg" /> */ 00166 /* { */ 00167 /* DD3Vector x,y,z; */ 00168 /* ddSetAxes ( x, y, z, 90*deg, 0*deg, 90*deg, 90*deg, 180*deg, 0*deg ); */ 00169 /* DDRotationMatrix R(x, y, z); */ 00170 /* std::cout << " *** REFLECTION *** " << std::endl; */ 00171 /* checkNorm((x.Cross(y)).Dot(z)); */ 00172 /* ddOutVecs (x, y, z); */ 00173 /* std::cout << "Matrix output built up from vectors:" << std::endl; */ 00174 /* ddRotOut(R); */ 00175 /* std::cout << "Matrix built to preserve left-handedness:" << std::endl; */ 00176 /* DDRotationMatrix temp(x.x(),y.x(),z.x(), */ 00177 /* x.y(),y.y(),z.y(), */ 00178 /* x.z(),y.z(),z.z()); //matrix representation */ 00179 /* ddRotOut(temp); */ 00180 /* } */ 00181 /* // <Rotation name="RM1509" thetaX="90*deg" phiX="-51.39999*deg" thetaY="90*deg" phiY="38.60001*deg" thetaZ="0*deg" phiZ="0*deg" /> */ 00182 /* { */ 00183 /* DD3Vector x,y,z; */ 00184 /* ddSetAxes ( x, y, z, 90*deg, -51.39999*deg, 90*deg, 38.60001*deg, 0*deg, 0*deg ); */ 00185 /* DDRotationMatrix R(x, y, z); */ 00186 /* std::cout << " *** ROTATION *** " << std::endl; */ 00187 /* checkNorm( (x.Cross(y)).Dot(z) ); */ 00188 /* ddOutVecs (x, y, z); */ 00189 /* std::cout << "Matrix output built up from vectors:" << std::endl; */ 00190 /* ddRotOut(R); */ 00191 /* std::cout << "Matrix built to preserve left-handedness:" << std::endl; */ 00192 /* DDRotationMatrix temp(x.x(),y.x(),z.x(), */ 00193 /* x.y(),y.y(),z.y(), */ 00194 /* x.z(),y.z(),z.z()); //matrix representation */ 00195 /* ddRotOut(temp); */ 00196 /* } */ 00197 00198 00199 /* } */ 00200 #endif