File indexing completed on 2025-07-11 08:30:19
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <cstddef>
0010 #include <map>
0011
0012
0013 #include <edm4eic/CherenkovParticleID.h>
0014 #include <edm4eic/CherenkovParticleIDHypothesis.h>
0015 #include <edm4hep/ParticleIDCollection.h>
0016
0017 namespace eicrecon {
0018
0019 class ConvertParticleID {
0020 public:
0021
0022 using IndexMap = std::map<std::size_t, unsigned int>;
0023
0024
0025
0026
0027
0028
0029
0030 static IndexMap ConvertToParticleIDs(const edm4eic::CherenkovParticleID& in_pid,
0031 edm4hep::ParticleIDCollection& out_pids,
0032 bool sort_by_likelihood = false) {
0033
0034
0035 IndexMap out_indices;
0036
0037
0038 using HypIndex =
0039 std::pair<std::size_t, decltype(edm4eic::CherenkovParticleIDHypothesis::weight)>;
0040 std::vector<HypIndex> hyp_indices;
0041 for (std::size_t hyp_index = 0; hyp_index < in_pid.hypotheses_size(); hyp_index++)
0042 hyp_indices.push_back(HypIndex{hyp_index, in_pid.getHypotheses(hyp_index).weight});
0043
0044
0045 if (sort_by_likelihood)
0046 std::sort(hyp_indices.begin(), hyp_indices.end(),
0047 [](HypIndex& a, HypIndex& b) { return a.second > b.second; });
0048
0049
0050 for (const auto& [hyp_index, hyp_weight] : hyp_indices) {
0051
0052
0053 auto in_hyp = in_pid.getHypotheses(hyp_index);
0054
0055
0056 auto out_index = out_pids.size();
0057 auto out_pid = out_pids.create();
0058 out_indices.insert({out_index, out_pid.getObjectID().index});
0059
0060
0061 out_pid.setPDG(static_cast<decltype(edm4hep::ParticleIDData::PDG)>(in_hyp.PDG));
0062 out_pid.setLikelihood(
0063 static_cast<decltype(edm4hep::ParticleIDData::likelihood)>(in_hyp.weight));
0064 out_pid.setType(
0065 static_cast<decltype(edm4hep::ParticleIDData::type)>(0));
0066 out_pid.setAlgorithmType(
0067 static_cast<decltype(edm4hep::ParticleIDData::algorithmType)>(0));
0068
0069
0070 out_pid.addToParameters(static_cast<float>(in_hyp.npe));
0071 }
0072
0073 return out_indices;
0074 }
0075
0076 };
0077 }