Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-24 08:25:02

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