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/MultiTrajectory.hpp"
9#include "Acts/EventData/SourceLink.hpp"
10#include "Acts/EventData/VectorMultiTrajectory.hpp"
11#include "Acts/Utilities/CalibrationContext.hpp"
12#include "Tracking/Event/Measurement.h"
13#include "Tracking/Sim/IndexSourceLink.h"
14#include "Tracking/Sim/LdmxSpacePoint.h"
15
38
39namespace tracking {
40namespace sim {
41
43 public:
46
47 // The calibrator needs to access the sim hit container
49 const std::vector<ldmx::Measurement>& measurements) {
50 m_measurements_ = &measurements;
51 }
52
59 template <typename traj_t>
60 void calibrate(const Acts::GeometryContext& /*gctx*/,
61 const Acts::CalibrationContext& /*cctx*/,
62 const Acts::SourceLink& genericSourceLink /*sourceLink*/,
63 typename traj_t::TrackStateProxy trackState) const {
65 genericSourceLink.get<acts_examples::IndexSourceLink>()};
66 assert(m_measurements_ and
67 "Undefined measurement container in LdmxMeasurementCalibrator");
68 assert((source_link.index() < m_measurements_->size()) and
69 "Source link index is outside the container bounds in "
70 "LdmxMeasurementCalibrator");
71
72 auto meas = m_measurements_->at(source_link.index());
73 Acts::Vector2 local_pos{meas.getLocalPosition()[0],
74 meas.getLocalPosition()[1]};
75 trackState.allocateCalibrated(2);
76 auto ts_cal{trackState.template calibrated<2>()};
77 auto ts_cal_cov{trackState.template calibratedCovariance<2>()};
78 ts_cal.setZero();
79 ts_cal.template head<2>() = local_pos;
80 Acts::SquareMatrix2 local_cov;
81 local_cov.setZero();
82 local_cov(0, 0) = meas.getLocalCovariance()[0];
83 local_cov(1, 1) = meas.getLocalCovariance()[1];
84 ts_cal_cov.setZero();
85 // make tsCalCov 2x2 block the local_cov we just set
86 ts_cal_cov.block(0, 0, 2, 2) = local_cov;
87
88 trackState.setProjectorSubspaceIndices(
89 std::array<Acts::BoundIndices, 2>{Acts::eBoundLoc0, Acts::eBoundLoc1});
90 trackState.setUncalibratedSourceLink(Acts::SourceLink{genericSourceLink});
91 }
92
99 template <typename traj_t>
100 void calibrate1d(const Acts::GeometryContext& /*gctx*/,
101 const Acts::CalibrationContext& /*cctx*/,
102 const Acts::SourceLink& genericSourceLink /*sourceLink*/,
103 typename traj_t::TrackStateProxy trackState) const {
105 genericSourceLink.get<acts_examples::IndexSourceLink>()};
106
107 assert(m_measurements_ and
108 "Undefined measurement container in LdmxMeasurementCalibrator");
109 assert((source_link.index() < m_measurements_->size()) and
110 "Source link index is outside the container bounds in "
111 "LdmxMeasurementCalibrator");
112
113 auto meas = m_measurements_->at(source_link.index());
114
115 trackState.allocateCalibrated(1);
116 auto ts_cal{trackState.template calibrated<1>()};
117 auto ts_cal_cov{trackState.template calibratedCovariance<1>()};
118
119 ts_cal.setZero();
120 ts_cal(0) = (meas.getLocalPosition())[0];
121 ts_cal_cov.setZero();
122 ts_cal_cov(0, 0) = (meas.getLocalCovariance())[0];
123
124 trackState.setProjectorSubspaceIndices(
125 std::array<Acts::BoundIndices, 1>{Acts::eBoundLoc0});
126 trackState.setUncalibratedSourceLink(Acts::SourceLink{genericSourceLink});
127 }
128
129 // Function to test the measurement calibrator
130 // It takes an user defined source link and returns the information of the
131 // linked measurement
132 void test(const Acts::GeometryContext& /*gctx*/,
133 const acts_examples::IndexSourceLink& sourceLink) const {
134 auto meas = m_measurements_->at(sourceLink.index());
135
136 Acts::Vector3 global_pos{meas.getGlobalPosition()[0],
137 meas.getGlobalPosition()[1],
138 meas.getGlobalPosition()[2]};
139 std::cout << "Measurement global_position::\n" << global_pos << std::endl;
140
141 Acts::Vector2 local_pos{meas.getLocalPosition()[0],
142 meas.getLocalPosition()[1]};
143 std::cout << "Measurement local_position::\n" << local_pos << std::endl;
144 }
145
146 private:
147 // use pointer so the calibrator is copyable and default constructible.
148 const std::vector<ldmx::Measurement>* m_measurements_ = nullptr;
149};
150
151} // namespace sim
152} // namespace tracking
153
154#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...