ATLAS Offline Software
Loading...
Searching...
No Matches
MuonChamberToolTest.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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#include <GaudiKernel/SystemOfUnits.h>
20
21#include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
22#include "Acts/Geometry/TrackingGeometry.hpp"
23#include "Acts/Surfaces/TrapezoidBounds.hpp"
24
25#include "Acts/Visualization/ObjVisualization3D.hpp"
26#include "Acts/Visualization/GeometryView3D.hpp"
27#include "Acts/Definitions/Units.hpp"
28
30
31using namespace Acts::UnitLiterals;
32using namespace Muon::MuonStationIndex;
33
34
35#include <format>
36namespace{
37 constexpr double tolerance = 10. *Gaudi::Units::micrometer;
38
39 std::vector<std::shared_ptr<Acts::Volume>> chamberVolumes(const ActsTrk::GeometryContext& gctx,
40 const MuonGMR4::SpectrometerSector& sector) {
41 std::vector<std::shared_ptr<Acts::Volume>> vols{};
42 std::ranges::transform(sector.chambers(),std::back_inserter(vols),
43 [&gctx](const auto& ch){ return ch->boundingVolume(gctx); });
44 return vols;
45 }
46}
47
48namespace MuonGMR4 {
49
51 ATH_CHECK(m_idHelperSvc.retrieve());
52 ATH_CHECK(m_geoCtxKey.initialize());
54 ATH_CHECK(detStore()->retrieve(m_detMgr));
55 return StatusCode::SUCCESS;
56 }
57 template <class EnvelopeType>
58#if defined(FLATTEN) && defined(__GNUC__)
59// We compile this function with optimization, even in debug builds; otherwise,
60// the heavy use of Eigen makes it too slow. However, from here we may call
61// to out-of-line Eigen code that is linked from other DSOs; in that case,
62// it would not be optimized. Avoid this by forcing all Eigen code
63// to be inlined here if possible.
64[[gnu::flatten]]
65#endif
66 StatusCode MuonChamberToolTest::pointInside(const EnvelopeType& chamb,
67 const Acts::Volume& boundVol,
68 const Amg::Vector3D& point,
69 const std::string& descr,
70 const Identifier& channelId) const {
71
72 // Explicitly inline Volume::inside here so that it gets
73 // flattened in debug builds.
74 Acts::Vector3 posInVolFrame((boundVol.transform().inverse()) * point);
75 if (boundVol.volumeBounds().inside(posInVolFrame,tolerance)) {
76 ATH_MSG_VERBOSE("In channel "<<m_idHelperSvc->toString(channelId)
77 <<", point "<<descr <<" is inside of the chamber "<<std::endl<<chamb<<std::endl
78 <<"Local position:" <<Amg::toString(boundVol.itransform() * point));
79 return StatusCode::SUCCESS;
80 }
81 const Amg::Vector3D locPos{boundVol.itransform() * point};
82
83 StripDesign planeTrapezoid{};
84 planeTrapezoid.defineTrapezoid(chamb.halfXShort(), chamb.halfXLong(), chamb.halfY());
85 planeTrapezoid.setLevel(MSG::VERBOSE);
87 static const Eigen::Rotation2D axisSwap{90. *Gaudi::Units::deg};
88 if (std::abs(locPos.z()) - chamb.halfZ() < -tolerance &&
89 planeTrapezoid.insideTrapezoid(axisSwap*locPos.block<2,1>(0,0))) {
90 return StatusCode::SUCCESS;
91 }
92 planeTrapezoid.defineStripLayout(locPos.y() * Amg::Vector2D::UnitX(), 1, 1, 1);
93 ATH_MSG_FATAL("In channel "<<m_idHelperSvc->toString(channelId) <<", the point "
94 << descr <<" "<<Amg::toString(point)<<" is not part of the chamber volume."
95 <<std::endl<<std::endl<<chamb<<std::endl<<"Local position "<<Amg::toString(locPos)
96 <<", "<<planeTrapezoid
97 <<", box left edge: "<<Amg::toString(planeTrapezoid.leftEdge(1).value_or(Amg::Vector2D::Zero()))
98 <<", box right edge "<<Amg::toString(planeTrapezoid.rightEdge(1).value_or(Amg::Vector2D::Zero())));
99 return StatusCode::FAILURE;
100 }
101
102 StatusCode MuonChamberToolTest::pointInside(const Acts::TrackingVolume& volume,
103 const Amg::Vector3D& point,
104 const std::string& descr,
105 const Identifier& chamberId) const {
106 if (volume.inside(point, tolerance)) {
107 return StatusCode::SUCCESS;
108 }
109 const std::array<Amg::Vector3D, 8> volumeCorners = cornerPoints(volume);
110 ATH_MSG_FATAL("In channel "<<m_idHelperSvc->toString(chamberId) <<", the point "
111 << descr <<" "<<Amg::toString(volume.itransform()* point)<<" is not part of the chamber volume. The corners of the volume are:");
112 for(const auto& corner : volumeCorners) {
113 ATH_MSG_FATAL(" "<<Amg::toString(volume.itransform()*corner));
114 }
115 return StatusCode::FAILURE;
116 }
117
118 template <class EnvelopeType>
120 const EnvelopeType& envelope) const {
121 std::shared_ptr<Acts::Volume> boundVol = envelope.boundingVolume(gctx);
122 const Chamber::ReadoutSet reEles = envelope.readoutEles();
123 for(const MuonReadoutElement* readOut : reEles) {
124 if constexpr (std::is_same_v<EnvelopeType, SpectrometerSector>) {
125 if (readOut->msSector() != &envelope) {
126 ATH_MSG_FATAL("Mismatch in the sector association "<<m_idHelperSvc->toStringDetEl(readOut->identify())
127 <<std::endl<<(*readOut->msSector())<<std::endl<<envelope);
128 return StatusCode::FAILURE;
129 }
130 } else if constexpr (std::is_same_v<EnvelopeType, Chamber>) {
131 if (readOut->chamber() != &envelope) {
132 ATH_MSG_FATAL("Mismatch in the chamber association "<<m_idHelperSvc->toStringDetEl(readOut->identify())
133 <<std::endl<<(*readOut->chamber())<<std::endl<<envelope);
134 return StatusCode::FAILURE;
135 }
136 }
137 switch (readOut->detectorType()) {
139 const auto* detEle = static_cast<const TgcReadoutElement*>(readOut);
140 ATH_CHECK(testReadoutEle(gctx, *detEle, envelope, *boundVol));
141 break;
143 const auto* detEle = static_cast<const MdtReadoutElement*>(readOut);
144 ATH_CHECK(testReadoutEle(gctx, *detEle, envelope, *boundVol));
145 break;
147 const auto* detEle = static_cast<const RpcReadoutElement*>(readOut);
148 ATH_CHECK(testReadoutEle(gctx, *detEle, envelope, *boundVol));
149 break;
151 const auto* detEle = static_cast<const MmReadoutElement*>(readOut);
152 ATH_CHECK(testReadoutEle(gctx, *detEle, envelope, *boundVol));
153 break;
155 const auto* detEle = static_cast<const sTgcReadoutElement*>(readOut);
156 ATH_CHECK(testReadoutEle(gctx, *detEle, envelope, *boundVol));
157 break;
158 } default: {
159 ATH_MSG_FATAL("Who came up with putting "<<ActsTrk::to_string(readOut->detectorType())
160 <<" into the MS");
161 return StatusCode::FAILURE;
162 }
163 }
164 }
165 ATH_MSG_DEBUG("All "<<reEles.size()<<" readout elements are embedded in "<<envelope);
166 return StatusCode::SUCCESS;
167 }
168
169 std::array<Amg::Vector3D, 8> MuonChamberToolTest::cornerPoints(const Acts::Volume& volume) const {
170 std::array<Amg::Vector3D, 8> edges{make_array<Amg::Vector3D,8>(Amg::Vector3D::Zero())};
171 unsigned int edgeIdx{0};
172 ATH_MSG_VERBOSE("Fetch volume bounds "<<Amg::toString(volume.transform()));
173 const auto& bounds = volume.volumeBounds();
174 for (const double signX : {-1., 1.}) {
175 for (const double signY : { -1., 1.}) {
176 for (const double signZ: {-1., 1.}) {
177 const Amg::Vector3D edge{signX* (signY>0 ? MuonGMR4::halfXhighY(bounds) : MuonGMR4::halfXlowY(bounds)),
178 signY*MuonGMR4::halfY(bounds),
179 signZ*MuonGMR4::halfZ(bounds)};
180 edges[edgeIdx] = volume.transform() * edge;
181 ATH_MSG_VERBOSE("Local edge "<<Amg::toString(edge)<<", global edge: "<<Amg::toString(edges[edgeIdx]));
182 ++edgeIdx;
183 }
184 }
185 }
186 return edges;
187 }
188
189 std::array<Amg::Vector3D, 8> MuonChamberToolTest::cornerPoints(const Acts::GeometryContext& gctx, const Acts::StrawSurface& surface) const {
190 std::array<Amg::Vector3D, 8> edges{make_array<Amg::Vector3D,8>(Amg::Vector3D::Zero())};
191 using BoundEnum = Acts::LineBounds::BoundValues;
192 const auto& bounds = static_cast<const Acts::LineBounds&>(surface.bounds());
193 unsigned int edgeIdx{0};
194
195 ATH_MSG_VERBOSE("Fetch volume bounds "<<Amg::toString(surface.transform(gctx)));
196 for (const double signX : {-1., 1.}) {
197 for (const double signY : { -1., 1.}) {
198 for (const double signZ: {-1., 1.}) {
199 const Amg::Vector3D edge{signX*bounds.get(BoundEnum::eR),
200 signY*bounds.get(BoundEnum::eR),
201 signZ*bounds.get(BoundEnum::eHalfLengthZ)};
202 edges[edgeIdx] = surface.transform(gctx) * edge;
203 ++edgeIdx;
204 }
205 }
206 }
207 return edges;
208 }
209
210 std::array<Amg::Vector3D, 4> MuonChamberToolTest::cornerPoints(const Acts::GeometryContext& gctx, const Acts::PlaneSurface& surface) const {
211 std::array<Amg::Vector3D, 4> edges{make_array<Amg::Vector3D,4>(Amg::Vector3D::Zero())};
212 if(surface.bounds().type() == Acts::SurfaceBounds::BoundsType::eRectangle) { //RPC surfaces are rectangles
213 const Acts::RectangleBounds& bounds = static_cast<const Acts::RectangleBounds&>(surface.bounds());
214 using BoundEnum = Acts::RectangleBounds::BoundValues;
215
216 unsigned int edgeIdx{0};
217 for(const double signX : {-1., 1.}) {
218 for (const double signY : { -1., 1.}) {
219 const Amg::Vector3D edge{signX < 0 ? bounds.get(BoundEnum::eMinX) : bounds.get(BoundEnum::eMaxX),
220 signY < 0 ? bounds.get(BoundEnum::eMinY) : bounds.get(BoundEnum::eMaxY), 0.};
221 edges[edgeIdx] = surface.transform(gctx) * edge;
222 ++edgeIdx;
223 }
224 }
225 return edges;
226 } else if(surface.bounds().type() == Acts::SurfaceBounds::BoundsType::eTrapezoid) {
227 using BoundEnum = Acts::TrapezoidBounds::BoundValues;
228 const auto& bounds = static_cast<const Acts::TrapezoidBounds&>(surface.bounds());
229 unsigned int edgeIdx{0};
230
231 ATH_MSG_VERBOSE("Fetch volume bounds "<<Amg::toString(surface.transform(gctx)));
232 for (const double signX : {-1., 1.}) {
233 for (const double signY : { -1., 1.}) {
234 const Amg::Vector3D edge{Amg::getRotateZ3D(-1.*bounds.get(BoundEnum::eRotationAngle)) *
235 Amg::Vector3D(signX*bounds.get(signY < 0 ? BoundEnum::eHalfLengthXnegY : BoundEnum::eHalfLengthXposY),
236 signY*bounds.get(BoundEnum::eHalfLengthY), 0.)};
237
238 edges[edgeIdx] = surface.transform(gctx) * edge;
239 ++edgeIdx;
240 }
241 }
242
243 return edges;
244 } else {
245 ATH_MSG_FATAL("The surface bounds are neither a rectangle nor a trapezoid, this is not supported yet");
246 return edges;
247 }
248 }
249
250#if defined(FLATTEN) && defined(__GNUC__)
251// We compile this function with optimization, even in debug builds; otherwise,
252// the heavy use of Eigen makes it too slow. However, from here we may call
253// to out-of-line Eigen code that is linked from other DSOs; in that case,
254// it would not be optimized. Avoid this by forcing all Eigen code
255// to be inlined here if possible.
256[[gnu::flatten]]
257#endif
258 bool MuonChamberToolTest::hasOverlap(const std::array<Amg::Vector3D, 8>& chamberEdges,
259 const Acts::Volume& volume) const {
260
262 const Amg::Vector3D center{volume.center()};
263 double minDist = 1._km;
264 for (const Amg::Vector3D& edge : chamberEdges) {
265 minDist = std::min(minDist, (edge - center).mag());
266 }
269 std::vector<double> boundValues = volume.volumeBounds().values();
270 if (std::ranges::none_of(boundValues, [minDist](const double bound){
271 return minDist < 2.5*bound;
272 })) {
273 return false;
274 }
275 const double stepLength = 1. / m_overlapSamples;
276
277 const Acts::VolumeBounds& volBounds = volume.volumeBounds();
278 const Acts::Transform3& itransform = volume.itransform();
279 for (unsigned edge1 = 1; edge1 < chamberEdges.size(); ++edge1) {
280 for (unsigned edge2 = 0; edge2 < edge1; ++edge2) {
281 for (unsigned step = 0 ; step <= m_overlapSamples; ++step) {
282 const double section = stepLength * step;
283 const Amg::Vector3D testPoint = section* chamberEdges[edge1] + (1. -section) *chamberEdges[edge2];
284 // Using acts::Volume::inside is horribly slow in dbg builds.
285 Acts::Vector3 posInVolFrame = itransform * testPoint;
286 if (volBounds.inside (posInVolFrame)) {
287 return true;
288 }
289 }
290 }
291 }
292 return false;
293 }
295
296 std::vector<const MuonReadoutElement*> allRE = m_detMgr->getAllReadoutElements();
298 const ChamberSet chambers = m_detMgr->getAllChambers();
299 ATH_MSG_INFO("Fetched "<<chambers.size()<<" chambers.");
300 std::vector<const Chamber*> chamberVec{chambers.begin(), chambers.end()};
301
302 const auto missChamb = std::ranges::find_if(allRE, [&chamberVec](const MuonGMR4::MuonReadoutElement* re){
303 return std::ranges::find(chamberVec, re->chamber()) == chamberVec.end();
304 });
305 if (missChamb != allRE.end()) {
306 ATH_MSG_FATAL("The chamber "<<(*(*missChamb)->chamber())<<" is not in the chamber set");
307 return StatusCode::FAILURE;
308 }
309
310 std::set<const Chamber*> overlapChambers{};
311 std::stringstream overlapstream{};
312 for (std::size_t chIdx = 0; chIdx< chamberVec.size(); ++chIdx) {
313 const Chamber& chamber{*chamberVec[chIdx]};
314 if (m_dumpObjs) {
315 saveEnvelope(gctx, std::format("Chamber_{:}{:}{:}{:}{:}",
316 ActsTrk::to_string(chamber.detectorType()),
317 chName(chamber.chamberIndex()),
318 Acts::abs(chamber.stationEta()),
319 chamber.stationEta() > 0 ? 'A' : 'C',
320 chamber.stationPhi()),
321 *chamber.boundingVolume(gctx), chamber.readoutEles());
322 }
323 ATH_CHECK(allReadoutInEnvelope(gctx, chamber));
324 const std::array<Amg::Vector3D, 8> chambCorners = cornerPoints(*chamber.boundingVolume(gctx));
326 std::vector<const Chamber*> overlaps{};
327 for (std::size_t chIdx1 = 0; chIdx1<chamberVec.size(); ++chIdx1) {
328 if (chIdx == chIdx1) {
329 continue;
330 }
331 const Chamber* overlapTest{chamberVec[chIdx1]};
332 if (hasOverlap(chambCorners, *(overlapTest->boundingVolume(gctx)))) {
333 overlaps.push_back(overlapTest);
334 }
335 }
336 if (overlaps.empty()) {
337 continue;
338 }
339 overlapstream<<"The chamber "<<chamber<<" overlaps with "<<std::endl;
340 for (const Chamber* itOverlaps : overlaps) {
341 overlapstream<<" *** "<<(*itOverlaps)<<std::endl;
342 }
343 overlapstream<<std::endl<<std::endl;
344 overlapChambers.insert(overlaps.begin(), overlaps.end());
345 overlapChambers.insert(chamberVec[chIdx]);
346 }
347 if (!overlapChambers.empty()) {
348 Acts::ObjVisualization3D visualHelper{};
349 for (const Chamber* hasOverlap: overlapChambers) {
350 Acts::GeometryView3D::drawVolume(visualHelper, *hasOverlap->boundingVolume(gctx), gctx.context());
351 visualHelper.write(m_overlapChambObj.value());
352 }
353 if (m_ignoreOverlapCh) {
354 ATH_MSG_WARNING(overlapstream.str());
355 } else {
356 ATH_MSG_FATAL(overlapstream.str());
357 }
358 }
359 return overlapChambers.empty() || m_ignoreOverlapCh ? StatusCode::SUCCESS : StatusCode::FAILURE;
360 }
361
363
364 std::vector<const MuonReadoutElement*> allREs = m_detMgr->getAllReadoutElements();
365 for (const MuonReadoutElement* re : allREs) {
366 if (!re->msSector()) {
367 ATH_MSG_FATAL("The readout element "<<m_idHelperSvc->toStringDetEl(re->identify())<<" does not have any sector associated ");
368 return StatusCode::FAILURE;
369 }
370 const SpectrometerSector* sectorFromDet = m_detMgr->getSectorEnvelope(re->chamberIndex(),
371 m_idHelperSvc->sector(re->identify()),
372 re->stationEta());
373 if (sectorFromDet != re->msSector()) {
374 ATH_MSG_FATAL("The sector attached to "<<m_idHelperSvc->toStringDetEl(re->identify())
375 <<", chIdx: "<<chName(re->chamberIndex())<<", sector: "<<m_idHelperSvc->sector(re->identify())
376 <<" is not the one attached to the readout geometry \n"<<(*re->msSector())<<"\n"<<(*sectorFromDet));
377 return StatusCode::FAILURE;
378 }
379 }
380 using SectorSet = MuonDetectorManager::MuonSectorSet;
381 const SectorSet sectors = m_detMgr->getAllSectors();
382 ATH_MSG_INFO("Fetched "<<sectors.size()<<" sectors. ");
383 for (const SpectrometerSector* sector : sectors) {
384 if (m_dumpObjs) {
385 saveEnvelope(gctx, std::format("Sector_{:}{:}{:}",
386 chName(sector->chamberIndex()),
387 sector->side() >0? 'A' :'C',
388 sector->stationPhi() ),
389 *sector->boundingVolume(gctx), sector->readoutEles(),
390 chamberVolumes(gctx, *sector));
391 }
392 ATH_CHECK(allReadoutInEnvelope(gctx, *sector));
393 const std::shared_ptr<Acts::Volume> secVolume = sector->boundingVolume(gctx);
394 for (const SpectrometerSector::ChamberPtr& chamber : sector->chambers()){
395 const std::array<Amg::Vector3D, 8> edges = cornerPoints(*chamber->boundingVolume(gctx));
396 unsigned int edgeCount{0};
397 for (const Amg::Vector3D& edge : edges) {
398 ATH_CHECK(pointInside(*sector,*secVolume, edge, std::format("Edge {:}", ++edgeCount),
399 chamber->readoutEles().front()->identify()));
400 }
401 }
402 }
403 return StatusCode::SUCCESS;
404 }
406 const std::string& envName,
407 const Acts::Volume& envelopeVol,
408 const std::vector<const MuonGMR4::MuonReadoutElement*>& assocRE,
409 const std::vector<std::shared_ptr<Acts::Volume>>& subVols) const {
410 Acts::ObjVisualization3D visualHelper{};
411 std::ranges::for_each(assocRE, [&visualHelper, &gctx](const MuonReadoutElement* re){
412 std::ranges::for_each(re->getSurfaces(),[&visualHelper, &gctx](const std::shared_ptr<Acts::Surface>& surface){
413 Acts::GeometryView3D::drawSurface(visualHelper, *surface, gctx.context());
414 });
415 });
416 std::ranges::for_each(subVols, [&visualHelper, &gctx](const std::shared_ptr<Acts::Volume>& subVol ){
417 Acts::GeometryView3D::drawVolume(visualHelper,*subVol, gctx.context(), Amg::Transform3D::Identity(),
418 Acts::s_viewPassive);
419 });
420 Acts::GeometryView3D::drawVolume(visualHelper, envelopeVol, gctx.context());
421 ATH_MSG_DEBUG("Save new envelope 'MsTrackTest_"<<envName<<".obj'");
422 visualHelper.write(std::format("MsTrackTest_{:}.obj", envName));
423 }
424
425 StatusCode MuonChamberToolTest::execute(const EventContext& ctx) const {
426 const ActsTrk::GeometryContext* gctx{nullptr};
427 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
428 std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry = m_trackingGeometrySvc->trackingGeometry();
430 ATH_CHECK(checkChambers(*gctx));
432
433 return StatusCode::SUCCESS;
434 }
435 template <class EnvelopeType>
437 const MdtReadoutElement& mdtMl,
438 const EnvelopeType& chamber,
439 const Acts::Volume& detVol) const {
440 ATH_MSG_VERBOSE("Test whether "<<m_idHelperSvc->toStringDetEl(mdtMl.identify())<<std::endl<<mdtMl.getParameters());
441
442 for (unsigned int layer = 1; layer <= mdtMl.numLayers(); ++layer) {
443 for (unsigned int tube = 1; tube <= mdtMl.numTubesInLay(); ++tube) {
444 const IdentifierHash idHash = mdtMl.measurementHash(layer, tube);
445 if (!mdtMl.isValid(idHash)){
446 continue;
447 }
448 const Amg::Transform3D& locToGlob{mdtMl.localToGlobalTrans(gctx, idHash)};
449 const Identifier measId{mdtMl.measurementId(idHash)};
450
451 ATH_CHECK(pointInside(chamber, detVol, mdtMl.globalTubePos(gctx, idHash), "tube center", measId));
452
453 ATH_CHECK(pointInside(chamber, detVol, mdtMl.readOutPos(gctx, idHash), "tube readout", measId));
454 ATH_CHECK(pointInside(chamber, detVol, mdtMl.highVoltPos(gctx, idHash), "tube HV", measId));
455
456 ATH_CHECK(pointInside(chamber, detVol, locToGlob*(-mdtMl.innerTubeRadius() * Amg::Vector3D::UnitX()),
457 "bottom of the tube box", measId));
458 ATH_CHECK(pointInside(chamber, detVol, locToGlob*(mdtMl.innerTubeRadius() * Amg::Vector3D::UnitX()),
459 "sealing of the tube box", measId));
460
461 ATH_CHECK(pointInside(chamber, detVol, locToGlob*(-mdtMl.innerTubeRadius() * Amg::Vector3D::UnitY()),
462 "wall to the previous tube", measId));
463 ATH_CHECK(pointInside(chamber, detVol, locToGlob*(-mdtMl.innerTubeRadius() * Amg::Vector3D::UnitY()),
464 "wall to the next tube", measId));
465 }
466 }
467 return StatusCode::SUCCESS;
468 }
469 template<class EnvelopeType>
471 const RpcReadoutElement& rpc,
472 const EnvelopeType& chamber,
473 const Acts::Volume& detVol) const {
474
475 ATH_MSG_VERBOSE("Test whether "<<m_idHelperSvc->toStringDetEl(rpc.identify())<<std::endl<<rpc.getParameters());
476
477 const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
478 for (unsigned int gasGap = 1 ; gasGap <= rpc.nGasGaps(); ++gasGap) {
479 for (int doubletPhi = rpc.doubletPhi(); doubletPhi <= rpc.doubletPhiMax(); ++doubletPhi){
480 for (bool measPhi : {false, true}) {
481 const int nStrips = measPhi ? rpc.nPhiStrips() : rpc.nEtaStrips();
482 for (int strip = 1; strip <= nStrips; ++strip) {
483 const Identifier stripId = idHelper.channelID(rpc.identify(),rpc.doubletZ(),
484 doubletPhi, gasGap, measPhi, strip);
485 ATH_CHECK(pointInside(chamber, detVol, rpc.stripPosition(gctx, stripId), "center", stripId));
486 ATH_CHECK(pointInside(chamber, detVol, rpc.leftStripEdge(gctx, stripId), "right edge", stripId));
487 ATH_CHECK(pointInside(chamber, detVol, rpc.rightStripEdge(gctx, stripId), "left edge", stripId));
488 }
489 }
490 }
491 }
492 return StatusCode::SUCCESS;
493 }
494 template <class EnevelopeType>
496 const TgcReadoutElement& tgc,
497 const EnevelopeType& chamber,
498 const Acts::Volume& detVol) const {
499 for (unsigned int gasGap = 1; gasGap <= tgc.nGasGaps(); ++gasGap){
500 for (bool isStrip : {false}) {
501 const IdentifierHash layHash = tgc.constructHash(0, gasGap, isStrip);
502 const unsigned int nChannel = tgc.numChannels(layHash);
503 for (unsigned int channel = 1; channel <= nChannel ; ++channel) {
504 const IdentifierHash measHash = tgc.constructHash(channel, gasGap, isStrip);
505 ATH_CHECK(pointInside(chamber, detVol, tgc.channelPosition(gctx, measHash), "center", tgc.measurementId(measHash)));
506 }
507 }
508 }
509 return StatusCode::SUCCESS;
510 }
511 template <class EnevelopeType>
513 const MmReadoutElement& mm,
514 const EnevelopeType& chamber,
515 const Acts::Volume& detVol) const {
516
517 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
518 for(unsigned int gasGap = 1; gasGap <= mm.nGasGaps(); ++gasGap){
519 IdentifierHash gasGapHash = MmReadoutElement::createHash(gasGap,0);
520 unsigned int firstStrip = mm.firstStrip(gasGapHash);
521 for(unsigned int strip = firstStrip; strip <= mm.numStrips(gasGapHash); ++strip){
522 const Identifier stripId = idHelper.channelID(mm.identify(), mm.multilayer(), gasGap, strip);
523 ATH_CHECK(pointInside(chamber, detVol, mm.stripPosition(gctx, stripId), "center", stripId));
524 ATH_CHECK(pointInside(chamber, detVol, mm.leftStripEdge(gctx, mm.measurementHash(stripId)), "left edge", stripId));
525 ATH_CHECK(pointInside(chamber, detVol, mm.rightStripEdge(gctx, mm.measurementHash(stripId)), "right edge", stripId));
526 }
527 }
528
529 return StatusCode::SUCCESS;
530 }
531 template <class EnvelopeType>
533 const sTgcReadoutElement& stgc,
534 const EnvelopeType& chamber,
535 const Acts::Volume& detVol) const{
536
537 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
538 for(unsigned int gasGap = 1; gasGap <= stgc.numLayers(); ++gasGap){
539
540 for(unsigned int nch = 1; nch <= stgc.nChTypes(); ++nch){
541 IdentifierHash gasGapHash = sTgcReadoutElement::createHash(gasGap, nch, 0, 0);
542 const unsigned int nStrips = stgc.numChannels(gasGapHash);
544
545 for(unsigned int strip = 1; strip <= nStrips; ++strip){
546 const Identifier stripId = idHelper.channelID(stgc.identify(), stgc.multilayer(), gasGap, nch, strip);
547 ATH_CHECK(pointInside(chamber, detVol, stgc.globalChannelPosition(gctx, stripId), "channel position", stripId));
548
550 ATH_CHECK(pointInside(chamber, detVol, stgc.rightStripEdge(gctx, stgc.measurementHash(stripId)), "channel position", stripId));
551 ATH_CHECK(pointInside(chamber, detVol, stgc.leftStripEdge(gctx, stgc.measurementHash(stripId)), "channel position", stripId));
552 }
553 }
554 }
555 }
556 return StatusCode::SUCCESS;
557
558 }
559}
560
const boost::regex re(r_e)
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_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
void section(const std::string &sec)
Acts::GeometryContext context() const
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
std::shared_ptr< Acts::Volume > boundingVolume(const ActsTrk::GeometryContext &gctx) const
Returns the Acts::Volume representation of the chamber.
Definition Chamber.cxx:79
std::vector< const MuonReadoutElement * > ReadoutSet
Define the list of read out elements of the chamber.
Definition Chamber.h:26
Amg::Vector3D highVoltPos(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the global position of the High Voltage connectors.
static IdentifierHash measurementHash(unsigned int layerNumber, unsigned int tubeNumber)
Transform the layer and tube number to the measurementHash.
bool isValid(const IdentifierHash &measHash) const
Amg::Vector3D readOutPos(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the global position of the readout card.
Amg::Vector3D globalTubePos(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the global position of the tube center.
unsigned int numTubesInLay() const
Returns the number of tubes per layer.
double innerTubeRadius() const
Returns the inner tube radius.
Identifier measurementId(const IdentifierHash &measHash) const override final
Converts the measurement hash back to the full Identifier.
unsigned int numLayers() const
Returns the number of tube layer.
static IdentifierHash createHash(const int gasGap, const int strip)
const MuonDetectorManager * m_detMgr
std::array< Amg::Vector3D, 8 > cornerPoints(const Acts::Volume &volume) const
Returns the 8 edge points from a trapezoidal / cuboid volume.
Gaudi::Property< bool > m_ignoreOverlapCh
The overlap of chamber volumes does not lead to a failure.
StatusCode pointInside(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.
StatusCode checkEnvelopes(const ActsTrk::GeometryContext &gctx) const
Check envelopes.
void saveEnvelope(const ActsTrk::GeometryContext &gctx, const std::string &envName, const Acts::Volume &envelopeVol, const std::vector< const MuonGMR4::MuonReadoutElement * > &assocRE, const std::vector< std::shared_ptr< Acts::Volume > > &subVolumes={}) const
StatusCode execute(const EventContext &ctx) const override
bool hasOverlap(const std::array< Amg::Vector3D, 8 > &chamberEdges, const Acts::Volume &volume) const
StatusCode checkChambers(const ActsTrk::GeometryContext &gctx) const
Check whether the chamber envelopes are consistent.
Gaudi::Property< bool > m_dumpObjs
Dump the chambers & sectors as separate obj files.
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
StatusCode allReadoutInEnvelope(const ActsTrk::GeometryContext &ctx, const EnvelopeType &envelope) const
Checks whether the readout elements of an enevelope are completely embedded into the envelope.
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
The MuonReadoutElement is an abstract class representing the geometry representing the muon detector.
const Amg::Transform3D & localToGlobalTrans(const ActsTrk::GeometryContext &ctx) const
Returns the local to global transformation into the ATLAS coordinate system.
Identifier identify() const override final
Return the athena identifier.
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
Converts the measurement hash back to the full Identifier.
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)
Amg::Vector3D globalChannelPosition(const ActsTrk::GeometryContext &ctx, const Identifier &measId) const
Returns the global pad/strip/wireGroup position.
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
static IdentifierHash createHash(const unsigned int gasGap, const unsigned int channelType, const unsigned int channel, const unsigned int wireInGrp=0)
Create a measurement hash from the Identifier fields.
int multilayer() const
Returns the multilayer of the sTgcReadoutElement.
Amg::Vector3D rightStripEdge(const ActsTrk::GeometryContext &ctx, const IdentifierHash &measHash) const
unsigned int nChTypes() const
Number of Channel Types.
unsigned int numLayers() const
Returns the number of gas gap layers.
ReadoutChannelType
ReadoutChannelType to distinguish the available readout channels Pad - pad readout channel Strip - et...
unsigned int numChannels(const Identifier &measId) const
Returns the number of strips / wires / pads in a given gasGap.
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
std::string to_string(const DetectorType &type)
@ 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.
Amg::Transform3D getRotateZ3D(double angle)
get a rotation transformation around 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
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)
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.