|
23 | 23 |
|
24 | 24 | #include <TF1.h> |
25 | 25 | #include <TH1.h> |
| 26 | +#include <TFitResult.h> |
| 27 | +#include <TFitResultPtr.h> |
26 | 28 |
|
27 | 29 | namespace o2::quality_control_modules::glo::helpers |
28 | 30 | { |
@@ -84,23 +86,41 @@ struct K0sFitter { |
84 | 86 |
|
85 | 87 | bool fit(TH1* h, bool add = false) |
86 | 88 | { |
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; |
89 | 92 | return false; |
90 | 93 | } |
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; |
94 | 102 | return false; |
95 | 103 | } |
| 104 | + |
| 105 | + // --- Initialize signal+background from background fit |
96 | 106 | mSignalAndBackground->SetParameter(Parameters::Pol0, mBackground->GetParameter(Parameters::Pol0)); |
97 | 107 | mSignalAndBackground->SetParameter(Parameters::Pol1, mBackground->GetParameter(Parameters::Pol1)); |
98 | 108 | mSignalAndBackground->SetParameter(Parameters::Pol2, mBackground->GetParameter(Parameters::Pol2)); |
99 | 109 | mSignalAndBackground->SetParameter(Parameters::Amplitude, h->GetMaximum() - mBackground->Eval(mMassK0s)); |
100 | 110 | mSignalAndBackground->SetParameter(Parameters::Mass, mMassK0s); |
101 | 111 | 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 | + } |
104 | 124 | return true; |
105 | 125 | } |
106 | 126 |
|
|
0 commit comments