Jpp test-rotations-old-57-g407471f53
the software that should make you happy
Loading...
Searching...
No Matches
examples/JDetector/JCompass.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5
6#include "TRandom3.h"
7
11
12#include "JUTM/JUTMPosition.hh"
13
14#include "JDetector/JCompass.hh"
15
16#include "Jeep/JPrint.hh"
17#include "Jeep/JParser.hh"
18#include "Jeep/JMessage.hh"
19
20
21/**
22 * \file
23 *
24 * Example compass operations.
25 * \author mdejong
26 */
27int main(int argc, char **argv)
28{
29 using namespace std;
30 using namespace JPP;
31
32 int numberOfEvents;
33 ULong_t seed;
34 double precision;
35 int debug;
36
37 try {
38
39 JParser<> zap;
40
41 zap['n'] = make_field(numberOfEvents) = 100;
42 zap['e'] = make_field(precision) = 1.0e-8;
43 zap['S'] = make_field(seed) = 0;
44 zap['d'] = make_field(debug) = 3;
45
46 zap(argc, argv);
47 }
48 catch(const exception &error) {
49 FATAL(error.what() << endl);
50 }
51
52 gRandom->SetSeed(seed);
53
54 {
55 const JCompass c1(0.5*PI, 0.0, 0.0);
56
57 const JUTMPosition pointer[] = { JNorth_t, JEast_t, JSouth_t, JWest_t, JNorth_t };
58
59 for (int i = 0; i != 4; ++i) {
60
61 JPosition3D u = pointer[i];
62
63 DEBUG(u << " - > ");
64
65 u.rotate(c1.getRotation());
66
67 DEBUG(u << endl);
68
69 ASSERT(u.equals(pointer[i+1], precision), "compass definitions");
70 }
71 }
72
73 for (int count = 0; count < numberOfEvents; ++count) {
74
75 STATUS("event: " << setw(10) << count << '\r'); DEBUG(endl);
76
77 const JCompass c1(gRandom->Uniform(-1.0*PI,+1.0*PI),
78 gRandom->Uniform(-0.5*PI,+0.5*PI),
79 gRandom->Uniform(-0.5*PI,+0.5*PI));
80
81 const JRotation3D R1 = c1.getRotation();
82 const JQuaternion3D Q1(R1);
83 const JQuaternion3D Q2 = c1.getQuaternion();
84 const JCompass c2(Q1);
85
86 DEBUG("compass [1] " << setprecision(3) << c1 << endl);
87 DEBUG("compass [2] " << setprecision(3) << c2 << endl);
88 DEBUG("quaternion [1] " << setprecision(5) << Q1 << endl);
89 DEBUG("quaternion [2] " << setprecision(5) << Q2 << endl);
90
91 DEBUG(R1 << endl);
92
93 ASSERT(Q1.equals(+Q2, precision) ||
94 Q1.equals(-Q2, precision), "compass to rotation to quaternion versus compass to quaternion");
95
96 ASSERT(c1.equals(c2, precision), "compass to quaternion to compass");
97
98 const JPosition3D pos[] = {
99 JVector3X_t,
100 JVector3Y_t,
101 JVector3Z_t,
102 };
103
104 for (int i = 0; i != sizeof(pos)/sizeof(pos[0]); ++i) {
105
106 JPosition3D p0 = pos[i];
107 JPosition3D p1 = p0;
108
109 p1.rotate(R1);
110
111 JPosition3D p2 = p1;
112
113 p2.rotate_back(Q1);
114
115 DEBUG(showpos << FIXED(8,3) << p0 << " -> " << flush);
116 DEBUG(showpos << FIXED(8,3) << p1 << " -> " << flush);
117 DEBUG(showpos << FIXED(8,3) << p2 << endl);
118
119 ASSERT(p0.equals(p2, precision));
120 }
121 }
122
123 return 0;
124}
TCanvas * c1
Global variables to handle mouse events.
TPaveText * p1
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
Data structure for compass in three dimensions.
Definition JCompass.hh:51
Data structure for position in three dimensions.
JPosition3D & rotate(const JRotation3D &R)
Rotate.
JPosition3D & rotate_back(const JRotation3D &R)
Rotate back.
Data structure for unit quaternion in three dimensions.
const JQuaternion3D & getQuaternion() const
Get quaternion.
bool equals(const JQuaternion3D &quaternion, const double precision=std::numeric_limits< double >::min()) const
Check equality.
const JRotation3D & getRotation() const
Get rotation.
bool equals(const JVector3D &vector, const double precision=std::numeric_limits< double >::min()) const
Check equality.
Definition JVector3D.hh:221
Utility class to parse command line options.
Definition JParser.hh:1698
Data structure for UTM position.
#define R1(x)
int main(int argc, char **argv)
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448