ATLAS Offline Software
Loading...
Searching...
No Matches
MuonFastRecoTester.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
13#include "CxxUtils/phihelper.h"
14
15namespace {
16 static const Muon::MuonSectorMapping sectorMap{};
17 void resize_all (const std::size_t nEle, const std::size_t size, auto&&... vecs) {
18 for (std::size_t idx = 0; idx < nEle; ++idx) {
19 (vecs[idx].resize(size), ...);
20 }
21 };
22 double inDegrees(double angle) {
23 return angle / Gaudi::Units::deg;
24 }
25}
26
27namespace MuonValR4 {
28 using namespace MuonR4;
29 using namespace MuonVal;
31 constexpr std::size_t s_nStations {Acts::toUnderlying(StIndex::StIndexMax)};
33 std::optional<std::size_t> isTruthMatched (const xAOD::MuonMeasurement& meas,
34 const TruthParticleMap& truthHits) {
36 if (!hit) return std::nullopt;
37 std::size_t idx{0};
38 for (const auto& [tp, truthHitSets] : truthHits) {
39 for (const auto& truthHitSet : truthHitSets) {
40 if (std::ranges::contains(truthHitSet, hit)) {
41 if (tp) return idx;
42 else return truthHits.size(); // Pileup muon
43 }
44 }
45 if (tp) ++idx;
46 }
47 return std::nullopt;
48 };
49 bool isInPattern (const SpacePoint* sp,
50 const StIndex station,
51 const GlobalPattern& pattern){
52 for (const SpacePoint* hit : pattern.hitsInStation(station)) {
53 if (hit == sp) return true;
54 }
55 return false;
56 };
57
59 ATH_CHECK(m_geoCtxKey.initialize());
60 {
61 int infoOpts = 0;
62 if (m_isMC) infoOpts = EventInfoBranch::isMC;
63 m_tree.addBranch(std::make_unique<EventInfoBranch>(m_tree, infoOpts));
64 }
65 ATH_CHECK(m_spKey.initialize(!m_spKey.empty()));
66 ATH_CHECK(m_NSWspKey.initialize(!m_NSWspKey.empty()));
69 if (!m_spKey.empty()) {
70 m_spTester = std::make_shared<SpacePointTesterModule>(m_tree, m_spKey.key(), msgLevel(), "Muon");
71 m_tree.addBranch(m_spTester);
72 if (!m_isMC) m_tree.disableBranch(m_spMatchedToTruth.name());
73 }
74 if (!m_NSWspKey.empty()) {
75 m_NSWspTester = std::make_shared<SpacePointTesterModule>(m_tree, m_NSWspKey.key(), msgLevel(), "Nsw");
76 m_tree.addBranch(m_NSWspTester);
77 if (!m_isMC) m_tree.disableBranch(m_NSWspMatchedToTruth.name());
78 }
79 } else {
80 m_tree.disableBranch(m_spType.name());
81 m_tree.disableBranch(m_NSWspType.name());
82 m_tree.disableBranch(m_spMatchedToPattern.name());
83 m_tree.disableBranch(m_NSWspMatchedToPattern.name());
84 m_tree.disableBranch(m_spMatchedToTruth.name());
85 m_tree.disableBranch(m_NSWspMatchedToTruth.name());
86 }
87 if (!m_isMC) {
88 m_tree.disableBranch(m_gen_Eta.name());
89 m_tree.disableBranch(m_gen_Phi.name());
90 m_tree.disableBranch(m_gen_Pt.name());
91 m_tree.disableBranch(m_gen_Q.name());
92 m_tree.disableBranch(m_pat_nTruthNonPrecMeas.name());
93 m_tree.disableBranch(m_pat_nTruthPrecMeas.name());
94 m_tree.disableBranch(m_pat_nTruthPhiMeas.name());
95 m_tree.disableBranch(m_pat_MatchedToTruth.name());
96 }
97 if (!m_isSeededReco) {
98 m_tree.disableBranch(m_roi_EtaMin.name());
99 m_tree.disableBranch(m_roi_EtaMax.name());
100 m_tree.disableBranch(m_roi_PhiMin.name());
101 m_tree.disableBranch(m_roi_PhiMax.name());
102 m_tree.disableBranch(m_roi_ZMin.name());
103 m_tree.disableBranch(m_roi_ZMax.name());
104 }
105 ATH_CHECK(m_patternKey.initialize());
106 ATH_CHECK(m_fastMuonKey.initialize());
107 ATH_CHECK(m_truthSegmentKey.initialize(!m_truthSegmentKey.empty()));
108 ATH_CHECK(m_tree.init(this));
109 ATH_CHECK(m_idHelperSvc.retrieve());
110 return StatusCode::SUCCESS;
111 }
112
114 ATH_CHECK(m_tree.write());
115 return StatusCode::SUCCESS;
116 }
117 StatusCode MuonFastRecoTester::execute(const EventContext& ctx) {
118
119 //const ActsTrk::GeometryContext* gctxPtr{nullptr};
120 //ATH_CHECK(SG::get(gctxPtr, m_geoCtxKey, ctx));
121
122 const SpacePointContainer* spContainer {nullptr};
123 ATH_CHECK(SG::get(spContainer, m_spKey, ctx));
124
125 const SpacePointContainer* NSWspContainer {nullptr};
126 ATH_CHECK(SG::get(NSWspContainer, m_NSWspKey, ctx));
127
128 const GlobalPatternContainer* globPatterns{nullptr};
129 ATH_CHECK(SG::get(globPatterns, m_patternKey, ctx));
130
131 const xAOD::MuonContainer* fastMuons{nullptr};
132 ATH_CHECK(SG::get(fastMuons, m_fastMuonKey, ctx));
133
134 const xAOD::MuonSegmentContainer* readTruthSegments{nullptr};
135 if(m_isMC){
136 ATH_CHECK(SG::get(readTruthSegments , m_truthSegmentKey, ctx));
137 }
138 const TrigRoiDescriptorCollection* roiCollection{nullptr};
139 if(m_isSeededReco) {
140 ATH_CHECK(SG::get(roiCollection, m_roiCollectionKey, ctx));
141 }
142
143 ATH_MSG_DEBUG("Succesfully retrieved input collections: Global Patterns: "<<globPatterns->size()
144 <<", truth segments: "<<(readTruthSegments? std::to_string(readTruthSegments->size()) : std::to_string(-1))
145 <<", Rois: "<<(roiCollection ? std::to_string(roiCollection->size()) : std::to_string(-1)));
146
147 const TruthParticleMap truthMap{fillTruthMap(readTruthSegments, roiCollection)};
148 fillTruthInfo(truthMap, {spContainer, NSWspContainer});
149 fillRoIInfo(roiCollection);
150
151 if (m_writeSpacePoints) {
152 fillSpacePointInfo(spContainer, globPatterns, truthMap,
154 fillSpacePointInfo(NSWspContainer, globPatterns, truthMap,
156 }
157 fillGlobPatternInfo(globPatterns, truthMap,
158 std::vector<const MuonR4::SpacePointContainer*>{spContainer, NSWspContainer});
159
160 fillFastRecoMuonInfo(fastMuons, globPatterns);
161
162 ATH_CHECK(m_tree.fill(ctx));
163 return StatusCode::SUCCESS;
164 }
166 const TrigRoiDescriptorCollection* roiCollection) const {
167 if (!truthSegments) return TruthParticleMap{};
168 ATH_MSG_VERBOSE("Filling truth map with "<<truthSegments->size());
170 auto isInROI = [roiCollection](const xAOD::TruthParticle* tp) {
171 for (const TrigRoiDescriptor* roi : *roiCollection) {
173 if (tp->eta() < roi->etaMinus() || tp->eta() > roi->etaPlus()) continue;
175 const double dPhiPlus = CxxUtils::deltaPhi(roi->phiPlus(), tp->phi());
176 const double dPhiMinus = CxxUtils::deltaPhi(roi->phiMinus(), tp->phi());
177 if (dPhiPlus >= 0. && dPhiMinus <= 0.) return true;
178 }
179 return false;
180 };
181
182 TruthParticleMap truthMap{};
183 for (const xAOD::MuonSegment* truth : *truthSegments) {
185 // In case of seeded reco, we only save truth particles that are in the RoIs
186 if (!m_isSeededReco || !tp || isInROI(tp)){
187 truthMap[tp].push_back(getMatchingSimHits(*truth));
188 }
189 }
190 return truthMap;
191 }
193 const std::vector<const MuonR4::SpacePointContainer*>& spContainers) {
194 if (!m_isMC || truthHits.empty()) return;
195 resize_all(truthHits.size(), s_nStations,
197 using enum measType;
198 using LayerBookeeper = std::unordered_map<const MuonGMR4::SpectrometerSector*, std::set<unsigned>>;
199 using MeasBookeeper = std::array<std::vector<const SpacePoint*>, Acts::toUnderlying(nTypes)>;
201 MeasBookeeper measInStation{};
202 LayerBookeeper seenEtaLayers{};
203 LayerBookeeper seenPhiLayers{};
204
205 auto processMeas = [&truthHits, &measInStation, &seenEtaLayers, &seenPhiLayers, this]
206 (const SpacePoint* sp, const measType type, const bool process2Dmeas, const int tpIdx, const std::size_t stIdx) {
208 const bool isPrec {MuonR4::isPrecisionHit(*sp)};
209 if ((type == Prec && !isPrec) ||
210 (type == NonPrec && (isPrec || !sp->measuresEta())) || (type == Phi && sp->measuresEta())) {
211 return;
212 }
213 /* Check if the hit has already been counted, i.e. duplicated hits. Needed for precision hits, since we can have multiple on the same layer */
214 std::vector<const SpacePoint*>& outCont {measInStation[Acts::toUnderlying(type)]};
215 if (std::ranges::find_if(outCont, [sp](const SpacePoint* s) {
216 return s->primaryMeasurement() == sp->primaryMeasurement(); }) != outCont.end()) {
217 return;
218 }
220 if (isTruthMatched(*sp->primaryMeasurement(), truthHits) != tpIdx) return;
221
222 const bool isDoubleMatched {sp->dimension() == 2u && sp->secondaryMeasurement() && isTruthMatched(*sp->secondaryMeasurement(), truthHits) == tpIdx};
223 if (process2Dmeas && !isDoubleMatched) return;
224
225 /* Check if we have already measurements in the same layer, except for precision hits */
226 const unsigned layNum {m_spSorter.sectorLayerNum(*sp)};
227
228 if (sp->measuresEta()) {
229 const bool isSeenLayer {seenEtaLayers[sp->msSector()].count(layNum) > 0};
230 if (isSeenLayer && !sp->isStraw()) return;
231 if (!isSeenLayer) seenEtaLayers[sp->msSector()].insert(layNum);
232 auto& measCounter = isPrec ? m_gen_nPrecMeas : m_gen_nNonPrecMeas;
233 ++measCounter[tpIdx][stIdx];
234
235 // Eta hit can also have phi measurements. For combined spacepoints, need to be check the secondaty measurements. No need for 2D spacepoints.
236 if (sp->measuresPhi() && isDoubleMatched) {
237 seenPhiLayers[sp->msSector()].insert(layNum);
238 ++m_gen_nPhiMeas[tpIdx][stIdx];
239 measInStation[Acts::toUnderlying(Phi)].push_back(sp);
240 }
241 } else {
242 if (seenPhiLayers[sp->msSector()].count(layNum) > 0) return;
243 seenPhiLayers[sp->msSector()].insert(layNum);
244 ++m_gen_nPhiMeas[tpIdx][stIdx];
245 }
246 outCont.push_back(sp);
247 ATH_MSG_VERBOSE("---> "<<(isPrec ? "Prec" : (type == NonPrec ? "Trig" : "Phi "))<< " " << *sp << " in sector "<<sp->msSector()->identString() << " lay "<<layNum);
248 };
249
250 int tpIdx{-1};
251 for (const auto& [tp, _] : truthHits) {
252 if(!tp) continue;
253 m_gen_Eta.push_back(tp->eta());
254 m_gen_Phi.push_back(tp->phi());
255 m_gen_Pt.push_back(tp->pt());
256 m_gen_Q.push_back(tp->charge());
257 ++tpIdx;
258 // Save the sectors compatible for the tp
259 std::vector<int> sectors{};
260 sectorMap.getSectors(tp->phi(), sectors);
261 const int side {tp->eta() > 0 ? 1 : -1};
264 ATH_MSG_VERBOSE("tp: " << tpIdx << ", Eta: " << tp->eta() << ", Phi: " << inDegrees(tp->phi()) << ", Pt [GeV]: " << tp->pt() * 1e-3 << ", Q: " << tp->charge());
265 for (std::size_t stIdx = 0; stIdx < s_nStations; ++stIdx) {
266 ATH_MSG_VERBOSE("\tStation "<< stName(static_cast<StIndex>(stIdx)) << ": matched hits before layer deduplication: ");
267 // Clear the bookkeeping structures for the new station
268 for (auto& vec : measInStation) vec.clear();
269 seenEtaLayers.clear();
270 seenPhiLayers.clear();
271 // We fill per measurement type, so we give priority to precision hits if they are in the same layer as trigger hits, e.g. sTGCs
272 for (const measType type : {Prec, NonPrec, Phi}) {
273 // We fill first 2D measurements and then 1D ones
274 for (const bool process2Dmeas : {true, false}) {
275 for (const auto& spContainer : spContainers) {
276 if (!spContainer) continue;
277 for (const SpacePointBucket* bucket : *spContainer) {
279 if (static_cast<std::size_t>(m_idHelperSvc->stationIndex(bucket->front()->identify())) != stIdx) continue;
281 if (bucket->msSector()->side() != side ||
282 std::ranges::none_of(sectors, [&](int s){ return bucket->msSector()->sector() == s; })) {
283 continue;
284 }
285 for (const auto& sp : *bucket) {
286 /* Process first the precision hits, 2D measurements first and then 1D */
287 processMeas(sp.get(), type, process2Dmeas, tpIdx, stIdx);
288 }
289 } // End loop over buckets
290 } // End loop over containers
291 } // End loop over "process2Dmeas" flag
292 } // End loop over measurement types
293 if (msgLevel(MSG::VERBOSE)) {
294 const auto gen_nNonPrecHits {static_cast<unsigned>(m_gen_nNonPrecMeas[tpIdx][stIdx])};
295 const auto gen_nPrecHits {static_cast<unsigned>(m_gen_nPrecMeas[tpIdx][stIdx])};
296 const auto gen_nPhiHits {static_cast<unsigned>(m_gen_nPhiMeas[tpIdx][stIdx])};
297 if (gen_nNonPrecHits + gen_nPrecHits + gen_nPhiHits > 0) {
298 ATH_MSG_VERBOSE("\t after deduplication: N trig/Prec/phi meas: "
299 << gen_nNonPrecHits << "/" << gen_nPrecHits << "/" << gen_nPhiHits);
300 }
301 }
302
303 } // End loop over stations
304 } // End loop over truth particles
305 }
307 if (!m_isSeededReco || !roiCollection || roiCollection->empty()) return;
308 for (const TrigRoiDescriptor* roi : *roiCollection) {
309 m_roi_EtaMin.push_back(roi->etaMinus());
310 m_roi_EtaMax.push_back(roi->etaPlus());
311 m_roi_PhiMin.push_back(roi->phiMinus());
312 m_roi_PhiMax.push_back(roi->phiPlus());
313 m_roi_ZMin.push_back(roi->zedMinus());
314 m_roi_ZMax.push_back(roi->zedPlus());
315 }
316 }
318 const MuonR4::GlobalPatternContainer* patternCont,
319 const TruthParticleMap& truthHits,
320 SpacePointTesterModule& spTester,
322 MuonVal::MatrixBranch<unsigned char>& spMatchedToPatternBranch,
323 MuonVal::MatrixBranch<unsigned char>& spMatchedToTruthBranch) const {
324 if (!spc) return;
325 for (const SpacePointBucket* bucket : *spc) {
326 for (const auto& sp : *bucket) {
328 spTypeBranch.push_back(Acts::toUnderlying(type));
329 if(!m_isMC) continue;
330 if (const auto tpIdx {isTruthMatched(*sp->primaryMeasurement(), truthHits)}; tpIdx.has_value()) {
331 unsigned treeIdx = spTester.push_back(*sp);
332 spMatchedToTruthBranch[tpIdx.value()].push_back(treeIdx);
333 }
334 }
335 }
336 std::size_t patternIdx{0};
337 for (const GlobalPattern* pattern : *patternCont) {
338 for (const StIndex station : pattern->getStations()) {
339 for (const SpacePoint* sp : pattern->hitsInStation(station)) {
340 unsigned treeIdx = spTester.push_back(*sp);
341 spMatchedToPatternBranch[patternIdx].push_back(treeIdx);
342 }
343 }
344 ++patternIdx;
345 }
346 }
348 const TruthParticleMap& truthHits,
349 const std::vector<const MuonR4::SpacePointContainer*>& spContainers) {
350 m_pat_n = patternCont->size();
351 // Resize all the matrix branches
352 resize_all(patternCont->size(), s_nStations,
356 if (m_isMC) {
357 resize_all(patternCont->size(), s_nStations,
360 }
361 auto isSecondaryMatched = [&truthHits](const SpacePoint* sp, std::size_t tpIdx) {
362 return sp->secondaryMeasurement() && isTruthMatched(*sp->secondaryMeasurement(), truthHits) == tpIdx;
363 };
364 std::size_t patternIdx{0};
365 for (const GlobalPattern* pattern : *patternCont) {
366 // We define a map of truth particles and associated hits for the current pattern, so we can determine the main truth particle is multiple are associated
367 std::unordered_map<std::size_t, std::vector<const SpacePoint*>> patternTruthHits{};
368
369 const std::vector<StIndex> stations {pattern->getStations()};
370 for (const StIndex station : stations) {
371 for (const SpacePoint* sp : pattern->hitsInStation(station)) {
372 updatePatHitInfo(ePatBranchType::eReco, patternIdx, station, sp);
373
374 if (!m_isMC) continue;
375 if (const auto tpIdx {isTruthMatched(*sp->primaryMeasurement(), truthHits)}; tpIdx.has_value()) {
376 // By convention, if truth particle index is equal to the size of the truth map, it means it's a pileup particle
377 if (*tpIdx >= truthHits.size() ) {
378 updatePatHitInfo(ePatBranchType::ePileup, patternIdx, station, sp, isSecondaryMatched(sp, *tpIdx));
379 } else {
380 patternTruthHits[*tpIdx].push_back(sp);
381 }
382 }
383 }
384 }
385 if (!patternTruthHits.empty()) {
386 // Sort the TPs by number of matched hits and define the main truth particle as the one with the most hits in the pattern
387 std::vector<std::size_t> sortedTPs {};
388 std::ranges::transform(patternTruthHits, std::back_inserter(sortedTPs), [](const auto& pair){ return pair.first; });
389 std::ranges::sort(sortedTPs, [&patternTruthHits](const auto& a, const auto& b){
390 return patternTruthHits.at(a).size() > patternTruthHits.at(b).size();
391 });
392 const auto mainTP = sortedTPs.front();
393 for (const SpacePoint* sp : patternTruthHits[mainTP]) {
394 const StIndex station {m_idHelperSvc->stationIndex(sp->identify())};
395 updatePatHitInfo(ePatBranchType::eTruth, patternIdx, station, sp, isSecondaryMatched(sp, mainTP));
396 }
397 // Add truth hits that are matched to other truth particles than the main one
398 for (const auto& [tpIdx, hits] : patternTruthHits) {
399 if (tpIdx == mainTP) continue;
400 for (const SpacePoint* sp : hits) {
401 const StIndex station {m_idHelperSvc->stationIndex(sp->identify())};
402 updatePatHitInfo(ePatBranchType::eMismatched, patternIdx, station, sp, isSecondaryMatched(sp, tpIdx));
403 }
404 }
405 // Save the matched truth particle index in the tree, either is a signal or pileup particle
406 std::ranges::transform(sortedTPs, std::back_inserter(m_pat_MatchedToTruth[patternIdx]), [](const std::size_t& tp){ return tp; });
407 }
408 // Loop over the space point containers to count the number of hits in the buckets crossed by the pattern
409 for (const SpacePointContainer* spContainer : spContainers) {
410 if (!spContainer) continue;
411 for (const SpacePointBucket* bucket : *spContainer) {
412 bool bucketInPattern{false};
413 const StIndex bucketStation {m_idHelperSvc->stationIndex(bucket->front()->identify())};
414 std::vector<const SpacePoint*> allHits{};
415
416 for (const auto& sp : *bucket) {
417 if (isInPattern(sp.get(), bucketStation, *pattern)) {
418 bucketInPattern = true;
419 }
420 allHits.push_back(sp.get());
421 }
422 if (bucketInPattern) {
423 for (const SpacePoint* sp : allHits) {
424 updatePatHitInfo(ePatBranchType::eAll, patternIdx, bucketStation, sp);
425 }
426 }
427 }
428 }
429 m_pat_Eta.push_back(-std::log(std::tan(pattern->theta()/2.)));
430 m_pat_phi.push_back(pattern->phi());
431 m_pat_sector1.push_back(pattern->sector());
432 m_pat_sector2.push_back(pattern->secondarySector());
433 m_pat_meanNormResidual2.push_back(pattern->meanNormResidual2());
434 m_pat_side.push_back(pattern->hitsInStation(stations.front()).front()->msSector()->side());
435 m_pat_nStations.push_back(stations.size());
436
437 if (msgLevel(MSG::VERBOSE)) {
438 const auto mainTP {m_pat_MatchedToTruth[patternIdx].size() > 0 ? static_cast<int>(m_pat_MatchedToTruth[patternIdx].front()) : -1};
439 unsigned nPrecHits{0}, nNonPrecHits{0}, nPhiHits{0};
440 unsigned gen_nPrecHits{0}, gen_nNonPrecHits{0}, gen_nPhiHits{0};
441 for (std::size_t stIdx = 0; stIdx < s_nStations; ++stIdx) {
442 nPrecHits += static_cast<unsigned>(m_pat_nTruthPrecMeas[patternIdx][stIdx]);
443 nNonPrecHits += static_cast<unsigned>(m_pat_nTruthNonPrecMeas[patternIdx][stIdx]);
444 nPhiHits += static_cast<unsigned>(m_pat_nTruthPhiMeas[patternIdx][stIdx]);
445 if (mainTP < 0) continue;
446 gen_nPrecHits += static_cast<unsigned>(m_gen_nPrecMeas[mainTP][stIdx]);
447 gen_nNonPrecHits += static_cast<unsigned>(m_gen_nNonPrecMeas[mainTP][stIdx]);
448 gen_nPhiHits += static_cast<unsigned>(m_gen_nPhiMeas[mainTP][stIdx]);
449 }
450 ATH_MSG_VERBOSE("Pat #" << patternIdx<< ": " << *pattern << "mainTP: "<<std::to_string(mainTP)
451 <<", nTruthMatchedHits Trig: "<<nNonPrecHits<<" / "<<gen_nNonPrecHits<<", Prec: "<<nPrecHits<<" / "<<gen_nPrecHits<<", Phi: "<<nPhiHits<<" / "<<gen_nPhiHits);
452 }
453 patternIdx++;
454 }
455 }
457 const GlobalPatternContainer* patternCont) {
458 if (!fastMuons) return;
459
460
461 for (const xAOD::Muon* mu : *fastMuons) {
462 m_muon_Eta.push_back(mu->eta());
463 m_muon_Phi.push_back(mu->phi());
464 m_muon_Pt.push_back(mu->pt());
465 m_muon_Q.push_back(mu->charge());
466
467 auto patItr {std::ranges::find(*patternCont, FastReco::getParentPattern(*mu))};
468 assert(patItr != patternCont->end());
469 const std::size_t patIdx = std::distance(patternCont->begin(), patItr);
470 m_muon_MatchedToPattern.push_back(patIdx);
471
472 ATH_MSG_VERBOSE("FastMuonSA eta: "<<mu->eta()<<", phi[Deg]: "<<inDegrees(mu->phi())
473 <<", pt[GeV]: "<<mu->pt()/Gaudi::Units::GeV<<", q: "<<mu->charge());
474 }
475 }
477 const std::size_t patIdx,
479 const MuonR4::SpacePoint* sp,
480 const bool isSecondaryMatched) {
481 using enum ePatBranchType;
482 const bool isTruthInfo = (type == ePatBranchType::eTruth || type == ePatBranchType::eMismatched);
483 const auto updateCounts = [&](unsigned char& nonPrecCount,
484 unsigned char& precCount,
485 unsigned char& phiCount) {
486 if (sp->measuresEta()) {
487 if (MuonR4::isPrecisionHit(*sp)) precCount++;
488 else nonPrecCount++;
490 ATH_MSG_VERBOSE("---> "<<(MuonR4::isPrecisionHit(*sp) ? "Prec" : "Trig")<< " " << *sp << " in sector "<<sp->msSector()->identString() << " lay "<<m_spSorter.sectorLayerNum(*sp));
491 }
492 }
493 if (sp->measuresPhi() && (!isTruthInfo || isSecondaryMatched)) {
494 ++phiCount;
496 ATH_MSG_VERBOSE("---> "<<"Phi " << *sp << " in sector "<<sp->msSector()->identString() << " lay "<<m_spSorter.sectorLayerNum(*sp));
497 }
498 }
499 };
500 const auto stIdx = Acts::toUnderlying(hitSt);
501 switch (type) {
502 case eReco:
503 updateCounts(m_pat_nNonPrecMeas[patIdx][stIdx],
504 m_pat_nPrecMeas[patIdx][stIdx], m_pat_nPhiMeas[patIdx][stIdx]);
505 return;
506 case eTruth:
507 updateCounts(m_pat_nTruthNonPrecMeas[patIdx][stIdx],
508 m_pat_nTruthPrecMeas[patIdx][stIdx], m_pat_nTruthPhiMeas[patIdx][stIdx]);
509 return;
510 case eMismatched:
511 updateCounts(m_pat_nMisTruthNonPrecMeas[patIdx][stIdx],
512 m_pat_nMisTruthPrecMeas[patIdx][stIdx], m_pat_nMisTruthPhiMeas[patIdx][stIdx]);
513 return;
514 case eAll:
515 updateCounts(m_pat_nAllNonPrecMeas[patIdx][stIdx],
516 m_pat_nAllPrecMeas[patIdx][stIdx], m_pat_nAllPhiMeas[patIdx][stIdx]);
517 return;
518 case ePileup:
519 updateCounts(m_pat_nPileupNonPrecMeas[patIdx][stIdx],
520 m_pat_nPileupPrecMeas[patIdx][stIdx], m_pat_nPileupPhiMeas[patIdx][stIdx]);
521 return;
522 }
523 }
524} // namespace MuonValR4
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_VERBOSE(x,...)
std::vector< size_t > vec
bool hit(const Container &ids, int pdgId)
static Double_t sp
static Double_t a
size_t size() const
Number of registered mappings.
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
Data class to represent an eta maximum in hough space.
: The muon space point bucket represents a collection of points that will bre processed together in t...
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
void fillTruthInfo(const TruthParticleMap &truthHits, const std::vector< const MuonR4::SpacePointContainer * > &spContainers)
Fill the truth particle information into the tree.
MuonVal::VectorBranch< float > & m_gen_Phi
MuonVal::MatrixBranch< unsigned char > & m_pat_nAllNonPrecMeas
Number of trigger eta measurements in the buckets crossed by the pattern, grouped by station.
MuonVal::VectorBranch< unsigned char > & m_spType
Type of spacepoints: 1 for trigger eta, 2 for precision, 3 for only-phi.
MuonVal::VectorBranch< float > & m_roi_ZMax
SG::ReadHandleKey< MuonR4::SpacePointContainer > m_NSWspKey
ActsTrk::GeoContextReadKey_t m_geoCtxKey
MuonVal::MatrixBranch< unsigned char > & m_pat_nNonPrecMeas
Number of trigger eta measurements per station.
measType
Enum for measurement types.
SG::ReadHandleKey< xAOD::MuonContainer > m_fastMuonKey
MuonVal::MatrixBranch< unsigned char > & m_pat_nAllPhiMeas
Number of phi measurements in the buckets crossed by the pattern, grouped by station.
MuonVal::MatrixBranch< unsigned char > & m_pat_nTruthPrecMeas
Number of truth precision measurements per station.
SG::ReadHandleKey< MuonR4::GlobalPatternContainer > m_patternKey
MuonVal::ScalarBranch< unsigned > & m_pat_n
====== Global Pattern block ===========
MuonVal::MatrixBranch< unsigned char > & m_spMatchedToPattern
Branch indicating which space points in the tree are associated to the i-th pattern.
MuonVal::VectorBranch< unsigned char > & m_muon_MatchedToPattern
MuonVal::MatrixBranch< unsigned char > & m_pat_nMisTruthPhiMeas
Number of mismatched truth phi measurements per station.
MuonVal::VectorBranch< unsigned char > & m_pat_nStations
Number of stations.
MuonVal::MatrixBranch< unsigned char > & m_NSWspMatchedToTruth
MuonVal::MatrixBranch< unsigned char > & m_pat_nPileupPhiMeas
Number of pileup phi measurements per station.
void fillRoIInfo(const TrigRoiDescriptorCollection *roiCollection)
Fill the RoI information into the tree.
MuonVal::VectorBranch< uint16_t > & m_pat_sector2
MuonVal::VectorBranch< float > & m_gen_Eta
MuonVal::MatrixBranch< unsigned char > & m_pat_nAllPrecMeas
Number of precision measurements in the buckets crossed by the pattern, grouped by station.
MuonVal::MatrixBranch< unsigned char > & m_pat_nPileupPrecMeas
Number of pileup precision measurements per station.
MuonVal::VectorBranch< float > & m_muon_Pt
MuonVal::VectorBranch< float > & m_pat_phi
MuonVal::VectorBranch< short > & m_muon_Q
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roiCollectionKey
std::map< const xAOD::TruthParticle *, std::vector< simHitSet > > TruthParticleMap
MuonVal::VectorBranch< short > & m_gen_Q
====== Truth particle block ===========
virtual StatusCode finalize() override
MuonVal::MatrixBranch< unsigned char > & m_gen_nPrecMeas
Number of precision measurements per station.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
void updatePatHitInfo(const ePatBranchType type, const std::size_t patIdx, const Muon::MuonStationIndex::StIndex hitSt, const MuonR4::SpacePoint *sp, const bool isSecondaryMatched=false)
Update the hit counts for a given pattern branch type.
ePatBranchType
Enum for different types of pattern hit content branches.
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_truthSegmentKey
MuonVal::VectorBranch< float > & m_roi_EtaMin
====== RoI info ===========
MuonVal::MatrixBranch< unsigned char > & m_pat_nTruthPhiMeas
Number of truth phi measurements per station.
void fillFastRecoMuonInfo(const xAOD::MuonContainer *muonCont, const MuonR4::GlobalPatternContainer *patternCont)
Fill the info associated to fast reco muons.
std::shared_ptr< SpacePointTesterModule > m_NSWspTester
MuonVal::VectorBranch< float > & m_roi_PhiMin
MuonVal::VectorBranch< float > & m_roi_PhiMax
std::shared_ptr< SpacePointTesterModule > m_spTester
====== Spacepoint block ===========
MuonVal::MatrixBranch< unsigned char > & m_pat_nTruthNonPrecMeas
Number of truth trigger eta measurements per station.
virtual StatusCode initialize() override
MuonVal::MatrixBranch< unsigned char > & m_pat_nPhiMeas
Number of phi measurements per station.
MuonVal::MatrixBranch< unsigned char > & m_pat_nPrecMeas
Number of precision measurements per station.
MuonVal::VectorBranch< float > & m_muon_Phi
MuonVal::VectorBranch< float > & m_roi_EtaMax
MuonVal::VectorBranch< float > & m_pat_meanNormResidual2
mean square normalized pattern residual
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
MuonVal::VectorBranch< float > & m_gen_Pt
void fillSpacePointInfo(const MuonR4::SpacePointContainer *spc, const MuonR4::GlobalPatternContainer *patternCont, const TruthParticleMap &truthHits, SpacePointTesterModule &spTester, MuonVal::VectorBranch< unsigned char > &spTypeBranch, MuonVal::MatrixBranch< unsigned char > &spMatchedToPatternBranch, MuonVal::MatrixBranch< unsigned char > &spMatchedToTruthBranch) const
Fill the space point information into the tree.
MuonVal::MatrixBranch< unsigned char > & m_pat_nMisTruthNonPrecMeas
Number of mismatched truth trigger eta measurements per station.
MuonVal::VectorBranch< unsigned char > & m_NSWspType
void fillGlobPatternInfo(const MuonR4::GlobalPatternContainer *patternCont, const TruthParticleMap &truthHits, const std::vector< const MuonR4::SpacePointContainer * > &spContainers)
Fill the info associated to the global patterns into the tree.
MuonVal::VectorBranch< uint16_t > & m_pat_sector1
pattern primary & secondary sectors (different if the pattern is in the sector overlap)
MuonVal::MatrixBranch< unsigned char > & m_NSWspMatchedToPattern
MuonVal::MatrixBranch< unsigned char > & m_pat_nMisTruthPrecMeas
Number of mismatched truth precision measurements per station.
MuonVal::MuonTesterTree m_tree
MuonVal::VectorBranch< float > & m_muon_Eta
====== Fast Reco Muon info ===========
MuonVal::VectorBranch< short > & m_pat_side
+1 for A-, -1 of C-side
MuonVal::MatrixBranch< unsigned char > & m_pat_MatchedToTruth
Branch indicating which truth particles in the tree are associated to the i-th pattern.
MuonR4::SpacePointPerLayerSorter m_spSorter
MuonVal::MatrixBranch< unsigned char > & m_spMatchedToTruth
Branch indicating which space points in the tree are associated to the i-th truth particle.
MuonVal::MatrixBranch< unsigned char > & m_gen_nPhiMeas
Number of phi measurements per station.
MuonVal::MatrixBranch< unsigned char > & m_pat_nPileupNonPrecMeas
Number of pileup trigger eta measurements per station.
MuonVal::VectorBranch< float > & m_pat_Eta
pattern average theta & phi
MuonVal::MatrixBranch< unsigned char > & m_gen_nNonPrecMeas
Number of trigger eta measurements per station.
SG::ReadHandleKey< MuonR4::SpacePointContainer > m_spKey
TruthParticleMap fillTruthMap(const xAOD::MuonSegmentContainer *truthSegments, const TrigRoiDescriptorCollection *roiCollection) const
Fill the truth particle map.
MuonVal::VectorBranch< float > & m_roi_ZMin
unsigned int push_back(const MuonR4::SpacePointBucket &bucket)
@ isMC
Flag determining whether the branch is simulation.
void push_back(size_t i, const T &value)
void push_back(const T &value)
Adds a new element at the end of the vector.
void getSectors(double phi, std::vector< int > &sectors) const
returns the main sector plus neighboring if the phi position is in an overlap region
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
STL class.
constexpr T deltaPhi(T phiA, T phiB)
Return difference phiA - phiB in range [-pi, pi].
Definition phihelper.h:64
const GlobalPattern * getParentPattern(const xAOD::MuonSegment &segment)
Retrieve the parent global pattern of the segment.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::MuonMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
std::vector< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
DataVector< GlobalPattern > GlobalPatternContainer
Abrivation of the GlobalPattern container type.
bool isPrecisionHit(const SpacePoint &hit)
Returns whether the uncalibrated spacepoint is a precision hit (Mdt, micromegas, stgc strips).
DataVector< SpacePointBucket > SpacePointContainer
Abrivation of the space point container type.
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
bool isInPattern(const SpacePoint *sp, const StIndex station, const GlobalPattern &pattern)
MuonFastRecoTester::TruthParticleMap TruthParticleMap
constexpr std::size_t s_nStations
std::optional< std::size_t > isTruthMatched(const xAOD::MuonMeasurement &meas, const TruthParticleMap &truthHits)
StIndex
enum to classify the different station layers in the muon spectrometer
const std::string & stName(StIndex index)
convert StIndex into a string
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
MuonMeasurement_v1 MuonMeasurement
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12
TruthParticle_v1 TruthParticle
Typedef to implementation.
Muon_v1 Muon
Reference the current persistent version:
Definition Muon.h:13
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
MuonSegment_v1 MuonSegment
Reference the current persistent version:
Helper for azimuthal angle calculations.