Skip to content

Commit

Permalink
using TGraph to fit
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajmz committed Jun 6, 2024
1 parent 16be349 commit 661e575
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/TRestDetectorSignal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,11 @@ TRestDetectorSignal::GetPeakGauss() // returns a 2vector with the time of the p
}

TF1 gauss("gaus", "gaus", lowerLimit, upperLimit);
TH1F h("h", "h", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1));

// copying the signal peak to a histogram
for (int i = 0; i < GetNumberOfPoints(); i++) {
h.SetBinContent(i + 1, GetData(i));
}
auto signal_graph = std::unique_ptr<TGraph>(GetGraph());

TFitResultPtr fitResult =
h.Fit(&gauss, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in
signal_graph->Fit(&gauss, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in
// the function range; S = save and return the fit result

if (!fitResult->IsValid()) {
Expand All @@ -337,7 +333,7 @@ TRestDetectorSignal::GetPeakGauss() // returns a 2vector with the time of the p

double energy = gauss.GetParameter(0);
double time = gauss.GetParameter(1);

return make_pair(time, energy);
}

Expand Down Expand Up @@ -372,15 +368,11 @@ TRestDetectorSignal::GetPeakLandau() // returns a 2vector with the time of the
}

TF1 landau("landau", "landau", lowerLimit, upperLimit);
TH1F h("h", "h", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1));

// copying the signal peak to a histogram
for (int i = 0; i < GetNumberOfPoints(); i++) {
h.SetBinContent(i + 1, GetData(i));
}

auto signal_graph = std::unique_ptr<TGraph>(GetGraph());

TFitResultPtr fitResult =
h.Fit(&landau, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in the function range;
signal_graph->Fit(&landau, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in the function range;
// S = save and return the fit result
if (!fitResult->IsValid()) {
return nullopt;
Expand Down Expand Up @@ -435,15 +427,11 @@ TRestDetectorSignal::GetPeakAget() // returns a 2vector with the time of the pe
}

TF1 aget("aget", agetResponseFunction, lowerLimit, upperLimit, 3); //
TH1F h("h", "h", GetNumberOfPoints(), GetTime(0), GetTime(GetNumberOfPoints() - 1));
aget.SetParameters(500, maxRawTime, 1.2);

// copying the signal peak to a histogram
for (int i = 0; i < GetNumberOfPoints(); i++) {
h.SetBinContent(i + 1, GetData(i));
}
auto signal_graph = std::unique_ptr<TGraph>(GetGraph());

TFitResultPtr fitResult = h.Fit(&aget, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in
TFitResultPtr fitResult = signal_graph->Fit(&aget, "QNRS"); // Q = quiet, no info in screen; N = no plot; R = fit in
// the function range; S = save and return the fit result

if (!fitResult->IsValid()) {
Expand Down

0 comments on commit 661e575

Please sign in to comment.