CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDRotation.cc
Go to the documentation of this file.
1 #include <cmath>
5 #include "CLHEP/Units/GlobalSystemOfUnits.h"
6 #include <Math/AxisAngle.h>
7 
8 #include <sstream>
9 #include <cstdlib>
10 
11 // Message logger.
13 
14 //static DDRotationMatrix GLOBAL_UNIT;
15 
16 //DDBase<DDName,DDRotationMatrix*>::StoreT::pointer_type
17 // DDBase<DDName,DDRotationMatrix*>::StoreT::instance_ = 0;
18 
19 std::ostream & operator<<(std::ostream & os, const DDRotation & r)
20 {
22  if (defined.first) {
23  os << *(defined.first) << " ";
24  if (defined.second) {
25  const DDRotationMatrix & rm = *(r.rotation());
26  DDAxisAngle ra(rm);
27  os << "t=" << ra.Axis().Theta()/deg << "deg "
28  << "p=" << ra.Axis().Phi()/deg << "deg "
29  << "a=" << ra.Angle()/deg << "deg";
30  DCOUT_V('R', rm);
31  }
32  else {
33  os << "* rotation not defined * ";
34  }
35  }
36  else {
37  os << "* rotation not declared * ";
38  }
39  return os;
40 }
41 
42 
44 {
45  //static bool onlyOnce=true;
46  //if (onlyOnce) {
47  // static DDRotationMatrix* rm_ = new DDRotationMatrix;
48  // prep_ = StoreT::instance().create(DDName("",""), rm_ );
49  constexpr char const* baseName = "DdBlNa";
50  static int countBlank;
51  char buf[64];
52  snprintf(buf, 64, "%s%i", baseName, countBlank++);
53  prep_ = StoreT::instance().create(DDName(buf,baseName), new DDRotationMatrix );
54  // std::cout << "making a BLANK " << buf << " named rotation, " << prep_->second << std::endl;
55 }
56 
57 
59 {
60  prep_ = StoreT::instance().create(name);
61 
62 }
63 
64 
67 {
68  prep_ = StoreT::instance().create(name,rot);
69 
70 }
71 
72 
75 {
76  static std::string baseNoName("DdNoNa");
77  static int countNN;
78  static std::ostringstream ostr2;
79  ostr2 << countNN++;
80  prep_ = StoreT::instance().create(DDName(baseNoName+ostr2.str(), baseNoName), rot);
81  // std::cout << "making a NO-NAME " << baseNoName+ostr2.str() << " named rotation, " << prep_->second << std::endl;
82  ostr2.clear();
83  ostr2.str("");
84 }
85 
86 // void DDRotation::clear()
87 // {
88 // StoreT::instance().clear();
89 // }
90 
92 {
93  // memory of rot goes sto DDRotationImpl!!
94  //DCOUT('c', "DDrot: new rotation " << ddname);
95  //if (rot) rot->invert();
96  return DDRotation(ddname, rot);
97 }
98 
99 // makes sure that the DDRotationMatrix constructed is right-handed and orthogonal.
100 DDRotation DDrot(const DDName & ddname,
101  double thetaX, double phiX,
102  double thetaY, double phiY,
103  double thetaZ, double phiZ)
104 {
105  // define 3 unit std::vectors
106  DD3Vector x(cos(phiX)*sin(thetaX), sin(phiX)*sin(thetaX), cos(thetaX));
107  DD3Vector y(cos(phiY)*sin(thetaY), sin(phiY)*sin(thetaY), cos(thetaY));
108  DD3Vector z(cos(phiZ)*sin(thetaZ), sin(phiZ)*sin(thetaZ), cos(thetaZ));
109 
110  double tol = 1.0e-3; // Geant4 compatible
111  double check = (x.Cross(y)).Dot(z); // in case of a LEFT-handed orthogonal system this must be -1
112  if (fabs(1.-check)>tol) {
113  edm::LogError("DDRotation") << ddname << " is not a RIGHT-handed orthonormal matrix!" << std::endl;
114  throw cms::Exception("DDException") << ddname.name() << " is not RIGHT-handed!";
115  }
116 
117  DDRotationMatrix* rot = new DDRotationMatrix(x.x(),y.x(),z.x(),
118  x.y(),y.y(),z.y(),
119  x.z(),y.z(),z.z());
120 
121  return DDRotation(ddname, rot);
122 
123 }
124 
125 
127 {
128  // memory of rot goes sto DDRotationImpl!!
129  //DCOUT('c', "DDrot: new rotation " << ddname);
130 // if (rot) rot->invert();
131  return DDRotation(ddname, rot);
132 }
133 
134 
135 // makes sure that the DDRotationMatrix built is LEFT-handed coordinate system (i.e. reflected)
137  double thetaX, double phiX,
138  double thetaY, double phiY,
139  double thetaZ, double phiZ)
140 {
141 
142  // define 3 unit std::vectors forming the new left-handed axes
143  DD3Vector x(cos(phiX)*sin(thetaX), sin(phiX)*sin(thetaX), cos(thetaX));
144  DD3Vector y(cos(phiY)*sin(thetaY), sin(phiY)*sin(thetaY), cos(thetaY));
145  DD3Vector z(cos(phiZ)*sin(thetaZ), sin(phiZ)*sin(thetaZ), cos(thetaZ));
146 
147  double tol = 1.0e-3; // Geant4 compatible
148  double check = (x.Cross(y)).Dot(z); // in case of a LEFT-handed orthogonal system this must be -1
149  if (fabs(1.+check)>tol) {
150  edm::LogError("DDRotation") << ddname << " is not a LEFT-handed orthonormal matrix!" << std::endl;
151  throw cms::Exception("DDException") << ddname.name() << " is not LEFT-handed!";
152  }
153 
154  DDRotationMatrix* rot = new DDRotationMatrix(x.x(),y.x(),z.x(),
155  x.y(),y.y(),z.y(),
156  x.z(),y.z(),z.z());
157 
158  //DCOUT('c', "DDrotReflect: new reflection " << ddname);
159  //rot->invert();
160  return DDRotation(ddname, rot);
161 
162 }
163 
164 
165 // does NOT check LEFT or Right handed coordinate system takes either.
166 DDRotationMatrix * DDcreateRotationMatrix(double thetaX, double phiX,
167  double thetaY, double phiY,
168  double thetaZ, double phiZ)
169 {
170  // define 3 unit std::vectors forming the new left-handed axes
171  DD3Vector x(cos(phiX)*sin(thetaX), sin(phiX)*sin(thetaX), cos(thetaX));
172  DD3Vector y(cos(phiY)*sin(thetaY), sin(phiY)*sin(thetaY), cos(thetaY));
173  DD3Vector z(cos(phiZ)*sin(thetaZ), sin(phiZ)*sin(thetaZ), cos(thetaZ));
174 
175  double tol = 1.0e-3; // Geant4 compatible
176  double check = (x.Cross(y)).Dot(z);// in case of a LEFT-handed orthogonal system this must be -1, RIGHT-handed: +1
177  if ((1.-fabs(check))>tol) {
178  std::ostringstream o;
179  o << "matrix is not an (left or right handed) orthonormal matrix! (in deg)" << std::endl
180  << " thetaX=" << thetaX/deg << " phiX=" << phiX/deg << std::endl
181  << " thetaY=" << thetaY/deg << " phiY=" << phiY/deg << std::endl
182  << " thetaZ=" << thetaZ/deg << " phiZ=" << phiZ/deg << std::endl;
183  edm::LogError("DDRotation") << o.str() << std::endl;
184 
185 
186  throw cms::Exception("DDException") << o.str();
187  }
188 
189  return new DDRotationMatrix(x.x(),y.x(),z.x(),
190  x.y(),y.y(),z.y(),
191  x.z(),y.z(),z.z());
192 }
193 
194 
196 {
197  return DDRotation(rot);
198 }
Definition: DDBase.h:14
const DDRotationMatrix * rotation() const
Returns the read-only rotation-matrix.
Definition: DDTransform.h:90
def_type isDefined() const
Definition: DDBase.h:115
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:18
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
float float float z
DDRotation DDanonymousRot(DDRotationMatrix *rot)
Defines a anonymous rotation or rotation-reflection matrix.
Definition: DDRotation.cc:195
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:66
static value_type & instance()
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
string rm
Definition: submit.py:76
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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:136
DDRotation DDrot(const DDName &name, DDRotationMatrix *rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:91
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
DDRotation()
refers to the unit-rotation (no rotation at all)
Definition: DDRotation.cc:43
Definition: DDAxes.h:10
ROOT::Math::AxisAngle DDAxisAngle
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const std::string & name() const
Returns the name.
Definition: DDName.cc:87
#define constexpr
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:166