Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHMakeGroups.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHMakeGroups.h
1 #ifndef CALORECO_PHMAKEGROUPS_H
2 #define CALORECO_PHMAKEGROUPS_H
3 // Requirements:
4 //
5 // the class type Hit needs to provide:
6 //
7 // an operator< that sorts by ix and then by iz
8 // a function is_adjacent() which returns true if the argumment hit is adjacent
9 // a function ...() that returns true if the argument Hit is far enough away
10 // from this one to allow breaking out of the inner loop early
11 //
12 
13 #include <boost/bind/bind.hpp>
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wshadow"
16 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
17 #include <boost/graph/adjacency_list.hpp>
18 #include <boost/graph/connected_components.hpp>
19 #pragma GCC diagnostic pop
20 
21 #include <map>
22 #include <vector>
23 
24 template <class Hit>
25 int PHMakeGroups(std::vector<Hit>& hits,
26  std::multimap<int, Hit>& groups)
27 {
28  typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;
29 
30  Graph G;
31 
32  // Process the hits in ix-then-iz order
33  std::sort(hits.begin(), hits.end());
34 
35  // TODO: Since the list is sorted by channel number, it should
36  // be possible to terminate the inner loop if we find the next hit
37  // is more than one Z channel away (in which case the subsequent ones
38  // will be adjacent neither in X nor Z).
39  for (unsigned int i = 0; i < hits.size(); i++)
40  {
41  for (unsigned int j = i + 1; j < hits.size(); j++)
42  {
43  if (hits[i].is_adjacent(hits[j])) add_edge(i, j, G);
44  }
45  add_edge(i, i, G);
46  }
47 
48  // Find the connections between the vertices of the graph (vertices are the rawhits,
49  // connections are made when they are adjacent to one another)
50  std::vector<int> component(num_vertices(G));
51  // connected_components(G, &component[0]);
52  connected_components(G, &component[0]);
53  // std::cout << "Found " << num << " groups of hits" << std::endl;
54 
55  // Loop over the components(vertices) compiling a list of the unique
56  // connections (ie clusters).
57  std::set<int> comps; // Number of unique components
58  for (unsigned int i = 0; i < component.size(); i++)
59  {
60  comps.insert(component[i]);
61  groups.insert(std::make_pair(component[i], hits[i]));
62  }
63 
64  // for(std::set<int>::const_iterator id=comps.begin(); id!=comps.end(); id++)
65  // {
66  // std::multimap<int,SvxRawhitAdapter>::const_iterator curr, last;
67  // boost::tie(curr,last) = groups[iread].equal_range(*id);
68  // std::cout << "Group " << *id << " has " << groups[iread].count(*id) << " Rawhits:" << std::endl;
69  // for ( ; curr!=last; curr++)
70  // {
71  // SvxRawhitAdapter h = curr->second;
72  // h.hit->print();
73  // }
74  // }
75 
76  return 0;
77 }
78 
79 #endif