DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Hit.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <vector>
6#include <cmath>
7#include <list>
8
9namespace triggeralgs {
10namespace dbscan {
11//======================================================================
12
13// Special "cluster numbers" for hits that are not (yet) in a cluster
14const int kNoise = -2;
15const int kUndefined = -1;
16
17//======================================================================
18
19// Hit classifications in the DBSCAN scheme
20enum class Connectedness
21{
22 // clang-format off
24 kNoise, // Fewer than minPts neighbours, not in a cluster
25 kCore, // minPts neighbours or more
26 kEdge // Fewer than minPts neighbours, part of a cluster
27 // clang-format on
28};
29
30//======================================================================
31
32// As new hits arrive, they push forward the "current" time, and
33// eventually a given hit or cluster will know that it cannot be
34// modified any further. A hit becomes kComplete when its time is so
35// far behind the current time that new hits cannot be neighbours of
36// it. A cluster becomes kComplete when its latest hit is complete
37enum class Completeness
38{
41};
42
43class Hit;
44
45//======================================================================
46
47// An array of unique hits, sorted by time. The actual container
48// implementation is a std::vector, which seems to be faster than a
49// std::set (needs rechecking)
50class HitSet
51{
52public:
53 HitSet();
54
55 // Insert a hit in the set, if not already present. Keeps the
56 // array sorted by time
57 void insert(Hit* h);
58
59 std::vector<Hit*>::iterator begin() { return hits.begin(); }
60 std::vector<Hit*>::iterator end() { return hits.end(); }
61
62 std::vector<Hit*>::const_iterator begin() const { return hits.cbegin(); }
63 std::vector<Hit*>::const_iterator end() const { return hits.cend(); }
64
65 void clear() { hits.clear(); }
66
67 size_t size() const { return hits.size(); }
68
69 std::vector<Hit*> hits;
70};
71
72//======================================================================
73struct Hit
74{
75 Hit(float _time, int _chan, const triggeralgs::TriggerPrimitive* _prim=nullptr);
76
77 void reset(float _time, int _chan, const triggeralgs::TriggerPrimitive* _prim=nullptr);
78 // Add hit `other` to this hit's list of neighbours if they are
79 // closer than `eps`. Return true if so
80 bool add_potential_neighbour(Hit* other, float eps, int minPts);
81
82 float time;
87};
88
89//======================================================================
90inline float
91manhattan_distance(const Hit& p, const Hit& q)
92{
93 return fabs((p.time - q.time)) + fabs(p.chan - q.chan);
94}
95
96//======================================================================
97template<class T>
98inline T
99sqr(T x)
100{
101 return x * x;
102}
103
104//======================================================================
105inline float
106euclidean_distance(const Hit& p, const Hit& q)
107{
108 return std::sqrt(sqr(p.time - q.time) + sqr(p.chan - q.chan));
109}
110
111//======================================================================
112inline float
113euclidean_distance_sqr(const Hit& p, const Hit& q)
114{
115 return sqr(p.time - q.time) + sqr(p.chan - q.chan);
116}
117
118//======================================================================
119inline bool
120time_comp_lower(const Hit* hit, const float t)
121{
122 return hit->time < t;
123}
124
125}
126}
127// Local Variables:
128// mode: c++
129// c-basic-offset: 4
130// c-file-style: "linux"
131// End:
std::vector< Hit * >::iterator begin()
Definition Hit.hpp:59
void insert(Hit *h)
Definition Hit.cpp:16
std::vector< Hit * >::const_iterator end() const
Definition Hit.hpp:63
std::vector< Hit * > hits
Definition Hit.hpp:69
std::vector< Hit * >::const_iterator begin() const
Definition Hit.hpp:62
std::vector< Hit * >::iterator end()
Definition Hit.hpp:60
size_t size() const
Definition Hit.hpp:67
const int kUndefined
Definition Hit.hpp:15
bool time_comp_lower(const Hit *hit, const float t)
Definition Hit.hpp:120
const int kNoise
Definition Hit.hpp:14
float euclidean_distance(const Hit &p, const Hit &q)
Definition Hit.hpp:106
float manhattan_distance(const Hit &p, const Hit &q)
Definition Hit.hpp:91
float euclidean_distance_sqr(const Hit &p, const Hit &q)
Definition Hit.hpp:113
A single energy deposition on a TPC or PDS channel.
bool add_potential_neighbour(Hit *other, float eps, int minPts)
Definition Hit.cpp:60
triggeralgs::TriggerPrimitive primitive
Definition Hit.hpp:86
Hit(float _time, int _chan, const triggeralgs::TriggerPrimitive *_prim=nullptr)
Definition Hit.cpp:36
void reset(float _time, int _chan, const triggeralgs::TriggerPrimitive *_prim=nullptr)
Definition Hit.cpp:44
Connectedness connectedness
Definition Hit.hpp:84