Skip to content

Commit 005a4c3

Browse files
committed
GLO: actual check if signal fit converged
1 parent eee1fee commit 005a4c3

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

Modules/GLO/include/GLO/Helpers.h

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

2424
#include <TF1.h>
2525
#include <TH1.h>
26+
#include <TFitResultPtr.h>
2627

2728
namespace o2::quality_control_modules::glo::helpers
2829
{
@@ -84,23 +85,41 @@ struct K0sFitter {
8485

8586
bool fit(TH1* h, bool add = false)
8687
{
87-
if (h->GetEntries() == 0) {
88-
ILOG(Warning, Devel) << "Cannot fit empty histogram: " << h->GetName() << ENDM;
88+
if (!h || h->GetEntries() == 0) {
89+
ILOG(Warning, Devel) << "Cannot fit empty histogram: "
90+
<< (h ? h->GetName() : "<null>") << ENDM;
8991
return false;
9092
}
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;
93+
94+
// --- First: background-only fit
95+
auto bgResult = h->Fit(mBackground.get(), "RNQS");
96+
if (bgResult.Get() == nullptr || bgResult->Status() != 0) {
97+
ILOG(Warning, Devel) << "Failed k0s background fit for histogram: "
98+
<< h->GetName()
99+
<< " (status=" << (bgResult ? bgResult->Status() : -1) << ")"
100+
<< ENDM;
94101
return false;
95102
}
103+
104+
// --- Initialize signal+background from background fit
96105
mSignalAndBackground->SetParameter(Parameters::Pol0, mBackground->GetParameter(Parameters::Pol0));
97106
mSignalAndBackground->SetParameter(Parameters::Pol1, mBackground->GetParameter(Parameters::Pol1));
98107
mSignalAndBackground->SetParameter(Parameters::Pol2, mBackground->GetParameter(Parameters::Pol2));
99108
mSignalAndBackground->SetParameter(Parameters::Amplitude, h->GetMaximum() - mBackground->Eval(mMassK0s));
100109
mSignalAndBackground->SetParameter(Parameters::Mass, mMassK0s);
101110
mSignalAndBackground->SetParameter(Parameters::Sigma, 0.005);
102-
mSignalAndBackground->SetParLimits(Parameters::Sigma, 1e-6, 1);
103-
h->Fit(mSignalAndBackground.get(), (add) ? "RMQ" : "RMQ0");
111+
mSignalAndBackground->SetParLimits(Parameters::Sigma, 1e-6, 1.0);
112+
113+
// --- Fit signal+background
114+
const std::string fitOpt = add ? "RMQS" : "RMQS0";
115+
auto sbResult = h->Fit(mSignalAndBackground.get(), fitOpt.c_str());
116+
if (sbResult.Get() == nullptr || sbResult->Status() != 0) {
117+
ILOG(Warning, Devel) << "Failed k0s signal+background fit for histogram: "
118+
<< h->GetName()
119+
<< " (status=" << (sbResult ? sbResult->Status() : -1) << ")"
120+
<< ENDM;
121+
return false;
122+
}
104123
return true;
105124
}
106125

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)