Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JCompass.cc File Reference

Example compass operations. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TRandom3.h"
#include "JGeometry3D/JPosition3D.hh"
#include "JGeometry3D/JRotation3D.hh"
#include "JGeometry3D/JQuaternion3D.hh"
#include "JUTM/JUTMPosition.hh"
#include "JDetector/JCompass.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example compass operations.

Author
mdejong

Definition in file examples/JDetector/JCompass.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 27 of file examples/JDetector/JCompass.cc.

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
#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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
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.
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)
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