-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename the EDM4HEP::utils target to not have a library that is called libutils.so
- Loading branch information
Showing
6 changed files
with
92 additions
and
5 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
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
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,48 @@ | ||
#ifndef EDM4HEP_UTILS_PARTICLEIDUTILS_H | ||
#define EDM4HEP_UTILS_PARTICLEIDUTILS_H | ||
|
||
#include <edm4hep/ParticleIDCollection.h> | ||
#include <edm4hep/ReconstructedParticle.h> | ||
|
||
#include <map> | ||
#include <type_traits> | ||
#include <vector> | ||
|
||
namespace edm4hep::utils { | ||
|
||
/// Utility class to invert the ParticleID to ReconstructedParticle relation | ||
class PIDHandler { | ||
|
||
using MapType = std::multimap<edm4hep::ReconstructedParticle, edm4hep::ParticleID>; | ||
|
||
MapType m_recoPidMap{}; ///< The internal map from recos to pids | ||
|
||
public: | ||
PIDHandler() = default; | ||
~PIDHandler() = default; | ||
PIDHandler(const PIDHandler&) = default; | ||
PIDHandler& operator=(const PIDHandler&) = default; | ||
PIDHandler(PIDHandler&&) = default; | ||
PIDHandler& operator=(PIDHandler&&) = default; | ||
|
||
/// Construct a PIDHandler from an arbitrary number of ParticleIDCollections | ||
template <typename... PIDColls> | ||
static PIDHandler from(const ParticleIDCollection& coll, const PIDColls&... pidColls) { | ||
static_assert((std::is_same_v<PIDColls, edm4hep::ParticleIDCollection> && ...), | ||
"PIDHandler can only be constructed from ParticleIDCollections"); | ||
PIDHandler handler{}; | ||
handler.addColl(coll); | ||
(handler.addColl(pidColls), ...); | ||
return handler; | ||
} | ||
|
||
/// Add the information from one ParticleIDCollection to the handler | ||
void addColl(const edm4hep::ParticleIDCollection& coll); | ||
|
||
/// Retrieve all ParticleIDs that are related to the passed | ||
/// RecontstructedParticle | ||
std::vector<edm4hep::ParticleID> getPIDs(const edm4hep::ReconstructedParticle& reco) const; | ||
}; | ||
} // namespace edm4hep::utils | ||
|
||
#endif // EDM4HEP_UTILS_PARTICLEIDUTILS_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/ReconstructedParticle.h" | ||
#include <edm4hep/utils/ParticleIDUtils.h> | ||
|
||
#include <iterator> | ||
|
||
namespace edm4hep::utils { | ||
|
||
void PIDHandler::addColl(const edm4hep::ParticleIDCollection& coll) { | ||
for (const auto pid : coll) { | ||
m_recoPidMap.emplace(pid.getParticle(), pid); | ||
} | ||
} | ||
|
||
std::vector<edm4hep::ParticleID> PIDHandler::getPIDs(const edm4hep::ReconstructedParticle& reco) const { | ||
std::vector<edm4hep::ParticleID> pids; | ||
const auto& [begin, end] = m_recoPidMap.equal_range(reco); | ||
pids.reserve(std::distance(begin, end)); | ||
|
||
for (auto it = begin; it != end; ++it) { | ||
pids.emplace_back(it->second); | ||
} | ||
|
||
return pids; | ||
} | ||
|
||
} // namespace edm4hep::utils |