Skip to content

Commit 2766dcd

Browse files
authored
Update Helpers.h
1 parent 11563e6 commit 2766dcd

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

Modules/GLO/include/GLO/Helpers.h

Lines changed: 29 additions & 9 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,42 @@ 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;
89-
return false;
88+
if (!h || h->GetEntries() == 0) {
89+
ILOG(Warning, Devel) << "Cannot fit empty histogram: "
90+
<< (h ? h->GetName() : "<null>") << ENDM;
91+
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;
94-
return false;
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;
101+
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-
return h->Fit(mSignalAndBackground.get(), (add) ? "RMQ" : "RMQ0") == 0;
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+
}
123+
return true;
104124
}
105125

106126
auto getMass() const noexcept

0 commit comments

Comments
 (0)