CbmRoot
Loading...
Searching...
No Matches
CbmLitTestMatrixMath.cxx
Go to the documentation of this file.
1/* Copyright (C) 2011-2012 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
6
7#include "TMatrixT.h"
8#include "TMatrixTSym.h"
9#include "TRandom.h"
11
12#include <cmath>
13#include <iostream>
14#include <sstream>
15#include <vector>
16
17
19
21
23{
24 std::cout << "Start matrix math test..." << std::endl;
25
26 TestInvSym15(1);
27 TestInvSym15(2);
28 TestInvSym15(3);
29
33
34 std::cout << "Finish matrix math test..." << std::endl;
35}
36
38{
39 std::cout << "Test InvSym15 #" << testId << std::endl;
40 std::vector<litfloat> input1(15);
41 for (int i = 0; i < 15; i++) {
42 input1[i] = gRandom->Rndm();
43 }
44
45 std::cout << "Input array: " << VectorToString(input1);
46
47 std::vector<litfloat> a1(input1);
48 InvSym15(a1);
49 std::cout << "Output InvSym15: " << VectorToString(a1);
50
51 litfloat rd1[25], rd2[15];
52 Convert15To25(&input1[0], rd1);
53 TMatrixTSym<litfloat> r1(5, rd1);
54 r1.InvertFast();
55 Convert25To15(r1.GetMatrixArray(), rd2);
56 std::cout << "Output ROOT: " << ArrayToString(rd2, 15);
57
58 // Compare output arrays
59 bool testPassed = true;
60 for (int i = 0; i < 15; i++) {
61 if (std::abs(a1[i] - rd2[i]) > fEpsilon) {
62 testPassed = false;
63 break;
64 }
65 }
66 if (testPassed) {
67 std::cout << "Test InvSym15 #" << testId << " PASSED" << std::endl;
68 }
69 else {
70 std::cout << "Test InvSym15 #" << testId << " !!!NOT PASSED!!!" << std::endl;
71 }
72}
73
75{
76 std::cout << "Test Mult15On5 #" << testId << std::endl;
77 std::vector<litfloat> input1(15);
78 for (int i = 0; i < 15; i++) {
79 input1[i] = gRandom->Rndm();
80 }
81 std::vector<litfloat> input2(5);
82 for (int i = 0; i < 5; i++) {
83 input2[i] = gRandom->Rndm();
84 }
85
86 std::cout << "Input array1: " << VectorToString(input1);
87 std::cout << "Input array2: " << VectorToString(input2);
88
89 std::vector<litfloat> a1(5);
90 Mult15On5(input1, input2, a1);
91 std::cout << "Output Mult15On5: " << VectorToString(a1);
92
93 litfloat rd1[25];
94 Convert15To25(&input1[0], rd1);
95 TMatrixTSym<litfloat> r1(5, rd1);
96 TMatrixT<litfloat> v1(5, 1, &input2[0]);
97 TMatrixT<litfloat> u1(5, 1);
98 u1 = r1 * v1;
99
100 litfloat* ro = u1.GetMatrixArray();
101
102 std::cout << "Output ROOT: " << ArrayToString(ro, 5);
103
104 // Compare output arrays
105 bool testPassed = true;
106 for (int i = 0; i < 5; i++) {
107 if (std::abs(a1[i] - ro[i]) > fEpsilon) {
108 testPassed = false;
109 break;
110 }
111 }
112 if (testPassed) {
113 std::cout << "Test Mult15On5 #" << testId << " PASSED" << std::endl;
114 }
115 else {
116 std::cout << "Test Mult15On5 #" << testId << " !!!NOT PASSED!!!" << std::endl;
117 }
118}
119
121{
122 a25[0] = a15[0];
123 a25[1] = a15[1];
124 a25[2] = a15[2];
125 a25[3] = a15[3];
126 a25[4] = a15[4];
127 a25[5] = a15[1];
128 a25[6] = a15[5];
129 a25[7] = a15[6];
130 a25[8] = a15[7];
131 a25[9] = a15[8];
132 a25[10] = a15[2];
133 a25[11] = a15[6];
134 a25[12] = a15[9];
135 a25[13] = a15[10];
136 a25[14] = a15[11];
137 a25[15] = a15[3];
138 a25[16] = a15[7];
139 a25[17] = a15[10];
140 a25[18] = a15[12];
141 a25[19] = a15[13];
142 a25[20] = a15[4];
143 a25[21] = a15[8];
144 a25[22] = a15[11];
145 a25[23] = a15[13];
146 a25[24] = a15[14];
147}
148
150{
151 a15[0] = a25[0];
152 a15[1] = a25[1];
153 a15[2] = a25[2];
154 a15[3] = a25[3];
155 a15[4] = a25[4];
156 a15[5] = a25[6];
157 a15[6] = a25[7];
158 a15[7] = a25[8];
159 a15[8] = a25[9];
160 a15[9] = a25[12];
161 a15[10] = a25[13];
162 a15[11] = a25[14];
163 a15[12] = a25[18];
164 a15[13] = a25[19];
165 a15[14] = a25[24];
166}
167
168std::string CbmLitTestMatrixMath::VectorToString(const std::vector<litfloat>& a)
169{
170 std::stringstream out;
171 for (unsigned int i = 0; i < a.size(); i++) {
172 out << a[i] << " ";
173 }
174 out << std::endl;
175 return out.str();
176}
177
179{
180 std::stringstream out;
181 for (int i = 0; i < n; i++) {
182 out << a[i] << " ";
183 }
184 out << std::endl;
185 return out.str();
186}
double litfloat
Definition CbmLitFloat.h:19
bool Mult15On5(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
bool InvSym15(std::vector< litfloat > &a)
std::string ArrayToString(const litfloat *a, int n)
void Convert25To15(const litfloat *a25, litfloat *a15)
void Convert15To25(const litfloat *a15, litfloat *a25)
std::string VectorToString(const std::vector< litfloat > &a)