CMS 3D CMS Logo

DDLRotationAndReflection.cc
Go to the documentation of this file.
10 #include "Math/GenVector/Cartesian3D.h"
11 #include "Math/GenVector/DisplacementVector3D.h"
12 
13 #include <cmath>
14 #include <iostream>
15 #include <map>
16 #include <utility>
17 
18 class DDCompactView;
19 
20 using namespace geant_units::operators;
21 
23 
25  DD3Vector x = makeX(nmspace);
26  DD3Vector y = makeY(nmspace);
27  DD3Vector z = makeZ(nmspace);
28 
30 
31  if ((name == "Rotation") && isLeftHanded(x, y, z, nmspace) == 0) {
32  DDRotation ddrot = DDrot(getDDName(nmspace), std::make_unique<DDRotationMatrix>(x, y, z));
33  } else if ((name == "Rotation") && isLeftHanded(x, y, z, nmspace) == 1) {
34  std::string msg("\nDDLRotationAndReflection attempted to make a");
35  msg += " left-handed rotation with a Rotation element. If";
36  msg += " you meant to make a reflection, use ReflectionRotation";
37  msg += " elements, otherwise, please check your matrix. Other";
38  msg += " errors may follow. Rotation matrix not created.";
39  edm::LogError("DetectorDescription_Parser_Rotation_and_Reflection")
40  << msg << std::endl; // this could become a throwWarning or something.
41  } else if (name == "ReflectionRotation" && isLeftHanded(x, y, z, nmspace) == 1) {
43  DDRotation ddrot = DDrotReflect(getDDName(nmspace),
44  ev.eval(nmspace, atts.find("thetaX")->second),
45  ev.eval(nmspace, atts.find("phiX")->second),
46  ev.eval(nmspace, atts.find("thetaY")->second),
47  ev.eval(nmspace, atts.find("phiY")->second),
48  ev.eval(nmspace, atts.find("thetaZ")->second),
49  ev.eval(nmspace, atts.find("phiZ")->second));
50  } else if (name == "ReflectionRotation" && isLeftHanded(x, y, z, nmspace) == 0) {
51  std::string msg("WARNING: Attempted to make a right-handed");
52  msg += " rotation using a ReflectionRotation element. ";
53  msg += " If you meant to make a Rotation, use Rotation";
54  msg += " elements, otherwise, please check your matrix.";
55  msg += " Other errors may follow. ReflectionRotation";
56  msg += " matrix not created.";
57  edm::LogError("DetectorDescription_Parser_Rotation_and_Reflection")
58  << msg << std::endl; // this could be a throwWarning or something.
59  } else {
60  std::string msg = "\nDDLRotationAndReflection::processElement tried to process wrong element.";
61  throwError(msg);
62  }
63  // after a rotation or reflection rotation has been processed, clear it
64  clear();
65 }
66 
67 // returns 1 if it is a left-handed CLHEP rotation matrix, 0 if not, but is okay, -1 if
68 // it is not an orthonormal matrix.
69 //
70 // Upon encountering the end tag of a Rotation element, we've got to feed
71 // the appropriate rotation in to the DDCore. This is an attempt to do so.
72 //
73 // Basically, I cannibalized code from g3tog4 (see http link below) and then
74 // provided the information from our DDL to the same calls. Tim Cox showed me
75 // how to build the rotation matrix (mathematically) and the g3tog4 code basically
76 // did the rest.
77 //
78 
80  const DD3Vector& y,
81  const DD3Vector& z,
82  const std::string& nmspace) {
83  int ret = 0;
84 
85  // check for orthonormality and left-handedness
86 
87  double check = (x.Cross(y)).Dot(z);
88  double tol = 1.0e-3;
91 
92  if (1.0 - std::abs(check) > tol) {
93  std::cout << "DDLRotationAndReflection Coordinate axes forming rotation matrix " << getDDName(nmspace)
94  << " are not orthonormal.(tolerance=" << tol << " check=" << std::abs(check) << ")" << std::endl
95  << " thetaX=" << (atts.find("thetaX")->second) << ' '
96  << convertRadToDeg(ev.eval(nmspace, atts.find("thetaX")->second)) << std::endl
97  << " phiX=" << (atts.find("phiX")->second) << ' '
98  << convertRadToDeg(ev.eval(nmspace, atts.find("phiX")->second)) << std::endl
99  << " thetaY=" << (atts.find("thetaY")->second) << ' '
100  << convertRadToDeg(ev.eval(nmspace, atts.find("thetaY")->second)) << std::endl
101  << " phiY=" << (atts.find("phiY")->second) << ' '
102  << convertRadToDeg(ev.eval(nmspace, atts.find("phiY")->second)) << std::endl
103  << " thetaZ=" << (atts.find("thetaZ")->second) << ' '
104  << convertRadToDeg(ev.eval(nmspace, atts.find("thetaZ")->second)) << std::endl
105  << " phiZ=" << (atts.find("phiZ")->second) << ' '
106  << convertRadToDeg(ev.eval(nmspace, atts.find("phiZ")->second)) << std::endl
107  << " WAS NOT CREATED!" << std::endl;
108  ret = -1;
109  } else if (1.0 + check <= tol) {
110  ret = 1;
111  }
112  return ret;
113 }
114 
116  DD3Vector x;
118  if (atts.find("thetaX") != atts.end()) {
120  double thetaX = ev.eval(nmspace, atts.find("thetaX")->second);
121  double phiX = ev.eval(nmspace, atts.find("phiX")->second);
122  // colx
123  x.SetX(sin(thetaX) * cos(phiX));
124  x.SetY(sin(thetaX) * sin(phiX));
125  x.SetZ(cos(thetaX));
126  }
127  return x;
128 }
129 
131  DD3Vector y;
133  if (atts.find("thetaY") != atts.end()) {
135  double thetaY = ev.eval(nmspace, atts.find("thetaY")->second);
136  double phiY = ev.eval(nmspace, atts.find("phiY")->second);
137 
138  // coly
139  y.SetX(sin(thetaY) * cos(phiY));
140  y.SetY(sin(thetaY) * sin(phiY));
141  y.SetZ(cos(thetaY));
142  }
143  return y;
144 }
145 
147  DD3Vector z;
149  if (atts.find("thetaZ") != atts.end()) {
151  double thetaZ = ev.eval(nmspace, atts.find("thetaZ")->second);
152  double phiZ = ev.eval(nmspace, atts.find("phiZ")->second);
153 
154  // colz
155  z.SetX(sin(thetaZ) * cos(phiZ));
156  z.SetY(sin(thetaZ) * sin(phiZ));
157  z.SetZ(cos(thetaZ));
158  }
159  return z;
160 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
DDXMLElement::clear
virtual void clear(void)
clear this element's contents.
Definition: DDXMLElement.cc:40
DDLRotationAndReflection::isLeftHanded
int isLeftHanded(const DD3Vector &x, const DD3Vector &y, const DD3Vector &z, const std::string &nmspace)
returns 1 = left handed rotation matrix, 0 = right-handed, -1 = not orthonormal.
Definition: DDLRotationAndReflection.cc:79
DDAxes::y
DDTransform.h
MessageLogger.h
DDrot
DDRotation DDrot(const DDName &name, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:67
DDXMLElement::throwError
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
Definition: DDXMLElement.cc:209
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
angle_units::operators::convertRadToDeg
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
DDLRotationAndReflection::DDLRotationAndReflection
DDLRotationAndReflection(DDLElementRegistry *myreg)
Definition: DDLRotationAndReflection.cc:22
ClhepEvaluator.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DDLElementRegistry
The main class for processing parsed elements.
Definition: DDLElementRegistry.h:23
ClhepEvaluator
Definition: ClhepEvaluator.h:8
mps_check.msg
tuple msg
Definition: mps_check.py:285
DDLRotationAndReflection::makeX
DD3Vector makeX(const std::string &nmspace)
Definition: DDLRotationAndReflection.cc:115
DDAxes::x
geant_units::operators
Definition: GeantUnits.h:18
DDXMLElement::getAttributeSet
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:54
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDLElementRegistry::evaluator
ClhepEvaluator & evaluator()
Definition: DDLElementRegistry.h:42
RPCNoise_example.check
check
Definition: RPCNoise_example.py:71
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DDCompactView
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
DDLRotationAndReflection::makeY
DD3Vector makeY(const std::string &nmspace)
Definition: DDLRotationAndReflection.cc:130
DDAxes::z
DDLRotationAndReflection.h
DDXMLAttribute
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
DD3Vector
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
Definition: PGeometricDetBuilder.cc:20
GeantUnits.h
DDXMLElement
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
DOFs::thetaY
Definition: AlignPCLThresholdsWriter.cc:37
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
DDLElementRegistry.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDXMLElement::getDDName
const virtual DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:56
DOFs::thetaX
Definition: AlignPCLThresholdsWriter.cc:37
DDRotationMatrix.h
DDXMLElement.h
DOFs::thetaZ
Definition: AlignPCLThresholdsWriter.cc:37
DDLRotationAndReflection::makeZ
DD3Vector makeZ(const std::string &nmspace)
Definition: DDLRotationAndReflection.cc:146
DDName.h
ev
bool ev
Definition: Hydjet2Hadronizer.cc:97
genVertex_cff.x
x
Definition: genVertex_cff.py:13
DDrotReflect
DDRotation DDrotReflect(const DDName &name, double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
Defines a rotation-reflection in the Geant3 way.
Definition: DDRotation.cc:101
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
DDRotation
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
DDXMLElement::myRegistry_
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:173
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DDLRotationAndReflection::processElement
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Processing the element.
Definition: DDLRotationAndReflection.cc:24