Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-14 08:50:49

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 
0017 #include "CalorimeterClusterShapeConfig.h"
0018 #include "algorithms/interfaces/WithPodConfig.h"
0019 
0020 namespace eicrecon {
0021 
0022 // --------------------------------------------------------------------------
0023 //! Algorithm input/output
0024 // --------------------------------------------------------------------------
0025 using CalorimeterClusterShapeAlgorithm = algorithms::Algorithm<
0026     algorithms::Input<edm4eic::ClusterCollection,
0027                       std::optional<edm4eic::MCRecoClusterParticleAssociationCollection>>,
0028     algorithms::Output<edm4eic::ClusterCollection,
0029                        std::optional<edm4eic::MCRecoClusterParticleAssociationCollection>>>;
0030 
0031 // --------------------------------------------------------------------------
0032 //! Calculate cluster shapes for provided clusters
0033 // --------------------------------------------------------------------------
0034 /*! An algorithm which takes a collection of clusters,
0035    *  computes their cluster shape parameters, and saves
0036    *  outputs the same clusters with computed parameters.
0037    */
0038 class CalorimeterClusterShape : public CalorimeterClusterShapeAlgorithm,
0039                                 public WithPodConfig<CalorimeterClusterShapeConfig> {
0040 
0041 public:
0042   // ctor
0043   CalorimeterClusterShape(std::string_view name)
0044       : CalorimeterClusterShapeAlgorithm{name,
0045                                          {"inputClusters", "inputMCClusterAssociations"},
0046                                          {"outputClusters", "outputMCClusterAssociations"},
0047                                          "Computes cluster shape parameters"} {}
0048 
0049   // public methods
0050   void init() final;
0051   void process(const Input&, const Output&) const final;
0052 
0053 private:
0054   //! constant weighting
0055   static double constWeight(double /*E*/, double /*tE*/, double /*p*/, int /*type*/) { return 1.0; }
0056 
0057   //! linear weighting by energy
0058   static double linearWeight(double E, double /*tE*/, double /*p*/, int /*type*/) { return E; }
0059 
0060   //! log weighting by energy
0061   static double logWeight(double E, double tE, double base, int /*type*/) {
0062     return std::max(0., base + std::log(E / tE));
0063   }
0064 
0065   //! map of weighting method to function
0066   const std::map<std::string, std::function<double(double, double, double, int)>> m_weightMethods =
0067       {{"none", constWeight}, {"linear", linearWeight}, {"log", logWeight}};
0068 
0069   //! weight function selected by m_cfg.energyWeight
0070   std::function<double(double, double, double, int)> m_weightFunc;
0071 };
0072 
0073 } // namespace eicrecon