5#include "TRestRawPeaksFinderProcess.h"
9#include "TRestRawReadoutMetadata.h"
20 auto event = fSignalEvent->GetSignalEventForTypes(fChannelTypes, fReadoutMetadata);
22 if (fReadoutMetadata ==
nullptr) {
23 fReadoutMetadata = fSignalEvent->GetReadoutMetadata();
26 if (fReadoutMetadata ==
nullptr) {
27 cerr <<
"TRestRawPeaksFinderProcess::ProcessEvent: readout metadata is null" << endl;
31 std::vector<tuple<UShort_t, UShort_t, double>> eventPeaks;
33 for (
int signalIndex = 0; signalIndex <
event.GetNumberOfSignals(); signalIndex++) {
34 const auto signal =
event.GetSignal(signalIndex);
35 const UShort_t signalId = signal->GetSignalID();
37 const string channelType = fReadoutMetadata->GetTypeForChannelDaqId(signalId);
38 const string channelName = fReadoutMetadata->GetNameForChannelDaqId(signalId);
41 if (fChannelTypes.find(channelType) == fChannelTypes.end()) {
45 signal->CalculateBaseLine(0, 5);
46 const auto peaks = signal->GetPeaks(signal->GetBaseLine() + 1.0,
fDistance);
48 for (
const auto& [time, amplitude] : peaks) {
49 eventPeaks.emplace_back(signalId, time, amplitude);
60 sort(eventPeaks.begin(), eventPeaks.end(),
61 [](
const tuple<UShort_t, UShort_t, double>& a,
const tuple<UShort_t, UShort_t, double>& b) {
62 return std::tie(std::get<1>(a), std::get<0>(a)) < std::tie(std::get<1>(b), std::get<0>(b));
67 std::vector<UShort_t> windowIndex(eventPeaks.size(), 0);
68 std::vector<UShort_t> windowCenter;
70 for (
size_t peakIndex = 0; peakIndex < eventPeaks.size(); peakIndex++) {
71 const auto& [channelId, time, amplitude] = eventPeaks[peakIndex];
72 const auto windowTime = time -
fWindow / 2;
73 const auto windowEnd = time +
fWindow / 2;
76 if (windowIndex[peakIndex] != 0) {
81 windowCenter.push_back(time);
84 windowIndex[peakIndex] = windowCenter.size();
87 for (
size_t otherPeakIndex = peakIndex + 1; otherPeakIndex < eventPeaks.size(); otherPeakIndex++) {
88 const auto& [otherChannelId, otherTime, otherAmplitude] = eventPeaks[otherPeakIndex];
90 if (otherTime < windowTime) {
94 if (otherTime > windowEnd) {
98 windowIndex[otherPeakIndex] = windowCenter.size();
103 for (
auto& index : windowIndex) {
110 for (
size_t index = 0; index < windowCenter.size(); index++) {
112 for (
const auto& window : windowIndex) {
113 if (window == index) {
119 cerr <<
"TRestRawPeaksFinderProcess::ProcessEvent: window index " << index <<
" not found"
132 const auto filterType =
GetParameter(
"channelType",
"");
133 if (!filterType.empty()) {
134 fChannelTypes.insert(filterType);
137 if (fChannelTypes.empty()) {
147 cerr <<
"TRestRawPeaksFinderProcess::InitProcess: baseline range is not sorted or < 0" << endl;
152 cerr <<
"TRestRawPeaksFinderProcess::InitProcess: threshold over baseline is < 0" << endl;
157 cerr <<
"TRestRawPeaksFinderProcess::InitProcess: distance is < 0" << endl;
162 cerr <<
"TRestRawPeaksFinderProcess::InitProcess: window is < 0" << endl;
168 cout <<
"Applying process to channel types: ";
169 for (
const auto& type : fChannelTypes) {
177 cout <<
"Distance: " <<
fDistance << endl;
178 cout <<
"Window: " <<
fWindow << endl;
TRestRun * GetRunInfo() const
Return the pointer of the hosting TRestRun object.
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
A base class for any REST event.
virtual void InitializeReferences(TRestRun *run)
Initialize dynamical references when loading the event from a root file.
UShort_t fDistance
distance between two peaks to consider them as different
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
Double_t fThresholdOverBaseline
threshold over baseline to consider a peak
UShort_t fWindow
window size to calculate the peak amplitude
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
TVector2 fBaselineRange
range of samples to calculate baseline for peak finding
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
An event container for time rawdata signals with fixed length.
Double_t StringToDouble(std::string in)
Gets a double from a string.