Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-05 09:11:17

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2026 Sebouh Paul, Baptiste Fraisse
0003 
0004 #pragma once
0005 #include <DD4hep/Detector.h>
0006 #include <algorithms/algorithm.h>
0007 #include <algorithms/geo.h>
0008 #include <edm4eic/ClusterCollection.h>
0009 #include <edm4eic/ReconstructedParticleCollection.h>
0010 #include <spdlog/logger.h>
0011 #include <gsl/pointers>
0012 #include <memory>
0013 #include <string>      // for basic_string
0014 #include <string_view> // for string_view
0015 #include <vector>
0016 #include <functional>
0017 #include "algorithms/interfaces/WithPodConfig.h"
0018 #include "services/particle/ParticleSvc.h"
0019 #include "algorithms/reco/FarForwardNeutralsReconstructionConfig.h"
0020 
0021 namespace eicrecon {
0022 
0023 using FarForwardNeutralsReconstructionAlgorithm =
0024 
0025     algorithms::Algorithm<
0026         algorithms::Input<const edm4eic::ClusterCollection,  // clusters ZDC-Hcal
0027                           const edm4eic::ClusterCollection,  // clusters B0-Ecal
0028                           const edm4eic::ClusterCollection,  // clusters EndcapP-Ecal
0029                           const edm4eic::ClusterCollection>, // clusters LFHCAL
0030 
0031         algorithms::Output<
0032             edm4eic::ReconstructedParticleCollection,   // neutrons/gamma in ZDC-Hcal
0033             edm4eic::ReconstructedParticleCollection,   // neutrons/gamma in B0-Ecal
0034             edm4eic::ReconstructedParticleCollection,   // neutrons/gamma in EndcapP-Ecal
0035             edm4eic::ReconstructedParticleCollection>>; // neutrons/gamma in LFHCAL
0036 /**
0037  * Reconstructs far-forward neutral candidates from multiple calorimeter cluster collections.
0038  *
0039  * This algorithm processes clusters from the configured far-forward calorimeters
0040  * and builds reconstructed neutral candidates used downstream in the far-forward
0041  * Lambda reconstruction chain.
0042  *
0043  * Photon-like candidates are identified from calorimeter-cluster properties and
0044  * detector-dependent selections. The remaining neutral energy deposits can be used
0045  * to form neutron-like candidates, depending on the detector response and clustering
0046  * configuration.
0047  *
0048  * The reconstructed energies are corrected using detector-dependent linear
0049  * calibration functions. Separate calibration parameters can be configured for
0050  * the different calorimeters and neutral-candidate types.
0051  *
0052  * This implementation is intended to support a multi-calorimeter workflow beyond
0053  * the ZDC-only reconstruction.
0054  */
0055 class FarForwardNeutralsReconstruction
0056     : public FarForwardNeutralsReconstructionAlgorithm,
0057       public WithPodConfig<FarForwardNeutralsReconstructionConfig> {
0058 public:
0059   FarForwardNeutralsReconstruction(std::string_view name)
0060       : FarForwardNeutralsReconstructionAlgorithm{
0061             name,
0062 
0063             {"clustersHcal", "clustersB0", "clustersEcalEndCapP", "clustersLFHCAL"},
0064 
0065             {"outputNeutralsHcal", "outputNeutralsB0", "outputNeutralsEcalEndCapP",
0066              "outputNeutralsLFHCAL"},
0067 
0068             "Convert EMCal and HCal clusters into neutron or photon candidates"} {}
0069 
0070   void init() final;
0071   void process(const Input&, const Output&) const final;
0072 
0073 private:
0074   bool isGamma(const edm4eic::Cluster& cluster) const;
0075   std::shared_ptr<spdlog::logger> m_log;
0076   const algorithms::ParticleSvc& m_particleSvc = algorithms::ParticleSvc::instance();
0077   const dd4hep::Detector* m_detector{algorithms::GeoSvc::instance().detector()};
0078   double m_gammaZMax{0};
0079 
0080   enum class GammaMode { None, LeaderOnly, AllPassing };
0081   enum class NeutronMode { None, SumAll, LeaderOnly };
0082 
0083   using CorrFunc = std::function<double(double, const std::vector<double>&)>;
0084 
0085   static double corrPower(double E, const std::vector<double>& coeffs);
0086 
0087   int processNeutralCalo(const edm4eic::ClusterCollection* clusters,
0088                          edm4eic::ReconstructedParticleCollection* out_neutrals,
0089                          const std::vector<double>& gammaScaleCoeff,
0090                          const std::vector<double>& neutronScaleCoeff, bool canDetectGammas,
0091                          bool canDetectNeutrons, const CorrFunc& gammaCorr,
0092                          const CorrFunc& neutronCorr, GammaMode gammaMode,
0093                          double gammaLeaderFracMin, double clusterEmin, NeutronMode neutronMode,
0094                          bool associateAllClustersToNeutron) const;
0095 };
0096 
0097 } // namespace eicrecon