ATLAS Offline Software
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>
9 #include <StoreGate/ReadHandle.h>
11 #include <StoreGate/WriteHandle.h>
12 namespace 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  SG::ReadHandle inContainer{m_readKey, ctx};
22  ATH_CHECK(inContainer.isPresent());
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 }
xAOD::UncalibratedMeasurement_v1::identifierHash
DetectorIDHashType identifierHash() const
Returns the IdentifierHash of the measurement (corresponds to the detector element IdentifierHash)
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
xAOD::ChamberViewer::size
std::size_t size() const noexcept
Returns how many hits are in the current chamber.
Definition: ChamberViewer.h:105
MuonR4::RpcClusteringAlg::m_linkKey
SG::WriteDecorHandleKey< xAOD::RpcStripContainer > m_linkKey
Definition: RpcClusteringAlg.h:25
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
MuonR4::RpcClusteringAlg::initialize
StatusCode initialize() override final
Definition: RpcClusteringAlg.cxx:14
RpcClusteringAlg.h
MuonR4::RpcClusteringAlg::LinkType
std::vector< ElementLink< xAOD::RpcStripContainer > > LinkType
Definition: RpcClusteringAlg.h:24
MuonR4::RpcClusteringAlg::m_maxHoles
Gaudi::Property< unsigned > m_maxHoles
Definition: RpcClusteringAlg.h:27
xAOD::RpcStrip_v1
Definition: RpcStrip_v1.h:11
x
#define x
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
xAOD::ChamberViewer
Definition: ChamberViewer.h:67
WriteHandle.h
Handle class for recording to StoreGate.
MuonR4::RpcClusteringAlg::m_writeKey
SG::WriteHandleKey< xAOD::RpcStripContainer > m_writeKey
Definition: RpcClusteringAlg.h:23
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
xAOD::RpcMeasurement_v1::setTimeCovariance
void setTimeCovariance(float timeCov)
Set the time covariance of the Measurement.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DMTest::links
links
Definition: CLinks_v1.cxx:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::UncalibratedMeasurement_v1::localCovariance
ConstMatrixMap< N > localCovariance() const
Returns the local covariance of the measurement.
xAOD::MeasVector
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
Definition: MeasurementDefs.h:52
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
MuonR4::RpcClusteringAlg::m_maxSize
Gaudi::Property< unsigned > m_maxSize
Definition: RpcClusteringAlg.h:28
ChamberViewer.h
xAOD::RpcMeasurement_v1::setTime
void setTime(float time)
Sets the the triger time of the hit.
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MuonR4::RpcClusteringAlg::m_readKey
SG::ReadHandleKey< xAOD::RpcStripContainer > m_readKey
Definition: RpcClusteringAlg.h:21
a
TList * a
Definition: liststreamerinfos.cxx:10
xAOD::UncalibratedMeasurement_v1::setMeasurement
void setMeasurement(const DetectorIDHashType idHash, MeasVector< N > locPos, MeasMatrix< N > locCov)
Sets IdentifierHash, local position and local covariance of the measurement.
xAOD::MeasMatrix
Eigen::Matrix< float, N, N > MeasMatrix
Definition: MeasurementDefs.h:54
ReadHandle.h
Handle class for reading from StoreGate.
RpcStripAuxContainer.h
MuonR4::RpcClusteringAlg::execute
StatusCode execute(const EventContext &ctx) const override final
Definition: RpcClusteringAlg.cxx:20