ATLAS Offline Software
Loading...
Searching...
No Matches
TrackingGeometry.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// TrackingGeometry.cxx, (c) ATLAS Detector software
8
9// Trk
11
13#include "TrkGeometry/Layer.h"
19// GaudiKernel
20#include "GaudiKernel/MsgStream.h"
21
22
23
25 NavigationLevel navLev):
26 m_world(highestVolume),
27 m_navigationLevel(navLev) {
28 // for the time being only world
29 if (!m_world) return;
31}
32
35void Trk::TrackingGeometry::addToGarbage(std::vector<std::unique_ptr<DetachedTrackingVolume>>&& garbageVec) {
37 std::make_move_iterator(garbageVec.begin()),
38 std::make_move_iterator(garbageVec.end()));
39}
40void Trk::TrackingGeometry::addToGarbage(std::vector<std::unique_ptr<TrackingVolume>>&& garbageVec){
42 std::make_move_iterator(garbageVec.begin()),
43 std::make_move_iterator(garbageVec.end()));
44}
45
48{
49 const Trk::TrackingVolume* searchVolume = highestTrackingVolume();
50 const Trk::TrackingVolume* currentVolume = nullptr;
51 while (currentVolume != searchVolume && searchVolume) {
52 currentVolume = searchVolume;
53 searchVolume = searchVolume->associatedSubVolume(gp);
54 }
55 return (currentVolume);
56}
57
58std::vector<const Trk::DetachedTrackingVolume*>
60 const Amg::Vector3D& gp) const
61{
62 double tol = 0.001;
63 const Trk::TrackingVolume* currentVolume = lowestStaticTrackingVolume(gp);
64 if (currentVolume){
65 return currentVolume->assocDetachedSubVolumes(gp, tol);
66 }
67 return {};
68}
69
72{
73 const Trk::TrackingVolume* searchVolume = highestTrackingVolume();
74 const Trk::TrackingVolume* currentVolume = nullptr;
75 while (currentVolume != searchVolume && searchVolume) {
76 currentVolume = searchVolume;
77 if (searchVolume->confinedDetachedVolumes().empty())
78 searchVolume = searchVolume->associatedSubVolume(gp);
79 }
80 return (currentVolume);
81}
82
83void
86 int lvl)
87{
88 int sublvl = lvl + 1;
89 std::string indent = "";
90 for (int l = 0; l < lvl; ++l){
91 indent += " ";
92 }
93
94 tvol.setMotherVolume(mvol);
95 m_trackingVolumes[tvol.volumeName()] = (&tvol);
97 if (confinedVolumes) {
98 std::span<Trk::TrackingVolume* const> volumes = confinedVolumes->arrayObjects();
99 for (const auto& volumesIter : volumes){
100 if (volumesIter){
101 registerTrackingVolumes(*volumesIter, &tvol, sublvl);
102 }
103 }
104 }
105
107 if (!confinedDenseVolumes.empty()) {
108 for (const auto& volumesIter : confinedDenseVolumes){
109 if (volumesIter){
110 registerTrackingVolumes(*volumesIter, &tvol, sublvl);
111 }
112 }
113 }
116 if (!confinedDetachedVolumes.empty()) {
117 for (const auto& volumesIter : confinedDetachedVolumes){
118 if (volumesIter &&
119 tvol.inside(volumesIter->trackingVolume()->center(), 0.)){
120 registerTrackingVolumes( *(volumesIter->trackingVolume()), &tvol, sublvl);
121 }
122 }
123 }
125 // boundary layers
126 const auto& bounds = tvol.boundarySurfaces();
127 for (const auto & bound : bounds) {
129 if (bLayer) {
130 int& layerCount{m_boundaryLayers[bLayer]};
131 ++layerCount;
132 }
133 }
134}
135
137{
138 msg << MSG::VERBOSE
139 << "====== Calling TrackingGeometry::compactify() ===== " << std::endl;
140 Trk::TrackingVolume* tVolume = vol ? vol : highestTrackingVolume();
141 size_t cSurfaces = 0;
142 size_t tSurfaces = 0;
143 if (tVolume) {
144 tVolume->compactify(cSurfaces, tSurfaces);
145 }
146 msg << MSG::VERBOSE << " --> set TG ownership of " << cSurfaces << " out of "
147 << tSurfaces << std::endl;
148 for (const auto& bLayerIter : m_boundaryLayers) {
149 bLayerIter.first->surfaceRepresentation().setOwner(Trk::TGOwn);
150 }
151 msg << MSG::VERBOSE << " --> set TG ownership of " << m_boundaryLayers.size()
152 << " boundary layers." << std::endl;
153 msg << MSG::VERBOSE << endmsg;
154}
155
156void
162
165 Trk::TrackingVolume* checkoutVolume = m_world.release();
166 // clear the boundary layers they go with the highest volume
167 m_boundaryLayers.clear();
168 return checkoutVolume;
169}
170
171void
173{
174 msg << "TrackingGeometry Summary : " << std::endl;
175 const Trk::TrackingVolume* highestVolume = highestTrackingVolume();
176 int level = 0;
177 if (highestVolume)
178 printVolumeInformation(msg, *highestVolume, level);
179 msg << endmsg;
180}
181
182void
184 const Trk::TrackingVolume& tvol,
185 int lvl) const
186{
187 int sublevel = lvl + 1;
188
189 for (int indent = 0; indent < sublevel; ++indent)
190 msg << " ";
191 msg << "TrackingVolume ( at : " << (&tvol) << ") name: " << tvol.volumeName()
192 << std::endl;
193
194 const Trk::BinnedArray<Trk::Layer>* confinedLayers = tvol.confinedLayers();
195 if (confinedLayers) {
196 std::span<Trk::Layer const* const> layers =
197 confinedLayers->arrayObjects();
198 for (int indent = 0; indent < sublevel; ++indent)
199 msg << " ";
200 msg << "- found : " << layers.size() << " confined Layers" << std::endl;
201 }
202
203 const Trk::BinnedArray<Trk::TrackingVolume>* confinedVolumes =
204 tvol.confinedVolumes();
205 if (confinedVolumes) {
206 std::span<Trk::TrackingVolume const* const> volumes =
207 confinedVolumes->arrayObjects();
208
209 for (int indent = 0; indent < sublevel; ++indent)
210 msg << " ";
211 msg << "- found : " << volumes.size() << " confined TrackingVolumes"
212 << std::endl;
213
214 for (const auto& volumesIter : volumes)
215 if (volumesIter)
216 printVolumeInformation(msg, *volumesIter, sublevel);
217 }
218
221 if (!confinedDenseVolumes.empty()) {
222 for (int indent = 0; indent < sublevel; ++indent) {
223 msg << " ";
224 }
225 msg << "- found : " << confinedDenseVolumes.size()
226 << " confined unordered (dense) TrackingVolumes" << std::endl;
227
228 for (const auto& volumesIter : (confinedDenseVolumes))
229 if (volumesIter) {
230 printVolumeInformation(msg, *volumesIter, sublevel);
231 }
232 }
233}
234
236{
237 if (m_world) {
238 m_world->indexContainedStaticLayers(geosit, offset);
239 m_world->indexContainedMaterialLayers(geosit, offset);
240 }
241}
242
243bool
245 const Trk::TrackingVolume* vol,
246 double tol)
247{
248 bool isAtBoundary = false;
249 if (!vol)
250 return isAtBoundary;
251 const auto& bounds = vol->boundarySurfaces();
252 for (size_t ib = 0; ib < bounds.size(); ++ib) {
253 const Trk::Surface& surf = bounds[ib]->surfaceRepresentation();
254 if (surf.isOnSurface(gp, true, tol, tol))
255 isAtBoundary = true;
256 }
257 return isAtBoundary;
258}
259
261bool
263 const Amg::Vector3D& mom,
264 const TrackingVolume* vol,
265 const TrackingVolume*& nextVol,
267 double tol)
268{
269 bool isAtBoundary = false;
270 nextVol = nullptr;
271 if (!vol)
272 return isAtBoundary;
273 const auto& bounds = vol->boundarySurfaces();
274 for (size_t ib = 0; ib < bounds.size(); ++ib) {
275 const Trk::Surface& surf = bounds[ib]->surfaceRepresentation();
276 if (surf.isOnSurface(gp, true, tol, tol)) {
277 isAtBoundary = true;
278 const Trk::TrackingVolume* attachedVol =
279 bounds[ib]->attachedVolume(gp, mom, dir);
280 if (!nextVol && attachedVol)
281 nextVol = attachedVol;
282 }
283 }
284 return isAtBoundary;
285}
286
287void
288Trk::TrackingGeometry::dump(MsgStream& out, const std::string& head) const
289{
290 out << MSG::ALWAYS;
291 for (const auto& bound_layers : m_boundaryLayers) {
292 out << head << " [" << bound_layers.second << "] ";
293 dumpLayer(out, "", bound_layers.first);
294 }
295 int counter = 0;
296 for (const std::pair<const std::string, const TrackingVolume*>& volume : m_trackingVolumes) {
297 out << head << " [" << counter++ << "] " << volume.first << " volumeBound=";
298 volume.second->volumeBounds().dump(out);
299 out << std::endl;
301 volume.second->confinedArbitraryLayers();
302 if (!confArbLayers.empty()) {
303 int j = 0;
304 for (const Layer* confined_layer : confArbLayers) {
305 out << head << " [" << counter++ << "] " << volume.first
306 << " confinedArbitrary layer " << j++ << " ";
307 dumpLayer(out, "", confined_layer);
308 }
309 }
310 if (volume.second->confinedLayers()) {
311 int j = 0;
312 for (const Layer* confined_layer :
313 volume.second->confinedLayers()->arrayObjects()) {
314 out << head << " [" << counter++ << "] " << volume.first
315 << " confined layer" << j++ << " ";
316 dumpLayer(out, "", confined_layer);
317 }
318 }
319 }
320 out << endmsg;
321}
322void
324 const std::string& head,
325 const Layer* layer)
326{
327 if (!layer) {
328 return;
329 }
330 out << head << layer->layerIndex().value() << " [t=" << layer->layerType()
331 << "] d=" << layer->thickness();
332 out << layer->surfaceRepresentation();
333 out << std::endl;
334}
#define endmsg
Binned Array for avoiding map searches/.
Definition BinnedArray.h:36
virtual std::span< T *const > arrayObjects()=0
Return all objects of the Array non-const we can still modify the T.
Base Class for a Detector Layer in the Tracking realm.
Definition Layer.h:72
A material layer is a simple helper class to attach material information to a boundary surface.
virtual const Surface & surfaceRepresentation() const override=0
Transforms the layer into a Surface representation for extrapolation.
Abstract Base Class for tracking surfaces.
virtual bool isOnSurface(const Amg::Vector3D &glopo, const BoundaryCheck &bchk=true, double tol1=0., double tol2=0.) const
This method returns true if the GlobalPosition is on the Surface for both, within or without check of...
Definition Surface.cxx:123
const Trk::MaterialLayer * materialLayer() const
return the material Layer
std::vector< const Trk::DetachedTrackingVolume * > lowestDetachedTrackingVolumes(const Amg::Vector3D &gp) const
return the vector of lowest detached tracking Volume(->overlaps)
virtual ~TrackingGeometry()
Destructor.
void addToGarbage(std::vector< std::unique_ptr< Trk::DetachedTrackingVolume > > &&garbageVec)
void dump(MsgStream &out, const std::string &head) const
static bool atVolumeBoundary(const Amg::Vector3D &gp, const TrackingVolume *vol, double tol)
check position at volume boundary
std::map< Layer *, int > m_boundaryLayers
The unique boundary Layers.
static void dumpLayer(MsgStream &out, const std::string &head, const Layer *layer)
void registerTrackingVolumes(TrackingVolume &tvol, TrackingVolume *mvol=nullptr, int lvl=0)
private method to register recursively the tracking volumes
const TrackingVolume * highestTrackingVolume() const
return the world
std::vector< std::unique_ptr< DetachedTrackingVolume > > m_detachedVolGarbage
In some cases the Tracking Geometry needs to keep certain objectss alive delete them at the end of it...
std::vector< std::unique_ptr< TrackingVolume > > m_trkVolumeGarbage
void indexStaticLayers(GeometrySignature geosit, int offset=0)
indexLayers : method to re-set the index of the layers, depending on geometrySignature
void compactify(MsgStream &msgstream, TrackingVolume *vol=nullptr)
Geometry Builder busineess: set all contained surfaces TG owned - this should save memory and avoid s...
const TrackingVolume * lowestTrackingVolume(const Amg::Vector3D &gp) const
return the lowest tracking Volume
const TrackingVolume * lowestStaticTrackingVolume(const Amg::Vector3D &gp) const
return the lowest static tracking Volume
void synchronizeLayers(MsgStream &msgstream, TrackingVolume *vol=nullptr)
Geometry Builder business: synchronize all layers to enclosed volume dimensions.
void printVolumeInformation(MsgStream &msgstream, const TrackingVolume &tvol, int lvl) const
print VolumeInformation with Level
NavigationLevel m_navigationLevel
The Navigation level for identification.
void printVolumeHierarchy(MsgStream &msgstream) const
Print the summary of volume Hierarchy of the TrackingGeometry.
TrackingVolume * checkoutHighestTrackingVolume()
private method to be called from GeometryBuilder: return the world with ownership
std::map< const std::string, const TrackingVolume * > m_trackingVolumes
The Volumes in a map for later finding.
TrackingGeometry(TrackingVolume *highestVolume, NavigationLevel navlevel=globalSearch)
Constructor.
std::unique_ptr< TrackingVolume > m_world
The known world - and the beam.
Full Volume description used in Tracking, it inherits from Volume to get the geometrical structure,...
void setMotherVolume(const TrackingVolume *mvol)
set the MotherVolume
const LayerArray * confinedLayers() const
Return the subLayer array.
const TrackingVolumeArray * confinedVolumes() const
Return the subLayer array.
std::vector< const DetachedTrackingVolume * > assocDetachedSubVolumes(const Amg::Vector3D &gp, double tol) const
Return the associated detached subvolumes.
const TrackingVolume * associatedSubVolume(const Amg::Vector3D &gp) const
Return the associated sub Volume, returns THIS if no subVolume exists.
std::vector< std::shared_ptr< BoundarySurface< TrackingVolume > > > & boundarySurfaces()
Method to return the BoundarySurfaces.
const std::string & volumeName() const
Returns the VolumeName - for debug reason, might be depreciated later.
void synchronizeLayers(MsgStream &msgstream, double envelope=1.)
method to synchronize the layers with potentially updated volume bounds:
ArraySpan< DetachedTrackingVolume const *const > confinedDetachedVolumes() const
Return detached subVolumes - not the ownership.
void compactify(size_t &rSurfaces, size_t &tSurfaces)
compactify the memory usage in the event by setting ownership to TackingGeometry the referenced types...
ArraySpan< TrackingVolume const *const > confinedDenseVolumes() const
Return unordered subVolumes - not the ownership.
bool inside(const Amg::Vector3D &gp, double tol=0.) const
Inside() method for checks.
Definition Volume.cxx:72
std::string head(std::string s, const std::string &pattern)
head of a string
Eigen::Matrix< double, 3, 1 > Vector3D
PropDirection
PropDirection, enum for direction of the propagation.
std::span< T > ArraySpan
NavigationLevel
destinguishes an association TrackingGeometry with one for global search
MsgStream & msg
Definition testRead.cxx:32