Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-29 07:05:54

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/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 /*E*/, double /*tE*/, double /*p*/, int /*type*/) { return 1.0; }
0032 static double linearWeight(double E, double /*tE*/, double /*p*/, int /*type*/) { return E; }
0033 static double logWeight(double E, double tE, double base, int /*type*/) {
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 } // eicrecon