11#include "CorrFitPainter.h"
18 CorrFit::CorrFit(Int_t parameters_no) :
22 fParametersNo(parameters_no),
25 fMinAlgo(kDefaultAlgo),
28 fParameters.resize(fParametersNo);
29 for (
int i = 0; i < fParametersNo; i++) {
30 fParameters[i].SetMapMin(-9999);
31 fParameters[i].SetMapMax(9999);
33 fTempParamsEval =
new Double_t[fParametersNo];
36 std::vector<TString> CorrFit::AlgoToOptions(EMinAlgo algo)
const {
38 std::vector<TString> res;
41 pattern =
"Minuit2:Migrad";
43 case kMinuitSimplex: {
44 pattern =
"Minuit2:Simplex";
46 case kMinuitCombined: {
47 pattern =
"Minuit2:Combined";
50 pattern =
"Minuit2:Scan";
53 pattern =
"Minuit2:Scan";
55 case kGLSMultiMinConjungateFR: {
56 pattern =
"GSLMultiMin:ConjugateFR";
58 case kGLSMultiMinConjugatePR: {
59 pattern =
"GSLMultiMin:ConjugatePR";
61 case kGLSMultiMinBFGS: {
62 pattern =
"GSLMultiMin:BFGS";
64 case kGLSMultiMinBFGS2: {
65 pattern =
"GSLMultiMin:BFGS2";
67 case kGLSMultiMinSteppestDescent: {
68 pattern =
"GSLMultiMin:SteepestDescent";
71 pattern =
"GSLMultiFit:";
74 pattern =
"GSLSimAn:";
77 pattern =
"Minuit2:Migrad";
80 pattern =
"HalMinimizer:Scan";
83 pattern =
"HalMinimizer:Ant";
85 case kHalScanMigrad: {
86 pattern =
"HalMinimizer:Scan:Minuit2:Migrad";
89 pattern =
"HalMinimizer:Scan:Minuit2:Migrad";
92 res = Hal::Std::ExplodeString(pattern,
':');
96 void CorrFit::ChangeParametersNo() {
97 fParameters.resize(fParametersNo);
98 delete[] fTempParamsEval;
99 fTempParamsEval =
new Double_t[fParametersNo];
102 void CorrFit::SetParLimits(Int_t par, Double_t min, Double_t max) {
103 if (par < fParametersNo && par >= 0) { fParameters[par].SetRange(min, max); }
106 void CorrFit::FixParameter(Int_t par, Double_t val) {
107 if (par < fParametersNo && par >= 0) { fParameters[par].SetRange(val, val); }
110 void CorrFit::SetParameterName(Int_t par, TString name) {
111 if (par >= 0 && par < fParametersNo) { fParameters[par].SetParName(name); }
114 Int_t CorrFit::GetParameterIndex(TString name)
const {
115 for (
int i = 0; i < fParametersNo; i++) {
116 if (fParameters[i].GetParName().EqualTo(name))
return i;
121 Bool_t CorrFit::IsParFixed(Int_t par)
const {
122 if (par >= 0 && par < fParametersNo) {
return fParameters[par].IsFixed(); }
126 Bool_t CorrFit::IsParDiscrete(Int_t par)
const {
127 if (par >= 0 && par < fParametersNo) {
return fParameters[par].IsDiscrete(); }
131 Double_t CorrFit::GetParMin(Int_t par)
const {
132 if (par >= 0 && par < fParametersNo)
return fParameters[par].GetMin();
136 Double_t CorrFit::GetParMax(Int_t par)
const {
137 if (par >= 0 && par < fParametersNo)
return fParameters[par].GetMax();
141 Double_t CorrFit::GetParameter(Int_t par)
const {
142 if (par >= 0 && par < fParametersNo) {
143 return fParameters[par].GetFittedValue();
149 Double_t CorrFit::GetParError(Int_t par)
const {
150 if (par >= 0 && par < fParametersNo) {
151 return fParameters[par].GetError();
157 void CorrFit::PrintFitResults()
const {
158 Cout::Text(Form(
"%s fit results", ClassName()),
"M", kWhite);
159 Cout::Database({
"ParName",
"Val",
"Err",
"Min",
"Max"});
160 for (
int i = 0; i < GetParametersNo(); i++) {
161 if (fParameters[i].IsFixed()) {
162 Cout::Database({GetParameterName(i), Form(
"%4.2f", GetParameter(i)),
"fixed",
"-",
"-"});
165 Cout::Database({GetParameterName(i),
166 Form(
"%4.2f", GetParameter(i)),
167 Form(
"%4.2f", GetParError(i)),
168 Form(
"%4.2f", GetParMin(i)),
169 Form(
"%4.2f", GetParMax(i))});
175 void CorrFit::CopyParamsToTF1(TF1* f, Bool_t numPar, Bool_t graphPar)
const {
177 for (
int i = 0; i < GetParametersNo(); i++) {
178 f->FixParameter(i, GetParameter(i));
179 f->SetParName(i, GetParameterName(i));
182 f->SetLineColor(GetLineColor());
183 f->SetLineStyle(GetLineStyle());
184 f->SetLineWidth(GetLineWidth());
188 CorrFit::~CorrFit() {
189 for (
auto f : fDrawFunc) {
190 if (f.first !=
nullptr) {
delete f.first; }
192 if (fPainter)
delete fPainter;
196 void CorrFit::SetErrorsNegative() {
197 for (
auto& i : fParameters)
201 void CorrFit::SetFitOrder(std::initializer_list<Int_t> order) {
202 auto vec = Hal::Std::GetVector(order);
203 if (
int(vec.size()) != fParametersNo) {
207 std::vector<bool> vals(fParametersNo,
false);
208 for (
unsigned int it = 0; it < vec.size(); it++) {
209 vals[vec[it]] =
true;
212 for (
auto i : vals) {
221 void CorrFit::CheckOrder() {
222 if (fFitOrder.size() == 0) {
223 fFitOrder.resize(fParametersNo);
224 for (
int i = 0; i < fParametersNo; i++) {
static void PrintInfo(TString text, Hal::EInfo status)