ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
xAOD
xAODTrackingCnv
src
TrackParticleCompressorTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
// Local include(s):
7
#include <memory>
8
9
10
11
#include "
TrackParticleCompressorTool.h
"
12
13
namespace
xAODMaker
{
14
15
TrackParticleCompressorTool::
16
TrackParticleCompressorTool
(
const
std::string&
type
,
17
const
std::string& name,
18
const
IInterface* parent )
19
:
AthAlgTool
(
type
, name, parent ) {
20
21
// Declare the interface implemented by the tool
22
declareInterface< xAODMaker::ITrackParticleCompressorTool >(
this
);
23
24
// Declare the properties of the tool:
25
declareProperty
(
"OffDiagCovMatrixBits"
,
m_offDiagCovMatrixBits
= 23,
26
"Bits kept for the off-diagonal covariance matrix "
27
"elements"
);
28
declareProperty
(
"DiagonalCovMatrixBits"
,
m_diagCovMatrixBits
= 23,
29
"Bits kept for the diagonal covariance matrix "
30
"elements"
);
31
declareProperty
(
"UseOffDiagCompr"
,
m_useOffDiagCompr
=
false
,
32
"Flag to control the off-diagonal compression "
33
"scheme"
);
34
}
35
36
StatusCode
TrackParticleCompressorTool::initialize
() {
37
38
// Greet the user:
39
ATH_MSG_INFO
(
"Initialising"
);
40
ATH_MSG_INFO
(
" OffDiagCovMatrixBits = "
<<
m_offDiagCovMatrixBits
);
41
ATH_MSG_INFO
(
" DiagCovMatrixBits = "
<<
m_diagCovMatrixBits
);
42
ATH_MSG_INFO
(
" UseOffDiagCompr = "
<<
m_useOffDiagCompr
);
43
44
45
// Create the helper objects:
46
m_diagCovMatrixCompressor
= std::make_unique<CxxUtils::FloatCompressor>(
47
m_diagCovMatrixBits
);
48
49
// Return gracefully:
50
return
StatusCode::SUCCESS;
51
}
52
53
StatusCode
54
TrackParticleCompressorTool::compress
(
xAOD::TrackParticle
& tp )
const
{
55
56
xAOD::ParametersCovMatrix_t covMatrix = tp.
definingParametersCovMatrix
();
57
tp.
setDefiningParametersCovMatrix
(covMatrix);
//Separate diag and offdiag cov matrix vectors may not have been set before
58
if
(
m_useOffDiagCompr
) tp.
compressDefiningParametersCovMatrixOffDiag
();
59
60
//Check if determinant got negative after compression
61
//If so, undo
62
xAOD::ParametersCovMatrix_t covMatrixCompr = tp.
definingParametersCovMatrix
();
63
if
(covMatrixCompr.determinant()<=0.) tp.
setDefiningParametersCovMatrix
(covMatrix);
64
65
const
std::vector< float > diagVec = tp.
definingParametersCovMatrixDiagVec
();
66
std::vector< float > diagVecCompr;
67
68
diagVecCompr.reserve(diagVec.size());
69
for
(
float
i : diagVec) {
70
diagVecCompr.push_back(
71
m_diagCovMatrixCompressor
->reduceFloatPrecision(i));
72
}
73
74
tp.
setDefiningParametersCovMatrixDiagVec
( diagVecCompr );
75
76
auto
compressOffDiag = [](
const
std::vector< float >& offDiagVec,
int
bits ) -> std::vector< float > {
77
CxxUtils::FloatCompressor
fc( bits );
78
std::vector< float > offDiagVecCompr;
79
offDiagVecCompr.reserve( offDiagVec.size() );
80
for
(
float
element : offDiagVec ) {
81
offDiagVecCompr.push_back( fc.
reduceFloatPrecision
( element ) );
82
}
83
return
offDiagVecCompr;
84
};
85
86
const
std::vector< float > offDiagVec = tp.
definingParametersCovMatrixOffDiagVec
();
87
tp.
setDefiningParametersCovMatrixOffDiagVec
( compressOffDiag( offDiagVec,
m_offDiagCovMatrixBits
) );
88
int
offDiagComprBits =
m_offDiagCovMatrixBits
;
89
90
// Need to check determinant of the matrix + its inverse to prevent any precision issue in inverse computation
91
while
( ( tp.
definingParametersCovMatrix
().determinant() <= 0.0 || tp.
definingParametersCovMatrix
().inverse().determinant() <= 0.0 ) &&
92
( ++offDiagComprBits <=
m_diagCovMatrixBits
) ) {
93
tp.
setDefiningParametersCovMatrixOffDiagVec
( compressOffDiag( offDiagVec, offDiagComprBits ) );
94
}
95
96
// Return gracefully:
97
return
StatusCode::SUCCESS;
98
}
99
100
}
// namespace xAODMaker
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
TrackParticleCompressorTool.h
AthAlgTool::AthAlgTool
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Definition
AthAlgTool.cxx:16
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
CxxUtils::FloatCompressor
Class implementing a lossy float compression.
Definition
FloatCompressor.h:31
CxxUtils::FloatCompressor::reduceFloatPrecision
float reduceFloatPrecision(float value) const
Function returning a reduced precision float value.
Definition
FloatCompressor.cxx:100
xAODMaker::TrackParticleCompressorTool::TrackParticleCompressorTool
TrackParticleCompressorTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
Definition
TrackParticleCompressorTool.cxx:16
xAODMaker::TrackParticleCompressorTool::initialize
StatusCode initialize() override
Function initialising the tool.
Definition
TrackParticleCompressorTool.cxx:36
xAODMaker::TrackParticleCompressorTool::compress
StatusCode compress(xAOD::TrackParticle &tp) const override
The function doing the heavy lifting.
Definition
TrackParticleCompressorTool.cxx:54
xAODMaker::TrackParticleCompressorTool::m_diagCovMatrixCompressor
std::unique_ptr< CxxUtils::FloatCompressor > m_diagCovMatrixCompressor
Helper object for compressing the on-diagonal covariance matrix elements.
Definition
TrackParticleCompressorTool.h:63
xAODMaker::TrackParticleCompressorTool::m_useOffDiagCompr
bool m_useOffDiagCompr
Definition
TrackParticleCompressorTool.h:59
xAODMaker::TrackParticleCompressorTool::m_offDiagCovMatrixBits
int m_offDiagCovMatrixBits
The number of mantissa bits to keep for off-diagonal covariance matrix elements.
Definition
TrackParticleCompressorTool.h:54
xAODMaker::TrackParticleCompressorTool::m_diagCovMatrixBits
int m_diagCovMatrixBits
The number of mantissa bits to keep for the diagonal covariance matrix elements.
Definition
TrackParticleCompressorTool.h:57
xAOD::TrackParticle_v1::setDefiningParametersCovMatrix
void setDefiningParametersCovMatrix(const ParametersCovMatrix_t &cov)
Set the defining parameters covariance matrix.
Definition
TrackParticle_v1.cxx:227
xAOD::TrackParticle_v1::definingParametersCovMatrixDiagVec
const std::vector< float > & definingParametersCovMatrixDiagVec() const
Returns the diagonal elements of the defining parameters covariance matrix.
Definition
TrackParticle_v1.cxx:326
xAOD::TrackParticle_v1::setDefiningParametersCovMatrixOffDiagVec
void setDefiningParametersCovMatrixOffDiagVec(const std::vector< float > &vec)
Set the off-diagonal elements of the defining parameters covariance matrix.
Definition
TrackParticle_v1.cxx:359
xAOD::TrackParticle_v1::compressDefiningParametersCovMatrixOffDiag
void compressDefiningParametersCovMatrixOffDiag()
Delete some off-diagonal elements for compression.
Definition
TrackParticle_v1.cxx:388
xAOD::TrackParticle_v1::definingParametersCovMatrix
const ParametersCovMatrix_t definingParametersCovMatrix() const
Returns the 5x5 symmetric matrix containing the defining parameters covariance matrix.
Definition
TrackParticle_v1.cxx:260
xAOD::TrackParticle_v1::setDefiningParametersCovMatrixDiagVec
void setDefiningParametersCovMatrixDiagVec(const std::vector< float > &vec)
Set the defining parameters covariance matrix using a length 15 vector.
Definition
TrackParticle_v1.cxx:345
xAOD::TrackParticle_v1::definingParametersCovMatrixOffDiagVec
const std::vector< float > & definingParametersCovMatrixOffDiagVec() const
Returns the correlation coefficient associated with the off-diagonal elements of the covariance matri...
Definition
TrackParticle_v1.cxx:331
xAODMaker
Definition
StoreGateSvc.h:70
xAOD::TrackParticle
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Definition
Event/xAOD/xAODTracking/xAODTracking/TrackParticle.h:13
type
Generated on
for ATLAS Offline Software by
1.17.0