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

Replace Short_t by UShort_t in raw signal #116

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
14 changes: 7 additions & 7 deletions inc/TRestRawSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <iostream>
#include <string>

//! It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
//! It defines a UShort_t array with a physical parameter that evolves in time using a fixed time bin.
class TRestRawSignal : public TObject {
private:
void CalculateThresholdIntegral();
Expand All @@ -47,7 +47,7 @@ class TRestRawSignal : public TObject {
Int_t fSignalID;

/// Vector with the data of the signal
std::vector<Short_t> fSignalData;
std::vector<UShort_t> fSignalData;

Bool_t fShowWarnings = true;

Expand Down Expand Up @@ -121,7 +121,7 @@ class TRestRawSignal : public TObject {

Double_t GetRawData(Int_t n) const;

Short_t operator[](Int_t n);
UShort_t operator[](Int_t n);

/// It sets the id number of the signal
inline void SetSignalID(Int_t sID) { fSignalID = sID; }
Expand All @@ -147,11 +147,11 @@ class TRestRawSignal : public TObject {

void Initialize();

void AddPoint(Short_t d);
void AddPoint(UShort_t d);

void AddCharge(Short_t d);
void AddCharge(UShort_t d);

void AddDeposit(Short_t d);
void AddDeposit(UShort_t d);

void IncreaseBinBy(Int_t bin, Double_t data);

Expand Down Expand Up @@ -201,7 +201,7 @@ class TRestRawSignal : public TObject {

void GetBaseLineCorrected(TRestRawSignal* smoothedSignal, Int_t averagingPoints);

void AddOffset(Short_t offset);
void AddOffset(UShort_t offset);

void SignalAddition(const TRestRawSignal& signal);

Expand Down
2 changes: 1 addition & 1 deletion inc/TRestRawSignalEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TRestRawSignalEvent : public TRestEvent {

void RemoveSignalWithId(Int_t sId);

void AddChargeToSignal(Int_t sgnlID, Int_t bin, Short_t value);
void AddChargeToSignal(Int_t sgnlID, Int_t bin, UShort_t value);

void SetTailPoints(Int_t p) {
for (int n = 0; n < GetNumberOfSignals(); n++) fSignal[n].SetTailPoints(p);
Expand Down
4 changes: 2 additions & 2 deletions inc/TRestRawSignalRangeReductionProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "TRestRawSignalEvent.h"

//! A process to reduce the range of values of the signals to emulate a realistic ADC.
//! Using Short_t (default) is equivalent to using a 16 bit ADC, we can use this process to go from a 16 bit
//! Using UShort_t (default) is equivalent to using a 16 bit ADC, we can use this process to go from a 16 bit
//! signal to a 12 bit signal (between 0 and 4095) for example.
class TRestRawSignalRangeReductionProcess : public TRestEventProcess {
private:
Expand All @@ -40,7 +40,7 @@ class TRestRawSignalRangeReductionProcess : public TRestEventProcess {

UShort_t fResolutionInBits = 12; // from 1 to 16 bits
TVector2 fDigitizationInputRange =
TVector2(std::numeric_limits<Short_t>::min(), std::numeric_limits<Short_t>::max());
TVector2(std::numeric_limits<UShort_t>::min(), std::numeric_limits<UShort_t>::max());

TVector2 fDigitizationOutputRange; //!

Expand Down
2 changes: 1 addition & 1 deletion pipeline/processes/commonNoise/commonNoise.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Int_t commonNoise() {
TRestRawSignalEvent* ev = new TRestRawSignalEvent();

TRestRawSignal* sgnl = new TRestRawSignal();
for (int n = 0; n < 512; n++) sgnl->AddPoint((Short_t)(50 * TMath::Sin(2 * TMath::Pi() * n / 200)));
for (int n = 0; n < 512; n++) sgnl->AddPoint((UShort_t)(50 * TMath::Sin(2 * TMath::Pi() * n / 200)));

for (int n = 0; n < 205; n++) {
sgnl->SetID(n);
Expand Down
4 changes: 2 additions & 2 deletions src/TRestRawBiPoToSignalProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ TRestEvent* TRestRawBiPoToSignalProcess::ProcessEvent(TRestEvent* inputEvent) {
Int_t nBins = fBiPoSettings[bIndex].t1_window + fBiPoSettings[bIndex].t2_window;

for (int b = 0; b < nBins; b++) {
Short_t sdata = data[GetBin(bIndex, nch, b)];
Short_t v = MATACQ_ZERO - sdata; // Inversing polarity
UShort_t sdata = data[GetBin(bIndex, nch, b)];
UShort_t v = MATACQ_ZERO - sdata; // Inversing polarity
if (sdata == MATACQ_OVERFLOW) {
v = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/TRestRawCommonNoiseReductionProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
///
/// * **Mode = 0**: For each time bin, all time bins are gathered for all the
/// signals
/// and ranked increasingly. We take the middle bin and substract its values to
/// and ranked increasingly. We take the middle bin and subtract its values to
/// all the bins corresponding to that time.
///
/// * **Mode = 1**: The method is exactly the same but we take into account
Expand Down
2 changes: 1 addition & 1 deletion src/TRestRawMultiCoBoAsAdToSignalProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ TRestEvent* TRestRawMultiCoBoAsAdToSignalProcess::ProcessEvent(TRestEvent* input
signal.Initialize();
signal.SetSignalID(m + data->asadId * 272);

for (int j = 0; j < 512; j++) signal.AddPoint((Short_t)data->data[m][j]);
for (int j = 0; j < 512; j++) signal.AddPoint((UShort_t)data->data[m][j]);

fSignalEvent->AddSignal(signal);

Expand Down
2 changes: 1 addition & 1 deletion src/TRestRawMultiFEMINOSToSignalProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ Bool_t TRestRawMultiFEMINOSToSignalProcess::ReadFrame(void* fr, int fr_sz) {
if (showSamples > 0) printf("ReadFrame: %03d 0x%04x (%4d)\n", si, r0, r0);
showSamples--;
}
if (sgnl.GetSignalID() >= 0) sgnl.AddPoint((Short_t)r0);
if (sgnl.GetSignalID() >= 0) sgnl.AddPoint((UShort_t)r0);
p++;
si++;
}
Expand Down
42 changes: 21 additions & 21 deletions src/TRestRawSignal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,26 @@ void TRestRawSignal::Reset() {
///////////////////////////////////////////////
/// \brief Adds a new point to the end of the signal data array
///
void TRestRawSignal::AddPoint(Short_t d) { fSignalData.push_back(d); }
void TRestRawSignal::AddPoint(UShort_t d) { fSignalData.push_back(d); }

///////////////////////////////////////////////
/// \brief Adds a new point to the end of the signal data array. Same as
/// AddPoint.
///
void TRestRawSignal::AddCharge(Short_t d) { AddPoint(d); }
void TRestRawSignal::AddCharge(UShort_t d) { AddPoint(d); }

///////////////////////////////////////////////
/// \brief Adds a new point to the end of the signal data array. Same as
/// AddPoint.
///
void TRestRawSignal::AddDeposit(Short_t d) { AddPoint(d); }
void TRestRawSignal::AddDeposit(UShort_t d) { AddPoint(d); }

///////////////////////////////////////////////
/// \brief It overloads the operator [] so that we can retrieve a particular
/// point *n* in the form
/// rawSignal[n].
///
Short_t TRestRawSignal::operator[](Int_t n) {
UShort_t TRestRawSignal::operator[](Int_t n) {
if (n >= GetNumberOfPoints()) {
if (fShowWarnings) {
std::cout << "TRestRawSignal::GetSignalData: outside limits" << endl;
Expand All @@ -160,7 +160,7 @@ Short_t TRestRawSignal::operator[](Int_t n) {
///////////////////////////////////////////////
/// \brief It returns the data value of point *n* including baseline correction.
///
/// This method will substract the internal value of fBaseLine that is extracted
/// This method will subtract the internal value of fBaseLine that is extracted
/// from the existing data points
/// after calling the method CalculateBaseLine. If CalculateBaseLine has not
/// been called previously, this
Expand Down Expand Up @@ -538,7 +538,7 @@ Bool_t TRestRawSignal::IsADCSaturation(int Nflat) {
if (Nflat <= 0) return false;
// GetMaxPeakBin() will always find the first max peak bin if multiple bins are in same max value.
int index = GetMaxPeakBin();
Short_t value = fSignalData[index];
UShort_t value = fSignalData[index];

bool sat = false;
if (index + Nflat <= (int)fSignalData.size()) {
Expand Down Expand Up @@ -573,7 +573,7 @@ void TRestRawSignal::GetDifferentialSignal(TRestRawSignal* diffSignal, Int_t sme
for (int i = smearPoints; i < this->GetNumberOfPoints() - smearPoints; i++) {
Double_t value = 0.5 * (this->GetData(i + smearPoints) - GetData(i - smearPoints)) / smearPoints;

diffSignal->AddPoint((Short_t)value);
diffSignal->AddPoint((UShort_t)value);
}

for (int i = GetNumberOfPoints() - smearPoints; i < GetNumberOfPoints(); i++) diffSignal->AddPoint(0);
Expand All @@ -594,7 +594,7 @@ void TRestRawSignal::GetWhiteNoiseSignal(TRestRawSignal* noiseSignal, Double_t n
TRandom3* fRandom = new TRandom3(seed);

for (int i = 0; i < GetNumberOfPoints(); i++) {
noiseSignal->AddPoint(this->GetData(i) + (Short_t)fRandom->Gaus(0, noiseLevel));
noiseSignal->AddPoint(this->GetData(i) + (UShort_t)fRandom->Gaus(0, noiseLevel));
}
delete fRandom;
}
Expand All @@ -613,12 +613,12 @@ void TRestRawSignal::GetSignalSmoothed(TRestRawSignal* smoothedSignal, Int_t ave

Double_t sumAvg = GetIntegralInRange(0, averagingPoints) / averagingPoints;

for (int i = 0; i <= averagingPoints / 2; i++) smoothedSignal->AddPoint((Short_t)sumAvg);
for (int i = 0; i <= averagingPoints / 2; i++) smoothedSignal->AddPoint((UShort_t)sumAvg);

for (int i = averagingPoints / 2 + 1; i < GetNumberOfPoints() - averagingPoints / 2; i++) {
sumAvg -= this->GetRawData(i - (averagingPoints / 2 + 1)) / averagingPoints;
sumAvg += this->GetRawData(i + averagingPoints / 2) / averagingPoints;
smoothedSignal->AddPoint((Short_t)sumAvg);
smoothedSignal->AddPoint((UShort_t)sumAvg);
}

for (int i = GetNumberOfPoints() - averagingPoints / 2; i < GetNumberOfPoints(); i++)
Expand Down Expand Up @@ -752,10 +752,10 @@ void TRestRawSignal::CalculateBaseLineMedian(Int_t startBin, Int_t endBin) {
<< endl;
endBin = fSignalData.size();
} else {
vector<Short_t>::const_iterator first = fSignalData.begin() + startBin;
vector<Short_t>::const_iterator last = fSignalData.begin() + endBin;
vector<Short_t> v(first, last);
const Short_t* signalInRange = &v[0];
vector<UShort_t>::const_iterator first = fSignalData.begin() + startBin;
vector<UShort_t>::const_iterator last = fSignalData.begin() + endBin;
vector<UShort_t> v(first, last);
const UShort_t* signalInRange = &v[0];
fBaseLine = TMath::Median(endBin - startBin, signalInRange);
}
}
Expand Down Expand Up @@ -806,12 +806,12 @@ void TRestRawSignal::CalculateBaseLineSigmaIQR(Int_t startBin, Int_t endBin) {
if (endBin - startBin <= 0) {
fBaseLineSigma = 0;
} else {
vector<Short_t>::const_iterator first = fSignalData.begin() + startBin;
vector<Short_t>::const_iterator last = fSignalData.begin() + endBin;
vector<Short_t> v(first, last);
vector<UShort_t>::const_iterator first = fSignalData.begin() + startBin;
vector<UShort_t>::const_iterator last = fSignalData.begin() + endBin;
vector<UShort_t> v(first, last);
std::sort(v.begin(), v.end());
Short_t Q1 = v[(int)(endBin - startBin) * 0.25];
Short_t Q3 = v[(int)(endBin - startBin) * 0.75];
UShort_t Q1 = v[(int)(endBin - startBin) * 0.25];
UShort_t Q3 = v[(int)(endBin - startBin) * 0.75];
Double_t IQR = Q3 - Q1;
fBaseLineSigma =
IQR / 1.349; // IQR/1.349 equals the standard deviation in case of normally distributed data
Expand All @@ -821,7 +821,7 @@ void TRestRawSignal::CalculateBaseLineSigmaIQR(Int_t startBin, Int_t endBin) {
///////////////////////////////////////////////
/// \brief This method adds an offset to the signal data
///
void TRestRawSignal::AddOffset(Short_t offset) {
void TRestRawSignal::AddOffset(UShort_t offset) {
if (fBaseLine != 0 || fBaseLineSigma != 0) fBaseLineSigma += (Double_t)offset;
for (int i = 0; i < GetNumberOfPoints(); i++) fSignalData[i] = fSignalData[i] + offset;
}
Expand All @@ -832,7 +832,7 @@ void TRestRawSignal::AddOffset(Short_t offset) {
void TRestRawSignal::Scale(Double_t value) {
for (int i = 0; i < GetNumberOfPoints(); i++) {
Double_t scaledValue = value * fSignalData[i];
fSignalData[i] = (Short_t)scaledValue;
fSignalData[i] = (UShort_t)scaledValue;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/TRestRawSignalAnalysisProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ TRestEvent* TRestRawSignalAnalysisProcess::ProcessEvent(TRestEvent* inputEvent)
// Keep in mind, to add raw signal analysis, we must write code at before
// This is where most of the problems occur
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Javier: I believe we should not substract baseline in the analysis process
// Javier: I believe we should not subtract baseline in the analysis process
// then ...
// ... of course we need to consider baseline substraction for each
// observable. TRestRawSignal methods
Expand All @@ -386,7 +386,7 @@ TRestEvent* TRestRawSignalAnalysisProcess::ProcessEvent(TRestEvent* inputEvent)
// Baseline substraction will always happen when we transfer a TRestRawSignal
// to TRestDetectorSignal
//
// We do not substract baselines then now, as it was done before
// We do not subtract baselines then now, as it was done before
//
// fSignalEvent->SubstractBaselines(fBaseLineRange.X(), fBaseLineRange.Y());
//
Expand Down
4 changes: 2 additions & 2 deletions src/TRestRawSignalEvent.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Double_t TRestRawSignalEvent::GetBaseLineSigmaAverage() {
// GetSignal(signal)->subtractBaseline();
//}

void TRestRawSignalEvent::AddChargeToSignal(Int_t signalID, Int_t bin, Short_t value) {
void TRestRawSignalEvent::AddChargeToSignal(Int_t signalID, Int_t bin, UShort_t value) {
Int_t signalIndex = GetSignalIndex(signalID);
if (signalIndex == -1) {
signalIndex = GetNumberOfSignals();
Expand Down Expand Up @@ -608,7 +608,7 @@ TPad* TRestRawSignalEvent::DrawEvent(const TString& option) {
///
void TRestRawSignalEvent::DrawSignals(TPad* pad, const std::vector<Int_t>& signals) {
int maxSID = -1;
int max = numeric_limits<Short_t>::min();
int max = numeric_limits<UShort_t>::min();
int graphIndex = 1;

for (const auto& s : signals) {
Expand Down
6 changes: 3 additions & 3 deletions src/TRestRawSignalRangeReductionProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ TRestEvent* TRestRawSignalRangeReductionProcess::ProcessEvent(TRestEvent* inputE
} else if (newValue > fDigitizationOutputRange.Y()) {
newValue = fDigitizationOutputRange.Y();
}
const Short_t newValueDigitized = (Short_t)round(newValue);
const UShort_t newValueDigitized = (UShort_t)round(newValue);
signal.AddPoint(newValueDigitized);
}

Expand All @@ -114,8 +114,8 @@ void TRestRawSignalRangeReductionProcess::SetResolutionInNumberOfBits(UShort_t n
void TRestRawSignalRangeReductionProcess::SetDigitizationInputRange(const TVector2& range) {
fDigitizationInputRange = range;

const auto limitMin = std::numeric_limits<Short_t>::min();
const auto limitMax = std::numeric_limits<Short_t>::max();
const auto limitMin = std::numeric_limits<UShort_t>::min();
const auto limitMax = std::numeric_limits<UShort_t>::max();
if (range.X() < limitMin) {
RESTWarning << "TRestRawSignalRangeReductionProcess::SetDigitizationRange - user set start of "
"Digitization range to "
Expand Down
2 changes: 1 addition & 1 deletion src/TRestRawSignalShapingProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ TRestEvent* TRestRawSignalShapingProcess::ProcessEvent(TRestEvent* inputEvent) {
}

for (int i = 0; i < nBins; i++) {
shapingSignal.AddPoint((Short_t)round(out[i]));
shapingSignal.AddPoint((UShort_t)round(out[i]));
}
shapingSignal.SetSignalID(inSignal.GetSignalID());

Expand Down
2 changes: 1 addition & 1 deletion src/TRestRawTDSToSignalProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ TRestEvent* TRestRawTDSToSignalProcess::ProcessEvent(TRestEvent* evInput) {
if (fread((char*)&buffer[0], pulseDepth, 1, fInputBinFile) != 1) return nullptr;
totalBytesReaded += pulseDepth;
for (int j = 0; j < pulseDepth; j++) {
Short_t data = buffer[j];
UShort_t data = buffer[j];
if (negPolarity[i]) data *= -1; // Inversion in case pulses are negative
data += 128; // Add 128 since the oscilloscope range is [-128:128]
fSignalEvent->AddChargeToSignal(i, j, data);
Expand Down
2 changes: 1 addition & 1 deletion src/TRestRawUSTCToSignalProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ TRestEvent* TRestRawUSTCToSignalProcess::ProcessEvent(TRestEvent* inputEvent) {
sgnl.Initialize();
sgnl.SetSignalID(frame->signalId);
for (int j = 0; j < 512; j++) {
sgnl.AddPoint((Short_t)frame->dataPoint[j]);
sgnl.AddPoint((UShort_t)frame->dataPoint[j]);
}
fSignalEvent->AddSignal(sgnl);

Expand Down
4 changes: 2 additions & 2 deletions test/src/TRestRawSignalRangeReductionProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ TEST(TRestRawSignalRangeReductionProcess, Default) {

EXPECT_TRUE(process.GetResolutionInNumberOfBits() == 12);

EXPECT_TRUE(process.GetDigitizationInputRange().X() == numeric_limits<Short_t>::min());
EXPECT_TRUE(process.GetDigitizationInputRange().Y() == numeric_limits<Short_t>::max());
EXPECT_TRUE(process.GetDigitizationInputRange().X() == numeric_limits<UShort_t>::min());
EXPECT_TRUE(process.GetDigitizationInputRange().Y() == numeric_limits<UShort_t>::max());
}

TEST(TRestRawSignalRangeReductionProcess, FromRml) {
Expand Down