Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JGeometry3D.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TRandom3.h"
6 
7 #include "JTools/JQuantile.hh"
12 #include "JMath/JMathToolkit.hh"
13 #include "JMath/JConstants.hh"
14 
15 #include "Jeep/JPrint.hh"
16 #include "Jeep/JParser.hh"
17 #include "Jeep/JMessage.hh"
18 
19 
20 /**
21  * \file
22  *
23  * Example program to test rotations in 3D.
24  * \author mdejong
25  */
26 int main(int argc, char**argv)
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:1514
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
Definition: Main.cc:15
Auxiliary methods for geometrical methods.
#define STATUS(A)
Definition: JMessage.hh:63
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
I/O formatting auxiliaries.
Mathematical constants.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define ERROR(A)
Definition: JMessage.hh:66
static const double PI
Mathematical constants.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
Utility class to parse command line options.
int j
Definition: JPolint.hh:703
data_type v[N+1][M+1]
Definition: JPolint.hh:777
source $JPP_DIR setenv csh $JPP_DIR &dev null eval JShellParser o a A
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62