File indexing completed on 2025-07-11 08:30:18
0001
0002
0003
0004 #pragma once
0005
0006 #include <DD4hep/Detector.h>
0007 #include <DD4hep/IDDescriptor.h>
0008 #include <algorithms/algorithm.h>
0009 #include <algorithms/geo.h>
0010 #include <edm4eic/CalorimeterHitCollection.h>
0011 #include <edm4eic/ProtoClusterCollection.h>
0012 #include <edm4hep/Vector2f.h>
0013 #include <array>
0014 #include <cstddef>
0015 #include <functional>
0016 #include <gsl/pointers>
0017 #include <set>
0018 #include <string>
0019 #include <string_view>
0020 #include <vector>
0021
0022 #include "CalorimeterIslandClusterConfig.h"
0023 #include "algorithms/interfaces/WithPodConfig.h"
0024
0025 namespace eicrecon {
0026
0027 using CaloHit = edm4eic::CalorimeterHit;
0028
0029 using CalorimeterIslandClusterAlgorithm =
0030 algorithms::Algorithm<algorithms::Input<edm4eic::CalorimeterHitCollection>,
0031 algorithms::Output<edm4eic::ProtoClusterCollection>>;
0032
0033 class CalorimeterIslandCluster : public CalorimeterIslandClusterAlgorithm,
0034 public WithPodConfig<CalorimeterIslandClusterConfig> {
0035
0036 public:
0037 CalorimeterIslandCluster(std::string_view name)
0038 : CalorimeterIslandClusterAlgorithm{name,
0039 {"inputProtoClusterCollection"},
0040 {"outputClusterCollection"},
0041 "Island clustering."} {}
0042
0043 void init() final;
0044 void process(const Input&, const Output&) const final;
0045
0046 private:
0047 const dd4hep::Detector* m_detector{algorithms::GeoSvc::instance().detector()};
0048 std::vector<double> m_localDistXY;
0049
0050 public:
0051
0052 std::function<edm4hep::Vector2f(const CaloHit&, const CaloHit&)> hitsDist;
0053
0054 std::function<edm4hep::Vector2f(const CaloHit& h1, const CaloHit& h2)>
0055 transverseEnergyProfileMetric;
0056 double u_transverseEnergyProfileScale;
0057 double transverseEnergyProfileScaleUnits;
0058
0059
0060 std::function<bool(const CaloHit& h1, const CaloHit& h2)> is_neighbour;
0061
0062
0063 std::function<bool(const CaloHit& maximum, const CaloHit& other)> is_maximum_neighbourhood;
0064
0065
0066 std::array<double, 2> neighbourDist;
0067
0068
0069 dd4hep::IDDescriptor m_idSpec;
0070
0071 private:
0072
0073 void bfs_group(const edm4eic::CalorimeterHitCollection& hits, std::set<std::size_t>& group,
0074 std::size_t idx, std::vector<bool>& visits) const;
0075
0076
0077 std::vector<std::size_t> find_maxima(const edm4eic::CalorimeterHitCollection& hits,
0078 const std::set<std::size_t>& group,
0079 bool global = false) const;
0080
0081
0082 inline static void vec_normalize(std::vector<double>& vals) {
0083 double total = 0.;
0084 for (auto& val : vals) {
0085 total += val;
0086 }
0087 for (auto& val : vals) {
0088 val /= total;
0089 }
0090 }
0091
0092
0093 void split_group(const edm4eic::CalorimeterHitCollection& hits, std::set<std::size_t>& group,
0094 const std::vector<std::size_t>& maxima,
0095 edm4eic::ProtoClusterCollection* protoClusters) const;
0096 };
0097
0098 }