#include <DetectorDescription/Parser/src/DDLRotationAndReflection.h>
Public Member Functions | |
DDLRotationAndReflection () | |
Constructor. | |
int | isLeftHanded (DD3Vector x, DD3Vector y, DD3Vector z, const std::string &nmspace) |
returns 1 = left handed rotation matrix, 0 = right-handed, -1 = not orthonormal. | |
void | processElement (const std::string &name, const std::string &nmspace) |
Processing the element. | |
~DDLRotationAndReflection () | |
Destructor. | |
Private Member Functions | |
DD3Vector | makeX (std::string nmspace) |
DD3Vector | makeY (std::string nmspace) |
DD3Vector | makeZ (std::string nmspace) |
DDLRotationAndReflection.h - description ------------------- begin: Tue Oct 30 2001 email: case@ucdhep.ucdavis.edu
This is the Rotation and Reflection element processor.
Definition at line 25 of file DDLRotationAndReflection.h.
DDLRotationAndReflection::DDLRotationAndReflection | ( | ) |
DDLRotationAndReflection::~DDLRotationAndReflection | ( | ) |
int DDLRotationAndReflection::isLeftHanded | ( | DD3Vector | x, | |
DD3Vector | y, | |||
DD3Vector | z, | |||
const std::string & | nmspace | |||
) |
returns 1 = left handed rotation matrix, 0 = right-handed, -1 = not orthonormal.
Definition at line 124 of file DDLRotationAndReflection.cc.
References funct::abs(), HcalDataFrameFilter_impl::check(), GenMuonPlsPt100GeV_cfg::cout, DCOUT_V, lat::endl(), ExprEvalInterface::eval(), DDXMLElement::getAttributeSet(), DDXMLElement::getDDName(), and DDI::Singleton< I >::instance().
Referenced by processElement().
00125 { 00126 DCOUT_V('P', "DDLRotation::isLeftHanded started"); 00127 00128 int ret = 0; 00129 00130 /**************** copied and cannibalized code: 00131 00132 from g3tog4 00133 00134 https://atlassw1.phy.bnl.gov/lxr/source/external/geant4.3.1/source/g3tog4/src/G4gsrotm.cc 00135 00136 48 // Construct unit std::vectors 00137 49 00138 50 G4ThreeVector x(sin(th1r)*cos(phi1r), sin(th1r)*sin(phi1r), cos(th1r)->second; 00139 51 G4ThreeVector y(sin(th2r)*cos(phi2r), sin(th2r)*sin(phi2r), cos(th2r)); 00140 52 G4ThreeVector z(sin(th3r)*cos(phi3r), sin(th3r)*sin(phi3r), cos(th3r)); 00141 53 00142 54 // check for orthonormality and left-handedness 00143 55 00144 56 G4double check = (x.cross(y))*z; 00145 57 G4double tol = 1.0e-3; 00146 58 00147 59 if (1-abs(check)>tol) { 00148 60 G4cerr << "Coordinate axes forming rotation matrix " 00149 61 << irot << " are not orthonormal.(" << 1-abs(check) << ")" 00150 62 << G4std::endl; 00151 63 G4cerr << " thetaX=" << theta1; 00152 64 G4cerr << " phiX=" << phi1; 00153 65 G4cerr << " thetaY=" << theta2; 00154 66 G4cerr << " phiY=" << phi2; 00155 67 G4cerr << " thetaZ=" << theta3; 00156 68 G4cerr << " phiZ=" << phi3; 00157 69 G4cerr << G4std::endl; 00158 70 G4Exception("G4gsrotm error"); 00159 71 } 00160 72 else if (1+check<=tol) { 00161 73 G4cerr << "G4gsrotm warning: coordinate axes forming rotation " 00162 74 << "matrix " << irot << " are left-handed" << G4std::endl; 00163 75 } 00164 76 00165 77 G3toG4RotationMatrix* rotp = new G3toG4RotationMatrix; 00166 78 00167 79 rotp->SetRotationMatrixByRow(x, y, z); 00168 00169 ****************/ 00170 00171 00172 // check for orthonormality and left-handedness 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 }
DD3Vector DDLRotationAndReflection::makeX | ( | std::string | nmspace | ) | [private] |
Definition at line 208 of file DDLRotationAndReflection.cc.
References funct::cos(), ExprEvalInterface::eval(), DDXMLElement::getAttributeSet(), DDI::Singleton< I >::instance(), funct::sin(), and x.
Referenced by processElement().
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 // colx 00218 x.SetX(sin(thetaX) * cos(phiX)); 00219 x.SetY(sin(thetaX) * sin(phiX)); 00220 x.SetZ(cos(thetaX)); 00221 } 00222 return x; 00223 }
DD3Vector DDLRotationAndReflection::makeY | ( | std::string | nmspace | ) | [private] |
Definition at line 225 of file DDLRotationAndReflection.cc.
References funct::cos(), ExprEvalInterface::eval(), DDXMLElement::getAttributeSet(), DDI::Singleton< I >::instance(), funct::sin(), and y.
Referenced by processElement().
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 // coly 00236 y.SetX(sin(thetaY) * cos(phiY)); 00237 y.SetY(sin(thetaY) * sin(phiY)); 00238 y.SetZ(cos(thetaY)); 00239 } 00240 return y; 00241 }
DD3Vector DDLRotationAndReflection::makeZ | ( | std::string | nmspace | ) | [private] |
Definition at line 243 of file DDLRotationAndReflection.cc.
References funct::cos(), ExprEvalInterface::eval(), DDXMLElement::getAttributeSet(), DDI::Singleton< I >::instance(), funct::sin(), and z.
Referenced by processElement().
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 // colz 00254 z.SetX(sin(thetaZ) * cos(phiZ)); 00255 z.SetY(sin(thetaZ) * sin(phiZ)); 00256 z.SetZ(cos(thetaZ)); 00257 } 00258 return z; 00259 }
void DDLRotationAndReflection::processElement | ( | const std::string & | name, | |
const std::string & | nmspace | |||
) | [virtual] |
Processing the element.
The processElement method completes any necessary work to process the XML element.
For example, this can be used to call the DDCore to make the geometry in memory. There is a default for this so that if not declared in the inheriting class, no processing is done.
Reimplemented from DDXMLElement.
Definition at line 50 of file DDLRotationAndReflection.cc.
References DDXMLElement::clear(), DCOUT_V, DDrot(), DDrotReflect(), lat::endl(), ExprEvalInterface::eval(), DDXMLElement::getAttributeSet(), DDXMLElement::getDDName(), DDI::Singleton< I >::instance(), isLeftHanded(), makeX(), makeY(), makeZ(), alivecheck_mergeAndRegister::msg, DDXMLElement::throwError(), x, y, and z.
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; // this could become a throwWarning or something. 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; // this could be a throwWarning or something. 00099 } 00100 else 00101 { 00102 std::string msg = "\nDDLRotationAndReflection::processElement tried to process wrong element."; 00103 throwError(msg); 00104 } 00105 // after a rotation or reflection rotation has been processed, clear it 00106 clear(); 00107 00108 DCOUT_V('P', "DDLRotationAndReflection::processElement completed"); 00109 }