ATLAS Offline Software
Loading...
Searching...
No Matches
MultiTrajectory.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5#include <Acts/Geometry/GeometryIdentifier.hpp>
12
13constexpr uint64_t InvalidGeoID = std::numeric_limits<uint64_t>::max();
14
15const std::set<std::string> ActsTrk::MutableMultiTrajectory::s_staticVariables = {
16 "chi2", "pathLength", "typeFlags", "previous", "next", "predicted", "filtered", "smoothed", "jacobian", "calibrated", "measDim",
17 "uncalibratedMeasurement", "uncalibratedMeasurementLink" /*created by converter*/, "geometryId", "surfaceIndex"
18 };
19
20namespace {
21constexpr std::optional<bool> has_impl(
22 const xAOD::TrackStateAuxContainer* trackStates, Acts::HashedString key,
23 ActsTrk::IndexType istate) {
24 using namespace Acts::HashedStringLiteral;
25 using Acts::MultiTrajectoryTraits::kInvalid;
26 INSPECTCALL(key << " " << istate);
27
28 switch (key) {
29 case "previous"_hash:
30 return trackStates->previous[istate] < kInvalid;
31 case "chi2"_hash:{
32 INSPECTCALL(key << " " << istate << " chi2");
33 return true;
34 }
35 case "pathLength"_hash:{
36 INSPECTCALL(key << " " << istate << " pathLength");
37 return true;
38 }
39 case "typeFlags"_hash:{
40 INSPECTCALL(key << " " << istate << " type flags");
41 return true;
42 }
43 case "predicted"_hash:{
44 INSPECTCALL(key << " " << istate << " predicted");
45 return trackStates->predicted[istate] < kInvalid;
46 }
47 case "filtered"_hash:{
48 INSPECTCALL(key << " " << istate << " filtered");
49 return trackStates->filtered[istate] < kInvalid;
50 }
51 case "smoothed"_hash:{
52 INSPECTCALL(key << " " << istate << " smoothed");
53 return trackStates->smoothed[istate] < kInvalid;
54 }
55 case "jacobian"_hash:{
56 INSPECTCALL(key << " " << istate << " jacobian");
57 return trackStates->jacobian[istate] < kInvalid;
58 }
59 case "projector"_hash:{
60 INSPECTCALL(key << " " << istate << " projector");
61 return trackStates->calibrated[istate] < kInvalid;
62 }
63 case "calibrated"_hash:{
64 INSPECTCALL(key << " " << istate << " calibrated");
65 return trackStates->measDim[istate] < kInvalid;
66 }
67 case "calibratedCov"_hash: {
68 INSPECTCALL(key << " " << istate << " calibratedCov");
69 return trackStates->measDim[istate] < kInvalid;
70 }
71 case "measdim"_hash: {
72 INSPECTCALL(key << " " << istate << " measdim");
73 return true;
74 }
75 case "referenceSurface"_hash: {
76 INSPECTCALL(key << " " << istate << " referenceSurfaceEnco");
77 return true;
78 }
79
80 // TODO restore once only the EL Source Links are in use
81 // return !trackStates[istate]->uncalibratedMeasurementLink().isDefault();
82 }
83 INSPECTCALL(key << " " << istate << " not a predefined component");
84 return std::optional<bool>();
85}
86}
87
88
89template<typename T>
90const T* to_const_ptr(const std::unique_ptr<T>& ptr) {
91 return ptr.get();
92}
93
95 : m_trackStatesAux (std::make_unique<xAOD::TrackStateAuxContainer>()),
96 m_trackParametersAux (std::make_unique<xAOD::TrackParametersAuxContainer>()),
97 m_trackJacobiansAux (std::make_unique<xAOD::TrackJacobianAuxContainer>()),
98 m_trackMeasurementsAux (std::make_unique<xAOD::TrackMeasurementAuxContainer>()),
99 m_surfacesBackend (std::make_unique<xAOD::TrackSurfaceContainer>()),
100 m_surfacesBackendAux (std::make_unique<xAOD::TrackSurfaceAuxContainer>())
101{
102 INSPECTCALL("c-tor " << this)
103
105 m_trackStatesIface.setStore(m_trackStatesAux.get());
106
107}
108
111 {
112 INSPECTCALL("copy c-tor " << this << " src " << &other << " " << other.size())
113
114 *m_trackStatesAux = *other.m_trackStatesAux;
115 *m_trackParametersAux = *other.m_trackParametersAux;
116 *m_trackJacobiansAux = *other.m_trackJacobiansAux;
117 *m_trackMeasurementsAux = *other.m_trackMeasurementsAux;
118 m_decorations = other.m_decorations;
119 m_calibratedSourceLinks = other.m_calibratedSourceLinks;
120 m_uncalibratedSourceLinks = other.m_uncalibratedSourceLinks;
121
122 m_surfaces = other.m_surfaces;
123 m_geoContext = other.m_geoContext;
124 m_trackStatesIface.resize(m_trackStatesAux->size());
125 INSPECTCALL("copy c-tor done")
126}
127
128
130 return m_trackStatesAux != nullptr and m_trackParametersAux != nullptr and
131 m_trackJacobiansAux != nullptr and m_trackMeasurementsAux != nullptr
132 and m_surfacesBackend != nullptr;
133}
134
135namespace{
136 template<typename CONT>
137 void stepResize( CONT* auxPtr, const size_t realSize, const size_t sizeStep = 20) {
138 if( realSize >= auxPtr->size() ) auxPtr->resize(auxPtr->size()+sizeStep);
139 }
140}
141
143 Acts::TrackStatePropMask mask,
144 ActsTrk::IndexType previous) {
145 using namespace Acts::HashedStringLiteral;
146 INSPECTCALL( this << " " << mask << " " << m_trackStatesIface.size() << " " << previous);
147 assert(m_trackStatesAux && "Missing Track States backend");
149 m_surfaces.push_back(nullptr);
150
151 // set kInvalid
152 using Acts::MultiTrajectoryTraits::kInvalid;
153
154 if (previous >= kInvalid - 1)
155 previous = kInvalid; // fix needed in Acts::MTJ
156 m_trackStatesAux->previous[m_trackStatesSize] = previous;
157 using namespace Acts;
158
159 auto addParam = [this]() -> ActsTrk::IndexType {
160 stepResize(m_trackParametersAux.get(), m_trackParametersSize, 60);
161 // TODO ask AK if this resize could be method of aux container
162 m_trackParametersAux->params[m_trackParametersSize].resize(Acts::eBoundSize);
163 m_trackParametersAux->covMatrix[m_trackParametersSize].resize(Acts::eBoundSize*Acts::eBoundSize);
165 return m_trackParametersSize-1;
166 };
167
168 auto addJacobian = [this]() -> ActsTrk::IndexType {
169 stepResize(m_trackJacobiansAux.get(), m_trackJacobiansSize);
170 m_trackJacobiansAux->jac[m_trackJacobiansSize].resize(Acts::eBoundSize*Acts::eBoundSize);
172 return m_trackJacobiansSize-1;
173 };
174
175 auto addMeasurement = [this]() -> ActsTrk::IndexType {
177 m_trackMeasurementsAux->meas[m_trackMeasurementsSize].resize(Acts::eBoundSize);
178 m_trackMeasurementsAux->covMatrix[m_trackMeasurementsSize].resize(Acts::eBoundSize*Acts::eBoundSize);
181 };
182
183 m_trackStatesAux->predicted[m_trackStatesSize] = kInvalid;
184 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Predicted)) {
185 m_trackStatesAux->predicted[m_trackStatesSize] = addParam();
186 }
187
188 m_trackStatesAux->filtered[m_trackStatesSize] = kInvalid;
189 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Filtered)) {
190 m_trackStatesAux->filtered[m_trackStatesSize] = addParam();
191 }
192
193 m_trackStatesAux->smoothed[m_trackStatesSize] = kInvalid;
194 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Smoothed)) {
195 m_trackStatesAux->smoothed[m_trackStatesSize] = addParam();
196 }
197
198 m_trackStatesAux->jacobian[m_trackStatesSize] = kInvalid;
199 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Jacobian)) {
200 m_trackStatesAux->jacobian[m_trackStatesSize] = addJacobian();
201 }
202
203 m_uncalibratedSourceLinks.emplace_back(std::nullopt);
204 m_trackStatesAux->calibrated[m_trackStatesSize] = kInvalid;
205 m_trackStatesAux->measDim[m_trackStatesSize] = kInvalid;
206 // @TODO uncalibrated ?
207 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Calibrated)) {
208 m_trackStatesAux->calibrated.at(m_trackStatesSize) = addMeasurement();
209 m_calibratedSourceLinks.emplace_back(std::nullopt);
210 }
211
212 m_trackStatesAux->geometryId[m_trackStatesSize] = InvalidGeoID; // surface is invalid until set
214 return m_trackStatesSize-1;
215}
216
217
219 ActsTrk::IndexType istate,
220 Acts::TrackStatePropMask mask) {
221 using namespace Acts::HashedStringLiteral;
222 INSPECTCALL( this << " " << mask << " " << m_trackStatesIface.size() << " " << istate);
223
224 assert(m_trackStatesAux && "Missing Track States backend");
225
226 // set kInvalid
227 using Acts::MultiTrajectoryTraits::kInvalid;
228
229 using namespace Acts;
230
231 auto addParam = [this]() -> ActsTrk::IndexType {
232 stepResize(m_trackParametersAux.get(), m_trackParametersSize, 60);
233 // TODO ask AK if this resize could be method of aux container
234 m_trackParametersAux->params[m_trackParametersSize].resize(Acts::eBoundSize);
235 m_trackParametersAux->covMatrix[m_trackParametersSize].resize(Acts::eBoundSize*Acts::eBoundSize);
237 return m_trackParametersSize-1;
238 };
239
240 auto addJacobian = [this]() -> ActsTrk::IndexType {
241 stepResize(m_trackJacobiansAux.get(), m_trackJacobiansSize);
242 m_trackJacobiansAux->jac[m_trackJacobiansSize].resize(Acts::eBoundSize*Acts::eBoundSize);
244 return m_trackJacobiansSize-1;
245 };
246
247 auto addMeasurement = [this]() -> ActsTrk::IndexType {
249 m_trackMeasurementsAux->meas[m_trackMeasurementsSize].resize(Acts::eBoundSize);
250 m_trackMeasurementsAux->covMatrix[m_trackMeasurementsSize].resize(Acts::eBoundSize*Acts::eBoundSize);
253 };
254
255 if ((m_trackStatesAux->predicted[istate] == kInvalid) &&
256 ACTS_CHECK_BIT(mask, TrackStatePropMask::Predicted)) {
257 m_trackStatesAux->predicted[istate] = addParam();
258 }
259
260 if ((m_trackStatesAux->filtered[istate] == kInvalid) &&
261 ACTS_CHECK_BIT(mask, TrackStatePropMask::Filtered)) {
262 m_trackStatesAux->filtered[istate] = addParam();
263 }
264
265 if ((m_trackStatesAux->smoothed[istate] == kInvalid) &&
266 ACTS_CHECK_BIT(mask, TrackStatePropMask::Smoothed)) {
267 m_trackStatesAux->smoothed[istate] = addParam();
268 }
269
270 if ((m_trackStatesAux->jacobian[istate] == kInvalid) &&
271 ACTS_CHECK_BIT(mask, TrackStatePropMask::Jacobian)) {
272 m_trackStatesAux->jacobian[istate] = addJacobian();
273 }
274
275 if ((m_trackStatesAux->calibrated[istate] == kInvalid) &&
276 ACTS_CHECK_BIT(mask, TrackStatePropMask::Calibrated)) {
277 m_trackStatesAux->calibrated[istate] = addMeasurement();
278 m_calibratedSourceLinks.emplace_back(std::nullopt);
279 }
280}
281
282
284 ActsTrk::IndexType iself,
285 ActsTrk::IndexType iother,
286 Acts::TrackStatePropMask shareSource,
287 Acts::TrackStatePropMask shareTarget) {
288
289 assert(ACTS_CHECK_BIT(this->getTrackState(iother).getMask(), shareSource) &&
290 "Source has incompatible allocation");
291
292 using PM = Acts::TrackStatePropMask;
293 // set kInvalid
294 using Acts::MultiTrajectoryTraits::kInvalid;
295
296 ActsTrk::IndexType sourceIndex{kInvalid};
297 switch (shareSource) {
298 case PM::Predicted:
299 sourceIndex = m_trackStatesAux->predicted[iother];
300 break;
301 case PM::Filtered:
302 sourceIndex = m_trackStatesAux->filtered[iother];
303 break;
304 case PM::Smoothed:
305 sourceIndex = m_trackStatesAux->smoothed[iother];
306 break;
307 case PM::Jacobian:
308 sourceIndex = m_trackStatesAux->jacobian[iother];
309 break;
310 default:
311 throw std::domain_error{"MutableMultiTrajectory Unable to share this component"};
312 }
313
314 assert(sourceIndex != kInvalid);
315
316 switch (shareTarget) {
317 case PM::Predicted:
318 assert(shareSource != PM::Jacobian);
319 m_trackStatesAux->predicted[iself] = sourceIndex;
320 break;
321 case PM::Filtered:
322 assert(shareSource != PM::Jacobian);
323 m_trackStatesAux->filtered[iself] = sourceIndex;
324 break;
325 case PM::Smoothed:
326 assert(shareSource != PM::Jacobian);
327 m_trackStatesAux->smoothed[iself] = sourceIndex;
328 break;
329 case PM::Jacobian:
330 assert(shareSource == PM::Jacobian);
331 m_trackStatesAux->jacobian[iself] = sourceIndex;
332 break;
333 default:
334 throw std::domain_error{"MutableMultiTrajectory Unable to share this component"};
335 }
336}
337
338
340 Acts::TrackStatePropMask target,
341 ActsTrk::IndexType istate) {
342
343 using PM = Acts::TrackStatePropMask;
344 // set kInvalid
345 using Acts::MultiTrajectoryTraits::kInvalid;
346
347 switch (target) {
348 case PM::Predicted:
349 m_trackStatesAux->predicted[istate] = kInvalid;
350 break;
351 case PM::Filtered:
352 m_trackStatesAux->filtered[istate] = kInvalid;
353
354 break;
355 case PM::Smoothed:
356 m_trackStatesAux->smoothed[istate] = kInvalid;
357 break;
358 case PM::Jacobian:
359 m_trackStatesAux->jacobian[istate] = kInvalid;
360
361 break;
362 case PM::Calibrated:
363 m_trackStatesAux->measDim[istate] = kInvalid;
364 // TODO here m_measOffset[istate] and m_measCovOffset[istate] should be
365 // set to kInvalid
366
367 break;
368 default:
369 throw std::domain_error{"MutableMultiTrajectory Unable to unset this component"};
370 }
371}
372
374 Acts::HashedString key, ActsTrk::IndexType istate) {
375 using namespace Acts::HashedStringLiteral;
376 assert(istate < m_trackStatesIface.size() &&
377 "Attempt to reach beyond the Track States container size");
378 INSPECTCALL(key << " " << istate << " non-const component_impl")
379
380 switch (key) {
381 case "previous"_hash:
382 return &(m_trackStatesAux->previous[istate]);
383 case "next"_hash:
384 return &(m_trackStatesAux->next[istate]);
385 case "chi2"_hash:
386 return &(m_trackStatesAux->chi2[istate]);
387 case "pathLength"_hash:
388 return &(m_trackStatesAux->pathLength[istate]);
389 case "predicted"_hash:
390 return &(m_trackStatesAux->predicted[istate]);
391 case "filtered"_hash:
392 return &(m_trackStatesAux->filtered[istate]);
393 case "smoothed"_hash:
394 return &(m_trackStatesAux->smoothed[istate]);
395 case "projector"_hash: {
396 auto idx = m_trackStatesAux->calibrated[istate];
397 return &(m_trackMeasurementsAux->projector[idx]);
398 }
399 case "measdim"_hash:
400 return &(m_trackStatesAux->measDim[istate]);
401 case "typeFlags"_hash:
402 return &(m_trackStatesAux->typeFlags[istate]);
403
404 default: {
405 for (auto& d : m_decorations) {
406 if (d.hash == key) {
407 return d.setter(m_trackStatesAux.get(), istate, d.auxid);
408 }
409 }
410 throw std::runtime_error("MutableMultiTrajectory::component_impl no such component " + std::to_string(key));
411 }
412 }
413}
414
415
417 Acts::HashedString key,
418 ActsTrk::IndexType istate) const {
419 using namespace Acts::HashedStringLiteral;
420 assert(istate < m_trackStatesIface.size() &&
421 "Attempt to reach beyond the Track States container size");
422 INSPECTCALL(key << " " << istate << " const component_impl")
423 switch (key) {
424 case "previous"_hash:
425 return &(to_const_ptr(m_trackStatesAux)->previous[istate]);
426 case "next"_hash:
427 return &(to_const_ptr(m_trackStatesAux)->next[istate]);
428 case "chi2"_hash:
429 return &(to_const_ptr(m_trackStatesAux)->chi2[istate]);
430 case "pathLength"_hash:
431 return &(to_const_ptr(m_trackStatesAux)->pathLength[istate]);
432 case "predicted"_hash:
433 return &(to_const_ptr(m_trackStatesAux)->predicted[istate]);
434 case "filtered"_hash:
435 return &(to_const_ptr(m_trackStatesAux)->filtered[istate]);
436 case "smoothed"_hash:
437 return &(to_const_ptr(m_trackStatesAux)->smoothed[istate]);
438 case "jacobian"_hash:
439 return &(to_const_ptr(m_trackStatesAux)->jacobian[istate]);
440 case "projector"_hash:{
441 auto idx = to_const_ptr(m_trackStatesAux)->calibrated[istate];
442 return &(to_const_ptr(m_trackMeasurementsAux)->projector[idx]);
443 }
444 case "calibrated"_hash: {
445 return &(to_const_ptr(m_trackStatesAux)->calibrated[istate]);
446 }
447 case "calibratedCov"_hash: {
448 return &(to_const_ptr(m_trackStatesAux)->calibrated[istate]);
449 }
450 case "measdim"_hash:
451 return &(to_const_ptr(m_trackStatesAux)->measDim[istate]);
452 case "typeFlags"_hash:
453 return &(to_const_ptr(m_trackStatesAux)->typeFlags[istate]);
454 default: {
455 for (auto& d : m_decorations) {
456 if (d.hash == key) {
457 INSPECTCALL("getting dynamic variable " << d.name << " " << istate);
458 return d.getter(m_trackStatesAux.get(), istate, d.auxid);
459 }
460 }
461 throw std::runtime_error("MutableMultiTrajectory::component_impl const no such component " + std::to_string(key));
462 }
463 }
464}
465
467 Acts::HashedString key, ActsTrk::IndexType istate) const {
468 std::optional<bool> inTrackState = ::has_impl(m_trackStatesAux.get(), key, istate);
469 if (inTrackState.has_value())
470 return inTrackState.value();
471
472 // TODO remove once EL based source links are in use only
473 using namespace Acts::HashedStringLiteral;
474 if (key == "uncalibratedSourceLink"_hash){
475 INSPECTCALL(key << " " << istate << " uncalibratedSourceLink")
476 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
477 if (acc.isAvailable (m_trackStatesIface)) {
478 if (acc(m_trackStatesIface, istate) != nullptr) return true;
479 }
480
481 return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
482 }
483
484 for (auto& d : m_decorations) {
485 if (d.hash == key) {
486 INSPECTCALL(key << " " << istate << " d.name")
487 return true;
488 }
489 }
490
491 return false;
492}
493
495 INSPECTCALL(this);
496 m_trackStatesIface.resize(0);
498
499 m_trackParametersAux->resize(0);
501
502 m_trackJacobiansAux->resize(0);
504
505 m_trackMeasurementsAux->resize(0);
507
508 m_surfacesBackend->clear();
509 m_surfaces.clear();
512}
513
514
516 // Retrieve the calibrated measurement size
517 // INSPECTCALL(istate << " " << trackMeasurements().size());
518 return m_trackStatesAux->measDim[istate];
519}
520
521
523 const Acts::SourceLink& sourceLink) {
524 INSPECTCALL( istate );
525
527 static const Decor_t decor{"uncalibratedMeasurement"};
528 if (istate>= m_trackStatesIface.size()) {
529 throw std::range_error("istate out of range on TrackStates when attempting to access uncalibrated measurements");
530 }
531 Decor_t::span uncalibratedMeasurements = decor.getDecorationSpan(m_trackStatesIface);
532
533 // @TODO normally the source links should contain an xAOD::UncalibratedMeasurement pointer
534 // but in some cases some other payload is used e.g. when converting Trk::Tracks.
535 // Only UncalibratedMeasurement pointer can be stored in the xAOD backend. Everything
536 // else has to go into the cache.
537 // Currently there is no possibility to check whether the source link contains a certain payload
538 // so can only catch the bad any cast
539 try {
540 uncalibratedMeasurements.at(istate) = sourceLink.get<ATLASUncalibSourceLink>();
541 }
542 catch (std::bad_any_cast &err) {
543 assert( istate < m_uncalibratedSourceLinks.size());
544 m_uncalibratedSourceLinks[istate] = sourceLink;
545 }
546}
547
549 std::shared_ptr<const Acts::Surface> surface) {
550 if ( istate >= m_surfaces.size() )
551 m_surfaces.resize(istate+1, nullptr);
552
553 m_trackStatesAux->geometryId[istate] = surface->geometryId().value();
554 if (surface->geometryId().value() == 0) { // free surface, needs recording of properties
555 m_surfacesBackend->push_back(new xAOD::TrackSurface());
556 encodeSurface(m_surfacesBackendAux.get(), m_surfacesBackendAux->size()-1, surface.get(), m_geoContext.context());
557 m_trackStatesAux->surfaceIndex[istate] = m_surfacesBackend->size()-1;
558 m_surfaces[istate] = std::move(surface); // and memory management
559
560 } else {
561 m_surfaces[istate] = surface.get(); // no memory management, bare pointer
562 }
563 // store surface representation in
564}
565
566namespace {
567 const Acts::Surface* toSurfacePtr(const ActsTrk::StoredSurface& surfaceVariant) {
568 if ( std::holds_alternative<const Acts::Surface*>(surfaceVariant))
569 return std::get<const Acts::Surface*>(surfaceVariant);
570 return std::get<std::shared_ptr<const Acts::Surface>>(surfaceVariant).get();
571 }
572}
573
575 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");
576 return toSurfacePtr(m_surfaces[istate]);
577}
578
580 Acts::HashedString key,
581 const std::any& src_ptr) {
582 INSPECTCALL("copy dynamic decoration of key " << key << " destination MTJ has " << m_decorations.size() << " decorations");
584 INSPECTCALL("checking for destination of dynamic decoration " << d.name << " hash " << d.hash << " while looking for the key " << key);
585 if (d.hash == key) {
586 d.copier(m_trackStatesAux.get(), istate, d.auxid, src_ptr);
587 return;
588 }
589 }
590 throw std::invalid_argument("MultiTrajectory::copyDynamicFrom_impl no such decoration in destination MTJ " + std::to_string(key));
591}
592
593std::vector<Acts::HashedString> ActsTrk::MutableMultiTrajectory::dynamicKeys_impl() const {
594 std::vector<Acts::HashedString> keys;
596 keys.push_back(d.hash);
597 INSPECTCALL("collecting dynamic decoration " << d.name << " hash " << d.hash);
598 }
599 return keys;
600}
601
602
613
615// ReadOnly MTJ
632
644
645
646bool ActsTrk::MultiTrajectory::has_impl(Acts::HashedString key,
647 ActsTrk::IndexType istate) const {
648 // const auto& trackStates = *m_trackStates;
649 std::optional<bool> inTrackState = ::has_impl(m_trackStatesAux, key, istate);
650 if (inTrackState.has_value())
651 return inTrackState.value();
652 // TODO remove once EL based source links are in use only
653 using namespace Acts::HashedStringLiteral;
654 if (key == "uncalibratedSourceLink"_hash) {
655 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
656 if (acc.isAvailable (m_trackStatesIface)) {
657 return acc(m_trackStatesIface, istate) != nullptr;
658 }
659 else {
660 return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
661 }
662 }
663 return false;
664}
665
667 Acts::HashedString key, ActsTrk::IndexType istate) const {
668 using namespace Acts::HashedStringLiteral;
669 switch (key) {
670 case "previous"_hash:
671 return &(m_trackStatesAux->previous[istate]);
672 case "next"_hash:
673 return &(m_trackStatesAux->next[istate]);
674 case "chi2"_hash:
675 return &(m_trackStatesAux->chi2[istate]);
676 case "pathLength"_hash:
677 return &(m_trackStatesAux->pathLength[istate]);
678 case "predicted"_hash:
679 return &(m_trackStatesAux->predicted[istate]);
680 case "filtered"_hash:
681 return &(m_trackStatesAux->filtered[istate]);
682 case "smoothed"_hash:
683 return &(m_trackStatesAux->smoothed[istate]);
684 case "jacobian"_hash:
685 return &(m_trackStatesAux->jacobian[istate]);
686 case "projector"_hash: {
687 return &(m_trackMeasurementsAux->projector.at(m_trackStatesAux->calibrated[istate]));
688 }
689 case "calibrated"_hash: {
690 return &(m_trackStatesAux->calibrated[istate]);
691 }
692 case "calibratedCov"_hash: {
693 return &(m_trackStatesAux->calibrated[istate]);
694 }
695 case "measdim"_hash:
696 return &(m_trackStatesAux->measDim[istate]);
697 case "typeFlags"_hash:
698 return &(m_trackStatesAux->typeFlags[istate]);
699 default: {
700 for (auto& d : m_decorations) {
701 if (d.hash == key) {
702 // TODO the dynamic_cast will disappear
703 return d.getter(m_trackStatesAux.cptr(), istate, d.auxid);
704 }
705 }
706 throw std::runtime_error("MultiTrajectory::component_impl no such component " + std::to_string(key));
707 }
708 }
709}
710
712 Acts::HashedString key) const {
713 using namespace Acts::HashedStringLiteral;
714 // TODO try using staticVariables set
715 switch (key) {
716 case "previous"_hash:
717 case "next"_hash:
718 case "chi2"_hash:
719 case "pathLength"_hash:
720 case "predicted"_hash:
721 case "filtered"_hash:
722 case "smoothed"_hash:
723 case "jacobian"_hash:
724 case "projector"_hash:
725 case "uncalibratedSourceLink"_hash:
726 case "calibrated"_hash:
727 case "calibratedCov"_hash:
728 case "measdim"_hash:
729 case "typeFlags"_hash:
730 return true;
731 }
732 for (auto& d : m_decorations) {
733 if (d.hash == key) {
734 return true;
735 }
736 }
737 return false;
738}
739
744
748
749// TODO remove this implementation once tracking uses only sourceLinks with EL
754
755std::vector<Acts::HashedString> ActsTrk::MultiTrajectory::dynamicKeys_impl() const {
756 std::vector<Acts::HashedString> keys;
758 keys.push_back(d.hash);
759 }
760 return keys;
761}
762
763
764void ActsTrk::MultiTrajectory::fillSurfaces(const Acts::TrackingGeometry* geo) {
765 if ( not m_surfaces.empty() )
766 return;
767 m_surfaces.resize(m_trackStatesIface.size(), nullptr);
768 for ( IndexType i = 0; i < m_trackStatesIface.size(); i++ ) {
769 auto geoID = m_trackStatesAux->geometryId[i];
770 if ( geoID == InvalidGeoID ) {
771 m_surfaces[i] = nullptr;
772 continue;
773 }
774 if ( geoID != 0 ) {
775 m_surfaces[i] = geo->findSurface(Acts::GeometryIdentifier{geoID});
776 } else {
777 unsigned int backendIndex = m_trackStatesAux->surfaceIndex[i];
778 std::shared_ptr<const Acts::Surface> surface = decodeSurface(m_trackSurfacesAux, backendIndex);
779 m_surfaces[i] = surface; // TODO
780
781 }
782 }
783}
784
785
787 INSPECTCALL( this << " " << istate << " " << m_trackStatesIface.size() << " " << m_surfaces.size() << " surf ptr " << toSurfacePtr(m_surfaces[istate]));
788 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");
789 return toSurfacePtr(m_surfaces[istate]);
790}
791
792typename Acts::SourceLink
794 ActsTrk::IndexType istate) const {
795 assert(istate < m_trackStatesIface.size());
796 // at the moment when converting Trk::Track to Acts tracks the measurements on track
797 // are not converted to xAOD::UncalibratedMeasurements, and the Acts::SourceLinks
798 // just contain a pointer to the Trk::Measurement. To keep this functionality
799 // SourceLinks are either stored in the m_uncalibratedSourceLinks cache
800 // or taken from the xAOD backend.
801 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
802 if (const xAOD::UncalibratedMeasurement* ptr = acc.withDefault(m_trackStatesIface, istate, nullptr))
803 {
804 return Acts::SourceLink( ptr );
805 }
806 return m_uncalibratedSourceLinks[istate].value();
807}
808
809typename Acts::SourceLink
811 ActsTrk::IndexType istate) const {
812 assert(istate < m_trackStatesIface.size());
813 // at the moment when converting Trk::Track to Acts tracks the measurements on track
814 // are not converted to xAOD::UncalibratedMeasurements, and the Acts::SourceLinks
815 // just contain a pointer to the Trk::Measurement. To keep this functionality
816 // SourceLinks are either stored in the m_uncalibratedSourceLinks cache
817 // or taken from the xAOD backend.
818 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
819 if (const xAOD::UncalibratedMeasurement* ptr = acc.withDefault(m_trackStatesIface, istate, nullptr))
820 {
821 return Acts::SourceLink( ptr );
822 }
823 return m_uncalibratedSourceLinks[istate].value();
824}
const T * to_const_ptr(const std::unique_ptr< T > &ptr)
constexpr uint64_t InvalidGeoID
#define INSPECTCALL(_INFO)
std::vector< std::optional< Acts::SourceLink > > m_uncalibratedSourceLinks
bool has_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
const DataLink< xAOD::TrackParametersAuxContainer > m_trackParametersAux
Acts::SourceLink getUncalibratedSourceLink_impl(ActsTrk::IndexType istate) const
const DataLink< xAOD::TrackMeasurementAuxContainer > m_trackMeasurementsAux
std::vector< ActsTrk::detail::Decoration > m_decorations
xAOD::TrackStateContainer m_trackStatesIface
const DataLink< xAOD::TrackStateAuxContainer > m_trackStatesAux
std::vector< Acts::HashedString > dynamicKeys_impl() const
std::vector< std::optional< Acts::SourceLink > > m_calibratedSourceLinks
std::vector< StoredSurface > m_surfaces
ActsTrk::IndexType calibratedSize_impl(ActsTrk::IndexType istate) const
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
void moveSurfaces(const ActsTrk::MutableMultiTrajectory *mtj)
reuse surfaces from MutableMultiTrajectory
const Acts::Surface * referenceSurface_impl(IndexType) const
const DataLink< xAOD::TrackSurfaceAuxContainer > m_trackSurfacesAux
const DataLink< xAOD::TrackJacobianAuxContainer > m_trackJacobiansAux
MultiTrajectory(DataLink< xAOD::TrackStateAuxContainer > trackStates, DataLink< xAOD::TrackParametersAuxContainer > trackParameters, DataLink< xAOD::TrackJacobianAuxContainer > trackJacobians, DataLink< xAOD::TrackMeasurementAuxContainer > trackMeasurements, DataLink< xAOD::TrackSurfaceAuxContainer > trackSurfaces)
void fillSurfaces(const Acts::TrackingGeometry *geo)
Fill surfaces either from persistency or from geometry If the surfaces are already there it means tha...
void moveLinks(const ActsTrk::MutableMultiTrajectory *mtj)
bool hasColumn_impl(Acts::HashedString key) const
Athena implementation of ACTS::MultiTrajectory (ReadWrite version) The data is stored in 4 external b...
std::vector< StoredSurface > m_surfaces
static const std::set< std::string > s_staticVariables
std::vector< std::optional< Acts::SourceLink > > m_calibratedSourceLinks
bool has_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
checks if given state has requested component
std::vector< ActsTrk::detail::Decoration > m_decorations
Acts::SourceLink getUncalibratedSourceLink_impl(ActsTrk::IndexType istate) const
Implementation of uncalibrated link fetch.
void setReferenceSurface_impl(IndexType, std::shared_ptr< const Acts::Surface >)
std::unique_ptr< xAOD::TrackParametersAuxContainer > m_trackParametersAux
ActsTrk::IndexType addTrackState_impl(Acts::TrackStatePropMask mask, ActsTrk::IndexType iprevious)
Add state with stograge for data that depends on the mask.
void unset_impl(Acts::TrackStatePropMask target, ActsTrk::IndexType istate)
unsets a given state
std::any component_impl(Acts::HashedString key, ActsTrk::IndexType istate) const
Access component by key.
MutableMultiTrajectory()
Construct a new Multi Trajectory object owning backends.
xAOD::TrackStateContainer m_trackStatesIface
std::vector< Acts::HashedString > dynamicKeys_impl() const
returns the keys of all the dynamic columns
std::unique_ptr< xAOD::TrackStateAuxContainer > m_trackStatesAux
std::unique_ptr< xAOD::TrackSurfaceAuxContainer > m_surfacesBackendAux
const Acts::Surface * referenceSurface_impl(IndexType) const
std::vector< std::optional< Acts::SourceLink > > m_uncalibratedSourceLinks
std::unique_ptr< xAOD::TrackMeasurementAuxContainer > m_trackMeasurementsAux
void addTrackStateComponents_impl(ActsTrk::IndexType istate, Acts::TrackStatePropMask mask)
Add state components for the given mask.
void copyDynamicFrom_impl(ActsTrk::IndexType istate, Acts::HashedString key, const std::any &src_ptr)
copy dynamic data from another MTJ
std::unique_ptr< xAOD::TrackSurfaceContainer > m_surfacesBackend
bool has_backends() const
checks if the backends are connected (i.e.
void shareFrom_impl(ActsTrk::IndexType iself, ActsTrk::IndexType iother, Acts::TrackStatePropMask shareSource, Acts::TrackStatePropMask shareTarget)
shares from a given state
ActsTrk::IndexType calibratedSize_impl(ActsTrk::IndexType istate) const
Implementation of calibrated size.
std::unique_ptr< xAOD::TrackJacobianAuxContainer > m_trackJacobiansAux
void setUncalibratedSourceLink_impl(ActsTrk::IndexType istate, const Acts::SourceLink &sourceLink)
Implementation of uncalibrated link insertion.
void clear_impl()
clears backends decoration columns are still declared
Helper class to provide constant type-safe access to aux data.
Helper class to provide type-safe access to aux data.
Definition Decorator.h:59
span getDecorationSpan(const AuxVectorData &container) const
Get a span over the auxilary data array.
std::vector< TrackStateIndexType > measDim
std::vector< TrackStateIndexType > filtered
std::vector< TrackStateIndexType > calibrated
std::vector< TrackStateIndexType > smoothed
std::vector< TrackStateIndexType > predicted
std::vector< TrackStateIndexType > jacobian
std::vector< TrackStateIndexType > previous
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
std::vector< Decoration > restoreDecorations(const SG::IConstAuxStore *container, const std::set< std::string > &staticVariables)
void encodeSurface(xAOD::TrackSurfaceAuxContainer *backend, size_t index, const Acts::Surface *surface, const Acts::GeometryContext &geoContext)
Prepares persistifiable representation of surface into xAOD::TrackSurface object.
std::shared_ptr< const Acts::Surface > decodeSurface(const xAOD::TrackSurface *backend)
Creates transient Acts Surface objects given a surface backend implementation should be exact mirror ...
std::variant< const Acts::Surface *, std::shared_ptr< const Acts::Surface > > StoredSurface
std::uint32_t IndexType
Definition Decoration.h:14
const xAOD::UncalibratedMeasurement * ATLASUncalibSourceLink
STL namespace.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
TrackStateAuxContainer_v1 TrackStateAuxContainer
TrackSurface_v1 TrackSurface
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.