7#include "Acts/Geometry/BlueprintNode.hpp"
8#include "Acts/Geometry/StaticBlueprintNode.hpp"
9#include "Acts/Geometry/CylinderVolumeBounds.hpp"
10#include <Acts/Geometry/ContainerBlueprintNode.hpp>
11#include "Acts/Geometry/MultiWireVolumeBuilder.hpp"
12#include "Acts/Surfaces/TrapezoidBounds.hpp"
13#include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
14#include <Acts/Geometry/MaterialDesignatorBlueprintNode.hpp>
15#include <Acts/Geometry/GeometryIdentifierBlueprintNode.hpp>
16#include <Acts/Geometry/VolumeAttachmentStrategy.hpp>
17#include "Acts/Geometry/VolumeResizeStrategy.hpp"
18#include <Acts/Geometry/TrackingVolume.hpp>
19#include <Acts/Geometry/TrapezoidVolumeBounds.hpp>
20#include <Acts/Geometry/CuboidVolumeBounds.hpp>
21#include <Acts/Geometry/DiamondVolumeBounds.hpp>
22#include <Acts/Surfaces/PlaneSurface.hpp>
23#include <Acts/Surfaces/CylinderSurface.hpp>
24#include <Acts/Surfaces/DiscSurface.hpp>
25#include "Acts/Surfaces/RadialBounds.hpp"
26#include <ActsPlugins/GeoModel/GeoModelMaterialConverter.hpp>
27#include <Acts/Visualization/ObjVisualization3D.hpp>
28#include <Acts/Visualization/GeometryView3D.hpp>
35#include "GeoModelValidation/GeoMaterialHelper.h"
37using namespace Acts::UnitLiterals;
41 constexpr std::size_t s_muonBarrelId = 30;
42 constexpr std::size_t s_muonEndcapAId = 31;
43 constexpr std::size_t s_muonEndcapCId = 32;
44 constexpr std::size_t s_muonEndcapMiddleAId = 33;
45 constexpr std::size_t s_muonEndcapMiddleCId = 34;
60 return StatusCode::SUCCESS;
67EnvelopeSet_t barrelStations, endcapOuterAStations, endcapOuterCStations,
68 endcapMiddleAStations, endcapMiddleCStations;
71 elements =
m_detMgr->getAllSectors();
73 elements =
m_detMgr->getAllChambers();
76std::visit([&](
auto& elems) {
77 using SetType = std::decay_t<
decltype(elems)>;
80 SetType
barrel, endcapA, endcapC, endcapMiddleA, endcapMiddleC;
82 for (
const auto& element : elems) {
84 {StIdx::BI, StIdx::BM, StIdx::BO, StIdx::BE, StIdx::EE, StIdx::EI},
88 endcapA.push_back(element);
90 endcapC.push_back(element);
92 endcapMiddleA.push_back(element);
94 endcapMiddleC.push_back(element);
97 <<
" not assigned to any station!");
102 barrelStations = std::move(
barrel);
103 endcapOuterAStations = std::move(endcapA);
104 endcapOuterCStations = std::move(endcapC);
105 endcapMiddleAStations = std::move(endcapMiddleA);
106 endcapMiddleCStations = std::move(endcapMiddleC);
110auto muonNode = std::make_shared<Acts::Experimental::CylinderContainerBlueprintNode>(
"MuonNode", Acts::AxisDirection::AxisZ);
112Acts::VolumeBoundFactory boundsFactory{};
113auto barrelNode =
buildMuonNode(gctx, barrelStations,
"BI_BM_BO_EE_EI", Acts::GeometryIdentifier().withVolume(s_muonBarrelId), boundsFactory, {ChIdx::BIS, ChIdx::BML, ChIdx::BOL,
114 ChIdx::EIS, ChIdx::EIL});
115auto endcapANode =
buildMuonNode(gctx, endcapOuterAStations,
"EO_A", Acts::GeometryIdentifier().withVolume(s_muonEndcapAId), boundsFactory);
116auto endcapCNode =
buildMuonNode(gctx, endcapOuterCStations,
"EO_C", Acts::GeometryIdentifier().withVolume(s_muonEndcapCId), boundsFactory);
117auto endcapMiddleANode =
buildMuonNode(gctx, endcapMiddleAStations,
"EM_A", Acts::GeometryIdentifier().withVolume(s_muonEndcapMiddleAId), boundsFactory, {ChIdx::EML, ChIdx::EMS});
118auto endcapMiddleCNode =
buildMuonNode(gctx, endcapMiddleCStations,
"EM_C", Acts::GeometryIdentifier().withVolume(s_muonEndcapMiddleCId), boundsFactory, {ChIdx::EML, ChIdx::EMS});
122 barrelNode->addChild(std::move(childNode));
124muonNode->addChild(std::move(barrelNode));
125muonNode->addChild(std::move(endcapANode));
126muonNode->addChild(std::move(endcapCNode));
127muonNode->addChild(std::move(endcapMiddleANode));
128muonNode->addChild(std::move(endcapMiddleCNode));
134std::shared_ptr<Acts::Experimental::StaticBlueprintNode>
137 const std::string& name,
138 const Acts::GeometryIdentifier&
id,
139 Acts::VolumeBoundFactory& boundsFactory,
140 const std::vector<ChIdx>& passiveStationIds)
const {
143 std::vector<std::string> stationNames;
145 std::vector<std::shared_ptr<Acts::Experimental::StaticBlueprintNode>> nodes;
147 double innerRadius{0.0};
148 double outerRadius{std::numeric_limits<double>::lowest()};
149 double maxZ{std::numeric_limits<double>::lowest()};
150 double minZ{std::numeric_limits<double>::max()};
152 std::vector<std::shared_ptr<Acts::Surface>> passiveSurfaces;
154 std::visit([&](
const auto& elems){
156 using SetType = std::decay_t<
decltype(elems)>;
157 std::unordered_map<unsigned int, SetType> elementsPerStation;
159 for(
const auto& element : elems){
160 auto vol = std::make_unique<Acts::TrackingVolume>(*element->boundingVolume(*context),
161 element->identString());
163 Acts::GeometryIdentifier chId =
id.withLayer(chamberId++);
164 vol->assignGeometryId(chId);
165 std::pair<std::vector<staticNodePtr>,std::vector<surfacePtr>> innerStructure =
getSensitiveElements(*context, *element, chId, boundsFactory);
166 for(
auto& surface: innerStructure.second){
167 vol->addSurface(surface);
170 for(
const auto& surface: vol->volumeBounds().orientedSurfaces(vol->localToGlobalTransform(gctx))) {
171 const auto& surfaceRepr = (*surface.surface);
172 const Acts::Polyhedron& polyhedron = surfaceRepr.polyhedronRepresentation(gctx);
175 maxZ = std::max(maxZ, center.z());
176 minZ = std::min(minZ, center.z());
180 outerRadius = std::max(outerRadius, vertex.perp());
183 std::shared_ptr<Acts::Experimental::StaticBlueprintNode>
node;
184 const bool isSingleMdt =
185 (element->readoutEles().size() == 1 &&
190 node = std::move(innerStructure.first.front());
192 node = std::make_shared<Acts::Experimental::StaticBlueprintNode>(std::move(vol));
193 for (
auto& childNode : innerStructure.first) {
194 node->addChild(std::move(childNode));
196 innerStructure.first.clear();
201 nodes.emplace_back(std::move(
node));
204 if(!Acts::rangeContainsValue(passiveStationIds, element->chamberIndex())){
209 elementsPerStation[Muon::MuonStationIndex::regionChamberHash(detIdx, element->chamberIndex())].push_back(element);
216 double halfLengthZ = 0.5 * std::abs(maxZ - minZ);
217 ATH_MSG_DEBUG(
"Inner radius: " << innerRadius<<
", outer radius: " << outerRadius
218 <<
", max Z: " << maxZ<<
", min Z: " << minZ<<
", half length Z: " << halfLengthZ);
222 auto bounds = boundsFactory.makeBounds<Acts::CylinderVolumeBounds>(innerRadius, outerRadius, halfLengthZ);
223 auto volume = std::make_unique<Acts::TrackingVolume>(trf, bounds, name);
224 volume->assignGeometryId(
id);
227 std::ranges::for_each(passiveSurfaces, [&volume](
auto& surf){
228 volume->addSurface(surf);
231 auto muonNode = std::make_shared<Acts::Experimental::StaticBlueprintNode>(std::move(volume));
233 std::ranges::for_each(nodes, [&muonNode](
auto&
node) {
234 muonNode->addChild(std::move(
node));
243 const Acts::GeometryIdentifier& chId,
244 Acts::VolumeBoundFactory& boundsFactory)
const
245 requires(std::is_same_v<T, MuonGMR4::Chamber> || std::is_same_v<T, MuonGMR4::SpectrometerSector>){
247 std::vector<staticNodePtr> readoutVolumes;
248 std::vector<surfacePtr> readoutSurfaces;
249 Acts::GeometryIdentifier::Value mdtId{1};
253 std::vector<surfacePtr> detSurfaces = readoutEle->getSurfaces();
254 switch(readoutEle->detectorType()){
260 const Amg::Vector3D toChamber = element.globalToLocalTransform(gctx)*mdtReadoutEle->center(gctx);
261 Acts::Transform3 mdtTransform = element.localToGlobalTransform(gctx) *
Amg::getTranslate3D(toChamber);
264 Acts::Experimental::MultiWireVolumeBuilder::Config mwCfg;
265 mwCfg.name =
m_detMgr->idHelperSvc()->toStringDetEl(mdtReadoutEle->identify());
266 mwCfg.mlSurfaces = detSurfaces;
267 mwCfg.transform = mdtTransform;
271 std::shared_ptr<Acts::VolumeBounds> mdtBounds{
nullptr};
272 if(isBIS78(mdtReadoutEle) && mdtReadoutEle->multilayer() == 2){
275 std::vector<double> tubeLengths;
276 tubeLengths.reserve(mdtReadoutEle->numTubesInLay());
277 for(std::size_t tube = 1; tube < mdtReadoutEle->numTubesInLay(); ++tube){
279 double tubeLength = mdtReadoutEle->tubeLength(tubeHash);
282 auto [minX,maxX] = std::ranges::minmax_element(tubeLengths);
283 int nSmallTubes = std::count_if(tubeLengths.begin(), tubeLengths.end(), [minX](
double length){
284 return std::abs(*minX-length) < Acts::s_epsilon;
288 double y2 = (nSmallTubes+1)*parameters.tubePitch ;
289 double y1 = 2*parameters.halfY - y2;
291 mdtBounds = boundsFactory.makeBounds<Acts::DiamondVolumeBounds>(0.5*(*maxX), 0.5*(*maxX), 0.5*(*minX),
292 y1, y2, parameters.halfHeight);
295 if(std::abs(parameters.shortHalfX - parameters.longHalfX) < Acts::s_epsilon){
296 mdtBounds = boundsFactory.makeBounds<Acts::CuboidVolumeBounds>(parameters.shortHalfX, parameters.halfY, parameters.halfHeight);
298 mdtBounds = boundsFactory.makeBounds<Acts::TrapezoidVolumeBounds>(parameters.shortHalfX,
299 parameters.longHalfX, parameters.halfY, parameters.halfHeight);
302 mwCfg.bounds = mdtBounds;
303 mwCfg.transform = mdtTransform;
304 using BoundsV = Acts::TrapezoidVolumeBounds::BoundValues;
305 mwCfg.binning = {{{Acts::AxisDirection::AxisY, Acts::AxisBoundaryType::Bound,
308 static_cast<std::size_t
>(std::lround(2 * parameters.halfY / parameters.tubePitch))}, 2u},
309 {{Acts::AxisDirection::AxisZ, Acts::AxisBoundaryType::Bound,
310 -parameters.halfHeight,
311 parameters.halfHeight,
312 static_cast<std::size_t
>(std::lround(2 * parameters.halfHeight / parameters.tubePitch))}, 1u}};
313 Acts::Experimental::MultiWireVolumeBuilder mdtBuilder{mwCfg};
314 std::unique_ptr<Acts::TrackingVolume> mdtVolume = mdtBuilder.buildVolume();
316 mdtVolume->assignGeometryId(chId.withExtra(mdtId++));
318 std::shared_ptr<Acts::Experimental::StaticBlueprintNode> mdtNode = std::make_shared<Acts::Experimental::StaticBlueprintNode>(std::move(mdtVolume));
319 mdtNode->setNavigationPolicyFactory(mdtBuilder.createNavigationPolicyFactory());
320 readoutVolumes.push_back(std::move(mdtNode));
329 readoutSurfaces.insert(readoutSurfaces.end(), std::make_move_iterator(detSurfaces.begin()),
330 std::make_move_iterator(detSurfaces.end()));
341 return std::make_pair(std::move(readoutVolumes), std::move(readoutSurfaces));
344template<
typename ElementSet_t>
345std::vector<std::shared_ptr<Acts::Surface>>
347 const Acts::GeometryContext& gctx,
348 const std::unordered_map<unsigned int, ElementSet_t>& elementsPerStation)
const {
352 constexpr double margin{4._mm};
354 std::vector<std::shared_ptr<Acts::Surface>> surfaces;
355 surfaces.reserve(elementsPerStation.size());
356 LayIdx layIdx = LayIdx::LayerIndexMax;
357 DetIdx detIdx = DetIdx::DetectorRegionIndexMax;
365 switch (readoutEle->detectorType()) {
367 const auto* techEle =
369 if (techEle->multilayer() == 2) {
375 const auto* techEle =
377 if (techEle->doubletZ() == 2) {
385 return isBIS78(readoutEle) && reject;
388 for(
const auto& [hash, elements] : elementsPerStation){
395 double maxZ{std::numeric_limits<double>::lowest()};
396 double minZ{std::numeric_limits<double>::max()};
397 double rMin{std::numeric_limits<double>::max()};
398 double rMax{std::numeric_limits<double>::lowest()};
400 for(
const auto& el : elements){
402 if(rejectBIS78(el->readoutEles().front())){
407 const auto& bounds = el->bounds();
408 for(
const auto& surface : bounds->orientedSurfaces(locToGlobal)){
409 const auto& surfaceRepr = (*surface.surface);
411 rMin = std::min(rMin, center.perp());
412 minZ = std::min(minZ, center.z());
413 maxZ = std::max(maxZ, center.z());
414 rMax = std::max(rMax, center.perp());
418 double halfZ = 0.5*std::abs(maxZ-minZ);
422 const auto& testCh = elements.front();
423 int8_t side = testCh->side();
424 switch (testCh->chamberIndex()) {
428 side > 0 ? zShift = minZ - margin : zShift = maxZ + margin;
430 auto surface = Acts::Surface::makeShared<Acts::DiscSurface>(trf, std::make_shared<Acts::RadialBounds>(0., rMax));
431 surfaces.push_back(surface);
439 if(testCh->chamberIndex() == ChIdx::EIL){
442 side > 0 ? zShift = maxZ + margin : zShift = minZ - margin;
444 auto surface = Acts::Surface::makeShared<Acts::DiscSurface>(trf, std::make_shared<Acts::RadialBounds>(0., rMax));
445 surfaces.push_back(surface);
451 auto surface = Acts::Surface::makeShared<Acts::CylinderSurface>(
452 trf, std::make_shared<Acts::CylinderBounds>(rMin - margin, halfZ));
453 surfaces.push_back(surface);
456 throw std::runtime_error(
"No implementation of passive material surface for this station!!!! - sorry :) ");
458 ATH_MSG_VERBOSE(
"Putting passive material surface for station " << layerName(layIdx) <<
"/ "<< regionName(detIdx) <<
": minZ = " << minZ <<
", maxZ = " << maxZ<<
"and radius "<< rMax);
461 if(msgLvl(MSG::VERBOSE)){
462 std::stringstream stream{};
463 for(
const auto& surf : surfaces){
464 stream<<
" at position : "<<
Amg::toString(surf->center(gctx))<<
"with bounds "<< surf->bounds()<<std::endl;
466 ATH_MSG_VERBOSE(
"Constructed "<< surfaces.size()<<
" surfaces for passive material description : "<<std::endl<<stream.str());
473 const std::vector<StIdx>& stationIndex,
475 requires(std::is_same_v<T, MuonGMR4::Chamber> ||
476 std::is_same_v<T, MuonGMR4::SpectrometerSector>) {
480 return etaSignCorrect &&
481 Acts::rangeContainsValue(stationIndex, toStationIndex(element.chamberIndex()));
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
BluePrintSurfPairs_t getSensitiveElements(const ActsTrk::GeometryContext &gctx, const T &element, const Acts::GeometryIdentifier &chId, Acts::VolumeBoundFactory &boundsFactory) const
Get the chamber's sensitive elements.
std::shared_ptr< Acts::Experimental::BlueprintNode > buildBlueprintNode(const Acts::GeometryContext &gctx, std::shared_ptr< Acts::Experimental::BlueprintNode > &&childNode) override
Build the Muon Blueprint Node.
staticNodePtr buildMuonNode(const Acts::GeometryContext &gctx, const EnvelopeSet_t &elements, const std::string &name, const Acts::GeometryIdentifier &id, Acts::VolumeBoundFactory &boundsFactory, const std::vector< ChIdx > &passiveStationIds={}) const
Build subnodes for the muon system node.
bool isElementInTheStation(const T &element, const std::vector< StIdx > &stationNames, const EndcapSide side) const
Check if the chamber is in this node.
std::vector< surfacePtr > getPassiveMaterialSurfaces(const Acts::GeometryContext &gctx, const std::unordered_map< unsigned int, ElementSet_t > &elementsPerStation) const
Construct and return the surfaces for the passive material description (e.g cylinders for barrel/ dis...
Muon::MuonStationIndex::DetectorRegionIndex DetIdx
Abrivatin for the detector region index.
Gaudi::Property< bool > m_useSectors
Flag to control if we want to build the muon node from sectors or chambers.
std::variant< MuonChamberSet, MuonSectorSet > EnvelopeSet_t
Hide the flexibility to build the tracking geometry from sectors or chambers behind a variant.
const MuonGMR4::MuonDetectorManager * m_detMgr
the Detector manager
Muon::MuonStationIndex::LayerIndex LayIdx
Abrivation for the layer index.
std::pair< std::vector< staticNodePtr >, std::vector< surfacePtr > > BluePrintSurfPairs_t
Abrivate the vector pair of blue print nodes and associated active surfaces.
StatusCode initialize() override
This is a "hash" representation of an Identifier.
Readout element to describe the Monitored Drift Tube (Mdt) chambers Mdt chambers usually comrpise out...
static IdentifierHash measurementHash(unsigned layerNumber, unsigned tubeNumber)
Constructs a Measurement hash from layer && tube number.
MuonReadoutElement is an abstract class representing the geometry of a muon detector.
int stationEta() const
Returns the stationEta (positive A site, negative C site)
Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index of the Identifier (MMS & STS) have the same chamber Index (EIS)
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::string to_string(const DetectorType &type)
@ Mm
Maybe not needed in the migration.
@ Tgc
Resitive Plate Chambers.
@ Rpc
Monitored Drift Tubes.
Amg::Transform3D getTranslate3D(const double X, const double Y, const double Z)
: Returns a shift transformation along an arbitrary axis
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Amg::Transform3D getTranslateZ3D(const double Z)
: Returns a shift transformation along the z-axis
Amg::Transform3D getTranslateY3D(const double Y)
: Returns a shift transformation along the y-axis
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
std::pair< DetectorRegionIndex, ChIndex > decomposeRegionChamberHash(unsigned int hash)
decompose the hash into Region and Chamber
LayerIndex toLayerIndex(ChIndex index)
convert ChIndex into LayerIndex
DetectorRegionIndex toDetectorRegionIndex(ChIndex index, int8_t etaSign)
convert ChamberIndex + etaSign into DetectorRegionIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
Set of parameters to describe a MDT chamber.
#define THROW_EXCEPTION(MESSAGE)