ATLAS Offline Software
Loading...
Searching...
No Matches
VolumePlacement.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef SIMULATIONBASE
6#include "GeoModelHelpers/GeoDeDuplicator.h"
7
8#include <cassert>
9namespace ActsTrk{
10 //#################################################################################
11 // VolumePlacement::VolumeGeoPositioning
12 //#################################################################################
19 const std::size_t portalIdx):
20 ActsTrk::AlignableGeoPositioning(portalIdx, parent->detectorType()),
21 m_parent{parent} {}
22
24 switch (m_flags) {
26 return m_parent->localToGlobalTransform(store);
28 return m_parent->localToGlobalTransform(store) *
29 m_parent->portalPlacement(hash())->portalToVolumeCenter();
31 return m_parent->localToGlobalTransform(store).inverse();
32 }
33 }
34 return Amg::Transform3D::Identity();
35 }
36 //#################################################################################
37 // VolumePlacement
38 //#################################################################################
40 const AlignableNode_t parentNode,
41 std::optional<Amg::Transform3D> addShift):
42 m_parent{parentNode},
43 m_locToGlobCache{std::make_unique<VolumeGeoPositioning>(VolumeGeoPositioning::CacheFlags::volumeLocToGlob, detType, this)},
44 m_globToLocCache{std::make_unique<VolumeGeoPositioning>(VolumeGeoPositioning::CacheFlags::volumeGlobToLoc, detType, this)} {
45 if (!addShift) {
46 return;
47 }
48 m_refShift = GeoDeDuplicator{}.makeTransform(*addShift);
49 }
50 void VolumePlacement::addChild(std::unique_ptr<VolumePlacement>&& child){
51 assert(child.get() != this);
52 assert(child != nullptr);
53 m_children.push_back(std::move(child));
54 }
56 std::optional<Amg::Transform3D> addShift):
57 m_parent{&parentElement},
58 m_globToLocCache{std::make_unique<VolumeGeoPositioning>(VolumeGeoPositioning::CacheFlags::volumeGlobToLoc,
59 parentElement.detectorType(), this)} {
60 if (!addShift) {
61 return;
62 }
63 m_locToGlobCache = std::make_unique<VolumeGeoPositioning>(VolumeGeoPositioning::CacheFlags::volumeLocToGlob,
64 parentElement.detectorType(), this);
65 m_refShift = GeoDeDuplicator{}.makeTransform(*addShift);
66
67 }
68
70 std::optional<Amg::Transform3D> addShift):
71 m_parent{&parentPlacement}{
72 if (!addShift) {
73 return;
74 }
75 m_locToGlobCache = std::make_unique<VolumeGeoPositioning>(VolumeGeoPositioning::CacheFlags::volumeLocToGlob,
76 parentPlacement.detectorType(), this);
77 m_globToLocCache = std::make_unique<VolumeGeoPositioning>(VolumeGeoPositioning::CacheFlags::volumeGlobToLoc,
78 parentPlacement.detectorType(), this);
79 m_refShift = GeoDeDuplicator{}.makeTransform(*addShift);
80
81 }
82
83 void VolumePlacement::makePortalsAlignable(const Acts::GeometryContext& gctx,
84 const std::vector<std::shared_ptr<Acts::RegularSurface>>& portalsToAlign) {
85 Acts::VolumePlacementBase::makePortalsAlignable(gctx, portalsToAlign);
86 for (std::size_t p = 0ul; p < portalsToAlign.size(); ++p) {
87 m_portalCaches.emplace_back(std::make_unique<VolumeGeoPositioning>(this, p));
88 }
89 }
90
91 const Acts::Transform3& VolumePlacement::localToGlobalTransform(const Acts::GeometryContext& tgContext) const {
92 if (!m_locToGlobCache) {
93 if (std::holds_alternative<const IDetectorElement*>(m_parent)){
94 const auto* gctx = tgContext.get<const GeometryContext*>();
95 return std::get<const IDetectorElement*>(m_parent)->localToGlobalTransform(*gctx);
96 } else if (std::holds_alternative<const VolumePlacement*>(m_parent)) {
97 return std::get<const VolumePlacement*>(m_parent)->localToGlobalTransform(tgContext);
98 } else {
99 THROW_EXCEPTION("A VolumePlacement without cache && alignable trf should never happen");
100 }
101 }
102 return m_locToGlobCache->getTransform(tgContext);
103 }
107 const Acts::Transform3& VolumePlacement::globalToLocalTransform(const Acts::GeometryContext& tgContext) const{
108 // The only configuration without glob -> loc cache is a parent volume placement
109 if (!m_globToLocCache) {
110 return std::get<const VolumePlacement*>(m_parent)->globalToLocalTransform(tgContext);
111 }
112 return m_globToLocCache->getTransform(tgContext);
113 }
117
118 const Acts::Transform3& VolumePlacement::portalLocalToGlobal(const Acts::GeometryContext& tgContext,
119 const std::size_t portalIdx) const {
120 return portalIdx < m_portalCaches.size() ?
121 m_portalCaches.at(portalIdx)->getTransform(tgContext) : localToGlobalTransform(tgContext);
122 }
123 void VolumePlacement::connectCenterSurface(std::shared_ptr<Acts::RegularSurface> surface) {
124 if (m_surfacePlacement) {
125 THROW_EXCEPTION("Center surface already defined");
126 }
127 m_surfacePlacement = std::make_shared<Acts::detail::PortalPlacement>(std::numeric_limits<std::size_t>::max(),
128 Amg::Transform3D::Identity(), this,
129 surface);
130 }
132 if (m_locToGlobCache){
133 return m_locToGlobCache->detectorType();
134 }
135 return std::visit([](const auto& parent) {
136 using visit_t = std::decay_t<decltype(parent)>;
137 if constexpr(!std::is_same_v<visit_t, AlignableNode_t>) {
138 return parent->detectorType();
139 }
141 }, m_parent);
142 }
143
145 return std::visit([&](const auto& parent) -> Amg::Transform3D {
146 using visit_t = std::decay_t<decltype(parent)>;
147 if constexpr(std::is_same_v<visit_t, AlignableNode_t>) {
148 return parent->getTransform(store ? store->geoModelAlignment.get() : nullptr);
149 } else {
150 return parent->localToGlobalTransform(store);
151 }
152 return Amg::Transform3D::Identity();
153 }, m_parent) * (m_refShift ? m_refShift->getDefTransform()
154 : Amg::Transform3D::Identity());
155 }
156
158 unsigned n{0};
159 for (const VolumeGeoPositioning* volCache : {m_locToGlobCache.get(), m_globToLocCache.get()}) {
160 if (volCache) {
161 n+=volCache->storeTransform(store);
162 }
163 }
164 for (const std::unique_ptr<VolumeGeoPositioning>& cache: m_portalCaches) {
165 n+=cache->storeTransform(store);
166 }
167 for (const std::shared_ptr<VolumePlacement>& child : m_children) {
168 n+=child->storeAlignedTransforms(store);
169 }
170 return n;
171 }
172}
173#endif
IdentifierHash hash() const
Returns the sensor hash of this transformation cache.
DetectorType detectorType() const
returns the detector type of the cache
AlignableGeoPositioning(const IdentifierHash &cacheHash, const DetectorType type)
Standard constrcutor.
Acts::GeometryContext context() const
ATLAS interface of a detector element.
virtual DetectorType detectorType() const =0
Returns the detector element type.
Auxiliary class to store the aligned transforms of the volume and of the associated portals.
const VolumePlacement * m_parent
Back reference to the parent VolumePlacement.
CacheFlags m_flags
Flags to indicate which transform type is handled.
CacheFlags
Flag to indicate which kind of transform is handled by the AlignedCache.
VolumeGeoPositioning(const CacheFlags flags, const DetectorType type, const VolumePlacement *parent)
Constructor for the cache storing the of the volume itself.
virtual Amg::Transform3D fetchTransform(const DetectorAlignStore *store) const override
Fetch the transform to store it in the detector alignment cache.
const Acts::Transform3 & globalToLocalTransform(const Acts::GeometryContext &gctx) const override final
std::unique_ptr< VolumeGeoPositioning > m_locToGlobCache
Cache to handle the local -> global transform of the volume.
GeoIntrusivePtr< GeoAlignableTransform > AlignableNode_t
Abrivation of an alignable GeoTransform.
Parent_t m_parent
Parent element which is following the alignment.
unsigned storeAlignedTransforms(DetectorAlignStore &store) const override final
const Acts::Transform3 & localToGlobalTransform(const Acts::GeometryContext &gctx) const override final
VolumePlacement(const DetectorType detType, const AlignableNode_t parentNode, std::optional< Amg::Transform3D > addShift=std::nullopt)
Constructor taking an Alignable transform from the geometry tree.
std::vector< std::shared_ptr< VolumePlacement > > m_children
Children spawning from this VolumePlacement.
GeoIntrusivePtr< GeoTransform > m_refShift
Additional shift on top of the parent position.
void addChild(std::unique_ptr< VolumePlacement > &&child)
Add a child volume placement to this placement.
std::unique_ptr< VolumeGeoPositioning > m_globToLocCache
Cache to handle the global -> local transform of the volume.
std::vector< std::unique_ptr< VolumeGeoPositioning > > m_portalCaches
Cache to handle the local -> global transforms of the associated portals.
std::shared_ptr< Acts::detail::PortalPlacement > m_surfacePlacement
Pipe the local -> global transform to a surface.
DetectorType detectorType() const override final
void makePortalsAlignable(const Acts::GeometryContext &gctx, const std::vector< std::shared_ptr< Acts::RegularSurface > > &portalsToAlign) override final
const Acts::Transform3 & portalLocalToGlobal(const Acts::GeometryContext &gctx, const std::size_t portalIdx) const override final
void connectCenterSurface(std::shared_ptr< Acts::RegularSurface > surface)
Connect an external surface and place it into the volume center.
This is a "hash" representation of an Identifier.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
DetectorType
Simple enum to Identify the Type of the ACTS sub detector.
@ UnDefined
Small Thing Gap chambers (NSW).
Eigen::Affine3d Transform3D
STL namespace.
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10