KaliVeda
Toolkit for HIC analysis
rogly_fitting_function.h
1 #ifndef ROGLY_FITTING_FUNCTION_H
2 #define ROGLY_FITTING_FUNCTION_H
3 
4 #include "ipde_fit_parameter.h"
5 #include <TH1.h>
6 #include <vector>
7 #include "TRandom.h"
8 #include "KVNameValueList.h"
9 
10 namespace KVImpactParameters {
27  template<unsigned int PolyDegree>
29  ipde_fit_parameter theta_p;
30  ipde_fit_parameter kmax;
31  std::vector<ipde_fit_parameter> poly_param;
32 
33  public:
35  : poly_param(PolyDegree)
36  {}
38  : theta_p(prev_fit.theta_p), kmax(prev_fit.kmax), poly_param(PolyDegree)
39  {
40  poly_param = prev_fit.poly_param;
41  }
42  rogly_fitting_function(std::initializer_list<double> params)
43  : poly_param(PolyDegree)
44  {
51  int i = 0;
52  for (auto param : params) {
53  switch (i) {
54  case 0:
55  theta_p.value = param;
56  break;
57  case 1:
58  kmax.value = param;
59  break;
60  default:
61  poly_param[i - 2].value = param;
62  }
63  ++i;
64  }
65  }
66  constexpr int npar() const
67  {
69  return PolyDegree + 2;
70  }
71 
72  double k_cb(double cb) const
73  {
76  double kcb = 0;
77  for (unsigned int j = 1; j <= PolyDegree; ++j) kcb += poly_param[j - 1].value * pow(cb, j);
78  return kmax.value * TMath::Exp(-kcb);
79  }
80  void fill_params_from_array(double* p)
81  {
89  theta_p.value = p[0];
90  kmax.value = p[1];
91  for (unsigned int j = 1; j <= PolyDegree; ++j) poly_param[j - 1].value = p[j + 1];
92  }
93  void fill_array_from_params(double* p) const
94  {
102  p[0] = theta_p.value;
103  p[1] = kmax.value;
104  for (unsigned int j = 1; j <= PolyDegree; ++j) p[j + 1] = poly_param[j - 1].value ;
105  }
107  {
109 
111  l.SetValue("Theta", theta_p.value);
112  l.SetValue("kmax", kmax.value);
113  for (int j = 1; j <= PolyDegree; ++j) l.SetValue(Form("a_%d", j), poly_param[j - 1].value);
114  return l;
115  }
116  void set_par_names(TF1& f) const
117  {
120  f.SetParName(0, "#theta");
121  f.SetParName(1, "k_{max}");
122  for (unsigned int j = 1; j <= PolyDegree; ++j) f.SetParName(j + 1, Form("a_{%d}", j));
123  }
125  {
129  f.SetParameter(0, theta_p.value = 0.5);
130  f.SetParLimits(0, 0.1, 5);
131  double xmax = h->GetXaxis()->GetBinUpEdge(h->GetNbinsX());
132  double xmin = xmax / 7.;
133  f.SetParameter(1, kmax.value = (xmin * 2) / theta_p.value);
134  f.SetParLimits(1, xmin / theta_p.value, xmax / theta_p.value);
135  for (unsigned int j = 1; j <= PolyDegree; ++j) {
136  f.SetParameter(j + 1, gRandom->Uniform(-1, 1));
137  f.SetParLimits(j + 1, -5, 5);
138  }
139  }
140  void print_fit_params() const
141  {
142  std::cout << "Theta = ";
143  theta_p.print();
144  std::cout << "\n";
145  std::cout << "kmax = ";
146  kmax.print();
147  std::cout << "(Xmax = " << theta_p.value* kmax.value << ")";
148  std::cout << "\n";
149  for (unsigned int j = 1; j <= PolyDegree; ++j) {
150  std::cout << "a" << j << " = ";
151  poly_param[j - 1].print();
152  std::cout << " ";
153  }
154  std::cout << "\n";
155  }
157  {
159  theta_p.backup();
160  kmax.backup();
161  std::for_each(poly_param.begin(), poly_param.end(), [](ipde_fit_parameter & p) {
162  p.backup();
163  });
164  }
166  {
168  theta_p.restore();
169  kmax.restore();
170  std::for_each(poly_param.begin(), poly_param.end(), [](ipde_fit_parameter & p) {
171  p.restore();
172  });
173  }
175  {
179  kmax.value = 1;
180  }
181  double meanX(double cb) const
182  {
183  return theta_p.value * k_cb(cb);
184  }
185  double redVar(double) const
186  {
187  return theta_p.value;
188  }
189 
190  ClassDef(rogly_fitting_function, 0) //fit using exponential polynomial
191  };
192 }
193 
194 #endif // ROGLY_FITTING_FUNCTION_H
#define f(i)
#define ClassDef(name, id)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
float xmin
float xmax
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
Exponential function relating mean value of observable to centrality.
ipde_fit_parameter theta_p
fluctuation parameter
rogly_fitting_function(const rogly_fitting_function &prev_fit)
ipde_fit_parameter kmax
maximum of mean value for
rogly_fitting_function(std::initializer_list< double > params)
std::vector< ipde_fit_parameter > poly_param
polynomial coefficients
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
virtual Double_t GetBinUpEdge(Int_t bin) const
TAxis * GetXaxis()
virtual Int_t GetNbinsX() const
virtual Double_t Uniform(Double_t x1, Double_t x2)
RVec< PromoteTypes< T0, T1 > > pow(const T0 &x, const RVec< T1 > &v)
TH1 * h
Double_t Exp(Double_t x)
TLine l