Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
34  if (m_world) delete m_world;
35 }
36 void Trk::TrackingGeometry::addToGarbage(std::vector<std::unique_ptr<DetachedTrackingVolume>>&& garbageVec) {
37  m_detachedVolGarbage.insert(m_detachedVolGarbage.end(),
38  std::make_move_iterator(garbageVec.begin()),
39  std::make_move_iterator(garbageVec.end()));
40 }
41 void Trk::TrackingGeometry::addToGarbage(std::vector<std::unique_ptr<TrackingVolume>>&& garbageVec){
42  m_trkVolumeGarbage.insert(m_trkVolumeGarbage.end(),
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 
59 std::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 
84 void
86  Trk::TrackingVolume* mvol,
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 
157 void
159 {
160  Trk::TrackingVolume* tVolume = vol ? vol : highestTrackingVolume();
161  tVolume->synchronizeLayers(msg);
162 }
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 
173 void
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 
184 void
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 
222  tvol.confinedDenseVolumes();
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 
245 bool
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 
263 bool
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 
289 void
290 Trk::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 }
324 void
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 }
Trk::Surface::materialLayer
const Trk::MaterialLayer * materialLayer() const
return the material Layer
Trk::TrackingGeometry::m_world
TrackingVolume * m_world
The known world - and the beam.
Definition: TrackingGeometry.h:203
Trk::TrackingGeometry::atVolumeBoundary
static bool atVolumeBoundary(const Amg::Vector3D &gp, const TrackingVolume *vol, double tol)
check position at volume boundary
Definition: TrackingGeometry.cxx:246
GeometrySignature
MaterialProperties.h
Trk::Volume::inside
bool inside(const Amg::Vector3D &gp, double tol=0.) const
Inside() method for checks.
Definition: Volume.cxx:72
Trk::TrackingGeometry::dump
void dump(MsgStream &out, const std::string &head) const
Definition: TrackingGeometry.cxx:290
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:530
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:85
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:33
Trk::MaterialLayer::surfaceRepresentation
virtual const Surface & surfaceRepresentation() const override=0
Transforms the layer into a Surface representation for extrapolation.
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:158
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:325
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
geometry_dat_to_json.indent
indent
Definition: geometry_dat_to_json.py:37
Trk::TrackingVolume::assocDetachedSubVolumes
std::vector< const DetachedTrackingVolume * > assocDetachedSubVolumes(const Amg::Vector3D &gp, double tol) const
Return the associated detached subvolumes.
Definition: TrackingVolume.cxx:624
TrigConf::MSGTC::ALWAYS
@ ALWAYS
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:29
Trk::ArraySpan
std::span< T > ArraySpan
Definition: TrackingVolume.h:59
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:72
Trk::TrackingVolume::synchronizeLayers
void synchronizeLayers(MsgStream &msgstream, double envelope=1.)
method to synchronize the layers with potentially updated volume bounds:
Definition: TrackingVolume.cxx:1103
Trk::TrackingGeometry::addToGarbage
void addToGarbage(std::vector< std::unique_ptr< Trk::DetachedTrackingVolume >> &&garbageVec)
Definition: TrackingGeometry.cxx:36
Trk::TrackingVolume::boundarySurfaces
std::vector< std::shared_ptr< BoundarySurface< TrackingVolume > > > & boundarySurfaces()
Method to return the BoundarySurfaces.
Definition: TrackingVolume.cxx:809
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:137
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
Trk::BinnedArray::arrayObjects
virtual std::span< T *const > arrayObjects()=0
Return all objects of the Array non-const we can still modify the T.
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:237
Trk::TGOwn
@ TGOwn
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:58
head
std::string head(std::string s, const std::string &pattern)
head of a string
Definition: computils.cxx:311
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:24
Trk::TrackingGeometry::printVolumeHierarchy
void printVolumeHierarchy(MsgStream &msgstream) const
Print the summary of volume Hierarchy of the TrackingGeometry.
Definition: TrackingGeometry.cxx:174
MaterialLayer.h
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:60
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:1131
Trk::TrackingGeometry::checkoutHighestTrackingVolume
TrackingVolume * checkoutHighestTrackingVolume()
private method to be called from GeometryBuilder: return the world with ownership
Definition: TrackingGeometry.cxx:165
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:48
Trk::TrackingGeometry::printVolumeInformation
void printVolumeInformation(MsgStream &msgstream, const TrackingVolume &tvol, int lvl) const
print VolumeInformation with Level
Definition: TrackingGeometry.cxx:185
TrackingGeometry.h
Trk::MaterialLayer
Definition: MaterialLayer.h:42
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:13
Trk::BinnedArray
Definition: BinnedArray.h:36
test_pyathena.counter
counter
Definition: test_pyathena.py:15
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:79
Trk::TrackingVolume
Definition: TrackingVolume.h:119
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Trk::Layer
Definition: Layer.h:72