Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-28 09:20:35

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2026 Chun Yuen Tsang, Minho Kim
0003 
0004 // Temporary BEMC compatibility implementation until its single-sided CALOROC migration.
0005 
0006 #pragma once
0007 
0008 #include <DD4hep/DetElement.h>
0009 #include <DD4hep/Detector.h>
0010 #include <DD4hep/IDDescriptor.h>
0011 #include <DDRec/CellIDPositionConverter.h>
0012 #include <Parsers/Primitives.h>
0013 #include <algorithms/algorithm.h>
0014 #include <algorithms/geo.h>
0015 #include <edm4eic/CalorimeterHitCollection.h>
0016 #include <edm4eic/MCRecoCalorimeterHitAssociationCollection.h>
0017 #include <edm4eic/MCRecoCalorimeterHitLinkCollection.h>
0018 #include <edm4eic/RawCALOROCHitCollection.h>
0019 #include <edm4hep/RawCalorimeterHitCollection.h>
0020 #include <edm4hep/SimCalorimeterHitCollection.h>
0021 #include <cstddef>
0022 #include <gsl/pointers>
0023 #include <map>
0024 #include <string>
0025 #include <string_view>
0026 #include <vector>
0027 
0028 #include "CalorimeterCALOROCRecoLegacyConfig.h"
0029 #include "algorithms/interfaces/WithPodConfig.h"
0030 
0031 namespace eicrecon {
0032 
0033 using CalorimeterCALOROCRecoLegacyAlgorithm = algorithms::Algorithm<
0034     algorithms::Input<edm4hep::SimCalorimeterHitCollection, edm4eic::RawCALOROCHitCollection,
0035                       edm4hep::SimCalorimeterHitCollection, edm4eic::RawCALOROCHitCollection>,
0036     algorithms::Output<edm4eic::CalorimeterHitCollection, edm4hep::RawCalorimeterHitCollection,
0037                        edm4eic::MCRecoCalorimeterHitLinkCollection,
0038                        edm4eic::MCRecoCalorimeterHitAssociationCollection>>;
0039 
0040 class CalorimeterCALOROCRecoLegacy : public CalorimeterCALOROCRecoLegacyAlgorithm,
0041                                      public WithPodConfig<CalorimeterCALOROCRecoLegacyConfig> {
0042 
0043 public:
0044   CalorimeterCALOROCRecoLegacy(std::string_view name)
0045       : CalorimeterCALOROCRecoLegacyAlgorithm{
0046             name,
0047             {"inputNpeHitPCollection", "inputADCPCollection", "inputNpeHitNCollection",
0048              "inputADCNCollection"},
0049             {"outputRecHitCollection", "outputRawHitCollection", "outputRawLink", "outputRawAssoc"},
0050             "Reconstruct hit from CALOROC ADC data with MC truth from NpeHits."} {}
0051 
0052   void init() final;
0053   void process(const Input&, const Output&) const final;
0054 
0055 private:
0056   dd4hep::IDDescriptor id_spec;
0057   dd4hep::BitFieldCoder* id_dec = nullptr;
0058 
0059   double m_reference_z_p, m_reference_z_n;
0060   std::size_t sector_idx{0}, layer_idx{0};
0061 
0062   mutable bool warned_unsupported_segmentation = false;
0063 
0064   dd4hep::DetElement m_local;
0065   std::size_t local_mask = ~static_cast<std::size_t>(0), gpos_mask = static_cast<std::size_t>(0);
0066 
0067   std::map<std::vector<int>, double> m_edep_to_npe_lut{};
0068   std::vector<std::size_t> m_field_idxs{};
0069 
0070   double _energyCor(double referencePos, double energy, double z) const;
0071   double _sumADC(const edm4eic::RawCALOROCHit& ADC) const;
0072   static double _toa(const edm4eic::RawCALOROCHit& ADC);
0073   double _timeWalkCorrection(double toa, double ADC) const;
0074 
0075   const algorithms::GeoSvc& m_geo = algorithms::GeoSvc::instance();
0076 
0077 private:
0078   const dd4hep::Detector* m_detector{algorithms::GeoSvc::instance().detector()};
0079   const dd4hep::rec::CellIDPositionConverter* m_converter{
0080       algorithms::GeoSvc::instance().cellIDPositionConverter()};
0081 };
0082 
0083 } // namespace eicrecon