ATLAS Offline Software
MdtTubeLayer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
5 #include <GeoModelKernel/GeoTube.h>
6 #include <GeoModelKernel/GeoAccessVolumeAction.h>
7 
8 #include <GeoModelHelpers/TransformSorter.h>
9 #include <GeoModelHelpers/GeoPhysVolSorter.h>
11 
12 namespace MuonGMR4{
13 
14 
16  // Don't bother calling the underlying comparisons
17  // if the objects are the same. This saves a lot of time.
18  if (&a.layerTransform() != &b.layerTransform()) {
19  static const GeoTrf::TransformSorter trfSort{};
20  const int trfCmp = trfSort.compare(a.layerTransform(), b.layerTransform());
21  if (trfCmp) return trfCmp < 0;
22  }
23  if (a.m_layerNode != b.m_layerNode) {
24  static const GeoPhysVolSorter physSort{};
25  return physSort(a.m_layerNode, b.m_layerNode);
26  }
27  return false;
28  }
30  return (*this)(*a, *b);
31  }
32 
33 
35  const GeoIntrusivePtr<const GeoTransform> toLayTrf):
36  m_layerNode{std::move(layer)},
37  m_layTrf{std::move(toLayTrf)} {}
38 
40  return m_layTrf->getDefTransform();
41 }
42 namespace {
43 // Helper to find the Nth child volume, without keeping track
44 // of the transform.
45 class GeoGetChild : public IGeoVisitVolumesNoXformAction
46 {
47 public:
48  GeoGetChild (size_t n) : m_n (n) {}
49  virtual void operator() (GeoNodeAction& action,
50  int /*id*/,
51  const std::string& /*name*/,
52  const GeoVPhysVol* volume) override
53  {
54  if (m_n == 0) {
55  m_node = volume;
56  action.terminate();
57  }
58  else {
59  --m_n;
60  }
61  }
62 
63  size_t m_n;
64  const GeoVPhysVol* m_node = nullptr;
65 };
66 } // anonymous namespace
67 PVConstLink MdtTubeLayer::getTubeNode(unsigned int tube) const {
68  if (tube >= nTubes()) {
69  std::stringstream except{};
70  except<<__FILE__<<":"<<__LINE__<<" "<<m_layerNode->getLogVol()->getName()<<" has only "<<nTubes()<<" tubes. But "<<tube<<" is requested. Please check.";
71  throw std::out_of_range(except.str());
72  }
73 
74  // Don't use getChildVol. Under the hood, that keeps track of the
75  // transform to each child, even though that is not actually used.
76  // This is slow, especially in debug builds where Eigen operations
77  // tend to be expensive.
78  GeoGetChild a (tube);
79  GeoVisitVolumes visitor (a);
80  m_layerNode->exec (&visitor);
81  return a.m_node;
82 }
83 const Amg::Transform3D MdtTubeLayer::tubeTransform(const unsigned int tube) const {
84  if (tube >= nTubes()) {
85  std::stringstream except{};
86  except<<__FILE__<<":"<<__LINE__<<" "<<m_layerNode->getLogVol()->getName()<<" has only "<<nTubes()<<" tubes. But "<<tube<<" is requested. Please check.";
87  throw std::out_of_range(except.str());
88  }
89  GeoAccessVolumeAction volAcc{tube, nullptr};
90  m_layerNode->exec(&volAcc);
91  return layerTransform() * volAcc.getDefTransform();
92 }
93 GeoVolumeCursor MdtTubeLayer::tubeCursor() const {
94  return GeoVolumeCursor(m_layerNode);
95 }
96 const Amg::Vector3D MdtTubeLayer::tubePosInLayer(const unsigned int tube) const {
97  return layerTransform().inverse() * tubeTransform(tube).translation();
98 }
99 unsigned int MdtTubeLayer::nTubes() const {
100  return m_layerNode->getNChildVols();
101 }
102 double MdtTubeLayer::tubeHalfLength(const unsigned int tube) const {
103  const PVConstLink child = getTubeNode(tube);
104  const GeoShape* shape = child->getLogVol()->getShape();
105  const GeoTube* tubeShape = static_cast<const GeoTube*>(shape);
106  return tubeShape->getZHalfLength();
107 }
108 }
109 
GeoModel::TransientConstSharedPtr
The TransientConstSharedPtr allows non-const access if the pointer itself is non-const but in the con...
Definition: TransientConstSharedPtr.h:13
MuonGMR4::MdtTubeLayer::layerTransform
const Amg::Transform3D & layerTransform() const
: Returns the transformation from the layer to the muon station
Definition: MdtTubeLayer.cxx:39
m_n
size_t m_n
Definition: MdtTubeLayer.cxx:63
MuonGMR4::MdtTubeLayer
Helper struct to retrieve the tube lengths and the tube centers directly from the GeoModel tree.
Definition: MdtTubeLayer.h:28
MuonGMR4::MdtTubeLayer::MdtTubeLayer
MdtTubeLayer(const PVConstLink layer, const GeoIntrusivePtr< const GeoTransform > toLayTrf)
Standard constructor of a MdtTube layer.
Definition: MdtTubeLayer.cxx:34
MdtTubeLayer.h
GeoVisitVolumes.h
Visitor to process all volumes under a GeoModel node.
IGeoVisitVolumesNoXformAction
Define a simple callback for each volume found, without keeping track of geometrical transforms.
Definition: GeoVisitVolumes.h:57
MuonGMR4
A muon chamber is a collection of readout elements belonging to the same station.
Definition: ChamberAssembleTool.h:16
beamspotman.n
n
Definition: beamspotman.py:731
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
MuonGMR4::MdtTubeLayer::getTubeNode
PVConstLink getTubeNode(unsigned int tube) const
returns the PVConst link to the n-th tube [0 - nTubes() -1]
Definition: MdtTubeLayer.cxx:67
MuonGMR4::MdtTubeLayerSorter::operator()
bool operator()(const MdtTubeLayer &a, const MdtTubeLayer &b) const
Definition: MdtTubeLayer.cxx:15
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
MuonGMR4::MdtTubeLayer::nTubes
unsigned int nTubes() const
Returns the number of tubes in the layer.
Definition: MdtTubeLayer.cxx:99
MuonGMR4::MdtTubeLayer::tubeHalfLength
double tubeHalfLength(const unsigned int tube) const
Returns the half-length of the given tube.
Definition: MdtTubeLayer.cxx:102
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonGMR4::MdtTubeLayer::tubeTransform
const Amg::Transform3D tubeTransform(const unsigned int tube) const
Returns the transformation of the tube to the muon station Index counting [0 - nTubes()-1].
Definition: MdtTubeLayer.cxx:83
MuonGMR4::MdtTubeLayer::m_layerNode
PVConstLink m_layerNode
Definition: MdtTubeLayer.h:56
a
TList * a
Definition: liststreamerinfos.cxx:10
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77
MuonGMR4::MdtTubeLayer::tubeCursor
GeoVolumeCursor tubeCursor() const
Return a cursor object over the tubes in the layer.
Definition: MdtTubeLayer.cxx:93
GeoVisitVolumes
Visitor to process all volumes under a GeoModel node.
Definition: GeoVisitVolumes.h:77
MuonGMR4::MdtTubeLayer::m_layTrf
GeoIntrusivePtr< const GeoTransform > m_layTrf
Definition: MdtTubeLayer.h:57
MuonGMR4::MdtTubeLayer::tubePosInLayer
const Amg::Vector3D tubePosInLayer(const unsigned int tube) const
Returns the tube position within the given tube layer.
Definition: MdtTubeLayer.cxx:96
calibdata.tube
tube
Definition: calibdata.py:31
m_node
const GeoVPhysVol * m_node
Definition: MdtTubeLayer.cxx:64