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