Skip to content

Commit

Permalink
Add a utility function to return a leading track of the Reconstructed…
Browse files Browse the repository at this point in the history
…Particle
  • Loading branch information
dudarboh committed Sep 12, 2022
1 parent db5c9ff commit 1e46059
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/cpp/include/UTIL/ReconstructedParticleTools.h
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions src/cpp/src/UTIL/ReconstructedParticleTools.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "UTIL/ReconstructedParticleTools.h"
#include <algorithm>
#include "UTIL/TrackTools.h"
// #include <vector>

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;
}
}

0 comments on commit 1e46059

Please sign in to comment.