1#include "CLHEP/Units/SystemOfUnits.h"
2#include "CLHEP/Vector/ThreeVector.h"
3#include "CLHEP/Vector/Rotation.h"
8bool equal(
double a,
double b) {
9 const double eps = 1e-9;
10 return (std::abs(a - b) < eps);
14 const double eps = 1e-10;
15 return (std::abs(a.
x() - b.
x()) < eps &&
16 std::abs(a.
y() - b.
y()) < eps &&
17 std::abs(a.
z() - b.
z()) < eps);
24 std::cout <<
"\n=== Check rotation around specified axes" << std::endl;
29 std::cout <<
"Zero rotation - OK" << std::endl;
37 std::cout <<
"Rotation by 180 degrees around X - OK" << std::endl;
45 std::cout <<
"Rotation by 180 degrees around Y - OK" << std::endl;
53 std::cout <<
"Rotation by 180 degrees around Z - OK" << std::endl;
61 std::cout <<
"Rotation by 180 degrees around XY - OK" << std::endl;
69 std::cout <<
"Rotation by 180 degrees around YZ - OK" << std::endl;
77 std::cout <<
"Rotation by 180 degrees around ZX - OK" << std::endl;
91 std::cout <<
"\n=== Check all possible axes and angles (step = " << step <<
" degree)" << std::endl;
93 for (
int the = 0; the <= 180; the += step) {
94 for (
int phi = 0; phi < 360; phi += step) {
95 for (
int a = 0; a < 360; a += step) {
96 double z = std::cos(the*deg);
97 double y = std::sin(the*deg)*sin(phi*deg);
98 double x = std::sin(the*deg)*cos(phi*deg);
103 matrix.
set(vinput, ang);
106 voutput = matrix.
axis();
107 double del = matrix.
delta();
109 del = CLHEP::twopi - del;
114 if (a != 180) assert(
equal(ang,del) );
117 if (a == 0)
continue;
119 assert(
equal(vinput,voutput) ||
equal(-vinput,voutput));
121 assert(
equal(vinput,voutput) );
126 std::cout <<
"OK" << std::endl;
131 std::cout <<
"\n=== Check angles near 0 (step = 1/" << istep <<
" degree)" << std::endl;
133 for (
int the = 0; the <= 180; the += 5) {
134 for (
int phi = 0; phi < 360; phi += 5) {
135 for (
int a = -istep; a <= istep; a += 1) {
136 double z = std::cos(the*deg);
137 double y = std::sin(the*deg)*sin(phi*deg);
138 double x = std::sin(the*deg)*cos(phi*deg);
139 double ang = 0. + a * (deg/istep);
143 matrix.
set(vinput, ang);
146 voutput = matrix.
axis();
147 double del = matrix.
delta();
154 assert(
equal(ang,del) );
157 if (a == 0)
continue;
158 assert(
equal(vinput,voutput) );
162 std::cout <<
"OK" << std::endl;
167 std::cout <<
"\n=== Check angles near 180 (step = 1/" << istep <<
" degree)" << std::endl;
169 for (
int the = 0; the <= 180; the += 5) {
170 for (
int phi = 0; phi < 360; phi += 5) {
171 for (
int a = -istep; a <= istep; a += 1) {
172 double z = std::cos(the*deg);
173 double y = std::sin(the*deg)*sin(phi*deg);
174 double x = std::sin(the*deg)*cos(phi*deg);
175 double ang = pi + a * (deg/istep);
179 matrix.
set(vinput, ang);
182 voutput = matrix.
axis();
183 double del = matrix.
delta();
185 del = CLHEP::twopi - del;
190 if (a != 0) assert(
equal(ang,del) );
194 assert(
equal(vinput,voutput) ||
equal(-vinput,voutput));
196 assert(
equal(vinput,voutput) );
201 std::cout <<
"OK" << std::endl;
203 std::cout << std::endl;
void set(double x, double y, double z)
HepRotation & set(const Hep3Vector &axis, double delta)
bool equal(double a, double b)