Skip to content

Commit

Permalink
Merge pull request #78 from DUNE-DAQ/asztuc/txmakers_v5_port
Browse files Browse the repository at this point in the history
Porting triggeralgs from v4 to v5
  • Loading branch information
ArturSztuc authored Aug 30, 2024
2 parents e2e67ce + 22333e3 commit 4fddb07
Show file tree
Hide file tree
Showing 49 changed files with 1,451 additions and 367 deletions.
23 changes: 15 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@ add_library(triggeralgs SHARED
src/TCMakerADCSimpleWindowAlgorithm.cpp
src/TAMakerHorizontalMuonAlgorithm.cpp
src/TCMakerHorizontalMuonAlgorithm.cpp
src/TriggerCandidateMakerPlaneCoincidence.cpp
src/TriggerActivityMakerPlaneCoincidence.cpp
src/TriggerActivityMakerMichelElectron.cpp
src/TriggerCandidateMakerMichelElectron.cpp
src/TCMakerPlaneCoincidenceAlgorithm.cpp
src/TAMakerPlaneCoincidenceAlgorithm.cpp
src/TAMakerMichelElectronAlgorithm.cpp
src/TCMakerMichelElectronAlgorithm.cpp
src/TAMakerPrescaleAlgorithm.cpp
src/TCMakerPrescaleAlgorithm.cpp
src/TriggerActivityMakerSupernova.cpp
src/TriggerCandidateMakerSupernova.cpp
src/TriggerDecisionMakerSupernova.cpp
src/TriggerActivityMakerDBSCAN.cpp
src/TAMakerSupernovaAlgorithm.cpp
src/TCMakerSupernovaAlgorithm.cpp
src/TDMakerSupernovaAlgorithm.cpp
src/TAMakerDBSCANAlgorithm.cpp
src/TCMakerDBSCANAlgorithm.cpp
src/TAMakerChannelDistanceAlgorithm.cpp
src/TCMakerChannelDistanceAlgorithm.cpp
src/TAMakerBundleNAlgorithm.cpp
src/TCMakerBundleNAlgorithm.cpp
src/TAMakerChannelAdjacencyAlgorithm.cpp
src/TCMakerChannelAdjacencyAlgorithm.cpp
src/TAWindow.cpp
src/TPWindow.cpp
src/dbscan/dbscan.cpp
Expand Down
4 changes: 2 additions & 2 deletions include/triggeralgs/ADCSimpleWindow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
- A “next-to-most-simple” triggering algorithm to exercise the TP chain.
- Look at the total ADC of incoming TPs in a given time window (`window_length`), trigger if that total goes above some user defined threshold (`adc_threshold`). Both `window_length` and `adc_threshold` are configurable members of the `TAMakerADCSimpleWindow` class. Defaults obtained based on the data in `tps_link_11.txt`.
- All of the logic is implemented in the `TAMakerADCSimpleWindow` class. A nested class called `Window` monitors incoming TPs (which are time ordered).
- When a particular window exceeds threshold, `TAMakerADCSimpleWindow::construct_ta()` constructs a `TriggerActivity`. This is enough (eventually) to request data to be read out. The `TriggerCandidateMakerADCSimpleWindow` class simply constructs trigger candidates one-for-one from the trigger activities.
- When a particular window exceeds threshold, `TAMakerADCSimpleWindow::construct_ta()` constructs a `TriggerActivity`. This is enough (eventually) to request data to be read out. The `TCMakerADCSimpleWindowAlgorithm` class simply constructs trigger candidates one-for-one from the trigger activities.
- Note that an activity will only be constructed once the window is full length even if the total ADC goes above the threshold beforehand. For example, if the user defines a window 1 ms in length and the ADC threshold is reached after 0.5 ms, a candidate will only be constructed once a TP is received with a start time 1 ms after the first TP in that window.
- Can use `faketp_chain` confgen to generate the configuration to run the fake TP chain with the `ADCSimpleWindow` algorithm:
```
python -m trigger.faketp_chain -a TAMakerADCSimpleWindowPlugin -A "dict(window_length=100000,adc_threshold=1000000)" -c TriggerCandidateMakerADCSimpleWindowPlugin -f tps_link_11.txt faketp_chain_ADCSimpleWindow
python -m trigger.faketp_chain -a TAMakerADCSimpleWindowPlugin -A "dict(window_length=100000,adc_threshold=1000000)" -c TCMakerADCSimpleWindowPlugin -f tps_link_11.txt faketp_chain_ADCSimpleWindow
```
- Then to run:
```
Expand Down
9 changes: 5 additions & 4 deletions include/triggeralgs/AbstractFactory.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef TRIGGERALGS_ABSTRACT_FACTORY_HXX_
#define TRIGGERALGS_ABSTRACT_FACTORY_HXX_

#include "triggeralgs/Issues.hpp"

namespace triggeralgs {

template <typename T>
Expand All @@ -29,8 +31,7 @@ void AbstractFactory<T>::register_creator(const std::string alg_name, maker_crea
makers[alg_name] = creator;
return;
}
TLOG(0) << "Attempted to overwrite a creator in factory with " << alg_name << ".";
throw; // creators should not be overwritten.
throw FactoryOverwrite(ERS_HERE, alg_name);
return;
}

Expand All @@ -41,11 +42,11 @@ std::unique_ptr<T> AbstractFactory<T>::build_maker(const std::string& alg_name)
auto it = makers.find(alg_name);

if (it != makers.end()) {
TLOG(0) << "Factory building " << alg_name << ".";
TLOG() << "[AF] Factory building " << alg_name << ".";
return it->second();
}

TLOG(0) << "Factory couldn't find " << alg_name << ".";
throw FactoryNotFound(ERS_HERE, alg_name);
return nullptr;
}

Expand Down
33 changes: 33 additions & 0 deletions include/triggeralgs/BundleN/TAMakerBundleNAlgorithm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file TAMakerBundleNAlgorithm.hpp
*
* This is part of the DUNE DAQ Application Framework, copyright 2020.
* Licensing/copyright details are in the COPYING file that you should have
* received with this code.
*/

#ifndef TRIGGERALGS_BUNDLEN_TRIGGERACTIVITYMAKERBUNDLEN_HPP_
#define TRIGGERALGS_BUNDLEN_TRIGGERACTIVITYMAKERBUNDLEN_HPP_

#include "triggeralgs/TriggerActivityFactory.hpp"

#include <vector>

namespace triggeralgs {

class TAMakerBundleNAlgorithm : public TriggerActivityMaker
{
public:
void process(const TriggerPrimitive& input_tp, std::vector<TriggerActivity>& output_tas);
void configure(const nlohmann::json& config);
bool bundle_condition();

private:
uint64_t m_bundle_size = 1;
TriggerActivity m_current_ta;
void set_ta_attributes();
};

} // namespace triggeralgs

#endif // TRIGGERALGS_BUNDLEN_TRIGGERACTIVITYMAKERBUNDLEN_HPP_
33 changes: 33 additions & 0 deletions include/triggeralgs/BundleN/TCMakerBundleNAlgorithm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file TCMakerBundleNAlgorithm.hpp
*
* This is part of the DUNE DAQ Application Framework, copyright 2020.
* Licensing/copyright details are in the COPYING file that you should have
* received with this code.
*/

#ifndef TRIGGERALGS_BUNDLEN_TRIGGERCANDIDATEMAKERBUNDLEN_HPP_
#define TRIGGERALGS_BUNDLEN_TRIGGERCANDIDATEMAKERBUNDLEN_HPP_

#include "triggeralgs/TriggerCandidateFactory.hpp"

#include <vector>

namespace triggeralgs {

class TCMakerBundleNAlgorithm: public TriggerCandidateMaker
{
public:
void process(const TriggerActivity& input_ta, std::vector<TriggerCandidate>& output_tcs);
void configure(const nlohmann::json& config);
bool bundle_condition();

private:
uint64_t m_bundle_size = 1;
TriggerCandidate m_current_tc;
void set_tc_attributes();
};

} // namespace triggeralgs

#endif // TRIGGERALGS_BUNDLEN_TRIGGERCANDIDATEMAKERBUNDLEN_HPP_
3 changes: 3 additions & 0 deletions include/triggeralgs/ChannelAdjacency/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The ChannelAdjacency algorithm is a refined version of the HorizontalMuon algorithm (only the TA maker part for the moment). TA logic changes: in a given TP window (of default 8000 ticks), when TAs are constructed, they only contain the TPs which form an activity/track (and are not the outliers). More than one TAs per window are allowed but they should not be overlapping!

More details can be found here https://indico.fnal.gov/event/63863/ (Horizontal Muon refinement by SS Chhibra)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file TAMakerChannelAdjacencyAlgorithm.hpp
*
* This is part of the DUNE DAQ Application Framework, copyright 2021.
* Licensing/copyright details are in the COPYING file that you should have
* received with this code.
*/

#ifndef TRIGGERALGS_CHANNELADJACENCY_TRIGGERACTIVITYMAKERCHANNELADJACENCY_HPP_
#define TRIGGERALGS_CHANNELADJACENCY_TRIGGERACTIVITYMAKERCHANNELADJACENCY_HPP_

#include "triggeralgs/TPWindow.hpp"
#include "triggeralgs/TriggerActivityFactory.hpp"
#include <fstream>
#include <vector>

namespace triggeralgs {
class TAMakerChannelAdjacencyAlgorithm : public TriggerActivityMaker
{
public:
void process(const TriggerPrimitive& input_tp, std::vector<TriggerActivity>& output_ta);
void configure(const nlohmann::json& config);

private:
TriggerActivity construct_ta(TPWindow) const;

TPWindow check_adjacency();

TPWindow m_current_window;

// Configurable parameters.
bool m_print_tp_info = false; // Prints out some information on every TP received
uint16_t m_adjacency_threshold = 15; // Default is 15 wire track for testing
uint16_t m_adj_tolerance = 3; // Adjacency tolerance - default is 3 from coldbox testing.
timestamp_t m_window_length = 8000; // Shouldn't exceed the max drift which is ~9375 62.5 MHz ticks for VDCB

// For debugging and performance study purposes.
void add_window_to_record(TPWindow window);
std::vector<TPWindow> m_window_record;
};
} // namespace triggeralgs
#endif // TRIGGERALGS_CHANNELADJACENCY_TRIGGERACTIVITYMAKERCHANNELADJACENCY_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @file TCMakerChannelAdjacencyAlgorithm.hpp
*
* This is part of the DUNE DAQ Application Framework, copyright 2021.
* Licensing/copyright details are in the COPYING file that you should have
* received with this code.
*/

#ifndef TRIGGERALGS_CHANNELADJACENCY_TRIGGERCANDIDATEMAKERCHANNELADJACENCY_HPP_
#define TRIGGERALGS_CHANNELADJACENCY_TRIGGERCANDIDATEMAKERCHANNELADJACENCY_HPP_

#include "triggeralgs/TriggerCandidateFactory.hpp"
#include "triggeralgs/TAWindow.hpp"

#include <fstream>
#include <vector>

namespace triggeralgs {
class TCMakerChannelAdjacencyAlgorithm : public TriggerCandidateMaker
{

public:
// The function that gets called when there is a new activity
void process(const TriggerActivity&, std::vector<TriggerCandidate>&);
void configure(const nlohmann::json& config);

private:

TriggerCandidate construct_tc() const;

TAWindow m_current_window;
uint64_t m_activity_count = 0; // NOLINT(build/unsigned)

// Configurable parameters.
bool m_trigger_on_adc = false;
bool m_trigger_on_n_channels = false;
uint32_t m_adc_threshold = 1200000;
uint16_t m_n_channels_threshold = 600; // 80ish for frames, O(200 - 600) for tpslink
timestamp_t m_window_length = 80000;

// For debugging purposes.
void add_window_to_record(TAWindow window);
std::vector<TAWindow> m_window_record;
};
} // namespace triggeralgs
#endif // TRIGGERALGS_CHANNELADJACENCY_TRIGGERCANDIDATEMAKERCHANNELADJACENCY_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file TAMakerChannelDistanceAlgorithm.hpp
*
* This is part of the DUNE DAQ Application Framework, copyright 2021.
* Licensing/copyright details are in the COPYING file that you should have
* received with this code.
*/

#ifndef TRIGGERALGS_CHANNELDISTANCE_TRIGGERACTIVITYMAKERCHANNELDISTANCE_HPP_
#define TRIGGERALGS_CHANNELDISTANCE_TRIGGERACTIVITYMAKERCHANNELDISTANCE_HPP_

#include "triggeralgs/TriggerActivityFactory.hpp"
#include <algorithm>

namespace triggeralgs {

class TAMakerChannelDistanceAlgorithm : public TriggerActivityMaker {
public:
void process(const TriggerPrimitive& input_tp, std::vector<TriggerActivity>& output_tas);
void configure(const nlohmann::json& config);
void set_ta_attributes();

private:
void set_new_ta(const TriggerPrimitive& input_tp);
TriggerActivity m_current_ta;
uint32_t m_max_channel_distance = 50;
uint64_t m_window_length = 8000;
uint16_t m_min_tps = 20; // AEO: Type is arbitrary. Surprised even asking for 2^8 TPs.
uint32_t m_current_lower_bound;
uint32_t m_current_upper_bound;
};

} // namespace triggeralgs

#endif // TRIGGERALGS_CHANNELDISTANCE_TRIGGERACTIVITYMAKERCHANNELDISTANCE_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file TCMakerChannelDistanceAlgorithm.hpp
*
* This is part of the DUNE DAQ Application Framework, copyright 2021.
* Licensing/copyright details are in the COPYING file that you should have
* received with this code.
*/

#ifndef TRIGGERALGS_CHANNELDISTANCE_TRIGGERCANDIDATEMAKERCHANNELDISTANCE_HPP_
#define TRIGGERALGS_CHANNELDISTANCE_TRIGGERCANDIDATEMAKERCHANNELDISTANCE_HPP_

#include "triggeralgs/TriggerCandidateFactory.hpp"
#include <algorithm>

namespace triggeralgs {

class TCMakerChannelDistanceAlgorithm : public TriggerCandidateMaker {
public:
void process(const TriggerActivity& input_ta, std::vector<TriggerCandidate>& output_tcs);
void configure(const nlohmann::json& config);
void set_tc_attributes();

private:
void set_new_tc(const TriggerActivity& input_ta);
TriggerCandidate m_current_tc;
uint16_t m_current_tp_count;
uint16_t m_max_tp_count = 1000; // Produce a TC when this count is exceeded. AEO: Arbitrary choice of 1000.
};

} // namespace triggeralgs

#endif // TRIGGERALGS_CHANNELDISTANCE_TRIGGERCANDIDATEMAKERCHANNELDISTANCE_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ class TAMakerHorizontalMuonAlgorithm : public TriggerActivityMaker

private:
TriggerActivity construct_ta() const;
uint16_t check_adjacency() const; // Returns longest string of adjacent collection hits in window
uint16_t check_adjacency() const; // Returns longest string of adjacent collection hits in window

TPWindow m_current_window; // Holds collection hits only
uint64_t m_primitive_count = 0;
TPWindow m_current_window; // Holds collection hits only
int check_tot() const;

// Configurable parameters.
bool m_trigger_on_adc = false;
bool m_trigger_on_n_channels = false;
bool m_trigger_on_adjacency = true; // Default use of the horizontal muon triggering
bool m_trigger_on_adjacency = true; // Default use of the horizontal muon triggering
bool m_trigger_on_tot = false;
uint16_t m_tot_threshold = 5000; // Time over threshold - threshold to exceed.
bool m_print_tp_info = false; // Prints out some information on every TP received
Expand All @@ -44,7 +43,7 @@ class TAMakerHorizontalMuonAlgorithm : public TriggerActivityMaker
int index = 0;
uint16_t ta_adc = 0;
uint16_t ta_channels = 0;
timestamp_t m_window_length = 8000; // Shouldn't exceed the max drift which is ~9375 62.5 MHz ticks for VDCB
timestamp_t m_window_length = 8000; // Shouldn't exceed the max drift which is ~9375 62.5 MHz ticks for VDCB

// For debugging and performance study purposes.
void add_window_to_record(TPWindow window);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class TCMakerHorizontalMuonAlgorithm : public TriggerCandidateMaker
uint32_t m_adc_threshold = 1200000;
uint16_t m_n_channels_threshold = 600; // 80ish for frames, O(200 - 600) for tpslink
timestamp_t m_window_length = 80000;
timestamp_t m_readout_window_ticks_before = 32768;
timestamp_t m_readout_window_ticks_after = 32768;
int tc_number = 0;

// For debugging purposes.
Expand Down
31 changes: 31 additions & 0 deletions include/triggeralgs/Issues.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @file Issues.hpp
*
* This is part of the DUNE DAQ Application Framework, copyright 2020.
* Licensing/copyright details are in the COPYING file that you should have
* received with this code.
*/

#ifndef TRIGGERALGS_INCLUDE_TRIGGERALGS_ISSUES_HPP_
#define TRIGGERALGS_INCLUDE_TRIGGERALGS_ISSUES_HPP_

#include "ers/Issue.hpp"

#include <string>

ERS_DECLARE_ISSUE(triggeralgs,
FactoryOverwrite,
"Attempted to overwrite a creator in factory with " << alg_name,
((std::string)alg_name))

ERS_DECLARE_ISSUE(triggeralgs,
FactoryNotFound,
"Factory couldn't find: " << alg_name,
((std::string)alg_name))

ERS_DECLARE_ISSUE(triggeralgs,
BadConfiguration,
"Bad configuration in " << alg_name,
((std::string)alg_name))

#endif // TRIGGERALGS_INCLUDE_TRIGGERALGS_ISSUES_HPP_
Loading

0 comments on commit 4fddb07

Please sign in to comment.