ATLAS Offline Software
Loading...
Searching...
No Matches
HGTD_DetectorManager.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
9
12#include "GeoModelKernel/GeoVAlignmentStore.h"
14
18
20 : AthMessaging("HGTD_DetectorManager"),
21 m_idHelper(0)
22{
23 setName("HGTD");
24
25 //
26 // Initialize the Identifier helper
27 //
28 StatusCode sc = detStore->retrieve(m_idHelper,"HGTD_ID");
29 if (sc.isFailure() ) {
30 ATH_MSG_ERROR ("Could not retrieve HGTD id helper");
31 }
32
33 // Initialize the collections
34 if (m_idHelper) {
35 m_elementCollection.resize(m_idHelper->wafer_hash_max());
36 m_alignableTransforms.resize(m_idHelper->wafer_hash_max());
37 }
38 ATH_MSG_INFO("HGTD_DetectorManager initialized");
39}
40
42
44{
45 return m_volume.size();
46}
47
48PVConstLink HGTD_DetectorManager::getTreeTop(unsigned int i) const
49{
50 return m_volume[i];
51}
52
54 m_volume.push_back(vol);
55}
56
58{
59 // Make sure it is a wafer Id
60 Identifier waferId = m_idHelper->wafer_id(id);
61 IdentifierHash idHash = m_idHelper->wafer_hash(waferId);
62 if (idHash.is_valid()) {
63 return m_elementCollection[idHash];
64 } else {
65 return 0;
66 }
67}
68
73
74const HGTD_DetectorElement* HGTD_DetectorManager::getDetectorElement(int endcap, int layer, int phi_module, int eta_module) const
75{
76 return getDetectorElement(m_idHelper->wafer_id(endcap, layer, phi_module, eta_module));
77}
78
83
85{
86 IdentifierHash idHash = element->identifyHash();
87 if (idHash >= m_elementCollection.size()) {
88 throw std::runtime_error(
89 "HGTD_DetectorManager: Error adding detector element."
90 );
91 }
92 m_elementCollection[idHash] = element;
93}
94
95// Register alignable transform
97 const Identifier& id,
98 GeoAlignableTransform* transform,
99 const GeoVFullPhysVol* child)
100{
101 (void)level;
102
103 if (!m_idHelper) return;
104
105 IdentifierHash idHash = m_idHelper->wafer_hash(id);
106
107 if (!idHash.is_valid()) {
108 ATH_MSG_WARNING("Invalid idHash for alignable transform");
109 return;
110 }
111
112 ATH_MSG_DEBUG("STORE ALIGNABLE:"
113 << " hash=" << idHash
114 << " transform ptr=" << transform
115 << " child ptr=" << child);
116
117 m_alignableTransforms[idHash] =
118 std::make_unique<InDetDD::ExtendedAlignableTransform>(transform, child);
119
120 ATH_MSG_DEBUG("Alignable container size = "
121 << m_alignableTransforms.size());
122
123 ATH_MSG_DEBUG("HGTD ALIGNABLE ADDED: idHash = " << idHash);
124
125 int count = 0;
126 for (const auto& t : m_alignableTransforms) {
127 if (t) count++;
128 }
129
130 ATH_MSG_DEBUG("HGTD alignable transforms registered: " << count);
131}
132
134 const Identifier& id,
135 const Amg::Transform3D& delta,
136 GeoVAlignmentStore* alignStore) const
137{
138 (void)level;
139
140 IdentifierHash idHash = m_idHelper->wafer_hash(id);
141
142 if (!idHash.is_valid()) return false;
143
144 ATH_MSG_DEBUG("idHash = " << idHash);
145
146 auto* transform = m_alignableTransforms[idHash].get();
147 ATH_MSG_DEBUG("RETRIEVE ALIGNABLE:"
148 << " hash=" << idHash
149 << " ext transform ptr=" << transform
150 << " geo alignable ptr="
151 << (transform ? transform->alignableTransform() : nullptr));
152
153 ATH_MSG_DEBUG("transform ptr = " << transform);
154
155 if (!transform){
156 ATH_MSG_ERROR("NO ALIGNABLE FOUND");
157 return false;
158 }
159 ATH_MSG_DEBUG("SETTING DELTA dx="
160 << delta.translation().x()
161 << " dy="
162 << delta.translation().y()
163 << " dz="
164 << delta.translation().z());
165
166 alignStore->setDelta(transform->alignableTransform(), delta);
167
168 return true;
169
170}
171
173 const AlignableTransformContainer* container,
174 GeoVAlignmentStore* alignStore) const
175{
176 ATH_MSG_DEBUG("Applying HGTD alignment");
177
178 ATH_MSG_DEBUG("Entered align()");
179 if (!container) {
180 ATH_MSG_ERROR("Null AlignableTransformContainer");
181 return StatusCode::FAILURE;
182 }
183 ATH_MSG_DEBUG("Container pointer = " << container);
184 ATH_MSG_DEBUG("Container size = " << container->size());
185
186 if (container->empty()) {
187 ATH_MSG_WARNING("AlignableTransformContainer is empty");
188 return StatusCode::SUCCESS;
189 }
190
191 ATH_MSG_DEBUG("AlignableTransformContainer has "
192 << container->size()
193 << " AlignableTransform collection(s)");
194
195 // Use only the last tag of each AlignableTransform, exactly like InDet
196 std::map<std::string,const AlignableTransform*> transforms;
197
198 for (const auto* pat : *container) {
199
200 if (!pat) {
201 ATH_MSG_WARNING("Null AlignableTransform pointer");
202 continue;
203 }
204
205 ATH_MSG_DEBUG("--------------------------------");
206 ATH_MSG_DEBUG("Collection tag = " << pat->tag());
207 ATH_MSG_DEBUG("Collection size = " << pat->size());
208 transforms[pat->tag()] = pat;
209
210 }
211
212 for (const auto& entry : transforms) {
213
214 const AlignableTransform* transformCollection = entry.second;
215
216 ATH_MSG_DEBUG("Processing tag " << entry.first);
217
219 transformCollection->begin();
220 transIter != transformCollection->end();
221 ++transIter)
222 {
223
224 Identifier id = transIter->identify();
225
226 ATH_MSG_DEBUG("--------------------------------");
227 ATH_MSG_DEBUG("Identifier = " << id.get_compact());
228
229 Amg::Transform3D delta =
230 Amg::CLHEPTransformToEigen(transIter->transform());
231
232 ATH_MSG_DEBUG("Translation = ("
233 << delta.translation().x() << ", "
234 << delta.translation().y() << ", "
235 << delta.translation().z() << ")");
236
237 bool ok =
239 0,
240 id,
241 delta,
242 alignStore);
243
244 ATH_MSG_DEBUG("setAlignableTransformDelta returned "
245 << std::boolalpha << ok);
246
247 if (!ok) {
248 ATH_MSG_WARNING("Failed to apply alignment for identifier "
249 << id.get_compact());
250 }
251 }
252 }
253
254 return StatusCode::SUCCESS;
255}
256
258{
259 return m_idHelper;
260}
261
263{
265 if (element) {
266 element->invalidate();
267 }
268 }
269}
270
272{
273 for (const HGTD_DetectorElement* element : m_elementCollection) {
274 if (element) {
275 element->updateCache();
276 }
277 }
278}
279
280void HGTD_DetectorManager::setCommonItems(std::unique_ptr<const SiCommonItems>&& commonItems)
281{
282 m_commonItems = std::move(commonItems);
283}
CondMultChanCollection< AlignableTransform > AlignableTransformContainer
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
std::vector< AlignTransMember >::const_iterator AlignTransMem_citr
AlignTransMem_citr end() const
AlignTransMem_citr begin() const
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
virtual unsigned int getNumTreeTops() const override
Access to raw geometry:
void addTreeTop(PVConstLink treeTop)
Add a Tree top:
const InDetDD::HGTD_DetectorElement * getDetectorElement(const Identifier &id) const
access to individual elements : via Identifier
bool setAlignableTransformDelta(int level, const Identifier &id, const Amg::Transform3D &delta, GeoVAlignmentStore *alignStore) const
Apply alignment correction.
const InDetDD::HGTD_DetectorElementCollection * getDetectorElementCollection() const
Get the collection of element that is held.
void invalidateAll()
Invalidate cache for all detector elements.
void updateAll() const
Update all caches.
~HGTD_DetectorManager()
Destructor.
std::vector< PVConstLink > m_volume
HGTD_DetectorManager(StoreGateSvc *detStore)
Constructor.
std::unique_ptr< const InDetDD::SiCommonItems > m_commonItems
void addDetectorElement(InDetDD::HGTD_DetectorElement *element)
Add elememts.
std::vector< std::unique_ptr< InDetDD::ExtendedAlignableTransform > > m_alignableTransforms
const HGTD_ID * getIdHelper() const
virtual PVConstLink getTreeTop(unsigned int i) const override
void setCommonItems(std::unique_ptr< const InDetDD::SiCommonItems > &&commonItems)
Set SiCommonItems.
void addAlignableTransform(int level, const Identifier &id, GeoAlignableTransform *transform, const GeoVFullPhysVol *child)
Register alignable transform.
InDetDD::HGTD_DetectorElementCollection m_elementCollection
StatusCode align(const AlignableTransformContainer *container, GeoVAlignmentStore *alignStore) const
Apply alignment constants from an AlignableTransformContainer.
This is an Identifier helper class for the HGTD subdetector.
Definition HGTD_ID.h:47
This is a "hash" representation of an Identifier.
constexpr bool is_valid() const
Class to hold geometrical description of an HGTD detector element.
Helper class to concentrate common items, such as the pointer to the IdHelper, the lorentzAngle tool ...
virtual IdentifierHash identifyHash() const override final
identifier hash (inline)
The Athena Transient Store API.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
Amg::Transform3D CLHEPTransformToEigen(const HepGeom::Transform3D &CLHEPtransf)
Converts a CLHEP-based HepGeom::Transform3D into an Eigen Amg::Transform3D.
Eigen::Affine3d Transform3D
DataVector< HGTD_DetectorElement > HGTD_DetectorElementCollection