EICrecon
JANA based reconstruction for the EPIC detector
Loading...
Searching...
No Matches
ImagingTopoCluster.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// Copyright (C) 2022 Chao Peng, Sylvester Joosten, Whitney Armstrong, Wouter Deconinck
3
4/*
5 * Topological Cell Clustering Algorithm for Imaging Calorimetry
6 * 1. group all the adjacent pixels
7 *
8 * Author: Chao Peng (ANL), 06/02/2021
9 * Original reference: https://arxiv.org/pdf/1603.02934.pdf
10 *
11 * Modifications:
12 *
13 * Wouter Deconinck (Manitoba), 08/24/2024
14 * - converted hit storage model from std::vector to std::set sorted on layer
15 * where only hits remaining to be assigned to a group are in the set
16 * - erase hits that are too low in energy to be part of a cluster
17 * - converted group storage model from std::set to std::list to allow adding
18 * hits while keeping iterators valid
19 *
20 */
21#pragma once
22
23#include <algorithms/algorithm.h>
24// Event Model related classes
25#include <edm4eic/CalorimeterHitCollection.h>
26#include <edm4eic/ProtoClusterCollection.h>
27#include <array>
28#include <cstddef>
29#include <list>
30#include <set>
31#include <string>
32#include <string_view>
33
36
37namespace eicrecon {
38
40 algorithms::Algorithm<algorithms::Input<edm4eic::CalorimeterHitCollection>,
41 algorithms::Output<edm4eic::ProtoClusterCollection>>;
42
44 public WithPodConfig<ImagingTopoClusterConfig> {
45
46public:
47 ImagingTopoCluster(std::string_view name)
49 name,
50 {"inputHitCollection"},
51 {"outputProtoClusterCollection"},
52 "Topological cell clustering algorithm for imaging calorimetry."} {}
53
54private:
55 // unitless counterparts of the input parameters
56 std::array<double, 2> sameLayerDistXY{0, 0};
57 std::array<double, 2> diffLayerDistXY{0, 0};
58 std::array<double, 2> sameLayerDistEtaPhi{0, 0};
59 std::array<double, 2> diffLayerDistEtaPhi{0, 0};
60 std::array<double, 2> sameLayerDistTZ{0, 0};
61 std::array<double, 2> diffLayerDistTZ{0, 0};
62 double sectorDist{0};
63 double minClusterHitEdep{0};
64 double minClusterCenterEdep{0};
65 double minClusterEdep{0};
66
67public:
68 void init();
69 void process(const Input& input, const Output& output) const final;
70
71private:
72 // helper function to group hits
73 bool is_neighbour(const edm4eic::CalorimeterHit& h1, const edm4eic::CalorimeterHit& h2) const;
74
75 // grouping function with Breadth-First Search
76 // note: template to allow Compare only known in local scope of caller
77 template <typename Compare>
78 void bfs_group(const edm4eic::CalorimeterHitCollection& hits,
79 std::set<std::size_t, Compare>& indices, std::list<std::size_t>& group,
80 const std::size_t idx) const {
81
82 // loop over group as it grows, until the end is stable and we reach it
83 for (auto idx1 = group.begin(); idx1 != group.end(); ++idx1) {
84 // check neighbours (note comments on loop over set above)
85 for (auto idx2 = indices.begin(); idx2 != indices.end();
86 indices.empty() ? idx2 = indices.end() : idx2) {
87
88 // skip idx1 and original idx
89 // (we cannot erase idx since it would invalidate iterator in calling scope)
90 if (*idx2 == *idx1 || *idx2 == idx) {
91 idx2++;
92 continue;
93 }
94
95 // skip rest of list of hits when we're past relevant layers
96 //if (hits[*idx2].getLayer() - hits[*idx1].getLayer() > m_cfg.neighbourLayersRange) {
97 // break;
98 //}
99
100 // not energetic enough for cluster hit
101 if (hits[*idx2].getEnergy() < m_cfg.minClusterHitEdep) {
102 idx2 = indices.erase(idx2);
103 continue;
104 }
105
106 if (is_neighbour(hits[*idx1], hits[*idx2])) {
107 group.push_back(*idx2);
108 idx2 = indices.erase(idx2); // takes role of idx2++
109 } else {
110 idx2++;
111 }
112 }
113 }
114 }
115};
116
117} // namespace eicrecon
Definition ImagingTopoCluster.h:44
ImagingTopoCluster(std::string_view name)
Definition ImagingTopoCluster.h:47
Definition WithPodConfig.h:22
-client
Definition CalorimeterClusterRecoCoG.cc:37
algorithms::Algorithm< algorithms::Input< edm4eic::CalorimeterHitCollection >, algorithms::Output< edm4eic::ProtoClusterCollection > > ImagingTopoClusterAlgorithm
Definition ImagingTopoCluster.h:41