8#include "CorrFitPainter.h"
11#include <TVirtualPad.h>
14#include "CorrFitFunc.h"
16#include "FemtoCFPainter.h"
21 const int CorrFitPainter::kAutoNormBit = 8;
22 const int CorrFitPainter::kLegendBit = 9;
23 const int CorrFitPainter::kChi2 = 10;
24 const int CorrFitPainter::kChi2Short = 11;
25 CorrFitPainter::CorrFitPainter(CorrFitFunc* func) : Painter(), fFittedFunc(func) {
26 fNormIndex = fFittedFunc->GetParameterIndex(
"N");
29 void CorrFitPainter::ScaleFunctions() {
30 Int_t flag = CheckOpt(kAutoNormBit);
31 for (
auto x : fFunctions) {
33 if (y) { y->FixParameter(y->GetNpar() - 1, flag); }
38 void CorrFitPainter::DeleteFunctions() {
39 for (
auto x : fFunctions) {
46 void CorrFitPainter::MakeLegend() {
47 if (!CheckOpt(kLegendBit))
return;
49 fLegend =
new TLegend(fLegendPos[0], fLegendPos[1], fLegendPos[2], fLegendPos[3]);
50 fLegend->SetHeader(GetName());
51 if (fFittedFunc) { fLegend->SetHeader(fFittedFunc->GetName()); }
52 auto label = GetLegendLabels();
53 for (
auto str : label) {
54 fLegendEntries.push_back(fLegend->AddEntry((TObject*) 0x0, str,
""));
58 void CorrFitPainter::UpdateLegend() {
60 auto labels = GetLegendLabels();
61 for (
unsigned int i = 0; i < labels.size(); i++) {
62 TLegendEntry* ent = fLegendEntries[i];
63 ent->SetLabel(labels[i]);
64 ent->SetTextColor(kGreen);
66 fLegendPad->Modified(1);
70 CorrFitPainter::~CorrFitPainter() { DeleteFunctions(); }
72 void CorrFitPainter::InnerPaint() {
80 if (fLegendPad && CheckOpt(kLegendBit)) {
82 fLegend->Draw(
"SAME");
84 Painter::InnerPaint();
88 void CorrFitPainter::InnerRepaint() {
94 Painter::InnerRepaint();
98 void CorrFitPainter::DrawFunctions() {
101 for (
auto padfunc : fFunctions) {
103 for (
auto func : padfunc) {
104 if (func) { func->Draw(fDefFuncDrawOpt); }
110 ULong64_t CorrFitPainter::PrepBitTemplate(std::initializer_list<int> temps)
const {
112 auto vec = Hal::Std::GetVector(temps);
118 Bool_t CorrFitPainter::AreSimiliar(ULong64_t current, ULong64_t pattern)
const {
return pattern == current & pattern; }
120 ULong64_t CorrFitPainter::SetOptionInternal(TString opt, ULong64_t newFlag) {
121 ContitionalPattern(opt,
"norm", newFlag, kAutoNormBit, kTRUE);
122 if (Hal::Std::FindParam(opt,
"chi2s", kTRUE)) {
123 CLRBIT(newFlag, kChi2Short);
124 SETBIT(newFlag, kChi2);
126 if (Hal::Std::FindParam(opt,
"chi2", kTRUE)) {
127 SETBIT(newFlag, kChi2);
128 SETBIT(newFlag, kChi2Short);
130 if (Hal::Std::FindParam(opt,
"legend", kTRUE)) {
131 SETBIT(newFlag, kLegendBit);
132 auto bra = Hal::Std::FindBrackets(opt, kTRUE, kTRUE);
133 for (
auto pat : bra) {
134 std::vector<Double_t> vals;
135 if (GetPatterns(pat,
"leg", vals)) {
136 if (vals.size() == 4) {
137 for (
int i = 0; i < 4; i++)
138 fLegendPos[i] = vals[i];
146 std::vector<TString> CorrFitPainter::GetLegendLabels()
const {
147 std::vector<TString> label;
148 TString chi_label =
"";
149 if (CheckOpt(kChi2)) {
150 Double_t chi2 = fFittedFunc->GetChiTF(fFittedFunc->fTempParamsEval);
151 TString chi_s, chindf_s, ndf_s;
152 Double_t chi = fFittedFunc->GetChiSquare();
153 Double_t chindf = fFittedFunc->GetChiNDF();
154 Double_t ndf = fFittedFunc->GetNDF();
156 chi_s = Form(
"%4.3f", chi);
158 chi_s = Hal::Std::RoundToString(chi, 2,
"prefix");
159 if (chindf <= 1000) {
160 chindf_s = Form(
"%4.3f", chindf);
162 chindf_s = Hal::Std::RoundToString(chindf, 2,
"prefix");
165 ndf_s = Form(
"%i", (
int) ndf);
167 ndf_s = Hal::Std::RoundToString(ndf, 2,
"prefix");
169 if (CheckOpt(kChi2Short)) {
170 chi_label = Form(
"#chi^{2}/NDF %s (%s/%s)", chindf_s.Data(), chi_s.Data(), ndf_s.Data());
172 chi_label = Form(
"#chi^{2}/NDF %s", chindf_s.Data());
175 for (
int i = 0; i < fFittedFunc->GetParametersNo(); i++) {
176 if (fFittedFunc->IsParFixed(i)) {
177 label.push_back(Form(
178 "%s %4.3f (fixed)", fFittedFunc->fParameters[i].GetParName().Data(), fFittedFunc->fParameters[i].GetFittedValue()));
180 if (TMath::IsNaN(fFittedFunc->fParameters[i].GetError())) {
181 label.push_back(Form(
"%s %4.3f#color[2]{#pm%4.3f}",
182 fFittedFunc->fParameters[i].GetParName().Data(),
183 fFittedFunc->fParameters[i].GetFittedValue(),
184 fFittedFunc->fParameters[i].GetError()));
185 }
else if (fFittedFunc->fParameters[i].GetError() < 0) {
186 label.push_back(Form(
"%s %4.3f#color[16]{#pm%4.3f}",
187 fFittedFunc->fParameters[i].GetParName().Data(),
188 fFittedFunc->fParameters[i].GetFittedValue(),
189 fFittedFunc->fParameters[i].GetError()));
191 label.push_back(Form(
"%s %4.3f#pm%4.3f",
192 fFittedFunc->fParameters[i].GetParName().Data(),
193 fFittedFunc->fParameters[i].GetFittedValue(),
194 fFittedFunc->fParameters[i].GetError()));
198 if (chi_label.Length() > 0) label.push_back(chi_label);
203 void CorrFitPainter::ScaleHistograms() {
204 auto func = (CorrFitFunc*) fFittedFunc;
205 Double_t norm = func->GetNorm();
206 if (CheckOpt(kAutoNormBit)) {
207 fCFPainter->Rescale(1.0 / func->GetNorm());
208 fCFPainter->ScaleHistograms();