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"