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

Use std::optional for peak fitting (which can fail) and other minor refactorings #120

Merged
merged 12 commits into from
Jun 6, 2024

Conversation

lobis
Copy link
Member

@lobis lobis commented May 31, 2024

lobis Ok: 89 Powered by Pull Request Badge

New we skip the peak if it's not being found, instead of returning energy -1

@lobis lobis requested review from jgalan, mariajmz and JPorron May 31, 2024 08:38
lobis added 3 commits May 31, 2024 11:19
* origin/lobis-option:
  [pre-commit.ci] auto fixes from pre-commit.com hooks

# Conflicts:
#	src/TRestDetectorSignal.cxx
@lobis lobis marked this pull request as ready for review May 31, 2024 09:34
@mariajmz
Copy link
Contributor

mariajmz commented Jun 3, 2024

Some examples of TRestDetectorSignalEvents analyzed with a macro using TRestDetectorSignal::GetPeakGauss():

void DrawEvent(TRestDetectorSignalEvent* event, TCanvas* canvas) {
    Int_t numberOfSignals = event->GetNumberOfSignals();
    std::cout << "Number of signals in event: " << numberOfSignals << std::endl;
    canvas->Clear();
    TPad* pad = event->DrawEvent();
    if (pad) {
        pad->SetCanvas(canvas);
        canvas->cd();
        pad->Draw();
        pad->cd();
    } else {
        std::cout << "Failed to draw event, pad is null." << std::endl;
    }
    
    for (int i = 0; i < numberOfSignals; i++) {
        TRestDetectorSignal* signal = event->GetSignal(i);
        std::optional<std::pair<Double_t, Double_t>> maxGaussOpt = signal->GetPeakGauss();
        if (maxGaussOpt) {
            auto maxGauss = maxGaussOpt.value();
            std::cout << "Max peak for signal " << i << " : " << maxGauss.first << " " << maxGauss.second << std::endl;
            TMarker* marker = new TMarker(maxGauss.first, maxGauss.second, 20);
            marker->SetMarkerColor(2);
            marker->Draw("same");
        }
    }

    canvas->Update();
}

20 ns of sampling time:
imagen
imagen

40 ns of sampling time:
imagen
The previous event, when I fit it with the method GetMaxGauss of mariajmz_fits branch, I get this:
imagen

Another event:
imagen

Also, I tried using gaussFit in TRestDetectorSignalToHitsProcess in a rml file with the same events and I get the usual errors when the fit fails:
imagen

Plotting the spectra (hitsAna_energy) with this branch and mariajmz_fits, they look similar:

This branch:
imagen

mariajmz_fits branch:
imagen

@lobis lobis changed the base branch from mariajmz_fits to master June 3, 2024 10:10
@lobis lobis requested a review from mariajmz June 6, 2024 08:15
@lobis lobis merged commit 79268d2 into master Jun 6, 2024
63 checks passed
@lobis lobis deleted the lobis-option branch June 6, 2024 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants