Line data Source code
1 : /**
2 : * @file TAMakerDBSCANAlgorithm.cpp
3 : *
4 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "triggeralgs/dbscan/TAMakerDBSCANAlgorithm.hpp"
10 : #include "dbscan/Point.hpp"
11 :
12 : #include "TRACE/trace.h"
13 : #include "triggeralgs/Types.hpp"
14 : #include <chrono>
15 : #include <limits>
16 : #define TRACE_NAME "TAMakerDBSCANAlgorithm"
17 :
18 : #include <vector>
19 :
20 : using namespace triggeralgs;
21 :
22 : using Logging::TLVL_DEBUG_LOW;
23 :
24 : void
25 0 : TAMakerDBSCANAlgorithm::process(const TriggerPrimitive& input_tp, std::vector<TriggerActivity>& output_ta)
26 : {
27 0 : if(input_tp.time_start < m_prev_timestamp){
28 0 : TLOG_DEBUG(TLVL_DEBUG_LOW) << "[TAM:DBS] Out-of-order TPs: prev " << m_prev_timestamp << ", current " << input_tp.time_start;
29 0 : return;
30 : }
31 :
32 0 : m_dbscan_clusters.clear();
33 0 : m_dbscan->add_primitive(input_tp, &m_dbscan_clusters);
34 :
35 0 : uint64_t t0=m_dbscan->get_first_prim_time();
36 :
37 0 : for(auto const& cluster : m_dbscan_clusters){
38 0 : auto& ta=output_ta.emplace_back();
39 :
40 0 : ta.time_start = std::numeric_limits<timestamp_t>::max();
41 0 : ta.time_end = 0;
42 0 : ta.channel_start = std::numeric_limits<channel_t>::max();
43 0 : ta.channel_end = 0;
44 0 : ta.adc_integral = 0;
45 :
46 0 : for(auto const& hit : cluster.hits){
47 0 : auto const& prim=hit->primitive;
48 :
49 0 : ta.inputs.push_back(prim);
50 :
51 0 : ta.time_start = std::min(prim.time_start, ta.time_start);
52 0 : ta.time_end = std::max(prim.time_start + prim.samples_over_threshold * 32, ta.time_end); // FIXME: Replace the hard-coded SOT to TOT scaling.
53 :
54 0 : ta.channel_start = std::min(channel_t(prim.channel), ta.channel_start);
55 0 : ta.channel_end = std::max(channel_t(prim.channel), ta.channel_end);
56 :
57 0 : ta.adc_integral += prim.adc_integral;
58 :
59 0 : ta.detid = prim.detid;
60 0 : if (prim.adc_peak > ta.adc_peak) {
61 0 : ta.adc_peak = prim.adc_peak;
62 0 : ta.channel_peak = prim.channel;
63 0 : ta.time_peak = prim.samples_to_peak * 32 + prim.time_start; // FIXME: Replace hard-coded STP to `time_peak` conversion.
64 : }
65 : }
66 0 : ta.time_activity = ta.time_peak;
67 :
68 0 : ta.type = TriggerActivity::Type::kTPC;
69 0 : ta.algorithm = TriggerActivity::Algorithm::kDBSCAN;
70 : }
71 :
72 0 : m_dbscan->trim_hits();
73 : }
74 :
75 : void
76 0 : TAMakerDBSCANAlgorithm::configure(const nlohmann::json& config)
77 : {
78 0 : TriggerActivityMaker::configure(config);
79 :
80 0 : if (config.is_object())
81 : {
82 0 : if (config.contains("min_pts"))
83 0 : m_min_pts = config["min_pts"];
84 0 : if (config.contains("eps"))
85 0 : m_eps = config["eps"];
86 : }
87 0 : m_dbscan=std::make_unique<dbscan::IncrementalDBSCAN>(m_eps, m_min_pts, 10000);
88 0 : }
89 :
90 : // Register algo in TA Factory
91 12 : REGISTER_TRIGGER_ACTIVITY_MAKER(TRACE_NAME, TAMakerDBSCANAlgorithm)
|