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
17const std::set<std::string> ActsTrk::MutableMultiTrajectory::s_staticVariables = {
18 "chi2", "pathLength", "typeFlags", "previous", "next", "predicted", "filtered", "smoothed", "jacobian", "calibrated", "measDim",
19 "uncalibratedMeasurement", "uncalibratedMeasurementLink" /*created by converter*/, "geometryId", "surfaceIndex"
20 };
21
22namespace {
23constexpr std::optional<bool> has_impl(
24 const xAOD::TrackStateAuxContainer* trackStates, Acts::HashedString key,
25 ActsTrk::IndexType istate) {
26 using namespace Acts::HashedStringLiteral;
27 constexpr auto kInvalid = Acts::kTrackIndexInvalid;
28 INSPECTCALL(key << " " << istate);
29
30 switch (key) {
31 case "previous"_hash:
32 return trackStates->previous[istate] < kInvalid;
33 case "chi2"_hash:{
34 INSPECTCALL(key << " " << istate << " chi2");
35 return true;
36 }
37 case "pathLength"_hash:{
38 INSPECTCALL(key << " " << istate << " pathLength");
39 return true;
40 }
41 case "typeFlags"_hash:{
42 INSPECTCALL(key << " " << istate << " type flags");
43 return true;
44 }
45 case "predicted"_hash:{
46 INSPECTCALL(key << " " << istate << " predicted");
47 return trackStates->predicted[istate] < kInvalid;
48 }
49 case "filtered"_hash:{
50 INSPECTCALL(key << " " << istate << " filtered");
51 return trackStates->filtered[istate] < kInvalid;
52 }
53 case "smoothed"_hash:{
54 INSPECTCALL(key << " " << istate << " smoothed");
55 return trackStates->smoothed[istate] < kInvalid;
56 }
57 case "jacobian"_hash:{
58 INSPECTCALL(key << " " << istate << " jacobian");
59 return trackStates->jacobian[istate] < kInvalid;
60 }
61 case "projector"_hash:{
62 INSPECTCALL(key << " " << istate << " projector");
63 return trackStates->calibrated[istate] < kInvalid;
64 }
65 case "calibrated"_hash:{
66 INSPECTCALL(key << " " << istate << " calibrated");
67 return trackStates->measDim[istate] < kInvalid;
68 }
69 case "calibratedCov"_hash: {
70 INSPECTCALL(key << " " << istate << " calibratedCov");
71 return trackStates->measDim[istate] < kInvalid;
72 }
73 case "measdim"_hash: {
74 INSPECTCALL(key << " " << istate << " measdim");
75 return true;
76 }
77 case "referenceSurface"_hash: {
78 INSPECTCALL(key << " " << istate << " referenceSurfaceEnco");
79 return true;
80 }
81
82 // TODO restore once only the EL Source Links are in use
83 // return !trackStates[istate]->uncalibratedMeasurementLink().isDefault();
84 }
85 INSPECTCALL(key << " " << istate << " not a predefined component");
86 return std::optional<bool>();
87}
88}
89
90
91template<typename T>
92const T* to_const_ptr(const std::unique_ptr<T>& ptr) {
93 return ptr.get();
94}
95
97 : m_trackStatesAux (std::make_unique<xAOD::TrackStateAuxContainer>()),
98 m_trackParametersAux (std::make_unique<xAOD::TrackParametersAuxContainer>()),
99 m_trackJacobiansAux (std::make_unique<xAOD::TrackJacobianAuxContainer>()),
100 m_trackMeasurementsAux (std::make_unique<xAOD::TrackMeasurementAuxContainer>()),
101 m_surfacesBackend (std::make_unique<xAOD::TrackSurfaceContainer>()),
102 m_surfacesBackendAux (std::make_unique<xAOD::TrackSurfaceAuxContainer>())
103{
104 INSPECTCALL("c-tor " << this)
105
107 m_trackStatesIface.setStore(m_trackStatesAux.get());
108
109}
110
113 {
114 INSPECTCALL("copy c-tor " << this << " src " << &other << " " << other.size())
115
116 *m_trackStatesAux = *other.m_trackStatesAux;
117 *m_trackParametersAux = *other.m_trackParametersAux;
118 *m_trackJacobiansAux = *other.m_trackJacobiansAux;
119 *m_trackMeasurementsAux = *other.m_trackMeasurementsAux;
120 m_decorations = other.m_decorations;
121 m_calibratedSourceLinks = other.m_calibratedSourceLinks;
122 m_uncalibratedSourceLinks = other.m_uncalibratedSourceLinks;
123
124 m_surfaces = other.m_surfaces;
125 m_geoContext = other.m_geoContext;
126 m_trackStatesIface.resize(m_trackStatesAux->size());
127 INSPECTCALL("copy c-tor done")
128}
129
130
132 return m_trackStatesAux != nullptr and m_trackParametersAux != nullptr and
133 m_trackJacobiansAux != nullptr and m_trackMeasurementsAux != nullptr
134 and m_surfacesBackend != nullptr;
135}
136
137namespace{
138 template<typename CONT>
139 void stepResize( CONT* auxPtr, const size_t realSize, const size_t sizeStep = 20) {
140 if( realSize >= auxPtr->size() ) auxPtr->resize(auxPtr->size()+sizeStep);
141 }
142}
143
145 Acts::TrackStatePropMask mask,
146 ActsTrk::IndexType previous) {
147 using namespace Acts::HashedStringLiteral;
148 INSPECTCALL( this << " " << mask << " " << m_trackStatesIface.size() << " " << previous);
149 assert(m_trackStatesAux && "Missing Track States backend");
151 m_surfaces.push_back(nullptr);
152
153 // set kInvalid
154 constexpr auto kInvalid = Acts::kTrackIndexInvalid;
155
156 if (previous >= kInvalid - 1)
157 previous = kInvalid; // fix needed in Acts::MTJ
158 m_trackStatesAux->previous[m_trackStatesSize] = previous;
159 using namespace Acts;
160
161 auto addParam = [this]() -> ActsTrk::IndexType {
162 stepResize(m_trackParametersAux.get(), m_trackParametersSize, 60);
163 // TODO ask AK if this resize could be method of aux container
164 m_trackParametersAux->params[m_trackParametersSize].resize(Acts::eBoundSize);
165 m_trackParametersAux->covMatrix[m_trackParametersSize].resize(Acts::eBoundSize*Acts::eBoundSize);
167 return m_trackParametersSize-1;
168 };
169
170 auto addJacobian = [this]() -> ActsTrk::IndexType {
171 stepResize(m_trackJacobiansAux.get(), m_trackJacobiansSize);
172 m_trackJacobiansAux->jac[m_trackJacobiansSize].resize(Acts::eBoundSize*Acts::eBoundSize);
174 return m_trackJacobiansSize-1;
175 };
176
177 auto addMeasurement = [this]() -> ActsTrk::IndexType {
179 m_trackMeasurementsAux->meas[m_trackMeasurementsSize].resize(Acts::eBoundSize);
180 m_trackMeasurementsAux->covMatrix[m_trackMeasurementsSize].resize(Acts::eBoundSize*Acts::eBoundSize);
183 };
184
185 m_trackStatesAux->predicted[m_trackStatesSize] = kInvalid;
186 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Predicted)) {
187 m_trackStatesAux->predicted[m_trackStatesSize] = addParam();
188 }
189
190 m_trackStatesAux->filtered[m_trackStatesSize] = kInvalid;
191 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Filtered)) {
192 m_trackStatesAux->filtered[m_trackStatesSize] = addParam();
193 }
194
195 m_trackStatesAux->smoothed[m_trackStatesSize] = kInvalid;
196 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Smoothed)) {
197 m_trackStatesAux->smoothed[m_trackStatesSize] = addParam();
198 }
199
200 m_trackStatesAux->jacobian[m_trackStatesSize] = kInvalid;
201 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Jacobian)) {
202 m_trackStatesAux->jacobian[m_trackStatesSize] = addJacobian();
203 }
204
205 m_uncalibratedSourceLinks.emplace_back(std::nullopt);
206 m_trackStatesAux->calibrated[m_trackStatesSize] = kInvalid;
207 m_trackStatesAux->measDim[m_trackStatesSize] = kInvalid;
208 // @TODO uncalibrated ?
209 if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Calibrated)) {
210 m_trackStatesAux->calibrated.at(m_trackStatesSize) = addMeasurement();
211 m_calibratedSourceLinks.emplace_back(std::nullopt);
212 }
213
214 m_trackStatesAux->geometryId[m_trackStatesSize] = InvalidGeoID; // surface is invalid until set
216 return m_trackStatesSize-1;
217}
218
219
221 ActsTrk::IndexType istate,
222 Acts::TrackStatePropMask mask) {
223 using namespace Acts::HashedStringLiteral;
224 INSPECTCALL( this << " " << mask << " " << m_trackStatesIface.size() << " " << istate);
225
226 assert(m_trackStatesAux && "Missing Track States backend");
227
228 // set kInvalid
229 constexpr auto kInvalid = Acts::kTrackIndexInvalid;
230
231 using namespace Acts;
232
233 auto addParam = [this]() -> ActsTrk::IndexType {
234 stepResize(m_trackParametersAux.get(), m_trackParametersSize, 60);
235 // TODO ask AK if this resize could be method of aux container
236 m_trackParametersAux->params[m_trackParametersSize].resize(Acts::eBoundSize);
237 m_trackParametersAux->covMatrix[m_trackParametersSize].resize(Acts::eBoundSize*Acts::eBoundSize);
239 return m_trackParametersSize-1;
240 };
241
242 auto addJacobian = [this]() -> ActsTrk::IndexType {
243 stepResize(m_trackJacobiansAux.get(), m_trackJacobiansSize);
244 m_trackJacobiansAux->jac[m_trackJacobiansSize].resize(Acts::eBoundSize*Acts::eBoundSize);
246 return m_trackJacobiansSize-1;
247 };
248
249 auto addMeasurement = [this]() -> ActsTrk::IndexType {
251 m_trackMeasurementsAux->meas[m_trackMeasurementsSize].resize(Acts::eBoundSize);
252 m_trackMeasurementsAux->covMatrix[m_trackMeasurementsSize].resize(Acts::eBoundSize*Acts::eBoundSize);
255 };
256
257 if ((m_trackStatesAux->predicted[istate] == kInvalid) &&
258 ACTS_CHECK_BIT(mask, TrackStatePropMask::Predicted)) {
259 m_trackStatesAux->predicted[istate] = addParam();
260 }
261
262 if ((m_trackStatesAux->filtered[istate] == kInvalid) &&
263 ACTS_CHECK_BIT(mask, TrackStatePropMask::Filtered)) {
264 m_trackStatesAux->filtered[istate] = addParam();
265 }
266
267 if ((m_trackStatesAux->smoothed[istate] == kInvalid) &&
268 ACTS_CHECK_BIT(mask, TrackStatePropMask::Smoothed)) {
269 m_trackStatesAux->smoothed[istate] = addParam();
270 }
271
272 if ((m_trackStatesAux->jacobian[istate] == kInvalid) &&
273 ACTS_CHECK_BIT(mask, TrackStatePropMask::Jacobian)) {
274 m_trackStatesAux->jacobian[istate] = addJacobian();
275 }
276
277 if ((m_trackStatesAux->calibrated[istate] == kInvalid) &&
278 ACTS_CHECK_BIT(mask, TrackStatePropMask::Calibrated)) {
279 m_trackStatesAux->calibrated[istate] = addMeasurement();
280 m_calibratedSourceLinks.emplace_back(std::nullopt);
281 }
282}
283
284
286 ActsTrk::IndexType iself,
287 ActsTrk::IndexType iother,
288 Acts::TrackStatePropMask shareSource,
289 Acts::TrackStatePropMask shareTarget) {
290
291 assert(ACTS_CHECK_BIT(this->getTrackState(iother).getMask(), shareSource) &&
292 "Source has incompatible allocation");
293
294 using PM = Acts::TrackStatePropMask;
295 // set kInvalid
296 constexpr auto kInvalid = Acts::kTrackIndexInvalid;
297
298 ActsTrk::IndexType sourceIndex{kInvalid};
299 switch (shareSource) {
300 case PM::Predicted:
301 sourceIndex = m_trackStatesAux->predicted[iother];
302 break;
303 case PM::Filtered:
304 sourceIndex = m_trackStatesAux->filtered[iother];
305 break;
306 case PM::Smoothed:
307 sourceIndex = m_trackStatesAux->smoothed[iother];
308 break;
309 case PM::Jacobian:
310 sourceIndex = m_trackStatesAux->jacobian[iother];
311 break;
312 default:
313 throw std::domain_error{"MutableMultiTrajectory Unable to share this component"};
314 }
315
316 assert(sourceIndex != kInvalid);
317
318 switch (shareTarget) {
319 case PM::Predicted:
320 assert(shareSource != PM::Jacobian);
321 m_trackStatesAux->predicted[iself] = sourceIndex;
322 break;
323 case PM::Filtered:
324 assert(shareSource != PM::Jacobian);
325 m_trackStatesAux->filtered[iself] = sourceIndex;
326 break;
327 case PM::Smoothed:
328 assert(shareSource != PM::Jacobian);
329 m_trackStatesAux->smoothed[iself] = sourceIndex;
330 break;
331 case PM::Jacobian:
332 assert(shareSource == PM::Jacobian);
333 m_trackStatesAux->jacobian[iself] = sourceIndex;
334 break;
335 default:
336 throw std::domain_error{"MutableMultiTrajectory Unable to share this component"};
337 }
338}
339
340
342 Acts::TrackStatePropMask target,
343 ActsTrk::IndexType istate) {
344
345 using PM = Acts::TrackStatePropMask;
346 // set kInvalid
347 constexpr auto kInvalid = Acts::kTrackIndexInvalid;
348
349 switch (target) {
350 case PM::Predicted:
351 m_trackStatesAux->predicted[istate] = kInvalid;
352 break;
353 case PM::Filtered:
354 m_trackStatesAux->filtered[istate] = kInvalid;
355
356 break;
357 case PM::Smoothed:
358 m_trackStatesAux->smoothed[istate] = kInvalid;
359 break;
360 case PM::Jacobian:
361 m_trackStatesAux->jacobian[istate] = kInvalid;
362
363 break;
364 case PM::Calibrated:
365 m_trackStatesAux->measDim[istate] = kInvalid;
366 // TODO here m_measOffset[istate] and m_measCovOffset[istate] should be
367 // set to kInvalid
368
369 break;
370 default:
371 throw std::domain_error{"MutableMultiTrajectory Unable to unset this component"};
372 }
373}
374
376 Acts::HashedString key, ActsTrk::IndexType istate) {
377 using namespace Acts::HashedStringLiteral;
378 assert(istate < m_trackStatesIface.size() &&
379 "Attempt to reach beyond the Track States container size");
380 INSPECTCALL(key << " " << istate << " non-const component_impl")
381
382 switch (key) {
383 case "previous"_hash:
384 return &(m_trackStatesAux->previous[istate]);
385 case "next"_hash:
386 return &(m_trackStatesAux->next[istate]);
387 case "chi2"_hash:
388 return &(m_trackStatesAux->chi2[istate]);
389 case "pathLength"_hash:
390 return &(m_trackStatesAux->pathLength[istate]);
391 case "predicted"_hash:
392 return &(m_trackStatesAux->predicted[istate]);
393 case "filtered"_hash:
394 return &(m_trackStatesAux->filtered[istate]);
395 case "smoothed"_hash:
396 return &(m_trackStatesAux->smoothed[istate]);
397 case "projector"_hash: {
398 auto idx = m_trackStatesAux->calibrated[istate];
399 return &(m_trackMeasurementsAux->projector[idx]);
400 }
401 case "measdim"_hash:
402 return &(m_trackStatesAux->measDim[istate]);
403 case "typeFlags"_hash:
404 return &(m_trackStatesAux->typeFlags[istate]);
405
406 default: {
407 for (auto& d : m_decorations) {
408 if (d.hash == key) {
409 return d.setter(m_trackStatesAux.get(), istate, d.auxid);
410 }
411 }
412 throw std::runtime_error("MutableMultiTrajectory::component_impl no such component " + std::to_string(key));
413 }
414 }
415}
416
417
419 Acts::HashedString key,
420 ActsTrk::IndexType istate) const {
421 using namespace Acts::HashedStringLiteral;
422 assert(istate < m_trackStatesIface.size() &&
423 "Attempt to reach beyond the Track States container size");
424 INSPECTCALL(key << " " << istate << " const component_impl")
425 switch (key) {
426 case "previous"_hash:
427 return &(to_const_ptr(m_trackStatesAux)->previous[istate]);
428 case "next"_hash:
429 return &(to_const_ptr(m_trackStatesAux)->next[istate]);
430 case "chi2"_hash:
431 return &(to_const_ptr(m_trackStatesAux)->chi2[istate]);
432 case "pathLength"_hash:
433 return &(to_const_ptr(m_trackStatesAux)->pathLength[istate]);
434 case "predicted"_hash:
435 return &(to_const_ptr(m_trackStatesAux)->predicted[istate]);
436 case "filtered"_hash:
437 return &(to_const_ptr(m_trackStatesAux)->filtered[istate]);
438 case "smoothed"_hash:
439 return &(to_const_ptr(m_trackStatesAux)->smoothed[istate]);
440 case "jacobian"_hash:
441 return &(to_const_ptr(m_trackStatesAux)->jacobian[istate]);
442 case "projector"_hash:{
443 auto idx = to_const_ptr(m_trackStatesAux)->calibrated[istate];
444 return &(to_const_ptr(m_trackMeasurementsAux)->projector[idx]);
445 }
446 case "calibrated"_hash: {
447 return &(to_const_ptr(m_trackStatesAux)->calibrated[istate]);
448 }
449 case "calibratedCov"_hash: {
450 return &(to_const_ptr(m_trackStatesAux)->calibrated[istate]);
451 }
452 case "measdim"_hash:
453 return &(to_const_ptr(m_trackStatesAux)->measDim[istate]);
454 case "typeFlags"_hash:
455 return &(to_const_ptr(m_trackStatesAux)->typeFlags[istate]);
456 default: {
457 for (auto& d : m_decorations) {
458 if (d.hash == key) {
459 INSPECTCALL("getting dynamic variable " << d.name << " " << istate);
460 return d.getter(m_trackStatesAux.get(), istate, d.auxid);
461 }
462 }
463 throw std::runtime_error("MutableMultiTrajectory::component_impl const no such component " + std::to_string(key));
464 }
465 }
466}
467
469 Acts::HashedString key, ActsTrk::IndexType istate) const {
470 std::optional<bool> inTrackState = ::has_impl(m_trackStatesAux.get(), key, istate);
471 if (inTrackState.has_value())
472 return inTrackState.value();
473
474 // TODO remove once EL based source links are in use only
475 using namespace Acts::HashedStringLiteral;
476 if (key == "uncalibratedSourceLink"_hash){
477 INSPECTCALL(key << " " << istate << " uncalibratedSourceLink")
478 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
479 if (acc.isAvailable (m_trackStatesIface)) {
480 if (acc(m_trackStatesIface, istate) != nullptr) return true;
481 }
482
483 return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
484 }
485
486 for (auto& d : m_decorations) {
487 if (d.hash == key) {
488 INSPECTCALL(key << " " << istate << " d.name")
489 return true;
490 }
491 }
492
493 return false;
494}
495
497 INSPECTCALL(this);
498 m_trackStatesIface.resize(0);
500
501 m_trackParametersAux->resize(0);
503
504 m_trackJacobiansAux->resize(0);
506
507 m_trackMeasurementsAux->resize(0);
509
510 m_surfacesBackend->clear();
511 m_surfaces.clear();
514}
515
516
518 // Retrieve the calibrated measurement size
519 // INSPECTCALL(istate << " " << trackMeasurements().size());
520 return m_trackStatesAux->measDim[istate];
521}
522
523
525 const Acts::SourceLink& sourceLink) {
526 INSPECTCALL( istate );
527
529 static const Decor_t decor{"uncalibratedMeasurement"};
530 if (istate>= m_trackStatesIface.size()) {
531 throw std::range_error("istate out of range on TrackStates when attempting to access uncalibrated measurements");
532 }
533 Decor_t::span uncalibratedMeasurements = decor.getDecorationSpan(m_trackStatesIface);
534
535 // @TODO normally the source links should contain an xAOD::UncalibratedMeasurement pointer
536 // but in some cases some other payload is used e.g. when converting Trk::Tracks.
537 // Only UncalibratedMeasurement pointer can be stored in the xAOD backend. Everything
538 // else has to go into the cache.
539 // Currently there is no possibility to check whether the source link contains a certain payload
540 // so can only catch the bad any cast
541 try {
543 auto unpacked = detail::MeasurementCalibratorBase::unpackBase(sourceLink);
544 uncalibratedMeasurements.at(istate) = std::get<const xAOD::UncalibratedMeasurement*>(unpacked);
545 } else {
546 assert( istate < m_uncalibratedSourceLinks.size());
547 m_uncalibratedSourceLinks[istate] = sourceLink;
548 }
549 } catch (const std::bad_any_cast &err) {
550 try {
551 auto unpacked = sourceLink.get<const xAOD::UncalibratedMeasurement*>();
552 uncalibratedMeasurements.at(istate) = unpacked;
553 } catch (const std::bad_any_cast &err1) {
554 assert( istate < m_uncalibratedSourceLinks.size());
555 m_uncalibratedSourceLinks[istate] = sourceLink;
556 }
557 }
558}
559
561 std::shared_ptr<const Acts::Surface> surface) {
562 if ( istate >= m_surfaces.size() )
563 m_surfaces.resize(istate+1, nullptr);
564
565 m_trackStatesAux->geometryId[istate] = surface->geometryId().value();
566 if (surface->geometryId().value() == 0) { // free surface, needs recording of properties
567 m_surfacesBackend->push_back(new xAOD::TrackSurface());
568 encodeSurface(m_surfacesBackendAux.get(), m_surfacesBackendAux->size()-1, surface.get(), m_geoContext.context());
569 m_trackStatesAux->surfaceIndex[istate] = m_surfacesBackend->size()-1;
570 m_surfaces[istate] = std::move(surface); // and memory management
571
572 } else {
573 m_surfaces[istate] = surface.get(); // no memory management, bare pointer
574 }
575 // store surface representation in
576}
577
578namespace {
579 const Acts::Surface* toSurfacePtr(const ActsTrk::StoredSurface& surfaceVariant) {
580 if ( std::holds_alternative<const Acts::Surface*>(surfaceVariant))
581 return std::get<const Acts::Surface*>(surfaceVariant);
582 return std::get<std::shared_ptr<const Acts::Surface>>(surfaceVariant).get();
583 }
584}
585
587 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");
588 return toSurfacePtr(m_surfaces[istate]);
589}
590
592 Acts::HashedString key,
593 const std::any& src_ptr) {
594 INSPECTCALL("copy dynamic decoration of key " << key << " destination MTJ has " << m_decorations.size() << " decorations");
596 INSPECTCALL("checking for destination of dynamic decoration " << d.name << " hash " << d.hash << " while looking for the key " << key);
597 if (d.hash == key) {
598 d.copier(m_trackStatesAux.get(), istate, d.auxid, src_ptr);
599 return;
600 }
601 }
602 throw std::invalid_argument("MultiTrajectory::copyDynamicFrom_impl no such decoration in destination MTJ " + std::to_string(key));
603}
604
605std::vector<Acts::HashedString> ActsTrk::MutableMultiTrajectory::dynamicKeys_impl() const {
606 std::vector<Acts::HashedString> keys;
608 keys.push_back(d.hash);
609 INSPECTCALL("collecting dynamic decoration " << d.name << " hash " << d.hash);
610 }
611 return keys;
612}
613
614
625
627// ReadOnly MTJ
644
656
657
658bool ActsTrk::MultiTrajectory::has_impl(Acts::HashedString key,
659 ActsTrk::IndexType istate) const {
660 // const auto& trackStates = *m_trackStates;
661 std::optional<bool> inTrackState = ::has_impl(m_trackStatesAux, key, istate);
662 if (inTrackState.has_value())
663 return inTrackState.value();
664 // TODO remove once EL based source links are in use only
665 using namespace Acts::HashedStringLiteral;
666 if (key == "uncalibratedSourceLink"_hash) {
667 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
668 if (acc.isAvailable (m_trackStatesIface)) {
669 return acc(m_trackStatesIface, istate) != nullptr;
670 }
671 else {
672 return (istate < m_uncalibratedSourceLinks.size() && m_uncalibratedSourceLinks[istate].has_value());
673 }
674 }
675 return false;
676}
677
679 Acts::HashedString key, ActsTrk::IndexType istate) const {
680 using namespace Acts::HashedStringLiteral;
681 switch (key) {
682 case "previous"_hash:
683 return &(m_trackStatesAux->previous[istate]);
684 case "next"_hash:
685 return &(m_trackStatesAux->next[istate]);
686 case "chi2"_hash:
687 return &(m_trackStatesAux->chi2[istate]);
688 case "pathLength"_hash:
689 return &(m_trackStatesAux->pathLength[istate]);
690 case "predicted"_hash:
691 return &(m_trackStatesAux->predicted[istate]);
692 case "filtered"_hash:
693 return &(m_trackStatesAux->filtered[istate]);
694 case "smoothed"_hash:
695 return &(m_trackStatesAux->smoothed[istate]);
696 case "jacobian"_hash:
697 return &(m_trackStatesAux->jacobian[istate]);
698 case "projector"_hash: {
699 return &(m_trackMeasurementsAux->projector.at(m_trackStatesAux->calibrated[istate]));
700 }
701 case "calibrated"_hash: {
702 return &(m_trackStatesAux->calibrated[istate]);
703 }
704 case "calibratedCov"_hash: {
705 return &(m_trackStatesAux->calibrated[istate]);
706 }
707 case "measdim"_hash:
708 return &(m_trackStatesAux->measDim[istate]);
709 case "typeFlags"_hash:
710 return &(m_trackStatesAux->typeFlags[istate]);
711 default: {
712 for (auto& d : m_decorations) {
713 if (d.hash == key) {
714 // TODO the dynamic_cast will disappear
715 return d.getter(m_trackStatesAux.cptr(), istate, d.auxid);
716 }
717 }
718 throw std::runtime_error("MultiTrajectory::component_impl no such component " + std::to_string(key));
719 }
720 }
721}
722
724 Acts::HashedString key) const {
725 using namespace Acts::HashedStringLiteral;
726 // TODO try using staticVariables set
727 switch (key) {
728 case "previous"_hash:
729 case "next"_hash:
730 case "chi2"_hash:
731 case "pathLength"_hash:
732 case "predicted"_hash:
733 case "filtered"_hash:
734 case "smoothed"_hash:
735 case "jacobian"_hash:
736 case "projector"_hash:
737 case "uncalibratedSourceLink"_hash:
738 case "calibrated"_hash:
739 case "calibratedCov"_hash:
740 case "measdim"_hash:
741 case "typeFlags"_hash:
742 return true;
743 }
744 for (auto& d : m_decorations) {
745 if (d.hash == key) {
746 return true;
747 }
748 }
749 return false;
750}
751
756
760
761// TODO remove this implementation once tracking uses only sourceLinks with EL
766
767std::vector<Acts::HashedString> ActsTrk::MultiTrajectory::dynamicKeys_impl() const {
768 std::vector<Acts::HashedString> keys;
770 keys.push_back(d.hash);
771 }
772 return keys;
773}
774
775
776void ActsTrk::MultiTrajectory::fillSurfaces(const Acts::TrackingGeometry* geo) {
777 if ( not m_surfaces.empty() )
778 return;
779 m_surfaces.resize(m_trackStatesIface.size(), nullptr);
780 for ( IndexType i = 0; i < m_trackStatesIface.size(); i++ ) {
781 auto geoID = m_trackStatesAux->geometryId[i];
782 if ( geoID == InvalidGeoID ) {
783 m_surfaces[i] = nullptr;
784 continue;
785 }
786 if ( geoID != 0 ) {
787 m_surfaces[i] = geo->findSurface(Acts::GeometryIdentifier{geoID});
788 } else {
789 unsigned int backendIndex = m_trackStatesAux->surfaceIndex[i];
790 std::shared_ptr<const Acts::Surface> surface = decodeSurface(m_trackSurfacesAux, backendIndex);
791 m_surfaces[i] = surface; // TODO
792
793 }
794 }
795}
796
797
799 INSPECTCALL( this << " " << istate << " " << m_trackStatesIface.size() << " " << m_surfaces.size() << " surf ptr " << toSurfacePtr(m_surfaces[istate]));
800 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");
801 return toSurfacePtr(m_surfaces[istate]);
802}
803
804typename Acts::SourceLink
806 ActsTrk::IndexType istate) const {
807 assert(istate < m_trackStatesIface.size());
808 // at the moment when converting Trk::Track to Acts tracks the measurements on track
809 // are not converted to xAOD::UncalibratedMeasurements, and the Acts::SourceLinks
810 // just contain a pointer to the Trk::Measurement. To keep this functionality
811 // SourceLinks are either stored in the m_uncalibratedSourceLinks cache
812 // or taken from the xAOD backend.
813 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
814 if (const xAOD::UncalibratedMeasurement* ptr = acc.withDefault(m_trackStatesIface, istate, nullptr))
815 {
817 }
818 return m_uncalibratedSourceLinks[istate].value();
819}
820
821typename Acts::SourceLink
823 ActsTrk::IndexType istate) const {
824 assert(istate < m_trackStatesIface.size());
825 // at the moment when converting Trk::Track to Acts tracks the measurements on track
826 // are not converted to xAOD::UncalibratedMeasurements, and the Acts::SourceLinks
827 // just contain a pointer to the Trk::Measurement. To keep this functionality
828 // SourceLinks are either stored in the m_uncalibratedSourceLinks cache
829 // or taken from the xAOD backend.
830 static const SG::ConstAccessor<const xAOD::UncalibratedMeasurement*> acc{"uncalibratedMeasurement"};
831 if (const xAOD::UncalibratedMeasurement* ptr = acc.withDefault(m_trackStatesIface, istate, nullptr))
832 {
834 }
835 return m_uncalibratedSourceLinks[istate].value();
836}
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
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
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.
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.
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:18
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