File indexing completed on 2024-04-06 12:24:43
0001 #ifndef RecoEcal_EgammaCoreTools_GraphMap_h
0002 #define RecoEcal_EgammaCoreTools_GraphMap_h
0003
0004 #include <vector>
0005 #include <array>
0006 #include <map>
0007 #include <algorithm>
0008
0009
0010
0011
0012
0013
0014
0015
0016 namespace reco {
0017
0018 class GraphMap {
0019 public:
0020 GraphMap(uint nNodes);
0021
0022 enum NodeCategory { kNode, kSeed, kNcategories };
0023
0024 void addNode(const uint index, const NodeCategory category);
0025 void addNodes(const std::vector<uint> &indices, const std::vector<NodeCategory> &categories);
0026 void addEdge(const uint i, const uint j);
0027 void setAdjMatrix(const uint i, const uint j, const float score);
0028 void setAdjMatrixSym(const uint i, const uint j, const float score);
0029 void printGraphMap();
0030
0031
0032 const std::vector<uint> &getOutEdges(const uint i) const;
0033 const std::vector<uint> &getInEdges(const uint i) const;
0034 uint getAdjMatrix(const uint i, const uint j) const;
0035 std::vector<float> getAdjMatrixRow(const uint i) const;
0036 std::vector<float> getAdjMatrixCol(const uint j) const;
0037
0038 enum CollectionStrategy {
0039 Cascade,
0040
0041 CollectAndMerge,
0042
0043
0044
0045
0046 SeedsFirst,
0047
0048
0049 CascadeHighest
0050
0051
0052
0053 };
0054
0055
0056 typedef std::vector<std::pair<uint, std::vector<uint>>> GraphOutput;
0057 typedef std::map<uint, std::vector<uint>> GraphOutputMap;
0058
0059 void collectNodes(GraphMap::CollectionStrategy strategy, float threshold);
0060 const GraphOutput &getGraphOutput() { return graphOutput_; };
0061
0062 private:
0063 uint nNodes_;
0064
0065 std::map<NodeCategory, std::vector<uint>> nodesCategories_;
0066
0067 std::map<uint, uint> nodesCount_;
0068
0069 std::vector<std::vector<uint>> edgesIn_;
0070
0071 std::vector<std::vector<uint>> edgesOut_;
0072
0073
0074
0075 std::map<std::pair<uint, uint>, float> adjMatrix_;
0076
0077
0078 GraphOutput graphOutput_;
0079
0080
0081 void collectCascading(float threshold);
0082 void assignHighestScoreEdge();
0083
0084
0085 std::pair<GraphOutput, GraphOutputMap> collectSeparately(float threshold);
0086 void mergeSubGraphs(float threshold, GraphOutput seedsGraph, GraphOutputMap nodesGraphMap);
0087 void resolveSuperNodesEdges(float threshold);
0088 };
0089
0090 }
0091
0092 #endif