File indexing completed on 2024-09-27 07:02:57
0001
0002
0003
0004 #include "CalorimeterTruthClustering.h"
0005
0006 #include <DD4hep/config.h>
0007 #include <edm4hep/CaloHitContributionCollection.h>
0008 #include <edm4hep/MCParticleCollection.h>
0009 #include <podio/ObjectID.h>
0010 #include <cstddef>
0011 #include <cstdint>
0012 #include <gsl/pointers>
0013 #include <map>
0014
0015 using namespace dd4hep;
0016
0017 namespace eicrecon {
0018
0019 void CalorimeterTruthClustering::init() { }
0020
0021
0022 void CalorimeterTruthClustering::process(
0023 const CalorimeterTruthClustering::Input& input,
0024 const CalorimeterTruthClustering::Output& output) const {
0025 const auto [hits, mc] = input;
0026 auto [clusters] = output;
0027
0028
0029 std::map<int32_t, int32_t> protoIndex;
0030
0031
0032 for (const auto& hit : *hits) {
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 std::size_t mcIndex;
0052 if ((hit.getObjectID().index >= 0) && (hit.getObjectID().index < mc->size())) {
0053 mcIndex = hit.getObjectID().index;
0054 } else {
0055 mcIndex = 0;
0056 bool success = false;
0057 for (auto tmpmc : *mc) {
0058 if (tmpmc.getCellID() == hit.getCellID()) {
0059 success = true;
0060 break;
0061 }
0062 mcIndex++;
0063 }
0064 if (not success) {
0065 continue;
0066 }
0067 }
0068
0069 const auto &trackID = (*mc)[mcIndex].getContributions(0).getParticle().getObjectID().index;
0070
0071 if (protoIndex.count(trackID) == 0) {
0072 clusters->create();
0073 protoIndex[trackID] = clusters->size() - 1;
0074 }
0075
0076 (*clusters)[protoIndex[trackID]].addToHits(hit);
0077 (*clusters)[protoIndex[trackID]].addToWeights(1);
0078 }
0079
0080 }
0081
0082 }