10#include "ChiSqMap2D.h"
11#include "CorrFitFunc.h"
12#include "CorrFitPainter.h"
21#include <TVirtualPad.h>
25#include "../painters/FemtoCFPainter.h"
29 CorrFitGUI::CorrFitGUI(CorrFit* f, Int_t prec) :
30 TGMainFrame(gClient->GetRoot(), 350, 300 + 440), fFunc(f), fNormIndex(fFunc->GetParameterIndex(
"N")) {
31 const Int_t width = 350;
32 Int_t nparams = fFunc->GetParametersNo();
33 fInitalNorm = fFunc->GetParameter(fNormIndex);
34 fSliders =
new CorrFitParButton*[nparams];
36 Color_t col = f->GetLineColor();
37 TGHorizontalFrame* descFrame =
new TGHorizontalFrame(
this, width, 40);
38 TGLabel* lab11 =
new TGLabel(descFrame, f->ClassName());
39 TColor* color = gROOT->GetColor(col);
40 lab11->SetTextColor(color);
41 TGLabel* lab12 =
new TGLabel(descFrame, f->GetName());
42 descFrame->AddFrame(lab11,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 3, 4));
43 descFrame->AddFrame(lab12,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 3, 4));
44 AddFrame(descFrame,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 5, 5));
45 for (
int i = 0; i < nparams; i++) {
46 maxL = fFunc->GetParameterName(i).Length();
49 for (
int i = 0; i < nparams; i++) {
50 TString name = fFunc->GetParameterName(i);
51 if (name.Length() < maxL) {
52 for (
int j = name.Length(); j < maxL; j++) {
56 fSliders[i] =
new CorrFitParButton(
this, 200, 40);
57 fSliders[i]->Init(
this, name, fFunc->GetParamConf(i));
58 fSliders[i]->SetPrecission(prec);
61 TGHorizontalFrame* autonormframe =
new TGHorizontalFrame(
this, width, 40);
62 fAutoNorm =
new TGCheckButton(autonormframe,
"Autonorm");
63 fAutoNorm->SetOn(kTRUE);
64 fAutoNorm->Connect(
"Clicked()", this->ClassName(),
this,
"ApplyParams()");
66 TGTextButton* round1 =
new TGTextButton(autonormframe,
"&Round 1");
67 autonormframe->AddFrame(round1,
new TGLayoutHints(kLHintsLeft, 5, 5, 3, 4));
68 round1->Connect(
"Clicked()", this->ClassName(),
this,
"Round(=1)");
70 TGTextButton* round2 =
new TGTextButton(autonormframe,
"&Round 2");
71 autonormframe->AddFrame(round2,
new TGLayoutHints(kLHintsLeft, 5, 5, 3, 4));
72 round2->Connect(
"Clicked()", this->ClassName(),
this,
"Round(=2)");
74 TGTextButton* round3 =
new TGTextButton(autonormframe,
"&Round 3");
75 autonormframe->AddFrame(round3,
new TGLayoutHints(kLHintsLeft, 5, 5, 3, 4));
76 round3->Connect(
"Clicked()", this->ClassName(),
this,
"Round(=3)");
79 autonormframe->AddFrame(fAutoNorm,
new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5));
80 AddFrame(autonormframe,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 5, 5));
82 TGHorizontalFrame* legendFrame =
new TGHorizontalFrame(
this, width, 40);
83 TGLabel* lab1 =
new TGLabel(legendFrame,
"Par. Name");
84 TGLabel* lab2 =
new TGLabel(legendFrame,
"Min");
85 TGLabel* lab3 =
new TGLabel(legendFrame,
"Max");
86 TGLabel* lab4 =
new TGLabel(legendFrame,
"Steps");
87 legendFrame->AddFrame(lab1,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 3, 4));
88 legendFrame->AddFrame(lab2,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 3, 4));
89 legendFrame->AddFrame(lab3,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 3, 4));
90 legendFrame->AddFrame(lab4,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 3, 4));
92 AddFrame(legendFrame,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 5, 5));
95 fPairChi1 =
new CorrFitChiSelector(
this, width, 100);
96 fPairChi2 =
new CorrFitChiSelector(
this, width, 100);
97 fPairChi1->Init(
this, fFunc);
98 fPairChi2->Init(
this, fFunc);
100 TGHorizontalFrame* chiFrame =
new TGHorizontalFrame(
this, width, 40);
101 fChiMin =
new TGCheckButton(chiFrame,
"Draw Chi min");
102 fChiMin->SetOn(kFALSE);
103 fChiLogz =
new TGCheckButton(chiFrame,
"Draw Chi logZ");
104 fChiLogz->SetOn(kFALSE);
105 fChiFit =
new TGCheckButton(chiFrame,
"Draw Fit par");
106 fChiFit->SetOn(kTRUE);
107 chiFrame->AddFrame(fChiMin,
new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5));
108 chiFrame->AddFrame(fChiLogz,
new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5));
109 chiFrame->AddFrame(fChiFit,
new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5));
110 AddFrame(chiFrame,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 5, 5));
112 TGHorizontalFrame* applyFrame =
new TGHorizontalFrame(
this, width, 40);
113 TGTextButton* draw =
new TGTextButton(applyFrame,
"&Draw chi");
114 applyFrame->AddFrame(draw,
new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
115 draw->Connect(
"Clicked()", this->ClassName(),
this,
"DrawChi2()");
116 TGTextButton* exit =
new TGTextButton(applyFrame,
"&Exit",
"gApplication->Terminate(0)");
117 applyFrame->AddFrame(exit,
new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
118 AddFrame(applyFrame,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 5, 5));
119 SetCleanup(kDeepCleanup);
120 SetWindowName(
"CorrFit GUI");
122 Resize(width + 1, nparams * 40 + 240);
126 void CorrFitGUI::ApplyParams() {
127 for (
int i = 0; i < fFunc->GetParametersNo(); i++) {
128 fFunc->OverwriteParam(i, fSliders[i]->GetValue());
129 fFunc->fTempParamsEval[i] = fSliders[i]->GetValue();
133 auto func =
dynamic_cast<CorrFitFunc*
>(fFunc);
134 Double_t normScale = fFunc->fTempParamsEval[fNormIndex];
135 if (normScale == 0) { normScale = 1; }
137 if (func->GetPainter()) {
139 if (fAutoNorm->IsOn()) {
140 func->GetPainter()->SetOption(
"norm+keep");
141 cf_painter->Rescale(1.0 / normScale);
143 func->GetPainter()->SetOption(
"!norm+keep");
144 cf_painter->Rescale(1.0);
151 CorrFitGUI::~CorrFitGUI() { Cleanup(); }
153 CorrFitParButton::CorrFitParButton(
const TGWindow* p, UInt_t w, UInt_t h, UInt_t options, Pixel_t back) :
154 TGHorizontalFrame(p, w, h, options, back), fNumberEntry(nullptr), fComboBox(nullptr), fDiscrete(kFALSE) {}
156 void CorrFitParButton::Init(CorrFitGUI* gui, TString parName, FitParam parConf) {
157 fDiscrete = parConf.IsDiscrete();
158 SetLayoutManager(
new TGHorizontalLayout(
this));
160 TGHorizontalFrame* rightLabel =
new TGHorizontalFrame(
this);
162 TGHorizontalFrame* leftLabel =
new TGHorizontalFrame(
this);
164 TGLabel* label =
new TGLabel(leftLabel, parName);
165 if (parConf.IsFixed()) {
166 label->SetTextColor(
new TColor(255, 0, 0));
168 label->SetTextColor(
new TColor(0, 0, 0));
170 label->SetMinWidth(100);
171 leftLabel->AddFrame(label,
new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
176 Hal::Std::Discretize(parConf.GetNPoints(), parConf.GetMapMin(), parConf.GetMapMax(), parConf.GetFittedValue(),
'=');
179 for (Double_t a = parConf.GetMapMin(); a <= parConf.GetMapMax(); a += parConf.GetDParam()) {
181 if (a == val) par_sec = entry;
185 fComboBox =
new TGComboBox(rightLabel);
186 for (
unsigned int i = 0; i < fSteps.size(); i++) {
187 fComboBox->AddEntry(Form(
"%4.3f", fSteps[i]), i);
189 fComboBox->Resize(70, 20);
190 fComboBox->Select(par_sec);
192 fComboBox->Connect(
"Selected(Int_t)", gui->ClassName(), gui,
"ApplyParams()");
193 rightLabel->AddFrame(fComboBox,
new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5));
194 this->AddFrame(leftLabel,
new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
195 this->AddFrame(rightLabel,
new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
196 gui->AddFrame(
this,
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5));
198 fNumberEntry =
new TGNumberEntry(rightLabel,
199 parConf.GetFittedValue(),
202 TGNumberFormat::EStyle::kNESReal,
203 TGNumberFormat::EAttribute::kNEAAnyNumber,
204 TGNumberFormat::kNELLimitMinMax,
206 parConf.GetMapMax());
207 fNumberEntry->Connect(
"ValueSet(Long_t)", gui->ClassName(), gui,
"ApplyParams()");
208 rightLabel->AddFrame(fNumberEntry,
new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5));
209 this->AddFrame(leftLabel,
new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
210 this->AddFrame(rightLabel,
new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
211 gui->AddFrame(
this,
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5));
215 Double_t CorrFitParButton::GetValue() {
217 Int_t pos = fComboBox->GetSelected();
220 return fNumberEntry->GetNumber();
224 void CorrFitParButton::SetValue(Double_t val) {
225 if (!fDiscrete) { fNumberEntry->SetNumber(val, kFALSE); }
227 void CorrFitParButton::SetPrecission(Int_t prec) {
228 TGNumberFormat::EStyle style = TGNumberFormat::EStyle::kNESReal;
229 if (prec == 1) style = TGNumberFormat::EStyle::kNESRealOne;
230 if (prec == 2) style = TGNumberFormat::EStyle::kNESRealTwo;
231 if (prec == 3) style = TGNumberFormat::EStyle::kNESRealThree;
233 if (!fDiscrete) {
return fNumberEntry->SetFormat(style, TGNumberFormat::EAttribute::kNEAAnyNumber); }
236 CorrFitChiSelector::CorrFitChiSelector(
const TGWindow* p, UInt_t w, UInt_t h, UInt_t options, Pixel_t back) :
237 TGHorizontalFrame(p, w, h, options, back), fParName(nullptr), fMin(nullptr), fMax(nullptr), fSteps(nullptr) {}
239 void CorrFitChiSelector::Init(CorrFitGUI* gui, CorrFit* f) {
240 fParName =
new TGComboBox(
this);
241 for (
int i = 0; i < f->GetParametersNo(); i++) {
242 fParName->AddEntry(f->GetParameterName(i), i);
244 fParName->Selected(0);
245 AddFrame(fParName,
new TGLayoutHints(kLHintsLeft | kLHintsCenterY | kLHintsExpandX, 5, 5, 5, 5));
246 fMin =
new TGNumberEntry(
this,
250 TGNumberFormat::EStyle::kNESReal,
251 TGNumberFormat::EAttribute::kNEAAnyNumber,
252 TGNumberFormat::kNELLimitMinMax,
255 this->AddFrame(fMin,
new TGLayoutHints(kLHintsTop | kLHintsCenterY | kLHintsExpandX, 5, 5, 5, 5));
256 fMax =
new TGNumberEntry(
this,
260 TGNumberFormat::EStyle::kNESReal,
261 TGNumberFormat::EAttribute::kNEAAnyNumber,
262 TGNumberFormat::kNELLimitMinMax,
265 this->AddFrame(fMax,
new TGLayoutHints(kLHintsTop | kLHintsCenterY | kLHintsExpandX, 5, 5, 5, 5));
266 fSteps =
new TGNumberEntry(
this,
270 TGNumberFormat::EStyle::kNESInteger,
271 TGNumberFormat::EAttribute::kNEAPositive,
272 TGNumberFormat::kNELLimitMinMax,
275 this->AddFrame(fSteps,
new TGLayoutHints(kLHintsTop | kLHintsCenterY | kLHintsExpandX, 5, 5, 5, 5));
276 fParName->Resize(70, 20);
277 gui->AddFrame(
this,
new TGLayoutHints(kLHintsCenterX, 5, 5, 5, 5));
280 void CorrFitChiSelector::GetValue(Int_t& par, Int_t& steps, Double_t& min, Double_t& max) {
281 par = fParName->GetSelected();
282 steps = fSteps->GetIntNumber();
283 min = fMin->GetNumber();
284 max = fMax->GetNumber();
287 void CorrFitGUI::DrawChi2() {
289 Int_t par1, par2, steps1, steps2;
290 Double_t min1, min2, max1, max2;
291 fPairChi1->GetValue(par1, steps1, min1, max1);
292 fPairChi2->GetValue(par2, steps2, min2, max2);
293 if (min1 > max1)
return;
294 if (min2 > max2)
return;
295 if (steps1 < 1 || steps2 < 1)
return;
296 ChiSqMap2D* chi =
static_cast<CorrFitFunc*
>(fFunc)->GetChiSquareMap(par1, steps1, min1, max1, par2, steps2, min2, max2);
298 TVirtualPad* pad = gPad;
299 TCanvas* c =
new TCanvas();
302 if (fChiMin->IsOn()) opt =
"min";
303 if (!fChiFit->IsOn()) {
304 if (opt.Length() == 0)
307 opt = opt +
"+nolin";
313 if (fChiLogz->IsOn()) { gPad->SetLogz(); }
315 for (
int ispe = 0; ispe < 2; ispe++) {
316 if (gSystem->ProcessEvents())
break;
322 void CorrFitGUI::SetParams() {
323 for (
int i = 0; i < fFunc->GetParametersNo(); i++) {
324 fFunc->OverwriteParam(i, fSliders[i]->GetValue());
328 void CorrFitGUI::Round(Int_t prec) {
329 Double_t x = TMath::Power(10, prec);
330 for (
int i = 0; i < fFunc->GetParametersNo(); i++) {
331 Double_t val = fSliders[i]->GetValue();
332 val = std::round(val * x) / x;
334 fSliders[i]->SetValue(val);