Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-12 08:54:08

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2025 Chao Peng, Dhevan Gangadharan, Sebouh Paul, Derek Anderson
0003 
0004 #pragma once
0005 
0006 #include <algorithms/algorithm.h>
0007 #include <edm4eic/ClusterCollection.h>
0008 #include <edm4eic/MCRecoClusterParticleAssociationCollection.h>
0009 #include <algorithm>
0010 #include <cmath>
0011 #include <functional>
0012 #include <map>
0013 #include <optional>
0014 #include <string>
0015 #include <string_view>
0016 #include <utility>
0017 
0018 #include "CalorimeterClusterShapeConfig.h"
0019 #include "algorithms/interfaces/WithPodConfig.h"
0020 
0021 namespace eicrecon {
0022 
0023 // --------------------------------------------------------------------------
0024 //! Algorithm input/output
0025 // --------------------------------------------------------------------------
0026 using CalorimeterClusterShapeAlgorithm = algorithms::Algorithm<
0027     algorithms::Input<edm4eic::ClusterCollection,
0028                       std::optional<edm4eic::MCRecoClusterParticleAssociationCollection>>,
0029     algorithms::Output<edm4eic::ClusterCollection,
0030                        std::optional<edm4eic::MCRecoClusterParticleAssociationCollection>>>;
0031 
0032 // --------------------------------------------------------------------------
0033 //! Calculate cluster shapes for provided clusters
0034 // --------------------------------------------------------------------------
0035 /*! An algorithm which takes a collection of clusters,
0036    *  computes their cluster shape parameters, and saves
0037    *  outputs the same clusters with computed parameters.
0038    */
0039 class CalorimeterClusterShape : public CalorimeterClusterShapeAlgorithm,
0040                                 public WithPodConfig<CalorimeterClusterShapeConfig> {
0041 
0042 public:
0043   // ctor
0044   CalorimeterClusterShape(std::string_view name)
0045       : CalorimeterClusterShapeAlgorithm{name,
0046                                          {"inputClusters", "inputMCClusterAssociations"},
0047                                          {"outputClusters", "outputMCClusterAssociations"},
0048                                          "Computes cluster shape parameters"} {}
0049 
0050   // public methods
0051   void init() final;
0052   void process(const Input&, const Output&) const final;
0053 
0054 private:
0055   //! constant weighting
0056   static double constWeight(double /*E*/, double /*tE*/, double /*p*/, int /*type*/) { return 1.0; }
0057 
0058   //! linear weighting by energy
0059   static double linearWeight(double E, double /*tE*/, double /*p*/, int /*type*/) { return E; }
0060 
0061   //! log weighting by energy
0062   static double logWeight(double E, double tE, double base, int /*type*/) {
0063     return std::max(0., base + std::log(E / tE));
0064   }
0065 
0066   //! map of weighting method to function
0067   const std::map<std::string, std::function<double(double, double, double, int)>> m_weightMethods =
0068       {{"none", constWeight}, {"linear", linearWeight}, {"log", logWeight}};
0069 
0070   //! weight function selected by m_cfg.energyWeight
0071   std::function<double(double, double, double, int)> m_weightFunc;
0072 };
0073 
0074 } // namespace eicrecon