ATLAS Offline Software
Loading...
Searching...
No Matches
MuonPrecisionLayerDecorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9#include <unordered_map>
10namespace{
11 static const SG::AuxElement::ConstAccessor<std::vector<std::vector<unsigned int>>> acc_alignEffectChId("alignEffectChId");
12 static const SG::AuxElement::ConstAccessor<std::vector<float>> acc_alligSigmaDeltaTrans("alignEffectSigmaDeltaTrans");
13 constexpr unsigned badQualityFlag = 2;
14 constexpr unsigned goodQualityFlag = 1;
15
16}
17
19 ATH_CHECK(m_MuonContainer.initialize());
20 ATH_CHECK(m_TrackContainer.initialize());
21 m_trkAlignReadKey.clear();
23 m_trkAlignReadKey.emplace_back(trk, "alignEffectChId");
24 m_trkAlignReadKey.emplace_back(trk, "alignEffectSigmaDeltaTrans");
25 }
26 ATH_CHECK(m_trkAlignReadKey.initialize());
27 ATH_CHECK(m_goodPrecLayerKey.initialize());
28 ATH_CHECK(m_isGoodSmallKey.initialize());
30 return StatusCode::SUCCESS;
31 }
32
33 StatusCode MuonPrecisionLayerDecorAlg::execute(const EventContext& ctx) const {
35 if (!muons.isValid()) {
36 ATH_MSG_FATAL("Failed to load track collection "<<m_MuonContainer.fullKey());
37 return StatusCode::FAILURE;
38 }
42
43 for (const xAOD::Muon* mu : *muons) {
44 using enum xAOD::Muon::TrackParticleType;
45 // no CT or ST muons
46 if (mu->primaryTrackParticle() == mu->trackParticle(InnerDetectorTrackParticle)) continue;
47 // no SA muons w/o ME tracks
48 if (mu->primaryTrackParticle() == mu->trackParticle(MuonSpectrometerTrackParticle)) continue;
49 const xAOD::TrackParticle* ptp = mu->primaryTrackParticle();
50 const std::vector<std::vector<unsigned int>>& chIds = acc_alignEffectChId(*ptp);
51 const std::vector<float>& alignEffSDT = acc_alligSigmaDeltaTrans(*ptp);
52
53 uint8_t prec{0}; // all precision layers
54 mu->summaryValue(prec, xAOD::numberOfPrecisionLayers);
55 const uint8_t nTotPrec = prec;
56 uint8_t nBadPrec{0}, nBadBar{0}, nBadSmall{0}, nBadLarge{0}, nGoodBar{0}, nGoodLarge{0}, nGoodSmall{0};
57
58 using namespace Muon::MuonStationIndex;
59 std::unordered_map<ChIndex, int> chamberQual{}; // 1=good, 2=bad; for choosing large/small
61 for (unsigned int i = 0; i < chIds.size(); ++i) {
63 for (unsigned int j = 0; j < chIds[i].size(); ++j) {
64 const auto currInd = static_cast<ChIndex>(chIds[i][j]);
65 const int quality = alignEffSDT[i] >= 0.5 ? badQualityFlag : goodQualityFlag;
66 if ((chamberQual.count(currInd) && chIds[i].size() > 1) || !chamberQual.count(currInd)) {
67 // either we haven't seen this chamber before, or we have but now
68 // we're in a sub-vector that's not just this chamber
69 chamberQual[currInd] = quality;
70 }
71 }
72 }
73 for (const auto& [chamber, quality] : chamberQual) {
74 const bool is_barrel = isBarrel(chamber);
75 const bool is_small = isSmall(chamber);
76 if (quality == badQualityFlag) {
77 ++nBadPrec;
78 nBadBar+= is_barrel;
79 nBadSmall+= is_small;
80 nBadLarge+= !is_small;
81 } else {
82 nGoodBar+= is_barrel;
83 nGoodLarge+= !is_small;
84 nGoodSmall+= is_small;
85 }
86 }
87 const uint8_t nGoodPrec = nTotPrec - nBadPrec;
88 const uint8_t nBadEnd = nBadPrec - nBadBar;
89 const uint8_t nGoodEnd = nGoodPrec - nGoodBar;
90 const bool countHits = (nGoodSmall == nGoodLarge) || (nBadSmall == nBadLarge);
91
92 uint8_t isSmall = (nGoodPrec >= nBadPrec&& nGoodSmall > nGoodLarge) || (nGoodPrec < nBadPrec&& nBadSmall > nBadLarge);
93 const uint8_t isEnd = (nGoodPrec >= nBadPrec&& nGoodEnd > nGoodBar) || (nGoodPrec < nBadPrec && nBadEnd >nBadBar );
94
95 static constexpr std::array<xAOD::MuonSummaryType, 4> small_sectors{xAOD::innerSmallHits, xAOD::middleSmallHits, xAOD::outerSmallHits, xAOD::extendedSmallHits};
96 static constexpr std::array<xAOD::MuonSummaryType, 4> large_sectors{xAOD::innerLargeHits, xAOD::middleLargeHits, xAOD::outerLargeHits, xAOD::extendedLargeHits};
97
98 if (countHits) { // decide large-small by counting hits
99 auto accumulator = [mu](int val, const xAOD::MuonSummaryType& sum) -> int{
100 uint8_t sumval = 0;
101 mu->summaryValue(sumval,sum);
102 return val +sumval;
103 };
104 const int nSmallHits = std::accumulate(small_sectors.begin(), small_sectors.end(),0 ,accumulator);
105 const int nLargeHits = std::accumulate(large_sectors.begin(), large_sectors.end(),0 ,accumulator);
106 isSmall = (nSmallHits > nLargeHits);
107 }
108 acc_precLayers(*mu) = nGoodPrec;
109 acc_isSmallGood(*mu) = isSmall;
110 acc_isEndcapGood(*mu) = isEnd;
111 }
112 return StatusCode::SUCCESS;
113 }
114
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainer
SG::ReadDecorHandleKeyArray< xAOD::TrackParticleContainer > m_trkAlignReadKey
SG::ReadHandleKeyArray< xAOD::TrackParticleContainer > m_TrackContainer
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_goodPrecLayerKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_isEndcapGoodLayersKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_isGoodSmallKey
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
bool isSmall(const ChIndex index)
Returns true if the chamber index is in a small sector.
bool isBarrel(const ChIndex index)
Returns true if the chamber index points to a barrel chamber.
ChIndex
enum to classify the different chamber layers in the muon spectrometer
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
@ numberOfPrecisionLayers
layers with at least 3 hits [unit8_t].
MuonSummaryType
Enumerates the different types of information stored in Summary.
@ outerSmallHits
number of precision hits in the outer small layer
@ middleSmallHits
number of precision hits in the middle small layer
@ outerLargeHits
number of precision hits in the outer large layer
@ middleLargeHits
number of precision hits in the middle large layer
@ extendedSmallHits
number of precision hits in the extended small layer
@ extendedLargeHits
number of precision hits in the extended large layer
@ innerLargeHits
number of precision hits in the inner large layer
@ innerSmallHits
number of precision hits in the inner small layer