Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
MinimizerStepConf.cxx
1/*
2 * MinimizerStepConf.cxx
3 *
4 * Created on: 22 sie 2022
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "MinimizerStepConf.h"
10
11#include "Cout.h"
12#include "XMLNode.h"
13
14#include <TMath.h>
15#include <iostream>
16
17namespace Hal {
18
19 MinimizerStepConf::MinimizerStepConf() {}
20
21 MinimizerStepConf::~MinimizerStepConf() {}
22
23 void MinimizerStepConf::ConfigureParameter(TString name, Double_t step, Double_t min, Double_t max, TString /*option*/) {
24 if (step <= 0) step = 0.01;
25 if (min > max) {
26 Double_t temp = min;
27 min = max;
28 max = temp;
29 }
30
31 Int_t points = 1 + (int) TMath::Ceil((max - min) / step); //+1 to take max
32 Bool_t created = kFALSE;
33 for (auto& iPar : fParams) {
34 if (iPar.GetParName().EqualTo(name)) {
35 iPar.SetMapRange(min, max, points);
36 iPar.SetIsDiscrete(kTRUE);
37 created = kTRUE;
38 }
39 }
40 if (!created) {
41 FitParam param;
42 param.SetParName(name);
43 param.SetIsDiscrete(kTRUE);
44 param.SetMapRange(min, max, points);
45 fParams.push_back(param);
46 }
47 }
48
49 void MinimizerStepConf::SetParameters(std::vector<FitParam>& input, Bool_t overwrite) const {
50 if (overwrite) {
51 input.clear();
52 for (auto iPar : fParams) {
53 FitParam par;
54 par.SetParName(iPar.GetParName());
55 par.SetMapRange(iPar.GetMapMin(), iPar.GetMapMax(), iPar.GetNPoints());
56 par.SetIsDiscrete(kTRUE);
57 input.push_back(par);
58 }
59 return;
60 }
61 for (auto iPar : fParams) {
62 for (auto& oPar : input) {
63 if (iPar.GetParName().EqualTo(oPar.GetParName())) {
64 oPar.SetMapRange(iPar.GetMapMin(), iPar.GetMapMax(), iPar.GetNPoints());
65 oPar.SetIsDiscrete(kTRUE);
66 }
67 }
68 }
69 }
70
71 MinimizerStepConf::MinimizerStepConf(const MinimizerStepConf& other, std::vector<int> order) {
72 std::cout << " > " << other.fParams.size() << " " << other.GetNParams() << std::endl;
73 if (order.size() != other.fParams.size()) {
74 Hal::Cout::PrintInfo(Form("Cannot configure MinimizerStepConf::MinimizerStepConf conf pars no: %i !=%i (order no)",
75 (int) other.fParams.size(),
76 (int) order.size()),
77 EInfo::kError);
78 return;
79 }
80 fParams.resize(other.fParams.size());
81 for (unsigned int i = 0; i < order.size(); i++) {
82 fParams[i] = other.fParams[order[i]];
83 }
84 }
85
86 void MinimizerStepConf::LoadFromXML(TString xmlFile) {
87 XMLFile file(xmlFile);
88 auto root = file.GetRootNode();
89 for (int i = 0; i < root->GetNChildren(); i++) {
90 auto child = root->GetChild(i);
91 TString name = child->GetName();
92 name.ToLower();
93 if (name == "param") {
94 auto minim = child->GetAttrib("min");
95 auto maxim = child->GetAttrib("max");
96 auto step = child->GetAttrib("step");
97 auto paramname = child->GetAttrib("name");
98 if (minim && maxim && name && step) {
99 double min_val = minim->GetValue().Atof();
100 double max_val = maxim->GetValue().Atof();
101 double dx = step->GetValue().Atof();
102 TString parname = paramname->GetValue();
103 std::cout << "CONFIG " << parname << " " << dx << " " << min_val << " " << max_val << std::endl;
104 ConfigureParameter(parname, dx, min_val, max_val, "");
105 }
106 }
107 }
108 }
109
110} /* namespace Hal */
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
void SetParameters(std::vector< FitParam > &input, Bool_t overwrite) const
void ConfigureParameter(TString name, Double_t step, Double_t min, Double_t max, TString option="")
void LoadFromXML(TString xmlFile)
XMLNode * GetRootNode() const
Definition XMLNode.h:180