File indexing completed on 2024-06-29 07:05:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #pragma once
0012
0013 #include <algorithms/algorithm.h>
0014 #include <edm4eic/ClusterCollection.h>
0015 #include <edm4eic/MCRecoClusterParticleAssociationCollection.h>
0016 #include <edm4eic/ProtoClusterCollection.h>
0017 #include <edm4hep/SimCalorimeterHitCollection.h>
0018 #include <algorithm>
0019 #include <cmath>
0020 #include <functional>
0021 #include <map>
0022 #include <memory>
0023 #include <optional>
0024 #include <string>
0025 #include <string_view>
0026 #include <utility>
0027
0028 #include "CalorimeterClusterRecoCoGConfig.h"
0029 #include "algorithms/interfaces/WithPodConfig.h"
0030
0031 static double constWeight(double , double , double , int ) { return 1.0; }
0032 static double linearWeight(double E, double , double , int ) { return E; }
0033 static double logWeight(double E, double tE, double base, int ) {
0034 return std::max(0., base + std::log(E / tE));
0035 }
0036
0037 static const std::map<std::string, std::function<double(double, double, double, int)>> weightMethods={
0038 {"none", constWeight},
0039 {"linear", linearWeight},
0040 {"log", logWeight},
0041 };
0042
0043 namespace eicrecon {
0044
0045 using ClustersWithAssociations = std::pair<
0046 std::unique_ptr<edm4eic::ClusterCollection>,
0047 std::unique_ptr<edm4eic::MCRecoClusterParticleAssociationCollection>
0048 >;
0049
0050 using CalorimeterClusterRecoCoGAlgorithm = algorithms::Algorithm<
0051 algorithms::Input<
0052 edm4eic::ProtoClusterCollection,
0053 std::optional<edm4hep::SimCalorimeterHitCollection>
0054 >,
0055 algorithms::Output<
0056 edm4eic::ClusterCollection,
0057 std::optional<edm4eic::MCRecoClusterParticleAssociationCollection>
0058 >
0059 >;
0060
0061 class CalorimeterClusterRecoCoG
0062 : public CalorimeterClusterRecoCoGAlgorithm,
0063 public WithPodConfig<CalorimeterClusterRecoCoGConfig> {
0064
0065 public:
0066 CalorimeterClusterRecoCoG(std::string_view name)
0067 : CalorimeterClusterRecoCoGAlgorithm{name,
0068 {"inputProtoClusterCollection", "mcHits"},
0069 {"outputClusterCollection", "outputAssociations"},
0070 "Reconstruct a cluster with the Center of Gravity method. For "
0071 "simulation results it optionally creates a Cluster <-> MCParticle "
0072 "association provided both optional arguments are provided."} {}
0073
0074 public:
0075 void init() final;
0076
0077 void process(const Input&, const Output&) const final;
0078
0079 private:
0080 std::function<double(double, double, double, int)> weightFunc;
0081
0082 private:
0083 std::optional<edm4eic::MutableCluster> reconstruct(const edm4eic::ProtoCluster& pcl) const;
0084 };
0085
0086 }