1#include "Tracking/Sim/TrackingUtils.h"
14 int vol = (tid.subdet() == ldmx::SD_TRACKER_RECOIL) ? 3 : 2;
16 unsigned int sensor_id = 0;
17 unsigned int layer_id = 0;
46 unsigned int index = vol * 1000 + layer_id * 100 + sensor_id;
49 std::cout <<
"LdmxSpacePointConverter::Check index::" << vol <<
"--"
50 << layer_id <<
"--" << sensor_id <<
"==>" << index << std::endl;
67 unsigned int index = getSensorID(hit);
75 index, hit.
getEdep(), sigma_u * sigma_u,
76 sigma_v * sigma_v, hit.
getID());
79void flatCov(Acts::BoundSquareMatrix cov, std::vector<double>& v_cov) {
81 v_cov.reserve(cov.rows() * (cov.rows() + 1) / 2);
82 for (
int i = 0; i < cov.rows(); i++)
83 for (
int j = i; j < cov.cols(); j++) v_cov.push_back(cov(i, j));
86Acts::BoundSquareMatrix unpackCov(
const std::vector<double>& v_cov) {
87 Acts::BoundSquareMatrix cov;
89 for (
int i = 0; i < cov.rows(); i++)
90 for (
int j = i; j < cov.cols(); j++) {
91 cov(i, j) = v_cov.at(e);
92 cov(j, i) = cov(i, j);
102Acts::SquareMatrix3 ldmx2ActsRotation() {
103 Acts::SquareMatrix3 r;
104 r << 0., 0., 1., 1., 0., 0., 0., 1., 0.;
108Acts::Vector3 ldmx2Acts(Acts::Vector3 ldmx_v) {
109 return ldmx2ActsRotation() * ldmx_v;
114Acts::SquareMatrix3 acts2LdmxRotation() {
115 return ldmx2ActsRotation().transpose();
118Acts::Vector3 acts2Ldmx(Acts::Vector3 acts_v) {
119 return acts2LdmxRotation() * acts_v;
123Acts::FreeVector toFreeParameters(Acts::Vector3 pos_, Acts::Vector3 mom,
124 Acts::ActsScalar q) {
125 Acts::FreeVector free_params;
126 Acts::ActsScalar p = mom.norm() * Acts::UnitConstants::MeV;
128 free_params[Acts::eFreePos0] = pos_(Acts::ePos0) * Acts::UnitConstants::mm;
129 free_params[Acts::eFreePos1] = pos_(Acts::ePos1) * Acts::UnitConstants::mm;
130 free_params[Acts::eFreePos2] = pos_(Acts::ePos2) * Acts::UnitConstants::mm;
131 free_params[Acts::eFreeTime] = 0.;
132 free_params[Acts::eFreeDir0] = mom(0) / mom.norm();
133 free_params[Acts::eFreeDir1] = mom(1) / mom.norm();
134 free_params[Acts::eFreeDir2] = mom(2) / mom.norm();
135 free_params[Acts::eFreeQOverP] =
136 (q != Acts::ActsScalar(0)) ? (q / p) : 0.;
143std::vector<double> convertActsToLdmxPars(Acts::BoundVector acts_par) {
144 std::vector<double> v_ldmx(
145 acts_par.data(), acts_par.data() + acts_par.rows() * acts_par.cols());
149Acts::BoundVector boundState(
const ldmx::Track& trk) {
150 Acts::BoundVector param_vec;
151 param_vec << trk.getD0(), trk.getZ0(), trk.getPhi(), trk.getTheta(),
152 trk.getQoP(), trk.getT();
156Acts::BoundTrackParameters boundTrackParameters(
157 const ldmx::Track& trk, std::shared_ptr<Acts::PerigeeSurface> perigee) {
158 Acts::BoundVector param_vec = boundState(trk);
159 Acts::BoundSquareMatrix cov_mat = unpackCov(trk.getPerigeeCov());
160 auto part_hypo{Acts::SinglyChargedParticleHypothesis::electron()};
161 return Acts::BoundTrackParameters(perigee, param_vec, std::move(cov_mat),
166const std::shared_ptr<Acts::PlaneSurface> unboundSurface(
double xloc,
175 Acts::RotationMatrix3 surf_rotation = Acts::RotationMatrix3::Zero();
177 surf_rotation(1, 0) = 1;
179 surf_rotation(2, 1) = 1;
181 surf_rotation(0, 2) = 1;
183 Acts::Vector3 pos(xloc, yloc, zloc);
184 Acts::Translation3 surf_translation(pos);
185 Acts::Transform3 surf_transform(surf_translation * surf_rotation);
188 const std::shared_ptr<Acts::PlaneSurface> target_surface =
189 Acts::Surface::makeShared<Acts::PlaneSurface>(surf_transform);
191 return Acts::Surface::makeShared<Acts::PlaneSurface>(surf_transform);
195std::size_t sourceLinkHash(
const Acts::SourceLink& a) {
196 return static_cast<std::size_t
>(
201bool sourceLinkEquality(
const Acts::SourceLink& a,
const Acts::SourceLink& b) {
219 const Acts::GeometryContext& gctx,
220 const Acts::BoundTrackParameters& bound_pars,
221 ldmx::TrackStateType ts_type) {
223 new_ts.ts_type_ = ts_type;
225 const double p = bound_pars.absoluteMomentum();
226 const Acts::Vector3 acts_pos = bound_pars.position(gctx);
227 const Acts::Vector3 acts_dir = bound_pars.direction();
230 const Acts::SquareMatrix3 r = acts2LdmxRotation();
231 const Acts::Vector3 ldmx_pos = r * acts_pos;
232 const Acts::Vector3 ldmx_mom = r * (acts_dir * p);
234 new_ts.pos_ = {ldmx_pos[0], ldmx_pos[1], ldmx_pos[2]};
236 new_ts.mom_ = {ldmx_mom[0] / Acts::UnitConstants::MeV,
237 ldmx_mom[1] / Acts::UnitConstants::MeV,
238 ldmx_mom[2] / Acts::UnitConstants::MeV};
240 const auto& bound_cov = bound_pars.covariance();
241 if (!bound_cov.has_value()) {
242 std::cerr <<
"TrackingUtils::makeTrackState: bound covariance missing\n";
247 const Acts::BoundToFreeMatrix j_btf =
248 bound_pars.referenceSurface().boundToFreeJacobian(gctx, acts_pos,
250 const Acts::FreeSquareMatrix free_cov =
251 j_btf * bound_cov.value() * j_btf.transpose();
255 constexpr std::array<int, 7> k_keep = {
256 Acts::eFreePos0, Acts::eFreePos1, Acts::eFreePos2, Acts::eFreeDir0,
257 Acts::eFreeDir1, Acts::eFreeDir2, Acts::eFreeQOverP};
258 Eigen::Matrix<double, 7, 7> free_cov7;
259 for (
int i = 0; i < 7; ++i)
260 for (
int j = 0; j < 7; ++j)
261 free_cov7(i, j) = free_cov(k_keep[i], k_keep[j]);
265 const double qop = bound_pars.parameters()[Acts::eBoundQOverP];
266 Eigen::Matrix<double, 6, 7> j_fp = Eigen::Matrix<double, 6, 7>::Zero();
267 j_fp.block<3, 3>(0, 0) = Eigen::Matrix3d::Identity();
268 j_fp.block<3, 3>(3, 3) = p * Eigen::Matrix3d::Identity();
269 j_fp(3, 6) = -acts_dir[0] * p / qop;
270 j_fp(4, 6) = -acts_dir[1] * p / qop;
271 j_fp(5, 6) = -acts_dir[2] * p / qop;
273 const Eigen::Matrix<double, 6, 6> cov_acts =
274 j_fp * free_cov7 * j_fp.transpose();
277 Eigen::Matrix<double, 6, 6> r_6 = Eigen::Matrix<double, 6, 6>::Zero();
278 r_6.block<3, 3>(0, 0) = r;
279 r_6.block<3, 3>(3, 3) = r;
280 const Eigen::Matrix<double, 6, 6> cov_ldmx = r_6 * cov_acts * r_6.transpose();
287 const double mev = Acts::UnitConstants::MeV;
288 new_ts.pos_mom_cov_.reserve(21);
289 for (
int i = 0; i < 6; ++i) {
290 for (
int j = i; j < 6; ++j) {
292 if (i >= 3) scale /= mev;
293 if (j >= 3) scale /= mev;
294 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...