161 std::unique_ptr<TMinuit> gMinuit = std::make_unique<TMinuit>();
165 std::vector<double> pfit(
np, 0), errfit(
np, 0);
166 Double_t **
matrix =
new Double_t *[
np];
168 for (
int i = 0;
i <
np;
i++) {
170 for (
int j = 0; j <
np; j++)
matrix[
i][j] = 0.;
176 MuonFixedId fId(T0h.id);
179 if (T0h.id == 1 || T0h.id == 2 || (T0h.id > 10 && T0h.id <= 23)) isMultilayer = 1;
182 if ((fId.isValid() && fId.is_mdt()) || isMultilayer) {
183 if (
log.level() <= MSG::INFO)
log << MSG::INFO <<
" STARTING doTimeFit " <<
endmsg;
191 if (fitMezz == 1 && !isMultilayer) {
192 int hIdMezz = fId.mdtMezzanine();
194 std::string HistoId =
std::format(
"time_mezz_{:}", (hIdMezz) % (900000000));
206 T0ClassicHistos *histosMezz =
getHistos(fId.mdtMezzanine());
207 h = histosMezz->time.get();
214 log <<
MSG::VERBOSE <<
" histogram " <<
h->GetName() <<
" " <<
h->GetTitle() <<
" entries=" <<
h->GetEntries()
220 std::unique_ptr<TF1> FitFunction{
h->GetFunction(
"TimeSpectrum")};
222 for (
int i = 0;
i <
np;
i++) {
223 pfit[
i] = FitFunction->GetParameter(
i);
224 errfit[
i] = FitFunction->GetParError(
i);
226 chi2 = FitFunction->GetChisquare();
227 ndof = FitFunction->GetNDF();
229 std::unique_ptr<TF1> TimeSpectrum = std::make_unique<TF1>(
230 "TimeSpectrum",
"[0]+([1]*(1+[2]*exp(-(x-[4])/[3])))/((1+exp((-x+[4])/[6]))*(1+exp((x-[5])/[7]))) ",
232 for (
int i = 0;
i <
np;
i++) {
233 pfit[
i] = pdefault[
i];
235 log <<
MSG::DEBUG <<
"T0CalibrationClassic::doTimeFit initial parameters" <<
i <<
"=" << pfit[
i] <<
endmsg;
239 log <<
MSG::DEBUG <<
"T0CalibrationClassic::doTimeFit parameters after searchParams " <<
endmsg;
242 TimeSpectrum->SetParameters(pfit.data());
243 TimeSpectrum->SetParLimits(0, 0., 5.);
244 TimeSpectrum->SetParLimits(1, 0., 1000.);
245 TimeSpectrum->SetParLimits(2, 0., 40.);
246 TimeSpectrum->SetParLimits(3, 50., 400.);
247 TimeSpectrum->SetParLimits(4, 0., 1000.);
249 TimeSpectrum->SetParLimits(5, pfit[5], pfit[5]);
250 TimeSpectrum->SetParLimits(6, pfit[6], pfit[6]);
251 TimeSpectrum->SetParLimits(7, pfit[7], pfit[7]);
252 h->Fit(
"TimeSpectrum",
"QLB");
254 TimeSpectrum->SetParLimits(5, 500., 2000.);
255 TimeSpectrum->SetParLimits(6, pfit[6], pfit[6]);
256 TimeSpectrum->SetParLimits(7, pfit[7], pfit[7]);
257 h->Fit(
"TimeSpectrum",
"QLB");
259 TimeSpectrum->SetParLimits(6, 4., 30.);
260 h->Fit(
"TimeSpectrum",
"QLB");
262 TimeSpectrum->SetParLimits(6, 4., 30.);
263 TimeSpectrum->SetParLimits(7, 4., 30.);
264 double xmin =
h->GetBinLowEdge(1);
265 double xmax = pfit[5] + 250.;
266 h->Fit(
"TimeSpectrum",
"QLB",
"",
xmin,
xmax);
269 for (
int i = 0;
i <
np;
i++) {
270 pfit[
i] = TimeSpectrum->GetParameter(
i);
271 errfit[
i] = TimeSpectrum->GetParError(
i);
273 chi2 = TimeSpectrum->GetChisquare();
274 ndof = TimeSpectrum->GetNDF();
281 if (
chi2 / ndof < m_settings->chi2max()) {
288 for (
int i = 0;
i <
np;
i++)
fi.par[
i] = pfit[
i];
295 for (
int i = 0;
i <
np;
i++)
fi.cov[
i] = errfit[
i];