Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 09:14:53

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2025 Chun Yuen Tsang
0003 
0004 #pragma once
0005 #include <DD4hep/DetElement.h>
0006 #include <DD4hep/Detector.h>
0007 #include <DD4hep/Segmentations.h>
0008 #include <DDRec/CellIDPositionConverter.h>
0009 #include <DDSegmentation/BitFieldCoder.h>
0010 #include <DDSegmentation/CartesianGridXY.h>
0011 #include <algorithms/algorithm.h>
0012 #include <edm4eic/Measurement2DCollection.h>
0013 #include <edm4eic/TrackerHitCollection.h>
0014 #include <spdlog/logger.h>
0015 #include <memory>
0016 #include <string>
0017 #include <string_view>
0018 #include <unordered_map>
0019 #include <vector>
0020 
0021 #include "LGADHitClusteringConfig.h"
0022 #include "algorithms/interfaces/WithPodConfig.h"
0023 #include "algorithms/tracking/ActsGeometryProvider.h"
0024 
0025 namespace eicrecon {
0026 
0027 using LGADHitClusteringAlgorithm =
0028     algorithms::Algorithm<algorithms::Input<edm4eic::TrackerHitCollection>,
0029                           algorithms::Output<edm4eic::Measurement2DCollection>>;
0030 
0031 class LGADHitClustering : public LGADHitClusteringAlgorithm,
0032                           public WithPodConfig<LGADHitClusteringConfig> {
0033 
0034 public:
0035   LGADHitClustering(std::string_view name)
0036       : LGADHitClusteringAlgorithm{name, {"TOFBarrelCalHit"}, {"TOFBarrelRecHit"}, ""} {};
0037 
0038   void init() final;
0039   void process(const Input&, const Output&) const final;
0040 
0041 private:
0042   void _calcCluster(const Output& output, const std::vector<edm4eic::TrackerHit>& hits) const;
0043 
0044   /** algorithm logger */
0045   std::shared_ptr<spdlog::logger> m_log;
0046 
0047   /// Cell ID position converter
0048   const dd4hep::rec::CellIDPositionConverter* m_converter = nullptr;
0049 
0050   /// fetch sensor information from cellID
0051   const dd4hep::DDSegmentation::BitFieldCoder* m_decoder = nullptr;
0052 
0053   const dd4hep::Detector* m_detector = nullptr;
0054 
0055   dd4hep::Segmentation m_seg;
0056 
0057   std::shared_ptr<const ActsGeometryProvider> m_acts_context;
0058 
0059   // neighbor finding algorithm copied from SiliconChargeSharing
0060   const dd4hep::DDSegmentation::CartesianGridXY*
0061   getLocalSegmentation(const dd4hep::rec::CellID& cellID) const;
0062 
0063   mutable std::unordered_map<const dd4hep::DetElement*,
0064                              const dd4hep::DDSegmentation::CartesianGridXY*>
0065       m_segmentation_map;
0066 
0067   // union-find algorithm to group contiguous clusters
0068   class UnionFind {
0069   private:
0070     std::vector<int> mParent, mRank;
0071 
0072   public:
0073     UnionFind(int n);
0074     int find(int id);
0075     void merge(int id1, int id2);
0076   };
0077 };
0078 } // namespace eicrecon