File indexing completed on 2025-01-30 10:04:51
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
0023 using IndexMap = std::map<std::size_t, unsigned int>;
0024
0025
0026
0027
0028
0029
0030
0031 static IndexMap ConvertToParticleIDs(
0032 const edm4eic::CherenkovParticleID& in_pid,
0033 edm4hep::ParticleIDCollection& out_pids,
0034 bool sort_by_likelihood = false
0035 )
0036 {
0037
0038
0039 IndexMap out_indices;
0040
0041
0042 using HypIndex = std::pair<std::size_t, decltype(edm4eic::CherenkovParticleIDHypothesis::weight)>;
0043 std::vector<HypIndex> hyp_indices;
0044 for(std::size_t hyp_index=0; hyp_index<in_pid.hypotheses_size(); hyp_index++)
0045 hyp_indices.push_back(HypIndex{
0046 hyp_index,
0047 in_pid.getHypotheses(hyp_index).weight
0048 });
0049
0050
0051 if(sort_by_likelihood)
0052 std::sort(
0053 hyp_indices.begin(),
0054 hyp_indices.end(),
0055 [] (HypIndex& a, HypIndex& b) { return a.second > b.second; }
0056 );
0057
0058
0059 for(const auto& [hyp_index, hyp_weight] : hyp_indices) {
0060
0061
0062 auto in_hyp = in_pid.getHypotheses(hyp_index);
0063
0064
0065 auto out_index = out_pids.size();
0066 auto out_pid = out_pids.create();
0067 out_indices.insert({out_index, out_pid.getObjectID().index});
0068
0069
0070 out_pid.setPDG( static_cast<decltype(edm4hep::ParticleIDData::PDG)> (in_hyp.PDG) );
0071 out_pid.setLikelihood( static_cast<decltype(edm4hep::ParticleIDData::likelihood)> (in_hyp.weight) );
0072 out_pid.setType( static_cast<decltype(edm4hep::ParticleIDData::type)> (0) );
0073 out_pid.setAlgorithmType( static_cast<decltype(edm4hep::ParticleIDData::algorithmType)> (0) );
0074
0075
0076 out_pid.addToParameters( static_cast<float> (in_hyp.npe) );
0077
0078 }
0079
0080 return out_indices;
0081 }
0082
0083 };
0084 }