Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-13 08:54:49

0001 // Copyright (C) 2022, 2023 Chao Peng, Wouter Deconinck, Sylvester Joosten, Thomas Britton
0002 // SPDX-License-Identifier: LGPL-3.0-or-later
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/RawCalorimeterHit.h>
0013 #include <edm4hep/Vector2f.h>
0014 #include <array>
0015 #include <cstddef>
0016 #include <functional>
0017 #include <gsl/pointers>
0018 #include <set>
0019 #include <string>
0020 #include <string_view>
0021 #include <vector>
0022 
0023 #include "CalorimeterIslandClusterConfig.h"
0024 #include "algorithms/interfaces/WithPodConfig.h"
0025 
0026 namespace eicrecon {
0027 
0028 using CaloHit = edm4eic::CalorimeterHit;
0029 
0030 using CalorimeterIslandClusterAlgorithm =
0031     algorithms::Algorithm<algorithms::Input<edm4eic::CalorimeterHitCollection>,
0032                           algorithms::Output<edm4eic::ProtoClusterCollection>>;
0033 
0034 class CalorimeterIslandCluster : public CalorimeterIslandClusterAlgorithm,
0035                                  public WithPodConfig<CalorimeterIslandClusterConfig> {
0036 
0037 public:
0038   CalorimeterIslandCluster(std::string_view name)
0039       : CalorimeterIslandClusterAlgorithm{name,
0040                                           {"inputProtoClusterCollection"},
0041                                           {"outputClusterCollection"},
0042                                           "Island clustering."} {}
0043 
0044   void init() final;
0045   void process(const Input&, const Output&) const final;
0046 
0047 private:
0048   const dd4hep::Detector* m_detector{algorithms::GeoSvc::instance().detector()};
0049   std::vector<double> m_localDistXY;
0050 
0051 public:
0052   // neighbor checking function
0053   std::function<edm4hep::Vector2f(const CaloHit&, const CaloHit&)> hitsDist;
0054 
0055   std::function<edm4hep::Vector2f(const CaloHit& h1, const CaloHit& h2)>
0056       transverseEnergyProfileMetric;
0057   double u_transverseEnergyProfileScale;
0058   double transverseEnergyProfileScaleUnits;
0059 
0060   // helper function to group hits
0061   std::function<bool(const CaloHit& h1, const CaloHit& h2)> is_neighbour;
0062 
0063   // helper function to define hit maximum
0064   std::function<bool(const CaloHit& maximum, const CaloHit& other)> is_maximum_neighbourhood;
0065 
0066   // unitless counterparts of the input parameters
0067   std::array<double, 2> neighbourDist;
0068 
0069   // Pointer to the geometry service
0070   dd4hep::IDDescriptor m_idSpec;
0071 
0072 private:
0073   // grouping function with Breadth-First Search
0074   void bfs_group(const edm4eic::CalorimeterHitCollection& hits, std::set<std::size_t>& group,
0075                  std::size_t idx, std::vector<bool>& visits) const;
0076 
0077   // find local maxima that above a certain threshold
0078   std::vector<std::size_t> find_maxima(const edm4eic::CalorimeterHitCollection& hits,
0079                                        const std::set<std::size_t>& group,
0080                                        bool global = false) const;
0081 
0082   // helper function
0083   inline static void vec_normalize(std::vector<double>& vals) {
0084     double total = 0.;
0085     for (auto& val : vals) {
0086       total += val;
0087     }
0088     for (auto& val : vals) {
0089       val /= total;
0090     }
0091   }
0092 
0093   // split a group of hits according to the local maxima
0094   void split_group(const edm4eic::CalorimeterHitCollection& hits, std::set<std::size_t>& group,
0095                    const std::vector<std::size_t>& maxima,
0096                    edm4eic::ProtoClusterCollection* protoClusters) const;
0097 };
0098 
0099 } // namespace eicrecon