CMS 3D CMS Logo

DDRotation.cc
Go to the documentation of this file.
1 #include <cstdio>
2 #include <atomic>
3 #include <cmath>
4 #include <sstream>
5 #include <string>
6 
15 #include "Math/GenVector/AxisAngle.h"
16 #include "Math/GenVector/Cartesian3D.h"
17 #include "Math/GenVector/DisplacementVector3D.h"
18 
19 using namespace geant_units::operators;
20 
21 std::ostream& operator<<(std::ostream& os, const DDRotation& r) {
23  if (defined.first) {
24  os << *(defined.first) << " ";
25  if (defined.second) {
26  const DDRotationMatrix& rm = r.rotation();
27  DDAxisAngle ra(rm);
28  os << "t=" << convertRadToDeg(ra.Axis().Theta()) << "deg "
29  << "p=" << convertRadToDeg(ra.Axis().Phi()) << "deg "
30  << "a=" << convertRadToDeg(ra.Angle()) << "deg";
31  } else {
32  os << "* rotation not defined * ";
33  }
34  } else {
35  os << "* rotation not declared * ";
36  }
37  return os;
38 }
39 
41  constexpr char const* baseName = "DdBlNa";
42  // In this particular case, we do not really care about multiple threads
43  // using the same counter, we simply need to have a unique id for the
44  // blank matrix being created, so just making this static an atomic should do
45  // the trick. In order to ensure repeatibility one should also include some
46  // some run specific Id, I guess. Not sure it really matters.
47  static std::atomic<int> countBlank;
48  char buf[64];
49  snprintf(buf, 64, "%s%i", baseName, countBlank++);
50  create(DDName(buf, baseName), std::make_unique<DDRotationMatrix>());
51 }
52 
54 
55 DDRotation::DDRotation(const DDName& name, std::unique_ptr<DDRotationMatrix> rot)
58 }
59 
60 DDRotation::DDRotation(std::unique_ptr<DDRotationMatrix> rot) : DDBase<DDName, std::unique_ptr<DDRotationMatrix>>() {
61  static std::atomic<int> countNN;
62  char buf[64];
63  snprintf(buf, 64, "DdNoNa%i", countNN++);
64  create(DDName(buf, "DdNoNa"), std::move(rot));
65 }
66 
67 DDRotation DDrot(const DDName& ddname, std::unique_ptr<DDRotationMatrix> rot) {
68  // memory of rot goes sto DDRotationImpl!!
69  return DDRotation(ddname, std::move(rot));
70 }
71 
72 std::unique_ptr<DDRotation> DDrotPtr(const DDName& ddname, std::unique_ptr<DDRotationMatrix> rot) {
73  // memory of rot goes sto DDRotationImpl!!
74  return std::make_unique<DDRotation>(ddname, std::move(rot));
75 }
76 
77 // makes sure that the DDRotationMatrix constructed is right-handed and orthogonal.
79  const DDName& ddname, double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ) {
80  // define 3 unit std::vectors
81  DD3Vector x(cos(phiX) * sin(thetaX), sin(phiX) * sin(thetaX), cos(thetaX));
82  DD3Vector y(cos(phiY) * sin(thetaY), sin(phiY) * sin(thetaY), cos(thetaY));
83  DD3Vector z(cos(phiZ) * sin(thetaZ), sin(phiZ) * sin(thetaZ), cos(thetaZ));
84 
85  double tol = 1.0e-3; // Geant4 compatible
86  double check = (x.Cross(y)).Dot(z); // in case of a LEFT-handed orthogonal system this must be -1
87  if (fabs(1. - check) > tol) {
88  edm::LogError("DDRotation") << ddname << " is not a RIGHT-handed orthonormal matrix!" << std::endl;
89  throw cms::Exception("DDException") << ddname.name() << " is not RIGHT-handed!";
90  }
91 
92  return DDRotation(ddname,
93  std::make_unique<DDRotationMatrix>(x.x(), y.x(), z.x(), x.y(), y.y(), z.y(), x.z(), y.z(), z.z()));
94 }
95 
96 DDRotation DDrotReflect(const DDName& ddname, std::unique_ptr<DDRotationMatrix> rot) {
97  return DDRotation(ddname, std::move(rot));
98 }
99 
100 // makes sure that the DDRotationMatrix built is LEFT-handed coordinate system (i.e. reflected)
102  const DDName& ddname, double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ) {
103  // define 3 unit std::vectors forming the new left-handed axes
104  DD3Vector x(cos(phiX) * sin(thetaX), sin(phiX) * sin(thetaX), cos(thetaX));
105  DD3Vector y(cos(phiY) * sin(thetaY), sin(phiY) * sin(thetaY), cos(thetaY));
106  DD3Vector z(cos(phiZ) * sin(thetaZ), sin(phiZ) * sin(thetaZ), cos(thetaZ));
107 
108  double tol = 1.0e-3; // Geant4 compatible
109  double check = (x.Cross(y)).Dot(z); // in case of a LEFT-handed orthogonal system this must be -1
110  if (fabs(1. + check) > tol) {
111  edm::LogError("DDRotation") << ddname << " is not a LEFT-handed orthonormal matrix!" << std::endl;
112  throw cms::Exception("DDException") << ddname.name() << " is not LEFT-handed!";
113  }
114 
115  return DDRotation(ddname,
116  std::make_unique<DDRotationMatrix>(x.x(), y.x(), z.x(), x.y(), y.y(), z.y(), x.z(), y.z(), z.z()));
117 }
118 
119 // does NOT check LEFT or Right handed coordinate system takes either.
120 std::unique_ptr<DDRotationMatrix> DDcreateRotationMatrix(
121  double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ) {
122  // define 3 unit std::vectors forming the new left-handed axes
123  DD3Vector x(cos(phiX) * sin(thetaX), sin(phiX) * sin(thetaX), cos(thetaX));
124  DD3Vector y(cos(phiY) * sin(thetaY), sin(phiY) * sin(thetaY), cos(thetaY));
125  DD3Vector z(cos(phiZ) * sin(thetaZ), sin(phiZ) * sin(thetaZ), cos(thetaZ));
126 
127  double tol = 1.0e-3; // Geant4 compatible
128  double check = (x.Cross(y)).Dot(z); // in case of a LEFT-handed orthogonal system this must be -1, RIGHT-handed: +1
129  if ((1. - fabs(check)) > tol) {
130  std::ostringstream o;
131  o << "matrix is not an (left or right handed) orthonormal matrix! (in deg)" << std::endl
132  << " thetaX=" << convertRadToDeg(thetaX) << " phiX=" << convertRadToDeg(phiX) << std::endl
133  << " thetaY=" << convertRadToDeg(thetaY) << " phiY=" << convertRadToDeg(phiY) << std::endl
134  << " thetaZ=" << convertRadToDeg(thetaZ) << " phiZ=" << convertRadToDeg(phiZ) << std::endl;
135  edm::LogError("DDRotation") << o.str() << std::endl;
136 
137  throw cms::Exception("DDException") << o.str();
138  }
139 
140  return std::make_unique<DDRotationMatrix>(x.x(), y.x(), z.x(), x.y(), y.y(), z.y(), x.z(), y.z(), z.z());
141 }
142 
143 DDRotation DDanonymousRot(std::unique_ptr<DDRotationMatrix> rot) { return DDRotation(std::move(rot)); }
DDBase.h
DDBase::def_type
std::pair< const N *, bool > def_type
Definition: DDBase.h:51
DDTransform.h
MessageLogger.h
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
DDName
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
DDrotPtr
std::unique_ptr< DDRotation > DDrotPtr(const DDName &ddname, std::unique_ptr< DDRotationMatrix > rot)
Definition: DDRotation.cc:72
angle_units::operators::convertRadToDeg
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
DDrotReflect
DDRotation DDrotReflect(const DDName &ddname, std::unique_ptr< DDRotationMatrix > rot)
Definition: DDRotation.cc:96
geant_units::operators
Definition: GeantUnits.h:18
DDRotationMatrix
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
Definition: DDRotationMatrix.h:8
DD3Vector
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
operator<<
std::ostream & operator<<(std::ostream &os, const DDRotation &r)
Definition: DDRotation.cc:21
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
RPCNoise_example.check
check
Definition: RPCNoise_example.py:71
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DDcreateRotationMatrix
std::unique_ptr< DDRotationMatrix > DDcreateRotationMatrix(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
create a new DDRotationMatrix in the GEANT3 style.
Definition: DDRotation.cc:120
vertices_cff.x
x
Definition: vertices_cff.py:29
DDBase< DDName, std::unique_ptr< DDRotationMatrix > >::name
const DDName & name() const
Definition: DDBase.h:59
submit.rm
rm
Definition: submit.py:77
edm::LogError
Definition: MessageLogger.h:183
DDrot
DDRotation DDrot(const DDName &ddname, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:67
GeantUnits.h
DDName::name
const std::string & name() const
Returns the name.
Definition: DDName.cc:40
DDAxisAngle
ROOT::Math::AxisAngle DDAxisAngle
Definition: DDRotationMatrix.h:9
DDTranslation.h
DOFs::thetaY
Definition: AlignPCLThresholdsWriter.cc:37
DDRotation::DDRotation
DDRotation()
refers to the unit-rotation (no rotation at all)
Definition: DDRotation.cc:40
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
alignCSCRings.r
r
Definition: alignCSCRings.py:93
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
DOFs::thetaX
Definition: AlignPCLThresholdsWriter.cc:37
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DOFs::thetaZ
Definition: AlignPCLThresholdsWriter.cc:37
DDBase< DDName, std::unique_ptr< DDRotationMatrix > >::create
void create(const DDName &name, std::unique_ptr< DDRotationMatrix > vals)
Definition: DDBase.h:96
DDName.h
Exception
Definition: hltDiff.cc:246
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
DDRotation
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
Exception.h
DDanonymousRot
DDRotation DDanonymousRot(std::unique_ptr< DDRotationMatrix > rot)
Defines a anonymous rotation or rotation-reflection matrix.
Definition: DDRotation.cc:143
DDBase
Definition: DDBase.h:10
DDRotation
ROOT::Math::Rotation3D DDRotation
Definition: DDEcalEndcapAlgo.cc:18
DDRotationMatrix.h