2#include "TRestRawPeaksFinderProcess.h"
20 auto event = fInputEvent->GetSignalEventForTypes(fChannelTypes, fReadoutMetadata);
22 if (fReadoutMetadata ==
nullptr) {
23 fReadoutMetadata = fInputEvent->GetReadoutMetadata();
26 if (fReadoutMetadata ==
nullptr && !fChannelTypes.empty()) {
27 cerr <<
"TRestRawPeaksFinderProcess::ProcessEvent: readout metadata is null, cannot filter "
28 "the process by signal type"
33 vector<tuple<UShort_t, UShort_t, double>> eventPeaks;
35 for (
int signalIndex = 0; signalIndex <
event.GetNumberOfSignals(); signalIndex++) {
36 const auto signal =
event.GetSignal(signalIndex);
37 const UShort_t signalId = signal->GetSignalID();
39 const string channelType = fReadoutMetadata->GetTypeForChannelDaqId(signalId);
40 const string channelName = fReadoutMetadata->GetNameForChannelDaqId(signalId);
43 if (fChannelTypes.find(channelType) == fChannelTypes.end()) {
47 signal->CalculateBaseLine(0, 5);
48 const auto peaks = signal->GetPeaks(signal->GetBaseLine() + 1.0,
fDistance);
50 for (
const auto& [time, amplitude] : peaks) {
51 eventPeaks.emplace_back(signalId, time, amplitude);
62 sort(eventPeaks.begin(), eventPeaks.end(),
63 [](
const tuple<UShort_t, UShort_t, double>& a,
const tuple<UShort_t, UShort_t, double>& b) {
64 return tie(get<1>(a), get<0>(a)) < tie(get<1>(b), get<0>(b));
68 vector<UShort_t> peaksChannelId;
69 vector<UShort_t> peaksTime;
70 vector<double> peaksAmplitude;
72 for (
const auto& [channelId, time, amplitude] : eventPeaks) {
73 peaksChannelId.push_back(channelId);
74 peaksTime.push_back(time);
75 peaksAmplitude.push_back(amplitude);
82 vector<UShort_t> windowIndex(eventPeaks.size(), 0);
83 vector<UShort_t> windowCenter;
85 for (
size_t peakIndex = 0; peakIndex < eventPeaks.size(); peakIndex++) {
86 const auto& [channelId, time, amplitude] = eventPeaks[peakIndex];
87 const auto windowTime = time -
fWindow / 2;
88 const auto windowEnd = time +
fWindow / 2;
91 if (windowIndex[peakIndex] != 0) {
96 windowCenter.push_back(time);
99 windowIndex[peakIndex] = windowCenter.size();
102 for (
size_t otherPeakIndex = peakIndex + 1; otherPeakIndex < eventPeaks.size(); otherPeakIndex++) {
103 const auto& [otherChannelId, otherTime, otherAmplitude] = eventPeaks[otherPeakIndex];
105 if (otherTime < windowTime) {
109 if (otherTime > windowEnd) {
113 windowIndex[otherPeakIndex] = windowCenter.size();
118 for (
auto& index : windowIndex) {
125 for (
size_t index = 0; index < windowCenter.size(); index++) {
127 for (
const auto& window : windowIndex) {
128 if (window == index) {
134 cerr <<
"TRestRawPeaksFinderProcess::ProcessEvent: window index " << index <<
" not found"
147 const auto filterType =
GetParameter(
"channelType",
"");
148 if (!filterType.empty()) {
149 fChannelTypes.insert(filterType);
152 if (fChannelTypes.empty()) {
162 cerr <<
"TRestRawPeaksFinderProcess::InitProcess: baseline range is not sorted or < 0" << endl;
167 cerr <<
"TRestRawPeaksFinderProcess::InitProcess: threshold over baseline is < 0" << endl;
172 cerr <<
"TRestRawPeaksFinderProcess::InitProcess: distance is < 0" << endl;
177 cerr <<
"TRestRawPeaksFinderProcess::InitProcess: window is < 0" << endl;
185 RESTMetadata <<
"Applying process to channel types: ";
186 for (
const auto& type : fChannelTypes) {
187 RESTMetadata << type <<
" ";
TRestRun * GetRunInfo() const
Return the pointer of the hosting TRestRun object.
void BeginPrintProcess()
[name, cut range]
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.