ATLAS Offline Software
Loading...
Searching...
No Matches
PixelClusterCalibrationToolBase.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include <limits>
5#include "ActsGeometry/ActsDetectorElement.h"
6#include <PixelReadoutGeometry/PixelModuleDesign.h>
7#include "InDetReadoutGeometry/SiDetectorElement.h"
8#include "InDetMeasurementUtilities/Helpers.h"
9
10#include <stdexcept>
11
12namespace ActsTrk::detail {
13
14template <typename traj_t>
15const InDetDD::SiDetectorElement&
16PixelClusterCalibratorCommon<traj_t>::getDetectorElement(const Acts::Surface &surface) const
17{
18 const ActsDetectorElement* detElem = dynamic_cast<const ActsDetectorElement*>(surface.surfacePlacement());
19 const InDetDD::SiDetectorElement *
20 siDetElement = detElem ? dynamic_cast<const InDetDD::SiDetectorElement *>(detElem->upstreamDetectorElement())
21 : nullptr;
22 if (!siDetElement) {
23 throw std::runtime_error("SiDetectorElement is NULL");
24 }
25 return *siDetElement;
26}
27
28template <typename traj_t>
29std::pair<float, float>
30PixelClusterCalibratorCommon<traj_t>::tanAnglesOfIncidence(const EventContext &ctx,
31 const Acts::GeometryContext& gctx,
32 const Acts::Surface &surface,
33 const InDetDD::SiDetectorElement& element,
34 const Acts::Vector3& direction) const
35{
36 // to ensure that referenceFrame can be called with dummy direction and position
37 assert(dynamic_cast<const Acts::PlaneSurface *>(&surface) != nullptr);
38 static const Acts::Vector3 dummy=Acts::Vector3::Zero();
39 Acts::Vector3 projection = surface.referenceFrame(gctx, dummy,dummy).transpose() * direction;
40#ifndef NDEBUG
41 float projPhi = direction.dot(element.phiAxis());
42 float projEta = direction.dot(element.etaAxis());
43 float projNorm = direction.dot(element.normal());
44 assert( std::abs(projection[0] - projPhi) < std::abs(projPhi) * std::numeric_limits<float>::epsilon() *2.);
45 assert( std::abs(projection[1] - projEta) < std::abs(projEta) * std::numeric_limits<float>::epsilon() *2.);
46 assert( std::abs(projection[2] - projNorm) < std::abs(projNorm) * std::numeric_limits<float>::epsilon() *2.);
47#endif
48
49 double inv_proj_norm = 1./projection[2];
50 double tan_phi = projection[0]*inv_proj_norm;
51 double tan_theta = projection[1]*inv_proj_norm;
52
53 // Subtract the Lorentz angle effect
54 double angleShift = m_baseOptions.m_lorentzAngleTool->getTanLorentzAngle(element.identifyHash(), ctx);
55 tan_phi -= element.design().readoutSide() * angleShift;
56
57 return std::make_pair(static_cast<float>(tan_phi), static_cast<float>(tan_theta));
58}
59
60template <typename derived_t, typename traj_t>
61std::pair<typename PixelClusterCalibratorCommon<traj_t>::Pos,
62 typename PixelClusterCalibratorCommon<traj_t>::Cov>
63PixelClusterCalibratorBase<derived_t, traj_t>::calibrate(
64 const Acts::GeometryContext& gctx,
65 const Acts::CalibrationContext& cctx,
66 const xAOD::PixelCluster& cluster,
67 const typename PixelClusterCalibratorBase<derived_t, traj_t>::TrackStateProxy& state) const
68{
69 const EventContext& ctx = *cctx.get<const EventContext*>();
70 const InDetDD::SiDetectorElement &detElement = this->getDetectorElement(state.referenceSurface());
71 Acts::Vector3 direction = Acts::makeDirectionFromPhiTheta(state.parameters()[Acts::eBoundPhi],
72 state.parameters()[Acts::eBoundTheta]);
73 return derived().calibrate(ctx, gctx, cctx, cluster, detElement, this->tanAnglesOfIncidence(ctx,
74 gctx,
75 state.referenceSurface(),
76 detElement,
77 direction));
78}
79
80template <typename derived_t, typename traj_t>
81std::pair<typename PixelClusterCalibratorCommon<traj_t>::Pos,
82 typename PixelClusterCalibratorCommon<traj_t>::Cov>
83PixelClusterCalibratorBase<derived_t, traj_t>::calibrate(const Acts::GeometryContext& gctx,
84 const Acts::CalibrationContext& cctx,
85 const Acts::Surface& surface,
86 const xAOD::PixelCluster& cluster,
87 const Acts::BoundTrackParameters& bound_parameters) const
88{
89 const EventContext& ctx = *cctx.get<const EventContext*>();
90 const InDetDD::SiDetectorElement &detElement = this->getDetectorElement(surface);
91 Acts::Vector3 direction = Acts::makeDirectionFromPhiTheta(bound_parameters.parameters()[Acts::eBoundPhi],
92 bound_parameters.parameters()[Acts::eBoundTheta]);
93 return this->derived().calibrate(ctx, gctx, cctx, cluster, detElement, this->tanAnglesOfIncidence(ctx,
94 gctx,
95 surface,
96 detElement,
97 direction));
98}
99
100
101template <typename derived_t, typename traj_t>
102void
103PixelClusterCalibratorBase<derived_t, traj_t>
104 ::connectOnTrackCalibrator(PixelClusterCalibratorBase<derived_t, traj_t>::OnTrackCalibrator& calibrator) const
105{
106 using CalibFuncPtr_t =
107 std::pair<typename PixelClusterCalibratorCommon<traj_t>::Pos,
108 typename PixelClusterCalibratorCommon<traj_t>::Cov>
109 (PixelClusterCalibratorBase<derived_t, traj_t>:: *)(const Acts::GeometryContext&,
110 const Acts::CalibrationContext&,
111 const xAOD::PixelCluster&,
112 const TrackStateProxy&) const;
113
114 calibrator. template connect<static_cast<CalibFuncPtr_t>(&PixelClusterCalibratorBase<derived_t, traj_t>::calibrate)>(this);
115}
116
117template <typename derived_t, typename traj_t>
118void
119PixelClusterCalibratorBase<derived_t,traj_t>
120 ::connectCalibrator(typename PixelClusterCalibratorBase<derived_t,traj_t>::Calibrator &calibrator) const {
121 using CalibFuncPtr_t =
122 std::pair<typename PixelClusterCalibratorCommon<traj_t>::Pos,
123 typename PixelClusterCalibratorCommon<traj_t>::Cov>
124 (PixelClusterCalibratorBase<derived_t, traj_t>:: *)(const Acts::GeometryContext&,
125 const Acts::CalibrationContext&,
126 const Acts::Surface&,
127 const xAOD::PixelCluster&,
128 const Acts::BoundTrackParameters&) const;
129
130 calibrator.template connect<static_cast<CalibFuncPtr_t>(&PixelClusterCalibratorBase<derived_t, traj_t>::calibrate)>(this);
131}
132
133template <typename traj_t>
134StatusCode PixelClusterCalibrationToolBase<traj_t>::initialize()
135{
136 ATH_CHECK(m_lorentzAngleTool.retrieve());
137 ATH_CHECK(AthAlgTool::detStore()->retrieve(m_pixelID, "PixelID"));
138
139 return StatusCode::SUCCESS;
140}
141
142template <typename traj_t>
143bool PixelClusterCalibrationToolBase<traj_t>::calibrateAfterMeasurementSelection() const
144{ return m_postCalibration.value(); }
145
146} // namespace ActsTrk