Skip to content
Snippets Groups Projects
Commit c16c8d20 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'refactor-for-acts-particle-hypothesis-encoding' into 'main'

Add simple code to convert between xAOD and Acts ParticleHypothesis standards

See merge request !67939
parents ddbc9986 2787abdc
No related branches found
No related tags found
No related merge requests found
......@@ -16,5 +16,7 @@ namespace xAOD {
AUX_VARIABLE(nSharedHits);
AUX_VARIABLE(tipIndex);
AUX_VARIABLE(stemIndex);
AUX_VARIABLE(particleHypothesis);
}
}
......@@ -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> >
......
......@@ -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;
};
}
......
......@@ -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)
*/
......
/*
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
......@@ -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;
......
/*
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
......@@ -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));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment