ATLAS Offline Software
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"
18 // GaudiKernel
19 #include "GaudiKernel/MsgStream.h"
20 
21 
22 
24  NavigationLevel navLev):
25  m_world(highestVolume),
26  m_navigationLevel(navLev) {
27  // for the time being only world
28  if (!m_world) return;
30 }
31 
33  if (m_world) delete m_world;
34 }
35 void Trk::TrackingGeometry::addToGarbage(std::vector<std::unique_ptr<DetachedTrackingVolume>>&& garbageVec) {
36  std::copy_if(std::make_move_iterator(garbageVec.begin()), std::make_move_iterator(garbageVec.end()),
37  std::back_inserter(m_detachedVolGarbage),
38  [](const std::unique_ptr<DetachedTrackingVolume>& ptr){
39  return ptr.get () != nullptr;
40  });
41 
42 }
43 void Trk::TrackingGeometry::addToGarbage(std::vector<std::unique_ptr<TrackingVolume>>&& garbageVec){
44  std::copy_if(std::make_move_iterator(garbageVec.begin()), std::make_move_iterator(garbageVec.end()),
45  std::back_inserter(m_trkVolumeGarbage),
46  [](const std::unique_ptr<TrackingVolume>& ptr){
47  return ptr.get () != nullptr;
48  });
49 }
50 
51 
54 {
55  const Trk::TrackingVolume* searchVolume = highestTrackingVolume();
56  const Trk::TrackingVolume* currentVolume = nullptr;
57  while (currentVolume != searchVolume && searchVolume) {
58  currentVolume = searchVolume;
59  searchVolume = searchVolume->associatedSubVolume(gp);
60  }
61  return (currentVolume);
62 }
63 
64 std::vector<const Trk::DetachedTrackingVolume*>
66  const Amg::Vector3D& gp) const
67 {
68  double tol = 0.001;
69  const Trk::TrackingVolume* currentVolume = lowestStaticTrackingVolume(gp);
70  if (currentVolume){
71  return currentVolume->assocDetachedSubVolumes(gp, tol);
72  }
73  return {};
74 }
75 
78 {
79  const Trk::TrackingVolume* searchVolume = highestTrackingVolume();
80  const Trk::TrackingVolume* currentVolume = nullptr;
81  while (currentVolume != searchVolume && searchVolume) {
82  currentVolume = searchVolume;
83  if (searchVolume->confinedDetachedVolumes().empty())
84  searchVolume = searchVolume->associatedSubVolume(gp);
85  }
86  return (currentVolume);
87 }
88 
89 void
91  Trk::TrackingVolume* mvol,
92  int lvl)
93 {
94  int sublvl = lvl + 1;
95  std::string indent = "";
96  for (int l = 0; l < lvl; ++l, indent += " ")
97  ;
98 
99  tvol.setMotherVolume(mvol);
100  m_trackingVolumes[tvol.volumeName()] = (&tvol);
101  Trk::BinnedArray<Trk::TrackingVolume>* confinedVolumes =
102  tvol.confinedVolumes();
103  if (confinedVolumes) {
105  confinedVolumes->arrayObjects();
106  for (const auto& volumesIter : volumes)
107  if (volumesIter)
108  registerTrackingVolumes(*volumesIter, &tvol, sublvl);
109  }
110 
111  Trk::ArraySpan<Trk::TrackingVolume* const> confinedDenseVolumes =
112  tvol.confinedDenseVolumes();
113  if (!confinedDenseVolumes.empty()) {
114  for (const auto& volumesIter : confinedDenseVolumes)
115  if (volumesIter)
116  registerTrackingVolumes(*volumesIter, &tvol, sublvl);
117  }
121  if (!confinedDetachedVolumes.empty()) {
122  for (const auto& volumesIter : confinedDetachedVolumes)
123  if (volumesIter &&
124  tvol.inside(volumesIter->trackingVolume()->center(), 0.))
125  registerTrackingVolumes(
126  *(volumesIter->trackingVolume()), &tvol, sublvl);
127  }
129  // boundary layers
130  const auto& bounds = tvol.boundarySurfaces();
131  for (const auto & bound : bounds) {
132  Trk::Layer* bLayer =
134  if (bLayer) {
135  int& layerCount{m_boundaryLayers[bLayer]};
136  ++layerCount;
137  }
138  }
139 }
140 
142 {
143  msg << MSG::VERBOSE
144  << "====== Calling TrackingGeometry::compactify() ===== " << std::endl;
145  Trk::TrackingVolume* tVolume = vol ? vol : highestTrackingVolume();
146  size_t cSurfaces = 0;
147  size_t tSurfaces = 0;
148  if (tVolume) {
149  tVolume->compactify(cSurfaces, tSurfaces);
150  }
151  msg << MSG::VERBOSE << " --> set TG ownership of " << cSurfaces << " out of "
152  << tSurfaces << std::endl;
153  for (const auto& bLayerIter : m_boundaryLayers) {
154  bLayerIter.first->surfaceRepresentation().setOwner(Trk::TGOwn);
155  }
156  msg << MSG::VERBOSE << " --> set TG ownership of " << m_boundaryLayers.size()
157  << " boundary layers." << std::endl;
158  msg << MSG::VERBOSE << endmsg;
159 }
160 
161 void
163 {
164  Trk::TrackingVolume* tVolume = vol ? vol : highestTrackingVolume();
165  tVolume->synchronizeLayers(msg);
166 }
167 
170  Trk::TrackingVolume* checkoutVolume{nullptr};
171  std::swap(m_world, checkoutVolume);
172  // clear the boundary layers they go with the highest volume
173  m_boundaryLayers.clear();
174  return checkoutVolume;
175 }
176 
177 void
179 {
180  msg << "TrackingGeometry Summary : " << std::endl;
181  const Trk::TrackingVolume* highestVolume = highestTrackingVolume();
182  int level = 0;
183  if (highestVolume)
184  printVolumeInformation(msg, *highestVolume, level);
185  msg << endmsg;
186 }
187 
188 void
190  const Trk::TrackingVolume& tvol,
191  int lvl) const
192 {
193  int sublevel = lvl + 1;
194 
195  for (int indent = 0; indent < sublevel; ++indent)
196  msg << " ";
197  msg << "TrackingVolume ( at : " << (&tvol) << ") name: " << tvol.volumeName()
198  << std::endl;
199 
200  const Trk::BinnedArray<Trk::Layer>* confinedLayers = tvol.confinedLayers();
201  if (confinedLayers) {
203  confinedLayers->arrayObjects();
204  for (int indent = 0; indent < sublevel; ++indent)
205  msg << " ";
206  msg << "- found : " << layers.size() << " confined Layers" << std::endl;
207  }
208 
209  const Trk::BinnedArray<Trk::TrackingVolume>* confinedVolumes =
210  tvol.confinedVolumes();
211  if (confinedVolumes) {
213  confinedVolumes->arrayObjects();
214 
215  for (int indent = 0; indent < sublevel; ++indent)
216  msg << " ";
217  msg << "- found : " << volumes.size() << " confined TrackingVolumes"
218  << std::endl;
219 
220  for (const auto& volumesIter : volumes)
221  if (volumesIter)
222  printVolumeInformation(msg, *volumesIter, sublevel);
223  }
224 
226  tvol.confinedDenseVolumes();
227  if (!confinedDenseVolumes.empty()) {
228  for (int indent = 0; indent < sublevel; ++indent) {
229  msg << " ";
230  }
231  msg << "- found : " << confinedDenseVolumes.size()
232  << " confined unordered (dense) TrackingVolumes" << std::endl;
233 
234  for (const auto& volumesIter : (confinedDenseVolumes))
235  if (volumesIter) {
236  printVolumeInformation(msg, *volumesIter, sublevel);
237  }
238  }
239 }
240 
242 {
243  if (m_world) {
244  m_world->indexContainedStaticLayers(geosit, offset);
245  m_world->indexContainedMaterialLayers(geosit, offset);
246  }
247 }
248 
249 bool
251  const Trk::TrackingVolume* vol,
252  double tol)
253 {
254  bool isAtBoundary = false;
255  if (!vol)
256  return isAtBoundary;
257  const auto& bounds = vol->boundarySurfaces();
258  for (size_t ib = 0; ib < bounds.size(); ++ib) {
259  const Trk::Surface& surf = bounds[ib]->surfaceRepresentation();
260  if (surf.isOnSurface(gp, true, tol, tol))
261  isAtBoundary = true;
262  }
263  return isAtBoundary;
264 }
265 
267 bool
269  const Amg::Vector3D& mom,
270  const TrackingVolume* vol,
271  const TrackingVolume*& nextVol,
273  double tol)
274 {
275  bool isAtBoundary = false;
276  nextVol = nullptr;
277  if (!vol)
278  return isAtBoundary;
279  const auto& bounds = vol->boundarySurfaces();
280  for (size_t ib = 0; ib < bounds.size(); ++ib) {
281  const Trk::Surface& surf = bounds[ib]->surfaceRepresentation();
282  if (surf.isOnSurface(gp, true, tol, tol)) {
283  isAtBoundary = true;
284  const Trk::TrackingVolume* attachedVol =
285  bounds[ib]->attachedVolume(gp, mom, dir);
286  if (!nextVol && attachedVol)
287  nextVol = attachedVol;
288  }
289  }
290  return isAtBoundary;
291 }
292 
293 void
294 Trk::TrackingGeometry::dump(MsgStream& out, const std::string& head) const
295 {
296  out << MSG::ALWAYS;
297  for (const auto& bound_layers : m_boundaryLayers) {
298  out << head << " [" << bound_layers.second << "] ";
299  dumpLayer(out, "", bound_layers.first);
300  }
301  int counter = 0;
302  for (const std::pair<const std::string, const TrackingVolume*>& volume :
303  m_trackingVolumes) {
304  out << head << " [" << counter++ << "] " << volume.first << " volumeBound=";
305  volume.second->volumeBounds().dump(out);
306  out << std::endl;
308  volume.second->confinedArbitraryLayers();
309  if (!confArbLayers.empty()) {
310  int j = 0;
311  for (const Layer* confined_layer : confArbLayers) {
312  out << head << " [" << counter++ << "] " << volume.first
313  << " confinedArbitrary layer " << j++ << " ";
314  dumpLayer(out, "", confined_layer);
315  }
316  }
317  if (volume.second->confinedLayers()) {
318  int j = 0;
319  for (const Layer* confined_layer :
320  volume.second->confinedLayers()->arrayObjects()) {
321  out << head << " [" << counter++ << "] " << volume.first
322  << " confined layer" << j++ << " ";
323  dumpLayer(out, "", confined_layer);
324  }
325  }
326  }
327  out << endmsg;
328 }
329 void
331  const std::string& head,
332  const Layer* layer)
333 {
334  if (!layer) {
335  return;
336  }
337  out << head << layer->layerIndex().value() << " [t=" << layer->layerType()
338  << "] d=" << layer->thickness();
339  out << layer->surfaceRepresentation();
340  out << std::endl;
341 }
Trk::TrackingGeometry::m_world
TrackingVolume * m_world
The known world - and the beam.
Definition: TrackingGeometry.h:204
Trk::TrackingGeometry::atVolumeBoundary
static bool atVolumeBoundary(const Amg::Vector3D &gp, const TrackingVolume *vol, double tol)
check position at volume boundary
Definition: TrackingGeometry.cxx:250
GeometrySignature
MaterialProperties.h
Trk::Volume::inside
bool inside(const Amg::Vector3D &gp, double tol=0.) const
Inside() method for checks.
Definition: Volume.cxx:90
Trk::TrackingGeometry::dump
void dump(MsgStream &out, const std::string &head) const
Definition: TrackingGeometry.cxx:294
Trk::TrackingVolume::boundarySurfaces
std::vector< SharedObject< BoundarySurface< TrackingVolume > > > & boundarySurfaces()
Method to return the BoundarySurfaces.
Definition: TrackingVolume.cxx:982
Trk::TrackingVolume::associatedSubVolume
const TrackingVolume * associatedSubVolume(const Amg::Vector3D &gp) const
Return the associated sub Volume, returns THIS if no subVolume exists.
Definition: TrackingVolume.cxx:710
module_driven_slicing.layers
layers
Definition: module_driven_slicing.py:114
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
PlotCalibFromCool.ib
ib
Definition: PlotCalibFromCool.py:419
Trk::TrackingGeometry::registerTrackingVolumes
void registerTrackingVolumes(TrackingVolume &tvol, TrackingVolume *mvol=nullptr, int lvl=0)
private method to register recursively the tracking volumes
Definition: TrackingGeometry.cxx:90
Trk::TrackingVolume::confinedDetachedVolumes
ArraySpan< DetachedTrackingVolume const *const > confinedDetachedVolumes() const
Return detached subVolumes - not the ownership.
VolumeBounds.h
Layer.h
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
Trk::TrackingGeometry::~TrackingGeometry
virtual ~TrackingGeometry()
Destructor.
Definition: TrackingGeometry.cxx:32
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
Trk::TrackingGeometry::synchronizeLayers
void synchronizeLayers(MsgStream &msgstream, TrackingVolume *vol=nullptr)
Geometry Builder business: synchronize all layers to enclosed volume dimensions.
Definition: TrackingGeometry.cxx:162
Trk::TrackingVolume::confinedLayers
const LayerArray * confinedLayers() const
Return the subLayer array.
MagneticFieldProperties.h
Trk::TrackingGeometry::dumpLayer
static void dumpLayer(MsgStream &out, const std::string &head, const Layer *layer)
Definition: TrackingGeometry.cxx:330
Trk::NavigationLevel
NavigationLevel
Definition: TrackingGeometry.h:43
Trk::PropDirection
PropDirection
Definition: PropDirection.h:19
Trk::Surface::isOnSurface
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
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
Trk::Layer::surfaceRepresentation
virtual const Surface & surfaceRepresentation() const =0
Transforms the layer into a Surface representation for extrapolation.
geometry_dat_to_json.indent
indent
Definition: geometry_dat_to_json.py:36
Trk::TrackingVolume::assocDetachedSubVolumes
std::vector< const DetachedTrackingVolume * > assocDetachedSubVolumes(const Amg::Vector3D &gp, double tol) const
Return the associated detached subvolumes.
Definition: TrackingVolume.cxx:800
TrigConf::MSGTC::ALWAYS
@ ALWAYS
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:29
Trk::ArraySpan
std::span< T > ArraySpan
Definition: DetachedTrackingVolume.h:34
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Trk::TrackingVolume::confinedDenseVolumes
ArraySpan< TrackingVolume const *const > confinedDenseVolumes() const
Return unordered subVolumes - not the ownership.
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
Trk::TrackingGeometry::lowestStaticTrackingVolume
const TrackingVolume * lowestStaticTrackingVolume(const Amg::Vector3D &gp) const
return the lowest static tracking Volume
Definition: TrackingGeometry.cxx:77
Trk::TrackingVolume::synchronizeLayers
void synchronizeLayers(MsgStream &msgstream, double envelope=1.)
method to synchronize the layers with potentially updated volume bounds:
Definition: TrackingVolume.cxx:1427
AnalysisUtils::copy_if
Out copy_if(In first, const In &last, Out res, const Pred &p)
Definition: IFilterUtils.h:30
Trk::TrackingGeometry::addToGarbage
void addToGarbage(std::vector< std::unique_ptr< Trk::DetachedTrackingVolume >> &&garbageVec)
Definition: TrackingGeometry.cxx:35
Trk::Surface::materialLayer
const Trk::Layer * materialLayer() const
return the material Layer
Trk::TrackingGeometry::compactify
void compactify(MsgStream &msgstream, TrackingVolume *vol=nullptr)
Geometry Builder busineess: set all contained surfaces TG owned - this should save memory and avoid s...
Definition: TrackingGeometry.cxx:141
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
DetachedTrackingVolume.h
beamspotman.dir
string dir
Definition: beamspotman.py:623
Trk::TrackingGeometry::indexStaticLayers
void indexStaticLayers(GeometrySignature geosit, int offset=0)
indexLayers : method to re-set the index of the layers, depending on geometrySignature
Definition: TrackingGeometry.cxx:241
Trk::TGOwn
@ TGOwn
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:55
head
std::string head(std::string s, const std::string &pattern)
head of a string
Definition: computils.cxx:310
Trk::TrackingVolume::volumeName
const std::string & volumeName() const
Returns the VolumeName - for debug reason, might be depreciated later.
Trk::TrackingGeometry::TrackingGeometry
TrackingGeometry(TrackingVolume *highestVolume, NavigationLevel navlevel=globalSearch)
Constructor.
Definition: TrackingGeometry.cxx:23
Trk::BinnedArray::arrayObjects
virtual BinnedArraySpan< T *const > arrayObjects()=0
Return all objects of the Array non-const we can still modify the T.
Trk::TrackingGeometry::printVolumeHierarchy
void printVolumeHierarchy(MsgStream &msgstream) const
Print the summary of volume Hierarchy of the TrackingGeometry.
Definition: TrackingGeometry.cxx:178
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TrackingVolume.h
Trk::TrackingGeometry::lowestDetachedTrackingVolumes
std::vector< const Trk::DetachedTrackingVolume * > lowestDetachedTrackingVolumes(const Amg::Vector3D &gp) const
return the vector of lowest detached tracking Volume(->overlaps)
Definition: TrackingGeometry.cxx:65
Trk::TrackingVolume::confinedVolumes
const TrackingVolumeArray * confinedVolumes() const
Return the subLayer array.
Trk::TrackingVolume::setMotherVolume
void setMotherVolume(const TrackingVolume *mvol)
set the MotherVolume
Trk::TrackingVolume::compactify
void compactify(size_t &rSurfaces, size_t &tSurfaces)
compactify the memory usage in the event by setting ownership to TackingGeometry the referenced types...
Definition: TrackingVolume.cxx:1455
Trk::TrackingGeometry::checkoutHighestTrackingVolume
TrackingVolume * checkoutHighestTrackingVolume()
private method to be called from GeometryBuilder: return the world with ownership
Definition: TrackingGeometry.cxx:169
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
Trk::TrackingGeometry::lowestTrackingVolume
const TrackingVolume * lowestTrackingVolume(const Amg::Vector3D &gp) const
return the lowest tracking Volume
Definition: TrackingGeometry.cxx:53
Trk::TrackingGeometry::printVolumeInformation
void printVolumeInformation(MsgStream &msgstream, const TrackingVolume &tvol, int lvl) const
print VolumeInformation with Level
Definition: TrackingGeometry.cxx:189
TrackingGeometry.h
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
Trk::BinnedArray
Definition: BinnedArray.h:38
test_pyathena.counter
counter
Definition: test_pyathena.py:15
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::TrackingVolume
Definition: TrackingVolume.h:121
Trk::BinnedArraySpan
std::span< T > BinnedArraySpan
Definition: BinnedArray.h:34
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Trk::Layer
Definition: Layer.h:73