From 1e46059a75705f616e5a7a1da91b268fc2d4b36e Mon Sep 17 00:00:00 2001 From: Bohdan Dudar Date: Wed, 31 Aug 2022 14:11:56 +0200 Subject: [PATCH] Add a utility function to return a leading track of the ReconstructedParticle --- src/cpp/CMakeLists.txt | 1 + src/cpp/include/UTIL/ReconstructedParticleTools.h | 15 +++++++++++++++ src/cpp/src/UTIL/ReconstructedParticleTools.cc | 15 +++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 src/cpp/include/UTIL/ReconstructedParticleTools.h create mode 100644 src/cpp/src/UTIL/ReconstructedParticleTools.cc 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; + } +}