TRestRawSignalShapingProcess affecting energy distribution

REST version: v2.3.12
Commit: 0cf8f3c8 (2022-04-25 16:40:49 +0200)

Hi,
I have noticed that TRestRawSignalShapingProcess is affecting the energy of the processed event(which should not in my opinion)
I use gaus convolution in my case.

To test that, I generated simple RawSignal events with only one signal and only one time-bin (Dirac-like signal):
Screenshot from 2023-01-26 18-41-09

The amplitude of the signal corresponds to the total integral over DetectorSignal event. And initial events themselves I generated in restG4
Thus, when I look at the residual between primaryEnergy from G4analysis and FullIntegral from RawSignalAnalysis:

AnalysisTree->Draw("g4Ana_energyPrimary-sAna_FullIntegral >> h1")

it peaks at zero:
Screenshot from 2023-01-26 18-48-10

However, when I apply TRestRawSignalShapingProcess on my RawSignal events the residual b/w primaryEnergy and FullIntegral is shifted:
Screenshot from 2023-01-26 18-50-22

I don’t know why this is happening as the gaussian convolution in the code is being normalized to one and should not affect the total energy of the event:

/// It is the response function. Does not change from event ot event
    if (fShapingType == "gaus") {
        Int_t cBin = (Int_t)(fShapingTime * 3.5);
        Nr = 2 * cBin;
        Double_t sigma = fShapingTime;

        rsp = new double[Nr];
        for (int i = 0; i < Nr; i++) {
            rsp[i] = TMath::Exp(-0.5 * (i - cBin) * (i - cBin) / sigma / sigma);
            rsp[i] = rsp[i] / TMath::Sqrt(2 * M_PI) / sigma;
        }
***
/ Making sure that rsp integral is 1, and applying the gain
    Double_t sum = 0;
    for (int n = 0; n < Nr; n++) sum += rsp[n];
    for (int n = 0; n < Nr; n++) rsp[n] = rsp[n] * fShapingGain / sum;

    for (int n = 0; n < fInputSignalEvent->GetNumberOfSignals(); n++) {
        TRestRawSignal shapingSignal = TRestRawSignal();
        TRestRawSignal inSignal = *fInputSignalEvent->GetSignal(n);
        Int_t nBins = inSignal.GetNumberOfPoints();

        vector<double> out(nBins);
        for (int m = 0; m < nBins; m++) out[m] = 0;

        for (int m = 0; m < nBins; m++) {
            if (inSignal.GetData(m) >= 0) {
                if (fShapingType == "gaus") {
                    for (int n = -Nr / 2; m + n < nBins && n < Nr / 2; n++)
                        if (m + n >= 0) out[m + n] += rsp[n + Nr / 2] * inSignal.GetData(m);
                } else
                    for (int n = 0; m + n < nBins && n < Nr; n++) out[m + n] += rsp[n] * inSignal.GetData(m);
            }
        }

***


Thank you in advance for any help
Andrii

The problem was found:

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

        fOutputSignalEvent->AddSignal(shapingSignal);

When the point is added to the output raw signal, out[i] should be rounded

Now the residual b/w primaryEnergy and FullIntegral is peaking at zero
image

1 Like

Great ! Well spotted!

Please, could you create a PR at the rawlib repository to fix the issue?

1 Like