forked from key4hep/EDM4hep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility class to reverse RecDqdx - Track relations
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |