EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHTpcLookup.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHTpcLookup.cc
1 
6 #include "PHTpcLookup.h"
7 #include "PHTpcTrackerUtil.h"
8 
9 #include <phool/PHLog.h>
10 
11 #include <log4cpp/CategoryStream.hh> // for CategoryStream
12 
13 #include <cmath> // for sqrt
14 #include <memory> // for allocator_traits<>::value_type
15 #include <utility> // for pair
16 
19 
21  : mClusterMap(nullptr)
22  , mHitsets(nullptr)
23  , mKDindex(nullptr)
24 {
25 }
26 
28 {
29  delete mKDindex;
30 }
31 
33 {
34  mClusterMap = cluster_map;
35  mHitsets = hitsets;
36  // convert cluster_map to kdhits
38 
39  // import kdhits into KDPointCloud
40  const size_t TOTALHITS = mKDhits.size();
41 
42  mCloud.pts.resize(TOTALHITS);
43  for (size_t i = 0, ilen = TOTALHITS; i < ilen; i++)
44  {
45  mCloud.pts[i] = mKDhits[i];
46  }
47 
48  // build mKDindex
49 
50  delete mKDindex;
51 
54 
56 }
57 
59 {
60  mCloud.pts.clear();
61  mKDhits.clear();
62 }
63 
64 std::vector<std::vector<double>*> PHTpcLookup::find(double x, double y, double z, double radius, size_t& nMatches)
65 {
66  std::vector<std::vector<double>*> matches;
67  if (!mKDindex)
68  {
69  LOG_ERROR("tracking.PHTpcLookup.find") << "using tpc lookup before init";
70  return matches;
71  }
72  radius *= radius; // KD-tree is using search radius^2
74  double query_pt[3] = {x, y, z};
75  std::vector<std::pair<size_t, double> > ret_matches;
76  nMatches = mKDindex->radiusSearch(&query_pt[0], radius, ret_matches, params);
77 
78  for (size_t i = 0; i < nMatches; i++)
79  {
80  std::vector<double>& hit = mKDhits[ret_matches[i].first];
81  matches.push_back(&hit);
82  double distance = std::sqrt(ret_matches[i].second);
83  LOG_DEBUG("tracking.PHTpcLookup.find") << "hit x: " << hit[0] << ", y: " << hit[1] << ", z: " << hit[2] << ", dist: " << distance;
84  }
85  return matches;
86 }