ATLAS Offline Software
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
16 Trk::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  Trk::BinnedArraySpan<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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
Trk::Intersection
Definition: Intersection.h:24
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::VertexMapper::finalize
StatusCode finalize()
AlgTool finalize method.
Definition: VertexMapper.cxx:43
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::Intersection::pathLength
double pathLength
Definition: Intersection.h:26
Trk::MappedVertex
Definition: IVertexMapper.h:23
Trk::Layer::overlapDescriptor
const OverlapDescriptor * overlapDescriptor() const
gettint hte overlap descriptor
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Trk::OverlapDescriptor::reachableSurfaces
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
Trk::VertexMapper::updateTrackingGeometry
StatusCode updateTrackingGeometry() const
< retrieve TrackingGeometry
Definition: VertexMapper.cxx:50
Trk::VertexMapper::initialize
StatusCode initialize()
AlgTool initialize method.
Definition: VertexMapper.cxx:35
Trk::TrackingVolume::confinedLayers
const LayerArray * confinedLayers() const
Return the subLayer array.
Trk::Layer::subSurface
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:121
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
VertexMapper.h
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::Intersection::position
Amg::Vector3D position
Definition: Intersection.h:25
Trk::VertexMapper::mapToLocal
MappedVertex mapToLocal(const Amg::Vector3D &vertex) const
Record the vertex into the local frame of the closest module
Definition: VertexMapper.cxx:60
Trk::VertexMapper::m_trackingGeometryName
std::string m_trackingGeometryName
Name of the TrackingGeometry as given in Detector Store.
Definition: VertexMapper.h:75
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
Trk::VertexMapper::~VertexMapper
virtual ~VertexMapper()
Virtual destructor.
Trk::BinnedArray::arrayObjects
virtual BinnedArraySpan< T *const > arrayObjects()=0
Return all objects of the Array non-const we can still modify the T.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::VertexMapper::VertexMapper
VertexMapper(const std::string &, const std::string &, const IInterface *)
AlgTool like constructor.
Definition: VertexMapper.cxx:16
Trk::Intersection::valid
bool valid
Definition: Intersection.h:28
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
TrackingVolume.h
Trk::SurfaceType::Cylinder
@ Cylinder
TrackingGeometry.h
Trk::BinnedArray
Definition: BinnedArray.h:38
AthAlgTool
Definition: AthAlgTool.h:26
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::TrackingVolume
Definition: TrackingVolume.h:121
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Trk::BinnedArraySpan
std::span< T > BinnedArraySpan
Definition: BinnedArray.h:34
Trk::Layer
Definition: Layer.h:73