ATLAS Offline Software
Loading...
Searching...
No Matches
SimpleSTgcClusterBuilderTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11
12using namespace Muon;
13
14//============================================================================
15Muon::SimpleSTgcClusterBuilderTool::SimpleSTgcClusterBuilderTool(const std::string& t, const std::string& n, const IInterface* p)
16: AthAlgTool(t,n,p) {}
17
18
19//============================================================================
21 ATH_CHECK( m_idHelperSvc.retrieve() );
22 ATH_CHECK(m_uncertCalibKey.initialize());
23 return StatusCode::SUCCESS;
24}
25
26
27//============================================================================
28// Build the clusters given a vector of single-hit PRD
29StatusCode Muon::SimpleSTgcClusterBuilderTool::getClusters(const EventContext& ctx,
30 std::vector<Muon::sTgcPrepData>&& stripsVect,
31 std::vector<std::unique_ptr<Muon::sTgcPrepData>>& clustersVect) const {
32
33 ATH_MSG_DEBUG("Size of the input vector: " << stripsVect.size());
34
35 if (stripsVect.empty()) return StatusCode::SUCCESS;
36
37
38 // define the identifier hash
39 Identifier chanId = stripsVect.at(0).identify();
40 IdentifierHash hash = m_idHelperSvc->moduleHash(chanId);
41
42 double resolution = Amg::error(stripsVect.at(0).localCovariance(), Trk::locX);
43 bool isStrip = ( m_idHelperSvc->stgcIdHelper().channelType(chanId) == sTgcIdHelper::Strip );
44 ATH_MSG_DEBUG(" channelType " << m_idHelperSvc->stgcIdHelper().channelType(chanId));
45 ATH_MSG_DEBUG(" isStrip: " << isStrip << "Single channel resolution: " << resolution);
46
48 if (!errorCalibDB.isValid()) {
49 ATH_MSG_FATAL("Failed to retrieve the parameterized errors "<<m_uncertCalibKey.fullKey());
50 return StatusCode::FAILURE;
51 }
52
53 Muon::STgcClusterBuilderCommon stgcClusterCommon(m_idHelperSvc->stgcIdHelper(), **errorCalibDB);
54 std::array<std::vector<Muon::sTgcPrepData>, 8> stgcPrdsPerLayer = stgcClusterCommon.sortSTGCPrdPerLayer(std::move(stripsVect));
55
56 for (std::vector<Muon::sTgcPrepData>& layPrds : stgcPrdsPerLayer) {
57 // Get the strip clusters of the layer.
58 std::vector<std::vector<Muon::sTgcPrepData>> layerClusters = stgcClusterCommon.findStripCluster(std::move(layPrds),
60
61 // Loop on the clusters of that gap
62 for (const std::vector<Muon::sTgcPrepData>& cluster: layerClusters) {
63 if (cluster.empty()) continue;
64
65 // Calculate the cluster position and error using the weighted average
66 std::optional<Muon::STgcClusterPosition> optClusterPos = stgcClusterCommon.weightedAverage(cluster, resolution, isStrip);
67 if (!optClusterPos) {
68 if (msgLvl(MSG::VERBOSE)) {
69 std::stringstream sstr{};
70 for (const Muon::sTgcPrepData& prd : cluster) {
71 sstr << m_idHelperSvc->toString(prd.identify())
72 << ", local pos: "<< Amg::toString(prd.localPosition(), 2)
73 << "), charge: " << prd.charge() << ", time: " << static_cast<int>(prd.time())
74 << std::endl;
75 }
76 ATH_MSG_VERBOSE("Reject invalid cluster..." << std::endl << std::endl << sstr.str());
77 }
78 continue;
79 }
80
81 Identifier clusterId = (*optClusterPos).getClusterId();
82 double posY = cluster[0].localPosition().y();
83 Amg::Vector2D localPosition((*optClusterPos).getMeanPosition(), posY);
84 auto covN = Amg::MatrixX(1,1);
85 covN(0,0) = (*optClusterPos).getErrorSquared();
86
87 std::vector<Identifier> rdoList;
88 std::vector<int> elementsCharge;
89 std::vector<short int> elementsTime;
90 std::vector<uint16_t> elementsChannel;
91 for (const Muon::sTgcPrepData& prd : cluster ) {
92 rdoList.push_back(prd.identify());
93 elementsCharge.push_back(prd.charge());
94 elementsChannel.push_back(m_idHelperSvc->stgcIdHelper().channel(prd.identify()));
95 elementsTime.push_back(prd.time());
96 }
97
98 // memory allocated dynamically for the PrepRawData is managed by Event Store in the converters
99 ATH_MSG_DEBUG("error on cluster " << std::sqrt((covN)(0,0)));
100
101 std::unique_ptr<sTgcPrepData> prdN = std::make_unique<sTgcPrepData>(
102 clusterId,
103 hash,
104 std::move(localPosition),
105 std::move(rdoList),
106 std::move(covN),
107 cluster.at(0).detectorElement(),
108 std::accumulate(elementsCharge.begin(), elementsCharge.end(), 0),
109 (short int)0,
110 std::move(elementsChannel),
111 std::move(elementsTime),
112 std::move(elementsCharge));
113
115 clustersVect.push_back(std::move(prdN));
116 }
117 }
118
119 ATH_MSG_DEBUG("Size of the output cluster vector: " << clustersVect.size());
120
121 return StatusCode::SUCCESS;
122}
123
124
125//============================================================================
127void SimpleSTgcClusterBuilderTool::dumpStrips(std::vector<Muon::sTgcPrepData>& stripsVect, std::vector<Muon::sTgcPrepData*>& clustersVect ) const {
128 ATH_MSG_INFO("====> Dumping all strips: ");
129 for ( const auto& it : stripsVect ) {
130 Identifier stripId = it.identify();
131 ATH_MSG_INFO("Strip identifier: " << m_idHelperSvc->stgcIdHelper().show_to_string(stripId) );
132 }
133
134 ATH_MSG_INFO("Dumping all clusters: ");
135 for ( auto *it : clustersVect ) {
136 Identifier clusterId = it->identify();
137 ATH_MSG_INFO("***> New cluster identifier: " << m_idHelperSvc->stgcIdHelper().show_to_string(clusterId) );
138 ATH_MSG_INFO("Cluster size: " << it->rdoList().size() );
139 ATH_MSG_INFO("List of associated RDO's: ");
140 }
141}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
bool msgLvl(const MSG::Level lvl) const
This is a "hash" representation of an Identifier.
std::optional< STgcClusterPosition > weightedAverage(const std::vector< sTgcPrepData > &cluster, const double resolution, bool isStrip) const
Compute the cluster position using the weighted average method.
std::array< std::vector< sTgcPrepData >, 8 > sortSTGCPrdPerLayer(std::vector< sTgcPrepData > &&stripPrds) const
Separate the sTGC PRDs by layer, from 0 to 7, and sort the PRDs per layer in ascending order of strip...
std::vector< std::vector< sTgcPrepData > > findStripCluster(std::vector< sTgcPrepData > &&strips, const int maxMissingStrip) const
Find strip clusters, assuming the input vector of PRDs are sorted in ascending order of strip number.
SG::ReadCondHandleKey< NswErrorCalibData > m_uncertCalibKey
StatusCode getClusters(const EventContext &ctx, std::vector< Muon::sTgcPrepData > &&stripsVect, std::vector< std::unique_ptr< Muon::sTgcPrepData > > &clustersVect) const override
void dumpStrips(std::vector< Muon::sTgcPrepData > &stripsVect, std::vector< Muon::sTgcPrepData * > &clustersVect) const
private functions
virtual StatusCode initialize() override
standard initialize method
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< unsigned int > m_maxHoleSize
SimpleSTgcClusterBuilderTool(const std::string &, const std::string &, const IInterface *)
Default constructor.
Class to represent sTgc measurements.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Eigen::Matrix< double, 2, 1 > Vector2D
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
@ locX
Definition ParamDefs.h:37