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 if (m_begin != m_end && (*m_begin)->identifierHash() == idHash) {
165 return true;
166 }
167 m_begin = std::ranges::find_if(m_container,[&idHash](const_ref meas) {
168 return meas->identifierHash() == idHash;
169 });
170 m_end = std::find_if(m_begin, m_container.end(),[&idHash](const_ref meas) {
171 return meas->identifierHash() != idHash;
172 });
173 return m_begin != m_end;
174 }
175
177 bool loadView(std::function<bool(const_ref)> selector) {
178 m_begin = std::ranges::find_if(m_container, selector);
179 m_end = std::find_if(m_begin, m_container.end(),
180 [&selector](const_ref meas) {
181 return !selector(meas);
182 });
183 return m_begin != m_end;
184 }
185 bool next(std::function<bool(const_ref)> selector) {
186 if (m_end == m_container.end()) {
187 return false;
188 }
190 const_iterator nextBegin = std::ranges::find_if(m_end, m_container.end(), selector);
191 if (nextBegin == m_container.end()) {
192 return false;
193 }
194 m_begin = nextBegin;
195 m_end = std::find_if(m_begin, m_container.end(),
196 [&selector](const_ref meas) {
197 return !selector(meas);
198 });
199 return true;
200 }
201
203 const HitObjContainer& get() const { return m_container; }
204
205 private:
208 return m_mode == ViewMode::DetElement ? m_idHelperSvc->detElementHash(id)
209 : m_idHelperSvc->moduleHash(id);
210 }
211 const HitObjContainer& m_container;
213 const ViewMode m_mode{ViewMode::DetElement};
216 };
217}
218#endif
219
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.
const HitObjContainer & get() const
Returns the reference to the container from which the ChamberViewer was made.
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.