29#include "Tracking/Sim/LdmxSpacePoint.h"
32#include "Tracking/Event/Track.h"
35#include "Acts/Definitions/Algebra.hpp"
36#include "Acts/Definitions/PdgParticle.hpp"
37#include "Acts/Definitions/TrackParametrization.hpp"
38#include "Acts/Definitions/Units.hpp"
39#include "Acts/EventData/TrackParameters.hpp"
40#include "Acts/Surfaces/PerigeeSurface.hpp"
41#include "Acts/Surfaces/PlaneSurface.hpp"
42#include "Acts/Surfaces/Surface.hpp"
43#include "Tracking/Event/Measurement.h"
44#include "Tracking/Sim/IndexSourceLink.h"
78 unsigned int sensor_id = 0;
79 unsigned int layer_id = 0;
108 unsigned int index = vol * 1000 + layer_id * 100 + sensor_id;
111 std::cout <<
"LdmxSpacePointConverter::Check index::" << vol <<
"--"
112 << layer_id <<
"--" << sensor_id <<
"==>" << index << std::endl;
132 double sigma_v = 1.) {
133 unsigned int index = getSensorID(hit);
141 index, hit.
getEdep(), sigma_u * sigma_u,
142 sigma_v * sigma_v, hit.
getID());
148inline void flatCov(Acts::BoundSquareMatrix cov, std::vector<double>& v_cov) {
150 v_cov.reserve(cov.rows() * (cov.rows() + 1) / 2);
151 for (
int i = 0; i < cov.rows(); i++)
152 for (
int j = i; j < cov.cols(); j++) v_cov.push_back(cov(i, j));
155inline Acts::BoundSquareMatrix unpackCov(
const std::vector<double>& v_cov) {
156 Acts::BoundSquareMatrix cov;
158 for (
int i = 0; i < cov.rows(); i++)
159 for (
int j = i; j < cov.cols(); j++) {
160 cov(i, j) = v_cov.at(e);
161 cov(j, i) = cov(i, j);
171inline Acts::SquareMatrix3 ldmx2ActsRotation() {
172 Acts::SquareMatrix3 r;
173 r << 0., 0., 1., 1., 0., 0., 0., 1., 0.;
177inline Acts::Vector3 ldmx2Acts(Acts::Vector3 ldmx_v) {
178 return ldmx2ActsRotation() * ldmx_v;
183inline Acts::SquareMatrix3 acts2LdmxRotation() {
184 return ldmx2ActsRotation().transpose();
187inline Acts::Vector3 acts2Ldmx(Acts::Vector3 acts_v) {
188 return acts2LdmxRotation() * acts_v;
193inline Acts::FreeVector toFreeParameters(Acts::Vector3 pos_, Acts::Vector3 mom,
194 Acts::ActsScalar q) {
195 Acts::FreeVector free_params;
196 Acts::ActsScalar p = mom.norm() * Acts::UnitConstants::MeV;
198 free_params[Acts::eFreePos0] = pos_(Acts::ePos0) * Acts::UnitConstants::mm;
199 free_params[Acts::eFreePos1] = pos_(Acts::ePos1) * Acts::UnitConstants::mm;
200 free_params[Acts::eFreePos2] = pos_(Acts::ePos2) * Acts::UnitConstants::mm;
201 free_params[Acts::eFreeTime] = 0.;
202 free_params[Acts::eFreeDir0] = mom(0) / mom.norm();
203 free_params[Acts::eFreeDir1] = mom(1) / mom.norm();
204 free_params[Acts::eFreeDir2] = mom(2) / mom.norm();
205 free_params[Acts::eFreeQOverP] =
206 (q != Acts::ActsScalar(0)) ? (q / p) : 0.;
214inline std::vector<double> convertActsToLdmxPars(Acts::BoundVector acts_par) {
215 std::vector<double> v_ldmx(
216 acts_par.data(), acts_par.data() + acts_par.rows() * acts_par.cols());
220inline Acts::BoundVector boundState(
const ldmx::Track& trk) {
221 Acts::BoundVector param_vec;
222 param_vec << trk.getD0(), trk.getZ0(), trk.getPhi(), trk.getTheta(),
223 trk.getQoP(), trk.getT();
227inline Acts::BoundTrackParameters boundTrackParameters(
228 const ldmx::Track& trk, std::shared_ptr<Acts::PerigeeSurface> perigee) {
229 Acts::BoundVector param_vec = boundState(trk);
230 Acts::BoundSquareMatrix cov_mat = unpackCov(trk.getPerigeeCov());
231 auto part_hypo{Acts::SinglyChargedParticleHypothesis::electron()};
232 return Acts::BoundTrackParameters(perigee, param_vec, std::move(cov_mat),
237inline const std::shared_ptr<Acts::PlaneSurface> unboundSurface(
238 double xloc,
double yloc = 0.,
double zloc = 0.) {
245 Acts::RotationMatrix3 surf_rotation = Acts::RotationMatrix3::Zero();
247 surf_rotation(1, 0) = 1;
249 surf_rotation(2, 1) = 1;
251 surf_rotation(0, 2) = 1;
253 Acts::Vector3 pos(xloc, yloc, zloc);
254 Acts::Translation3 surf_translation(pos);
255 Acts::Transform3 surf_transform(surf_translation * surf_rotation);
258 const std::shared_ptr<Acts::PlaneSurface> target_surface =
259 Acts::Surface::makeShared<Acts::PlaneSurface>(surf_transform);
261 return Acts::Surface::makeShared<Acts::PlaneSurface>(surf_transform);
265inline std::size_t sourceLinkHash(
const Acts::SourceLink& a) {
266 return static_cast<std::size_t
>(
271inline bool sourceLinkEquality(
const Acts::SourceLink& a,
272 const Acts::SourceLink& b) {
289 const Acts::GeometryContext& gctx,
290 const Acts::BoundTrackParameters& bound_pars,
291 ldmx::TrackStateType ts_type = ldmx::Invalid) {
293 new_ts.ts_type_ = ts_type;
295 const double p = bound_pars.absoluteMomentum();
296 const Acts::Vector3 acts_pos = bound_pars.position(gctx);
297 const Acts::Vector3 acts_dir = bound_pars.direction();
300 const Acts::SquareMatrix3 r = acts2LdmxRotation();
301 const Acts::Vector3 ldmx_pos = r * acts_pos;
302 const Acts::Vector3 ldmx_mom = r * (acts_dir * p);
304 new_ts.pos_ = {ldmx_pos[0], ldmx_pos[1], ldmx_pos[2]};
306 new_ts.mom_ = {ldmx_mom[0] / Acts::UnitConstants::MeV,
307 ldmx_mom[1] / Acts::UnitConstants::MeV,
308 ldmx_mom[2] / Acts::UnitConstants::MeV};
310 const auto& bound_cov = bound_pars.covariance();
311 if (!bound_cov.has_value()) {
312 std::cerr <<
"TrackingUtils::makeTrackState: bound covariance missing\n";
317 const Acts::BoundToFreeMatrix j_btf =
318 bound_pars.referenceSurface().boundToFreeJacobian(gctx, acts_pos,
320 const Acts::FreeSquareMatrix free_cov =
321 j_btf * bound_cov.value() * j_btf.transpose();
325 constexpr std::array<int, 7> k_keep = {
326 Acts::eFreePos0, Acts::eFreePos1, Acts::eFreePos2, Acts::eFreeDir0,
327 Acts::eFreeDir1, Acts::eFreeDir2, Acts::eFreeQOverP};
328 Eigen::Matrix<double, 7, 7> free_cov7;
329 for (
int i = 0; i < 7; ++i)
330 for (
int j = 0; j < 7; ++j)
331 free_cov7(i, j) = free_cov(k_keep[i], k_keep[j]);
335 const double qop = bound_pars.parameters()[Acts::eBoundQOverP];
336 Eigen::Matrix<double, 6, 7> j_fp = Eigen::Matrix<double, 6, 7>::Zero();
337 j_fp.block<3, 3>(0, 0) = Eigen::Matrix3d::Identity();
338 j_fp.block<3, 3>(3, 3) = p * Eigen::Matrix3d::Identity();
339 j_fp(3, 6) = -acts_dir[0] * p / qop;
340 j_fp(4, 6) = -acts_dir[1] * p / qop;
341 j_fp(5, 6) = -acts_dir[2] * p / qop;
343 const Eigen::Matrix<double, 6, 6> cov_acts =
344 j_fp * free_cov7 * j_fp.transpose();
347 Eigen::Matrix<double, 6, 6> r_6 = Eigen::Matrix<double, 6, 6>::Zero();
348 r_6.block<3, 3>(0, 0) = r;
349 r_6.block<3, 3>(3, 3) = r;
350 const Eigen::Matrix<double, 6, 6> cov_ldmx = r_6 * cov_acts * r_6.transpose();
357 const double mev = Acts::UnitConstants::MeV;
358 new_ts.pos_mom_cov_.reserve(21);
359 for (
int i = 0; i < 6; ++i) {
360 for (
int j = i; j < 6; ++j) {
362 if (i >= 3) scale /= mev;
363 if (j >= 3) scale /= mev;
364 new_ts.pos_mom_cov_.push_back(cov_ldmx(i, j) * scale);
Class which encapsulates information from a hit in a simulated tracking detector.
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.
The measurement calibrator can be a function or a class/struct able to retrieve the sim hits containe...