1#include "Tracking/Sim/TrackingUtils.h"
3#include "Acts/Definitions/Units.hpp"
4#include "Acts/Surfaces/Surface.hpp"
6#include "Tracking/Sim/IndexSourceLink.h"
17 auto subdet = tid.subdet();
21 int vol = (subdet == ldmx::SD_TRACKER_RECOIL ||
22 subdet == ldmx::SD_TRACKER_TESTSTAND)
26 unsigned int sensor_id = 0;
27 unsigned int layer_id = 0;
42 if (subdet == ldmx::SD_TRACKER_TESTSTAND) {
69 unsigned int index = vol * 1000 + layer_id * 100 + sensor_id;
72 std::cout <<
"LdmxSpacePointConverter::Check index::" << vol <<
"--"
73 << layer_id <<
"--" << sensor_id <<
"==>" << index << std::endl;
90 unsigned int index = getSensorID(hit);
98 index, hit.
getEdep(), sigma_u * sigma_u,
99 sigma_v * sigma_v, hit.
getID());
102void flatCov(Acts::BoundMatrix cov, std::vector<double>& v_cov) {
104 v_cov.reserve(cov.rows() * (cov.rows() + 1) / 2);
105 for (
int i = 0; i < cov.rows(); i++)
106 for (
int j = i; j < cov.cols(); j++) v_cov.push_back(cov(i, j));
109Acts::BoundMatrix unpackCov(
const std::vector<double>& v_cov) {
110 Acts::BoundMatrix cov;
112 for (
int i = 0; i < cov.rows(); i++)
113 for (
int j = i; j < cov.cols(); j++) {
114 cov(i, j) = v_cov.at(e);
115 cov(j, i) = cov(i, j);
125Acts::SquareMatrix3 ldmx2ActsRotation() {
126 Acts::SquareMatrix3 r;
127 r << 0., 0., 1., 1., 0., 0., 0., 1., 0.;
131Acts::Vector3 ldmx2Acts(Acts::Vector3 ldmx_v) {
132 return ldmx2ActsRotation() * ldmx_v;
137Acts::SquareMatrix3 acts2LdmxRotation() {
138 return ldmx2ActsRotation().transpose();
141Acts::Vector3 acts2Ldmx(Acts::Vector3 acts_v) {
142 return acts2LdmxRotation() * acts_v;
146Acts::FreeVector toFreeParameters(Acts::Vector3 pos_, Acts::Vector3 mom,
148 Acts::FreeVector free_params;
149 double p = mom.norm() * Acts::UnitConstants::MeV;
151 free_params[Acts::eFreePos0] = pos_(Acts::ePos0) * Acts::UnitConstants::mm;
152 free_params[Acts::eFreePos1] = pos_(Acts::ePos1) * Acts::UnitConstants::mm;
153 free_params[Acts::eFreePos2] = pos_(Acts::ePos2) * Acts::UnitConstants::mm;
154 free_params[Acts::eFreeTime] = 0.;
155 free_params[Acts::eFreeDir0] = mom(0) / mom.norm();
156 free_params[Acts::eFreeDir1] = mom(1) / mom.norm();
157 free_params[Acts::eFreeDir2] = mom(2) / mom.norm();
158 free_params[Acts::eFreeQOverP] =
159 (q != double(0)) ? (q / p) : 0.;
166std::vector<double> convertActsToLdmxPars(Acts::BoundVector acts_par) {
167 std::vector<double> v_ldmx(
168 acts_par.data(), acts_par.data() + acts_par.rows() * acts_par.cols());
172Acts::BoundVector boundState(
const ldmx::Track& trk) {
173 Acts::BoundVector param_vec;
174 param_vec << trk.getD0(), trk.getZ0(), trk.getPhi(), trk.getTheta(),
175 trk.getQoP(), trk.getT();
179Acts::BoundTrackParameters boundTrackParameters(
180 const ldmx::Track& trk, std::shared_ptr<Acts::PerigeeSurface> perigee) {
181 Acts::BoundVector param_vec = boundState(trk);
182 Acts::BoundMatrix cov_mat = unpackCov(trk.getPerigeeCov());
183 auto part_hypo{Acts::ParticleHypothesis::electron()};
184 return Acts::BoundTrackParameters(perigee, param_vec, std::move(cov_mat),
189const std::shared_ptr<Acts::PlaneSurface> unboundSurface(
double xloc,
198 Acts::RotationMatrix3 surf_rotation = Acts::RotationMatrix3::Zero();
200 surf_rotation(1, 0) = 1;
202 surf_rotation(2, 1) = 1;
204 surf_rotation(0, 2) = 1;
206 Acts::Vector3 pos(xloc, yloc, zloc);
207 Acts::Translation3 surf_translation(pos);
208 Acts::Transform3 surf_transform(surf_translation * surf_rotation);
211 const std::shared_ptr<Acts::PlaneSurface> target_surface =
212 Acts::Surface::makeShared<Acts::PlaneSurface>(surf_transform);
214 return Acts::Surface::makeShared<Acts::PlaneSurface>(surf_transform);
218std::size_t sourceLinkHash(
const Acts::SourceLink& a) {
219 return static_cast<std::size_t
>(
224bool sourceLinkEquality(
const Acts::SourceLink& a,
const Acts::SourceLink& b) {
242 const Acts::GeometryContext& gctx,
243 const Acts::BoundTrackParameters& bound_pars,
244 ldmx::TrackStateType ts_type) {
246 new_ts.ts_type_ = ts_type;
248 const double p = bound_pars.absoluteMomentum();
249 const Acts::Vector3 acts_pos = bound_pars.position(gctx);
250 const Acts::Vector3 acts_dir = bound_pars.direction();
253 const Acts::SquareMatrix3 r = acts2LdmxRotation();
254 const Acts::Vector3 ldmx_pos = r * acts_pos;
255 const Acts::Vector3 ldmx_mom = r * (acts_dir * p);
257 new_ts.pos_ = {ldmx_pos[0], ldmx_pos[1], ldmx_pos[2]};
259 new_ts.mom_ = {ldmx_mom[0] / Acts::UnitConstants::MeV,
260 ldmx_mom[1] / Acts::UnitConstants::MeV,
261 ldmx_mom[2] / Acts::UnitConstants::MeV};
263 const auto& bound_cov = bound_pars.covariance();
264 if (!bound_cov.has_value()) {
265 std::cerr <<
"TrackingUtils::makeTrackState: bound covariance missing\n";
270 const Acts::BoundToFreeMatrix j_btf =
271 bound_pars.referenceSurface().boundToFreeJacobian(gctx, acts_pos,
273 const Acts::FreeMatrix free_cov =
274 j_btf * bound_cov.value() * j_btf.transpose();
278 constexpr std::array<int, 7> k_keep = {
279 Acts::eFreePos0, Acts::eFreePos1, Acts::eFreePos2, Acts::eFreeDir0,
280 Acts::eFreeDir1, Acts::eFreeDir2, Acts::eFreeQOverP};
281 Eigen::Matrix<double, 7, 7> free_cov7;
282 for (
int i = 0; i < 7; ++i)
283 for (
int j = 0; j < 7; ++j)
284 free_cov7(i, j) = free_cov(k_keep[i], k_keep[j]);
288 const double qop = bound_pars.parameters()[Acts::eBoundQOverP];
289 Eigen::Matrix<double, 6, 7> j_fp = Eigen::Matrix<double, 6, 7>::Zero();
290 j_fp.block<3, 3>(0, 0) = Eigen::Matrix3d::Identity();
291 j_fp.block<3, 3>(3, 3) = p * Eigen::Matrix3d::Identity();
292 j_fp(3, 6) = -acts_dir[0] * p / qop;
293 j_fp(4, 6) = -acts_dir[1] * p / qop;
294 j_fp(5, 6) = -acts_dir[2] * p / qop;
296 const Eigen::Matrix<double, 6, 6> cov_acts =
297 j_fp * free_cov7 * j_fp.transpose();
300 Eigen::Matrix<double, 6, 6> r_6 = Eigen::Matrix<double, 6, 6>::Zero();
301 r_6.block<3, 3>(0, 0) = r;
302 r_6.block<3, 3>(3, 3) = r;
303 const Eigen::Matrix<double, 6, 6> cov_ldmx = r_6 * cov_acts * r_6.transpose();
310 const double mev = Acts::UnitConstants::MeV;
311 new_ts.pos_mom_cov_.reserve(21);
312 for (
int i = 0; i < 6; ++i) {
313 for (
int j = i; j < 6; ++j) {
315 if (i >= 3) scale /= mev;
316 if (j >= 3) scale /= mev;
317 new_ts.pos_mom_cov_.push_back(cov_ldmx(i, j) * scale);
Class that defines a Tracker detector ID with a module number.
A source link that stores just an index_.
constexpr Index index() const
Access the index_.
Represents a simulated tracker hit in the simulation.
int getModuleID() const
Get the module ID associated with a hit.
float getEdep() const
Get the energy deposited on the hit [MeV].
std::vector< float > getPosition() const
Get the XYZ position of the hit [mm].
int getID() const
Get the detector ID of the hit.
float getTime() const
Get the global time of the hit [ns].
int getLayerID() const
Get the geometric layer ID of the hit.
Implementation of a track object.
Extension of DetectorID providing access to layer and module number for tracker IDs.
The measurement calibrator can be a function or a class/struct able to retrieve the sim hits containe...