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
#include <cassert>
19
20
namespace
Amg
{
21
36
37
inline
double
roundWithPrecision
(
double
val,
int
precision) {
38
assert(precision>=0);
39
const
double
scale = std::pow(10.0, precision);
40
const
double
rounded = std::round(val * scale) / scale;
41
return
rounded == 0.0 ? 0.0 : rounded;
//avoids a -0 result.
42
}
43
44
inline
std::string
toString
(
const
MatrixX
& matrix,
int
precision = 4,
45
std::string_view offset =
""
) {
46
std::ostringstream sout;
47
48
sout << std::setiosflags(std::ios::fixed) << std::setprecision(precision);
49
if
(matrix.cols() == 1) {
50
sout <<
"("
;
51
for
(
int
i = 0; i < matrix.rows(); ++i) {
52
double
val =
roundWithPrecision
(matrix(i, 0), precision);
53
sout << val;
54
if
(i != matrix.rows() - 1)
55
sout <<
", "
;
56
}
57
sout <<
")"
;
58
}
else
{
59
for
(
int
i = 0; i < matrix.rows(); ++i) {
60
for
(
int
j = 0; j < matrix.cols(); ++j) {
61
if
(j == 0)
62
sout <<
"("
;
63
double
val =
roundWithPrecision
(matrix(i, j), precision);
64
sout << val;
65
if
(j == matrix.cols() - 1)
66
sout <<
")"
;
67
else
68
sout <<
", "
;
69
}
70
if
(i != matrix.rows() - 1) {
// make the end line and the offset in the next line
71
sout << std::endl;
72
sout << offset;
73
}
74
}
75
}
76
return
sout.str();
77
}
78
79
}
// namespace Amg
80
81
#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:37
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