LDMX Software
DetectorElement.cxx
1#include "Tracking/geo/DetectorElement.h"
2
3#include <iostream>
4
5#include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
6#include "Framework/Exception/Exception.h"
7#include "Tracking/geo/GeoUtils.h"
8#include "Tracking/geo/GeometryContext.h"
9
10namespace tracking::geo {
11
12DetectorElement::~DetectorElement() {};
13
14const Acts::Transform3& DetectorElement::localToGlobalTransform(
15 const Acts::GeometryContext& gctx) const {
16 if (!m_surface_)
17 EXCEPTION_RAISE("BadGeometry",
18 "DetectorElement:: Sensor/Element ID not set");
19
20 // The elementId will be valid only after tracking geometry is built
21 // I will use this fact to return the default transform in order to build
22 // always the same default tracking geometry and modify later the sensor
23 // transformations.
24
25 unsigned int element_id = unpackGeometryIdentifier(m_surface_->geometryId());
26
27 // Check if the elementId is valid
28 if (element_id > 9999) {
29 // elementId not valid: return default transformation
30 return m_transform_;
31 }
32
33 auto ctx = gctx.get<GeometryContext*>();
34
35 // Found the aligned transform for this sensor
36 if ((ctx->alignment_map_).count(element_id) > 0) {
37 const Acts::Transform3& c_transform = ctx->alignment_map_[element_id];
38
39 if (false) {
40 // TODO : Have this in the logging system
41 std::cout << "Aligned transform" << std::endl;
42 std::cout << c_transform.translation() << std::endl;
43 std::cout << c_transform.rotation() << std::endl;
44 std::cout << "Original transform" << std::endl;
45 std::cout << m_transform_.translation() << std::endl;
46 std::cout << m_transform_.rotation() << std::endl;
47 }
48
49 return c_transform;
50 }
51
52 else
53 return m_transform_;
54}
55
56const Acts::Surface& DetectorElement::surface() const {
57 if (!m_surface_)
58 EXCEPTION_RAISE(
59 "BadGeometry",
60 "DetectorElement::Attempted to return reference of null ptr");
61 return *m_surface_;
62}
63Acts::Surface& DetectorElement::surface() {
64 if (!m_surface_)
65 EXCEPTION_RAISE(
66 "BadGeometry",
67 "DetectorElement::Attempted to return reference of null ptr");
68 return *m_surface_;
69}
70
71// The thickness of the detector element is taken from the center of the
72// associated surface
73double DetectorElement::thickness() const {
74 // return m_thickness;
75 auto material = static_cast<const Acts::HomogeneousSurfaceMaterial*>(
76 m_surface_->surfaceMaterial());
77 return material->materialSlab(Acts::Vector2{0., 0.}).thickness();
78}
79} // namespace tracking::geo
Visualization.
unsigned int unpackGeometryIdentifier(const Acts::GeometryIdentifier &geoId)
The geometry identifier will return vol=0 and lay=0 when it is not valid.
Definition GeoUtils.cxx:5