ATLAS Offline Software
Loading...
Searching...
No Matches
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
12
13namespace xAODMaker {
14
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
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>(
48
49 // Return gracefully:
50 return StatusCode::SUCCESS;
51 }
52
53 StatusCode
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 > {
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
#define ATH_MSG_INFO(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Class implementing a lossy float compression.
float reduceFloatPrecision(float value) const
Function returning a reduced precision float value.
TrackParticleCompressorTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
StatusCode initialize() override
Function initialising the tool.
StatusCode compress(xAOD::TrackParticle &tp) const override
The function doing the heavy lifting.
std::unique_ptr< CxxUtils::FloatCompressor > m_diagCovMatrixCompressor
Helper object for compressing the on-diagonal covariance matrix elements.
int m_offDiagCovMatrixBits
The number of mantissa bits to keep for off-diagonal covariance matrix elements.
int m_diagCovMatrixBits
The number of mantissa bits to keep for the diagonal covariance matrix elements.
TrackParticle_v1 TrackParticle
Reference the current persistent version: