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
JMatrix5S.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TRandom3.h"
6 #include "TMatrixTSym.h"
7 
8 #include "JLang/JException.hh"
9 #include "JMath/JMatrix5S.hh"
10 #include "JMath/JMathTestkit.hh"
11 
12 #include "Jeep/JParser.hh"
13 #include "Jeep/JMessage.hh"
14 #include "Jeep/JTimer.hh"
15 
16 
17 /**
18  * \file
19  *
20  * Example program to test inversion of symmetric matrix.
21  * \author mdejong
22  */
23 int main(int argc, char**argv)
24 {
25  using namespace std;
26  using namespace JPP;
27 
28  double precision;
29  int numberOfEvents;
30  int debug;
31 
32  try {
33 
34  JParser<> zap("Example program to test inversion of symmetric matrix.");
35 
36  zap['e'] = make_field(precision) = 1.0e-6;
37  zap['n'] = make_field(numberOfEvents) = 1000;
38  zap['d'] = make_field(debug) = 3;
39 
40  zap(argc, argv);
41  }
42  catch(const exception &error) {
43  FATAL(error.what() << endl);
44  }
45 
46 
47  ASSERT(numberOfEvents > 0);
48 
49  gRandom->SetSeed(0);
50 
51  JTimer t1("Jpp");
52  JTimer t2("ROOT");
53 
54  for (int i = 0; i != numberOfEvents; ++i) {
55 
56  if (i%100 == 0) { STATUS(setw(8) << i << '\r'); DEBUG(endl); }
57 
58  JMatrix5S A = getRandom<JMatrix5S>();
59 
60  TMatrixTSym<double> R(5);
61 
62  R(0,0) = A.a00; R(0,1) = A.a01; R(0,2) = A.a02; R(0,3) = A.a03; R(0,4) = A.a04;
63  R(1,0) = A.a10; R(1,1) = A.a11; R(1,2) = A.a12; R(1,3) = A.a13; R(1,4) = A.a14;
64  R(2,0) = A.a20; R(2,1) = A.a21; R(2,2) = A.a22; R(2,3) = A.a23; R(2,4) = A.a24;
65  R(3,0) = A.a30; R(3,1) = A.a31; R(3,2) = A.a32; R(3,3) = A.a33; R(3,4) = A.a34;
66  R(4,0) = A.a40; R(4,1) = A.a41; R(4,2) = A.a42; R(4,3) = A.a43; R(4,4) = A.a44;
67 
68 
69  DEBUG("Matrix A" << endl);
70  DEBUG(A << endl);
71 
72  DEBUG("Determinant A " << A.getDeterminant() << endl);
73 
74  try {
75 
76  JMatrix5S B(A);
77 
78  t1.start();
79 
80  for (int i = 11; i != 0; --i) {
81  B.invert();
82  }
83 
84  t1.stop();
85 
86  t2.start();
87 
88  for (int i = 11; i != 0; --i) {
89  R.Invert();
90  }
91 
92  t2.stop();
93 
94  DEBUG("Matrix A^-1" << endl);
95  DEBUG(B << endl);
96 
97  DEBUG("Determinant A^-1 = " << B.getDeterminant() << endl);
98 
99  JMatrix5D C(A * B);
100 
101  DEBUG("Matrix A x A^-1" << endl);
102  DEBUG(C << endl);
103 
104  DEBUG("Determinant (A x A^-1) = " << C.getDeterminant() << endl);
105  DEBUG("Determinant A x Determinant A^-1 = " << A.getDeterminant() * B.getDeterminant() << endl);
106  DEBUG("A x A^-1 = I ? " << C.isIdentity(precision) << endl);
107 
108  if (!C.isIdentity(precision)) {
109  ERROR("Matrix A x A^-1 /= I" << endl);
110  }
111 
112  JMatrix5D D = C - JMatrix5D::getIdentity();
113 
114  DEBUG("Matrix D = C - I" << endl);
115  DEBUG(D << endl);
116 
117  ASSERT (C.isIdentity(precision));
118  }
119  catch (const JException& error) {
120  FATAL(error << endl);
121  }
122  }
123  STATUS(endl);
124 
125  if (numberOfEvents > 0) {
126 
127  const double factor = 1.0; // / numberOfEvents;
128 
129  t1.print(cout, factor, micro_t);
130  t2.print(cout, factor, micro_t);
131  }
132 
133  return 0;
134 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Exceptions.
int main(int argc, char *argv[])
Definition: Main.cc:15
micro
Definition: JScale.hh:29
#define STATUS(A)
Definition: JMessage.hh:63
static const double C
Physics constants.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:63
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A