ATLAS Offline Software
Loading...
Searching...
No Matches
RpcClusteringAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4#include "RpcClusteringAlg.h"
5
6#include <algorithm>
12namespace MuonR4{
13
15 ATH_CHECK(m_readKey.initialize());
16 ATH_CHECK(m_writeKey.initialize());
17 ATH_CHECK(m_linkKey.initialize());
18 return StatusCode::SUCCESS;
19 }
20 StatusCode RpcClusteringAlg::execute(const EventContext& ctx) const {
21 const xAOD::RpcStripContainer* inContainer{nullptr};
22 ATH_CHECK(SG::get(inContainer, m_readKey, ctx));
23
24 SG::WriteHandle outContainer{m_writeKey, ctx};
25 ATH_CHECK(outContainer.record(std::make_unique<xAOD::RpcStripContainer>(),
26 std::make_unique<xAOD::RpcStripAuxContainer>()));
27
29
30 auto createCluster = [&](std::vector<const xAOD::RpcStrip*>& constituents) {
31 if (constituents.empty()) return;
32 xAOD::RpcStrip* cluster = outContainer->push_back(std::make_unique<xAOD::RpcStrip>());
33 (*cluster) = (*constituents[constituents.size()/2]);
34
35 xAOD::MeasVector<1> locPos{ 0.5*(constituents[0]->localPosition<1>().x() +
36 constituents[constituents.size() -1]->localPosition<1>().x())};
37 xAOD::MeasMatrix<1> locCov{constituents.size() * cluster->localCovariance<1>()(0,0)};
38
39 cluster->setMeasurement(cluster->identifierHash(), std::move(locPos), std::move(locCov));
40
41 LinkType& links{linkDecor(*cluster)};
42 float midTime{0.f}, midTimeCov{0.f};
43 for (const xAOD::RpcStrip* strip: constituents){
44 links.emplace_back(*inContainer, strip->index());
45 midTime+= strip->time();
46 midTimeCov+=strip->timeCovariance();
47 }
48 midTime /= constituents.size();
49 midTimeCov /= constituents.size();
50 float spread{0.f};
51 for (const xAOD::RpcStrip* strip : constituents) {
52 spread+=std::pow(midTime - strip->time(), 2);
53 }
54 spread /= std::pow(constituents.size(), 2);
55 midTimeCov += spread;
56 cluster->setTime(midTime);
57 cluster->setTimeCovariance(midTimeCov);
58 constituents.clear();
59 };
60
62 xAOD::ChamberViewer hitsPerChamber{*inContainer};
63 std::size_t seenHits{};
64 do {
65 seenHits+=hitsPerChamber.size();
67 std::vector<std::vector<const xAOD::RpcStrip*>> sortedHits{};
68 for (const xAOD::RpcStrip* strip : hitsPerChamber) {
69 const unsigned int layerHash = strip->layerHash();
70 if (layerHash >= sortedHits.size()) {
71 sortedHits.resize(layerHash +1);
72 }
73 sortedHits[layerHash].push_back(strip);
74 }
76 for (std::vector<const xAOD::RpcStrip*>& hitsInLay : sortedHits){
77 if (hitsInLay.empty()) continue;
79 std::sort(hitsInLay.begin(), hitsInLay.end(),
80 [](const xAOD::RpcStrip*a, const xAOD::RpcStrip* b ){
81 return a->stripNumber() < b->stripNumber();
82 });
83 uint16_t lastChannel = hitsInLay[0]->stripNumber();
84 std::vector<const xAOD::RpcStrip*> groupedHits{};
85 for (const xAOD::RpcStrip* strip : hitsInLay) {
86 if (strip->stripNumber() - lastChannel -1u > m_maxHoles ||
87 (!groupedHits.empty() && 1u*(strip->stripNumber() - groupedHits[0]->stripNumber()) > m_maxSize)){
88 createCluster(groupedHits);
89 }
90 groupedHits.push_back(strip);
91 }
92 createCluster(groupedHits);
93 }
94
95 } while (hitsPerChamber.next());
96 if (seenHits != inContainer->size()) {
97 ATH_MSG_FATAL("Detected inconsistency between the hits in container "<<inContainer->size()<<
98 " and what's returned by the chamber viewer "<<seenHits);
99 return StatusCode::FAILURE;
100 }
101 return StatusCode::SUCCESS;
102 }
103}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
static Double_t a
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
Handle class for recording to StoreGate.
size_type size() const noexcept
Returns the number of elements in the collection.
Gaudi::Property< unsigned > m_maxSize
StatusCode execute(const EventContext &ctx) const override final
std::vector< ElementLink< xAOD::RpcStripContainer > > LinkType
Gaudi::Property< unsigned > m_maxHoles
StatusCode initialize() override final
SG::ReadHandleKey< xAOD::RpcStripContainer > m_readKey
SG::WriteHandleKey< xAOD::RpcStripContainer > m_writeKey
SG::WriteDecorHandleKey< xAOD::RpcStripContainer > m_linkKey
Handle class for adding a decoration to an object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
bool next() noexcept
Loads the hits from the next chamber.
std::size_t size() const noexcept
Returns how many hits are in the current chamber.
void setTime(float time)
Sets the the triger time of the hit.
void setTimeCovariance(float timeCov)
Set the time covariance of the Measurement.
void setMeasurement(const DetectorIDHashType idHash, MeasVector< N > locPos, MeasMatrix< N > locCov)
Sets IdentifierHash, local position and local covariance of the measurement.
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)
This header ties the generic definitions in this package.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
RpcStrip_v1 RpcStrip
Definition RpcStripFwd.h:12
RpcStripContainer_v1 RpcStripContainer
Eigen::Matrix< float, N, N > MeasMatrix
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.