Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process modified to allow for signal type selection #125

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions inc/TRestRawBaseLineCorrectionProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,32 @@
#ifndef RESTProc_TRestRawBaseLineCorrectionProcess
#define RESTProc_TRestRawBaseLineCorrectionProcess

#include "TRestEventProcess.h"
#include <TRestEventProcess.h>

#include "TRestRawReadoutMetadata.h"
#include "TRestRawSignalEvent.h"

class TRestRawBaseLineCorrectionProcess : public TRestEventProcess {
private:
// We define specific input/output event data holders
TRestRawSignalEvent* fInputEvent; //!
TRestRawSignalEvent* fOutputEvent; //!
TRestRawReadoutMetadata* fReadoutMetadata = nullptr;

void Initialize() override;

/// It defines the signals id range where analysis is applied
TVector2 fSignalsRange = TVector2(-1, -1);
TVector2 fSignalsRange = {-1, -1};

/// Time window width in bins for the moving average filter for baseline correction
Int_t fSmoothingWindow = 75;
UShort_t fSmoothingWindow = 75;

/// Just a flag to quickly determine if we have to apply the range filter
Bool_t fRangeEnabled = false; //!

/// Specify the channel types we want the process to be applied for
std::set<std::string> fChannelTypes = {};

public:
RESTValue GetInputEvent() const override { return fInputEvent; }
RESTValue GetOutputEvent() const override { return fOutputEvent; }
Expand All @@ -53,16 +59,32 @@ class TRestRawBaseLineCorrectionProcess : public TRestEventProcess {

void EndProcess() override;

void InitFromConfigFile() override;

void PrintMetadata() override {
BeginPrintProcess();

if (!fChannelTypes.empty()) {
RESTMetadata << "Selected channel types: ";
// Iterate through each channel type in fChannelTypes and print it
for (auto it = fChannelTypes.begin(); it != fChannelTypes.end(); ++it) {
RESTMetadata << *it;
// If it's not the last element, print a comma and a space
if (std::next(it) != fChannelTypes.end()) {
RESTMetadata << ", ";
}
}
RESTMetadata << RESTendl;
} else {
RESTMetadata << "No channel type chosen." << RESTendl;
}

RESTMetadata << "Smoothing window size: " << fSmoothingWindow << RESTendl;
RESTMetadata << "Baseline correction applied to signals with IDs in range (" << fSignalsRange.X()
<< "," << fSignalsRange.Y() << ")" << RESTendl;

EndPrintProcess();
}

/// Returns a new instance of this class
TRestEventProcess* Maker() { return new TRestRawBaseLineCorrectionProcess; }

Expand Down
48 changes: 47 additions & 1 deletion src/TRestRawBaseLineCorrectionProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@

#include "TRestRawBaseLineCorrectionProcess.h"

#include <utility>

ClassImp(TRestRawBaseLineCorrectionProcess);

TRestRawBaseLineCorrectionProcess::TRestRawBaseLineCorrectionProcess() { Initialize(); }
Expand All @@ -86,14 +88,44 @@ void TRestRawBaseLineCorrectionProcess::Initialize() {

void TRestRawBaseLineCorrectionProcess::InitProcess() {
if (fSignalsRange.X() != -1 && fSignalsRange.Y() != -1) fRangeEnabled = true;

const auto filterType = GetParameter("channelType", "");
if (!filterType.empty()) {
fChannelTypes.insert(filterType);
std::cout << "Types: " << filterType << std::endl;
}

if (fChannelTypes.empty()) {
// if no channel type is specified, use all channel types
}
}

TRestEvent* TRestRawBaseLineCorrectionProcess::ProcessEvent(TRestEvent* evInput) {
fInputEvent = (TRestRawSignalEvent*)evInput;
fInputEvent = dynamic_cast<TRestRawSignalEvent*>(evInput);
fInputEvent->InitializeReferences(GetRunInfo());

if (fReadoutMetadata == nullptr) {
fReadoutMetadata = fInputEvent->GetReadoutMetadata();
}

if (fReadoutMetadata == nullptr) {
std::cerr << "TRestRawBaseLineCorrectionProcess::ProcessEvent: readout metadata is null" << std::endl;
exit(1);
}

for (int s = 0; s < fInputEvent->GetNumberOfSignals(); s++) {
TRestRawSignal* sgnl = fInputEvent->GetSignal(s);

const UShort_t signalId = sgnl->GetSignalID();

const std::string channelType = fReadoutMetadata->GetTypeForChannelDaqId(signalId);
const std::string channelName = fReadoutMetadata->GetNameForChannelDaqId(signalId);

// check if channel type is in the list of selected channel types
if (fChannelTypes.find(channelType) == fChannelTypes.end()) {
continue;
}

if (fRangeEnabled && (sgnl->GetID() < fSignalsRange.X() || sgnl->GetID() > fSignalsRange.Y())) {
fOutputEvent->AddSignal(*sgnl);
continue;
Expand All @@ -109,3 +141,17 @@ TRestEvent* TRestRawBaseLineCorrectionProcess::ProcessEvent(TRestEvent* evInput)
}

void TRestRawBaseLineCorrectionProcess::EndProcess() {}

void TRestRawBaseLineCorrectionProcess::InitFromConfigFile() {
const auto filterType = GetParameter("channelType", "");
if (!filterType.empty()) {
fChannelTypes.insert(filterType);
}

if (fChannelTypes.empty()) {
// if no channel type is specified, use all channel types
}

fSignalsRange = Get2DVectorParameterWithUnits("signalsRange", fSignalsRange);
fSmoothingWindow = StringToDouble(GetParameter("smoothingWindow", fSmoothingWindow));
}
Loading