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>
6 #include "CLHEP/Units/GlobalSystemOfUnits.h"
7 #include <Math/AxisAngle.h>
8 
9 #include <sstream>
10 #include <cstdlib>
11 
12 // Message logger.
14 
15 //static DDRotationMatrix GLOBAL_UNIT;
16 
17 //DDBase<DDName,DDRotationMatrix*>::StoreT::pointer_type
18 // DDBase<DDName,DDRotationMatrix*>::StoreT::instance_ = 0;
19 
20 std::ostream & operator<<(std::ostream & os, const DDRotation & r)
21 {
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=" << ra.Axis().Theta()/deg << "deg "
29  << "p=" << ra.Axis().Phi()/deg << "deg "
30  << "a=" << ra.Angle()/deg << "deg";
31  DCOUT_V('R', rm);
32  }
33  else {
34  os << "* rotation not defined * ";
35  }
36  }
37  else {
38  os << "* rotation not declared * ";
39  }
40  return os;
41 }
42 
43 
45 {
46  //static bool onlyOnce=true;
47  //if (onlyOnce) {
48  // static DDRotationMatrix* rm_ = new DDRotationMatrix;
49  // prep_ = StoreT::instance().create(DDName("",""), rm_ );
50  static std::string baseName("DdBlNa");
51  static int countBlank;
52  static std::ostringstream ostr;
53  ostr << countBlank++;
54  prep_ = StoreT::instance().create(DDName(baseName+ostr.str(),baseName), new DDRotationMatrix );
55  // std::cout << "making a BLANK " << baseName+ostr.str() << " named rotation, " << prep_->second << std::endl;
56  ostr.clear();
57  ostr.str("");
58 }
59 
60 
62 {
63  prep_ = StoreT::instance().create(name);
64 
65 }
66 
67 
70 {
71  prep_ = StoreT::instance().create(name,rot);
72 
73 }
74 
75 
78 {
79  static std::string baseNoName("DdNoNa");
80  static int countNN;
81  static std::ostringstream ostr2;
82  ostr2 << countNN++;
83  prep_ = StoreT::instance().create(DDName(baseNoName+ostr2.str(), baseNoName), rot);
84  // std::cout << "making a NO-NAME " << baseNoName+ostr2.str() << " named rotation, " << prep_->second << std::endl;
85  ostr2.clear();
86  ostr2.str("");
87 }
88 
89 // void DDRotation::clear()
90 // {
91 // StoreT::instance().clear();
92 // }
93 
94 DDRotation DDrot(const DDName & ddname, DDRotationMatrix * rot)
95 {
96  // memory of rot goes sto DDRotationImpl!!
97  //DCOUT('c', "DDrot: new rotation " << ddname);
98  //if (rot) rot->invert();
99  return DDRotation(ddname, rot);
100 }
101 
102 // makes sure that the DDRotationMatrix constructed is right-handed and orthogonal.
103 DDRotation DDrot(const DDName & ddname,
104  double thetaX, double phiX,
105  double thetaY, double phiY,
106  double thetaZ, double phiZ)
107 {
108  // define 3 unit std::vectors
109  DD3Vector x(cos(phiX)*sin(thetaX), sin(phiX)*sin(thetaX), cos(thetaX));
110  DD3Vector y(cos(phiY)*sin(thetaY), sin(phiY)*sin(thetaY), cos(thetaY));
111  DD3Vector z(cos(phiZ)*sin(thetaZ), sin(phiZ)*sin(thetaZ), cos(thetaZ));
112 
113  double tol = 1.0e-3; // Geant4 compatible
114  double check = (x.Cross(y)).Dot(z); // in case of a LEFT-handed orthogonal system this must be -1
115  if (fabs(1.-check)>tol) {
116  edm::LogError("DDRotation") << ddname << " is not a RIGHT-handed orthonormal matrix!" << std::endl;
117  throw DDException( ddname.name() + std::string(" is not RIGHT-handed!" ) );
118  }
119 
120  DDRotationMatrix* rot = new DDRotationMatrix(x.x(),y.x(),z.x(),
121  x.y(),y.y(),z.y(),
122  x.z(),y.z(),z.z());
123 
124  return DDRotation(ddname, rot);
125 
126 }
127 
128 
130 {
131  // memory of rot goes sto DDRotationImpl!!
132  //DCOUT('c', "DDrot: new rotation " << ddname);
133 // if (rot) rot->invert();
134  return DDRotation(ddname, rot);
135 }
136 
137 
138 // makes sure that the DDRotationMatrix built is LEFT-handed coordinate system (i.e. reflected)
140  double thetaX, double phiX,
141  double thetaY, double phiY,
142  double thetaZ, double phiZ)
143 {
144 
145  // define 3 unit std::vectors forming the new left-handed axes
146  DD3Vector x(cos(phiX)*sin(thetaX), sin(phiX)*sin(thetaX), cos(thetaX));
147  DD3Vector y(cos(phiY)*sin(thetaY), sin(phiY)*sin(thetaY), cos(thetaY));
148  DD3Vector z(cos(phiZ)*sin(thetaZ), sin(phiZ)*sin(thetaZ), cos(thetaZ));
149 
150  double tol = 1.0e-3; // Geant4 compatible
151  double check = (x.Cross(y)).Dot(z); // in case of a LEFT-handed orthogonal system this must be -1
152  if (fabs(1.+check)>tol) {
153  edm::LogError("DDRotation") << ddname << " is not a LEFT-handed orthonormal matrix!" << std::endl;
154  throw DDException( ddname.name() + std::string(" is not LEFT-handed!" ) );
155  }
156 
157  DDRotationMatrix* rot = new DDRotationMatrix(x.x(),y.x(),z.x(),
158  x.y(),y.y(),z.y(),
159  x.z(),y.z(),z.z());
160 
161  //DCOUT('c', "DDrotReflect: new reflection " << ddname);
162  //rot->invert();
163  return DDRotation(ddname, rot);
164 
165 }
166 
167 
168 // does NOT check LEFT or Right handed coordinate system takes either.
169 DDRotationMatrix * DDcreateRotationMatrix(double thetaX, double phiX,
170  double thetaY, double phiY,
171  double thetaZ, double phiZ)
172 {
173  // define 3 unit std::vectors forming the new left-handed axes
174  DD3Vector x(cos(phiX)*sin(thetaX), sin(phiX)*sin(thetaX), cos(thetaX));
175  DD3Vector y(cos(phiY)*sin(thetaY), sin(phiY)*sin(thetaY), cos(thetaY));
176  DD3Vector z(cos(phiZ)*sin(thetaZ), sin(phiZ)*sin(thetaZ), cos(thetaZ));
177 
178  double tol = 1.0e-3; // Geant4 compatible
179  double check = (x.Cross(y)).Dot(z);// in case of a LEFT-handed orthogonal system this must be -1, RIGHT-handed: +1
180  if ((1.-fabs(check))>tol) {
181  std::ostringstream o;
182  o << "matrix is not an (left or right handed) orthonormal matrix! (in deg)" << std::endl
183  << " thetaX=" << thetaX/deg << " phiX=" << phiX/deg << std::endl
184  << " thetaY=" << thetaY/deg << " phiY=" << phiY/deg << std::endl
185  << " thetaZ=" << thetaZ/deg << " phiZ=" << phiZ/deg << std::endl;
186  edm::LogError("DDRotation") << o.str() << std::endl;
187 
188 
189  throw DDException( o.str() );
190  }
191 
192  return new DDRotationMatrix(x.x(),y.x(),z.x(),
193  x.y(),y.y(),z.y(),
194  x.z(),y.z(),z.z());
195 }
196 
197 
199 {
200  return DDRotation(rot);
201 }
Definition: DDBase.h:18
const DDRotationMatrix * rotation() const
Returns the read-only rotation-matrix.
Definition: DDTransform.h:90
def_type isDefined() const
Definition: DDBase.h:121
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
An exception for DDD errors.
Definition: DDException.h:23
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
double double double z
DDRotation DDanonymousRot(DDRotationMatrix *rot)
Defines a anonymous rotation or rotation-reflection matrix.
Definition: DDRotation.cc:198
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:139
DDRotation DDrot(const DDName &name, DDRotationMatrix *rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:94
#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:44
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
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:169