ATLAS Offline Software
Loading...
Searching...
No Matches
TrackingGeometry.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 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
36void Trk::TrackingGeometry::addToGarbage(std::vector<std::unique_ptr<DetachedTrackingVolume>>&& garbageVec) {
38 std::make_move_iterator(garbageVec.begin()),
39 std::make_move_iterator(garbageVec.end()));
40}
41void Trk::TrackingGeometry::addToGarbage(std::vector<std::unique_ptr<TrackingVolume>>&& garbageVec){
43 std::make_move_iterator(garbageVec.begin()),
44 std::make_move_iterator(garbageVec.end()));
45}
46
49{
50 const Trk::TrackingVolume* searchVolume = highestTrackingVolume();
51 const Trk::TrackingVolume* currentVolume = nullptr;
52 while (currentVolume != searchVolume && searchVolume) {
53 currentVolume = searchVolume;
54 searchVolume = searchVolume->associatedSubVolume(gp);
55 }
56 return (currentVolume);
57}
58
59std::vector<const Trk::DetachedTrackingVolume*>
61 const Amg::Vector3D& gp) const
62{
63 double tol = 0.001;
64 const Trk::TrackingVolume* currentVolume = lowestStaticTrackingVolume(gp);
65 if (currentVolume){
66 return currentVolume->assocDetachedSubVolumes(gp, tol);
67 }
68 return {};
69}
70
73{
74 const Trk::TrackingVolume* searchVolume = highestTrackingVolume();
75 const Trk::TrackingVolume* currentVolume = nullptr;
76 while (currentVolume != searchVolume && searchVolume) {
77 currentVolume = searchVolume;
78 if (searchVolume->confinedDetachedVolumes().empty())
79 searchVolume = searchVolume->associatedSubVolume(gp);
80 }
81 return (currentVolume);
82}
83
84void
87 int lvl)
88{
89 int sublvl = lvl + 1;
90 std::string indent = "";
91 for (int l = 0; l < lvl; ++l){
92 indent += " ";
93 }
94
95 tvol.setMotherVolume(mvol);
96 m_trackingVolumes[tvol.volumeName()] = (&tvol);
98 if (confinedVolumes) {
99 std::span<Trk::TrackingVolume* const> volumes = confinedVolumes->arrayObjects();
100 for (const auto& volumesIter : volumes){
101 if (volumesIter){
102 registerTrackingVolumes(*volumesIter, &tvol, sublvl);
103 }
104 }
105 }
106
108 if (!confinedDenseVolumes.empty()) {
109 for (const auto& volumesIter : confinedDenseVolumes){
110 if (volumesIter){
111 registerTrackingVolumes(*volumesIter, &tvol, sublvl);
112 }
113 }
114 }
117 if (!confinedDetachedVolumes.empty()) {
118 for (const auto& volumesIter : confinedDetachedVolumes){
119 if (volumesIter &&
120 tvol.inside(volumesIter->trackingVolume()->center(), 0.)){
121 registerTrackingVolumes( *(volumesIter->trackingVolume()), &tvol, sublvl);
122 }
123 }
124 }
126 // boundary layers
127 const auto& bounds = tvol.boundarySurfaces();
128 for (const auto & bound : bounds) {
130 if (bLayer) {
131 int& layerCount{m_boundaryLayers[bLayer]};
132 ++layerCount;
133 }
134 }
135}
136
138{
139 msg << MSG::VERBOSE
140 << "====== Calling TrackingGeometry::compactify() ===== " << std::endl;
141 Trk::TrackingVolume* tVolume = vol ? vol : highestTrackingVolume();
142 size_t cSurfaces = 0;
143 size_t tSurfaces = 0;
144 if (tVolume) {
145 tVolume->compactify(cSurfaces, tSurfaces);
146 }
147 msg << MSG::VERBOSE << " --> set TG ownership of " << cSurfaces << " out of "
148 << tSurfaces << std::endl;
149 for (const auto& bLayerIter : m_boundaryLayers) {
150 bLayerIter.first->surfaceRepresentation().setOwner(Trk::TGOwn);
151 }
152 msg << MSG::VERBOSE << " --> set TG ownership of " << m_boundaryLayers.size()
153 << " boundary layers." << std::endl;
154 msg << MSG::VERBOSE << endmsg;
155}
156
157void
163
166 Trk::TrackingVolume* checkoutVolume{nullptr};
167 std::swap(m_world, checkoutVolume);
168 // clear the boundary layers they go with the highest volume
169 m_boundaryLayers.clear();
170 return checkoutVolume;
171}
172
173void
175{
176 msg << "TrackingGeometry Summary : " << std::endl;
177 const Trk::TrackingVolume* highestVolume = highestTrackingVolume();
178 int level = 0;
179 if (highestVolume)
180 printVolumeInformation(msg, *highestVolume, level);
181 msg << endmsg;
182}
183
184void
186 const Trk::TrackingVolume& tvol,
187 int lvl) const
188{
189 int sublevel = lvl + 1;
190
191 for (int indent = 0; indent < sublevel; ++indent)
192 msg << " ";
193 msg << "TrackingVolume ( at : " << (&tvol) << ") name: " << tvol.volumeName()
194 << std::endl;
195
196 const Trk::BinnedArray<Trk::Layer>* confinedLayers = tvol.confinedLayers();
197 if (confinedLayers) {
198 std::span<Trk::Layer const* const> layers =
199 confinedLayers->arrayObjects();
200 for (int indent = 0; indent < sublevel; ++indent)
201 msg << " ";
202 msg << "- found : " << layers.size() << " confined Layers" << std::endl;
203 }
204
205 const Trk::BinnedArray<Trk::TrackingVolume>* confinedVolumes =
206 tvol.confinedVolumes();
207 if (confinedVolumes) {
208 std::span<Trk::TrackingVolume const* const> volumes =
209 confinedVolumes->arrayObjects();
210
211 for (int indent = 0; indent < sublevel; ++indent)
212 msg << " ";
213 msg << "- found : " << volumes.size() << " confined TrackingVolumes"
214 << std::endl;
215
216 for (const auto& volumesIter : volumes)
217 if (volumesIter)
218 printVolumeInformation(msg, *volumesIter, sublevel);
219 }
220
223 if (!confinedDenseVolumes.empty()) {
224 for (int indent = 0; indent < sublevel; ++indent) {
225 msg << " ";
226 }
227 msg << "- found : " << confinedDenseVolumes.size()
228 << " confined unordered (dense) TrackingVolumes" << std::endl;
229
230 for (const auto& volumesIter : (confinedDenseVolumes))
231 if (volumesIter) {
232 printVolumeInformation(msg, *volumesIter, sublevel);
233 }
234 }
235}
236
238{
239 if (m_world) {
240 m_world->indexContainedStaticLayers(geosit, offset);
241 m_world->indexContainedMaterialLayers(geosit, offset);
242 }
243}
244
245bool
247 const Trk::TrackingVolume* vol,
248 double tol)
249{
250 bool isAtBoundary = false;
251 if (!vol)
252 return isAtBoundary;
253 const auto& bounds = vol->boundarySurfaces();
254 for (size_t ib = 0; ib < bounds.size(); ++ib) {
255 const Trk::Surface& surf = bounds[ib]->surfaceRepresentation();
256 if (surf.isOnSurface(gp, true, tol, tol))
257 isAtBoundary = true;
258 }
259 return isAtBoundary;
260}
261
263bool
265 const Amg::Vector3D& mom,
266 const TrackingVolume* vol,
267 const TrackingVolume*& nextVol,
269 double tol)
270{
271 bool isAtBoundary = false;
272 nextVol = nullptr;
273 if (!vol)
274 return isAtBoundary;
275 const auto& bounds = vol->boundarySurfaces();
276 for (size_t ib = 0; ib < bounds.size(); ++ib) {
277 const Trk::Surface& surf = bounds[ib]->surfaceRepresentation();
278 if (surf.isOnSurface(gp, true, tol, tol)) {
279 isAtBoundary = true;
280 const Trk::TrackingVolume* attachedVol =
281 bounds[ib]->attachedVolume(gp, mom, dir);
282 if (!nextVol && attachedVol)
283 nextVol = attachedVol;
284 }
285 }
286 return isAtBoundary;
287}
288
289void
290Trk::TrackingGeometry::dump(MsgStream& out, const std::string& head) const
291{
292 out << MSG::ALWAYS;
293 for (const auto& bound_layers : m_boundaryLayers) {
294 out << head << " [" << bound_layers.second << "] ";
295 dumpLayer(out, "", bound_layers.first);
296 }
297 int counter = 0;
298 for (const std::pair<const std::string, const TrackingVolume*>& volume : m_trackingVolumes) {
299 out << head << " [" << counter++ << "] " << volume.first << " volumeBound=";
300 volume.second->volumeBounds().dump(out);
301 out << std::endl;
303 volume.second->confinedArbitraryLayers();
304 if (!confArbLayers.empty()) {
305 int j = 0;
306 for (const Layer* confined_layer : confArbLayers) {
307 out << head << " [" << counter++ << "] " << volume.first
308 << " confinedArbitrary layer " << j++ << " ";
309 dumpLayer(out, "", confined_layer);
310 }
311 }
312 if (volume.second->confinedLayers()) {
313 int j = 0;
314 for (const Layer* confined_layer :
315 volume.second->confinedLayers()->arrayObjects()) {
316 out << head << " [" << counter++ << "] " << volume.first
317 << " confined layer" << j++ << " ";
318 dumpLayer(out, "", confined_layer);
319 }
320 }
321 }
322 out << endmsg;
323}
324void
326 const std::string& head,
327 const Layer* layer)
328{
329 if (!layer) {
330 return;
331 }
332 out << head << layer->layerIndex().value() << " [t=" << layer->layerType()
333 << "] d=" << layer->thickness();
334 out << layer->surfaceRepresentation();
335 out << std::endl;
336}
#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)
TrackingVolume * m_world
The known world - and the beam.
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.
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
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
MsgStream & msg
Definition testRead.cxx:32