Skip to content

Commit 90159bb

Browse files
f3schknopers8
authored andcommitted
GLO: actual check if signal fit converged (#2607)
1 parent b69713d commit 90159bb

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

Modules/GLO/include/GLO/Helpers.h

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include <TF1.h>
2525
#include <TH1.h>
26+
#include <TFitResult.h>
27+
#include <TFitResultPtr.h>
2628

2729
namespace o2::quality_control_modules::glo::helpers
2830
{
@@ -84,23 +86,41 @@ struct K0sFitter {
8486

8587
bool fit(TH1* h, bool add = false)
8688
{
87-
if (h->GetEntries() == 0) {
88-
ILOG(Warning, Devel) << "Cannot fit empty histogram: " << h->GetName() << ENDM;
89+
if (!h || h->GetEntries() == 0) {
90+
ILOG(Warning, Devel) << "Cannot fit empty histogram: "
91+
<< (h ? h->GetName() : "<null>") << ENDM;
8992
return false;
9093
}
91-
Int_t res = h->Fit(mBackground.get(), "RNQ");
92-
if (res) {
93-
ILOG(Warning, Devel) << "Failed k0s background fit for histogram: " << h->GetName() << ENDM;
94+
95+
// --- First: background-only fit
96+
auto bgResult = h->Fit(mBackground.get(), "RNQS");
97+
if (bgResult.Get() == nullptr || bgResult->Status() != 0) {
98+
ILOG(Warning, Devel) << "Failed k0s background fit for histogram: "
99+
<< h->GetName()
100+
<< " (status=" << (bgResult ? bgResult->Status() : -1) << ")"
101+
<< ENDM;
94102
return false;
95103
}
104+
105+
// --- Initialize signal+background from background fit
96106
mSignalAndBackground->SetParameter(Parameters::Pol0, mBackground->GetParameter(Parameters::Pol0));
97107
mSignalAndBackground->SetParameter(Parameters::Pol1, mBackground->GetParameter(Parameters::Pol1));
98108
mSignalAndBackground->SetParameter(Parameters::Pol2, mBackground->GetParameter(Parameters::Pol2));
99109
mSignalAndBackground->SetParameter(Parameters::Amplitude, h->GetMaximum() - mBackground->Eval(mMassK0s));
100110
mSignalAndBackground->SetParameter(Parameters::Mass, mMassK0s);
101111
mSignalAndBackground->SetParameter(Parameters::Sigma, 0.005);
102-
mSignalAndBackground->SetParLimits(Parameters::Sigma, 1e-6, 1);
103-
h->Fit(mSignalAndBackground.get(), (add) ? "RMQ" : "RMQ0");
112+
mSignalAndBackground->SetParLimits(Parameters::Sigma, 1e-6, 1.0);
113+
114+
// --- Fit signal+background
115+
const std::string fitOpt = add ? "RMQS" : "RMQS0";
116+
auto sbResult = h->Fit(mSignalAndBackground.get(), fitOpt.c_str());
117+
if (sbResult.Get() == nullptr || sbResult->Status() != 0) {
118+
ILOG(Warning, Devel) << "Failed k0s signal+background fit for histogram: "
119+
<< h->GetName()
120+
<< " (status=" << (sbResult ? sbResult->Status() : -1) << ")"
121+
<< ENDM;
122+
return false;
123+
}
104124
return true;
105125
}
106126

Modules/GLO/src/ITSTPCmatchingCheck.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ void ITSTPCmatchingCheck::beautify(std::shared_ptr<MonitorObject> mo, Quality ch
527527
msg->AddText(Form("RError %.2f%%", rerr * 1e2));
528528
msg->SetFillColor(kGreen);
529529
}
530+
if (TF1* fit = h->GetFunction("gloFitK0sMassSignal"); fit != nullptr) {
531+
h->GetListOfFunctions()->Add(fit);
532+
}
530533
}
531534
h->GetListOfFunctions()->Add(msg);
532535
}

0 commit comments

Comments
 (0)