ATLAS Offline Software
Loading...
Searching...
No Matches
VertexMapper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6// VertexMapper.cxx, (c) ATLAS Detector software
8
9// Trk include
13
14
15// constructor
16Trk::VertexMapper::VertexMapper(const std::string& t, const std::string& n, const IInterface* p)
17: AthAlgTool(t,n,p),
18 m_trackingGeometry(nullptr),
19 m_trackingGeometryName("AtlasTrackingGeometry")
20{
21 declareInterface<IVertexMapper>(this);
22
23 // The TrackingGeometry
24 declareProperty("TrackingGeometry" , m_trackingGeometryName);
25
26
27}
28
29// destructor
31= default;
32
33// Athena standard methods
34// initialize
36{
37
38
39 return StatusCode::SUCCESS;
40}
41
42// finalize
44{
45 ATH_MSG_INFO( "finalize() successful" );
46 return StatusCode::SUCCESS;
47}
48
49
51 // retrieve the TrackingGeometry from the detector store
52 if (detStore()->retrieve(m_trackingGeometry, m_trackingGeometryName).isFailure()){
53 ATH_MSG_ERROR("Could not retrieve the tracking geometry. Bailing out.");
54 return StatusCode::FAILURE;
55 }
56 return StatusCode::SUCCESS;
57}
58
61
62 // first find the volume where you are in
63 const Trk::TrackingVolume* mVolume = trackingGeometry().lowestTrackingVolume(vertex);
64 // we have a volume, so go on
65 if (mVolume){
66 // from the volume, get all the layers
67 const Trk::LayerArray* mLayerArray = mVolume->confinedLayers();
68 // and check if we have confined layers
69 if (mLayerArray){
70 // extract all the layers with sensitive surfaces
71 std::span<Trk::Layer const * const> mLayerObjects = mLayerArray->arrayObjects();
72 std::vector<const Trk::Layer*> mSensitiveLayers;
73 // loop over for the extraction - and check if they have a sub surface array
74 for (const auto & mLayer : mLayerObjects){
75 if (mLayer->surfaceArray()){
76 // remember this layer
77 mSensitiveLayers.push_back(mLayer);
78 }
79 }
80 // now find out the closest - if you have layers to test
81 if (!mSensitiveLayers.empty()){
82 // prepare the book keepint
83 double mDistance = 10e10;
84 const Layer* mLayer = nullptr;
85 Amg::Vector3D mPosition(0.,0.,0.);
86 Amg::Vector3D mDirection(0.,0.,0.);
87 // loop over the test layers
88 for (auto& sLayer : mSensitiveLayers) {
89 // find out the optimal association :
90 // - for cylinders we want to radially hit the layer
91 // - for disks we want to move along z
92 mDirection = Amg::Vector3D(
93 (sLayer->surfaceRepresentation().type() ==
95 ? Amg::Vector3D(vertex.x(), vertex.y(), 0.)
96 : Amg::Vector3D(0., 0., 1.))
97 .unit();
98 // now intersect the layer
99 Intersection sIntersection = sLayer->surfaceRepresentation().straightLineIntersection(vertex,mDirection,false,false);
100 // check if valid
101 if (sIntersection.valid){
102 // record the new closest distance and remember the layer
103 double currentDistance = fabs(sIntersection.pathLength);
104 if ( currentDistance < mDistance ){
105 // assign the new closest distance
106 mDistance = currentDistance;
107 mLayer = sLayer;
108 mPosition = sIntersection.position;
109 }
110 }
111 } // loop over layers done
112
113 // continue if you have found a good layer
114 if (mLayer) {
115 // let's find the assoicated surfaces using the overlap descriptor
116 std::vector<SurfaceIntersection> testSurfaces;
117 // get the main target surface
118 const Surface* mSurface = mLayer->subSurface(mPosition);
119 // we have more than one test surface
120 if (mSurface && mLayer->overlapDescriptor()){
121 // get the reachable surfaces, the target surface will be added
122 mLayer->overlapDescriptor()->reachableSurfaces(testSurfaces, *mSurface, vertex, mDirection);
123 // let's loop over the provided surfaces, intersect them and take the closest
124 mDistance = 10e10;
125 for (auto& tSurface : testSurfaces){
126 // intersect
127 Intersection tsfInter = tSurface.object->straightLineIntersection(vertex,mDirection,false,false);
128 // check if the intersection is valid and the maxPathLength has not been exceeded
129 if (tsfInter.valid && tsfInter.pathLength < mDistance ){
130 // change the mDistance and remember the surface
131 mDistance = tsfInter.pathLength;
132 mSurface = tSurface.object;
133 }
134 }
135 }
136 // now collect all the other surfaces from the compatible surface call
137 if (mSurface){
138 // we have a surface, do the final transformation into the surface frame
139 Amg::Vector3D mLocPosition = mSurface->transform().inverse()*vertex;
140 // everything is set -> return
141 return Trk::MappedVertex(mLocPosition,*mSurface,*mLayer,*mVolume);
142 }
143 }
144 }
145 }
146 }
147 // did not succeed return an invalid solution
148 return {};
149}
150
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
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
const OverlapDescriptor * overlapDescriptor() const
gettint hte overlap descriptor
const Surface * subSurface(const Amg::Vector3D &gp) const
If no subSurface array is defined or no subSurface can be found to the given Amg::Vector3D,...
Definition Layer.cxx:107
virtual bool reachableSurfaces(std::vector< SurfaceIntersection > &cSurfaces, const Trk::Surface &sf, const Amg::Vector3D &pos, const Amg::Vector3D &dir) const =0
get the compatible surfaces
Abstract Base Class for tracking surfaces.
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Full Volume description used in Tracking, it inherits from Volume to get the geometrical structure,...
const LayerArray * confinedLayers() const
Return the subLayer array.
StatusCode initialize()
AlgTool initialize method.
const TrackingGeometry & trackingGeometry() const
retrieve the tracking geometry
std::string m_trackingGeometryName
Name of the TrackingGeometry as given in Detector Store.
MappedVertex mapToLocal(const Amg::Vector3D &vertex) const
Record the vertex into the local frame of the closest module.
StatusCode finalize()
AlgTool finalize method.
const TrackingGeometry * m_trackingGeometry
the tracking geometry owned by the navigator
VertexMapper(const std::string &, const std::string &, const IInterface *)
AlgTool like constructor.
StatusCode updateTrackingGeometry() const
< retrieve TrackingGeometry
virtual ~VertexMapper()
Virtual destructor.
Eigen::Matrix< double, 3, 1 > Vector3D
BinnedArray< Layer > LayerArray
simply for the eye
Amg::Vector3D position