ATLAS Offline Software
Loading...
Searching...
No Matches
MuonChamberToolTest.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#if defined(FLATTEN) && defined(__GNUC__)
6// Avoid warning in dbg build
7#pragma GCC optimize "-fno-var-tracking-assignments"
8#endif
9
10#include "MuonChamberToolTest.h"
11
19
21#include <GaudiKernel/SystemOfUnits.h>
22
23#include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
24#include "Acts/Geometry/TrackingGeometry.hpp"
25#include "Acts/Geometry/DiamondVolumeBounds.hpp"
26#include "Acts/Surfaces/TrapezoidBounds.hpp"
27#include "Acts/Surfaces/CylinderBounds.hpp"
28#include "Acts/Surfaces/RadialBounds.hpp"
29#include "Acts/Surfaces/CylinderSurface.hpp"
30#include "Acts/Surfaces/DiscSurface.hpp"
31#include "Acts/Geometry/VolumePlacementBase.hpp"
32
33#include "Acts/Visualization/ObjVisualization3D.hpp"
34#include "Acts/Visualization/GeometryView3D.hpp"
35#include "Acts/Definitions/Units.hpp"
36
38
39#include <format>
40
41using namespace Acts::UnitLiterals;
42using namespace Muon::MuonStationIndex;
43
44namespace{
45 constexpr double tolerance = 10. *Gaudi::Units::micrometer;
46
47 std::vector<std::shared_ptr<const Acts::Volume>> chamberVolumes(const ActsTrk::GeometryContext& gctx,
48 const MuonGMR4::SpectrometerSector& sector) {
49 std::vector<std::shared_ptr<const Acts::Volume>> vols{};
50 std::ranges::transform(sector.chambers(),std::back_inserter(vols),
51 [&gctx](const auto& ch){ return ch->boundingVolume(gctx); });
52 return vols;
53 }
54 std::vector<const Acts::Volume*> chamberVolumes(const Acts::TrackingVolume& vol) {
55 std::vector<const Acts::Volume*> children {};
56 for (const Acts::TrackingVolume& childVol : vol.volumes()) {
57 std::vector<const Acts::Volume*> grandChildren = chamberVolumes(childVol);
58 children.insert(children.end(), grandChildren.begin(), grandChildren.end());
59 }
60 return children;
61 }
62
63 std::vector<const Acts::Surface*> extractSurfaces(const std::vector<const MuonGMR4::MuonReadoutElement*>& reEles){
64 std::vector<const Acts::Surface*> surfaces{};
65 for (const auto* re : reEles) {
66 std::ranges::transform(re->getSurfaces(), std::back_inserter(surfaces),
67 [](const std::shared_ptr<Acts::Surface>& surface) { return surface.get() ; });
68 }
69 return surfaces;
70 }
71
72 std::vector<const Acts::Surface*> extractSurfaces(const Acts::TrackingVolume& volume) {
73 std::vector<const Acts::Surface*> surfaces{};
74 std::ranges::for_each(volume.surfaces(), [&surfaces](const Acts::Surface& surface){
75 if (surface.isSensitive()) {
76 surfaces.push_back(&surface);
77 }
78 });
79 for (const Acts::TrackingVolume& subVol : volume.volumes()) {
80 std::vector<const Acts::Surface*> childSurfaces = extractSurfaces(subVol);
81 surfaces.insert(surfaces.end(), childSurfaces.begin(), childSurfaces.end());
82
83 }
84 return surfaces;
85 }
86
87 Identifier identify(const Acts::Surface& surface) {
88 const auto* detEl = dynamic_cast<const ActsTrk::ISurfacePlacement*>(surface.surfacePlacement());
89 return detEl ? detEl->identify(): Identifier{};
90 }
91
92 bool checkOverlapWithCylinder(const Acts::GeometryContext& gctx,
93 const Acts::Surface* testSurf,
94 const Amg::Vector3D& center, double radius, double halfZ){
95
96 //cylinder-cylinder overlap check
97 if (testSurf->type() == Acts::Surface::SurfaceType::Cylinder) {
98 const auto& testBounds = static_cast<const Acts::CylinderBounds&>(testSurf->bounds());
99 using BoundEnum = Acts::CylinderBounds::BoundValues;
100 const double testR = testBounds.get(BoundEnum::eR);
101 const auto& testCenter = testSurf->center(gctx);
102 double dr = std::abs(testCenter.perp() - center.perp());
103 double dz = std::abs(testCenter.z() - center.z());
104 //the cylinders do not overlap
105 if (dr > testR + radius ||
106 (dr <= Acts::s_epsilon && std::abs(testR-radius) > Acts::s_epsilon) ||
107 (dz > halfZ + testBounds.get(BoundEnum::eHalfLengthZ))) {
108 return false;
109 }
110 } else if (testSurf->type() == Acts::Surface::SurfaceType::Disc) {
111 // Handle disc overlap logic
112 using BoundEnum = Acts::RadialBounds::BoundValues;
113 const auto& bounds = static_cast<const Acts::RadialBounds&>(testSurf->bounds());
114 const auto& testCenter = testSurf->center(gctx);
115 double dz = std::abs(testCenter.z() - center.z());
116 //cylinder and disc do not overlap
117 if (dz > halfZ ||
118 (dz < halfZ && bounds.get(BoundEnum::eMaxR) < (radius))) {
119 return false;
120 }
121 } else {
122 std::cerr << "Overlap check with surface type " << testSurf->type() << " is not implemented yet\n";
123 return false;
124 }
125 return true;
126 }
127
128 bool checkOverlapWithDisc(const Acts::GeometryContext& gctx,
129 const Acts::Surface* testSurf,
130 const Amg::Vector3D& center, double radius){
131 if (testSurf->type() == Acts::Surface::SurfaceType::Cylinder) {
132 const auto& testBounds = static_cast<const Acts::CylinderBounds&>(testSurf->bounds());
133 using BoundEnum = Acts::CylinderBounds::BoundValues;
134 const double testR = testBounds.get(BoundEnum::eR);
135 const auto& testCenter = testSurf->center(gctx);
136 double dz = std::abs(testCenter.z() - center.z());
137 //the cylinder and the disc do not overlap
138 if (dz > testBounds.get(BoundEnum::eHalfLengthZ) ||
139 (dz < testBounds.get(BoundEnum::eHalfLengthZ) && radius < testR)) {
140 return false;
141 }
142 } else if (testSurf->type() == Acts::Surface::SurfaceType::Disc) {
143 using BoundEnum = Acts::RadialBounds::BoundValues;
144 const auto& bounds = static_cast<const Acts::RadialBounds&>(testSurf->bounds());
145 const auto& testCenter = testSurf->center(gctx);
146 double dz = std::abs(testCenter.z() - center.z());
147 double dr = std::abs(testCenter.perp() - center.perp());
148 //the discs do not overlap
149 if (dz > Acts::s_epsilon ||
150 dr > (radius+bounds.get(BoundEnum::eMaxR))){
151 return false;
152 }
153 } else {
154 std::cerr << "Overlap check with surface type " << testSurf->type() << " is not implemented yet\n";
155 return false;
156 }
157 return true;
158 }
159}
160
161namespace MuonGMR4 {
162
164 ATH_CHECK(m_idHelperSvc.retrieve());
165 ATH_CHECK(m_geoCtxKey.initialize());
167 ATH_CHECK(detStore()->retrieve(m_detMgr));
168 return StatusCode::SUCCESS;
169 }
170 template <class EnvelopeType>
171#if defined(FLATTEN) && defined(__GNUC__)
172// We compile this function with optimization, even in debug builds; otherwise,
173// the heavy use of Eigen makes it too slow. However, from here we may call
174// to out-of-line Eigen code that is linked from other DSOs; in that case,
175// it would not be optimized. Avoid this by forcing all Eigen code
176// to be inlined here if possible.
177[[gnu::flatten]]
178#endif
180 const EnvelopeType& chamb,
181 const Acts::Volume& boundVol,
182 const Amg::Vector3D& point,
183 const std::string& descr,
184 const Identifier& channelId) const {
185
186 // Explicitly inline Volume::inside here so that it gets
187 // flattened in debug builds. Gives a significant speedup.
188 //if (boundVol.inside(gctx.context(), point, tolerance)) {
189 const Amg::Vector3D locPos{boundVol.globalToLocalTransform(gctx.context()) * point};
190 if (boundVol.volumeBounds().inside(locPos,tolerance)) {
191 ATH_MSG_VERBOSE("In channel "<<m_idHelperSvc->toString(channelId)
192 <<", point "<<descr <<" is inside of the chamber "<<std::endl<<chamb<<std::endl
193 <<"Local position:" <<Amg::toString(boundVol.globalToLocalTransform(gctx.context()) * point));
194 return StatusCode::SUCCESS;
195 }
196
197 StripDesign planeTrapezoid{};
198 planeTrapezoid.defineTrapezoid(chamb.halfXShort(), chamb.halfXLong(), chamb.halfY());
199 planeTrapezoid.setLevel(MSG::VERBOSE);
201 static const Eigen::Rotation2D axisSwap{90. *Gaudi::Units::deg};
202 if (std::abs(locPos.z()) - chamb.halfZ() < -tolerance &&
203 planeTrapezoid.insideTrapezoid(axisSwap*locPos.block<2,1>(0,0))) {
204 return StatusCode::SUCCESS;
205 }
206 planeTrapezoid.defineStripLayout(locPos.y() * Amg::Vector2D::UnitX(), 1, 1, 1);
207 ATH_MSG_ERROR("In channel "<<m_idHelperSvc->toString(channelId) <<", the point "
208 << descr <<" "<<Amg::toString(point)<<" is not part of the chamber volume."
209 <<std::endl<<std::endl<<chamb<<std::endl<<"Local position "<<Amg::toString(locPos)
210 <<", "<<planeTrapezoid
211 <<", box left edge: "<<Amg::toString(planeTrapezoid.leftEdge(1).value_or(Amg::Vector2D::Zero()))
212 <<", box right edge "<<Amg::toString(planeTrapezoid.rightEdge(1).value_or(Amg::Vector2D::Zero())));
213 return StatusCode::FAILURE;
214 }
215
217 const Acts::TrackingVolume& volume,
218 const Amg::Vector3D& point,
219 const std::string& descr,
220 const Identifier& chamberId) const {
221 if (volume.inside(gctx.context(), point, tolerance)) {
222 return StatusCode::SUCCESS;
223 }
224 ATH_MSG_ERROR("In channel "<<m_idHelperSvc->toString(chamberId) <<", the point "
225 << descr <<" "<<Amg::toString(volume.globalToLocalTransform(gctx.context())* point)
226 <<" is not part of the chamber volume. The corners of the volume are:");
227 for(const Amg::Vector3D& corner : cornerPoints(gctx, volume)) {
228 ATH_MSG_ERROR(" "<<Amg::toString(volume.globalToLocalTransform(gctx.context())*corner));
229 }
230 return StatusCode::FAILURE;
231 }
232
233 template <class EnvelopeType>
235 const EnvelopeType& envelope) const {
236 std::shared_ptr<Acts::Volume> boundVol = envelope.boundingVolume(gctx);
237 const Chamber::ReadoutSet reEles = envelope.readoutEles();
238 for(const MuonReadoutElement* readOut : reEles) {
239 if constexpr (std::is_same_v<EnvelopeType, SpectrometerSector>) {
240 if (readOut->msSector() != &envelope) {
241 ATH_MSG_ERROR("Mismatch in the sector association "<<m_idHelperSvc->toStringDetEl(readOut->identify())
242 <<std::endl<<(*readOut->msSector())<<std::endl<<envelope);
243 return StatusCode::FAILURE;
244 }
245 } else if constexpr (std::is_same_v<EnvelopeType, Chamber>) {
246 if (readOut->chamber() != &envelope) {
247 ATH_MSG_ERROR("Mismatch in the chamber association "<<m_idHelperSvc->toStringDetEl(readOut->identify())
248 <<std::endl<<(*readOut->chamber())<<std::endl<<envelope);
249 return StatusCode::FAILURE;
250 }
251 }
252 switch (readOut->detectorType()) {
254 const auto* detEle = static_cast<const TgcReadoutElement*>(readOut);
255 ATH_CHECK(testReadoutEle(gctx, *detEle, envelope, *boundVol));
256 break;
258 const auto* detEle = static_cast<const MdtReadoutElement*>(readOut);
259 ATH_CHECK(testReadoutEle(gctx, *detEle, envelope, *boundVol));
260 break;
262 const auto* detEle = static_cast<const RpcReadoutElement*>(readOut);
263 ATH_CHECK(testReadoutEle(gctx, *detEle, envelope, *boundVol));
264 break;
266 const auto* detEle = static_cast<const MmReadoutElement*>(readOut);
267 ATH_CHECK(testReadoutEle(gctx, *detEle, envelope, *boundVol));
268 break;
270 const auto* detEle = static_cast<const sTgcReadoutElement*>(readOut);
271 ATH_CHECK(testReadoutEle(gctx, *detEle, envelope, *boundVol));
272 break;
273 } default: {
274 ATH_MSG_ERROR("Who came up with putting "<<readOut->detectorType()<<" into the MS");
275 return StatusCode::FAILURE;
276 }
277 }
278 }
279 ATH_MSG_DEBUG("All "<<reEles.size()<<" readout elements are embedded in "<<envelope);
280 return StatusCode::SUCCESS;
281 }
282
283 std::vector<Amg::Vector3D> MuonChamberToolTest::cornerPoints(const ActsTrk::GeometryContext& gctx,
284 const Acts::Volume& volume) const {
285
286 const auto& bounds = volume.volumeBounds();
287 unsigned int edgeIdx{0};
288 //diamond volume bounds case - there are 12 edges
289 if(bounds.type() == Acts::VolumeBounds::BoundsType::eDiamond){
290 const auto& diamondBounds = static_cast<const Acts::DiamondVolumeBounds&>(bounds);
291 using BoundEnum = Acts::DiamondVolumeBounds::BoundValues;
292 std::vector<Amg::Vector3D> edges(12, Amg::Vector3D::Zero());
293 double xCord{0.}, yCord{0};
294 for(double signX : {-1.,1.}){
295 for(double signY : {-1., 0., 1.}){
296 for(double signZ : {-1.,1.}){
297 if(signY == 0){
298 xCord = diamondBounds.get(BoundEnum::eHalfLengthX2);
299 }else if(signY < 0){
300 xCord = diamondBounds.get(BoundEnum::eHalfLengthX1);
301 yCord = diamondBounds.get(BoundEnum::eLengthY1);
302 } else{
303 xCord = diamondBounds.get(BoundEnum::eHalfLengthX3);
304 yCord = diamondBounds.get(BoundEnum::eLengthY2);
305 }
306
307 const Amg::Vector3D edge{signX*xCord,
308 signY*yCord,
309 signZ*diamondBounds.get(BoundEnum::eHalfLengthZ)};
310 edges[edgeIdx] = volume.localToGlobalTransform(gctx.context())*edge;
311 ++edgeIdx;
312 }
313 }
314 }
315 return edges;
316 }
317
318 //trapezoid or rectangular bounds case
319 std::vector<Amg::Vector3D> edges{};
320 ATH_MSG_VERBOSE("Fetch volume bounds "<<Amg::toString(volume.localToGlobalTransform(gctx.context())));
321 for (const double signX : {-1., 1.}) {
322 for (const double signY : { -1., 1.}) {
323 for (const double signZ: {-1., 1.}) {
324 const Amg::Vector3D edge{signX* (signY>0 ? MuonGMR4::halfXhighY(bounds) : MuonGMR4::halfXlowY(bounds)),
325 signY*MuonGMR4::halfY(bounds),
326 signZ*MuonGMR4::halfZ(bounds)};
327 edges.push_back(volume.localToGlobalTransform(gctx.context()) * edge);
328 ATH_MSG_VERBOSE("Local edge "<<Amg::toString(edge)<<", global edge: "<<Amg::toString(edges[edgeIdx]));
329 ++edgeIdx;
330 }
331 }
332 }
333 return edges;
334 }
335
336 std::array<Amg::Vector3D, 8> MuonChamberToolTest::cornerPoints(const ActsTrk::GeometryContext& gctx, const Acts::StrawSurface& surface) const {
337 std::array<Amg::Vector3D, 8> edges{make_array<Amg::Vector3D,8>(Amg::Vector3D::Zero())};
338 using BoundEnum = Acts::LineBounds::BoundValues;
339 const auto& bounds = static_cast<const Acts::LineBounds&>(surface.bounds());
340 unsigned int edgeIdx{0};
341
342 ATH_MSG_VERBOSE("Fetch volume bounds "<<Amg::toString(surface.localToGlobalTransform(gctx.context())));
343 for (const double signX : {-1., 1.}) {
344 for (const double signY : { -1., 1.}) {
345 for (const double signZ: {-1., 1.}) {
346 const Amg::Vector3D edge{signX*bounds.get(BoundEnum::eR),
347 signY*bounds.get(BoundEnum::eR),
348 signZ*bounds.get(BoundEnum::eHalfLengthZ)};
349 edges[edgeIdx] = surface.localToGlobalTransform(gctx.context()) * edge;
350 ++edgeIdx;
351 }
352 }
353 }
354 return edges;
355 }
356
357 std::array<Amg::Vector3D, 4> MuonChamberToolTest::cornerPoints(const ActsTrk::GeometryContext& gctx, const Acts::PlaneSurface& surface) const {
358 std::array<Amg::Vector3D, 4> edges{make_array<Amg::Vector3D,4>(Amg::Vector3D::Zero())};
359 if(surface.bounds().type() == Acts::SurfaceBounds::BoundsType::eRectangle) { //RPC surfaces are rectangles
360 const Acts::RectangleBounds& bounds = static_cast<const Acts::RectangleBounds&>(surface.bounds());
361 using BoundEnum = Acts::RectangleBounds::BoundValues;
362
363 unsigned int edgeIdx{0};
364 for(const double signX : {-1., 1.}) {
365 for (const double signY : { -1., 1.}) {
366 const Amg::Vector3D edge{signX < 0 ? bounds.get(BoundEnum::eMinX) : bounds.get(BoundEnum::eMaxX),
367 signY < 0 ? bounds.get(BoundEnum::eMinY) : bounds.get(BoundEnum::eMaxY), 0.};
368 edges[edgeIdx] = surface.localToGlobalTransform(gctx.context()) * edge;
369 ++edgeIdx;
370 }
371 }
372 return edges;
373 } else if(surface.bounds().type() == Acts::SurfaceBounds::BoundsType::eTrapezoid) {
374 using BoundEnum = Acts::TrapezoidBounds::BoundValues;
375 const auto& bounds = static_cast<const Acts::TrapezoidBounds&>(surface.bounds());
376 unsigned int edgeIdx{0};
377
378 ATH_MSG_VERBOSE("Fetch volume bounds "<<Amg::toString(surface.localToGlobalTransform(gctx.context())));
379 for (const double signX : {-1., 1.}) {
380 for (const double signY : { -1., 1.}) {
381 const Amg::Vector3D edge{Amg::getRotateZ3D(-1.*bounds.get(BoundEnum::eRotationAngle)) *
382 Amg::Vector3D(signX*bounds.get(signY < 0 ? BoundEnum::eHalfLengthXnegY : BoundEnum::eHalfLengthXposY),
383 signY*bounds.get(BoundEnum::eHalfLengthY), 0.)};
384
385 edges[edgeIdx] = surface.localToGlobalTransform(gctx.context()) * edge;
386 ++edgeIdx;
387 }
388 }
389
390 return edges;
391 } else {
392 ATH_MSG_ERROR("The surface bounds are neither a rectangle nor a trapezoid, this is not supported yet");
393 return edges;
394 }
395 }
396
397
398#if defined(FLATTEN) && defined(__GNUC__)
399// We compile this function with optimization, even in debug builds; otherwise,
400// the heavy use of Eigen makes it too slow. However, from here we may call
401// to out-of-line Eigen code that is linked from other DSOs; in that case,
402// it would not be optimized. Avoid this by forcing all Eigen code
403// to be inlined here if possible.
404[[gnu::flatten]]
405#endif
407 const std::vector<Amg::Vector3D>& chamberEdges,
408 const Acts::Volume& volume) const {
409
411 const Amg::Vector3D center{volume.center(gctx.context())};
412 double minDist = 1._km;
413 for (const Amg::Vector3D& edge : chamberEdges) {
414 minDist = std::min(minDist, (edge - center).mag());
415 }
418 if (std::ranges::none_of(volume.volumeBounds().values(),
419 [minDist](const double bound){
420 return minDist < 2.5*bound;
421 })) {
422 return false;
423 }
424 const double stepLength = 1. / m_overlapSamples;
425
426 const Acts::VolumeBounds& volBounds = volume.volumeBounds();
427 const Acts::Transform3& transform = volume.globalToLocalTransform(gctx.context());
428 for (unsigned edge1 = 1; edge1 < chamberEdges.size(); ++edge1) {
429 for (unsigned edge2 = 0; edge2 < edge1; ++edge2) {
430 for (unsigned step = 0 ; step <= m_overlapSamples; ++step) {
431 const double section = stepLength * step;
432 const Amg::Vector3D testPoint = section* chamberEdges[edge1] + (1. -section) *chamberEdges[edge2];
433 // Using acts::Volume::inside is horribly slow in dbg builds.
434 // Using the bounds method directly is much faster.
435 if (volBounds.inside (transform * testPoint)) {
436 return true;
437 }
438 }
439 }
440 }
441 return false;
442 }
444
445 std::vector<const MuonReadoutElement*> allRE = m_detMgr->getAllReadoutElements();
447 const ChamberSet chambers = m_detMgr->getAllChambers();
448 ATH_MSG_INFO("Fetched "<<chambers.size()<<" chambers.");
449 std::vector<const Chamber*> chamberVec{chambers.begin(), chambers.end()};
450
451 const auto missChamb = std::ranges::find_if(allRE, [&chamberVec](const MuonGMR4::MuonReadoutElement* re){
452 return std::ranges::find(chamberVec, re->chamber()) == chamberVec.end();
453 });
454 if (missChamb != allRE.end()) {
455 ATH_MSG_ERROR("The chamber "<<(*(*missChamb)->chamber())<<" is not in the chamber set");
456 return StatusCode::FAILURE;
457 }
458
459 // Retrieve bounds here rather than inside the loop below,
460 // so we only need to do it O(N) rather than O(N^2) times.
461 std::vector<std::shared_ptr<Acts::Volume> > chamberBoundsVec;
462 chamberBoundsVec.reserve (chamberVec.size());
463 for (const Chamber* ch : chamberVec)
464 chamberBoundsVec.push_back (ch->boundingVolume(gctx));
465
466 std::set<const Chamber*> overlapChambers{};
467 std::stringstream overlapstream{};
468 for (std::size_t chIdx = 0; chIdx< chamberVec.size(); ++chIdx) {
469 const Chamber& chamber{*chamberVec[chIdx]};
470 const Acts::Volume& chamberBounds = *chamberBoundsVec[chIdx];
471 if (m_dumpObjs) {
472 saveEnvelope(gctx, std::format("Chamber_{:}{:}{:}{:}{:}",
473 chamber.detectorType(),
474 chName(chamber.chamberIndex()),
475 std::abs(chamber.stationEta()),
476 chamber.stationEta() > 0 ? 'A' : 'C',
477 chamber.stationPhi()),
478 chamberBounds, extractSurfaces(chamber.readoutEles()));
479 }
480 ATH_CHECK(allReadoutInEnvelope(gctx, chamber));
481 const std::vector<Amg::Vector3D> chambCorners = cornerPoints(gctx, chamberBounds);
483 std::vector<const Chamber*> overlaps{};
484 for (std::size_t chIdx1 = 0; chIdx1<chamberVec.size(); ++chIdx1) {
485 if (chIdx == chIdx1) {
486 continue;
487 }
488 const Chamber* overlapTest{chamberVec[chIdx1]};
489 if (hasOverlap(gctx, chambCorners, *chamberBoundsVec[chIdx1])) {
490 overlaps.push_back(overlapTest);
491 }
492 }
493 if (overlaps.empty()) {
494 continue;
495 }
496 overlapstream<<"The chamber "<<chamber<<" overlaps with "<<std::endl;
497 for (const Chamber* itOverlaps : overlaps) {
498 overlapstream<<" *** "<<(*itOverlaps)<<std::endl;
499 }
500 overlapstream<<std::endl<<std::endl;
501 overlapChambers.insert(overlaps.begin(), overlaps.end());
502 overlapChambers.insert(chamberVec[chIdx]);
503 }
504 if (!overlapChambers.empty()) {
505 Acts::ObjVisualization3D visualHelper{};
506 for (const Chamber* hasOverlap: overlapChambers) {
507 Acts::GeometryView3D::drawVolume(visualHelper, *hasOverlap->boundingVolume(gctx), gctx.context());
508 visualHelper.write(m_overlapChambObj.value());
509 }
510 if (m_ignoreOverlapCh) {
511 ATH_MSG_WARNING(overlapstream.str());
512 } else {
513 ATH_MSG_ERROR(overlapstream.str());
514 }
515 }
516 ATH_MSG_INFO("Chamber test completed. Found "<<overlapChambers.size()<<" overlapping chambers");
517 return overlapChambers.empty() || m_ignoreOverlapCh ? StatusCode::SUCCESS : StatusCode::FAILURE;
518 }
519
521
522 std::vector<const MuonReadoutElement*> allREs = m_detMgr->getAllReadoutElements();
523 for (const MuonReadoutElement* re : allREs) {
524 if (!re->msSector()) {
525 ATH_MSG_ERROR("The readout element "<<m_idHelperSvc->toStringDetEl(re->identify())<<" does not have any sector associated ");
526 return StatusCode::FAILURE;
527 }
528 const SpectrometerSector* sectorFromDet = m_detMgr->getSectorEnvelope(re->chamberIndex(),
529 m_idHelperSvc->sector(re->identify()),
530 re->stationEta());
531 if (sectorFromDet != re->msSector()) {
532 ATH_MSG_ERROR("The sector attached to "<<m_idHelperSvc->toStringDetEl(re->identify())
533 <<", chIdx: "<<chName(re->chamberIndex())<<", sector: "<<m_idHelperSvc->sector(re->identify())
534 <<" is not the one attached to the readout geometry \n"<<(*re->msSector())<<"\n"<<(*sectorFromDet));
535 return StatusCode::FAILURE;
536 }
537 }
538 using SectorSet = MuonDetectorManager::MuonSectorSet;
539 const SectorSet sectors = m_detMgr->getAllSectors();
540 ATH_MSG_INFO(__func__<<"() "<<__LINE__<<" - Fetched "<<sectors.size()<<" sectors. ");
541 for (const SpectrometerSector* sector : sectors) {
542 if (m_dumpObjs) {
543 const auto subVols = chamberVolumes(gctx, *sector);
544 saveEnvelope(gctx, std::format("Sector_{:}{:}{:}",
545 chName(sector->chamberIndex()),
546 sector->side() >0? 'A' :'C',
547 sector->stationPhi() ),
548 *sector->boundingVolume(gctx),
549 extractSurfaces(sector->readoutEles()),
550 Acts::unpackSmartPointers(subVols));
551 }
552 ATH_CHECK(allReadoutInEnvelope(gctx, *sector));
553 const std::shared_ptr<Acts::Volume> secVolume = sector->boundingVolume(gctx);
554 for (const SpectrometerSector::ChamberPtr& chamber : sector->chambers()){
555 const std::vector<Amg::Vector3D> edges = cornerPoints(gctx, *chamber->boundingVolume(gctx));
556 unsigned int edgeCount{0};
557 for (const Amg::Vector3D& edge : edges) {
558 ATH_CHECK(pointInside(gctx, *sector, *secVolume, edge, std::format("Edge {:}", ++edgeCount),
559 chamber->readoutEles().front()->identify()));
560 }
561 }
562 }
563 ATH_MSG_INFO(__func__<<"() "<<__LINE__<<" - Sector envelope test completed.");
564 return StatusCode::SUCCESS;
565 }
567 const Acts::TrackingVolume& volume) const {
568 if (!volume.isAlignable()) {
569 return StatusCode::SUCCESS;
570 }
571 const Acts::GeometryContext geoCtx = gctx.context();
572 std::vector<std::shared_ptr<const Acts::Surface>> portals{};
573 for (const Acts::Portal& portal : volume.portals()) {
574 if (portal.surface().geometryId().withBoundary(0) != volume.geometryId()) {
575 continue;
576 }
577 portals.push_back(portal.surface().getSharedPtr());
578 }
579 const auto unAlignedPortals = volume.volumeBounds().orientedSurfaces(volume.localToGlobalTransform(geoCtx));
580
581 if (unAlignedPortals.size() != portals.size()) {
582 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The size of the aligned and unaligned portals don't match for volume "
583 <<volume.volumeName()<<". Aligned: "<<portals.size()<<", unaligned: "<<unAlignedPortals.size());
584 return StatusCode::FAILURE;
585 }
586 StatusCode retCode = StatusCode::SUCCESS;
587 for (std::size_t p =0 ; p < portals.size(); ++p){
589 if (portals[p]->bounds() != unAlignedPortals[p].surface->bounds()) {
590 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The bounds of the "<<p
591 <<"-th portal differ:\n -- aligned: "<<portals[p]->bounds()
592 <<"\n -- unaligned: "<<unAlignedPortals[p].surface->bounds());
593 retCode = StatusCode::FAILURE;
594 }
595 const Amg::Transform3D& uTrf{unAlignedPortals[p].surface->localToGlobalTransform(geoCtx)};
596 const Amg::Transform3D& aTrf{portals[p]->localToGlobalTransform(geoCtx)};
597
598 if (!Amg::isIdentity(uTrf * aTrf.inverse())) {
599 ATH_MSG_ERROR(__func__<<"() "<<__LINE__
600 <<" - The unaligned and aligned portals don't end up at the same point \n"
601 <<" -- aligned: "<<Amg::toString(aTrf)<<"\n"<<" -- unaligned: "<<Amg::toString(uTrf));
602 retCode = StatusCode::FAILURE;
603 }
604 }
605 return retCode;
606 }
607
608
610 const Acts::TrackingGeometry& trackingGeometry) const {
611
612 //visit the volumes and check the overlaps with the other volumes in the tracking geometry
613 // also check overlaps between volumes and surfaces (e.g surfaces where the passive material is mapped)
614 std::vector<const Acts::TrackingVolume*> volumeVec{};
615 std::vector<const Acts::Surface*> passiveSurfaces{};
616
617 std::unordered_set<const Acts::TrackingVolume*> overlapVolumes{};
618 std::unordered_set<const Acts::Surface*> overlapSurfaces{};
619
620
621 //keep onyl the chamber volumes - not the cylinders
622 trackingGeometry.visitVolumes([&](const Acts::TrackingVolume* vol) {
623 //for the cylinder type volumes , fetch the inner surfaces only (e.g passive material surfaces)
624 if(vol->volumeBounds().type() == Acts::VolumeBounds::BoundsType::eCylinder){
625 ATH_MSG_DEBUG("checkTrackingGeometry() "<<__LINE__<<" - Fetch "<<vol->surfaces().size()
626 <<" passive surfaces from "<<vol->volumeName()<<".");
627 std::ranges::for_each(vol->surfaces(), [&](const Acts::Surface& surf){
628 ATH_MSG_VERBOSE(" --- "<<surf.type()<<" @"<<Amg::toString(surf.center(gctx.context()))
629 <<" "<<surf.bounds());
630 passiveSurfaces.push_back(&surf);
631 });
632 return;
633 }
634 const auto* placement = dynamic_cast<const ActsTrk::VolumePlacement*>(vol->volumePlacement());
635 // Not a senitive muon volume
636 if (!placement || !MuonGMR4::isMuon(placement->detectorType())) {
637 ATH_MSG_DEBUG("checkTrackingGeometry() "<<__LINE__<<" - Skip volume "
638 <<vol->volumeName()<<".");
639 return;
640 }
641 volumeVec.push_back(vol);
642 });
643
644 ATH_MSG_INFO(__func__<<"() "<<__LINE__<<" - Fetched "
645 << passiveSurfaces.size()<< " passive surfaces");
646 {
647 Acts::ObjVisualization3D visualHelper{};
648 std::ranges::for_each(passiveSurfaces,
649 [&visualHelper, &gctx](const Acts::Surface* surface) {
650 Acts::GeometryView3D::drawSurface(visualHelper, *surface, gctx.context());
651 });
652 visualHelper.write("MsTrackTest_passiveSurfaces.obj");
653
654 }
655 StatusCode retCode = StatusCode::SUCCESS;
656 for(std::size_t vIdx = 0; vIdx < volumeVec.size(); ++vIdx) {
657 const Acts::TrackingVolume* testVol{volumeVec.at(vIdx)};
658 ATH_CHECK(checkPortals(gctx, *testVol));
659
660 std::vector<const Acts::TrackingVolume*> overlaps{};
661 const std::vector<Amg::Vector3D> edges = cornerPoints(gctx, *testVol);
662
663 for(const auto& surface : testVol->surfaces()) {
664 //only plane or straw surfaces expected
665 std::vector<Amg::Vector3D> surfEdges = {};
666 if(surface.type() == Acts::Surface::SurfaceType::Straw){
667 ATH_MSG_VERBOSE(__func__<<"() - "<<__LINE__<<" Checking "<<surface.type()<<" surface "<<identify(surface)
668 <<" / "<<surface.geometryId() <<" in volume "<<testVol->volumeName());
669
670 auto edges = cornerPoints(gctx, dynamic_cast<const Acts::StrawSurface&>(surface));
671 surfEdges.insert(surfEdges.end() , edges.begin(), edges.end());
672 } else if(surface.type() == Acts::Surface::SurfaceType::Plane){
673 ATH_MSG_VERBOSE(__func__<<"() - "<<__LINE__<<" Checking "<<surface.type()<<" surface "<<identify(surface)
674 <<" / "<<surface.geometryId() <<" in volume "<<testVol->volumeName());
675
676 auto edges = cornerPoints(gctx, dynamic_cast<const Acts::PlaneSurface&>(surface));
677 surfEdges.insert(surfEdges.end() , edges.begin(), edges.end());
678 } else {
679 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The "<<surface.type()<<"-surface "
680 << m_idHelperSvc->toString(identify(surface))<<" / "
681 <<surface.geometryId() <<" is neither a straw nor a plane surface");
682 return StatusCode::FAILURE;
683 }
684
685 for(const auto& edge : surfEdges) {
686 if(!testVol->inside(gctx.context(), edge, 0.01)) {
687 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The "<<surface.type()<<"-surface "
688 << m_idHelperSvc->toString(identify(surface))<<" / "
689 <<surface.geometryId() <<" @vertex point "
690 <<Amg::toString(testVol->globalToLocalTransform(gctx.context()) *edge)<<", local: "
691 <<Amg::toString(surface.localToGlobalTransform(gctx.context()).inverse() * edge)
692 <<" is outside the parent volume: " << testVol->volumeName()
693 <<", "<<Amg::toString(testVol->localToGlobalTransform(gctx.context()))
694 <<", "<<testVol->volumeBounds());
695 overlapSurfaces.insert(&surface);
696 overlapVolumes.insert(testVol);
697 if (!m_ignoreOutsideSurf) {
698 retCode = StatusCode::FAILURE;
699 }
700 }
701 }
702 }
703
704 //check if the child volume is entirely enclosed by the mother volume
705 for (const Acts::TrackingVolume& child : testVol->volumes()) {
706 for(const auto& edge : cornerPoints(gctx, child)){
707 if(!testVol->inside(gctx.context(), edge, 0.01)){
708 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The children volume's "
709 << child.volumeName() <<" vertex point " <<Amg::toString(edge)
710 <<" is outside the parent volume" << testVol->volumeName());
711 return StatusCode::FAILURE;
712 }
713 }
714 }
716 if (!testVol->motherVolume()->isAlignable() && m_dumpObjs) {
717 std::vector<const Acts::Surface*> surfaces = extractSurfaces(*testVol);
718 const Identifier volId = identify(*surfaces.front());
719 const int eta = m_idHelperSvc->stationEta(volId);
720 saveEnvelope(gctx, std::format("TrackingVolume_{:}{:}{:}{:}_{:}",
721 chName(m_idHelperSvc->chamberIndex(volId)),
722 std::abs(eta), eta > 0 ? 'A' : 'C',
723 m_idHelperSvc->stationPhi(volId), vIdx),
724 *testVol, surfaces , chamberVolumes(*testVol));
725
726 }
727 // Check that there is not overlap with other volumes
728 for (std::size_t vIdx1 = 0 ; vIdx1 < vIdx; ++vIdx1) {
729 const Acts::TrackingVolume* overlapTest{volumeVec.at(vIdx1)};
730 if (overlapTest->motherVolume() == testVol ||
731 testVol->motherVolume() == overlapTest){
732 continue;
733 }
734 if (hasOverlap(gctx, edges, *overlapTest)) {
735 overlaps.push_back(overlapTest);
736 std::ranges::copy(extractSurfaces(*testVol),
737 std::inserter(overlapSurfaces, overlapSurfaces.begin()));
738 std::ranges::copy(extractSurfaces(*overlapTest),
739 std::inserter(overlapSurfaces, overlapSurfaces.begin()));
740 }
741 }
742 /*check if the tracking volume overlaps with surfaces of the tracking geometry
743 (e.g cylinders of the barrel where material is mapped) */
744 const Identifier volId = identify(*extractSurfaces(*testVol).front());
745 double volHalfR{0.}, volHalfZ{0.};
746 const double halfX = MuonGMR4::halfXhighY(testVol->volumeBounds());
747 const bool isBarrel = Muon::MuonStationIndex::isBarrel(m_idHelperSvc->chamberIndex(volId));
748 if (isBarrel){
749 volHalfR = MuonGMR4::halfZ(testVol->volumeBounds());
750 volHalfZ = MuonGMR4::halfY(testVol->volumeBounds());
751 } else {
752 volHalfZ = MuonGMR4::halfZ(testVol->volumeBounds());
753 volHalfR = MuonGMR4::halfY(testVol->volumeBounds());
754 }
755 const Amg::Vector3D center{testVol->center(gctx.context())};
756 const double rMin = center.perp() - volHalfR;
757 // Calculate the global r from the local half X which is always along phi
758 // and the halfR which is along Y (Z) for endcap (barrel) chambers.
759 const double rMax = (testVol->localToGlobalTransform(gctx.context()) *(
760 halfX * Amg::Vector3D::UnitX() +
761 volHalfR * Amg::Vector3D::Unit(1 + isBarrel))).perp();
762
763 double zMin = center.z() - volHalfZ;
764 double zMax = center.z() + volHalfZ;
766 if (testVol->volumeBounds().type() == Acts::VolumeBounds::eDiamond) {
767 zMin = 1._km; zMax = -1._km;
768 for (const Amg::Vector3D& p : cornerPoints(gctx, *testVol)){
769 zMin = std::min(zMin, p.z());
770 zMax = std::max(zMax, p.z());
771 }
772 }
773
774 for(std::size_t i = 0; i < passiveSurfaces.size(); ++i) {
775
776 const Acts::Surface* surf = passiveSurfaces[i];
777
778 const Amg::Vector3D center = surf->center(gctx.context());
779 if(surf->type() == Acts::Surface::SurfaceType::Cylinder) {
780 using BoundEnum = Acts::CylinderBounds::BoundValues;
781 const auto& bounds = static_cast<const Acts::CylinderBounds&>(surf->bounds());
782 const double passiveR = bounds.get(BoundEnum::eR);
783 const double passiveZ = bounds.get(BoundEnum:: eHalfLengthZ);
784 if (rMin < passiveR || rMax > passiveR){
785 continue;
786 }
787 if (passiveZ < zMin || -passiveZ > zMax) {
788 continue;
789 }
790 } else if(surf->type() == Acts::Surface::SurfaceType::Disc){
791 using BoundEnum = Acts::RadialBounds::BoundValues;
792 const auto& bounds = static_cast<const Acts::RadialBounds&>(surf->bounds());
793 if (center.z() < zMin || center.z() > zMax) {
794 continue;
795 }
796 const double surfRMax = bounds.get(BoundEnum::eMaxR);
797 const double surfRMin = bounds.get(BoundEnum::eMinR);
798 if (surfRMax < rMin || surfRMin > rMax){
799 continue;
800 }
801 // continue;
802 } else {
803 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The surface "<< surf->geometryId()
804 <<", "<< surf->name() <<" is not a cylinder surface or disc");
805 return StatusCode::FAILURE;
806 }
807
808 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The volume "
809 << testVol->volumeName() << " overlaps with the surface "
810 << surf->name() << " with geo id" << surf->geometryId()
811 <<" -- volume radius: ["<<rMin<<";"<<rMax<<"] z: ["<<zMin<<";"<<zMax<<"]"
812 <<" "<<surf->bounds());
813 if (m_ignoreOutsideSurf) {
814 retCode = StatusCode::FAILURE;
815 }
816 overlapSurfaces.insert(surf);
817 overlapVolumes.insert(testVol);
818
819
820 }
821
822 if(overlaps.empty()) {
823 ATH_MSG_DEBUG(__func__<<"() "<<__LINE__<<" - No overlaps detected for the volume "<<testVol->volumeName());
824 continue;
825 }
826
827 overlapVolumes.insert(overlaps.begin(), overlaps.end());
828 overlapVolumes.insert(testVol);
829
830 std::stringstream overlapStream{};
831 overlapStream<<__func__<<"() "<<__LINE__<<" - The volume "
832 <<testVol->volumeName() << " overlaps with: "<<std::endl;
833
834 for(const Acts::TrackingVolume* overlap: overlaps){
835 overlapStream<<" --- Volume: " << overlap->volumeName()<<", "<<overlap->volumeBounds()
836 <<", "<<Amg::toString(overlap->localToGlobalTransform(gctx.context()))<<std::endl;;
837 }
838 ATH_MSG_ALWAYS(overlapStream.str());
839 }
840
841 //check passive surfaces overlaps with each other
842 for(std::size_t i = 0; i < passiveSurfaces.size(); ++i) {
843 const Acts::Surface* surf = passiveSurfaces[i];
844 const Amg::Vector3D center = surf->center(gctx.context());
845 for(std::size_t j = i+1; j < passiveSurfaces.size(); ++j) {
846 const Acts::Surface* testSurf = passiveSurfaces[j];
847 ATH_MSG_INFO(__func__<<"() "<<__LINE__<<" - Checking passive surface "<<surf->name()<<" geo id "<<surf->geometryId()
848 <<" with passive surface "<<testSurf->name()<<" geo id "<<testSurf->geometryId());
849 if(testSurf->geometryId().volume() != surf->geometryId().volume()){
850 continue;
851 }
852 if(surf->type() == Acts::Surface::SurfaceType::Cylinder){
853 using BoundEnum = Acts::CylinderBounds::BoundValues;
854 const auto& bounds = static_cast<const Acts::CylinderBounds&>(surf->bounds());
855 double passiveR = bounds.get(BoundEnum::eR);
856 double passiveZ = bounds.get(BoundEnum:: eHalfLengthZ);
857 bool overlap = checkOverlapWithCylinder(gctx.context(), testSurf, center, passiveR, passiveZ);
858 if(overlap) {
859 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The surface "<<surf->name()<<"geo id "<<surf->geometryId()
860 <<" overlaps with surface "<<testSurf->name()<<"geo id "<<testSurf->geometryId()
861 <<" in the same volume "<<surf->geometryId().volume());
862 overlapSurfaces.insert(surf);
863 overlapSurfaces.insert(testSurf);
864 if (!m_ignoreOutsideSurf) {
865 retCode = StatusCode::FAILURE;
866 }
867 }
868 }else if(surf->type() == Acts::Surface::SurfaceType::Disc){
869 using BoundEnum = Acts::RadialBounds::BoundValues;
870 const auto& bounds = static_cast<const Acts::RadialBounds&>(surf->bounds());
871 bool overlap = checkOverlapWithDisc(gctx.context(), testSurf, center, bounds.get(BoundEnum::eMaxR));
872 if(overlap) {
873 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The surface "<<surf->name()<<"geo id "<<surf->geometryId()
874 <<" overlaps with surface "<<testSurf->name()<<"geo id "<<testSurf->geometryId()
875 <<" in the same volume "<<surf->geometryId().volume());
876 overlapSurfaces.insert(surf);
877 overlapSurfaces.insert(testSurf);
878 if (!m_ignoreOutsideSurf) {
879 retCode = StatusCode::FAILURE;
880 }
881 }
882 } else {
883 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The surface "<< surf->geometryId()
884 <<", "<< surf->name() <<" is not a cylinder surface or disc");
885 return StatusCode::FAILURE;
886 }
887 }
888 }
889
890 if (overlapVolumes.size() || overlapSurfaces.size()) {
891 const Acts::Volume* refVolume = (*overlapVolumes.begin());
892 std::vector<const Acts::Volume*> childVols{};
893 childVols.insert(childVols.begin(),std::next(overlapVolumes.begin()), overlapVolumes.end());
894 std::vector<const Acts::Surface*> childSurfs{overlapSurfaces.begin(), overlapSurfaces.end()};
895 saveEnvelope(gctx, "TrackingGeometryOverlaps", *refVolume,
896 childSurfs, childVols);
897 }
898
899
900 if(overlapVolumes.empty()) {
901 ATH_MSG_ALWAYS("No overlaps detected in the tracking geometry!!");
902 } else if (!m_ignoreOverlapCh) {
903 retCode = StatusCode::FAILURE;
904 }
905 return retCode;
906 }
907
909 const std::string& envName,
910 const Acts::Volume& envelopeVol,
911 const std::vector<const Acts::Surface*>& assocSurfaces,
912 const std::vector<const Acts::Volume*>& subVols) const {
913 Acts::ObjVisualization3D visualHelper{};
914 std::ranges::for_each(assocSurfaces, [&visualHelper, &gctx](const Acts::Surface* surface) {
915 Acts::GeometryView3D::drawSurface(visualHelper, *surface, gctx.context());
916
917 });
918 std::ranges::for_each(subVols, [&visualHelper, &gctx](const Acts::Volume* subVol) {
919 Acts::GeometryView3D::drawVolume(visualHelper,*subVol, gctx.context(), Amg::Transform3D::Identity(),
920 Acts::s_viewPassive);
921 });
922 Acts::GeometryView3D::drawVolume(visualHelper, envelopeVol, gctx.context());
923 ATH_MSG_DEBUG("Save new envelope 'MsTrackTest_"<<envName<<".obj'");
924 visualHelper.write(std::format("MsTrackTest_{:}.obj", envName));
925 }
926
927 StatusCode MuonChamberToolTest::execute(const EventContext& ctx) const {
928 const ActsTrk::GeometryContext* gctx{nullptr};
929 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
931 ATH_CHECK(checkChambers(*gctx));
933 ATH_CHECK(checkTrackingGeometry(*gctx, *m_trackingGeometrySvc->trackingGeometry()));
934
935 return StatusCode::SUCCESS;
936 }
937 template <class EnvelopeType>
939 const MdtReadoutElement& mdtMl,
940 const EnvelopeType& chamber,
941 const Acts::Volume& detVol) const {
942 ATH_MSG_VERBOSE("Test whether "<<m_idHelperSvc->toStringDetEl(mdtMl.identify())<<std::endl<<mdtMl.getParameters());
943
944 for (unsigned int layer = 1; layer <= mdtMl.numLayers(); ++layer) {
945 for (unsigned int tube = 1; tube <= mdtMl.numTubesInLay(); ++tube) {
946 const IdentifierHash idHash = mdtMl.measurementHash(layer, tube);
947 if (!mdtMl.isValid(idHash)){
948 continue;
949 }
950 const Amg::Transform3D& locToGlob{mdtMl.localToGlobalTransform(gctx, idHash)};
951 const Identifier measId{mdtMl.measurementId(idHash)};
952
953 ATH_CHECK(pointInside(gctx, chamber, detVol, mdtMl.globalTubePos(gctx, idHash), "tube center", measId));
954
955 ATH_CHECK(pointInside(gctx, chamber, detVol, mdtMl.readOutPos(gctx, idHash), "tube readout", measId));
956 ATH_CHECK(pointInside(gctx, chamber, detVol, mdtMl.highVoltPos(gctx, idHash), "tube HV", measId));
957
958 ATH_CHECK(pointInside(gctx, chamber, detVol, locToGlob*(-mdtMl.innerTubeRadius() * Amg::Vector3D::UnitX()),
959 "bottom of the tube box", measId));
960 ATH_CHECK(pointInside(gctx, chamber, detVol, locToGlob*(mdtMl.innerTubeRadius() * Amg::Vector3D::UnitX()),
961 "sealing of the tube box", measId));
962
963 ATH_CHECK(pointInside(gctx, chamber, detVol, locToGlob*(-mdtMl.innerTubeRadius() * Amg::Vector3D::UnitY()),
964 "wall to the previous tube", measId));
965 ATH_CHECK(pointInside(gctx, chamber, detVol, locToGlob*(-mdtMl.innerTubeRadius() * Amg::Vector3D::UnitY()),
966 "wall to the next tube", measId));
967 }
968 }
969 return StatusCode::SUCCESS;
970 }
971 template<class EnvelopeType>
973 const RpcReadoutElement& rpc,
974 const EnvelopeType& chamber,
975 const Acts::Volume& detVol) const {
976
977 ATH_MSG_VERBOSE("Test whether "<<m_idHelperSvc->toStringDetEl(rpc.identify())<<std::endl<<rpc.getParameters());
978
979 const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
980 for (unsigned int gasGap = 1 ; gasGap <= rpc.nGasGaps(); ++gasGap) {
981 for (int doubletPhi = rpc.doubletPhi(); doubletPhi <= rpc.doubletPhiMax(); ++doubletPhi){
982 for (bool measPhi : {false, true}) {
983 const int nStrips = measPhi ? rpc.nPhiStrips() : rpc.nEtaStrips();
984 for (int strip = 1; strip <= nStrips; ++strip) {
985 const Identifier stripId = idHelper.channelID(rpc.identify(),rpc.doubletZ(),
986 doubletPhi, gasGap, measPhi, strip);
987 ATH_CHECK(pointInside(gctx, chamber, detVol, rpc.stripPosition(gctx, stripId), "center", stripId));
988 ATH_CHECK(pointInside(gctx, chamber, detVol, rpc.leftStripEdge(gctx, stripId), "right edge", stripId));
989 ATH_CHECK(pointInside(gctx, chamber, detVol, rpc.rightStripEdge(gctx, stripId), "left edge", stripId));
990 }
991 }
992 }
993 }
994 return StatusCode::SUCCESS;
995 }
996 template <class EnevelopeType>
998 const TgcReadoutElement& tgc,
999 const EnevelopeType& chamber,
1000 const Acts::Volume& detVol) const {
1001 for (unsigned int gasGap = 1; gasGap <= tgc.nGasGaps(); ++gasGap){
1002 for (bool isStrip : {false}) {
1003 const IdentifierHash layHash = tgc.constructHash(0, gasGap, isStrip);
1004 const unsigned int nChannel = tgc.numChannels(layHash);
1005 for (unsigned int channel = 1; channel <= nChannel ; ++channel) {
1006 const IdentifierHash measHash = tgc.constructHash(channel, gasGap, isStrip);
1007 ATH_CHECK(pointInside(gctx, chamber, detVol, tgc.channelPosition(gctx, measHash),
1008 "center", tgc.measurementId(measHash)));
1009 }
1010 }
1011 }
1012 return StatusCode::SUCCESS;
1013 }
1014 template <class EnevelopeType>
1016 const MmReadoutElement& mm,
1017 const EnevelopeType& chamber,
1018 const Acts::Volume& detVol) const {
1019
1020 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
1021 for(unsigned int gasGap = 1; gasGap <= mm.nGasGaps(); ++gasGap){
1022 IdentifierHash gasGapHash = MmReadoutElement::createHash(gasGap,0);
1023 unsigned int firstStrip = mm.firstStrip(gasGapHash);
1024 for(unsigned int strip = firstStrip; strip <= mm.numStrips(gasGapHash); ++strip){
1025 const Identifier stripId = idHelper.channelID(mm.identify(), mm.multilayer(), gasGap, strip);
1026 ATH_CHECK(pointInside(gctx, chamber, detVol, mm.stripPosition(gctx, stripId), "center", stripId));
1027 ATH_CHECK(pointInside(gctx, chamber, detVol, mm.leftStripEdge(gctx, mm.measurementHash(stripId)), "left edge", stripId));
1028 ATH_CHECK(pointInside(gctx, chamber, detVol, mm.rightStripEdge(gctx, mm.measurementHash(stripId)), "right edge", stripId));
1029 }
1030 }
1031
1032 return StatusCode::SUCCESS;
1033 }
1034 template <class EnvelopeType>
1036 const sTgcReadoutElement& stgc,
1037 const EnvelopeType& chamber,
1038 const Acts::Volume& detVol) const{
1039
1040 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
1041 for(unsigned int gasGap = 1; gasGap <= stgc.numLayers(); ++gasGap){
1042
1043 for(unsigned int nch = 1; nch <= stgc.nChTypes(); ++nch){
1044 IdentifierHash gasGapHash = sTgcReadoutElement::createHash(gasGap, nch, 0, 0);
1045 const unsigned int nStrips = stgc.numChannels(gasGapHash);
1047
1048 for(unsigned int strip = 1; strip <= nStrips; ++strip){
1049 const Identifier stripId = idHelper.channelID(stgc.identify(), stgc.multilayer(), gasGap, nch, strip);
1050 const IdentifierHash stripHash = stgc.measurementHash(stripId);
1051 ATH_CHECK(pointInside(gctx, chamber, detVol, stgc.globalChannelPosition(gctx, stripHash), "channel position", stripId));
1052
1054 ATH_CHECK(pointInside(gctx, chamber, detVol, stgc.rightStripEdge(gctx, stripHash), "channel position", stripId));
1055 ATH_CHECK(pointInside(gctx, chamber, detVol, stgc.leftStripEdge(gctx, stripHash), "channel position", stripId));
1056 }
1057 }
1058 }
1059 }
1060 return StatusCode::SUCCESS;
1061
1062 }
1063}
1064
const std::regex re(r_e)
Scalar eta() const
pseudorapidity method
Scalar mag() const
mag method
constexpr std::array< T, N > make_array(const T &def_val)
Helper function to initialize in-place arrays with non-zero values.
Definition ArrayHelper.h:10
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_ALWAYS(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
void section(const std::string &sec)
Acts::GeometryContext context() const
Extension of the interface of the Acts::SurfacePlacementBase for ATLAS.
virtual Identifier identify() const =0
Return the ATLAS identifier of the surface.
Implementation to make a (tracking) volume alignable.
const ServiceHandle< StoreGateSvc > & detStore() const
void setLevel(MSG::Level lvl)
Change the current logging level.
This is a "hash" representation of an Identifier.
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channel) const
Chamber represent the volume enclosing a muon station.
Definition Chamber.h:29
std::vector< const MuonReadoutElement * > ReadoutSet
Define the list of read out elements of the chamber.
Definition Chamber.h:32
Readout element to describe the Monitored Drift Tube (Mdt) chambers Mdt chambers usually comrpise out...
Amg::Vector3D highVoltPos(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the endpoint of the tube connected to the high voltage in the ATLAS coordinate frame.
unsigned numLayers() const
Returns how many tube layers are inside the multi layer [1;4].
bool isValid(const IdentifierHash &measHash) const
Checks whether the passed meaurement hash corresponds to a valid tube described by the readout elemen...
Amg::Vector3D readOutPos(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the endpoint of the tube where the readout card is mounted in the ATLAS coordinate frame.
const parameterBook & getParameters() const
Get a const reference to the parameter book.
Amg::Vector3D globalTubePos(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the position of the tube mid point in the ATLAS coordinate frame.
double innerTubeRadius() const
Returns the inner tube radius.
unsigned numTubesInLay() const
Returns the number of tubes in a layer.
static IdentifierHash measurementHash(unsigned layerNumber, unsigned tubeNumber)
Constructs a Measurement hash from layer && tube number.
Identifier measurementId(const IdentifierHash &measHash) const override final
Back conversion of the measurement hash towards a full identifier Tube & layer number are extracted f...
static IdentifierHash createHash(const int gasGap, const int strip)
const MuonDetectorManager * m_detMgr
Gaudi::Property< bool > m_ignoreOverlapCh
The overlap of chamber volumes does not lead to a failure.
ActsTrk::GeoContextReadKey_t m_geoCtxKey
StatusCode checkEnvelopes(const ActsTrk::GeometryContext &gctx) const
Check envelopes.
StatusCode checkPortals(const ActsTrk::GeometryContext &gctx, const Acts::TrackingVolume &volume) const
StatusCode execute(const EventContext &ctx) const override
StatusCode checkChambers(const ActsTrk::GeometryContext &gctx) const
Check whether the chamber envelopes are consistent.
void saveEnvelope(const ActsTrk::GeometryContext &gctx, const std::string &envName, const Acts::Volume &envelopeVol, const std::vector< const Acts::Surface * > &assocSurfaces, const std::vector< const Acts::Volume * > &subVolumes={}) const
Gaudi::Property< bool > m_dumpObjs
Dump the chambers & sectors as separate obj files.
StatusCode pointInside(const ActsTrk::GeometryContext &gctx, const EnvelopeType &envelope, const Acts::Volume &boundVol, const Amg::Vector3D &point, const std::string &descr, const Identifier &channelId) const
Checks whether the point is inside of an envelope object, i.e.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< std::string > m_overlapChambObj
Name of the chamber output obj file.
StatusCode testReadoutEle(const ActsTrk::GeometryContext &gctx, const MdtReadoutElement &readOutEle, const EnvelopeType &envelope, const Acts::Volume &boundVol) const
Checks whether all channels of a given readout element are fully covered by the envelope.
Gaudi::Property< unsigned > m_overlapSamples
Number of points to scan along the lines between two volume corners to check whether they belong to a...
ServiceHandle< ActsTrk::ITrackingGeometrySvc > m_trackingGeometrySvc
Gaudi::Property< bool > m_ignoreOutsideSurf
The exceeding surfaces does not lead to a failure.
StatusCode allReadoutInEnvelope(const ActsTrk::GeometryContext &ctx, const EnvelopeType &envelope) const
Checks whether the readout elements of an enevelope are completely embedded into the envelope.
StatusCode checkTrackingGeometry(const ActsTrk::GeometryContext &gctx, const Acts::TrackingGeometry &trackingGeometry) const
Check tracking geometry volumes.
std::vector< Amg::Vector3D > cornerPoints(const ActsTrk::GeometryContext &gctx, const Acts::Volume &volume) const
Returns the edge points from a trapezoidal / cuboid /diamond volume.
bool hasOverlap(const ActsTrk::GeometryContext &gctx, const std::vector< Amg::Vector3D > &chamberEdges, const Acts::Volume &volume) const
Checks whether the edge points from a trapezoid/cuboid/diamond form a volume overlapping with the giv...
MuonReadoutElement is an abstract class representing the geometry of a muon detector.
Identifier identify() const override final
Return the ATLAS identifier.
const Amg::Transform3D & localToGlobalTransform(const ActsTrk::GeometryContext &ctx) const override final
Returns the transformation from the local coordinate system of the readout element into the global AT...
unsigned nPhiStrips() const
Number of strips measuring the phi coordinate.
Amg::Vector3D leftStripEdge(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the global posiition of the strip edge at positive local Y.
int doubletZ() const
Returns the doublet Z field of the MuonReadoutElement identifier.
int doubletPhi() const
Returns the doublet Phi field of the MuonReadoutElement identifier.
Amg::Vector3D rightStripEdge(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the global position of the strip edge at negative local Y.
unsigned nEtaStrips() const
Number of strips measuring the eta coordinate.
int doubletPhiMax() const
Returns the maximum phi panel.
Amg::Vector3D stripPosition(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the position of the strip center.
unsigned nGasGaps() const
Returns the number of gasgaps described by this ReadOutElement (usally 2 or 3).
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
const ChamberSet & chambers() const
Returns the associated chambers with this sector.
GeoModel::TransientConstSharedPtr< Chamber > ChamberPtr
void defineStripLayout(Amg::Vector2D &&posFirst, const double stripPitch, const double stripWidth, const int numStrips, const int numFirst=1)
Defines the layout of the strip detector by specifing the position of the first strip w....
CheckVector2D leftEdge(int stripNumb) const
Returns the left edge of the strip (Global numbering scheme).
void defineTrapezoid(double HalfShortY, double HalfLongY, double HalfHeight)
Defines the edges of the trapezoid.
bool insideTrapezoid(const Amg::Vector2D &extPos) const
Checks whether an external point is inside the trapezoidal area.
CheckVector2D rightEdge(int stripNumb) const
Returns the right edge of the strip (Global numbering scheme).
Amg::Vector3D channelPosition(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the center of the measurement channel eta measurement: wire gang center phi measurement: stri...
Identifier measurementId(const IdentifierHash &measHash) const override final
Back conversion of the measurement hash to a full Athena Identifier The behaviour is undefined if a l...
static IdentifierHash constructHash(unsigned measCh, unsigned gasGap, const bool isStrip)
Constructs the Hash out of the Identifier fields (channel, gasGap, isStrip).
unsigned numChannels(const IdentifierHash &measHash) const
Returns the number of readout channels.
unsigned nGasGaps() const
Returns the number of gasgaps described by this ReadOutElement (usally 2 or 3).
unsigned numChannels(const IdentifierHash &measHash) const
Returns the number of strips / wires / pads in a given gasGap.
IdentifierHash measurementHash(const Identifier &measId) const override final
Constructs the identifier hash from the full measurement Identifier.
Amg::Vector3D leftStripEdge(const ActsTrk::GeometryContext &ctx, const IdentifierHash &measHash) const
int multilayer() const
Returns the multilayer of the sTgcReadoutElement.
unsigned nChTypes() const
Number of Channel Types.
Amg::Vector3D rightStripEdge(const ActsTrk::GeometryContext &ctx, const IdentifierHash &measHash) const
unsigned numLayers() const
Returns the number of gas gap layers.
ReadoutChannelType
ReadoutChannelType to distinguish the available readout channels Pad - pad readout channel Strip - et...
Amg::Vector3D globalChannelPosition(const ActsTrk::GeometryContext &ctx, const IdentifierHash &measHash) const
Returns the global pad/strip/wireGroup position.
static IdentifierHash createHash(const unsigned gasGap, const unsigned channelType, const unsigned channel, const unsigned wireInGrp=0)
Create a measurement hash from the Identifier fields.
Identifier channelID(int stationName, int stationEta, int stationPhi, int doubletR, int doubletZ, int doubletPhi, int gasGap, int measuresPhi, int strip) const
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channelType, int channel) const
@ Mm
Maybe not needed in the migration.
@ Tgc
Resitive Plate Chambers.
@ sTgc
Micromegas (NSW).
@ Rpc
Monitored Drift Tubes.
@ Mdt
MuonSpectrometer.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
bool isIdentity(const Amg::Transform3D &trans)
Checks whether the transformation is the Identity transformation.
Amg::Transform3D getRotateZ3D(double angle)
Rotate the coordinate system by an angle around the z-axis.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
double halfY(const Acts::VolumeBounds &bounds)
Returns the half-Y length for the parsed volume bounds (Trapezoid/ Cuboid).
SpectrometerSector::ChamberSet ChamberSet
bool isMuon(const ActsTrk::DetectorType type)
Returns whether the parsed type is muon.
double halfZ(const Acts::VolumeBounds &bounds)
Returns the half-Z length for the parsed volume bounds (Trapezoid/ Cuboid).
double halfXhighY(const Acts::VolumeBounds &bounds)
Returns the half-Y length @ posiive Y for the parsed volume bounds (Trapezoid/ Cuboid).
double halfXlowY(const Acts::VolumeBounds &bounds)
Returns the half-X length @ negative Y for the parsed volume bounds (Trapezoid/ Cuboid).
bool isBarrel(const ChIndex index)
Returns true if the chamber index points to a barrel chamber.
const std::string & chName(ChIndex index)
convert ChIndex into a string
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.