Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:04:50

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 - 2025 Chao Peng, Jihee Kim, Sylvester Joosten, Whitney Armstrong, Wouter Deconinck, David Lawrence, Derek Anderson
0003 
0004 /*
0005  *  An algorithm to group readout hits from a calorimeter
0006  *  Energy is summed
0007  *
0008  *  Author: Chao Peng (ANL), 03/31/2021
0009  */
0010 
0011 #pragma once
0012 
0013 #include <DD4hep/Detector.h>
0014 #include <DD4hep/IDDescriptor.h>
0015 #include <DDRec/CellIDPositionConverter.h>
0016 #include <Parsers/Primitives.h>
0017 #include <algorithms/algorithm.h>
0018 #include <algorithms/geo.h>
0019 #include <edm4eic/CalorimeterHitCollection.h>
0020 #include <stdint.h>
0021 #include <cstddef>
0022 #include <functional>
0023 #include <gsl/pointers>
0024 #include <map>
0025 #include <string>
0026 #include <string_view>
0027 #include <unordered_map>
0028 #include <utility>
0029 #include <vector>
0030 
0031 #include "CalorimeterHitsMergerConfig.h"
0032 #include "algorithms/interfaces/WithPodConfig.h"
0033 
0034 namespace eicrecon {
0035 
0036   // aliases for convenience
0037   using MergeMap = std::unordered_map<uint64_t, std::vector<std::size_t>>;
0038   using RefField = std::pair<std::string, int>;
0039   using MapFunc = std::function<int(const edm4eic::CalorimeterHit&)>;
0040 
0041   using CalorimeterHitsMergerAlgorithm = algorithms::Algorithm<
0042     algorithms::Input<
0043       edm4eic::CalorimeterHitCollection
0044     >,
0045     algorithms::Output<
0046       edm4eic::CalorimeterHitCollection
0047     >
0048   >;
0049 
0050   class CalorimeterHitsMerger
0051   : public CalorimeterHitsMergerAlgorithm,
0052     public WithPodConfig<CalorimeterHitsMergerConfig> {
0053 
0054   public:
0055     CalorimeterHitsMerger(std::string_view name)
0056       : CalorimeterHitsMergerAlgorithm{name,
0057                             {"inputHitCollection"},
0058                             {"outputHitCollection"},
0059                             "Group readout hits from a calorimeter."} {}
0060 
0061     void init() final;
0062     void process(const Input&, const Output&) const final;
0063 
0064   private:
0065     uint64_t ref_mask{0};
0066 
0067   private:
0068     mutable std::map<std::string, MapFunc> ref_maps;
0069     dd4hep::IDDescriptor id_desc;
0070     dd4hep::BitFieldCoder* id_decoder;
0071 
0072   private:
0073     const dd4hep::Detector* m_detector{algorithms::GeoSvc::instance().detector()};
0074     const dd4hep::rec::CellIDPositionConverter* m_converter{algorithms::GeoSvc::instance().cellIDPositionConverter()};
0075 
0076   private:
0077     void build_merge_map(const edm4eic::CalorimeterHitCollection* in_hits, MergeMap& merge_map) const;
0078 
0079   };
0080 
0081 } // namespace eicrecon