29 #include <Eigen/src/Core/util/Memory.h>
30 #include <boost/graph/graph_traits.hpp>
31 #include <edm4hep/Track.h>
32 #include <edm4hep/TrackState.h>
34 #include "edm4hep/MutableTrack.h"
37 namespace EDM4hepUtil {
47 std::shared_ptr<const Acts::Surface>
surface;
67 template <
typename track_container_t,
typename track_state_container_t,
68 template <
typename>
class holder_t>
73 edm4hep::MutableTrack to,
double Bz,
76 to.setChi2(track.chi2());
77 to.setNdf(track.nDoF());
79 std::vector<edm4hep::TrackState> outTrackStates;
80 outTrackStates.reserve(track.nTrackStates());
82 auto setParameters = [](edm4hep::TrackState& trackState,
84 trackState.D0 = params.values[0];
85 trackState.Z0 = params.values[1];
86 trackState.phi = params.values[2];
87 trackState.tanLambda = params.values[3];
88 trackState.omega = params.values[4];
89 trackState.time = params.values[5];
91 if (params.covariance) {
93 trackState.covMatrix.data());
97 ACTS_VERBOSE(
"Converting " << track.nTrackStates() <<
" track states");
99 for (
const auto&
state : track.trackStatesReversed()) {
100 auto typeFlags =
state.typeFlags();
105 edm4hep::TrackState& trackState = outTrackStates.emplace_back();
106 trackState.location = edm4hep::TrackState::AtOther;
110 track.particleHypothesis()};
117 setParameters(trackState, converted);
119 << converted.
values.transpose());
121 <<
state.covariance() <<
"\n->\n"
126 auto center = converted.
surface->center(gctx);
127 trackState.referencePoint.x = center.x();
128 trackState.referencePoint.y = center.y();
129 trackState.referencePoint.z = center.z();
130 ACTS_VERBOSE(
"- ref surface ctr: " << center.transpose());
132 outTrackStates.front().location = edm4hep::TrackState::AtLastHit;
133 outTrackStates.back().location = edm4hep::TrackState::AtFirstHit;
136 auto& ipState = outTrackStates.emplace_back();
140 track.parameters(), track.covariance(),
141 track.particleHypothesis()};
146 setParameters(ipState, converted);
147 ipState.location = edm4hep::TrackState::AtIP;
148 ACTS_VERBOSE(
"Writing track level quantities as IP track state");
149 ACTS_VERBOSE(
"- parameters: " << track.parameters().transpose());
152 << track.covariance() <<
"\n->\n"
153 << converted.covariance.value());
159 auto center = converted.surface->center(gctx);
160 ipState.referencePoint.x = center.x();
161 ipState.referencePoint.y = center.y();
162 ipState.referencePoint.z = center.z();
164 ACTS_VERBOSE(
"- ref surface ctr: " << center.transpose());
166 for (
auto& trackState : outTrackStates) {
167 to.addToTrackStates(trackState);
171 template <
typename track_container_t,
typename track_state_container_t,
172 template <
typename>
class holder_t>
181 std::optional<edm4hep::TrackState> ipState;
189 params.
values[0] = trackState.D0;
190 params.
values[1] = trackState.Z0;
191 params.
values[2] = trackState.phi;
192 params.
values[3] = trackState.tanLambda;
193 params.
values[4] = trackState.omega;
194 params.
values[5] = trackState.time;
197 trackState.referencePoint.x,
198 trackState.referencePoint.y,
199 trackState.referencePoint.z,
201 params.
surface = Acts::Surface::makeShared<PerigeeSurface>(center);
207 <<
" track states (including IP state)");
210 for (
size_t i = from.trackStates_size() - 1;
i <= from.trackStates_size();
212 auto trackState = from.getTrackStates(
i);
213 if (trackState.location == edm4hep::TrackState::AtIP) {
214 ipState = trackState;
218 auto params = unpack(trackState);
220 auto ts = track.appendTrackState(mask);
225 ts.smoothed() = converted.parameters();
226 ts.smoothedCovariance() =
227 converted.covariance().value_or(BoundMatrix::Zero());
228 ts.setReferenceSurface(params.surface);
231 if (!ipState.has_value()) {
232 ACTS_ERROR(
"Did not find IP state in edm4hep input");
233 throw std::runtime_error{
"Did not find IP state in edm4hep input"};
240 ACTS_VERBOSE(
"IP state parameters: " << converted.parameters().transpose());
242 << converted.covariance().value_or(BoundMatrix::Zero()));
244 track.parameters() = converted.parameters();
245 track.covariance() = converted.covariance().value_or(BoundMatrix::Zero());
246 track.setReferenceSurface(params.
surface);
248 track.chi2() = from.getChi2();
249 track.nDoF() = from.getNdf();
250 track.nMeasurements() = track.nTrackStates();