74 std::function<
double(
const std::vector<double> &,
const std::vector<double> &,
const std::vector<double> &)> ef)
84 std::vector<double> contents(h_template.size());
85 std::vector<double> errors(h_template.size());
89 for (
int i = min; i <= max; i++)
91 double BinContent = h_target->GetBinContent(i);
92 double BinError = pow(h_target->GetBinError(i), 2);
94 for (
size_t j = 0; j < h_template.size(); j++)
96 contents[j] = h_template[j]->GetBinContent(i);
97 errors[j] = h_template[j]->GetBinError(i);
100 if (use_user_defined_function)
107 for (
size_t j = 0; j < h_template.size(); j++)
109 BinContent -= vpara[j] * h_template[j]->GetBinContent(i);
110 BinError += pow(vpara[j] * h_template[j]->GetBinError(i), 2);
115 chi2 += BinContent * BinContent / BinError;
137 MSGUser()->StartTitle(
"TemplateFitter::SetTarget");
156 MSGUser()->StartTitle(
"TemplateFitter::SetTemplate");
164 sfmin.push_back(-999);
165 sfmax.push_back(-1000);
177 auto titleguard =
MSGUser()->StartTitleWithGuard(
"TemplateFitter::SetTemplate");
186 if (SFMIN < SFMAX && SF < SFMAX && SF > SFMIN)
188 sfmin.push_back(SFMIN);
189 sfmax.push_back(SFMAX);
193 MSGUser()->MSG_WARNING(
"Input scale factor range is wrong, brought back to default");
194 sfmin.push_back(-999);
195 sfmax.push_back(-1000);
206 std::function<
double(
const std::vector<double> &,
const std::vector<double> &,
const std::vector<double> &)> ef)
217 if (min <= max && min > 0)
224 MSGUser()->StartTitle(
"TemplateFitter::SetFitRange");
232 auto titleguard =
MSGUser()->StartTitleWithGuard(
"TemplateFitter::Check");
245 for (
size_t i = 0; i <
vh.size(); i++)
260 auto titleguard =
MSGUser()->StartTitleWithGuard(
"TemplateFitter::Fit");
271 ROOT::Minuit2::MnUserParameters upar;
272 for (
size_t i = 0; i <
sf.size(); i++)
275 name.Form(
"sf_%lu", i);
278 upar.Add(name.Data(),
sf[i], fabs(
sf[i] / 5));
290 ROOT::Minuit2::MnSimplex simplex(fcn, upar, 2);
291 auto minsimplex = simplex(1e6);
293 ROOT::Minuit2::MnMigrad migrad(fcn, minsimplex.UserState(), ROOT::Minuit2::MnStrategy(2));
294 auto minmigrad = migrad(1e6);
296 for (
size_t i = 0; i <
sf.size(); i++)
298 sf[i] = minmigrad.UserState().Value(i);
299 sferr[i] = minmigrad.UserState().Error(i);
301 chi2 = minmigrad.Fval();
308 if (i <
sf.size() && i >= 0)
314 MSGUser()->StartTitle(
"TemplateFitter::GetSF");
325 if (i <
sf.size() && i >= 0)
331 MSGUser()->StartTitle(
"TemplateFitter::GetSFError");
double operator()(const std::vector< double > &) const override
TemplateFitterFCN(TH1D *, const std::vector< TH1D * > &, int, int)
void SetRelation(std::function< double(const std::vector< double > &, const std::vector< double > &)>, std::function< double(const std::vector< double > &, const std::vector< double > &, const std::vector< double > &)>)
std::vector< TH1D * > h_template
double GetSF(uint64_t i)
Get the scale factors for ith template.
double GetChi2()
Get the fit .
std::vector< double > sfmin
void SetFitRange(int min, int max)
Set the fit range.
void Clear()
Clear this tool.
double GetSFError(uint64_t i)
Get the uncertainty of the scale factors for ith template.
void SetTarget(TH1D *h)
Set the target histogram.
void SetTemplate(TH1D *h, double SF=1, bool fix=false)
Set the template histogram.
std::vector< bool > isfixed
std::function< double(const std::vector< double > &, const std::vector< double > &, const std::vector< double > &)> errorfunction
std::function< double(const std::vector< double > &, const std::vector< double > &)> contentfunction
std::vector< double > sferr
void SetRelation(std::function< double(const std::vector< double > &, const std::vector< double > &)>, std::function< double(const std::vector< double > &, const std::vector< double > &, const std::vector< double > &)>)
Set the relation between the target histogram and the template histograms. if not called,...
std::vector< double > sfmax