File indexing completed on 2025-01-30 10:04:49
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/EDM4eicVersion.h>
0016 #include <edm4hep/CaloHitContribution.h>
0017 #include <edm4hep/MCParticle.h>
0018 #if EDM4EIC_VERSION_MAJOR >= 7
0019 #include <edm4eic/MCRecoCalorimeterHitAssociationCollection.h>
0020 #else
0021 #include <edm4hep/SimCalorimeterHitCollection.h>
0022 #endif
0023 #include <edm4eic/MCRecoClusterParticleAssociationCollection.h>
0024 #include <edm4eic/ProtoClusterCollection.h>
0025 #include <algorithm>
0026 #include <cmath>
0027 #include <functional>
0028 #include <map>
0029 #include <memory>
0030 #include <optional>
0031 #include <string>
0032 #include <string_view>
0033 #include <utility>
0034
0035 #include "CalorimeterClusterRecoCoGConfig.h"
0036 #include "algorithms/interfaces/WithPodConfig.h"
0037
0038 static double constWeight(double , double , double , int ) { return 1.0; }
0039 static double linearWeight(double E, double , double , int ) { return E; }
0040 static double logWeight(double E, double tE, double base, int ) {
0041 return std::max(0., base + std::log(E / tE));
0042 }
0043
0044 static const std::map<std::string, std::function<double(double, double, double, int)>> weightMethods={
0045 {"none", constWeight},
0046 {"linear", linearWeight},
0047 {"log", logWeight},
0048 };
0049
0050 namespace eicrecon {
0051
0052 using ClustersWithAssociations = std::pair<
0053 std::unique_ptr<edm4eic::ClusterCollection>,
0054 std::unique_ptr<edm4eic::MCRecoClusterParticleAssociationCollection>
0055 >;
0056
0057 using CalorimeterClusterRecoCoGAlgorithm = algorithms::Algorithm<
0058 algorithms::Input<
0059 edm4eic::ProtoClusterCollection,
0060 #if EDM4EIC_VERSION_MAJOR >= 7
0061 std::optional<edm4eic::MCRecoCalorimeterHitAssociationCollection>
0062 #else
0063 std::optional<edm4hep::SimCalorimeterHitCollection>
0064 #endif
0065 >,
0066 algorithms::Output<
0067 edm4eic::ClusterCollection,
0068 std::optional<edm4eic::MCRecoClusterParticleAssociationCollection>
0069 >
0070 >;
0071
0072 class CalorimeterClusterRecoCoG
0073 : public CalorimeterClusterRecoCoGAlgorithm,
0074 public WithPodConfig<CalorimeterClusterRecoCoGConfig> {
0075
0076 public:
0077 CalorimeterClusterRecoCoG(std::string_view name)
0078 : CalorimeterClusterRecoCoGAlgorithm{name,
0079 #if EDM4EIC_VERSION_MAJOR >= 7
0080 {"inputProtoClusterCollection", "mcRawHitAssocations"},
0081 #else
0082 {"inputProtoClusterCollection", "mcHits"},
0083 #endif
0084 {"outputClusterCollection", "outputAssociations"},
0085 "Reconstruct a cluster with the Center of Gravity method. For "
0086 "simulation results it optionally creates a Cluster <-> MCParticle "
0087 "association provided both optional arguments are provided."} {}
0088
0089 public:
0090 void init() final;
0091
0092 void process(const Input&, const Output&) const final;
0093
0094 private:
0095 std::function<double(double, double, double, int)> weightFunc;
0096
0097 private:
0098 std::optional<edm4eic::MutableCluster> reconstruct(const edm4eic::ProtoCluster& pcl) const;
0099 #if EDM4EIC_VERSION_MAJOR >= 7
0100 void associate(const edm4eic::Cluster& cl, const edm4eic::MCRecoCalorimeterHitAssociationCollection* mchitassociations, edm4eic::MCRecoClusterParticleAssociationCollection* assocs) const;
0101 #else
0102 void associate(const edm4eic::Cluster& cl, const edm4hep::SimCalorimeterHitCollection* mchits, edm4eic::MCRecoClusterParticleAssociationCollection* assocs) const;
0103 #endif
0104 edm4hep::MCParticle get_primary(const edm4hep::CaloHitContribution& contrib) const;
0105
0106 };
0107
0108 }