ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
EventPrimitives
EventPrimitives
EventPrimitivesToStringConverter.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// EventPrimitivesToStringConverter.h, (c) ATLAS Detector software
8
9
#ifndef EVENTPRIMITIVESTOSTRINGCONVERTER_H_
10
#define EVENTPRIMITIVESTOSTRINGCONVERTER_H_
11
12
#include <iomanip>
13
#include <iostream>
14
#include <string>
15
16
#include "
EventPrimitives/EventPrimitives.h
"
17
18
namespace
Amg
{
19
34
35
inline
double
roundWithPrecision
(
double
val,
int
precision) {
36
if
(val < 0 && std::abs(val) * std::pow(10, precision) < 1.)
37
return
-val;
38
return
val;
39
}
40
41
inline
std::string
toString
(
const
MatrixX
& matrix,
int
precision = 4,
42
const
std::string& offset =
""
) {
43
std::ostringstream sout;
44
45
sout << std::setiosflags(std::ios::fixed) << std::setprecision(precision);
46
if
(matrix.cols() == 1) {
47
sout <<
"("
;
48
for
(
int
i = 0; i < matrix.rows(); ++i) {
49
double
val =
roundWithPrecision
(matrix(i, 0), precision);
50
sout << val;
51
if
(i != matrix.rows() - 1)
52
sout <<
", "
;
53
}
54
sout <<
")"
;
55
}
else
{
56
for
(
int
i = 0; i < matrix.rows(); ++i) {
57
for
(
int
j = 0; j < matrix.cols(); ++j) {
58
if
(j == 0)
59
sout <<
"("
;
60
double
val =
roundWithPrecision
(matrix(i, j), precision);
61
sout << val;
62
if
(j == matrix.cols() - 1)
63
sout <<
")"
;
64
else
65
sout <<
", "
;
66
}
67
if
(i != matrix.rows() -
68
1) {
// make the end line and the offset in the next line
69
sout << std::endl;
70
sout << offset;
71
}
72
}
73
}
74
return
sout.str();
75
}
76
77
}
// namespace Amg
78
79
#endif
/* EVENTPRIMITIVESTOSTRINGCONVERTER_H_ */
EventPrimitives.h
Amg
Definition of ATLAS Math & Geometry primitives (Amg).
Definition
AmgStringHelpers.h:19
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition
GeoPrimitivesToStringConverter.h:40
Amg::roundWithPrecision
double roundWithPrecision(double val, int precision)
EventPrimitvesToStringConverter.
Definition
EventPrimitivesToStringConverter.h:35
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition
EventPrimitives.h:27
Generated on
for ATLAS Offline Software by
1.17.0