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