00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "DetectorDescription/Parser/src/DDLRotationAndReflection.h"
00015
00016 #include "DetectorDescription/Core/interface/DDName.h"
00017 #include "DetectorDescription/Core/interface/DDTransform.h"
00018 #include "DetectorDescription/Base/interface/DDdebug.h"
00019
00020 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00021
00022
00023 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00024
00025 #include <cmath>
00026
00027 DDLRotationAndReflection::DDLRotationAndReflection( DDLElementRegistry* myreg )
00028 : DDXMLElement( myreg )
00029 {}
00030
00031 DDLRotationAndReflection::~DDLRotationAndReflection( void )
00032 {}
00033
00034 void
00035 DDLRotationAndReflection::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00036 {
00037
00038 DCOUT_V('P', "DDLRotationAndReflection::processElement started " << name);
00039
00040 DD3Vector x = makeX(nmspace);
00041 DD3Vector y = makeY(nmspace);
00042 DD3Vector z = makeZ(nmspace);
00043
00044 DDXMLAttribute atts = getAttributeSet();
00045
00046
00047 if ((name == "Rotation") && isLeftHanded(x, y, z, nmspace) == 0)
00048 {
00049 DDRotationMatrix* ddr = new DDRotationMatrix(x, y, z);
00050 DDRotation ddrot = DDrot(getDDName(nmspace), ddr);
00051 DCOUT_V ('p', "Rotation created: " << ddrot << std::endl);
00052 }
00053 else if ((name == "Rotation") && isLeftHanded(x, y, z, nmspace) == 1)
00054 {
00055 std::string msg("\nDDLRotationAndReflection attempted to make a");
00056 msg += " left-handed rotation with a Rotation element. If";
00057 msg += " you meant to make a reflection, use ReflectionRotation";
00058 msg += " elements, otherwise, please check your matrix. Other";
00059 msg += " errors may follow. Rotation matrix not created.";
00060 edm::LogError("DetectorDescription_Parser_Rotation_and_Reflection") << msg << std::endl;
00061 }
00062 else if (name == "ReflectionRotation" && isLeftHanded(x, y, z, nmspace) == 1)
00063 {
00064 ExprEvalInterface & ev = ExprEvalSingleton::instance();
00065 DDRotation ddrot =
00066 DDrotReflect(getDDName(nmspace)
00067 , ev.eval(nmspace, atts.find("thetaX")->second)
00068 , ev.eval(nmspace, atts.find("phiX")->second)
00069 , ev.eval(nmspace, atts.find("thetaY")->second)
00070 , ev.eval(nmspace, atts.find("phiY")->second)
00071 , ev.eval(nmspace, atts.find("thetaZ")->second)
00072 , ev.eval(nmspace, atts.find("phiZ")->second));
00073 DCOUT_V ('p', "Rotation created: " << ddrot << std::endl);
00074 }
00075 else if (name == "ReflectionRotation" && isLeftHanded(x, y, z, nmspace) == 0)
00076 {
00077 std::string msg("WARNING: Attempted to make a right-handed");
00078 msg += " rotation using a ReflectionRotation element. ";
00079 msg += " If you meant to make a Rotation, use Rotation";
00080 msg += " elements, otherwise, please check your matrix.";
00081 msg += " Other errors may follow. ReflectionRotation";
00082 msg += " matrix not created.";
00083 edm::LogError("DetectorDescription_Parser_Rotation_and_Reflection") << msg << std::endl;
00084 }
00085 else
00086 {
00087 std::string msg = "\nDDLRotationAndReflection::processElement tried to process wrong element.";
00088 throwError(msg);
00089 }
00090
00091 clear();
00092
00093 DCOUT_V('P', "DDLRotationAndReflection::processElement completed");
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 int
00110 DDLRotationAndReflection::isLeftHanded (DD3Vector x, DD3Vector y, DD3Vector z, const std::string & nmspace)
00111 {
00112 DCOUT_V('P', "DDLRotation::isLeftHanded started");
00113
00114 int ret = 0;
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 double check = (x.Cross(y)).Dot(z);
00161 double tol = 1.0e-3;
00162 ExprEvalInterface & ev = ExprEvalSingleton::instance();
00163 DDXMLAttribute atts = getAttributeSet();
00164
00165 if (1.0-std::abs(check)>tol) {
00166 std::cout << "DDLRotationAndReflection Coordinate axes forming rotation matrix "
00167 << getDDName(nmspace)
00168 << " are not orthonormal.(tolerance=" << tol
00169 << " check=" << std::abs(check) << ")"
00170 << std::endl
00171 << " thetaX=" << (atts.find("thetaX")->second)
00172 << ' ' << ev.eval(nmspace, atts.find("thetaX")->second)/deg << std::endl
00173 << " phiX=" << (atts.find("phiX")->second)
00174 << ' ' << ev.eval(nmspace, atts.find("phiX")->second)/deg << std::endl
00175 << " thetaY=" << (atts.find("thetaY")->second)
00176 << ' ' << ev.eval(nmspace, atts.find("thetaY")->second)/deg << std::endl
00177 << " phiY=" << (atts.find("phiY")->second)
00178 << ' ' << ev.eval(nmspace, atts.find("phiY")->second)/deg << std::endl
00179 << " thetaZ=" << (atts.find("thetaZ")->second)
00180 << ' ' << ev.eval(nmspace, atts.find("thetaZ")->second)/deg << std::endl
00181 << " phiZ=" << (atts.find("phiZ")->second)
00182 << ' ' << ev.eval(nmspace, atts.find("phiZ")->second)/deg
00183 << std::endl
00184 << " WAS NOT CREATED!" << std::endl;
00185 ret = -1;
00186 }
00187 else if (1.0+check<=tol) {
00188 ret = 1;
00189 }
00190 DCOUT_V('P', "DDLRotation::isLeftHanded completed");
00191 return ret;
00192 }
00193
00194 DD3Vector
00195 DDLRotationAndReflection::makeX(std::string nmspace)
00196 {
00197 DD3Vector x;
00198 DDXMLAttribute atts = getAttributeSet();
00199 if (atts.find("thetaX") != atts.end())
00200 {
00201 ExprEvalInterface & ev = ExprEvalSingleton::instance();
00202 double thetaX = ev.eval(nmspace, atts.find("thetaX")->second.c_str());
00203 double phiX = ev.eval(nmspace, atts.find("phiX")->second.c_str());
00204
00205 x.SetX(sin(thetaX) * cos(phiX));
00206 x.SetY(sin(thetaX) * sin(phiX));
00207 x.SetZ(cos(thetaX));
00208 }
00209 return x;
00210 }
00211
00212 DD3Vector
00213 DDLRotationAndReflection::makeY(std::string nmspace)
00214 {
00215 DD3Vector y;
00216 DDXMLAttribute atts = getAttributeSet();
00217 if (atts.find("thetaY") != atts.end())
00218 {
00219 ExprEvalInterface & ev = ExprEvalSingleton::instance();
00220 double thetaY = ev.eval(nmspace, atts.find("thetaY")->second.c_str());
00221 double phiY = ev.eval(nmspace, atts.find("phiY")->second.c_str());
00222
00223
00224 y.SetX(sin(thetaY) * cos(phiY));
00225 y.SetY(sin(thetaY) * sin(phiY));
00226 y.SetZ(cos(thetaY));
00227 }
00228 return y;
00229 }
00230
00231 DD3Vector DDLRotationAndReflection::makeZ(std::string nmspace)
00232 {
00233 DD3Vector z;
00234 DDXMLAttribute atts = getAttributeSet();
00235 if (atts.find("thetaZ") != atts.end())
00236 {
00237 ExprEvalInterface & ev = ExprEvalSingleton::instance();
00238 double thetaZ = ev.eval(nmspace, atts.find("thetaZ")->second.c_str());
00239 double phiZ = ev.eval(nmspace, atts.find("phiZ")->second.c_str());
00240
00241
00242 z.SetX(sin(thetaZ) * cos(phiZ));
00243 z.SetY(sin(thetaZ) * sin(phiZ));
00244 z.SetZ(cos(thetaZ));
00245 }
00246 return z;
00247 }