23#include "TRestRawSignalRangeReductionProcess.h"
29TRestRawSignalRangeReductionProcess::TRestRawSignalRangeReductionProcess() {
Initialize(); }
31TRestRawSignalRangeReductionProcess::TRestRawSignalRangeReductionProcess(
const char* configFilename) {
38TRestRawSignalRangeReductionProcess::~TRestRawSignalRangeReductionProcess() {
delete fOutputRawSignalEvent; }
40void TRestRawSignalRangeReductionProcess::LoadDefaultConfig() {
41 SetName(
"rawSignalRangeReductionProcess-default");
42 SetTitle(
"Default config");
49 fInputRawSignalEvent =
nullptr;
53void TRestRawSignalRangeReductionProcess::LoadConfig(
const string& configFilename,
const string& name) {
58 const UShort_t resolutionInBits =
60 SetResolutionInNumberOfBits(resolutionInBits);
62 const TVector2 DigitizationRange = Get2DVectorParameterWithUnits(
"inputRange", fDigitizationInputRange);
63 SetDigitizationInputRange(DigitizationRange);
67 fDigitizationOutputRange = {0, TMath::Power(2, fResolutionInBits) - 1};
73 if (fInputRawSignalEvent->GetNumberOfSignals() <= 0) {
77 for (
int n = 0; n < fInputRawSignalEvent->GetNumberOfSignals(); n++) {
78 const TRestRawSignal* inputSignal = fInputRawSignalEvent->GetSignal(n);
83 const Double_t value = (Double_t)inputSignal->
GetData(i);
84 Double_t newValue = ConvertFromStartingRangeToTargetRange(value);
88 fOutputRawSignalEvent->AddSignal(signal);
91 return fOutputRawSignalEvent;
94void TRestRawSignalRangeReductionProcess::SetResolutionInNumberOfBits(UShort_t nBits) {
95 if (nBits < 0 || nBits > 16) {
96 RESTWarning <<
"Number of bits must be between 1 and 16. Setting it to " << fResolutionInBits
100 fResolutionInBits = nBits;
103void TRestRawSignalRangeReductionProcess::SetDigitizationInputRange(
const TVector2& range) {
104 fDigitizationInputRange = range;
106 const auto limitMin = std::numeric_limits<Short_t>::min();
107 const auto limitMax = std::numeric_limits<Short_t>::max();
108 if (range.X() < limitMin) {
109 RESTWarning <<
"TRestRawSignalRangeReductionProcess::SetDigitizationRange - user set start of "
110 "Digitization range to "
111 << range.X() <<
" which is below the limit of " << limitMin <<
". Setting range start to "
113 fDigitizationInputRange = TVector2(limitMin, range.Y());
115 if (range.Y() > limitMax) {
116 RESTWarning <<
"TRestRawSignalRangeReductionProcess::SetDigitizationRange - user set end of "
117 "Digitization range to "
118 << range.Y() <<
" which is above the limit of " << limitMax <<
". Setting end start to "
120 fDigitizationInputRange = TVector2(range.X(), limitMax);
124Double_t TRestRawSignalRangeReductionProcess::ConvertFromStartingRangeToTargetRange(Double_t value)
const {
125 const Double_t conversionFactor = (fDigitizationOutputRange.Y() - fDigitizationOutputRange.X()) /
126 (fDigitizationInputRange.Y() - fDigitizationInputRange.X());
127 const Double_t newValue =
128 round(fDigitizationOutputRange.X() + (value - fDigitizationInputRange.X()) * conversionFactor);
130 if (newValue < fDigitizationOutputRange.X()) {
131 return fDigitizationOutputRange.X();
132 }
else if (newValue > fDigitizationOutputRange.Y()) {
133 return fDigitizationOutputRange.Y();
139Double_t TRestRawSignalRangeReductionProcess::ConvertFromTargetRangeToStartingRange(Double_t value)
const {
140 const Double_t conversionFactor = (fDigitizationInputRange.Y() - fDigitizationInputRange.X()) /
141 (fDigitizationOutputRange.Y() - fDigitizationOutputRange.X());
142 const Double_t newValue =
143 round(fDigitizationInputRange.X() + (value - fDigitizationOutputRange.X()) * conversionFactor);
145 if (newValue < fDigitizationInputRange.X()) {
146 return fDigitizationInputRange.X();
148 if (newValue > fDigitizationInputRange.Y()) {
149 return fDigitizationInputRange.Y();
A base class for any REST event.
An event container for time rawdata signals with fixed length.
void Initialize() override
Making default settings.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
void SetSignalID(Int_t sID)
It sets the id number of the signal.
Double_t GetData(Int_t n) const
It returns the data value of point n including baseline correction.
void AddPoint(Short_t)
Adds a new point to the end of the signal data array.
Int_t GetSignalID() const
Returns the value of signal ID.
Int_t GetNumberOfPoints() const
Returns the actual number of points, or size of the signal.
Double_t StringToDouble(std::string in)
Gets a double from a string.