File indexing completed on 2025-09-18 09:11:01
0001
0002
0003
0004 #pragma once
0005
0006 #include <algorithms/algorithm.h>
0007 #include <algorithms/geo.h>
0008 #include <edm4eic/ProtoClusterCollection.h>
0009 #include <edm4eic/TrackPoint.h>
0010 #include <edm4eic/TrackSegmentCollection.h>
0011 #include <edm4hep/Vector3f.h>
0012 #include <podio/ObjectID.h>
0013 #include <map>
0014 #include <set>
0015 #include <string>
0016 #include <string_view>
0017 #include <vector>
0018
0019 #include "TrackClusterMergeSplitterConfig.h"
0020
0021 #include "algorithms/interfaces/WithPodConfig.h"
0022
0023 namespace eicrecon {
0024
0025
0026
0027
0028
0029
0030
0031 struct CompareProto {
0032
0033 bool operator()(const edm4eic::ProtoCluster& lhs, const edm4eic::ProtoCluster& rhs) const {
0034 if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) {
0035 return (lhs.getObjectID().index < rhs.getObjectID().index);
0036 } else {
0037 return (lhs.getObjectID().collectionID < rhs.getObjectID().collectionID);
0038 }
0039 }
0040
0041 };
0042
0043
0044
0045
0046 using VecProj = std::vector<edm4eic::TrackPoint>;
0047 using VecClust = std::vector<edm4eic::ProtoCluster>;
0048 using SetClust = std::set<edm4eic::ProtoCluster, CompareProto>;
0049 using MapToVecProj = std::map<edm4eic::ProtoCluster, VecProj, CompareProto>;
0050 using MapToVecClust = std::map<edm4eic::ProtoCluster, VecClust, CompareProto>;
0051
0052
0053
0054
0055 using TrackClusterMergeSplitterAlgorithm = algorithms::Algorithm<
0056 algorithms::Input<edm4eic::ProtoClusterCollection, edm4eic::TrackSegmentCollection>,
0057 algorithms::Output<edm4eic::ProtoClusterCollection>>;
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 class TrackClusterMergeSplitter : public TrackClusterMergeSplitterAlgorithm,
0069 public WithPodConfig<TrackClusterMergeSplitterConfig> {
0070
0071 public:
0072
0073 TrackClusterMergeSplitter(std::string_view name)
0074 : TrackClusterMergeSplitterAlgorithm{
0075 name,
0076 {"InputProtoClusterCollection", "InputTrackProjections"},
0077 {"OutputProtoClusterCollection"},
0078 "Merges or splits clusters based on tracks projected to them."} {}
0079
0080
0081 void init();
0082 void process(const Input&, const Output&) const final;
0083
0084 private:
0085 const algorithms::GeoSvc& m_geo = algorithms::GeoSvc::instance();
0086
0087
0088 void get_projections(const edm4eic::TrackSegmentCollection* projections,
0089 VecProj& relevant_projects) const;
0090 void match_clusters_to_tracks(const edm4eic::ProtoClusterCollection* clusters,
0091 const VecProj& projections, MapToVecProj& matches) const;
0092 void merge_and_split_clusters(const VecClust& to_merge, const VecProj& to_split,
0093 edm4eic::ProtoClusterCollection* out_protoclusters) const;
0094 float get_cluster_energy(const edm4eic::ProtoCluster& clust) const;
0095 edm4hep::Vector3f get_cluster_position(const edm4eic::ProtoCluster& clust) const;
0096
0097
0098 unsigned int m_idCalo{0};
0099
0100 };
0101
0102 }