diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 38e1d7cda..8bcd22a21 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -122,6 +122,7 @@ SET( LCIO_UTIL_SRCS ./src/UTIL/ProcessFlag.cc ./src/UTIL/TrackTools.cc ./src/UTIL/LCCollectionTools.cc + ./src/UTIL/ReconstructedParticleTools.cc ) SET( LCIO_MT_SRCS diff --git a/src/cpp/include/UTIL/ReconstructedParticleTools.h b/src/cpp/include/UTIL/ReconstructedParticleTools.h new file mode 100644 index 000000000..acb133ac1 --- /dev/null +++ b/src/cpp/include/UTIL/ReconstructedParticleTools.h @@ -0,0 +1,15 @@ +#ifndef UTIL_ReconstructedParticleTools_H +#define UTIL_ReconstructedParticleTools_H 1 + +#include "EVENT/ReconstructedParticle.h" +#include "EVENT/Track.h" + +namespace UTIL{ + /** Extract the leading track in case of multiple tracks attached to a single ReconstructedParticle. + * @author Bohdan Dudar + * @version August 2022 + */ + EVENT::Track* getLeadingTrack(const EVENT::ReconstructedParticle* particle, double bz); +} + +#endif diff --git a/src/cpp/src/UTIL/ReconstructedParticleTools.cc b/src/cpp/src/UTIL/ReconstructedParticleTools.cc new file mode 100644 index 000000000..792965311 --- /dev/null +++ b/src/cpp/src/UTIL/ReconstructedParticleTools.cc @@ -0,0 +1,15 @@ +#include "UTIL/ReconstructedParticleTools.h" +#include +#include "UTIL/TrackTools.h" +// #include + +namespace UTIL{ + EVENT::Track* getLeadingTrack(const EVENT::ReconstructedParticle* particle, double bz){ + const EVENT::TrackVec& tracks = particle->getTracks(); + if ( tracks.empty() ) return nullptr; + auto sortByMomentum = [bz](const EVENT::Track* a, const EVENT::Track* b) { return getTrackMomentum(a, bz) < getTrackMomentum(b, bz); }; + auto* leadingTrack = *(std::max_element(tracks.begin(), tracks.end(), sortByMomentum)); + + return leadingTrack; + } +}