IniSegAlg.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Classes: IniSegAlg, Hit2D, bDistCentLess2D
3 // File: IniSegAlg.cxx
4 //
5 // dorota.stefan@cern.ch, robert.sulej@cern.ch, tjyang@fnal.gov
6 //
7 ////////////////////////////////////////////////////////////////////////
8 
9 #include "IniSegAlg.h"
10 
11 // framework libraries
12 #include "fhiclcpp/ParameterSet.h"
14 
15 // ROOT libraries
16 #include "TMath.h"
17 
18 // C/C++ libraries
19 #include <memory>
20 
21 dunefd::Hit2D::Hit2D(TVector2 point2d, size_t key) :
22 fPoint(point2d),
23 fKey(key)
24 {
25 }
26 
27 dunefd::IniSegAlg::IniSegAlg(std::map<size_t, std::vector<dunefd::Hit2D> > clusters) :
28 fClusters(clusters),
29 fRadius(10.0),
30 fDistVtxCl(0.0F),
31 fThrcos(0.9),
32 fCos(0.0F)
33 {
34 }
35 
37 fRadius(10.0),
38 fDistVtxCl(0.0F),
39 fThrcos(0.9),
40 fCos(-9999.0F)
41 {
42  fSelTrks = tracks;
43  fMcVtx3d = mcvtx;
44  fFound = false;
45 }
46 
47 void dunefd::IniSegAlg::FeedwithMc(TVector2 const & vtx, TVector2 const & dir, TVector3 const & dir3d)
48 {
49  fMcVtx = vtx;
50  fDir = dir;
51  fDir3d = dir3d;
53  SortLess();
54  FindCluster();
55 }
56 
57 void dunefd::IniSegAlg::FeedwithMc(TVector3 const & dir3d)
58 {
59  fDir3d = dir3d;
60  Find3dTrack();
61 }
62 
64 {
65  for (auto& cl: fClusters)
66  for (size_t h = 0; h < cl.second.size(); ++h)
67  if (pma::Dist2(fMcVtx, cl.second[h].GetPointCm()) < fRadius*fRadius)
68  {
69  fSelCls[cl.first] = cl.second;
70  break;
71  }
72 }
73 
75 {
76  for (auto& cl: fSelCls)
77  std::sort(cl.second.begin(), cl.second.end(), bDistCentLess2D(fMcVtx));
78 }
79 
80 TVector2 dunefd::IniSegAlg::ClusterDir(std::vector< Hit2D > const & hits)
81 {
82  TVector2 p1 = hits[0].GetPointCm();
83  size_t id = 0;
84  for (size_t i = 0; i < hits.size(); ++i)
85  if (pma::Dist2(hits[0].GetPointCm(), hits[i].GetPointCm()) < 1.0)
86  {
87  id = i;
88  }
89  else break;
90 
91  TVector2 p2 = hits[id].GetPointCm();
92  TVector2 dir = (p2 - p1) * (1 / (p2 - p1).Mod());
93 
94  return dir;
95 }
96 
98 {
99  double maxcos = 0;
100  std::map<size_t, std::vector<dunefd::Hit2D> > chosen;
101  for (auto& cl: fSelCls)
102  if (cl.second.size() > 2)
103  {
104  TVector2 dir = ClusterDir(cl.second);
105  double cos = fDir * dir;
106  if (cos > maxcos)
107  {
108  maxcos = cos;
109  chosen[cl.first] = cl.second;
110  fCl.clear();
111  fCl = cl.second;
112  fDistVtxCl = std::sqrt(pma::Dist2(fCl[0].GetPointCm(), fMcVtx));
113  }
114  }
115 
116  fSelCls.clear();
117  fSelCls = chosen;
118 }
119 
121 {
122  TVector3 larStart;
123  TVector3 larEnd;
124 
125  double maxcos = 0.0;
126  const double thrdist = 10; // cm
127 
128  for (auto& trk: fSelTrks)
129  {
130  std::tie(larStart,larEnd) = trk->Direction<TVector3>(); // correct, check both directions
131  TVector3 dir(larStart[0], larStart[1], larStart[2]);
132 
133  if (!trk->NumberTrajectoryPoints()) continue;
134  TVector3 pos_p = trk->LocationAtPoint<TVector3>(0);
135  TVector3 pos_end = trk->LocationAtPoint<TVector3>(trk->NumberTrajectoryPoints()-1);
136 
137  double dist = std::sqrt(pma::Dist2(pos_p, fMcVtx3d));
138 
139  if (dist > std::sqrt(pma::Dist2(pos_end, fMcVtx3d))) continue;
140 
141  double cos = fDir3d * dir;
142 
143  if ((cos > maxcos) && (dist < thrdist))
144  {
145  maxcos = cos;
146  fTrk = trk;
147  fCos = cos;
148  fFound = true;
149  }
150  }
151 }
152 
153 
std::vector< dunefd::Hit2D > fCl
Definition: IniSegAlg.h:82
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:37
Hit2D(TVector2 point2d, size_t key)
Definition: IniSegAlg.cxx:21
TVector2 fMcVtx
Definition: IniSegAlg.h:83
std::vector< art::Ptr< recob::Track > > fSelTrks
Definition: IniSegAlg.h:73
struct vector vector
IniSegAlg(std::map< size_t, std::vector< dunefd::Hit2D > > clusters)
Definition: IniSegAlg.cxx:27
string dir
std::map< size_t, std::vector< dunefd::Hit2D > > fClusters
Definition: IniSegAlg.h:69
QAsciiDict< Entry > cl
TVector3 fMcVtx3d
Definition: IniSegAlg.h:84
def key(type, name=None)
Definition: graph.py:13
void FeedwithMc(TVector2 const &vtx, TVector2 const &dir, TVector3 const &dir3d)
Definition: IniSegAlg.cxx:47
uint size() const
Definition: qasciidict.h:56
float const fThrcos
Definition: IniSegAlg.h:89
art::Ptr< recob::Track > fTrk
Definition: IniSegAlg.h:74
Definition: tracks.py:1
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
TVector2 fDir
Definition: IniSegAlg.h:85
void FindClustersInRad()
Definition: IniSegAlg.cxx:63
TVector2 ClusterDir(std::vector< Hit2D > const &hits)
Definition: IniSegAlg.cxx:80
std::map< size_t, std::vector< dunefd::Hit2D > > fSelCls
Definition: IniSegAlg.h:70
TVector3 fDir3d
Definition: IniSegAlg.h:76