diff --git a/Event/xAOD/xAODTracking/Root/TrackSummaryAuxContainer_v1.cxx b/Event/xAOD/xAODTracking/Root/TrackSummaryAuxContainer_v1.cxx index 0d8fee7ee70726f84ae1e85474cf072488b42298..68d9dc49dac0191a240ca44c31210fbb26f7a7f2 100644 --- a/Event/xAOD/xAODTracking/Root/TrackSummaryAuxContainer_v1.cxx +++ b/Event/xAOD/xAODTracking/Root/TrackSummaryAuxContainer_v1.cxx @@ -16,5 +16,7 @@ namespace xAOD { AUX_VARIABLE(nSharedHits); AUX_VARIABLE(tipIndex); AUX_VARIABLE(stemIndex); + AUX_VARIABLE(particleHypothesis); + } } diff --git a/Event/xAOD/xAODTracking/Root/TrackSummary_v1.cxx b/Event/xAOD/xAODTracking/Root/TrackSummary_v1.cxx index 4be88dc371d4b5e6da698a871ffa444aeb1273d6..1cc6ba522ca0192d21acdd04754debdf0afd410e 100644 --- a/Event/xAOD/xAODTracking/Root/TrackSummary_v1.cxx +++ b/Event/xAOD/xAODTracking/Root/TrackSummary_v1.cxx @@ -31,6 +31,9 @@ DEFINE_API(TrackSummary_v1, unsigned int, tipIndex, setTipIndex) DEFINE_API(TrackSummary_v1, unsigned int, stemIndex, setStemIndex) +AUXSTORE_OBJECT_SETTER_AND_GETTER(TrackSummary_v1, uint8_t, particleHypothesis, setParticleHypothesis) + + const SG::AuxElement::Accessor<std::vector<double> > xAOD::TrackSummary_v1::s_paramsAcc{"params"}; const SG::AuxElement::Accessor<std::vector<double> > diff --git a/Event/xAOD/xAODTracking/xAODTracking/versions/TrackSummaryAuxContainer_v1.h b/Event/xAOD/xAODTracking/xAODTracking/versions/TrackSummaryAuxContainer_v1.h index bf7affcd67e3969742a7c8fe5cfcf292d0d6cec2..b7f4aa1c1d3dd3610b0e3180640d41dc62b021e6 100644 --- a/Event/xAOD/xAODTracking/xAODTracking/versions/TrackSummaryAuxContainer_v1.h +++ b/Event/xAOD/xAODTracking/xAODTracking/versions/TrackSummaryAuxContainer_v1.h @@ -6,6 +6,7 @@ #include "xAODCore/AuxContainerBase.h" +#include "xAODTracking/TrackingPrimitives.h" #include <vector> namespace xAOD { class TrackSummaryAuxContainer_v1 : public AuxContainerBase { @@ -27,6 +28,7 @@ namespace xAOD { std::vector<unsigned int> nSharedHits; std::vector<unsigned int> tipIndex; std::vector<unsigned int> stemIndex; + std::vector<uint8_t> particleHypothesis; }; } diff --git a/Event/xAOD/xAODTracking/xAODTracking/versions/TrackSummary_v1.h b/Event/xAOD/xAODTracking/xAODTracking/versions/TrackSummary_v1.h index c3dc98246d2bcd43d1f6b62cd9e9a097c88c683d..cbf408ce4f508299596d68cbf4a2b08325dcb2c7 100644 --- a/Event/xAOD/xAODTracking/xAODTracking/versions/TrackSummary_v1.h +++ b/Event/xAOD/xAODTracking/xAODTracking/versions/TrackSummary_v1.h @@ -8,6 +8,7 @@ #include "AthLinks/ElementLink.h" #include "AthContainers/AuxElement.h" #include "EventPrimitives/EventPrimitives.h" +#include "xAODTracking/TrackingPrimitives.h" namespace xAOD @@ -199,6 +200,12 @@ namespace xAOD const unsigned int* stemIndexPtr() const; unsigned int* stemIndexPtr(); + /** + * particle hypothesis access + */ + const uint8_t& particleHypothesis() const; + void setParticleHypothesis(const uint8_t& ); + /** * @brief resize internal arrays to store params (to capacity sz) & convariances (to capacity sz x sz) */ diff --git a/Tracking/Acts/ActsEvent/ActsEvent/ParticleHypothesisEncoding.h b/Tracking/Acts/ActsEvent/ActsEvent/ParticleHypothesisEncoding.h new file mode 100644 index 0000000000000000000000000000000000000000..923cbe21e5f68c49c58286b9a68fd6173dbd0f93 --- /dev/null +++ b/Tracking/Acts/ActsEvent/ActsEvent/ParticleHypothesisEncoding.h @@ -0,0 +1,17 @@ +/* + Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration +*/ +#ifndef ActsEvent_ParticleHypothesisEncoding_h +#define ActsEvent_ParticleHypothesisEncoding_h +#include "xAODTracking/TrackingPrimitives.h" +#include "Acts/EventData/ParticleHypothesis.hpp" + + +namespace ActsTrk { +namespace ParticleHypothesis { + xAOD::ParticleHypothesis convert(Acts::ParticleHypothesis h); + Acts::ParticleHypothesis convert(xAOD::ParticleHypothesis h); +} // namespace ParticleHypothesis +} // namespace ActsTrk + +#endif \ No newline at end of file diff --git a/Tracking/Acts/ActsEvent/ActsEvent/TrackStorageContainer.h b/Tracking/Acts/ActsEvent/ActsEvent/TrackStorageContainer.h index a81ce141e1b023250c21b82e33c54b6649bc505c..e6e091529210c802b5dbbb1dbba6c4df7cb4d145 100644 --- a/Tracking/Acts/ActsEvent/ActsEvent/TrackStorageContainer.h +++ b/Tracking/Acts/ActsEvent/ActsEvent/TrackStorageContainer.h @@ -72,6 +72,11 @@ class TrackStorageContainer { */ const Acts::Surface* referenceSurface_impl(ActsTrk::IndexType itrack) const; + /** + * return pointer to reference surface + */ + Acts::ParticleHypothesis particleHypothesis_impl(IndexType itrack) const; + /** * returns number of stored tracks */ @@ -128,7 +133,6 @@ class MutableTrackStorageContainer : public TrackStorageContainer { MutableTrackStorageContainer operator=(const MutableTrackStorageContainer&) = delete; MutableTrackStorageContainer(MutableTrackStorageContainer&&) noexcept; -// Add and remove surface /** * adds new surface to the tail of the container */ @@ -139,9 +143,6 @@ class MutableTrackStorageContainer : public TrackStorageContainer { */ void removeSurface_impl(ActsTrk::IndexType isurf); - //TODO: function(s) needed to fill the surface in the way analog to tracks - - /** * adds new track to the tail of the container */ @@ -207,13 +208,13 @@ class MutableTrackStorageContainer : public TrackStorageContainer { */ void setReferenceSurface_impl(ActsTrk::IndexType itrack, std::shared_ptr<const Acts::Surface> surface); - - - void setParticleHypothesis_impl( - ActsTrk::IndexType itrack, const Acts::ParticleHypothesis& particleHypothesis) { - m_particleHypothesis.resize(itrack+1, Acts::ParticleHypothesis::pion()); - m_particleHypothesis[itrack] = particleHypothesis; - } + /** + * sets particle hypothesis + * @warning it will fail for an arbitrary particles as it converts to + * a predefined set (@see xAOD::ParticleHypothesis in TrackingPrimitives.h) of values + */ + void setParticleHypothesis_impl(ActsTrk::IndexType itrack, + const Acts::ParticleHypothesis& particleHypothesis); template<typename T> friend class MutableTrackContainerHandle; diff --git a/Tracking/Acts/ActsEvent/Root/ParticleHypothesisEncoding.cxx b/Tracking/Acts/ActsEvent/Root/ParticleHypothesisEncoding.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a03b62ea5f33d7e5c7663ef27629df39b58cefec --- /dev/null +++ b/Tracking/Acts/ActsEvent/Root/ParticleHypothesisEncoding.cxx @@ -0,0 +1,72 @@ +/* + Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration +*/ +#include "ActsEvent/ParticleHypothesisEncoding.h" + +#include <stdexcept> + +#include "CxxUtils/AthUnlikelyMacros.h" + +namespace ActsTrk::ParticleHypothesis { + +xAOD::ParticleHypothesis convert(Acts::ParticleHypothesis h) { + if (ATH_LIKELY(h == Acts::ParticleHypothesis::pion())) { + return xAOD::pion; + } else if ( h == Acts::ParticleHypothesis::muon()) { + return xAOD::muon; + } else if (h == Acts::ParticleHypothesis::electron()) { + return xAOD::electron; + } else if (h == Acts::ParticleHypothesis::geantino()) { + return xAOD::geantino; + } else { + throw std::domain_error( + "ActsTrk::ParticleHypothesis conversion to xAOD does not handle particle of abs(pdg)" + std::to_string(h.absolutePdg())); + } + return xAOD::undefined; +} + +Acts::ParticleHypothesis convert(xAOD::ParticleHypothesis h) { + switch (h) { + case xAOD::geantino: + return Acts::ParticleHypothesis::geantino(); + case xAOD::electron: + return Acts::ParticleHypothesis::electron(); + case xAOD::muon: + return Acts::ParticleHypothesis::muon(); + case xAOD::pion: + return Acts::ParticleHypothesis::pion(); + case xAOD::kaon: + throw std::domain_error( + "ActsTrk::ParticleHypothesis conversion to Acts does not handle " + "kaon"); + // return Acts::ParticleHypothesis(321); // TODO add in ACTS + case xAOD::proton: + return Acts::ParticleHypothesis(Acts::PdgParticle::eProton); + case xAOD::photon: + return Acts::ParticleHypothesis::photon(); + case xAOD::neutron: + throw std::domain_error( + "ActsTrk::ParticleHypothesis conversion to Acts doe not handle " + "neutron"); + // return Acts::ParticleHypothesis(2112); // TODO add in ACTS + case xAOD::pi0: + return Acts::ParticleHypothesis::pion0(); + case xAOD::k0: + throw std::domain_error( + "ActsTrk::ParticleHypothesis conversion to Acts doe not handle K0"); + // return Acts::ParticleHypothesis(311); // TODO add in ACTS + case xAOD::nonInteractingMuon: + throw std::domain_error( + "ActsTrk::ParticleHypothesis conversion to Acts does not handle " + "nonInteractingMuon"); + case xAOD::undefined: + throw std::domain_error( + "ActsTrk::ParticleHypothesis conversion to Acts does not handle " + "undefined/noHypothesis"); + default: + throw std::domain_error( + "ActsTrk::ParticleHypothesis conversion to Acts failed for" + + std::to_string(h)); + } +} +} // namespace ActsTrk::ParticleHypothesis \ No newline at end of file diff --git a/Tracking/Acts/ActsEvent/Root/TrackStorageContainer.cxx b/Tracking/Acts/ActsEvent/Root/TrackStorageContainer.cxx index 7c7130ecb4e22e7b1c31e0c67b29af787ad4df71..26836fdeec2d57fc4c7cfca638c19c0b7bda366c 100644 --- a/Tracking/Acts/ActsEvent/Root/TrackStorageContainer.cxx +++ b/Tracking/Acts/ActsEvent/Root/TrackStorageContainer.cxx @@ -3,12 +3,14 @@ */ #include "ActsEvent/TrackStorageContainer.h" #include "xAODTracking/TrackSummary.h" +#include "ActsEvent/ParticleHypothesisEncoding.h" // this is list of xAOD container varaible names that are "hardcoded" in TrackStorage_v1 // their compatibility is maintained by the unit tests: AllStaticxAODVaraiblesAreKnown const std::set<std::string> ActsTrk::TrackStorageContainer::staticVariables = { "params", "covParams", "nMeasurements", "nHoles", "chi2f", - "ndf", "nOutliers", "nSharedHits", "tipIndex", "stemIndex"}; + "ndf", "nOutliers", "nSharedHits", "tipIndex", "stemIndex", + "particleHypothesis"}; ActsTrk::TrackStorageContainer::TrackStorageContainer( @@ -25,6 +27,10 @@ const Acts::Surface* ActsTrk::TrackStorageContainer::referenceSurface_impl( return m_surfaces[itrack].get(); } +Acts::ParticleHypothesis ActsTrk::TrackStorageContainer::particleHypothesis_impl(IndexType itrack) const{ + return ActsTrk::ParticleHypothesis::convert( static_cast<xAOD::ParticleHypothesis>(m_trackBackend->at(itrack)->particleHypothesis())); +} + std::size_t ActsTrk::TrackStorageContainer::size_impl() const { return m_trackBackend->size(); } @@ -250,3 +256,7 @@ void ActsTrk::MutableTrackStorageContainer::setReferenceSurface_impl( m_surfaces.resize(itrack + 1, nullptr); m_surfaces[itrack] = std::move(surface); } + +void ActsTrk::MutableTrackStorageContainer::setParticleHypothesis_impl(ActsTrk::IndexType itrack, const Acts::ParticleHypothesis& particleHypothesis) { + m_mutableTrackBackend->at(itrack)->setParticleHypothesis(ActsTrk::ParticleHypothesis::convert(particleHypothesis)); +}