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]);
409 case "pathLength"_hash:
410 return &(
to_const_ptr(m_trackStatesAux)->pathLength[istate]);
411 case "predicted"_hash:
412 return &(
to_const_ptr(m_trackStatesAux)->predicted[istate]);
413 case "filtered"_hash:
414 return &(
to_const_ptr(m_trackStatesAux)->filtered[istate]);
415 case "smoothed"_hash:
416 return &(
to_const_ptr(m_trackStatesAux)->smoothed[istate]);
417 case "jacobian"_hash:
418 return &(
to_const_ptr(m_trackStatesAux)->jacobian[istate]);
419 case "projector"_hash:{
423 case "calibrated"_hash: {
424 return &(
to_const_ptr(m_trackStatesAux)->calibrated[istate]);
426 case "calibratedCov"_hash: {
427 return &(
to_const_ptr(m_trackStatesAux)->calibrated[istate]);
430 return &(
to_const_ptr(m_trackStatesAux)->measDim[istate]);
431 case "typeFlags"_hash:
432 return &(
to_const_ptr(m_trackStatesAux)->typeFlags[istate]);
434 for (
auto&
d : m_decorations) {
436 INSPECTCALL(
"getting dymaic variable " <<
d.name <<
" " << istate);
437 return d.getter(m_trackStatesAux.get(), istate,
d.auxid);
440 throw std::runtime_error(
"MutableMultiTrajectory::component_impl const no such component " +
std::to_string(
key));
447 std::optional<bool> inTrackState =
448 ActsTrk::details::has_impl(m_trackStatesAux.get(),
key, istate);
449 if (inTrackState.has_value())
450 return inTrackState.value();
453 using namespace Acts::HashedStringLiteral;
454 if (
key ==
"uncalibratedSourceLink"_hash){
457 bool has_auxid= m_trackStatesAux->getAuxIDs().test(
acc.auxid());
459 return getElement(*m_trackStatesAux,
acc, istate) !=
nullptr;
462 return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
466 for (
auto&
d : m_decorations) {
478 m_trackStatesAux->resize(0);
479 m_trackStatesSize = 0;
481 m_trackParametersAux->resize(0);
482 m_trackParametersSize = 0;
484 m_trackJacobiansAux->resize(0);
485 m_trackJacobiansSize = 0;
487 m_trackMeasurementsAux->resize(0);
488 m_trackMeasurementsSize = 0;
490 m_surfacesBackend->clear();
492 m_calibratedSourceLinks.clear();
493 m_uncalibratedSourceLinks.clear();
498 m_trackStatesAux->measDim[istate] = measdim;
499 auto idx = m_trackStatesAux->calibrated[istate];
500 m_trackMeasurementsAux->meas[
idx].resize(measdim);
501 m_trackMeasurementsAux->covMatrix[
idx].resize(measdim*measdim);
508 return m_trackStatesAux->measDim[istate];
513 const Acts::SourceLink& sourceLink) {
517 if (istate>= m_trackStatesAux->size()) {
518 throw std::range_error(
"istate out of range on TrackStates when attempting to acces uncalibrated measurements");
520 std::span<const xAOD::UncalibratedMeasurement*> uncalibratedMeasurements = createDecoration(*m_trackStatesAux, decor);
531 catch (std::bad_any_cast &
err) {
532 assert( istate < m_uncalibratedSourceLinks.size());
533 m_uncalibratedSourceLinks[istate] = sourceLink;
538 std::shared_ptr<const Acts::Surface> surface) {
539 if ( istate >= m_surfaces.size() )
540 m_surfaces.resize(istate+1,
nullptr);
542 m_trackStatesAux->geometryId[istate] = surface->geometryId().value();
543 if (surface->geometryId().value() == 0) {
545 encodeSurface(m_surfacesBackendAux.get(), m_surfacesBackendAux->size()-1, surface.get(), m_geoContext.context());
546 m_trackStatesAux->surfaceIndex[istate] = m_surfacesBackend->size()-1;
547 m_surfaces[istate] = std::move(surface);
550 m_surfaces[istate] = surface.get();
557 if ( std::holds_alternative<const Acts::Surface*>(surfaceVariant))
558 return std::get<const Acts::Surface*>(surfaceVariant);
559 return std::get<std::shared_ptr<const Acts::Surface>>(surfaceVariant).
get();
564 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");
565 return toSurfacePtr(m_surfaces[istate]);
569 m_trackStatesAux->resize(m_trackStatesSize);
571 std::span<const xAOD::UncalibratedMeasurement*> uncalibratedMeasurements = createDecoration(*m_trackStatesAux, decor);
572 (void) uncalibratedMeasurements;
573 m_trackMeasurementsAux->resize(m_trackMeasurementsSize);
574 m_trackJacobiansAux->resize(m_trackJacobiansSize);
575 m_trackParametersAux->resize(m_trackParametersSize);
586 : m_trackStatesAux(trackStates),
587 m_trackParametersAux(trackParameters),
588 m_trackJacobiansAux(trackJacobians),
589 m_trackMeasurementsAux(trackMeasurements),
590 m_trackSurfacesAux(trackSurfaces) {
598 std::optional<bool> inTrackState =
599 ActsTrk::details::has_impl(m_trackStatesAux,
key, istate);
600 if (inTrackState.has_value())
601 return inTrackState.value();
603 using namespace Acts::HashedStringLiteral;
604 if (
key ==
"uncalibratedSourceLink"_hash) {
606 bool has_auxid= m_trackStatesAux->getAuxIDs().test(
acc.auxid());
608 return getElement( *m_trackStatesAux,
acc, istate) !=
nullptr;
611 return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
619 using namespace Acts::HashedStringLiteral;
621 case "previous"_hash:
622 return &(m_trackStatesAux->previous[istate]);
624 return &(m_trackStatesAux->chi2[istate]);
625 case "pathLength"_hash:
626 return &(m_trackStatesAux->pathLength[istate]);
627 case "predicted"_hash:
628 return &(m_trackStatesAux->predicted[istate]);
629 case "filtered"_hash:
630 return &(m_trackStatesAux->filtered[istate]);
631 case "smoothed"_hash:
632 return &(m_trackStatesAux->smoothed[istate]);
633 case "jacobian"_hash:
634 return &(m_trackStatesAux->jacobian[istate]);
635 case "projector"_hash: {
636 return &(m_trackMeasurementsAux->projector.at(m_trackStatesAux->calibrated[istate]));
638 case "calibrated"_hash: {
639 return &(m_trackStatesAux->calibrated[istate]);
641 case "calibratedCov"_hash: {
642 return &(m_trackStatesAux->calibrated[istate]);
645 return &(m_trackStatesAux->measDim[istate]);
646 case "typeFlags"_hash:
647 return &(m_trackStatesAux->typeFlags[istate]);
649 for (
auto&
d : m_decorations) {
652 return d.getter(m_trackStatesAux.cptr(), istate,
d.auxid);
655 throw std::runtime_error(
"MultiTrajectory::component_impl no such component " +
std::to_string(
key));
661 Acts::HashedString
key)
const {
662 using namespace Acts::HashedStringLiteral;
665 case "previous"_hash:
667 case "pathLength"_hash:
668 case "predicted"_hash:
669 case "filtered"_hash:
670 case "smoothed"_hash:
671 case "jacobian"_hash:
672 case "projector"_hash:
673 case "uncalibratedSourceLink"_hash:
674 case "calibrated"_hash:
675 case "calibratedCov"_hash:
677 case "typeFlags"_hash:
680 for (
auto&
d : m_decorations) {
690 return m_trackStatesAux->measDim[istate];
704 if ( not m_surfaces.empty() )
706 m_surfaces.resize(m_trackStatesAux->size(),
nullptr);
707 for (
IndexType i = 0;
i < m_trackStatesAux->size();
i++ ) {
708 auto geoID = m_trackStatesAux->geometryId[
i];
710 m_surfaces[
i] =
nullptr;
714 m_surfaces[
i] =
geo->findSurface(geoID);
716 unsigned int backendIndex = m_trackStatesAux->surfaceIndex[
i];
717 std::shared_ptr<const Acts::Surface> surface =
decodeSurface( m_trackSurfacesAux, backendIndex, geoContext);
718 m_surfaces[
i] = surface;
726 INSPECTCALL(
this <<
" " << istate <<
" " << m_trackStatesAux->size() <<
" " << m_surfaces.size() <<
" surf ptr " << toSurfacePtr(m_surfaces[istate]));
727 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");
728 return toSurfacePtr(m_surfaces[istate]);
731 typename Acts::SourceLink
734 assert(istate < m_trackStatesAux->
size());
741 if (m_trackStatesAux->getAuxIDs().test(
acc.auxid())){
742 return Acts::SourceLink( getElement(*m_trackStatesAux,
acc, istate) );
745 return m_uncalibratedSourceLinks[istate].value();
749 typename Acts::SourceLink
752 assert(istate < m_trackStatesAux->
size());
759 if (m_trackStatesAux->getAuxIDs().test(
acc.auxid())){
760 return Acts::SourceLink( getElement(*m_trackStatesAux,
acc, istate) );
763 return m_uncalibratedSourceLinks[istate].value();