15 "chi2",
"pathLength",
"typeFlags",
"previous",
"next",
"predicted",
"filtered",
"smoothed",
"jacobian",
"calibrated",
"measDim",
16 "uncalibratedMeasurement",
"uncalibratedMeasurementLink" ,
"geometryId",
"surfaceIndex"
22 using const_span = std::span<T const>;
28 T *non_const_data =
const_cast< T *
>(
data);
29 std::span<T> ret(non_const_data, aux_container.
size() );
36 const_span<T> ret(
data, aux_container.
size() );
43 std::size_t
sz=aux_container.
size();
45 return std::span<T>(
data,
sz );
49 std::stringstream
msg;
50 msg <<
"range error: " <<
index <<
" >= " << aux_container.
size()
52 throw std::range_error(
msg.str());
60 throwRangeError(aux_container,
index);
62 const_span<const xAOD::UncalibratedMeasurement*>
vec = getElementVector(aux_container,
accessor);
107 return m_trackStatesAux !=
nullptr and m_trackParametersAux !=
nullptr and
108 m_trackJacobiansAux !=
nullptr and m_trackMeasurementsAux !=
nullptr
109 and m_surfacesBackend !=
nullptr;
113 template<
typename CONT>
114 void stepResize( CONT* auxPtr,
const size_t realSize,
const size_t sizeStep = 20) {
115 if( realSize >= auxPtr->size() ) auxPtr->resize(auxPtr->size()+sizeStep);
120 Acts::TrackStatePropMask
mask,
122 using namespace Acts::HashedStringLiteral;
124 assert(m_trackStatesAux &&
"Missing Track States backend");
125 constexpr
size_t NDim = 6;
126 stepResize(m_trackStatesAux.get(), m_trackStatesSize);
127 m_surfaces.push_back(
nullptr);
130 using Acts::MultiTrajectoryTraits::kInvalid;
134 m_trackStatesAux->previous[m_trackStatesSize] =
previous;
135 using namespace Acts;
138 stepResize(m_trackParametersAux.get(), m_trackParametersSize, 60);
140 m_trackParametersAux->params[m_trackParametersSize].resize(NDim);
141 m_trackParametersAux->covMatrix[m_trackParametersSize].resize(NDim*NDim);
142 m_trackParametersSize++;
143 return m_trackParametersSize-1;
147 stepResize(m_trackJacobiansAux.get(), m_trackJacobiansSize);
148 m_trackJacobiansAux->jac[m_trackJacobiansSize].resize(NDim*NDim);
149 m_trackJacobiansSize++;
150 return m_trackJacobiansSize-1;
154 stepResize(m_trackMeasurementsAux.get(), m_trackMeasurementsSize );
155 m_trackMeasurementsAux->meas[m_trackMeasurementsSize].resize(NDim);
156 m_trackMeasurementsAux->covMatrix[m_trackMeasurementsSize].resize(NDim*NDim);
157 m_trackMeasurementsSize++;
158 return m_trackMeasurementsSize-1;
161 m_trackStatesAux->predicted[m_trackStatesSize] = kInvalid;
162 if (ACTS_CHECK_BIT(
mask, TrackStatePropMask::Predicted)) {
163 m_trackStatesAux->predicted[m_trackStatesSize] = addParam();
166 m_trackStatesAux->filtered[m_trackStatesSize] = kInvalid;
167 if (ACTS_CHECK_BIT(
mask, TrackStatePropMask::Filtered)) {
168 m_trackStatesAux->filtered[m_trackStatesSize] = addParam();
171 m_trackStatesAux->smoothed[m_trackStatesSize] = kInvalid;
172 if (ACTS_CHECK_BIT(
mask, TrackStatePropMask::Smoothed)) {
173 m_trackStatesAux->smoothed[m_trackStatesSize] = addParam();
176 m_trackStatesAux->jacobian[m_trackStatesSize] = kInvalid;
177 if (ACTS_CHECK_BIT(
mask, TrackStatePropMask::Jacobian)) {
178 m_trackStatesAux->jacobian[m_trackStatesSize] = addJacobian();
181 m_uncalibratedSourceLinks.emplace_back(std::nullopt);
182 m_trackStatesAux->calibrated[m_trackStatesSize] = kInvalid;
183 m_trackStatesAux->measDim[m_trackStatesSize] = 0;
185 if (ACTS_CHECK_BIT(
mask, TrackStatePropMask::Calibrated)) {
186 m_trackStatesAux->calibrated[m_trackStatesSize] = addMeasurement();
187 m_calibratedSourceLinks.emplace_back(std::nullopt);
188 m_trackStatesAux->measDim[m_trackStatesSize] = m_trackMeasurementsAux->meas[m_trackStatesAux->calibrated[m_trackStatesSize]].size();
191 m_trackStatesAux->geometryId[m_trackStatesSize] =
InvalidGeoID;
193 return m_trackStatesSize-1;
199 Acts::TrackStatePropMask
mask) {
200 using namespace Acts::HashedStringLiteral;
203 assert(m_trackStatesAux &&
"Missing Track States backend");
204 constexpr
size_t NDim = 6;
207 using Acts::MultiTrajectoryTraits::kInvalid;
209 using namespace Acts;
212 stepResize(m_trackParametersAux.get(), m_trackParametersSize, 60);
214 m_trackParametersAux->params[m_trackParametersSize].resize(NDim);
215 m_trackParametersAux->covMatrix[m_trackParametersSize].resize(NDim*NDim);
216 m_trackParametersSize++;
217 return m_trackParametersSize-1;
221 stepResize(m_trackJacobiansAux.get(), m_trackJacobiansSize);
222 m_trackJacobiansAux->jac[m_trackJacobiansSize].resize(NDim*NDim);
223 m_trackJacobiansSize++;
224 return m_trackJacobiansSize-1;
228 stepResize(m_trackMeasurementsAux.get(), m_trackMeasurementsSize );
229 m_trackMeasurementsAux->meas[m_trackMeasurementsSize].resize(NDim);
230 m_trackMeasurementsAux->covMatrix[m_trackMeasurementsSize].resize(NDim*NDim);
231 m_trackMeasurementsSize++;
232 return m_trackMeasurementsSize-1;
235 if ((m_trackStatesAux->predicted[istate] == kInvalid) &&
236 ACTS_CHECK_BIT(
mask, TrackStatePropMask::Predicted)) {
237 m_trackStatesAux->predicted[istate] = addParam();
240 if ((m_trackStatesAux->filtered[istate] == kInvalid) &&
241 ACTS_CHECK_BIT(
mask, TrackStatePropMask::Filtered)) {
242 m_trackStatesAux->filtered[istate] = addParam();
245 if ((m_trackStatesAux->smoothed[istate] == kInvalid) &&
246 ACTS_CHECK_BIT(
mask, TrackStatePropMask::Smoothed)) {
247 m_trackStatesAux->smoothed[istate] = addParam();
250 if ((m_trackStatesAux->jacobian[istate] == kInvalid) &&
251 ACTS_CHECK_BIT(
mask, TrackStatePropMask::Jacobian)) {
252 m_trackStatesAux->jacobian[istate] = addJacobian();
255 if ((m_trackStatesAux->calibrated[istate] == kInvalid) &&
256 ACTS_CHECK_BIT(
mask, TrackStatePropMask::Calibrated)) {
257 m_trackStatesAux->calibrated[istate] = addMeasurement();
258 m_calibratedSourceLinks.emplace_back(std::nullopt);
259 m_trackStatesAux->measDim[istate] = m_trackMeasurementsAux->meas[m_trackStatesAux->calibrated[istate]].size();
267 Acts::TrackStatePropMask shareSource,
268 Acts::TrackStatePropMask shareTarget) {
270 assert(ACTS_CHECK_BIT(this->getTrackState(iother).getMask(), shareSource) &&
271 "Source has incompatible allocation");
273 using PM = Acts::TrackStatePropMask;
275 using Acts::MultiTrajectoryTraits::kInvalid;
278 switch (shareSource) {
280 sourceIndex = m_trackStatesAux->predicted[iother];
283 sourceIndex = m_trackStatesAux->filtered[iother];
286 sourceIndex = m_trackStatesAux->smoothed[iother];
289 sourceIndex = m_trackStatesAux->jacobian[iother];
292 throw std::domain_error{
"MutableMultiTrajectory Unable to share this component"};
295 assert(sourceIndex != kInvalid);
297 switch (shareTarget) {
299 assert(shareSource != PM::Jacobian);
300 m_trackStatesAux->predicted[iself] = sourceIndex;
303 assert(shareSource != PM::Jacobian);
304 m_trackStatesAux->filtered[iself] = sourceIndex;
307 assert(shareSource != PM::Jacobian);
308 m_trackStatesAux->smoothed[iself] = sourceIndex;
311 assert(shareSource == PM::Jacobian);
312 m_trackStatesAux->jacobian[iself] = sourceIndex;
315 throw std::domain_error{
"MutableMultiTrajectory Unable to share this component"};
321 Acts::TrackStatePropMask
target,
324 using PM = Acts::TrackStatePropMask;
326 using Acts::MultiTrajectoryTraits::kInvalid;
330 m_trackStatesAux->predicted[istate] = kInvalid;
333 m_trackStatesAux->filtered[istate] = kInvalid;
337 m_trackStatesAux->smoothed[istate] = kInvalid;
340 m_trackStatesAux->jacobian[istate] = kInvalid;
344 m_trackStatesAux->calibrated[istate] = kInvalid;
350 throw std::domain_error{
"MutableMultiTrajectory Unable to unset this component"};
356 using namespace Acts::HashedStringLiteral;
357 assert(istate < m_trackStatesAux->
size() &&
358 "Attempt to reach beyond the Track States container size");
362 case "previous"_hash:
363 return &(m_trackStatesAux->previous[istate]);
365 return &(m_trackStatesAux->next[istate]);
367 return &(m_trackStatesAux->chi2[istate]);
368 case "pathLength"_hash:
369 return &(m_trackStatesAux->pathLength[istate]);
370 case "predicted"_hash:
371 return &(m_trackStatesAux->predicted[istate]);
372 case "filtered"_hash:
373 return &(m_trackStatesAux->filtered[istate]);
374 case "smoothed"_hash:
375 return &(m_trackStatesAux->smoothed[istate]);
376 case "projector"_hash: {
377 auto idx = m_trackStatesAux->calibrated[istate];
378 return &(m_trackMeasurementsAux->projector[
idx]);
381 return &(m_trackStatesAux->measDim[istate]);
382 case "typeFlags"_hash:
383 return &(m_trackStatesAux->typeFlags[istate]);
386 for (
auto&
d : m_decorations) {
388 return d.setter(m_trackStatesAux.get(), istate,
d.auxid);
391 throw std::runtime_error(
"MutableMultiTrajectory::component_impl no such component " +
std::to_string(
key));
398 Acts::HashedString
key,
400 using namespace Acts::HashedStringLiteral;
401 assert(istate < m_trackStatesAux->
size() &&
402 "Attempt to reach beyond the Track States container size");
405 case "previous"_hash:
406 return &(
to_const_ptr(m_trackStatesAux)->previous[istate]);
411 case "pathLength"_hash:
412 return &(
to_const_ptr(m_trackStatesAux)->pathLength[istate]);
413 case "predicted"_hash:
414 return &(
to_const_ptr(m_trackStatesAux)->predicted[istate]);
415 case "filtered"_hash:
416 return &(
to_const_ptr(m_trackStatesAux)->filtered[istate]);
417 case "smoothed"_hash:
418 return &(
to_const_ptr(m_trackStatesAux)->smoothed[istate]);
419 case "jacobian"_hash:
420 return &(
to_const_ptr(m_trackStatesAux)->jacobian[istate]);
421 case "projector"_hash:{
425 case "calibrated"_hash: {
426 return &(
to_const_ptr(m_trackStatesAux)->calibrated[istate]);
428 case "calibratedCov"_hash: {
429 return &(
to_const_ptr(m_trackStatesAux)->calibrated[istate]);
432 return &(
to_const_ptr(m_trackStatesAux)->measDim[istate]);
433 case "typeFlags"_hash:
434 return &(
to_const_ptr(m_trackStatesAux)->typeFlags[istate]);
436 for (
auto&
d : m_decorations) {
438 INSPECTCALL(
"getting dynamic variable " <<
d.name <<
" " << istate);
439 return d.getter(m_trackStatesAux.get(), istate,
d.auxid);
442 throw std::runtime_error(
"MutableMultiTrajectory::component_impl const no such component " +
std::to_string(
key));
449 std::optional<bool> inTrackState =
450 ActsTrk::details::has_impl(m_trackStatesAux.get(),
key, istate);
451 if (inTrackState.has_value())
452 return inTrackState.value();
455 using namespace Acts::HashedStringLiteral;
456 if (
key ==
"uncalibratedSourceLink"_hash){
459 bool has_auxid= m_trackStatesAux->getAuxIDs().test(
acc.auxid());
461 return getElement(*m_trackStatesAux,
acc, istate) !=
nullptr;
464 return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
468 for (
auto&
d : m_decorations) {
480 m_trackStatesAux->resize(0);
481 m_trackStatesSize = 0;
483 m_trackParametersAux->resize(0);
484 m_trackParametersSize = 0;
486 m_trackJacobiansAux->resize(0);
487 m_trackJacobiansSize = 0;
489 m_trackMeasurementsAux->resize(0);
490 m_trackMeasurementsSize = 0;
492 m_surfacesBackend->clear();
494 m_calibratedSourceLinks.clear();
495 m_uncalibratedSourceLinks.clear();
502 return m_trackStatesAux->measDim[istate];
507 const Acts::SourceLink& sourceLink) {
511 if (istate>= m_trackStatesAux->size()) {
512 throw std::range_error(
"istate out of range on TrackStates when attempting to access uncalibrated measurements");
514 std::span<const xAOD::UncalibratedMeasurement*> uncalibratedMeasurements = createDecoration(*m_trackStatesAux, decor);
525 catch (std::bad_any_cast &
err) {
526 assert( istate < m_uncalibratedSourceLinks.size());
527 m_uncalibratedSourceLinks[istate] = sourceLink;
532 std::shared_ptr<const Acts::Surface> surface) {
533 if ( istate >= m_surfaces.size() )
534 m_surfaces.resize(istate+1,
nullptr);
536 m_trackStatesAux->geometryId[istate] = surface->geometryId().value();
537 if (surface->geometryId().value() == 0) {
539 encodeSurface(m_surfacesBackendAux.get(), m_surfacesBackendAux->size()-1, surface.get(), m_geoContext.context());
540 m_trackStatesAux->surfaceIndex[istate] = m_surfacesBackend->size()-1;
541 m_surfaces[istate] = std::move(surface);
544 m_surfaces[istate] = surface.get();
551 if ( std::holds_alternative<const Acts::Surface*>(surfaceVariant))
552 return std::get<const Acts::Surface*>(surfaceVariant);
553 return std::get<std::shared_ptr<const Acts::Surface>>(surfaceVariant).
get();
558 if ( istate >= m_surfaces.size() )
throw std::out_of_range(
"MutableMultiTrajectory index " +
std::to_string(istate) +
" out of range " +
std::to_string(m_surfaces.size()) +
" when accessing reference surface");
559 return toSurfacePtr(m_surfaces[istate]);
563 m_trackStatesAux->resize(m_trackStatesSize);
565 std::span<const xAOD::UncalibratedMeasurement*> uncalibratedMeasurements = createDecoration(*m_trackStatesAux, decor);
566 (void) uncalibratedMeasurements;
567 m_trackMeasurementsAux->resize(m_trackMeasurementsSize);
568 m_trackJacobiansAux->resize(m_trackJacobiansSize);
569 m_trackParametersAux->resize(m_trackParametersSize);
580 : m_trackStatesAux(trackStates),
581 m_trackParametersAux(trackParameters),
582 m_trackJacobiansAux(trackJacobians),
583 m_trackMeasurementsAux(trackMeasurements),
584 m_trackSurfacesAux(trackSurfaces) {
592 std::optional<bool> inTrackState =
593 ActsTrk::details::has_impl(m_trackStatesAux,
key, istate);
594 if (inTrackState.has_value())
595 return inTrackState.value();
597 using namespace Acts::HashedStringLiteral;
598 if (
key ==
"uncalibratedSourceLink"_hash) {
600 bool has_auxid= m_trackStatesAux->getAuxIDs().test(
acc.auxid());
602 return getElement( *m_trackStatesAux,
acc, istate) !=
nullptr;
605 return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
613 using namespace Acts::HashedStringLiteral;
615 case "previous"_hash:
616 return &(m_trackStatesAux->previous[istate]);
618 return &(m_trackStatesAux->next[istate]);
620 return &(m_trackStatesAux->chi2[istate]);
621 case "pathLength"_hash:
622 return &(m_trackStatesAux->pathLength[istate]);
623 case "predicted"_hash:
624 return &(m_trackStatesAux->predicted[istate]);
625 case "filtered"_hash:
626 return &(m_trackStatesAux->filtered[istate]);
627 case "smoothed"_hash:
628 return &(m_trackStatesAux->smoothed[istate]);
629 case "jacobian"_hash:
630 return &(m_trackStatesAux->jacobian[istate]);
631 case "projector"_hash: {
632 return &(m_trackMeasurementsAux->projector.at(m_trackStatesAux->calibrated[istate]));
634 case "calibrated"_hash: {
635 return &(m_trackStatesAux->calibrated[istate]);
637 case "calibratedCov"_hash: {
638 return &(m_trackStatesAux->calibrated[istate]);
641 return &(m_trackStatesAux->measDim[istate]);
642 case "typeFlags"_hash:
643 return &(m_trackStatesAux->typeFlags[istate]);
645 for (
auto&
d : m_decorations) {
648 return d.getter(m_trackStatesAux.cptr(), istate,
d.auxid);
651 throw std::runtime_error(
"MultiTrajectory::component_impl no such component " +
std::to_string(
key));
657 Acts::HashedString
key)
const {
658 using namespace Acts::HashedStringLiteral;
661 case "previous"_hash:
664 case "pathLength"_hash:
665 case "predicted"_hash:
666 case "filtered"_hash:
667 case "smoothed"_hash:
668 case "jacobian"_hash:
669 case "projector"_hash:
670 case "uncalibratedSourceLink"_hash:
671 case "calibrated"_hash:
672 case "calibratedCov"_hash:
674 case "typeFlags"_hash:
677 for (
auto&
d : m_decorations) {
687 return m_trackStatesAux->measDim[istate];
701 if ( not m_surfaces.empty() )
703 m_surfaces.resize(m_trackStatesAux->size(),
nullptr);
704 for (
IndexType i = 0;
i < m_trackStatesAux->size();
i++ ) {
705 auto geoID = m_trackStatesAux->geometryId[
i];
707 m_surfaces[
i] =
nullptr;
711 m_surfaces[
i] =
geo->findSurface(geoID);
713 unsigned int backendIndex = m_trackStatesAux->surfaceIndex[
i];
714 std::shared_ptr<const Acts::Surface> surface =
decodeSurface( m_trackSurfacesAux, backendIndex, geoContext);
715 m_surfaces[
i] = surface;
723 INSPECTCALL(
this <<
" " << istate <<
" " << m_trackStatesAux->size() <<
" " << m_surfaces.size() <<
" surf ptr " << toSurfacePtr(m_surfaces[istate]));
724 if ( istate >= m_surfaces.size() )
throw std::out_of_range(
"MultiTrajectory index " +
std::to_string(istate) +
" out of range " +
std::to_string(m_surfaces.size()) +
" when accessing reference surface");
725 return toSurfacePtr(m_surfaces[istate]);
728 typename Acts::SourceLink
731 assert(istate < m_trackStatesAux->
size());
738 if (m_trackStatesAux->getAuxIDs().test(
acc.auxid())){
739 return Acts::SourceLink( getElement(*m_trackStatesAux,
acc, istate) );
742 return m_uncalibratedSourceLinks[istate].value();
746 typename Acts::SourceLink
749 assert(istate < m_trackStatesAux->
size());
756 if (m_trackStatesAux->getAuxIDs().test(
acc.auxid())){
757 return Acts::SourceLink( getElement(*m_trackStatesAux,
acc, istate) );
760 return m_uncalibratedSourceLinks[istate].value();