Commit ba9d130b authored by Volker Friese's avatar Volker Friese Committed by Sergey Gorbunov
Browse files

Algo version of digi trigger. Derived from CbmSeedFinderSlidingWindow. Refs #2266.

parent aa16daad
......@@ -6,6 +6,7 @@ add_subdirectory (data)
set(SRCS
evbuild/EventBuilder.cxx
trigger/TimeClusterTrigger.cxx
)
add_library(Algo SHARED ${SRCS})
......
/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Volker Friese [committer], Dominik Smith */
#include "TimeClusterTrigger.h"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <vector>
using std::vector;
namespace cbm::algo
{
vector<double> TimeClusterTrigger::operator()(const vector<double>& dataVec, double winSize, int32_t minNumData,
double deadTime) const
{
assert(std::is_sorted(dataVec.begin(), dataVec.end()));
vector<double> triggerVec;
auto winStart = dataVec.begin();
auto current = dataVec.begin();
while (current != dataVec.end()) {
// If window size is exceeded, adjust window start
while (*current - *winStart > winSize)
winStart++;
// Create trigger if threshold is reached
if (std::distance(winStart, current) >= minNumData - 1) {
triggerVec.push_back(0.5 * (*current + *winStart));
// Start new window after dead time
winStart = current + 1;
while (winStart != dataVec.end() && *winStart - *current < deadTime)
winStart++;
current = winStart;
}
// If threshold is not reached, check with next element
else
current++;
}
return triggerVec;
}
} // namespace cbm::algo
/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Volker Friese [committer], Dominik Smith */
#ifndef CBM_ALGO_TIMECLUSTERTRIGGER_H
#define CBM_ALGO_TIMECLUSTERTRIGGER_H 1
#include <cstdint>
#include <vector>
namespace cbm::algo
{
/** @class TimeClusterTrigger
** @author Volker Friese <v.friese@gsi.de>
** @author Dominik Smith <d.smith@gsi.de>
** @since 2021
** @brief Finds clusters in time-series data
**
** A trigger is generated when the number density of data exceeds a given threshold. Each datum
** can contribute to only one trigger. Consecutive triggers are separated by at least the dead time.
**
** The input vector must be sorted, otherwise the behaviour is undefined.
**/
class TimeClusterTrigger {
public:
/** @brief Execution
** @param dataVec Source data vector
** @param winSize Size of trigger window
** @param minNumData Threshold on number of data within the trigger window
** @param deadTime Minimum time between two triggers
** @return Vector of trigger times
**/
std::vector<double> operator()(const std::vector<double>& dataVec, double winSize, int32_t minNumData,
double deadTime) const;
};
} // namespace cbm::algo
#endif /* CBM_ALGO_TIMECLUSTERTRIGGER_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment