CMS 3D CMS Logo

TICLGraph.h
Go to the documentation of this file.
1 #ifndef DataFormats_HGCalReco_TICLGraph_h
2 #define DataFormats_HGCalReco_TICLGraph_h
3 
6 #include <unordered_set>
7 
8 namespace ticl {
9 
10  class Node {
11  public:
12  Node() = default;
13  Node(unsigned index, bool isTrackster = true) : index_(index), isTrackster_(isTrackster), alreadyVisited_{false} {};
14 
15  inline void addOuterNeighbour(unsigned int trackster_id) { outerNeighboursId_.push_back(trackster_id); }
16  inline void addInnerNeighbour(unsigned int trackster_id) { innerNeighboursId_.push_back(trackster_id); }
17 
18  inline const unsigned int getId() const { return index_; }
19  const std::vector<unsigned int>& getOuterNeighbours() const { return outerNeighboursId_; }
20  const std::vector<unsigned int>& getInnerNeighbours() const { return innerNeighboursId_; }
21  void findSubComponents(std::vector<Node>& graph, std::vector<unsigned int>& subComponent, std::string tabs);
22 
23  inline bool isInnerNeighbour(const unsigned int tid) {
24  auto findInner = std::find(innerNeighboursId_.begin(), innerNeighboursId_.end(), tid);
25  return findInner != innerNeighboursId_.end();
26  }
27 
28  ~Node() = default;
29 
30  private:
31  unsigned index_;
33 
34  std::vector<unsigned int> outerNeighboursId_;
35  std::vector<unsigned int> innerNeighboursId_;
37 
38  //bool areCompatible(const std::vector<Node>& graph, const unsigned int& outerNode) { return true; };
39  };
40 } // namespace ticl
41 
42 class TICLGraph {
43 public:
44  // can i remove default constructor ?? edm::Wrapper problem
45  // without default constructor i could initialize connectedComponents when building the Graph
46  TICLGraph() = default;
47  TICLGraph(std::vector<ticl::Node>& n, std::vector<int> isRootNode) {
48  nodes_ = n;
49  isRootNode_ = isRootNode;
50  };
51  inline const std::vector<ticl::Node>& getNodes() const { return nodes_; }
52  inline const ticl::Node& getNode(int i) const { return nodes_[i]; }
53 
54  std::vector<std::vector<unsigned int>> findSubComponents();
55 
56  ~TICLGraph() = default;
57 
58  void dfsForCC(unsigned int nodeIndex,
59  std::unordered_set<unsigned int>& visited,
60  std::vector<unsigned int>& component) const;
61 
62  std::vector<std::vector<unsigned int>> getConnectedComponents() const;
63 
64 private:
65  std::vector<ticl::Node> nodes_;
66  std::vector<int> isRootNode_;
67 };
68 
69 #endif
~Node()=default
const ticl::Node & getNode(int i) const
Definition: TICLGraph.h:52
Node(unsigned index, bool isTrackster=true)
Definition: TICLGraph.h:13
const std::vector< unsigned int > & getInnerNeighbours() const
Definition: TICLGraph.h:20
unsigned index_
Definition: TICLGraph.h:31
std::vector< std::vector< unsigned int > > getConnectedComponents() const
Definition: TICLGraph.cc:48
std::vector< int > isRootNode_
Definition: TICLGraph.h:66
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< ticl::Node > nodes_
Definition: TICLGraph.h:65
const std::vector< ticl::Node > & getNodes() const
Definition: TICLGraph.h:51
bool isTrackster_
Definition: TICLGraph.h:32
const unsigned int getId() const
Definition: TICLGraph.h:18
TICLGraph()=default
void addInnerNeighbour(unsigned int trackster_id)
Definition: TICLGraph.h:16
const std::vector< unsigned int > & getOuterNeighbours() const
Definition: TICLGraph.h:19
void dfsForCC(unsigned int nodeIndex, std::unordered_set< unsigned int > &visited, std::vector< unsigned int > &component) const
Definition: TICLGraph.cc:35
std::vector< unsigned int > outerNeighboursId_
Definition: TICLGraph.h:34
std::vector< std::vector< unsigned int > > findSubComponents()
Definition: TICLGraph.cc:20
std::vector< unsigned int > innerNeighboursId_
Definition: TICLGraph.h:35
Definition: Common.h:10
void findSubComponents(std::vector< Node > &graph, std::vector< unsigned int > &subComponent, std::string tabs)
Definition: TICLGraph.cc:6
void addOuterNeighbour(unsigned int trackster_id)
Definition: TICLGraph.h:15
Node()=default
bool alreadyVisited_
Definition: TICLGraph.h:36
~TICLGraph()=default
bool isInnerNeighbour(const unsigned int tid)
Definition: TICLGraph.h:23
TICLGraph(std::vector< ticl::Node > &n, std::vector< int > isRootNode)
Definition: TICLGraph.h:47