Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 08:25:42

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Sylvester Joosten, Chao, Chao Peng, Whitney Armstrong
0003 
0004 /*
0005  *  Reconstruct the cluster with Center of Gravity method
0006  *  Logarithmic weighting is used for mimicking energy deposit in transverse direction
0007  *
0008  *  Author: Chao Peng (ANL), 09/27/2020
0009  */
0010 
0011 #pragma once
0012 
0013 #include <algorithms/algorithm.h>
0014 #include <edm4eic/ClusterCollection.h>
0015 #include <edm4eic/MCRecoCalorimeterHitAssociationCollection.h>
0016 #include <edm4eic/MCRecoCalorimeterHitLinkCollection.h>
0017 #include <edm4eic/MCRecoClusterParticleAssociationCollection.h>
0018 #include <edm4eic/MCRecoClusterParticleLinkCollection.h>
0019 #include <edm4eic/ProtoClusterCollection.h>
0020 #include <algorithm>
0021 #include <cmath>
0022 #include <functional>
0023 #include <map>
0024 #include <memory>
0025 #include <optional>
0026 #include <string>
0027 #include <string_view>
0028 #include <utility>
0029 
0030 #include "CalorimeterClusterRecoCoGConfig.h"
0031 #include "algorithms/interfaces/LinkTruthUtils.h"
0032 #include "algorithms/interfaces/WithPodConfig.h"
0033 
0034 static double constWeight(double /*E*/, double /*tE*/, double /*p*/, int /*type*/) { return 1.0; }
0035 static double linearWeight(double E, double /*tE*/, double /*p*/, int /*type*/) { return E; }
0036 static double logWeight(double E, double tE, double base, int /*type*/) {
0037   return std::max(0., base + std::log(E / tE));
0038 }
0039 
0040 static const std::map<std::string, std::function<double(double, double, double, int)>>
0041     weightMethods = {
0042         {"none", constWeight},
0043         {"linear", linearWeight},
0044         {"log", logWeight},
0045 };
0046 
0047 namespace eicrecon {
0048 
0049 using ClustersWithAssociations =
0050     std::pair<std::unique_ptr<edm4eic::ClusterCollection>,
0051               std::unique_ptr<edm4eic::MCRecoClusterParticleAssociationCollection>>;
0052 
0053 using CalorimeterClusterRecoCoGAlgorithm = algorithms::Algorithm<
0054     algorithms::Input<edm4eic::ProtoClusterCollection,
0055                       std::optional<edm4eic::MCRecoCalorimeterHitLinkCollection>,
0056                       std::optional<edm4eic::MCRecoCalorimeterHitAssociationCollection>>,
0057     algorithms::Output<edm4eic::ClusterCollection,
0058                        std::optional<edm4eic::MCRecoClusterParticleLinkCollection>,
0059                        std::optional<edm4eic::MCRecoClusterParticleAssociationCollection>>>;
0060 
0061 class CalorimeterClusterRecoCoG : public CalorimeterClusterRecoCoGAlgorithm,
0062                                   public WithPodConfig<CalorimeterClusterRecoCoGConfig> {
0063 
0064 public:
0065   CalorimeterClusterRecoCoG(std::string_view name)
0066       : CalorimeterClusterRecoCoGAlgorithm{
0067             name,
0068             {"inputProtoClusterCollection", "mcRawHitLinks", "mcRawHitAssocations"},
0069             {"outputClusterCollection", "outputLinks", "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   void
0085   associate(const edm4eic::Cluster& cl,
0086             const edm4eic::MCRecoCalorimeterHitAssociationCollection* mchitassociations,
0087             const truth::EventLinkNavigator<edm4eic::MCRecoCalorimeterHitLinkCollection>& link_nav,
0088             edm4eic::MCRecoClusterParticleLinkCollection* links,
0089             edm4eic::MCRecoClusterParticleAssociationCollection* assocs) const;
0090 };
0091 
0092 } // namespace eicrecon