EIC 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 <map>
14 #include <vector>
15 
16 #include <boost/bind.hpp>
17 #include <boost/graph/adjacency_list.hpp>
18 #include <boost/graph/connected_components.hpp>
19 
20 template <class Hit>
21 int PHMakeGroups(std::vector<Hit>& hits,
22  std::multimap<int, Hit>& groups)
23 {
24  typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;
25 
26  Graph G;
27 
28  // Process the hits in ix-then-iz order
29  std::sort(hits.begin(), hits.end());
30 
31  // TODO: Since the list is sorted by channel number, it should
32  // be possible to terminate the inner loop if we find the next hit
33  // is more than one Z channel away (in which case the subsequent ones
34  // will be adjacent neither in X nor Z).
35  for (unsigned int i = 0; i < hits.size(); i++)
36  {
37  for (unsigned int j = i + 1; j < hits.size(); j++)
38  {
39  if (hits[i].is_adjacent(hits[j])) add_edge(i, j, G);
40  }
41  add_edge(i, i, G);
42  }
43 
44  // Find the connections between the vertices of the graph (vertices are the rawhits,
45  // connections are made when they are adjacent to one another)
46  std::vector<int> component(num_vertices(G));
47  //connected_components(G, &component[0]);
48  connected_components(G, &component[0]);
49  //std::cout << "Found " << num << " groups of hits" << std::endl;
50 
51  // Loop over the components(vertices) compiling a list of the unique
52  // connections (ie clusters).
53  std::set<int> comps; // Number of unique components
54  for (unsigned int i = 0; i < component.size(); i++)
55  {
56  comps.insert(component[i]);
57  groups.insert(std::make_pair(component[i], hits[i]));
58  }
59 
60  // for(std::set<int>::const_iterator id=comps.begin(); id!=comps.end(); id++)
61  // {
62  // std::multimap<int,SvxRawhitAdapter>::const_iterator curr, last;
63  // boost::tie(curr,last) = groups[iread].equal_range(*id);
64  // std::cout << "Group " << *id << " has " << groups[iread].count(*id) << " Rawhits:" << std::endl;
65  // for ( ; curr!=last; curr++)
66  // {
67  // SvxRawhitAdapter h = curr->second;
68  // h.hit->print();
69  // }
70  // }
71 
72  return 0;
73 }
74 
75 #endif