ATLAS Offline Software
Loading...
Searching...
No Matches
ChamberViewer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef XAODMUONPREPDATA_CHAMBERVIEWER_H
5#define XAODMUONPREPDATA_CHAMBERVIEWER_H
6
7
8
11
12#include "Acts/Utilities/PointerTraits.hpp"
13
14#include <stdexcept>
15#include <format>
16#include <functional> //std::function
17#include <algorithm> //std::ranges::find_if
18
19namespace xAOD{
37
38
41 template <typename ObjType> concept identifyConcept = requires (const ObjType theObj) {
42 theObj.identify();
43 };
44
45 template <typename ObjType> concept identifierHashConcept = requires(const ObjType theObj) {
46 theObj.identifierHash();
47 };
48 template<class HitObjContainer> concept ContainerConcept =
51 }
52
53 namespace ChamberView {
55 enum class Mode: std::uint8_t{
58 };
59 }
60
61
62 template<ChamberViewConcepts::ContainerConcept HitObjContainer>
64 public:
65 using value_type = typename HitObjContainer::value_type;
66 using element_type = typename Acts::RemovePointer_t<value_type>;
67
68 using const_iterator = typename HitObjContainer::const_iterator;
71
74 ChamberViewer(const HitObjContainer& container)
76 m_container{container} {
77 next();
78 }
79
81 ChamberViewer(const HitObjContainer& container,
82 const Muon::IMuonIdHelperSvc* idHelperSvc,
83 const ViewMode mode = ViewMode::DetElement)
85 m_container{container},
86 m_idHelperSvc{idHelperSvc},
87 m_mode{mode} {
88 next();
89 }
90
100 return m_begin;
101 }
102
104 return m_end;
105 }
106
107 std::size_t size() const noexcept {
108 return std::distance(m_begin, m_end);
109 }
110
111 const_ref at(const std::size_t idx) const {
112 if (idx >= size()) {
113 throw std::domain_error(std::format("Invalid index given {:}. size: {:}, requested:{:} ",
114 typeid(const_ref).name(), size(), idx));
115 }
116 return *(m_begin +idx);
117 }
118
120 bool next() {
121 if (m_end == m_container.end()) {
122 return false;
123 }
124 m_begin = m_end;
126 const IdentifierHash currentHash = (*m_end)->identifierHash();
127 m_end = std::find_if(m_begin, m_container.end(),
128 [&currentHash](const_ref meas){
129 return meas->identifierHash() != currentHash;
130 });
131 } else {
132 const IdentifierHash currentHash = idHash((*m_end)->identify());
133 m_end = std::find_if(m_begin, m_container.end(),
134 [this,&currentHash](const_ref meas){
135 return idHash(meas->identify()) != currentHash;
136 });
137 }
138 if (m_begin == m_end) {
139 return next(); // veto empty views
140 }
141 return true;
142 }
143
147 bool loadView(const Identifier& chamberId)
149
150 const IdentifierHash detId = idHash(chamberId);
151 m_begin = std::ranges::find_if(m_container,[this,&detId](const_ref meas) {
152 return idHash(meas->identify()) == detId;
153 });
154 m_end = std::find_if(m_begin, m_container.end(),[this,&detId](const_ref meas) {
155 return idHash(meas->identify()) != detId;
156 });
157 return m_begin != m_end;
158 }
159
164 m_begin = std::ranges::find_if(m_container,[&idHash](const_ref meas) {
165 return meas->identifierHash() == idHash;
166 });
167 m_end = std::find_if(m_begin, m_container.end(),[&idHash](const_ref meas) {
168 return meas->identifierHash() != idHash;
169 });
170 return m_begin != m_end;
171 }
172
174 bool loadView(std::function<bool(const_ref)> selector) {
175 m_begin = std::ranges::find_if(m_container, selector);
176 m_end = std::find_if(m_begin, m_container.end(),
177 [&selector](const_ref meas) {
178 return !selector(meas);
179 });
180 return m_begin != m_end;
181 }
182 bool next(std::function<bool(const_ref)> selector) {
183 if (m_end == m_container.end()) {
184 return false;
185 }
187 const_iterator nextBegin = std::ranges::find_if(m_end, m_container.end(), selector);
188 if (nextBegin == m_container.end()) {
189 return false;
190 }
191 m_begin = nextBegin;
192 m_end = std::find_if(m_begin, m_container.end(),
193 [&selector](const_ref meas) {
194 return !selector(meas);
195 });
196 return true;
197 }
198
199 private:
202 return m_mode == ViewMode::DetElement ? m_idHelperSvc->detElementHash(id)
203 : m_idHelperSvc->moduleHash(id);
204 }
205 const HitObjContainer& m_container;
207 const ViewMode m_mode{ViewMode::DetElement};
210 };
211}
212#endif
213
CONT::reference reference
This is a "hash" representation of an Identifier.
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
const Muon::IMuonIdHelperSvc * m_idHelperSvc
ChamberViewer(const HitObjContainer &container, const Muon::IMuonIdHelperSvc *idHelperSvc, const ViewMode mode=ViewMode::DetElement)
Standard constructor.
IdentifierHash idHash(const Identifier &id) const
Returns the IdentifierHash from an Identifier.
ChamberViewer(const HitObjContainer &container)
Standard constructor.
typename const_iterator::reference const_ref
ChamberViewer(ChamberViewer &&other)=default
Standard move constructor.
bool next(std::function< bool(const_ref)> selector)
typename Acts::RemovePointer_t< value_type > element_type
const_iterator end() const noexcept
End iterator of the current chamber view.
bool loadView(const IdentifierHash &idHash)
Loads the view matching the parsed IdentifierHash.
const_ref at(const std::size_t idx) const
Returns the i-the measurement from the current chamber.
std::size_t size() const noexcept
Returns how many hits are in the current chamber.
ChamberView::Mode ViewMode
bool loadView(const Identifier &chamberId)
Loads the view matching the parsed identifier.
bool loadView(std::function< bool(const_ref)> selector)
Loads the view range based on a generic selector function.
ChamberViewer & operator=(const ChamberViewer &other)=delete
Delete the copy assignment operator.
bool next()
Loads the hits from the next chamber.
typename HitObjContainer::const_iterator const_iterator
const_iterator begin() const noexcept
Begin iterator of the current chamber view.
typename HitObjContainer::value_type value_type
ChamberViewer(const ChamberViewer &other)=delete
Delete the copy constructor.
ChamberViewer & operator=(ChamberViewer &&other)=default
Standard move operator.
const HitObjContainer & m_container
Define the concept that the object needs to have an IdentifierHash method.
Define the concept that the object needs to have an Identifier method.
Under the assumption that all measurements in an uncalibrated measurement container are sorted by the...
Mode
Switch setting the view mode if the chamber viewer is initialized with the IdHelperSvc.
@ Chamber
View ends if the moduleHash changes.
@ DetElement
View ends if the detElementHash changes.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.