test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CLHEPToROOTMath.h
Go to the documentation of this file.
1 #ifndef DD_CLHEPToROOTMath_h
2 #define DD_CLHEPToROOTMath_h
3 #include <iostream>
4 #include <fstream>
5 #include <iomanip>
6 
10 #include "CLHEP/Vector/Rotation.h"
11 #include "CLHEP/Vector/ThreeVector.h"
12 #include "CLHEP/Units/GlobalSystemOfUnits.h"
13 
15 
16 class HepRotOutput {
17  public:
20  void operator() ( const CLHEP::HepRotation& r ) {
21  std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << r.xx();
22  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.xy();
23  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.xz() << " ]" << std::endl;
24  std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << r.yx();
25  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.yy();
26  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.yz() << " ]" << std::endl;
27  std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << r.zx();
28  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.zy();
29  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << r.zz() << " ]" << std::endl;
30  }
31 };
32 
33 
34 /* void hepSetAxes( CLHEP::Hep3Vector& x, CLHEP::Hep3Vector& y, CLHEP::Hep3Vector& z */
35 /* , double thetaX, double phiX */
36 /* , double thetaY, double phiY */
37 /* , double thetaZ, double phiZ ) { */
38 /* x[0] = sin(thetaX) * cos(phiX); */
39 /* x[1] = sin(thetaX) * sin(phiX); */
40 /* x[2] = cos(thetaX); */
41 /* y[0] = sin(thetaY) * cos(phiY); */
42 /* y[1] = sin(thetaY) * sin(phiY); */
43 /* y[2] = cos(thetaY); */
44 /* z[0] = sin(thetaZ) * cos(phiZ); */
45 /* z[1] = sin(thetaZ) * sin(phiZ); */
46 /* z[2] = cos(thetaZ); */
47 /* } */
48 
49 /* void hepOutVecs( const CLHEP::Hep3Vector& x, const CLHEP::Hep3Vector& y, const CLHEP::Hep3Vector& z ) { */
50 /* std::cout << "Vectors used in construction:" << std::endl; */
51 /* std::cout << "x vector = " << std::setw(12) << std::fixed << std::setprecision(5) << x[0] */
52 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << y[0] */
53 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << z[0] << std::endl; */
54 /* std::cout << "y vector = " << std::setw(12) << std::fixed << std::setprecision(5) << x[1] */
55 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << y[1] */
56 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << z[1] << std::endl; */
57 /* std::cout << "z vector = " << std::setw(12) << std::fixed << std::setprecision(5) << x[2] */
58 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << y[2] */
59 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << z[2] << std::endl; */
60 /* } */
61 
62 class DDRotOutput {
63  public:
66  void operator() ( const DDRotationMatrix& r ) {
67  double xx, xy, xz, yx, yy, yz, zx, zy, zz;
68  r.GetComponents(xx, xy, xz, yx, yy, yz, zx, zy, zz);
69  std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << xx;
70  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << xy;
71  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << xz << " ]" << std::endl;
72  std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << yx;
73  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << yy;
74  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << yz << " ]" << std::endl;
75  std::cout << "[ " << std::setw(12) << std::fixed << std::setprecision(5) << zx;
76  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << zy;
77  std::cout << ", " << std::setw(12) << std::fixed << std::setprecision(5) << zz << " ]"<< std::endl;
78  }
79 };
80 
81 /* void ddSetAxes ( DD3Vector& x, DD3Vector& y, DD3Vector& z */
82 /* , double thetaX, double phiX */
83 /* , double thetaY, double phiY */
84 /* , double thetaZ, double phiZ ) { */
85 /* x.SetX(sin(thetaX) * cos(phiX)); */
86 /* x.SetY(sin(thetaX) * sin(phiX)); */
87 /* x.SetZ(cos(thetaX)); */
88 /* y.SetX(sin(thetaY) * cos(phiY)); */
89 /* y.SetY(sin(thetaY) * sin(phiY)); */
90 /* y.SetZ(cos(thetaY)); */
91 /* z.SetX(sin(thetaZ) * cos(phiZ)); */
92 /* z.SetY(sin(thetaZ) * sin(phiZ)); */
93 /* z.SetZ(cos(thetaZ)); */
94 /* } */
95 
96 /* void ddOutVecs( const DD3Vector& x, const DD3Vector& y, const DD3Vector& z ) { */
97 /* std::cout << "Vectors used in construction:" << std::endl; */
98 /* std::cout << "x vector = " << std::setw(12) << std::fixed << std::setprecision(5) << x.X() */
99 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << x.Y() */
100 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << x.Z() << std::endl; */
101 /* std::cout << "y vector = " << std::setw(12) << std::fixed << std::setprecision(5) << y.X() */
102 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << y.Y() */
103 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << y.Z() << std::endl; */
104 /* std::cout << "z vector = " << std::setw(12) << std::fixed << std::setprecision(5) << z.X() */
105 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) << z.Y() */
106 /* << ", " << std::setw(12) << std::fixed << std::setprecision(5) <<z.Z() << std::endl; */
107 /* } */
108 
109 
110 /* void checkNorm ( double check ) { */
111 /* double tol = 1.0e-3; */
112 /* if (1.0-std::abs(check)>tol) { */
113 /* std::cout << "NOT orthonormal!" << std::endl; */
114 /* } else if (1.0+check<=tol) { */
115 /* std::cout << "IS Left-handed (reflection)" << std::endl; */
116 /* } else { */
117 /* std::cout << "IS Right-handed (proper)" << std::endl; */
118 /* } */
119 
120 /* } */
121 
122 /* int main(int argc, char *argv[]) { */
123 /* std::cout << "====================== CLHEP: ========================" << std::endl; */
124 /* // Examples from DD XML */
125 /* // <ReflectionRotation name="180R" thetaX="90*deg" phiX="0*deg" thetaY="90*deg" phiY="90*deg" thetaZ="180*deg" phiZ="0*deg" /> */
126 /* { */
127 /* CLHEP::Hep3Vector x,y,z; */
128 /* hepSetAxes ( x, y, z, 90*deg, 0*deg, 90*deg, 90*deg, 180*deg, 0*deg ); */
129 /* CLHEP::HepRotation R; */
130 /* R.rotateAxes(x, y, z); */
131 /* CLHEP::HepRotation ddr(R); */
132 /* std::cout << " *** REFLECTION *** " << std::endl; */
133 /* checkNorm((x.cross(y))*z); */
134 /* hepOutVecs (x, y, z); */
135 /* std::cout << "Matrix output built up from vectors:" << std::endl; */
136 /* hrmOut(ddr); */
137 /* std::cout << "Matrix build from CLHEP::HepRep3x3 to preserve left-handedness:" << std::endl; */
138 /* CLHEP::HepRep3x3 temp(x.x(),y.x(),z.x(), */
139 /* x.y(),y.y(),z.y(), */
140 /* x.z(),y.z(),z.z()); //matrix representation */
141 /* CLHEP::HepRotation ddr2(temp); */
142 /* hrmOut(ddr2); */
143 /* } */
144 /* // <Rotation name="RM1509" thetaX="90*deg" phiX="-51.39999*deg" thetaY="90*deg" phiY="38.60001*deg" thetaZ="0*deg" phiZ="0*deg" /> */
145 /* { */
146 /* CLHEP::Hep3Vector x,y,z; */
147 /* hepSetAxes ( x, y, z, 90*deg, -51.39999*deg, 90*deg, 38.60001*deg, 0*deg, 0*deg ); */
148 /* CLHEP::HepRotation R; */
149 /* R.rotateAxes(x, y, z); */
150 /* CLHEP::HepRotation ddr(R); */
151 /* std::cout << " *** ROTATION *** " << std::endl; */
152 /* checkNorm((x.cross(y))*z); */
153 /* hepOutVecs (x, y, z); */
154 /* std::cout << "Matrix output built up from vectors:" << std::endl; */
155 /* hrmOut(ddr); */
156 /* std::cout << "Matrix build from CLHEP::HepRep3x3 to preserve left-handedness:" << std::endl; */
157 /* CLHEP::HepRep3x3 temp(x.x(),y.x(),z.x(), */
158 /* x.y(),y.y(),z.y(), */
159 /* x.z(),y.z(),z.z()); //matrix representation */
160 /* CLHEP::HepRotation ddr2(temp); */
161 /* hrmOut(ddr2); */
162 /* } */
163 
164 /* std::cout << "====================== ROOT::Math ========================" << std::endl; */
165 /* // <ReflectionRotation name="180R" thetaX="90*deg" phiX="0*deg" thetaY="90*deg" phiY="90*deg" thetaZ="180*deg" phiZ="0*deg" /> */
166 /* { */
167 /* DD3Vector x,y,z; */
168 /* ddSetAxes ( x, y, z, 90*deg, 0*deg, 90*deg, 90*deg, 180*deg, 0*deg ); */
169 /* DDRotationMatrix R(x, y, z); */
170 /* std::cout << " *** REFLECTION *** " << std::endl; */
171 /* checkNorm((x.Cross(y)).Dot(z)); */
172 /* ddOutVecs (x, y, z); */
173 /* std::cout << "Matrix output built up from vectors:" << std::endl; */
174 /* ddRotOut(R); */
175 /* std::cout << "Matrix built to preserve left-handedness:" << std::endl; */
176 /* DDRotationMatrix temp(x.x(),y.x(),z.x(), */
177 /* x.y(),y.y(),z.y(), */
178 /* x.z(),y.z(),z.z()); //matrix representation */
179 /* ddRotOut(temp); */
180 /* } */
181 /* // <Rotation name="RM1509" thetaX="90*deg" phiX="-51.39999*deg" thetaY="90*deg" phiY="38.60001*deg" thetaZ="0*deg" phiZ="0*deg" /> */
182 /* { */
183 /* DD3Vector x,y,z; */
184 /* ddSetAxes ( x, y, z, 90*deg, -51.39999*deg, 90*deg, 38.60001*deg, 0*deg, 0*deg ); */
185 /* DDRotationMatrix R(x, y, z); */
186 /* std::cout << " *** ROTATION *** " << std::endl; */
187 /* checkNorm( (x.Cross(y)).Dot(z) ); */
188 /* ddOutVecs (x, y, z); */
189 /* std::cout << "Matrix output built up from vectors:" << std::endl; */
190 /* ddRotOut(R); */
191 /* std::cout << "Matrix built to preserve left-handedness:" << std::endl; */
192 /* DDRotationMatrix temp(x.x(),y.x(),z.x(), */
193 /* x.y(),y.y(),z.y(), */
194 /* x.z(),y.z(),z.z()); //matrix representation */
195 /* ddRotOut(temp); */
196 /* } */
197 
198 
199 /* } */
200 #endif
void operator()(const DDRotationMatrix &r)
void operator()(const CLHEP::HepRotation &r)
C++ functors for output and conversion of CLHEP and ROOT::Math.
tuple cout
Definition: gather_cfg.py:121
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.