DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
triggeralgs
include
triggeralgs
dbscan
dbscan.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <vector>
4
#include <map>
5
#include <iostream>
6
#include <algorithm>
// For std::lower_bound
7
#include <set>
8
#include <list>
9
10
#include "
triggeralgs/dbscan/Hit.hpp
"
11
#include "
triggeralgs/TriggerPrimitive.hpp
"
12
13
namespace
triggeralgs
{
14
namespace
dbscan
{
15
//======================================================================
16
// Find the eps-neighbours of hit q, assuming that the hits vector is sorted by
17
// time
18
int
19
neighbours_sorted
(
const
std::vector<Hit*>& hits,
Hit
& q,
float
eps,
int
minPts);
20
21
//======================================================================
22
struct
Cluster
23
{
24
Cluster
(
int
index_)
25
:
index
{ index_ }
26
{}
27
// The index of this cluster
28
int
index
{ -1 };
29
// A cluster is kComplete if its hits are all kComplete, so no
30
// newly-arriving hit could be a neighbour of any hit in the
31
// cluster
32
Completeness
completeness
{
Completeness::kIncomplete
};
33
// The latest time of any hit in the cluster
34
float
latest_time
{ 0 };
35
// The latest (largest time) "core" point in the cluster
36
Hit
*
latest_core_point
{
nullptr
};
37
// The hits in this cluster
38
HitSet
hits
;
39
40
// Add hit if it's a neighbour of a hit already in the
41
// cluster. Precondition: time of new_hit is >= the time of any
42
// hit in the cluster. Returns true if the hit was added
43
bool
maybe_add_new_hit
(
Hit
* new_hit,
float
eps,
int
minPts);
44
45
// Add the hit `h` to this cluster
46
void
add_hit
(
Hit
* h);
47
48
// Steal all of the hits from cluster `other` and merge them into
49
// this cluster
50
void
steal_hits
(
Cluster
& other);
51
};
52
53
//======================================================================
54
//
55
// Modified DBSCAN algorithm that takes one hit at a time, with the requirement
56
// that the hits are passed in time order
57
class
IncrementalDBSCAN
58
{
59
public
:
60
IncrementalDBSCAN
(
float
eps,
unsigned
int
minPts,
size_t
pool_size=100000)
61
:
m_eps
(eps)
62
,
m_minPts
(minPts)
63
,
m_pool_begin
(0)
64
,
m_pool_end
(0)
65
{
66
for
(
size_t
i=0; i<pool_size; ++i){
67
m_hit_pool
.emplace_back(0,0);
68
}
69
}
70
71
void
add_primitive
(
const
triggeralgs::TriggerPrimitive
& prim, std::vector<Cluster>* completed_clusters=
nullptr
);
72
73
void
add_point
(
float
time,
float
channel, std::vector<Cluster>* completed_clusters=
nullptr
);
74
75
// Add a new hit. The hit time *must* be >= the time of all hits
76
// previously added
77
void
add_hit
(
Hit
* new_hit, std::vector<Cluster>* completed_clusters=
nullptr
);
78
79
void
trim_hits
();
80
81
std::vector<Hit*>
get_hits
()
const
{
return
m_hits
; }
82
83
std::map<int, Cluster>
get_clusters
()
const
{
return
m_clusters
; }
84
85
uint64_t
get_first_prim_time
()
const
{
return
m_first_prim_time
; }
86
87
private
:
88
//======================================================================
89
//
90
// Starting from `seed_hit`, find all the reachable hits and add them
91
// to `cluster`
92
void
cluster_reachable
(
Hit
* seed_hit,
Cluster
& cluster);
93
94
float
m_eps
;
95
float
m_minPts
;
96
std::vector<Hit>
m_hit_pool
;
97
size_t
m_pool_begin
,
m_pool_end
;
98
std::vector<Hit*>
m_hits
;
// All the hits we've seen so far, in time order
99
float
m_latest_time
{ 0 };
// The latest time of a hit in the vector of hits
100
uint64_t
m_first_prim_time
{0};
101
std::map<int, Cluster>
102
m_clusters
;
// All of the currently-active (ie, kIncomplete) clusters
103
};
104
105
}
106
}
107
108
// Local Variables:
109
// mode: c++
110
// c-basic-offset: 4
111
// c-file-style: "linux"
112
// End:
Hit.hpp
triggeralgs::dbscan::HitSet
Definition
Hit.hpp:51
triggeralgs::dbscan::IncrementalDBSCAN::get_first_prim_time
uint64_t get_first_prim_time() const
Definition
dbscan.hpp:85
triggeralgs::dbscan::IncrementalDBSCAN::trim_hits
void trim_hits()
Definition
dbscan.cpp:295
triggeralgs::dbscan::IncrementalDBSCAN::m_minPts
float m_minPts
Definition
dbscan.hpp:95
triggeralgs::dbscan::IncrementalDBSCAN::m_hits
std::vector< Hit * > m_hits
Definition
dbscan.hpp:98
triggeralgs::dbscan::IncrementalDBSCAN::add_primitive
void add_primitive(const triggeralgs::TriggerPrimitive &prim, std::vector< Cluster > *completed_clusters=nullptr)
Definition
dbscan.cpp:137
triggeralgs::dbscan::IncrementalDBSCAN::get_hits
std::vector< Hit * > get_hits() const
Definition
dbscan.hpp:81
triggeralgs::dbscan::IncrementalDBSCAN::get_clusters
std::map< int, Cluster > get_clusters() const
Definition
dbscan.hpp:83
triggeralgs::dbscan::IncrementalDBSCAN::m_hit_pool
std::vector< Hit > m_hit_pool
Definition
dbscan.hpp:96
triggeralgs::dbscan::IncrementalDBSCAN::m_first_prim_time
uint64_t m_first_prim_time
Definition
dbscan.hpp:100
triggeralgs::dbscan::IncrementalDBSCAN::m_pool_end
size_t m_pool_end
Definition
dbscan.hpp:97
triggeralgs::dbscan::IncrementalDBSCAN::IncrementalDBSCAN
IncrementalDBSCAN(float eps, unsigned int minPts, size_t pool_size=100000)
Definition
dbscan.hpp:60
triggeralgs::dbscan::IncrementalDBSCAN::m_pool_begin
size_t m_pool_begin
Definition
dbscan.hpp:97
triggeralgs::dbscan::IncrementalDBSCAN::add_point
void add_point(float time, float channel, std::vector< Cluster > *completed_clusters=nullptr)
Definition
dbscan.cpp:126
triggeralgs::dbscan::IncrementalDBSCAN::cluster_reachable
void cluster_reachable(Hit *seed_hit, Cluster &cluster)
Definition
dbscan.cpp:95
triggeralgs::dbscan::IncrementalDBSCAN::add_hit
void add_hit(Hit *new_hit, std::vector< Cluster > *completed_clusters=nullptr)
Definition
dbscan.cpp:153
triggeralgs::dbscan::IncrementalDBSCAN::m_latest_time
float m_latest_time
Definition
dbscan.hpp:99
triggeralgs::dbscan::IncrementalDBSCAN::m_clusters
std::map< int, Cluster > m_clusters
Definition
dbscan.hpp:102
triggeralgs::dbscan::IncrementalDBSCAN::m_eps
float m_eps
Definition
dbscan.hpp:94
dbscan
Definition
Point.hpp:3
triggeralgs::dbscan::Completeness
Completeness
Definition
Hit.hpp:38
triggeralgs::dbscan::Completeness::kIncomplete
@ kIncomplete
Definition
Hit.hpp:39
triggeralgs::dbscan::neighbours_sorted
int neighbours_sorted(const std::vector< Hit * > &hits, Hit &q, float eps, int minPts)
Definition
dbscan.cpp:12
triggeralgs
Definition
AbstractFactory.hpp:18
triggeralgs::TriggerPrimitive
dunedaq::trgdataformats::TriggerPrimitive TriggerPrimitive
Definition
TriggerPrimitive.hpp:22
triggeralgs::dbscan::Cluster
Definition
dbscan.hpp:23
triggeralgs::dbscan::Cluster::completeness
Completeness completeness
Definition
dbscan.hpp:32
triggeralgs::dbscan::Cluster::add_hit
void add_hit(Hit *h)
Definition
dbscan.cpp:63
triggeralgs::dbscan::Cluster::hits
HitSet hits
Definition
dbscan.hpp:38
triggeralgs::dbscan::Cluster::latest_core_point
Hit * latest_core_point
Definition
dbscan.hpp:36
triggeralgs::dbscan::Cluster::maybe_add_new_hit
bool maybe_add_new_hit(Hit *new_hit, float eps, int minPts)
Definition
dbscan.cpp:31
triggeralgs::dbscan::Cluster::latest_time
float latest_time
Definition
dbscan.hpp:34
triggeralgs::dbscan::Cluster::Cluster
Cluster(int index_)
Definition
dbscan.hpp:24
triggeralgs::dbscan::Cluster::steal_hits
void steal_hits(Cluster &other)
Definition
dbscan.cpp:76
triggeralgs::dbscan::Cluster::index
int index
Definition
dbscan.hpp:28
triggeralgs::dbscan::Hit
Definition
Hit.hpp:74
TriggerPrimitive.hpp
Generated on
for DUNE-DAQ by
1.17.0