ATLAS Offline Software
Loading...
Searching...
No Matches
ClusterValidationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
9
10#include <GaudiKernel/StatusCode.h>
11#include <traccc/edm/silicon_cell_collection.hpp>
12
13namespace {
14// Ad-hoc comparators and streamers of xAOD cluster objects in the context of
15// the Traccc to xAOD measurement conversion: only the relevant fields are
16// compared and printed.
17
18bool float_equal(float a, float b) {
19 // must be equal to the micrometer at least
20 if (std::abs(a-b) < 1e-3f) return true;
21 return false;
22}
23
24bool operator==(xAOD::PixelCluster const & lhs, xAOD::PixelCluster const & rhs) {
25 if (
26 // lhs.identifier() == rhs.identifier() // identifiers are actually different
27 float_equal(lhs.localPosition<2>()(0), rhs.localPosition<2>()(0))
28 && float_equal(lhs.localPosition<2>()(1), rhs.localPosition<2>()(1))
29 && float_equal(lhs.localCovariance<2>()(0, 0), rhs.localCovariance<2>()(0, 0))
30 && float_equal(lhs.localCovariance<2>()(0, 1), rhs.localCovariance<2>()(0, 1))
31 && float_equal(lhs.localCovariance<2>()(1, 0), rhs.localCovariance<2>()(1, 0))
32 && float_equal(lhs.localCovariance<2>()(1, 1), rhs.localCovariance<2>()(1, 1))
33 && float_equal(lhs.globalPosition()(0), rhs.globalPosition()(0))
34 && float_equal(lhs.globalPosition()(1), rhs.globalPosition()(1))
35 && float_equal(lhs.globalPosition()(2), rhs.globalPosition()(2))
36 && lhs.identifierHash() == rhs.identifierHash()
37 )
38 {
39 return true;
40 }
41 return false;
42}
43
44bool operator==(xAOD::StripCluster const & lhs, xAOD::StripCluster const & rhs) {
45 if (// lhs.identifier() == rhs.identifier()
46 float_equal(lhs.localPosition<1>()(0), rhs.localPosition<1>()(0))
47 && float_equal(lhs.localCovariance<1>()(0), rhs.localCovariance<1>()(0))
48 && lhs.identifierHash() == rhs.identifierHash()
49 )
50 {
51 return true;
52 }
53 return false;
54}
55
56MsgStream & operator<<(MsgStream & ms, xAOD::PixelCluster const & cl) {
57 ms << "id: " << cl.identifier()
58 << ", idhash: " << cl.identifierHash()
59 << ", locpos: [" << cl.localPosition<2>()(0) << ", " << cl.localPosition<2>()(1) << ']'
60 << ", locvar: [" << '[' << cl.localCovariance<2>()(0, 0) << ", " << cl.localCovariance<2>()(0, 1) << ']'
61 << ",[" << cl.localCovariance<2>()(1, 0) << ", " << cl.localCovariance<2>()(1, 1) << "]]"
62 << ", glopos: [" << cl.globalPosition()(0) << ", " << cl.globalPosition()(1) << ", " << cl.globalPosition()(2) << ']'
63 ;
64 return ms;
65}
66
67MsgStream & operator<<(MsgStream & ms, xAOD::StripCluster const & cl) {
68 ms << "id: " << cl.identifier()
69 << ", idhash: " << cl.identifierHash()
70 << ", locpos: " << cl.localPosition<1>()
71 << ", locvar: " << cl.localCovariance<1>()
72 ;
73 return ms;
74}
75
76} // anonymous namespace
77
78namespace ActsTrk {
79
81{
82 ATH_MSG_DEBUG("Initializing");
83
84 ATH_CHECK(m_referencePixelsKey.initialize());
85 ATH_CHECK(m_referenceStripsKey.initialize());
86 ATH_CHECK(m_monitoredPixelsKey.initialize());
87 ATH_CHECK(m_monitoredStripsKey.initialize());
88
89 return StatusCode::SUCCESS;
90}
91
92StatusCode ClusterValidationAlg::execute(const EventContext& ctx) const
93{
94 auto ref_pixels = SG::makeHandle(m_referencePixelsKey, ctx);
95 auto ref_strips = SG::makeHandle(m_referenceStripsKey, ctx);
96 auto mon_pixels = SG::makeHandle(m_monitoredPixelsKey, ctx);
97 auto mon_strips = SG::makeHandle(m_monitoredStripsKey, ctx);
98 ATH_CHECK(ref_pixels.isValid());
99 ATH_CHECK(ref_strips.isValid());
100 ATH_CHECK(mon_pixels.isValid());
101 ATH_CHECK(mon_strips.isValid());
102
103 if (mon_pixels->size() != ref_pixels->size() || mon_strips->size() != ref_strips->size()) {
104 std::ostringstream oss;
105 oss << "different sizes:";
106 if (mon_pixels->size() != ref_pixels->size()) {
107 oss << " pixels (ref: " << ref_pixels->size() << ", mon: " << mon_pixels->size() << ")";
108 }
109 if (mon_strips->size() != ref_strips->size()) {
110 oss << " strips (ref: " << ref_strips->size() << ", mon: " << mon_strips->size() << ")";
111 }
112 ATH_MSG_ERROR(oss.str());
113 return StatusCode::FAILURE;
114 }
115
116 unsigned int pixel_mismatch = 0;
117 for (size_t i = 0; i < mon_pixels->size(); ++i) {
118 xAOD::PixelCluster const & mon = *mon_pixels->at(i);
119 xAOD::PixelCluster const & ref = *ref_pixels->at(i);
120 if (mon != ref) {
121 pixel_mismatch += 1;
122 ATH_MSG_DEBUG("pixel clusters differ at " << i
123 << ": ref=[" << ref << ']'
124 << ", mon=[" << mon << ']');
125 }
126 }
127 unsigned int strip_mismatch = 0;
128 for (size_t i = 0; i < mon_strips->size(); ++i) {
129 xAOD::StripCluster const & mon = *mon_strips->at(i);
130 xAOD::StripCluster const & ref = *ref_strips->at(i);
131 if (mon != ref) {
132 strip_mismatch += 1;
133 ATH_MSG_DEBUG("strip clusters differ at " << i
134 << ": ref=[" << ref << ']'
135 << ", mon=[" << mon << ']');
136 }
137 }
138
139 if (pixel_mismatch != 0 || strip_mismatch != 0) {
140 ATH_MSG_ERROR("pixel clusters: " << pixel_mismatch << " mismatches over " << mon_pixels->size() << " clusters");
141 ATH_MSG_ERROR("strip clusters: " << strip_mismatch << " mismatches over " << mon_strips->size() << " clusters");
142 return StatusCode::FAILURE;
143 };
144
145 return StatusCode::SUCCESS;
146}
147
148} // namespace ActsTrk
const std::regex ref(r_ef)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
std::ostream & operator<<(std::ostream &s, const std::tuple< Tup... > &tup)
bool operator==(const DataVector< T > &a, const DataVector< T > &b)
Vector equality comparison.
static Double_t a
Handle class for reading from StoreGate.
SG::ReadHandleKey< xAOD::StripClusterContainer > m_monitoredStripsKey
SG::ReadHandleKey< xAOD::StripClusterContainer > m_referenceStripsKey
virtual StatusCode initialize() override
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_monitoredPixelsKey
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_referencePixelsKey
ConstVectorMap< 3 > globalPosition() const
Returns the global position of the pixel cluster.
ConstMatrixMap< N > localCovariance() const
Returns the local covariance of the measurement.
DetectorIDHashType identifierHash() const
Returns the IdentifierHash of the measurement (corresponds to the detector element IdentifierHash).
ConstVectorMap< N > localPosition() const
Returns the local position of the measurement.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
StripCluster_v1 StripCluster
Define the version of the strip cluster class.
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.