EICrecon
JANA based reconstruction for the EPIC detector
Loading...
Searching...
No Matches
ConvertParticleID.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// Copyright (C) 2023, Christopher Dilks
3
4// Converters of ParticleID objects
5//
6
7#pragma once
8
9#include <cstddef>
10#include <map>
11
12// data model
13#include <edm4eic/CherenkovParticleID.h>
14#include <edm4eic/CherenkovParticleIDHypothesis.h>
15#include <edm4hep/ParticleIDCollection.h>
16
17namespace eicrecon {
18
20public:
21 // index map, used for external access to the converted objects
22 using IndexMap = std::map<std::size_t, unsigned int>; // <collection index, object ID>
23
24 // convert edm4eic::CherenkovParticleID hypotheses to list of edm4hep::ParticleID objects
25 // - requires input `CherenkovParticleID` object `in_pid`
26 // - adds output `ParticleID` objects to collection `out_pids`
27 // - sorted by likelihood, if `sort_by_likelihood==true`
28 // - returns a map of the new `out_pid` indices to new `ParticleID` IDs, so the caller can
29 // access the newly created `ParticleID` objects
30 static IndexMap ConvertToParticleIDs(const edm4eic::CherenkovParticleID& in_pid,
31 edm4hep::ParticleIDCollection& out_pids,
32 bool sort_by_likelihood = false) {
33
34 // output vector of collection indices
35 IndexMap out_indices;
36
37 // build list of (hypothesis index, hypothesis weight)
38 using HypIndex =
39 std::pair<std::size_t, decltype(edm4eic::CherenkovParticleIDHypothesis::weight)>;
40 std::vector<HypIndex> hyp_indices;
41 for (std::size_t hyp_index = 0; hyp_index < in_pid.hypotheses_size(); hyp_index++)
42 hyp_indices.push_back(HypIndex{hyp_index, in_pid.getHypotheses(hyp_index).weight});
43
44 // sort it by likelihood, if needed
45 if (sort_by_likelihood)
46 std::sort(hyp_indices.begin(), hyp_indices.end(),
47 [](HypIndex& a, HypIndex& b) { return a.second > b.second; });
48
49 // create and fill output objects
50 for (const auto& [hyp_index, hyp_weight] : hyp_indices) {
51
52 // get the input hypothesis
53 auto in_hyp = in_pid.getHypotheses(hyp_index);
54
55 // create output `ParticleID` object
56 auto out_index = out_pids.size();
57 auto out_pid = out_pids.create();
58 out_indices.insert({out_index, out_pid.getObjectID().index});
59
60 // fill scalars
61 out_pid.setPDG(static_cast<decltype(edm4hep::ParticleIDData::PDG)>(in_hyp.PDG));
62 out_pid.setLikelihood(
63 static_cast<decltype(edm4hep::ParticleIDData::likelihood)>(in_hyp.weight));
64 out_pid.setType(
65 static_cast<decltype(edm4hep::ParticleIDData::type)>(0)); // FIXME: not used yet
66 out_pid.setAlgorithmType(
67 static_cast<decltype(edm4hep::ParticleIDData::algorithmType)>(0)); // FIXME: not used yet
68
69 // fill parameters vector
70 out_pid.addToParameters(static_cast<float>(in_hyp.npe)); // NPE for this hypothesis
71 }
72
73 return out_indices;
74 }
75
76}; // class ConvertParticleID
77} // namespace eicrecon
Definition ConvertParticleID.h:19
static IndexMap ConvertToParticleIDs(const edm4eic::CherenkovParticleID &in_pid, edm4hep::ParticleIDCollection &out_pids, bool sort_by_likelihood=false)
Definition ConvertParticleID.h:30
std::map< std::size_t, unsigned int > IndexMap
Definition ConvertParticleID.h:22
-client
Definition CalorimeterClusterRecoCoG.cc:37