Jpp  15.0.1-rc.2-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JGeometry3D.cc File Reference

Example program to test rotations in 3D. More...

#include <iostream>
#include <iomanip>
#include "TRandom3.h"
#include "JTools/JQuantile.hh"
#include "JGeometry3D/JPosition3D.hh"
#include "JGeometry3D/JAngle3D.hh"
#include "JGeometry3D/JRotation3D.hh"
#include "JGeometry3D/JQuaternion3D.hh"
#include "JMath/JMathToolkit.hh"
#include "JMath/JConstants.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 program to test rotations in 3D.

Author
mdejong

Definition in file JGeometry3D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 26 of file JGeometry3D.cc.

27 {
28  using namespace std;
29 
30  int numberOfEvents;
31  double precision;
32  UInt_t seed;
33  int debug;
34 
35  try {
36 
37  JParser<> zap("Example program to test rotations in 3D.");
38 
39  zap['n'] = make_field(numberOfEvents);
40  zap['e'] = make_field(precision) = 1.0e-12;
41  zap['S'] = make_field(seed) = 0;
42  zap['d'] = make_field(debug) = 1;
43 
44  zap(argc, argv);
45  }
46  catch(const exception &error) {
47  FATAL(error.what() << endl);
48  }
49 
50  gRandom->SetSeed(seed);
51 
52  using namespace JPP;
53 
54 
55  JQuantile Q("Distance");
56 
57  const JVector3D v[] = { JVector3D(1,0,0), // unit vector along x-axis
58  JVector3D(0,1,0), // unit vector along y-axis
59  JVector3D(0,0,1) }; // unit vector along z-axis
60 
61  for (int i = 0; i != numberOfEvents; ++i) {
62 
63  STATUS("event: " << setw(10) << i << '\r'); DEBUG(endl);
64 
65  const double theta = gRandom->Uniform(0.0, PI);
66  const double phi = gRandom->Uniform(0.0, 2*PI);
67 
68  const JAngle3D dir(theta, phi); // principal direction
69  const JRotation3D R(dir);
70 
71  //const JRotation3Y Ry(theta); // rotation around y-axis
72  //const JRotation3Z Rz(phi); // rotation around z-axis
73 
74  //const JQuaternion3D Ry(theta, JVersor3D(0,1,0)); // rotation around y-axis
75  //const JQuaternion3D Rz(phi, JVersor3D(0,0,1)); // rotation around z-axis
76 
77  const JQuaternion3X Rx(0.0); // rotation around x-axis
78  const JQuaternion3Y Ry(theta); // rotation around y-axis
79  const JQuaternion3Z Rz(phi); // rotation around z-axis
80 
81  //const JQuaternion3D Rs = Rz * Ry;
82  JQuaternion3D Rs(Rx, Ry, Rz);
83  /*
84  Rs.setIdentity();
85  Rs *= Rz;
86  Rs *= Ry;
87  */
88  for (int j = 0; j != sizeof(v)/sizeof(v[0]); ++j) {
89 
90  JPosition3D A(v[j]);
91  JPosition3D B(A);
92 
93  //B.rotate(Ry); // rotates around y-axis
94  //B.rotate(Rz); // rotates around z-axis
95  B.rotate(Rs);
96 
97  B.rotate(R); // rotates principal direction to z-axis
98 
99 
100  Q.put((B - A).getLength());
101 
102  if ((B - A).getLengthSquared() > precision*precision) {
103 
104  DEBUG("theta " << theta << endl);
105  DEBUG("phi " << phi << endl);
106 
107  //DEBUG("Ry" << endl << Ry);
108  //DEBUG("Rz" << endl << Rz);
109 
110  DEBUG("R " << endl << R);
111 
112  ERROR("A " << FIXED(7,3) << A.getX() << ' ' << A.getY() << ' ' << A.getZ() << endl);
113  ERROR("B " << FIXED(7,3) << B.getX() << ' ' << B.getY() << ' ' << B.getZ() << endl);
114  }
115  }
116  }
117  STATUS(endl);
118 
119  Q.print(cout);
120 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Q(UTCMax_s-UTCMin_s)-livetime_s
#define STATUS(A)
Definition: JMessage.hh:63
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define ERROR(A)
Definition: JMessage.hh:66
static const double PI
Mathematical constants.
int debug
debug level
Definition: JSirene.cc:63
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
int j
Definition: JPolint.hh:666
data_type v[N+1][M+1]
Definition: JPolint.hh:740
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A