Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CorrFitFunc.cxx
1/*
2 * CorrFit.cxx
3 *
4 * Created on: 08-04-2015
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "CorrFitFunc.h"
11
12#include "ChiSqMap2D.h"
13#include "CorrFitGUI.h"
14#include "CorrFitHDFunc.h"
15#include "CorrFitPainter.h"
16#include "Cout.h"
17#include "Femto1DCF.h"
18#include "Femto3DCF.h"
19#include "FemtoSHCF.h"
20#include "Minimizer.h"
21#include "Painter.h"
22#include "Splines.h"
23#include "Std.h"
24#include "StdString.h"
25
26#include <Math/Factory.h>
27#include <Math/Functor.h>
28#include <Math/Minimizer.h>
29#include <TAxis.h>
30#include <TF1.h>
31#include <TH1.h>
32#include <TH2.h>
33#include <TH3.h>
34#include <TLegend.h>
35#include <TLegendEntry.h>
36#include <TMath.h>
37#include <TMathBase.h>
38#include <TRegexp.h>
39#include <TVirtualPad.h>
40#include <fstream>
41#include <iostream>
42#include <string>
43#include <vector>
44
45
46namespace Hal {
47 CorrFitFunc::CorrFitFunc(Int_t nparams, Int_t dim) :
48 CorrFit(nparams),
49 fDim(dim),
50 fMaxIterations(10000),
51 fTolerance(0.001),
52 fActiveBins(0),
53 fTrace(kFALSE),
54 fOwnRangeMap(kFALSE),
55 fCF(nullptr),
56 fDenominatorHistogram(nullptr),
57 fNumeratorHistogram(nullptr),
58 fCorrelationFunctionHistogram(nullptr),
59 fMask(nullptr),
60 fHDMaps(nullptr) {
61 fChi[0] = fChi[1] = 0.0;
62 fKinematics = Femto::EKinematics::kLCMS;
64 for (int i = 0; i < fDim * 2; i++) {
65 if (i % 2 == 0)
66 fRange[i] = 0;
67 else
68 fRange[i] = 1;
69 }
70 }
71
72 Double_t CorrFitFunc::GetChiSquare(Option_t* opt) const {
73 TString option = opt;
74 if (option.EqualTo("fitted")) {
75 return fChi[0];
76 } else if (option.EqualTo("fitting")) {
77 return fChi[1];
78 }
79 return 0;
80 }
81
82 Double_t CorrFitFunc::GetChiNDF(Option_t* opt) const { return GetChiSquare(opt) / GetNDF(); }
83
84 void CorrFitFunc::SetRange(Double_t min, Double_t max) {
85 if (fDim == 1) {
86 fRange[0] = min;
87 fRange[1] = max;
88 }
89 if (fDim == 3) {
90 fRange[0] = fRange[2] = fRange[4] = min;
91 fRange[1] = fRange[3] = fRange[5] = max;
92 }
93 }
94
95 void CorrFitFunc::SetupFunction(TF1* f) const {
96 for (int i = 0; i < GetParametersNo(); i++) {
97 f->SetParName(i, fParameters[i].GetName());
98 if (fParameters[i].IsFixed()) {
99 f->FixParameter(i, fParameters[i].GetStartVal());
100 } else {
101 f->SetParLimits(i, fParameters[i].GetMin(), fParameters[i].GetMax());
102 }
103 }
104 f->SetRange(fRange.Get(0), fRange.Get(2), fRange.Get(4), fRange.Get(1), fRange.Get(3), fRange.Get(5));
105 }
106
108 fNDF = 0;
109 fChi[0] = 0;
110 fChi[1] = 0;
111 }
112
114 for (int i = 0; i < fDim; i++) {
115 if (fRange[2 * i] == fRange[2 * i + 1]) { // ranges on given axis are the same, fixing
116 switch (i) {
117 case 0: // one dim
118 fRange[0] = fCorrelationFunctionHistogram->GetXaxis()->GetXmin();
119 fRange[1] = fCorrelationFunctionHistogram->GetXaxis()->GetXmax();
120 break;
121 case 1: // two dims
122 fRange[2] = fCorrelationFunctionHistogram->GetYaxis()->GetXmin();
123 fRange[3] = fCorrelationFunctionHistogram->GetYaxis()->GetXmax();
124 break;
125 case 2: // three dims
126 fRange[4] = fCorrelationFunctionHistogram->GetZaxis()->GetXmin();
127 fRange[5] = fCorrelationFunctionHistogram->GetZaxis()->GetXmax();
128 break;
129 }
130 }
131 }
132 }
133
134 void CorrFitFunc::CalcError(const Double_t Num,
135 const Double_t NumErr,
136 const Double_t Den,
137 const Double_t DenErr,
138 Double_t& cf,
139 Double_t& cfe) const {
140 cf = Num / Den;
141 Double_t D2 = Den * Den;
142 cfe = TMath::Sqrt((NumErr * NumErr + Num * Num / D2 * DenErr) / D2);
143 }
144
146 ROOT::Math::Minimizer *min, *min2 = nullptr;
147 CheckOrder();
148 fNDF = CountNDF();
149 min = GetMinimizer1(fMinAlgo);
150 min2 = GetMinimizer2(fMinAlgo);
151 ROOT::Math::Functor f;
152 switch (fMinFunc) {
153 case kChi: f = ROOT::Math::Functor(this, &CorrFitFunc::FunctorChiTFD, GetParametersNo()); break;
154 case kChi2: f = ROOT::Math::Functor(this, &CorrFitFunc::FunctorChiTF, GetParametersNo()); break;
155 case kLog: f = ROOT::Math::Functor(this, &CorrFitFunc::FunctorLogTFD, GetParametersNo()); break;
156 default: f = ROOT::Math::Functor(this, &CorrFitFunc::FunctorChiTFD, GetParametersNo()); break;
157 }
158 min->SetFunction(f);
159 if (min2) min2->SetFunction(f);
160 min->Minimize();
161
162 if (min2) {
163 if (Hal::Cout::GetVerboseMode() <= Hal::EInfo::kInfo || fTrace) std::cout << "Switching to second minimizer " << std::endl;
164 const double* parameters_guess = min->X();
165 const double* errors_guess = min->Errors();
166 PrepareSecondMiminizer(min, parameters_guess, errors_guess);
167 SetParsOfMinimizer(min2);
168 min2->Minimize();
169 }
170
171 if (min2 == nullptr) min2 = min;
172
173 const double* parameters = min2->X();
174 const double* errors = min2->Errors();
175 /* MINOS ERROR ESTIMATION
176 if(true){
177 for(int ivar=0;ivar<GetParametersNo();ivar++){
178 double errLow, errUp;
179 min2->GetMinosError(ivar, errLow, errUp);
180 std::cout<<ivar<<"OE \t"<<errors[ivar]<<std::endl;
181 std::cout<<ivar<<"NE\t"<<TMath::Max(errLow,errUp)<<std::endl;
182 }
183
184 }
185 */
186 //=== COPY FROM NUMERICAL FUNCTION TO "FITTED" FUNCTION
187 for (int i = 0; i < GetParametersNo(); i++) {
188 int to = fFitOrder[i];
189 fParameters[to].SetFittedValue(parameters[i]);
190 fParameters[to].SetError(errors[i]);
191 fTempParamsEval[to] = parameters[i];
192 }
193
195 fChi[0] = GetChiTF(parameters);
196 }
197
199 CorrFitFunc::GetChiSquareMap(Int_t par1, Int_t par1_steps, Int_t par2, Int_t par2_steps, Bool_t scale, EMinFunc algo) const {
200 return GetChiSquareMap(par1,
201 par1_steps,
202 fParameters[par1].GetMin(),
203 fParameters[par1].GetMax(),
204 par2,
205 par2_steps,
206 fParameters[par1].GetMin(),
207 fParameters[par2].GetMax(),
208 scale,
209 algo);
210 }
211
213 Int_t par1_steps,
214 Double_t par1_min,
215 Double_t par1_max,
216 Int_t par2,
217 Int_t par2_steps,
218 Double_t par2_min,
219 Double_t par2_max,
220 Bool_t scale,
221 EMinFunc algo) const {
222 // TF1 *func = GetFittingFunction("TF");
223 auto testParam = [&](Int_t par, Int_t& step, Double_t& min, Double_t& max) {
224 auto& parval = fParameters[par];
225 min = Std::Discretize(parval.GetNPoints() - 1, parval.GetMapMin(), parval.GetMapMax(), min, '-');
226 max = Std::Discretize(parval.GetNPoints() - 1, parval.GetMapMin(), parval.GetMapMax(), max, '+');
227 if (min < parval.GetMapMin()) min = parval.GetMapMin();
228 if (max > parval.GetMapMax()) max = parval.GetMapMax();
229 double step_size = parval.GetDParam();
230 min -= step_size * 0.5;
231 max += step_size * 0.5;
232 step = std::round((max - min) / parval.GetDParam());
233 };
234
235
236 if (IsParDiscrete(par1)) { testParam(par1, par1_steps, par1_min, par1_max); }
237 if (IsParDiscrete(par2)) { testParam(par2, par2_steps, par2_min, par2_max); }
238
239 Double_t* params = new Double_t[GetParametersNo()];
240 TString var;
241 switch (algo) {
242 case kChi: var = "#chi^{2}_{den}"; break;
243 case kLog: var = "loglike"; break;
244 case kChi2: var = "#chi^{2}"; break;
245 }
246 TString title = var + "map";
247 if (scale) { title = var + " map (scaled)"; }
248 ChiSqMap2D* map = new ChiSqMap2D("chi_map", par1_steps, par1_min, par1_max, par2_steps, par2_min, par2_max);
249 map->SetParNames(fParameters[par1].GetParName(), fParameters[par2].GetParName());
250 Double_t bins, chi;
251 for (int i = 0; i < GetParametersNo(); i++) {
253 }
254 for (double i = 1; i <= par1_steps; i++) {
255 Double_t par1_val = map->GetHist()->GetXaxis()->GetBinCenter(i);
256 for (double j = 1; j <= par2_steps; j++) {
257 Double_t par2_val = map->GetHist()->GetYaxis()->GetBinCenter(j);
258 fTempParamsEval[par1] = par1_val;
259 fTempParamsEval[par2] = par2_val;
261 switch (algo) {
262 case kChi: {
263 chi = GetChiTFD(params);
264 } break;
265 case kChi2: {
266 chi = GetChiTF(params);
267 } break;
268 case kLog: {
269 chi = GetLogTFD(params);
270 } break;
271 default: chi = 0; break;
272 }
273 bins = fActiveBins - GetFreeParamsNo();
274 if (scale) {
275 // std::cout<<"SC "<<chi/bins<<std::endl;
276 map->GetHist()->SetBinContent(i, j, chi / bins);
277 } else {
278 // std::cout<<"NSC "<<chi<<std::endl;
279 map->GetHist()->SetBinContent(i, j, chi);
280 }
281 }
282 }
283 map->SetXFit(GetParameter(par1), GetParError(par1), GetParError(par1));
284 map->SetYFit(GetParameter(par2), GetParError(par2), GetParError(par2));
285 fTempParamsEval[par1] = GetParameter(par1);
286 fTempParamsEval[par2] = GetParameter(par2);
287 /*prevent root from drawing CF with current parameters*/
289 delete[] params;
290 return map;
291 }
292
293 CorrFitFunc::~CorrFitFunc() {
294 if (fMask) delete fMask;
295 if (fHDMaps) delete fHDMaps;
296 fDenominatorHistogram = nullptr;
299 if (fPainter) delete fPainter;
300 }
301
303 Int_t free = 0;
304 for (int i = 0; i < GetParametersNo(); i++) {
305 if (!IsParFixed(i)) free++;
306 }
307 return free;
308 }
309
310 double CorrFitFunc::FunctorChiTFD(const double* params) {
311 for (int i = 0; i < GetParametersNo(); i++)
312 fTempParamsEval[i] = params[i];
314 Double_t f = GetChiTFD(params);
315 if (fTrace) {
316 std::cout << "*** <ChiTFD> ***" << f << " / " << fActiveBins << std::endl;
317 for (int i = 0; i < GetParametersNo(); i++) {
318 std::cout << "\t" << GetParameterName(i) << Form("%4.5f", params[i]) << std::endl;
319 }
320 }
321 return f;
322 }
323
324 double CorrFitFunc::FunctorChiTF(const double* params) {
325 for (int i = 0; i < GetParametersNo(); i++)
326 fTempParamsEval[i] = params[i];
328 Double_t f = GetChiTF(params);
329 if (fTrace) {
330 std::cout << "*** <ChiTF> ***" << f << " / " << fActiveBins << std::endl;
331 for (int i = 0; i < GetParametersNo(); i++) {
332 std::cout << "\t" << GetParameterName(i) << Form("%4.5f", params[i]) << std::endl;
333 }
334 }
335 return f;
336 }
337
338 double CorrFitFunc::FunctorLogTFD(const double* params) {
339 for (int i = 0; i < GetParametersNo(); i++)
340 fTempParamsEval[i] = params[i];
342 Double_t f = GetLogTFD(params);
343 if (fTrace) {
344 std::cout << "*** <LogTFD> ***" << f << " / " << fActiveBins << std::endl;
345 for (int i = 0; i < GetParametersNo(); i++) {
346 std::cout << "\t" << GetParameterName(i) << Form("%4.5f", params[i]) << std::endl;
347 }
348 }
349 return f;
350 }
351
353 // calculate NDF
354 for (int i = 0; i < GetParametersNo(); i++) {
355 fParameters[i].SetError(0);
356 if (fParameters[i].IsFixed()) {
357 fParameters[i].SetFittedValue(fParameters[i].GetMin());
358 } else
359 fParameters[i].SetFittedValue(fParameters[i].GetStartVal());
360 fTempParamsEval[i] = fParameters[i].GetFittedValue();
361 }
362 }
363
364 Double_t CorrFitFunc::GetRangeMin(Int_t flag) const {
365 if (flag < fDim) return fRange.Get(flag * 2);
366 return 0;
367 }
368
369 Double_t CorrFitFunc::GetRangeMax(Int_t flag) const {
370 if (flag < fDim) return fRange.Get(flag * 2 + 1);
371 return 0;
372 }
373
376 min->SetTrace(fTrace);
377 min->Reset();
378 min->SetNDF(fNDF);
379 if (fMinAlgo == EMinAlgo::kHalAnt) {
380 min->SetMinimizerType("ant");
381 } else {
382 min->SetMinimizerType("scan");
383 }
384 for (int i = 0; i < GetParametersNo(); i++) {
385 auto Param = fParameters[fFitOrder[i]];
386 std::string name = Param.GetParName().Data();
387 if (Param.IsFixed()) {
388 min->SetFixedVariable(i, name, Param.GetStartVal());
389 } else {
390 Double_t lower = Param.GetMin();
391 Double_t upper = Param.GetMax();
392 min->SetLimitedVariable(i, name, 0.5 * (lower + upper), (upper - lower), lower, upper);
393 }
394 }
395 MinimizerStepConf conf(fDiscretteMinimzerConf, fFitOrder);
396 min->SetParamConf(conf, false);
397 }
398
399 void CorrFitFunc::Fit(TObject* histo) {
400 if (histo == fCF) {
401 Prepare();
402 } else {
403 fCF = histo;
404 PrepareRaw();
405 }
406 // checking ranges &other stuff
407 Check();
408 // set par names depending on frame
409 // init params
410 for (unsigned int i = 0; i < fParameters.size(); i++) {
411 fParameters[i].Init();
412 }
414 if (fMinAlgo == kDefaultAlgo) fMinAlgo = kMinuitScan;
416 }
417
418 void CorrFitFunc::FitDummy(TObject* histo) {
419 if (fCF != histo) {
420 fCF = histo;
421 PrepareRaw();
422 } else {
423 Prepare();
424 }
425 // checking ranges &other stuff
426 Check();
427 // set par names depending on frame
428 // init params
429 for (unsigned int i = 0; i < fParameters.size(); i++) {
430 fParameters[i].Init();
431 }
433 if (fMinAlgo == kDefaultAlgo) fMinAlgo = kMinuitScan;
435 }
436
437 void CorrFitFunc::PrepareRootMinimizer(ROOT::Math::Minimizer* min) const {
438 for (int i = 0; i < GetParametersNo(); i++) {
439 auto Param = fParameters[fFitOrder[i]];
440 if (Param.IsFixed()) {
441 if (TMath::IsNaN(Param.GetStartVal())) {
442 Cout::Text(Form(" Par No. %i Is Nan fixed parameter", fFitOrder[i]), "M", kRed);
443 }
444 min->SetFixedVariable(i, Param.GetParName().Data(), Param.GetStartVal());
445 } else {
446 if (TMath::IsNaN(Param.GetStartVal())) { Cout::Text(Form(" Par No. %i Is Nan parameter", fFitOrder[i]), "M", kRed); }
447 Double_t step = TMath::Max(Param.GetDParam(), (Param.GetMax() - Param.GetMin()) / 100.0);
448 min->SetLimitedVariable(i, Param.GetParName().Data(), Param.GetMin(), step, Param.GetMin(), Param.GetMax());
449 }
450 }
451 }
452
453 void CorrFitFunc::PreFit(TObject* histo, Double_t bins) {
454 if (histo == fCF) {
455 Prepare();
456 } else {
457 fCF = histo;
458 PrepareRaw();
459 }
460 // checking ranges &other stuff
461 Check();
462 // set par names depending on frame
463 // init params
464 for (unsigned int i = 0; i < fParameters.size(); i++) {
465 fParameters[i].Init();
466 }
468 if (fMinAlgo == kDefaultAlgo) fMinAlgo = kMinuitScan;
470 }
471
473 ROOT::Math::Minimizer* min = nullptr;
474 CheckOrder();
475 min = Minimizer::Instance();
476 static_cast<Minimizer*>(min)->SetMinimizerType("scan");
477 fNDF = CountNDF();
479 SetParsOfMinimizer(min);
480 auto minx = static_cast<Minimizer*>(min);
481 minx->SetNDF(fNDF);
482
483 ROOT::Math::Functor f;
484 switch (fMinFunc) {
485 case kChi: f = ROOT::Math::Functor(this, &CorrFitFunc::FunctorChiTFD, GetParametersNo()); break;
486 case kChi2: f = ROOT::Math::Functor(this, &CorrFitFunc::FunctorChiTF, GetParametersNo()); break;
487 case kLog: f = ROOT::Math::Functor(this, &CorrFitFunc::FunctorLogTFD, GetParametersNo()); break;
488 default: f = ROOT::Math::Functor(this, &CorrFitFunc::FunctorChiTFD, GetParametersNo()); break;
489 }
490 min->SetFunction(f);
491
492 min->Minimize();
493 const double* parameters = min->X();
494
495 if (bins == 0) {
496 for (int i = 0; i < GetParametersNo(); i++) {
497 if (!fParameters[i].IsFixed()) {
498 std::cout << "Estimated minimum of parameter " << fParameters[i].GetName() << " is " << Form("%4.4f", parameters[i]);
499 }
500 }
501 } else if (bins > 0) {
502 double scale = bins;
503 for (int i = 0; i < GetParametersNo(); i++) {
504 if (!fParameters[i].IsFixed()) {
505 FitParam p = minx->GetParConf(i);
506 p.Init();
507 double dx = p.GetDParam();
508 SetParLimits(i, parameters[i] - scale * dx, parameters[i] + scale * dx);
509 std::cout << "PRESCALED " << p.GetParName() << " " << (parameters[i] - scale * dx) << " "
510 << (parameters[i] + scale * dx) << std::endl;
511 }
512 }
513 } else if (bins < 0) {
514 for (int i = 0; i < GetParametersNo(); i++) {
515 if (!fParameters[i].IsFixed()) {
516 FitParam p = minx->GetParConf(i);
517 p.Init();
518 double dx = p.GetDParam();
519 SetParLimits(i, parameters[i] - dx, parameters[i] + dx);
521 double npoints = dx / bins + 1;
522 conf.ConfigureParameter(p.GetParName(), npoints, parameters[i] - dx, parameters[i] + dx);
523 minx->SetParamConf(conf, false);
524 }
525 }
526 }
527 //=== COPY FROM NUMERICAL FUNCTION TO "FITTED" FUNCTION
528 for (int i = 0; i < GetParametersNo(); i++) {
529 int to = fFitOrder[i];
530 fParameters[to].SetFittedValue(parameters[i]);
531 // fParameters[to].SetError(errors[i]);
532 fTempParamsEval[to] = parameters[i];
533 }
534
536 fChi[0] = GetChiTF(parameters);
537 }
538
539 void CorrFitFunc::SetMinimizerConf(TString xmlFile) { fDiscretteMinimzerConf.LoadFromXML(xmlFile); }
540
541 void CorrFitFunc::MakeDummyXMLConfig(TString xmlFile) {
542 std::ofstream file(xmlFile);
543 file << "<minimizer>" << std::endl;
544 for (int i = 0; i < GetParametersNo(); i++) {
545 file << "<param name=\"" << GetParameterName(i) << "\" min=\"" << GetParMin(i) << "\" max=\"" << GetParMax(i)
546 << "\" step=\"0.01\"></param>" << std::endl;
547 }
548 file << "</minimizer>" << std::endl;
549 file.close();
550 }
551
552 void CorrFitFunc::Draw(Option_t* option) {
553 bool painter_set = true;
554 if (!fPainter) {
555 MakePainter(option);
556 painter_set = false;
557 if (fCF) { // we have our CF, and it was painted, let's link painter
558 /* HalCoutDebug("LINKING TO CF");
559 auto div = (Hal::DividedHisto1D*) fCF;
560 auto painter = (Hal::Painter*) div->GetSpecial("painter");
561 if (painter) {
562 painter->AddPainter(fPainter);
563 HalCoutDebug("LINKING TO CF");
564 } else
565 Hal::Cout::PrintInfo(
566 Form("%s %i, CF is present but there is not painter, call cf->Draw() before func->Draw()", __FILE__, __LINE__),
567 EInfo::kWarning);*/
568 }
569 }
570 fPainter->SetOption(option);
571 fPainter->Paint();
572 }
573
574 void CorrFitFunc::Repaint() {
575 if (!fPainter) {
576 Draw("skip");
577 return;
578 }
579 fPainter->Paint();
580
581#ifdef __APPLE__
582 for (int ispe = 0; ispe < 2; ispe++) {
583 if (gSystem->ProcessEvents()) break;
584 }
585#endif
586 }
587
588 void CorrFitFunc::SetParsOfMinimizer(ROOT::Math::Minimizer* min) const {
589 min->SetMaxFunctionCalls(fMaxIterations);
590 min->SetMaxIterations(fMaxIterations);
591 min->SetTolerance(fTolerance);
592 }
593
594 Int_t CorrFitFunc::CountNDF() const {
595 Int_t freeParameters = 0;
596 for (int i = 0; i < GetParametersNo(); i++) {
597 if (!fParameters[i].IsFixed()) freeParameters++;
598 }
599 return fActiveBins - freeParameters;
600 }
601
602 ROOT::Math::Minimizer* CorrFitFunc::GetMinimizer1(EMinAlgo algo) const {
603 auto algos = AlgoToOptions(fMinAlgo);
604 if (algos.size() < 2) algos.push_back("");
605 TString pat1 = algos[0];
606 TString pat2 = algos[1];
607 ROOT::Math::Minimizer* min = nullptr;
608 if (pat1.EqualTo("HalMinimizer")) {
609 min = Minimizer::Instance();
610 static_cast<Minimizer*>(min)->SetMinimizerType(pat2);
611 static_cast<Minimizer*>(min)->SetNDF(fNDF);
613 } else {
614 min = ROOT::Math::Factory::CreateMinimizer(pat1.Data(), pat2.Data());
616 }
617 SetParsOfMinimizer(min);
618 return min;
619 }
620
621 ROOT::Math::Minimizer* CorrFitFunc::GetMinimizer2(EMinAlgo algo) const {
622 auto algos = AlgoToOptions(fMinAlgo);
623 if (algos.size() <= 3) return nullptr;
624 TString pat1 = algos[2];
625 TString pat2 = algos[3];
626 ROOT::Math::Minimizer* min = nullptr;
627 if (pat1.EqualTo("HalMinimizer")) {
628 Hal::Cout::PrintInfo("You should not use hal minimizer as second minimizer", EInfo::kWarning);
629 min = Minimizer::Instance();
630 static_cast<Minimizer*>(min)->SetMinimizerType(pat2);
631 static_cast<Minimizer*>(min)->SetNDF(fNDF);
633 } else {
634 min = ROOT::Math::Factory::CreateMinimizer(pat1.Data(), pat2.Data());
636 }
637 SetParsOfMinimizer(min);
638 return min;
639 }
640
641 void CorrFitFunc::PrepareSecondMiminizer(ROOT::Math::Minimizer* min,
642 const double* parameters_guess,
643 const double* errors_guess) const {
644 for (int i = 0; i < GetParametersNo(); i++) {
645 auto Param = fParameters[fFitOrder[i]];
646 if (Param.IsFixed()) {
647 min->SetFixedVariable(i, Param.GetParName().Data(), Param.GetStartVal());
648 } else {
649 Double_t param = parameters_guess[i];
650 Double_t minpar = param - 3.0 * errors_guess[i];
651 Double_t maxpar = param + 3.0 * errors_guess[i];
652 minpar = TMath::Max(Param.GetMin(), minpar);
653 maxpar = TMath::Min(Param.GetMax(), maxpar);
654 Double_t step = (maxpar - minpar) * 0.1;
655 min->SetLimitedVariable(i, Param.GetParName().Data(), parameters_guess[i], step, minpar, maxpar);
656 if (Hal::Cout::GetVerboseMode() >= Hal::EInfo::kInfo)
657 std::cout << "Set limits " << Param.GetParName() << "\t"
658 << Form(" %4.4f+/-%4.4f", parameters_guess[i], 3.0 * errors_guess[i]) << std::endl;
659 }
660 }
661 }
662
663 Hal::CorrFitGUI* CorrFitFunc::StartGui(Int_t prec) { return new CorrFitGUI(this, prec); }
664
665} // namespace Hal
T Get(Int_t i) const
Definition Array.h:97
void MakeBigger(Int_t new_dim)
Definition Array.cxx:5
void SetParNames(TString xpar, TString ypar)
void SetXFit(Double_t Value, Double_t errLow=0, Double_t errHigh=-1)
TH2D * GetHist() const
Definition ChiSqMap2D.h:135
void SetYFit(Double_t Value, Double_t errLow=0, Double_t errHigh=-1)
TH1 * fDenominatorHistogram
virtual void PrepareRootMinimizer(ROOT::Math::Minimizer *minizer) const
Double_t fTolerance
Definition CorrFitFunc.h:89
double FunctorLogTFD(const double *params)
CorrFitPainter * fPainter
void ParametersChanged() const
virtual void PreFit(TObject *histo, Double_t bins=1)
void MakeDummyXMLConfig(TString xmlFile)
TH1 * fCorrelationFunctionHistogram
double FunctorChiTF(const double *params)
CorrFitHDFunc * fHDMaps
ChiSqMap2D * GetChiSquareMap(Int_t par1, Int_t par1_steps, Int_t par2, Int_t par2_steps, Bool_t scale=kTRUE, EMinFunc=kChi2) const
Double_t GetRangeMin(Int_t flag=0) const
void NumericalPreMinimization(Double_t bins)
void DummyNumericalFunction()
Femto::EKinematics fKinematics
Definition CorrFitFunc.h:69
virtual void Prepare()
Double_t fActiveBins
Definition CorrFitFunc.h:93
virtual void FitDummy(TObject *histo)
virtual void Fit(TObject *histo)
void NumericalMinimization()
Hal::CorrFitGUI * StartGui(Int_t prec=-1)
Double_t fChi[2]
Definition CorrFitFunc.h:77
virtual void EstimateActiveBins()=0
void SetupFunction(TF1 *f) const
CorrFitMask * fMask
Double_t GetChiNDF(Option_t *opt="fitted") const
virtual void PrepareHalMinimizer() const
virtual void MakePainter(TString options)=0
void CalcError(const Double_t Num, const Double_t NumErr, const Double_t Den, const Double_t DenErr, Double_t &cf, Double_t &cfe) const
void SetMinimizerConf(const MinimizerStepConf &conf)
void SetRange(Double_t min, Double_t max)
virtual void Check()
Int_t GetFreeParamsNo() const
double FunctorChiTFD(const double *params)
virtual void PrepareRaw()=0
const Int_t fDim
Definition CorrFitFunc.h:73
Double_t GetRangeMax(Int_t flag=0) const
CorrFitFunc(Int_t nparams=1, Int_t dim=1)
Array_1< Double_t > fRange
Definition CorrFitFunc.h:97
Double_t GetChiSquare(Option_t *opt="fitted") const
Double_t GetParError(Int_t par) const
Definition CorrFit.cxx:149
Int_t fNDF
Definition CorrFit.h:95
Int_t GetParametersNo() const
Definition CorrFit.h:269
TString GetParameterName(Int_t no) const
Definition CorrFit.h:280
Double_t GetParameter(Int_t par) const
Definition CorrFit.cxx:141
Double_t GetParMax(Int_t par) const
Definition CorrFit.cxx:136
Double_t GetParMin(Int_t par) const
Definition CorrFit.cxx:131
Bool_t IsParDiscrete(Int_t par) const
Definition CorrFit.cxx:126
Double_t * fTempParamsEval
Definition CorrFit.h:109
void CheckOrder()
Definition CorrFit.cxx:221
Double_t GetNDF() const
Definition CorrFit.h:264
void SetParLimits(Int_t par, Double_t min, Double_t max)
Definition CorrFit.cxx:102
std::vector< FitParam > fParameters
Definition CorrFit.h:103
Bool_t IsParFixed(Int_t par) const
Definition CorrFit.cxx:121
static void Text(TString text, TString option="L", Color_t color=-1)
Definition Cout.cxx:92
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
static Hal::EInfo GetVerboseMode()
Definition Cout.h:165
void ConfigureParameter(TString name, Double_t step, Double_t min, Double_t max, TString option="")
void LoadFromXML(TString xmlFile)
virtual bool SetFixedVariable(unsigned int ivar, const std::string &name, double val)
Definition Minimizer.cxx:40
static Minimizer * Instance()
virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double points, double lower, double upper)
Definition Minimizer.cxx:61
void Paint()
Definition Painter.cxx:42
virtual void SetOption(TString option)
Definition Painter.cxx:124