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 "
EventPrimitives/EventPrimitives.h
"
13
#include <iomanip>
14
#include <iostream>
15
#include <string>
16
#include <string_view>
17
#include <cmath>
18
19
namespace
Amg
{
20
35
36
inline
double
roundWithPrecision
(
double
val,
int
precision) {
37
if
(val < 0 && std::abs(val) * std::pow(10, precision) < 1.)
38
return
-val;
39
return
val;
40
}
41
42
inline
std::string
toString
(
const
MatrixX
& matrix,
int
precision = 4,
43
std::string_view offset =
""
) {
44
std::ostringstream sout;
45
46
sout << std::setiosflags(std::ios::fixed) << std::setprecision(precision);
47
if
(matrix.cols() == 1) {
48
sout <<
"("
;
49
for
(
int
i = 0; i < matrix.rows(); ++i) {
50
double
val =
roundWithPrecision
(matrix(i, 0), precision);
51
sout << val;
52
if
(i != matrix.rows() - 1)
53
sout <<
", "
;
54
}
55
sout <<
")"
;
56
}
else
{
57
for
(
int
i = 0; i < matrix.rows(); ++i) {
58
for
(
int
j = 0; j < matrix.cols(); ++j) {
59
if
(j == 0)
60
sout <<
"("
;
61
double
val =
roundWithPrecision
(matrix(i, j), precision);
62
sout << val;
63
if
(j == matrix.cols() - 1)
64
sout <<
")"
;
65
else
66
sout <<
", "
;
67
}
68
if
(i != matrix.rows() - 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:36
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