ATLAS Offline Software
MuonPrecisionLayerDecorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "StoreGate/ReadHandle.h"
8 
9 namespace{
10  static const SG::AuxElement::ConstAccessor<std::vector<std::vector<unsigned int>>> acc_alignEffectChId("alignEffectChId");
11  static const SG::AuxElement::ConstAccessor<std::vector<float>> acc_alligSigmaDeltaTrans("alignEffectSigmaDeltaTrans");
12 }
13  MuonPrecisionLayerDecorAlg::MuonPrecisionLayerDecorAlg(const std::string& name, ISvcLocator* pSvcLocator):
14  AthReentrantAlgorithm(name,pSvcLocator){}
15 
17  ATH_CHECK(m_MuonContainer.initialize());
18  ATH_CHECK(m_TrackContainer.initialize());
19  m_trkAlignReadKey.clear();
21  m_trkAlignReadKey.emplace_back(trk.key()+".alignEffectChId");
22  }
23  ATH_CHECK(m_trkAlignReadKey.initialize());
24 
25  m_goodPrecLayerKey = m_MuonContainer.key() + ".numberOfGoodPrecisionLayers";
26  ATH_CHECK(m_goodPrecLayerKey.initialize());
27  m_isGoodSmallKey = m_MuonContainer.key() + ".isSmallGoodSectors";
28  ATH_CHECK(m_isGoodSmallKey.initialize());
29  m_isEndcapGoodLayersKey = m_MuonContainer.key() + ".isEndcapGoodLayers";
30  ATH_CHECK(m_isEndcapGoodLayersKey.initialize());
31  return StatusCode::SUCCESS;
32  }
33 
34  StatusCode MuonPrecisionLayerDecorAlg::execute(const EventContext& ctx) const {
36  if (!muons.isValid()) {
37  ATH_MSG_FATAL("Failed to load track collection "<<m_MuonContainer.fullKey());
38  return StatusCode::FAILURE;
39  }
43 
44  for (const xAOD::Muon* mu : *muons) {
45  // no CT or ST muons
46  if (mu->primaryTrackParticle() == mu->trackParticle(xAOD::Muon::InnerDetectorTrackParticle)) continue;
47  // no SA muons w/o ME tracks
48  if (mu->primaryTrackParticle() == mu->trackParticle(xAOD::Muon::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  std::map<Muon::MuonStationIndex::ChIndex, int> chamberQual; // 1=good, 2=bad; for choosing large/small
59  for (unsigned int i = 0; i < chIds.size(); ++i) {
60  for (unsigned int j = 0; j < chIds[i].size(); ++j) {
62  if (alignEffSDT[i] >= 0.5) {
63  if ((chamberQual.count(currInd) && chIds[i].size() > 1) || !chamberQual.count(currInd)) {
64  // either we haven't seen this chamber before, or we have but now
65  // we're in a sub-vector that's not just this chamber
66  chamberQual[currInd] = 2;
67  }
68  } else {
69  if ((chamberQual.count(currInd) && chIds[i].size() > 1) || !chamberQual.count(currInd)) {
70  // either we haven't seen this chamber before, or we have but now
71  // we're in a sub-vector that's not just this chamber
72  chamberQual[currInd] = 1;
73  }
74  }
75  }
76  }
77  for (const auto& it : chamberQual) {
78  const int chnum = it.first;
79  const bool is_barrel = chnum < 7;
80  const bool is_small = !(chnum %2);
81  if (it.second == 2) {
82  ++nBadPrec;
83  nBadBar+= is_barrel;
84  nBadSmall+= is_small;
85  nBadLarge+= !is_small;
86  } else {
87  nGoodBar+= is_barrel;
88  nGoodLarge+= !is_small;
89  nGoodSmall+= is_small;
90  }
91  }
92  const uint8_t nGoodPrec = nTotPrec - nBadPrec;
93  const uint8_t nBadEnd = nBadPrec - nBadBar;
94  const uint8_t nGoodEnd = nGoodPrec - nGoodBar;
95  const bool countHits = (nGoodSmall == nGoodLarge) || (nBadSmall == nBadLarge);
96 
97  uint8_t isSmall = (nGoodPrec >= nBadPrec&& nGoodSmall > nGoodLarge) || (nGoodPrec < nBadPrec&& nBadSmall > nBadLarge);
98  const uint8_t isEnd = (nGoodPrec >= nBadPrec&& nGoodEnd > nGoodBar) || (nGoodPrec < nBadPrec && nBadEnd >nBadBar );
99 
100  static constexpr std::array<xAOD::MuonSummaryType, 4> small_sectors{xAOD::innerSmallHits, xAOD::middleSmallHits, xAOD::outerSmallHits, xAOD::extendedSmallHits};
101  static constexpr std::array<xAOD::MuonSummaryType, 4> large_sectors{xAOD::innerLargeHits, xAOD::middleLargeHits, xAOD::outerLargeHits, xAOD::extendedLargeHits};
102 
103  if (countHits) { // decide large-small by counting hits
104  auto accumulator = [mu](int val, const xAOD::MuonSummaryType& sum) -> int{
105  uint8_t sumval = 0;
106  mu->summaryValue(sumval,sum);
107  return val +sumval;
108  };
109  const int nSmallHits = std::accumulate(small_sectors.begin(), small_sectors.end(),0 ,accumulator);
110  const int nLargeHits = std::accumulate(large_sectors.begin(), large_sectors.end(),0 ,accumulator);
111  isSmall = (nSmallHits > nLargeHits);
112  }
113  acc_precLayers(*mu) = nGoodPrec;
114  acc_isSmallGood(*mu) = isSmall;
115  acc_isEndcapGood(*mu) = isEnd;
116  }
117  return StatusCode::SUCCESS;
118  }
119 
MuonPrecisionLayerDecorAlg::m_isEndcapGoodLayersKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_isEndcapGoodLayersKey
Definition: MuonPrecisionLayerDecorAlg.h:44
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonPrecisionLayerDecorAlg::m_isGoodSmallKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_isGoodSmallKey
Definition: MuonPrecisionLayerDecorAlg.h:43
MuonPrecisionLayerDecorAlg::m_trkAlignReadKey
SG::ReadDecorHandleKeyArray< xAOD::TrackParticleContainer > m_trkAlignReadKey
Definition: MuonPrecisionLayerDecorAlg.h:38
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
skel.it
it
Definition: skel.GENtoEVGEN.py:423
MuonPrecisionLayerDecorAlg::m_MuonContainer
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainer
Definition: MuonPrecisionLayerDecorAlg.h:30
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
MuonPrecisionLayerDecorAlg::initialize
virtual StatusCode initialize() override
Definition: MuonPrecisionLayerDecorAlg.cxx:16
SG::ReadHandleKey< xAOD::TrackParticleContainer >
xAOD::MuonSummaryType
MuonSummaryType
Enumerates the different types of information stored in Summary.
Definition: TrackingPrimitives.h:324
MuonPrecisionLayerDecorAlg.h
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
xAOD::innerLargeHits
@ innerLargeHits
number of precision hits in the inner large layer
Definition: TrackingPrimitives.h:331
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAOD::middleLargeHits
@ middleLargeHits
number of precision hits in the middle large layer
Definition: TrackingPrimitives.h:333
MuonPrecisionLayerDecorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonPrecisionLayerDecorAlg.cxx:34
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
lumiFormat.i
int i
Definition: lumiFormat.py:92
xAOD::extendedLargeHits
@ extendedLargeHits
number of precision hits in the extended large layer
Definition: TrackingPrimitives.h:337
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h: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::middleSmallHits
@ middleSmallHits
number of precision hits in the middle small layer
Definition: TrackingPrimitives.h:332
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::outerSmallHits
@ outerSmallHits
number of precision hits in the outer small layer
Definition: TrackingPrimitives.h:334
MuonPrecisionLayerDecorAlg::m_TrackContainer
SG::ReadHandleKeyArray< xAOD::TrackParticleContainer > m_TrackContainer
Definition: MuonPrecisionLayerDecorAlg.h:33
xAOD::outerLargeHits
@ outerLargeHits
number of precision hits in the outer large layer
Definition: TrackingPrimitives.h:335
MuonPrecisionLayerDecorAlg::m_goodPrecLayerKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_goodPrecLayerKey
Definition: MuonPrecisionLayerDecorAlg.h:41
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
Muon::MuonStationIndex::ChIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
Definition: MuonStationIndex.h:15
MuonPrecisionLayerDecorAlg::MuonPrecisionLayerDecorAlg
MuonPrecisionLayerDecorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuonPrecisionLayerDecorAlg.cxx:13
jobOptions.prec
prec
Definition: jobOptions.Superchic_UPC_yyMuMu.py:20
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
xAOD::extendedSmallHits
@ extendedSmallHits
number of precision hits in the extended small layer
Definition: TrackingPrimitives.h:336
ReadHandle.h
Handle class for reading from StoreGate.
xAOD::innerSmallHits
@ innerSmallHits
number of precision hits in the inner small layer
Definition: TrackingPrimitives.h:330
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
xAOD::numberOfPrecisionLayers
@ numberOfPrecisionLayers
layers with at least 3 hits [unit8_t].
Definition: TrackingPrimitives.h:288