LDMX Software
MeasurementCalibrator.h
1#ifndef LDMXMEASUREMENTCALIBRATOR_H_
2#define LDMXMEASUREMENTCALIBRATOR_H_
3
4#include <vector>
5
6#include "Acts/Definitions/Algebra.hpp"
7#include "Acts/Definitions/TrackParametrization.hpp"
8#include "Acts/EventData/SourceLink.hpp"
9#include "Acts/Utilities/CalibrationContext.hpp"
10#include "Tracking/Event/Measurement.h"
11#include "Tracking/Sim/IndexSourceLink.h"
12
35
36namespace tracking {
37namespace sim {
38
40 public:
43
44 // The calibrator needs to access the sim hit container
46 const std::vector<ldmx::Measurement>& measurements) {
47 m_measurements_ = &measurements;
48 }
49
56 template <typename traj_t>
57 void calibrate(const Acts::GeometryContext& /*gctx*/,
58 const Acts::CalibrationContext& /*cctx*/,
59 const Acts::SourceLink& genericSourceLink /*sourceLink*/,
60 typename traj_t::TrackStateProxy trackState) const {
62 genericSourceLink.get<acts_examples::IndexSourceLink>()};
63 assert(m_measurements_ and
64 "Undefined measurement container in LdmxMeasurementCalibrator");
65 assert((source_link.index() < m_measurements_->size()) and
66 "Source link index is outside the container bounds in "
67 "LdmxMeasurementCalibrator");
68
69 auto meas = m_measurements_->at(source_link.index());
70 Acts::Vector2 local_pos{meas.getLocalPosition()[0],
71 meas.getLocalPosition()[1]};
72 trackState.allocateCalibrated(2);
73 auto ts_cal{trackState.template calibrated<2>()};
74 auto ts_cal_cov{trackState.template calibratedCovariance<2>()};
75 ts_cal.setZero();
76 ts_cal.template head<2>() = local_pos;
77 Acts::SquareMatrix2 local_cov;
78 local_cov.setZero();
79 local_cov(0, 0) = meas.getLocalCovariance()[0];
80 local_cov(1, 1) = meas.getLocalCovariance()[1];
81 ts_cal_cov.setZero();
82 // make tsCalCov 2x2 block the local_cov we just set
83 ts_cal_cov.block(0, 0, 2, 2) = local_cov;
84
85 trackState.setProjectorSubspaceIndices(
86 std::array<Acts::BoundIndices, 2>{Acts::eBoundLoc0, Acts::eBoundLoc1});
87 trackState.setUncalibratedSourceLink(Acts::SourceLink{genericSourceLink});
88 }
89
96 template <typename traj_t>
97 void calibrate1d(const Acts::GeometryContext& /*gctx*/,
98 const Acts::CalibrationContext& /*cctx*/,
99 const Acts::SourceLink& genericSourceLink /*sourceLink*/,
100 typename traj_t::TrackStateProxy trackState) const {
102 genericSourceLink.get<acts_examples::IndexSourceLink>()};
103
104 assert(m_measurements_ and
105 "Undefined measurement container in LdmxMeasurementCalibrator");
106 assert((source_link.index() < m_measurements_->size()) and
107 "Source link index is outside the container bounds in "
108 "LdmxMeasurementCalibrator");
109
110 auto meas = m_measurements_->at(source_link.index());
111
112 trackState.allocateCalibrated(1);
113 auto ts_cal{trackState.template calibrated<1>()};
114 auto ts_cal_cov{trackState.template calibratedCovariance<1>()};
115
116 ts_cal.setZero();
117 ts_cal(0) = (meas.getLocalPosition())[0];
118 ts_cal_cov.setZero();
119 ts_cal_cov(0, 0) = (meas.getLocalCovariance())[0];
120
121 trackState.setProjectorSubspaceIndices(
122 std::array<Acts::BoundIndices, 1>{Acts::eBoundLoc0});
123 trackState.setUncalibratedSourceLink(Acts::SourceLink{genericSourceLink});
124 }
125
126 // Function to test the measurement calibrator
127 // It takes an user defined source link and returns the information of the
128 // linked measurement
129 void test(const Acts::GeometryContext& /*gctx*/,
130 const acts_examples::IndexSourceLink& sourceLink) const {
131 auto meas = m_measurements_->at(sourceLink.index());
132
133 Acts::Vector3 global_pos{meas.getGlobalPosition()[0],
134 meas.getGlobalPosition()[1],
135 meas.getGlobalPosition()[2]};
136 std::cout << "Measurement global_position::\n" << global_pos << std::endl;
137
138 Acts::Vector2 local_pos{meas.getLocalPosition()[0],
139 meas.getLocalPosition()[1]};
140 std::cout << "Measurement local_position::\n" << local_pos << std::endl;
141 }
142
143 private:
144 // use pointer so the calibrator is copyable and default constructible.
145 const std::vector<ldmx::Measurement>* m_measurements_ = nullptr;
146};
147
148} // namespace sim
149} // namespace tracking
150
151#endif
void calibrate1d(const Acts::GeometryContext &, const Acts::CalibrationContext &, const Acts::SourceLink &genericSourceLink, typename traj_t::TrackStateProxy trackState) const
Find the measurement corresponding to the source link.
void calibrate(const Acts::GeometryContext &, const Acts::CalibrationContext &, const Acts::SourceLink &genericSourceLink, typename traj_t::TrackStateProxy trackState) const
Find the measurement corresponding to the source link.
LdmxMeasurementCalibrator()=default
Construct an invalid calibrator. Required to allow copying.
The measurement calibrator can be a function or a class/struct able to retrieve the sim hits containe...