ATLAS Offline Software
Loading...
Searching...
No Matches
MultiTrajectory.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5#include <Acts/Geometry/GeometryIdentifier.hpp>
13
14
15constexpr uint64_t InvalidGeoID = std::numeric_limits<uint64_t>::max();
16
17namespace {
18constexpr std::optional<bool> has_impl(
19 const xAOD::TrackStateAuxContainer* trackStates, Acts::HashedString key,
20 ActsTrk::IndexType istate) {
21 using namespace Acts::HashedStringLiteral;
22 constexpr auto kInvalid = Acts::kTrackIndexInvalid;
23 INSPECTCALL(key << " " << istate);
24
25 switch (key) {
26 case "previous"_hash:
27 return trackStates->previous[istate] < kInvalid;
28 case "chi2"_hash:{
29 INSPECTCALL(key << " " << istate << " chi2");
30 return true;
31 }
32 case "pathLength"_hash:{
33 INSPECTCALL(key << " " << istate << " pathLength");
34 return true;
35 }
36 case "typeFlags"_hash:{
37 INSPECTCALL(key << " " << istate << " type flags");
38 return true;
39 }
40 case "predicted"_hash:{
41 INSPECTCALL(key << " " << istate << " predicted");
42 return trackStates->predicted[istate] < kInvalid;
43 }
44 case "filtered"_hash:{
45 INSPECTCALL(key << " " << istate << " filtered");
46 return trackStates->filtered[istate] < kInvalid;
47 }
48 case "smoothed"_hash:{
49 INSPECTCALL(key << " " << istate << " smoothed");
50 return trackStates->smoothed[istate] < kInvalid;
51 }
52 case "jacobian"_hash:{
53 INSPECTCALL(key << " " << istate << " jacobian");
54 return trackStates->jacobian[istate] < kInvalid;
55 }
56 case "projector"_hash:{
57 INSPECTCALL(key << " " << istate << " projector");
58 return trackStates->calibrated[istate] < kInvalid;
59 }
60 case "calibrated"_hash:{
61 INSPECTCALL(key << " " << istate << " calibrated");
62 return trackStates->measDim[istate] < kInvalid;
63 }
64 case "calibratedCov"_hash: {
65 INSPECTCALL(key << " " << istate << " calibratedCov");
66 return trackStates->measDim[istate] < kInvalid;
67 }
68 case "measdim"_hash: {
69 INSPECTCALL(key << " " << istate << " measdim");
70 return true;
71 }
72 case "referenceSurface"_hash: {
73 INSPECTCALL(key << " " << istate << " referenceSurfaceEnco");
74 return true;
75 }
76
77 // TODO restore once only the EL Source Links are in use
78 // return !trackStates[istate]->uncalibratedMeasurementLink().isDefault();
79 }
80 INSPECTCALL(key << " " << istate << " not a predefined component");
81 return std::optional<bool>();
82}
83}
84
85
86template<typename T>
87const T* to_const_ptr(const std::unique_ptr<T>& ptr) {
88 return ptr.get();
89}
90
91
92
93namespace ActsTrk{
94
95const std::set<std::string> MutableMultiTrajectory::s_staticVariables = {
96 "chi2", "pathLength", "typeFlags", "previous", "next", "predicted", "filtered", "smoothed", "jacobian", "calibrated", "measDim",
97 "uncalibratedMeasurement", "uncalibratedMeasurementLink" /*created by converter*/, "geometryId", "surfaceIndex"
98 };
99
100
102 : m_trackStatesAux (std::make_unique<xAOD::TrackStateAuxContainer>()),
103 m_trackParametersAux (std::make_unique<xAOD::TrackParametersAuxContainer>()),
104 m_trackJacobiansAux (std::make_unique<xAOD::TrackJacobianAuxContainer>()),
105 m_trackMeasurementsAux (std::make_unique<xAOD::TrackMeasurementAuxContainer>()),
106 m_surfacesBackend (std::make_unique<xAOD::TrackSurfaceContainer>()),
107 m_surfacesBackendAux (std::make_unique<xAOD::TrackSurfaceAuxContainer>())
108{
109 INSPECTCALL("c-tor " << this)
110
112 m_trackStatesIface.setStore(m_trackStatesAux.get());
113
114}
115
118 {
119 INSPECTCALL("copy c-tor " << this << " src " << &other << " " << other.size())
120
121 *m_trackStatesAux = *other.m_trackStatesAux;
122 *m_trackParametersAux = *other.m_trackParametersAux;
123 *m_trackJacobiansAux = *other.m_trackJacobiansAux;
124 *m_trackMeasurementsAux = *other.m_trackMeasurementsAux;
125 m_decorations = other.m_decorations;
126 m_calibratedSourceLinks = other.m_calibratedSourceLinks;
127 m_uncalibratedSourceLinks = other.m_uncalibratedSourceLinks;
128
129 m_surfaces = other.m_surfaces;
130 m_geoContext = other.m_geoContext;
131 m_trackStatesIface.resize(m_trackStatesAux->size());
132 INSPECTCALL("copy c-tor done")
133}
134
135std::string_view MutableMultiTrajectory::columnName_impl(Acts::HashedString key) const {
136 for (auto& d : m_decorations) {
137 if (d.hash == key) {
138 return d.name;
139 }
140 }
141 throw std::runtime_error(std::format("{:}() - Key is unknown {:}",__func__, key));
142 return "";
143}
144const std::type_info& MutableMultiTrajectory::columnDataType_impl(Acts::HashedString key) const {
145 for (auto& d : m_decorations) {
146 if (d.hash == key) {
147 return *SG::AuxTypeRegistry::instance().getType(d.auxid);
148 }
149 }
150 throw std::runtime_error(std::format("{:}() - Key is unknown {:}",__func__, key));
151 return typeid(const void*);
152}
153
155 return m_trackStatesAux != nullptr and m_trackParametersAux != nullptr and
156 m_trackJacobiansAux != nullptr and m_trackMeasurementsAux != nullptr
157 and m_surfacesBackend != nullptr;
158}
159void MutableMultiTrajectory::ensureDynamicColumns_impl(const Acts::ConstVectorMultiTrajectory& /*other*/) {
160#ifdef ACTIVATE_LATER
161 ensureDynamicColumns(m_excluded, other, *this);
162#endif
163}
164void MutableMultiTrajectory::excludeDecoration(std::string_view decorName) {
165 m_excluded.insert(Acts::hashStringDynamic(decorName));
166}
167
168namespace{
169 template<typename CONT>
170 void stepResize( CONT* auxPtr, const size_t realSize, const size_t sizeStep = 20) {
171 if( realSize >= auxPtr->size() ) auxPtr->resize(auxPtr->size()+sizeStep);
172 }
173}
174
176 Acts::TrackStatePropMask mask,
177 IndexType previous) {
178 using namespace Acts::HashedStringLiteral;
179 INSPECTCALL( this << " " << mask << " " << m_trackStatesIface.size() << " " << previous);
180 assert(m_trackStatesAux && "Missing Track States backend");
182 m_surfaces.push_back(nullptr);
183
184 // set kInvalid
185 constexpr auto kInvalid = Acts::kTrackIndexInvalid;
186
187 if (previous >= kInvalid - 1)
188 previous = kInvalid; // fix needed in Acts::MTJ
189 m_trackStatesAux->previous[m_trackStatesSize] = previous;
190 using namespace Acts;
191
192 auto addParam = [this]() -> IndexType {
193 stepResize(m_trackParametersAux.get(), m_trackParametersSize, 60);
194 // TODO ask AK if this resize could be method of aux container
195 m_trackParametersAux->params[m_trackParametersSize].resize(Acts::eBoundSize);
196 m_trackParametersAux->covMatrix[m_trackParametersSize].resize(Acts::eBoundSize*Acts::eBoundSize);
198 return m_trackParametersSize-1;
199 };
200
201 auto addJacobian = [this]() -> IndexType {
202 stepResize(m_trackJacobiansAux.get(), m_trackJacobiansSize);
203 m_trackJacobiansAux->jac[m_trackJacobiansSize].resize(Acts::eBoundSize*Acts::eBoundSize);
205 return m_trackJacobiansSize-1;
206 };
207
208 auto addMeasurement = [this]() -> IndexType {
210 m_trackMeasurementsAux->meas[m_trackMeasurementsSize].resize(Acts::eBoundSize);
211 m_trackMeasurementsAux->covMatrix[m_trackMeasurementsSize].resize(Acts::eBoundSize*Acts::eBoundSize);
214 };
215
216 m_trackStatesAux->predicted[m_trackStatesSize] = kInvalid;
217 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Predicted)) {
218 m_trackStatesAux->predicted[m_trackStatesSize] = addParam();
219 }
220
221 m_trackStatesAux->filtered[m_trackStatesSize] = kInvalid;
222 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Filtered)) {
223 m_trackStatesAux->filtered[m_trackStatesSize] = addParam();
224 }
225
226 m_trackStatesAux->smoothed[m_trackStatesSize] = kInvalid;
227 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Smoothed)) {
228 m_trackStatesAux->smoothed[m_trackStatesSize] = addParam();
229 }
230
231 m_trackStatesAux->jacobian[m_trackStatesSize] = kInvalid;
232 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Jacobian)) {
233 m_trackStatesAux->jacobian[m_trackStatesSize] = addJacobian();
234 }
235
236 m_uncalibratedSourceLinks.emplace_back(std::nullopt);
237 m_trackStatesAux->calibrated[m_trackStatesSize] = kInvalid;
238 m_trackStatesAux->measDim[m_trackStatesSize] = kInvalid;
239 // @TODO uncalibrated ?
240 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Calibrated)) {
241 m_trackStatesAux->calibrated.at(m_trackStatesSize) = addMeasurement();
242 m_calibratedSourceLinks.emplace_back(std::nullopt);
243 }
244
245 m_trackStatesAux->geometryId[m_trackStatesSize] = InvalidGeoID; // surface is invalid until set
247 return m_trackStatesSize-1;
248}
249
250
252 IndexType istate,
253 Acts::TrackStatePropMask mask) {
254 using namespace Acts::HashedStringLiteral;
255 INSPECTCALL( this << " " << mask << " " << m_trackStatesIface.size() << " " << istate);
256
257 assert(m_trackStatesAux && "Missing Track States backend");
258
259 // set kInvalid
260 constexpr auto kInvalid = Acts::kTrackIndexInvalid;
261
262 using namespace Acts;
263
264 auto addParam = [this]() -> IndexType {
265 stepResize(m_trackParametersAux.get(), m_trackParametersSize, 60);
266 // TODO ask AK if this resize could be method of aux container
267 m_trackParametersAux->params[m_trackParametersSize].resize(Acts::eBoundSize);
268 m_trackParametersAux->covMatrix[m_trackParametersSize].resize(Acts::eBoundSize*Acts::eBoundSize);
270 return m_trackParametersSize-1;
271 };
272
273 auto addJacobian = [this]() -> IndexType {
274 stepResize(m_trackJacobiansAux.get(), m_trackJacobiansSize);
275 m_trackJacobiansAux->jac[m_trackJacobiansSize].resize(Acts::eBoundSize*Acts::eBoundSize);
277 return m_trackJacobiansSize-1;
278 };
279
280 auto addMeasurement = [this]() -> IndexType {
282 m_trackMeasurementsAux->meas[m_trackMeasurementsSize].resize(Acts::eBoundSize);
283 m_trackMeasurementsAux->covMatrix[m_trackMeasurementsSize].resize(Acts::eBoundSize*Acts::eBoundSize);
286 };
287
288 if ((m_trackStatesAux->predicted[istate] == kInvalid) &&
289 ACTS_CHECK_BIT(mask, TrackStatePropMask::Predicted)) {
290 m_trackStatesAux->predicted[istate] = addParam();
291 }
292
293 if ((m_trackStatesAux->filtered[istate] == kInvalid) &&
294 ACTS_CHECK_BIT(mask, TrackStatePropMask::Filtered)) {
295 m_trackStatesAux->filtered[istate] = addParam();
296 }
297
298 if ((m_trackStatesAux->smoothed[istate] == kInvalid) &&
299 ACTS_CHECK_BIT(mask, TrackStatePropMask::Smoothed)) {
300 m_trackStatesAux->smoothed[istate] = addParam();
301 }
302
303 if ((m_trackStatesAux->jacobian[istate] == kInvalid) &&
304 ACTS_CHECK_BIT(mask, TrackStatePropMask::Jacobian)) {
305 m_trackStatesAux->jacobian[istate] = addJacobian();
306 }
307
308 if ((m_trackStatesAux->calibrated[istate] == kInvalid) &&
309 ACTS_CHECK_BIT(mask, TrackStatePropMask::Calibrated)) {
310 m_trackStatesAux->calibrated[istate] = addMeasurement();
311 m_calibratedSourceLinks.emplace_back(std::nullopt);
312 }
313}
314
315
317 IndexType iself,
318 IndexType iother,
319 Acts::TrackStatePropMask shareSource,
320 Acts::TrackStatePropMask shareTarget) {
321
322 assert(ACTS_CHECK_BIT(this->getTrackState(iother).getMask(), shareSource) &&
323 "Source has incompatible allocation");
324
325 using PM = Acts::TrackStatePropMask;
326 // set kInvalid
327 constexpr auto kInvalid = Acts::kTrackIndexInvalid;
328
329 IndexType sourceIndex{kInvalid};
330 switch (shareSource) {
331 case PM::Predicted:
332 sourceIndex = m_trackStatesAux->predicted[iother];
333 break;
334 case PM::Filtered:
335 sourceIndex = m_trackStatesAux->filtered[iother];
336 break;
337 case PM::Smoothed:
338 sourceIndex = m_trackStatesAux->smoothed[iother];
339 break;
340 case PM::Jacobian:
341 sourceIndex = m_trackStatesAux->jacobian[iother];
342 break;
343 default:
344 throw std::domain_error{"MutableMultiTrajectory Unable to share this component"};
345 }
346
347 assert(sourceIndex != kInvalid);
348
349 switch (shareTarget) {
350 case PM::Predicted:
351 assert(shareSource != PM::Jacobian);
352 m_trackStatesAux->predicted[iself] = sourceIndex;
353 break;
354 case PM::Filtered:
355 assert(shareSource != PM::Jacobian);
356 m_trackStatesAux->filtered[iself] = sourceIndex;
357 break;
358 case PM::Smoothed:
359 assert(shareSource != PM::Jacobian);
360 m_trackStatesAux->smoothed[iself] = sourceIndex;
361 break;
362 case PM::Jacobian:
363 assert(shareSource == PM::Jacobian);
364 m_trackStatesAux->jacobian[iself] = sourceIndex;
365 break;
366 default:
367 throw std::domain_error{"MutableMultiTrajectory Unable to share this component"};
368 }
369}
370
371
373 Acts::TrackStatePropMask target,
374 IndexType istate) {
375
376 using PM = Acts::TrackStatePropMask;
377 // set kInvalid
378 constexpr auto kInvalid = Acts::kTrackIndexInvalid;
379
380 switch (target) {
381 case PM::Predicted:
382 m_trackStatesAux->predicted[istate] = kInvalid;
383 break;
384 case PM::Filtered:
385 m_trackStatesAux->filtered[istate] = kInvalid;
386
387 break;
388 case PM::Smoothed:
389 m_trackStatesAux->smoothed[istate] = kInvalid;
390 break;
391 case PM::Jacobian:
392 m_trackStatesAux->jacobian[istate] = kInvalid;
393
394 break;
395 case PM::Calibrated:
396 m_trackStatesAux->measDim[istate] = kInvalid;
397 // TODO here m_measOffset[istate] and m_measCovOffset[istate] should be
398 // set to kInvalid
399
400 break;
401 default:
402 throw std::domain_error{"MutableMultiTrajectory Unable to unset this component"};
403 }
404}
405
407 Acts::HashedString key, IndexType istate) {
408 using namespace Acts::HashedStringLiteral;
409 assert(istate < m_trackStatesIface.size() &&
410 "Attempt to reach beyond the Track States container size");
411 INSPECTCALL(key << " " << istate << " non-const component_impl")
412
413 switch (key) {
414 case "previous"_hash:
415 return &(m_trackStatesAux->previous[istate]);
416 case "next"_hash:
417 return &(m_trackStatesAux->next[istate]);
418 case "chi2"_hash:
419 return &(m_trackStatesAux->chi2[istate]);
420 case "pathLength"_hash:
421 return &(m_trackStatesAux->pathLength[istate]);
422 case "predicted"_hash:
423 return &(m_trackStatesAux->predicted[istate]);
424 case "filtered"_hash:
425 return &(m_trackStatesAux->filtered[istate]);
426 case "smoothed"_hash:
427 return &(m_trackStatesAux->smoothed[istate]);
428 case "projector"_hash: {
429 auto idx = m_trackStatesAux->calibrated[istate];
430 return &(m_trackMeasurementsAux->projector[idx]);
431 }
432 case "measdim"_hash:
433 return &(m_trackStatesAux->measDim[istate]);
434 case "typeFlags"_hash:
435 return &(m_trackStatesAux->typeFlags[istate]);
436
437 default: {
438 for (auto& d : m_decorations) {
439 if (d.hash == key) {
440 return d.setter(m_trackStatesAux.get(), istate, d.auxid);
441 }
442 }
443 throw std::runtime_error("MutableMultiTrajectory::component_impl no such component " + std::to_string(key));
444 }
445 }
446}
447
448
450 Acts::HashedString key,
451 IndexType istate) const {
452 using namespace Acts::HashedStringLiteral;
453 assert(istate < m_trackStatesIface.size() &&
454 "Attempt to reach beyond the Track States container size");
455 INSPECTCALL(key << " " << istate << " const component_impl")
456 switch (key) {
457 case "previous"_hash:
458 return &(to_const_ptr(m_trackStatesAux)->previous[istate]);
459 case "next"_hash:
460 return &(to_const_ptr(m_trackStatesAux)->next[istate]);
461 case "chi2"_hash:
462 return &(to_const_ptr(m_trackStatesAux)->chi2[istate]);
463 case "pathLength"_hash:
464 return &(to_const_ptr(m_trackStatesAux)->pathLength[istate]);
465 case "predicted"_hash:
466 return &(to_const_ptr(m_trackStatesAux)->predicted[istate]);
467 case "filtered"_hash:
468 return &(to_const_ptr(m_trackStatesAux)->filtered[istate]);
469 case "smoothed"_hash:
470 return &(to_const_ptr(m_trackStatesAux)->smoothed[istate]);
471 case "jacobian"_hash:
472 return &(to_const_ptr(m_trackStatesAux)->jacobian[istate]);
473 case "projector"_hash:{
474 auto idx = to_const_ptr(m_trackStatesAux)->calibrated[istate];
475 return &(to_const_ptr(m_trackMeasurementsAux)->projector[idx]);
476 }
477 case "calibrated"_hash: {
478 return &(to_const_ptr(m_trackStatesAux)->calibrated[istate]);
479 }
480 case "calibratedCov"_hash: {
481 return &(to_const_ptr(m_trackStatesAux)->calibrated[istate]);
482 }
483 case "measdim"_hash:
484 return &(to_const_ptr(m_trackStatesAux)->measDim[istate]);
485 case "typeFlags"_hash:
486 return &(to_const_ptr(m_trackStatesAux)->typeFlags[istate]);
487 default: {
488 for (auto& d : m_decorations) {
489 if (d.hash == key) {
490 INSPECTCALL("getting dynamic variable " << d.name << " " << istate);
491 return d.getter(m_trackStatesAux.get(), istate, d.auxid);
492 }
493 }
494 throw std::runtime_error("MutableMultiTrajectory::component_impl const no such component " + std::to_string(key));
495 }
496 }
497}
498
500 Acts::HashedString key, IndexType istate) const {
501 std::optional<bool> inTrackState = ::has_impl(m_trackStatesAux.get(), key, istate);
502 if (inTrackState.has_value())
503 return inTrackState.value();
504
505 // TODO remove once EL based source links are in use only
506 using namespace Acts::HashedStringLiteral;
507 if (key == "uncalibratedSourceLink"_hash){
508 INSPECTCALL(key << " " << istate << " uncalibratedSourceLink")
509 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
510 if (acc.isAvailable (m_trackStatesIface)) {
511 if (acc(m_trackStatesIface, istate) != nullptr) return true;
512 }
513
514 return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
515 }
516
517 for (auto& d : m_decorations) {
518 if (d.hash == key) {
519 INSPECTCALL(key << " " << istate << " d.name")
520 return true;
521 }
522 }
523
524 return false;
525}
526
528 INSPECTCALL(this);
529 m_trackStatesIface.resize(0);
531
532 m_trackParametersAux->resize(0);
534
535 m_trackJacobiansAux->resize(0);
537
538 m_trackMeasurementsAux->resize(0);
540
541 m_surfacesBackend->clear();
542 m_surfaces.clear();
545}
546
547
549 // Retrieve the calibrated measurement size
550 // INSPECTCALL(istate << " " << trackMeasurements().size());
551 return m_trackStatesAux->measDim[istate];
552}
553
554
556 const Acts::SourceLink& sourceLink) {
557 INSPECTCALL( istate );
558
560 static const Decor_t decor{"uncalibratedMeasurement"};
561 if (istate>= m_trackStatesIface.size()) {
562 throw std::range_error("istate out of range on TrackStates when attempting to access uncalibrated measurements");
563 }
564 Decor_t::span uncalibratedMeasurements = decor.getDecorationSpan(m_trackStatesIface);
565
566 // @TODO normally the source links should contain an xAOD::UncalibratedMeasurement pointer
567 // but in some cases some other payload is used e.g. when converting Trk::Tracks.
568 // Only UncalibratedMeasurement pointer can be stored in the xAOD backend. Everything
569 // else has to go into the cache.
570 // Currently there is no possibility to check whether the source link contains a certain payload
571 // so can only catch the bad any cast
572 try {
574 auto unpacked = detail::MeasurementCalibratorBase::unpackBase(sourceLink);
575 uncalibratedMeasurements.at(istate) = std::get<const xAOD::UncalibratedMeasurement*>(unpacked);
576 } else {
577 assert( istate < m_uncalibratedSourceLinks.size());
578 m_uncalibratedSourceLinks[istate] = sourceLink;
579 }
580 } catch (const std::bad_any_cast &err) {
581 try {
582 auto unpacked = sourceLink.get<const xAOD::UncalibratedMeasurement*>();
583 uncalibratedMeasurements.at(istate) = unpacked;
584 } catch (const std::bad_any_cast &err1) {
585 assert( istate < m_uncalibratedSourceLinks.size());
586 m_uncalibratedSourceLinks[istate] = sourceLink;
587 }
588 }
589}
590
592 std::shared_ptr<const Acts::Surface> surface) {
593 if ( istate >= m_surfaces.size() )
594 m_surfaces.resize(istate+1, nullptr);
595
596 m_trackStatesAux->geometryId[istate] = surface->geometryId().value();
597 if (surface->geometryId().value() == 0) { // free surface, needs recording of properties
598 m_surfacesBackend->push_back(new xAOD::TrackSurface());
599 encodeSurface(m_surfacesBackendAux.get(), m_surfacesBackendAux->size()-1, surface.get(), m_geoContext.context());
600 m_trackStatesAux->surfaceIndex[istate] = m_surfacesBackend->size()-1;
601 m_surfaces[istate] = std::move(surface); // and memory management
602
603 } else {
604 m_surfaces[istate] = surface.get(); // no memory management, bare pointer
605 }
606 // store surface representation in
607}
608
609namespace {
610 const Acts::Surface* toSurfacePtr(const StoredSurface& surfaceVariant) {
611 if ( std::holds_alternative<const Acts::Surface*>(surfaceVariant))
612 return std::get<const Acts::Surface*>(surfaceVariant);
613 return std::get<std::shared_ptr<const Acts::Surface>>(surfaceVariant).get();
614 }
615}
616
618 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");
619 return toSurfacePtr(m_surfaces[istate]);
620}
621
623 Acts::HashedString key,
624 const std::any& src_ptr) {
625 if (m_excluded.count(key)) { return; }
626 INSPECTCALL("copy dynamic decoration of key " << key << " destination MTJ has " << m_decorations.size() << " decorations");
627 for (const detail::Decoration& d : m_decorations) {
628 INSPECTCALL("checking for destination of dynamic decoration " << d.name << " hash " << d.hash << " while looking for the key " << key);
629 if (d.hash == key) {
630 d.copier(m_trackStatesAux.get(), istate, d.auxid, src_ptr);
631 return;
632 }
633 }
634 throw std::invalid_argument("MultiTrajectory::copyDynamicFrom_impl no such decoration in destination MTJ " + std::to_string(key));
635}
636
637std::vector<Acts::HashedString> MutableMultiTrajectory::dynamicKeys_impl() const {
638 std::vector<Acts::HashedString> keys;
639 for ( const detail::Decoration& d: m_decorations) {
640 keys.push_back(d.hash);
641 INSPECTCALL("collecting dynamic decoration " << d.name << " hash " << d.hash);
642 }
643 return keys;
644}
645
646
649 static const SG::Decorator<const xAOD::UncalibratedMeasurement*> decor{"uncalibratedMeasurement"};
650 if (m_trackStatesSize > 0) {
651 (void)decor.getDecorationSpan(m_trackStatesIface);
652 }
656}
657
659// ReadOnly MTJ
666 : m_trackStatesAux(trackStates),
667 m_trackParametersAux(trackParameters),
668 m_trackJacobiansAux(trackJacobians),
669 m_trackMeasurementsAux(trackMeasurements),
670 m_trackSurfacesAux(trackSurfaces),
671 m_trackStatesIface (trackStates->size()) {
672 m_trackStatesIface.setStore (trackStates.cptr());
673 INSPECTCALL("ctor from backends" << this << " " << m_trackStatesIface.size());
675}
676
688
689
690bool MultiTrajectory::has_impl(Acts::HashedString key,
691 IndexType istate) const {
692 // const auto& trackStates = *m_trackStates;
693 std::optional<bool> inTrackState = ::has_impl(m_trackStatesAux, key, istate);
694 if (inTrackState.has_value())
695 return inTrackState.value();
696 // TODO remove once EL based source links are in use only
697 using namespace Acts::HashedStringLiteral;
698 if (key == "uncalibratedSourceLink"_hash) {
699 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
700 if (acc.isAvailable (m_trackStatesIface)) {
701 return acc(m_trackStatesIface, istate) != nullptr;
702 }
703 else {
704 return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
705 }
706 }
707 return false;
708}
709
711 Acts::HashedString key, IndexType istate) const {
712 using namespace Acts::HashedStringLiteral;
713 switch (key) {
714 case "previous"_hash:
715 return &(m_trackStatesAux->previous[istate]);
716 case "next"_hash:
717 return &(m_trackStatesAux->next[istate]);
718 case "chi2"_hash:
719 return &(m_trackStatesAux->chi2[istate]);
720 case "pathLength"_hash:
721 return &(m_trackStatesAux->pathLength[istate]);
722 case "predicted"_hash:
723 return &(m_trackStatesAux->predicted[istate]);
724 case "filtered"_hash:
725 return &(m_trackStatesAux->filtered[istate]);
726 case "smoothed"_hash:
727 return &(m_trackStatesAux->smoothed[istate]);
728 case "jacobian"_hash:
729 return &(m_trackStatesAux->jacobian[istate]);
730 case "projector"_hash: {
731 return &(m_trackMeasurementsAux->projector.at(m_trackStatesAux->calibrated[istate]));
732 }
733 case "calibrated"_hash: {
734 return &(m_trackStatesAux->calibrated[istate]);
735 }
736 case "calibratedCov"_hash: {
737 return &(m_trackStatesAux->calibrated[istate]);
738 }
739 case "measdim"_hash:
740 return &(m_trackStatesAux->measDim[istate]);
741 case "typeFlags"_hash:
742 return &(m_trackStatesAux->typeFlags[istate]);
743 default: {
744 for (auto& d : m_decorations) {
745 if (d.hash == key) {
746 // TODO the dynamic_cast will disappear
747 return d.getter(m_trackStatesAux.cptr(), istate, d.auxid);
748 }
749 }
750 throw std::runtime_error("MultiTrajectory::component_impl no such component " + std::to_string(key));
751 }
752 }
753}
754
756 Acts::HashedString key) const {
757 using namespace Acts::HashedStringLiteral;
758 // TODO try using staticVariables set
759 switch (key) {
760 case "previous"_hash:
761 case "next"_hash:
762 case "chi2"_hash:
763 case "pathLength"_hash:
764 case "predicted"_hash:
765 case "filtered"_hash:
766 case "smoothed"_hash:
767 case "jacobian"_hash:
768 case "projector"_hash:
769 case "uncalibratedSourceLink"_hash:
770 case "calibrated"_hash:
771 case "calibratedCov"_hash:
772 case "measdim"_hash:
773 case "typeFlags"_hash:
774 return true;
775 }
776 for (auto& d : m_decorations) {
777 if (d.hash == key) {
778 return true;
779 }
780 }
781 return false;
782}
783
784
785
788 return m_trackStatesAux->measDim[istate];
789}
790
792 m_surfaces = std::move(mtj->m_surfaces);
793}
794
795// TODO remove this implementation once tracking uses only sourceLinks with EL
800
801std::vector<Acts::HashedString> MultiTrajectory::dynamicKeys_impl() const {
802 std::vector<Acts::HashedString> keys;
803 for ( const detail::Decoration& d: m_decorations) {
804 keys.push_back(d.hash);
805 }
806 return keys;
807}
808
809
810void MultiTrajectory::fillSurfaces(const Acts::TrackingGeometry* geo) {
811 if ( not m_surfaces.empty() )
812 return;
813 m_surfaces.resize(m_trackStatesIface.size(), nullptr);
814 for ( IndexType i = 0; i < m_trackStatesIface.size(); i++ ) {
815 auto geoID = m_trackStatesAux->geometryId[i];
816 if ( geoID == InvalidGeoID ) {
817 m_surfaces[i] = nullptr;
818 continue;
819 }
820 if ( geoID != 0 ) {
821 m_surfaces[i] = geo->findSurface(Acts::GeometryIdentifier{geoID});
822 } else {
823 unsigned int backendIndex = m_trackStatesAux->surfaceIndex[i];
824 std::shared_ptr<const Acts::Surface> surface = decodeSurface(m_trackSurfacesAux, backendIndex);
825 m_surfaces[i] = surface; // TODO
826
827 }
828 }
829}
830
831
832const Acts::Surface* MultiTrajectory::referenceSurface_impl(IndexType istate) const {
833 INSPECTCALL( this << " " << istate << " " << m_trackStatesIface.size() << " " << m_surfaces.size() << " surf ptr " << toSurfacePtr(m_surfaces[istate]));
834 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");
835 return toSurfacePtr(m_surfaces[istate]);
836}
837
838typename Acts::SourceLink
840 IndexType istate) const {
841 assert(istate < m_trackStatesIface.size());
842 // at the moment when converting Trk::Track to Acts tracks the measurements on track
843 // are not converted to xAOD::UncalibratedMeasurements, and the Acts::SourceLinks
844 // just contain a pointer to the Trk::Measurement. To keep this functionality
845 // SourceLinks are either stored in the m_uncalibratedSourceLinks cache
846 // or taken from the xAOD backend.
847 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
848 if (const xAOD::UncalibratedMeasurement* ptr = acc.withDefault(m_trackStatesIface, istate, nullptr))
849 {
851 }
852 return m_uncalibratedSourceLinks[istate].value();
853}
854
855typename Acts::SourceLink
857 IndexType istate) const {
858 assert(istate < m_trackStatesIface.size());
859 // at the moment when converting Trk::Track to Acts tracks the measurements on track
860 // are not converted to xAOD::UncalibratedMeasurements, and the Acts::SourceLinks
861 // just contain a pointer to the Trk::Measurement. To keep this functionality
862 // SourceLinks are either stored in the m_uncalibratedSourceLinks cache
863 // or taken from the xAOD backend.
864 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
865 if (const xAOD::UncalibratedMeasurement* ptr = acc.withDefault(m_trackStatesIface, istate, nullptr))
866 {
868 }
869 return m_uncalibratedSourceLinks[istate].value();
870}
871}
const T * to_const_ptr(const std::unique_ptr< T > &ptr)
constexpr uint64_t InvalidGeoID
#define INSPECTCALL(_INFO)
size_t size() const
Number of registered mappings.
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
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
ActsTrk::IndexType calibratedSize_impl(ActsTrk::IndexType istate) const
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
void ensureDynamicColumns_impl(const Acts::ConstVectorMultiTrajectory &other)
std::vector< std::optional< Acts::SourceLink > > m_calibratedSourceLinks
void excludeDecoration(std::string_view decorName)
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.
std::unordered_set< Acts::HashedString > m_excluded
void setReferenceSurface_impl(IndexType, std::shared_ptr< const Acts::Surface >)
std::unique_ptr< xAOD::TrackParametersAuxContainer > m_trackParametersAux
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
ActsTrk::IndexType calibratedSize_impl(ActsTrk::IndexType istate) const
Implementation of calibrated size.
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
const std::type_info & columnDataType_impl(Acts::HashedString key) const
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
std::string_view columnName_impl(Acts::HashedString key) const
ActsTrk::IndexType addTrackState_impl(Acts::TrackStatePropMask mask, ActsTrk::IndexType iprevious)
Add state with stograge for data that depends on the mask.
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
static Acts::SourceLink pack(const Ptr_t &measurement)
Pack the measurement type pointer to an Acts::SourceLink including the intermediate conversion into a...
static SourceLinkType getType(const Acts::SourceLink &sl)
Returns the enumeration corresponding to the object type cached within the Acts::SourceLink.
static SourceLink_t unpackBase(const Acts::SourceLink &sl)
Unpack the SourceLink_t from the passed Acts source link.
const std::type_info * getType(SG::auxid_t auxid) const
Return the type of an aux data item.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Helper class to provide constant type-safe access to aux data.
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:132
std::vector< Decoration > restoreDecorations(const SG::IConstAuxStore *container, const std::set< std::string > &staticVariables)
@ xAODUnCalibMeas
UnCalibrated Trk::PrepRawData objects.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
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 ...
void ensureDynamicColumns(const std::unordered_set< Acts::HashedString > &exclude, const cont_in &in_container, cont_out &out_container)
Definition Decoration.h:195
std::variant< const Acts::Surface *, std::shared_ptr< const Acts::Surface > > StoredSurface
std::uint32_t IndexType
Definition Decoration.h:28
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
Definition AuxElement.h:576
STL namespace.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
TrackStateAuxContainer_v1 TrackStateAuxContainer
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
TrackSurface_v1 TrackSurface