86#include "TRestRawCommonNoiseReductionProcess.h"
176 if (run !=
nullptr) {
181 for (
int signal = 0; signal <
fInputEvent->GetNumberOfSignals(); signal++) {
187 if (fReadoutMetadata ==
nullptr) {
188 fReadoutMetadata =
fInputEvent->GetReadoutMetadata();
191 if (fReadoutMetadata ==
nullptr && !fChannelType.empty()) {
192 cerr <<
"TRestRawCommonNoiseReductionProcess::ProcessEvent: readout metadata is null, cannot filter "
193 "the process by signal type"
198 vector<TRestRawSignal*> signalsToProcess;
199 vector<TRestRawSignal*> signalsToIgnore;
201 if (fChannelType.empty()) {
202 for (
int signal = 0; signal <
fInputEvent->GetNumberOfSignals(); signal++) {
203 signalsToProcess.push_back(
fInputEvent->GetSignal(signal));
206 for (
int signal = 0; signal <
fInputEvent->GetNumberOfSignals(); signal++) {
208 const UShort_t signalId = signalPtr->
GetSignalID();
209 const string channelType = fReadoutMetadata->GetTypeForChannelDaqId(signalId);
211 if (fChannelType == channelType) {
212 signalsToProcess.push_back(signalPtr);
214 signalsToIgnore.push_back(signalPtr);
220 for (
auto signal : signalsToIgnore) {
225 for (
auto signal : signalsToProcess) {
226 eventToProcess.AddSignal(*signal);
230 Double_t baseLineMean = 0;
231 for (
int signal = 0; signal < eventToProcess.GetNumberOfSignals(); signal++) {
232 eventToProcess.GetSignal(signal)->CalculateBaseLine(20, 150);
233 Double_t baseline = eventToProcess.GetSignal(signal)->GetBaseLine();
234 baseLineMean += baseline;
236 Double_t Baseline = baseLineMean / eventToProcess.GetNumberOfSignals();
239 Int_t N = eventToProcess.GetNumberOfSignals();
242 for (
int signal = 0; signal < N; signal++) {
243 fOutputEvent->AddSignal(*eventToProcess.GetSignal(signal));
246 Int_t nBins = eventToProcess.GetSignal(0)->GetNumberOfPoints();
247 vector<Double_t> signalValues(N, 0.0);
249 for (Int_t bin = 0; bin < nBins; bin++) {
250 for (Int_t signal = 0; signal < N; signal++) {
254 std::sort(signalValues.begin(), signalValues.end());
257 Int_t begin = 0, middle = 0, end = 0;
258 middle = (Int_t)N / 2;
263 begin = (Int_t)((double_t)N / 2.0);
266 }
else if (
fMode == 1) {
270 norm = (Double_t)end - begin;
274 Double_t binCorrection = 0.0;
275 for (Int_t i = begin; i <= end; i++) binCorrection += signalValues[i];
277 binCorrection = binCorrection / norm;
280 for (Int_t signal = 0; signal < N; signal++)
295 for (
int block = 0; block < nBlocks; block++) {
296 firstInBlock = firstID + block * (N + gap);
300 for (Int_t signal = 0; signal < N; signal++) {
301 sigID = firstInBlock + signal;
303 if (eventToProcess.GetSignalById(sigID)->GetBaseLineSigma() >= 3.3) {
307 fOutputEvent->AddSignal(*eventToProcess.GetSignalById(sigID));
312 Int_t nBins = eventToProcess.GetSignal(0)->GetNumberOfPoints();
313 vector<Double_t> signalValues(nSign, 0.0);
317 for (Int_t bin = 0; bin < nBins; bin++) {
319 for (Int_t signal = 0; signal < N; signal++) {
320 sigID = firstInBlock + signal;
321 if (eventToProcess.GetSignalById(sigID)->GetBaseLineSigma() >= 3.3) {
332 std::sort(signalValues.begin(), signalValues.end());
335 Int_t begin = 0, middle = 0, end = 0;
336 middle = (Int_t)nSign / 2;
341 begin = (Int_t)((double_t)nSign / 2.0);
344 }
else if (
fMode == 1) {
348 norm = (Double_t)end - begin;
352 Double_t binCorrection = 0.0;
353 for (Int_t i = begin; i <= end; i++) {
354 binCorrection += signalValues[i];
357 binCorrection = binCorrection / norm;
360 for (Int_t signal = 0; signal < N; signal++) {
361 if (eventToProcess.GetSignalById(firstInBlock + signal)->GetBaseLineSigma() >= 3.3) {
367 for (
int signal = 0; signal < N; signal++) {
368 if (eventToProcess.GetSignalById(firstInBlock + signal)->GetBaseLineSigma() < 3.3) {
369 fOutputEvent->AddSignal(*eventToProcess.GetSignalById(firstInBlock + signal));
TRestRun * GetRunInfo() const
Return the pointer of the hosting TRestRun object.
A base class for any REST event.
virtual void InitializeReferences(TRestRun *run)
Initialize dynamical references when loading the event from a root file.
A process to subtract the common channels noise from RawSignal type.
void Initialize() override
Function to initialize input/output event members and define the section name.
~TRestRawCommonNoiseReductionProcess()
Default destructor.
Int_t fBlocks
Common noise to all signals or by groups (It can be 0 or 1).
TRestRawSignalEvent * fInputEvent
A pointer to the specific TRestRawSignalEvent input.
Int_t fMinSignalsRequired
Minimum number of signals required to apply the process.
TRestRawSignalEvent * fOutputEvent
A pointer to the specific TRestRawSignalEvent output.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
void EndProcess() override
Function to include required actions after all events have been processed. This method will write the...
TRestRawCommonNoiseReductionProcess()
Default constructor.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
void InitProcess() override
Process initialization.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
Int_t fMode
The mode defines the method to be used (It can be 0 or 1).
An event container for time rawdata signals with fixed length.
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
void CalculateBaseLine(Int_t startBin, Int_t endBin, const std::string &option="")
This method calculates the average and fluctuation of the baseline in the specified range and writes ...
void IncreaseBinBy(Int_t bin, Double_t data)
It adds the content of data to fSignalData[bin].
Double_t GetRawData(Int_t n) const
It returns the original data value of point n without baseline correction.
Int_t GetSignalID() const
Returns the value of signal ID.