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