Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
examples/JDetector/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

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  UInt_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[] = {
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 }
Utility class to parse command line options.
Definition: JParser.hh:1517
static const JUTMPosition JNorth_t(0,+1, 0)
North.
TPaveText * p1
#define STATUS(A)
Definition: JMessage.hh:63
#define R1(x)
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
static const JUTMPosition JSouth_t(0,-1, 0)
South.
static const JVector3D JVector3X_t(1, 0, 0)
unit x-vector
static const JUTMPosition JWest_t(-1, 0, 0)
West.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
static const double PI
Mathematical constants.
#define FATAL(A)
Definition: JMessage.hh:67
TCanvas * c1
Global variables to handle mouse events.
p2
Definition: module-Z:fit.sh:74
static const JVector3D JVector3Z_t(0, 0, 1)
unit z-vector
static const JVector3D JVector3Y_t(0, 1, 0)
unit y-vector
double u[N+1]
Definition: JPolint.hh:776
static const JUTMPosition JEast_t(+1, 0, 0)
East.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62