Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
FitParam.cxx
1/*
2 * HalCorrFitParam.cxx
3 *
4 * Created on: 21 gru 2020
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "FitParam.h"
10
11#include "Std.h"
12
13#include <iostream>
14namespace Hal {
15 FitParam::FitParam() {}
16
17 void FitParam::Init() {
18 if (!IsDiscrete()) return;
19 if (fNPoint == 0) {
20 std::cout << " cannot have npoint = 0" << std::endl;
21 exit(0);
22 }
23 if (!IsMapSet()) {
24 if (fMin == fMax) {
25 SetMapRange(fMin, fMax, 1);
26 fDParam = 0;
27 } else {
28 SetMapRange(fMin, fMax, 100);
29 }
30 }
31 fDParam = (fMapMax - fMapMin) / Double_t(fNPoint - 1);
32 if (fNPoint == 1) fDParam = 0;
33 fMin = Hal::Std::Discretize(fNPoint - 1, fMapMin, fMapMax, fMin, '-'); // npoint -1 because we have n-1 areas than points
34 fMax = Hal::Std::Discretize(fNPoint - 1, fMapMin, fMapMax, fMax, '+');
35 fStart = Hal::Std::Discretize(fNPoint - 1, fMapMin, fMapMax, fStart, '=');
36 }
37
38 FitParam::~FitParam() {}
39
40 void FitParam::SetRange(Double_t min, Double_t max) {
41 if (min > max) {
42 Double_t temp = max;
43 max = min;
44 min = temp;
45 }
46 if (min == max) {
47 SetIsFixed(kTRUE);
48 } else {
49 SetIsFixed(kFALSE);
50 }
51 fMin = min;
52 fMax = max;
53 fStart = 0.5 * (min + max);
54 }
55
56 void FitParam::SetMapRange(Double_t min, Double_t max, Int_t points) {
57 if (points <= 1) SetIsFixed(kTRUE); // to not go into some infinite loops
58 if (min > max) {
59 Double_t temp = max;
60 max = min;
61 min = temp;
62 }
63 fMapMin = min;
64 fMapMax = max;
65 fNPoint = points;
66 fIsMapSet = kTRUE;
67 }
68
69 void FitParam::Print(Option_t* /*option*/) const {
70 std::cout << "PARAM " << GetParName() << std::endl;
71 TString disc = "no", fix = "no";
72 if (IsDiscrete()) disc = "yes";
73 if (IsFixed()) fix = "yes";
74 std::cout << "\tIsDiscrete: " << disc << "\tIsFixed: " << fix << std::endl;
75 std::cout << "\tStart val " << Form("%4.4f ", GetStartVal()) << std::endl;
76 std::cout << Form("\tLimits %4.4f - %4.4f ", GetMin(), GetMax()) << std::endl;
77 std::cout << "\tMap settings" << std::endl;
78 std::cout << Form("\tNPoints %i NDx %4.4f", GetNPoints(), GetDParam()) << std::endl;
79 std::cout << Form("\tMap Min: %4.4f Map Max: %4.4f", GetMapMin(), GetMapMax()) << std::endl;
80 std::cout << "\tValues ";
81 auto array = GetValuesArray();
82 for (unsigned int i = 0; i < array.size(); i++) {
83 std::cout << array[i] << " ";
84 }
85 std::cout << std::endl;
86 }
87
88 const std::vector<Double_t> FitParam::GetValuesArray() const {
89 std::vector<Double_t> values;
90 if (!IsDiscrete()) {
91 values.push_back(fMin);
92 return values;
93 }
94 if (IsFixed() || fDParam == 0) {
95 values.push_back(fMin);
96 } else {
97 for (double x = fMin; x <= fMax; x += fDParam) {
98 values.push_back(x);
99 }
100 }
101 return values;
102 }
103
104} // namespace Hal