Skip to content

Commit

Permalink
Add utility class to reverse RecDqdx - Track relations
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jul 10, 2024
1 parent b8a2f75 commit 14ca9e3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target_compile_features(kinematics INTERFACE cxx_std_17)
set(utils_sources
src/ParticleIDUtils.cc
src/MurmurHash3.cpp
src/TrackUtils.cc
)

add_library(utils SHARED ${utils_sources})
Expand Down
27 changes: 27 additions & 0 deletions utils/include/edm4hep/utils/TrackUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef EDM4HEP_UTILS_TRACKUTILS_H
#define EDM4HEP_UTILS_TRACKUTILS_H

#include <edm4hep/RecDqdxCollection.h>
#include <edm4hep/Track.h>

#include <podio/Frame.h>

#include <map>
#include <vector>

namespace edm4hep::utils {
/// Utility class to invert the relations between RecDqdx to Track relation
class TrackPIDHandler {
using TrackMapT = std::multimap<edm4hep::Track, edm4hep::RecDqdx>;

TrackMapT m_trackDqMap{}; ///< The internal map from tracks to RecDqdx
public:
/// Add the information from the passed collection to the handler
void addColl(const edm4hep::RecDqdxCollection& coll);

/// Get all RecDqdx objects for the given track
std::vector<edm4hep::RecDqdx> getDqdxValues(const edm4hep::Track& track) const;
};
} // namespace edm4hep::utils

#endif // EDM4HEP_UTILS_TRACKUTILS_H
26 changes: 26 additions & 0 deletions utils/src/TrackUtils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "edm4hep/utils/TrackUtils.h"
#include "edm4hep/RecDqdxCollection.h"

#include <iterator>

namespace edm4hep::utils {

void TrackPIDHandler::addColl(const edm4hep::RecDqdxCollection& coll) {
for (const auto dqdx : coll) {
m_trackDqMap.emplace(dqdx.getTrack(), dqdx);
}
}

std::vector<edm4hep::RecDqdx> TrackPIDHandler::getDqdxValues(const edm4hep::Track& track) const {
const auto& [begin, end] = m_trackDqMap.equal_range(track);
std::vector<edm4hep::RecDqdx> dqdxs{};
dqdxs.reserve(std::distance(begin, end));

for (auto it = begin; it != end; ++it) {
dqdxs.emplace_back(it->second);
}

return dqdxs;
}

} // namespace edm4hep::utils

0 comments on commit 14ca9e3

Please sign in to comment.