KaliVeda
Toolkit for HIC analysis
bayesian_estimator.h
1 
4 #ifndef __bayesian_estimator_H
5 #define __bayesian_estimator_H
6 
7 #include "KVBase.h"
8 #include "impact_parameter_distribution.h"
9 
10 #include <vector>
11 #include <numeric>
12 #include <TF2.h>
13 #include <TH1.h>
14 #include <TCanvas.h>
15 #include <TGraph.h>
16 #include <KVValueRange.h>
17 #include <KVNameValueList.h>
18 #include <TGraphErrors.h>
19 #include <TH2.h>
20 #include "TMath.h"
21 #include "TNamed.h"
22 
23 #include "Math/PdfFuncMathCore.h"
24 
25 namespace KVImpactParameters {
41  class gamma_kernel {
42  public:
43  double operator()(double X, double mean, double reduced_variance)
44  {
46  return ROOT::Math::gamma_pdf(X, mean / reduced_variance, reduced_variance);
47  }
48 
50  };
51 
67  class BD_kernel {
68  public:
69  double operator()(double X, double mean, double reduced_variance)
70  {
72  return ROOT::Math::binomial_pdf(TMath::Nint(X), 1. - reduced_variance, mean / (1. - reduced_variance));
73  }
74 
76  };
77 
93  class NBD_kernel {
94  public:
95  double operator()(double X, double mean, double reduced_variance)
96  {
98  return ROOT::Math::negative_binomial_pdf(TMath::Nint(X), 1. / reduced_variance, mean / (reduced_variance - 1.));
99  }
100 
101  ClassDef(NBD_kernel, 0)
102  };
103 
104 
219  template
220  <class FittingFunction, class FluctuationKernel>
221  class bayesian_estimator : public KVBase {
222 
223  FittingFunction theFitter;
224  FluctuationKernel theKernel;
225 
228  std::vector<double> sel_rapp;
241 
243 
244  impact_parameter_distribution fIPDist;// used to convert centrality to impact parameter
245 
246  double mean_X_vs_cb(double* x, double* par)
247  {
252 
253  theFitter.fill_params_from_array(par);
254  return theFitter.meanX(x[0]);
255  }
256  double mean_X_vs_b(double* x, double* par)
257  {
262 
263  theFitter.fill_params_from_array(par);
264  return theFitter.meanX(fIPDist.GetCentrality().Eval(x[0]));
265  }
266  double P_X_cb(double X, double cb)
267  {
271  return fIntegerVariable ? theKernel(TMath::Nint(X), theFitter.meanX(cb), theFitter.redVar(cb))
272  : theKernel(X, theFitter.meanX(cb), theFitter.redVar(cb));
273  }
274  double P_X_cb_for_TF2_obs_vs_b(double* x, double*)
275  {
279 
280  auto X = x[1];
281  auto cb = fIPDist.GetCentrality().Eval(x[0]);
282  return x[0] * theKernel(X, theFitter.meanX(cb), theFitter.redVar(cb));
283  }
284  double P_X_cb_for_integral(double* x, double* par)
285  {
292  return P_X_cb(par[0], x[0]);
293  }
294  double P_X_cb_for_X_integral(double* x, double* par)
295  {
303  return P_X_cb(x[0], par[0]);
304  }
305  double P_X_cb_for_X_integral_with_selection(double* x, double* par)
306  {
314 
315  int bin = histo->FindBin(x[0]);
316  if (bin < 1 || bin > histo->GetNbinsX()) return 0;
317  return sel_rapp[bin - 1] * P_X_cb(x[0], par[0]);
318  }
319  double cb_integrated_P_X(double* x, double* p)
320  {
328 
329  theFitter.fill_params_from_array(p);
330  p_X_cb_integrator.SetParameter(0, x[0]); // set value of X in integrand
331  return p_X_cb_integrator.Integral(0, 1, 1.e-4);
332  }
333  double P_X_from_fit(double* x, double* par)
334  {
339  p_X_cb_integrator.SetParameter(0, x[0]); // set value of X in integrand
340  return par[0] * p_X_cb_integrator.Integral(0, 1, 1.e-4);
341  }
342  double cb_dist_for_X_selection(double* x, double* p)
343  {
353 
355  double num = p_X_X_integrator.Integral(p[0], p[1], 1.e-4);
356  double den = fitted_P_X.Integral(p[0], p[1], 1.e-4);
357  if (den > 0) return num / den;
358  return 0;
359  }
360  double cb_dist_for_arb_X_selection(double* x, double* p)
361  {
370 
372  double num = p_X_X_integrator_with_selection.Integral(p[0], p[1], 1.e-4);
374 
375  return num;
376  }
377  double b_dist_for_X_selection(double* x, double* p)
378  {
388 
390  double num = p_X_X_integrator.Integral(p[0], p[1], 1.e-4);
391  return num * fIPDist.GetDifferentialCrossSection(x[0]);
392  }
393  double b_dist_for_arb_X_selection(double* x, double* p)
394  {
403 
405  double num = p_X_X_integrator_with_selection.Integral(p[0], p[1], 1.e-4);
406  return num * fIPDist.GetDifferentialCrossSection(x[0]);
407  }
408  double b_dist_for_arb_X_selection_from_histo(double* x, double* p)
409  {
418  TH1* hh_centb = fIPDist.GetCentralityFromHisto();
419  Double_t centb = hh_centb->GetBinContent(hh_centb->FindBin(x[0]));
420 
422  double num = p_X_X_integrator_with_selection.Integral(p[0], p[1], 1.e-4);
424  }
425 
426  public:
427  bayesian_estimator(Bool_t integer_variable = false)
428  : KVBase(),
429  theFitter(),
430  p_X_cb_integrator("p_X_cb_integrator", this, &bayesian_estimator::P_X_cb_for_integral, 0, 1, 1),
431  P_X_fit_function("P_X_fit_function", this, &bayesian_estimator::cb_integrated_P_X, 0, 1, theFitter.npar()),
432  mean_X_vs_cb_function("mean_X_vs_cb", this, &bayesian_estimator::mean_X_vs_cb, 0, 1, theFitter.npar()),
433  mean_X_vs_b_function("mean_X_vs_b", this, &bayesian_estimator::mean_X_vs_b, 0, 20, theFitter.npar()),
434  p_X_X_integrator("p_X_X_integrator", this, &bayesian_estimator::P_X_cb_for_X_integral, 0, 1000, 1),
435  p_X_X_integrator_with_selection("p_X_X_integrator_with_selection", this, &bayesian_estimator::P_X_cb_for_X_integral_with_selection, 0, 1000, 1),
436  fitted_P_X("fitted_P_X", this, &bayesian_estimator::P_X_from_fit, 0, 1000, 1),
437  Cb_dist_for_X_select("Cb_dist_for_X_select", this, &bayesian_estimator::cb_dist_for_X_selection, 0, 1, 2),
438  Cb_dist_for_arb_X_select("Cb_dist_for_arb_X_select", this, &bayesian_estimator::cb_dist_for_arb_X_selection, 0, 1, 2),
439  B_dist_for_X_select("b_dist_for_X_select", this, &bayesian_estimator::b_dist_for_X_selection, 0, 20, 2),
440  B_dist_for_arb_X_select("b_dist_for_arb_X_select", this, &bayesian_estimator::b_dist_for_arb_X_selection, 0, 20, 2),
441  B_dist_for_arb_X_select_from_histo("b_dist_for_arb_X_select_from_histo", this, &bayesian_estimator::b_dist_for_arb_X_selection_from_histo, 0, 20, 2),
442  fIntegerVariable(integer_variable)
443  {
448  theFitter.set_par_names(P_X_fit_function);
449  theFitter.set_par_names(mean_X_vs_cb_function);
450  theFitter.set_par_names(mean_X_vs_b_function);
451  }
452 
453  bayesian_estimator(const FittingFunction& previous_fit, Bool_t integer_variable = false)
454  : KVBase(),
455  theFitter(previous_fit),
456  p_X_cb_integrator("p_X_cb_integrator", this, &bayesian_estimator::P_X_cb_for_integral, 0, 1, 1),
457  P_X_fit_function("P_X_fit_function", this, &bayesian_estimator::cb_integrated_P_X, 0, 1, theFitter.npar()),
458  mean_X_vs_cb_function("mean_X_vs_cb", this, &bayesian_estimator::mean_X_vs_cb, 0, 1, theFitter.npar()),
459  mean_X_vs_b_function("mean_X_vs_b", this, &bayesian_estimator::mean_X_vs_b, 0, 20, theFitter.npar()),
460  p_X_X_integrator("p_X_X_integrator", this, &bayesian_estimator::P_X_cb_for_X_integral, 0, 1000, 1),
461  p_X_X_integrator_with_selection("p_X_X_integrator_with_selection", this, &bayesian_estimator::P_X_cb_for_X_integral_with_selection, 0, 1000, 1),
462  fitted_P_X("fitted_P_X", this, &bayesian_estimator::P_X_from_fit, 0, 1000, 1),
463  Cb_dist_for_X_select("Cb_dist_for_X_select", this, &bayesian_estimator::cb_dist_for_X_selection, 0, 1, 2),
464  Cb_dist_for_arb_X_select("Cb_dist_for_arb_X_select", this, &bayesian_estimator::cb_dist_for_arb_X_selection, 0, 1, 2),
465  B_dist_for_X_select("b_dist_for_X_select", this, &bayesian_estimator::b_dist_for_X_selection, 0, 20, 2),
466  B_dist_for_arb_X_select("b_dist_for_arb_X_select", this, &bayesian_estimator::b_dist_for_arb_X_selection, 0, 20, 2),
467  B_dist_for_arb_X_select_from_histo("b_dist_for_arb_X_select_from_histo", this, &bayesian_estimator::b_dist_for_arb_X_selection_from_histo, 0, 20, 2),
468  fIntegerVariable(integer_variable)
469  {
475  theFitter.set_par_names(P_X_fit_function);
476  theFitter.set_par_names(mean_X_vs_cb_function);
477  theFitter.set_par_names(mean_X_vs_b_function);
478  }
479 
480  virtual ~bayesian_estimator() {}
481 
483  {
489 
490  histo = h;
491  histo->Scale(1. / h->Integral("width"));
492  }
493 
494  void FitHisto(TH1* h = nullptr)
495  {
506 
507  if (h) histo = h;
508  auto xmin = histo->GetXaxis()->GetBinLowEdge(1);
511  theFitter.set_initial_parameters(histo, P_X_fit_function);
512  histo->Fit(&P_X_fit_function);//,"EMG");
513  }
514 
515  void SetIPDistParams(double sigmaR, double deltab)
516  {
533 
535  }
536 
537  void SetIPDistFromHisto(TH1* ip_histo)
538  {
552 
553  fIPDist.FitIPDist(ip_histo);
554  }
555 
557  {
564  return fIPDist;
565  }
566 
567  void DrawMeanXvsCb(const TString& title = "", Color_t color = -1, Option_t* opt = "")
568  {
577 
578  GetMeanXvsCb().Draw();
579  }
581  {
588 
589  Double_t par[theFitter.npar()];
590  theFitter.fill_array_from_params(par);
592  return mean_X_vs_cb_function;
593  }
594  TGraph* GraphMeanXvsb(int npts = 500)
595  {
605 
606  Double_t par[theFitter.npar()];
607  theFitter.fill_array_from_params(par);
608  KVValueRange<double> brange(0, GetIPDist().GetB0() + 4 * GetIPDist().GetDeltaB());
610  auto gr = new TGraph;
611  for (int i = 0; i <= npts; ++i) gr->SetPoint(i, brange.ValueIofN(i, npts), mean_X_vs_b_function.Eval(brange.ValueIofN(i, npts)));
612  return gr;
613  }
614  TH2* TransformXaxisToBaxis(const TH2* obs_vs_X, int baxis_nbins = 100, double baxis_bmin = 0, double baxis_bmax = 1)
615  {
620 
621  auto Nx = obs_vs_X->GetNbinsX();
622  auto Ny = obs_vs_X->GetNbinsY();
623  auto ymin = obs_vs_X->GetYaxis()->GetBinLowEdge(1);
624  auto ymax = obs_vs_X->GetYaxis()->GetBinUpEdge(Ny);
625  auto ywidth = obs_vs_X->GetYaxis()->GetBinWidth(1);
626  auto obs_vs_b = new TH2F("obs_vs_b", obs_vs_X->GetTitle(),
627  baxis_nbins, baxis_bmin, baxis_bmax, Ny, ymin, ymax);
628  for (int binx = 1; binx <= Nx; ++binx) {
630  obs_vs_X->GetXaxis()->GetBinUpEdge(binx));
631  for (int biny = 1; biny <= Ny; ++biny) {
632  auto stat = obs_vs_X->GetBinContent(binx, biny);
633  auto yval = obs_vs_X->GetYaxis()->GetBinCenter(biny);
634  for (int i = 0; i < stat; ++i) {
635  obs_vs_b->Fill(B_dist_for_X_select.GetRandom(0., 1.),
636  gRandom->Uniform(yval - .5 * ywidth, yval + .5 * ywidth));
637  }
638  }
639  }
640  return obs_vs_b;
641  }
643  {
645  if (!histo) {
646  Error("GraphMeanbvsX", "Need to give histogram of X observable to NormalizeHisto() first");
647  return nullptr;
648  }
649 
650  auto g = new TGraphErrors;
651  auto N = histo->GetNbinsX();
652  auto W = histo->GetBinWidth(1);
653 
654  std::cout << N << std::endl;
655 
656  for (int i = 1; i <= N; ++i) {
657  double mean, sigma;
658  if (histo->GetBinContent(i) > 0) {
659  auto X = histo->GetBinCenter(i);
660  std::cout << i << " " << X;
661  GetMeanAndSigmaBDistForXSelection({X - W / 2, X + W / 2}, mean, sigma);
662  g->AddPoint(X, mean);
663  g->SetPointError(g->GetN() - 1, 0, sigma);
664  std::cout << " " << mean << " " << sigma << std::endl;
665  }
666  }
667  return g;
668  }
670  {
675 
676  if (!histo) {
677  Warning("update_fit_params", "no histogram set with FitHisto(TH1*)");
678  return;
679  }
680  TF1* fit = (TF1*)histo->FindObject("P_X_fit_function");
681  if (!fit) {
682  Warning("update_fit_params", "no fit function found in histogram");
683  return;
684  }
685  theFitter.fill_params_from_array(fit->GetParameters());
686  }
687  double DrawCbDistForXSelection(double X1, double X2, Option_t* opt = "", Color_t color = kRed, const TString& title = "")
688  {
703  f->SetNpx(500);
704  f->SetLineColor(color);
705  f->SetMarkerColor(color);
706  f->SetLineWidth(2);
707  f->SetTitle(title);
708  return f->GetMaximum();
709  }
710  void DrawCbDistForSelection(TH1* sel, TH1* incl, double& mean_cb, double& sigma_cb, Option_t* opt = "", Color_t color = kRed, const TString& title = "")
711  {
726 
727  assert(sel->GetNbinsX() == incl->GetNbinsX());
728 
731  sel_rapp.assign((std::vector<double>::size_type)incl->GetNbinsX(), 0.0);
732  int first_bin(0), last_bin(0);
733  for (int i = 1; i <= incl->GetNbinsX(); ++i) {
734  if (incl->GetBinContent(i) > 0) {
735  sel_rapp[i - 1] = sel->GetBinContent(i) / incl->GetBinContent(i);
736  if (sel->GetBinContent(i) > 0) {
737  if (!first_bin) first_bin = i;
738  last_bin = i;
739  }
740  }
741  }
742  double Xmin = incl->GetBinLowEdge(first_bin);
743  double Xmax = incl->GetXaxis()->GetBinUpEdge(last_bin);
744 
745  histo = incl;
746  h_selection = sel;
747 
752 
754  double cb_mean(0), cb_sqrmean(0), sum_pcb(0);
755  TGraph* f = new TGraph;
756  for (int i = 0; i < 500; ++i) {//graph with 500 points
757  double cb = i / 499.;
758  double p_cb = Cb_dist_for_arb_X_select.Eval(cb);
759 
760  cb_mean += p_cb * cb;
761  cb_sqrmean += p_cb * cb * cb;
762  sum_pcb += p_cb;
763 
764  f->SetPoint(i, cb, p_cb);
765  }
766 
768  cb_sqrmean /= sum_pcb;
769  cb_mean /= sum_pcb;
770  mean_cb = cb_mean;
771  sigma_cb = TMath::Sqrt(cb_sqrmean - cb_mean * cb_mean);
772 
774  f->SetLineColor(color);
775  f->SetMarkerColor(color);
776  f->SetLineWidth(2);
777  f->SetTitle(title);
778  if (TString(opt) == "same") f->Draw("l");
779  else f->Draw("al");
780  }
781  double DrawBDistForXSelection(KVValueRange<double> Xrange, Option_t* opt = "", Color_t color = kRed, const TString& title = "")
782  {
799 
800  B_dist_for_X_select.SetParameters(Xrange.Min(), Xrange.Max());
801  TGraph* f = new TGraph;
802  double maxS = 0;
803  for (int i = 0; i < 500; ++i) {
804  double b = 2 * i * GetIPDist().GetB0() / 499.;
805  double sig = B_dist_for_X_select.Eval(b);
806  if (sig > maxS) maxS = sig;
807  f->SetPoint(i, b, sig);
808  }
809  f->SetLineColor(color);
810  f->SetMarkerColor(color);
811  f->SetLineWidth(2);
812  f->SetTitle(title);
813  if (TString(opt) == "same") f->Draw("l");
814  else f->Draw("al");
815  return maxS;
816  }
818  {
819  return B_dist_for_X_select;
820  }
822  {
835 
836 
837  B_dist_for_X_select.SetParameters(Xrange.Min(), Xrange.Max());
838  TGraph* f = new TGraph;
839  for (int i = 0; i < npts; ++i) {
840  double b = 2 * i * GetIPDist().GetB0() / 499.;
841  double sig = B_dist_for_X_select.Eval(b);
842  f->SetPoint(i, b, sig);
843  }
844  f->SetLineWidth(2);
845  return f;
846  }
847  void DrawBDistForSelection(TH1* sel, TH1* incl, double& mean, double& sigma, Option_t* opt = "", Color_t color = kRed, const TString& title = "")
848  {
868 
869 
870  assert(sel->GetNbinsX() == incl->GetNbinsX());
871 
872  sel_rapp.assign((std::vector<double>::size_type)incl->GetNbinsX(), 0.0);
873  int first_bin(0), last_bin(0);
874  for (int i = 1; i <= incl->GetNbinsX(); ++i) {
875  if (incl->GetBinContent(i) > 0) {
876  sel_rapp[i - 1] = sel->GetBinContent(i) / incl->GetBinContent(i);
877  if (sel->GetBinContent(i) > 0) {
878  if (!first_bin) first_bin = i;
879  last_bin = i;
880  }
881  }
882  }
883  double Xmin = incl->GetBinLowEdge(first_bin);
884  double Xmax = incl->GetXaxis()->GetBinUpEdge(last_bin);
885 
886  histo = incl;
887  h_selection = sel;
888 
890  B_dist_for_arb_X_select.SetRange(0, 2 * GetIPDist().GetB0());
892 
893  double bmean(0), bsqrmean(0), sigtot(0);
894  TGraph* f = new TGraph;
895  for (int i = 0; i < 500; ++i) {
896  double b = 2 * i * GetIPDist().GetB0() / 499.;
897  double sig = B_dist_for_arb_X_select.Eval(b);
898  bmean += sig * b;
899  bsqrmean += sig * b * b;
900  sigtot += sig;
901  f->SetPoint(i, b, sig);
902  }
903  f->SetLineColor(color);
904  f->SetMarkerColor(color);
905  f->SetLineWidth(2);
906  f->SetTitle(title);
907  mean = bmean / sigtot;
908  bsqrmean /= sigtot;
909  sigma = TMath::Sqrt(bsqrmean - mean * mean);
910  if (TString(opt) == "same") f->Draw("l");
911  else f->Draw("al");
912  }
913 
914  void DrawBDistForSelectionFromIPHisto(TH1* sel, TH1* incl, double& mean, double& sigma, Option_t* opt = "", Color_t color = kRed, const TString& title = "")
915  {
933 
934  assert(sel->GetNbinsX() == incl->GetNbinsX());
935 
936  sel_rapp.assign((std::vector<double>::size_type)incl->GetNbinsX(), 0.0);
937  int first_bin(0), last_bin(0);
938  for (int i = 1; i <= incl->GetNbinsX(); ++i) {
939  if (incl->GetBinContent(i) > 0) {
940  sel_rapp[i - 1] = sel->GetBinContent(i) / incl->GetBinContent(i);
941  if (sel->GetBinContent(i) > 0) {
942  if (!first_bin) first_bin = i;
943  last_bin = i;
944  }
945  }
946  }
947  double Xmin = incl->GetBinLowEdge(first_bin);
948  double Xmax = incl->GetXaxis()->GetBinUpEdge(last_bin);
949 
950  histo = incl;
951  h_selection = sel;
952 
954  B_dist_for_arb_X_select_from_histo.SetRange(0, 2 * GetIPDist().GetB0()); //if SetIPDistFromHisto() was called, a fit have been applied thus B0 was estimated
956 
957  double bmean(0), bsqrmean(0), sigtot(0);
958  TGraph* f = new TGraph;
959  for (int i = 0; i < 500; ++i) {
960  double b = 2 * i * GetIPDist().GetB0() / 499.;
962  bmean += sig * b;
963  bsqrmean += sig * b * b;
964  sigtot += sig;
965  f->SetPoint(i, b, sig);
966  }
967  f->SetLineColor(color);
968  f->SetMarkerColor(color);
969  f->SetLineWidth(2);
970  f->SetTitle(title);
971  mean = bmean / sigtot;
972  bsqrmean /= sigtot;
973  sigma = TMath::Sqrt(bsqrmean - mean * mean);
974  if (TString(opt) == "same") f->Draw("l");
975  else f->Draw("al");
976  }
977 
978  void GetMeanAndSigmaBDistForSelection(TH1* sel, TH1* incl, double& mean, double& sigma)
979  {
996 
997 
998  assert(sel->GetNbinsX() == incl->GetNbinsX());
999 
1000  sel_rapp.assign((std::vector<double>::size_type)incl->GetNbinsX(), 0.0);
1001  int first_bin(0), last_bin(0);
1002  for (int i = 1; i <= incl->GetNbinsX(); ++i) {
1003  if (incl->GetBinContent(i) > 0) {
1004  sel_rapp[i - 1] = sel->GetBinContent(i) / incl->GetBinContent(i);
1005  if (sel->GetBinContent(i) > 0) {
1006  if (!first_bin) first_bin = i;
1007  last_bin = i;
1008  }
1009  }
1010  }
1011  double Xmin = incl->GetBinLowEdge(first_bin);
1012  double Xmax = incl->GetXaxis()->GetBinUpEdge(last_bin);
1013 
1014  histo = incl;
1015  h_selection = sel;
1016 
1018  mean = B_dist_for_arb_X_select.Mean(0, 20);
1019  double var = B_dist_for_arb_X_select.Variance(0, 20);
1020  sigma = TMath::Sqrt(var);
1021  }
1022 
1023  void GetMeanAndSigmaBDistForXSelection(KVValueRange<double> Xrange, double& mean, double& sigma)
1024  {
1039 
1040  B_dist_for_X_select.SetParameters(Xrange.Min(), Xrange.Max());
1041  mean = sigma = 0;
1042  double sig_tot = 0;
1043  for (int i = 0; i < 500; ++i) {
1044  double b = 2 * i * GetIPDist().GetB0() / 499.;
1045  double sig = B_dist_for_X_select.Eval(b);
1046  mean += b * sig;
1047  sigma += pow(b, 2) * sig;
1048  sig_tot += sig;
1049  }
1050  if (sig_tot <= 0) {
1051  Warning("GetMeanAndSigmaBDistForXSelection", "Total cross-section = 0!");
1052  return;
1053  }
1054  mean /= sig_tot;
1055  sigma /= sig_tot;
1056  sigma = pow(sigma - pow(mean, 2), 0.5);
1057  }
1058  void DrawFittedP_X(double norm = 1.0, Option_t* opt = "", Color_t color = kRed, const TString& title = "")
1059  {
1066 
1067  TF1* f = GetFittedP_X(norm)->DrawCopy(opt);
1068  f->SetNpx(500);
1069  f->SetLineColor(color);
1070  f->SetLineWidth(2);
1071  f->SetTitle(title);
1072  }
1073  TF1* GetFittedP_X(double norm = 1.0)
1074  {
1079  fitted_P_X.SetParameter(0, norm);
1080  return &fitted_P_X;
1081  }
1082  TGraph* GraphP_XForGivenB(double b, KVValueRange<double> Xrange, int npts = 500)
1083  {
1090  auto graph = new TGraph;
1091  for (int i = 0; i < npts; ++i) graph->SetPoint(i, Xrange.ValueIofN(i, npts), p_X_X_integrator.Eval(Xrange.ValueIofN(i, npts)));
1092  return graph;
1093  }
1094  void Print(Option_t* = "") const
1095  {
1097  theFitter.print_fit_params();
1098  }
1100  {
1102  return theFitter.get_params();
1103  }
1104  void DrawNormalisedMeanXvsb(const TString& title, Color_t color, Option_t* opt)
1105  {
1121 
1122 
1123  theFitter.backup_params();
1124  theFitter.normalise_shape_function();
1125  Double_t par[5];
1126  theFitter.fill_array_from_params(par);
1127  mean_X_vs_b_function.SetRange(0, GetIPDist().GetB0() + 2 * GetIPDist().GetDeltaB());
1129  TF1* copy = mean_X_vs_b_function.DrawCopy(opt);
1130  if (!title.IsNull()) copy->SetTitle(title);
1131  if (color >= 0) copy->SetLineColor(color);
1132  theFitter.restore_params();
1133  }
1134 
1136  {
1139 
1140  auto jpd = new TF2("joint_proba_dist", this, &bayesian_estimator::P_X_cb_for_TF2_obs_vs_b,
1141  b_range.Min(), b_range.Max(), X_range.Min(), X_range.Max(), 0);
1142  return jpd;
1143  }
1144 
1145  ClassDef(bayesian_estimator, 1) //Estimate impact parameter distribution by fits to data
1146  };
1147 
1148 }
1149 
1150 #endif
#define f(i)
bool Bool_t
short Color_t
double Double_t
const char Option_t
#define ClassDef(name, id)
#define X(type, name)
#define N
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t g
float xmin
float ymin
float xmax
float ymax
R__EXTERN TRandom * gRandom
Base class for KaliVeda framework.
Definition: KVBase.h:139
Fluctuation kernel using binomial distribution for use with bayesian_estimator.
double operator()(double X, double mean, double reduced_variance)
Fluctuation kernel using negative binomial distribution for use with bayesian_estimator.
double operator()(double X, double mean, double reduced_variance)
Impact parameter distribution reconstruction from experimental data.
double P_X_cb_for_integral(double *x, double *par)
impact_parameter_distribution fIPDist
void DrawBDistForSelection(TH1 *sel, TH1 *incl, double &mean, double &sigma, Option_t *opt="", Color_t color=kRed, const TString &title="")
void DrawCbDistForSelection(TH1 *sel, TH1 *incl, double &mean_cb, double &sigma_cb, Option_t *opt="", Color_t color=kRed, const TString &title="")
double mean_X_vs_b(double *x, double *par)
double DrawBDistForXSelection(KVValueRange< double > Xrange, Option_t *opt="", Color_t color=kRed, const TString &title="")
void GetMeanAndSigmaBDistForSelection(TH1 *sel, TH1 *incl, double &mean, double &sigma)
bayesian_estimator(Bool_t integer_variable=false)
double cb_dist_for_X_selection(double *x, double *p)
void SetIPDistParams(double sigmaR, double deltab)
double b_dist_for_arb_X_selection_from_histo(double *x, double *p)
double P_X_cb_for_TF2_obs_vs_b(double *x, double *)
double P_X_from_fit(double *x, double *par)
double b_dist_for_arb_X_selection(double *x, double *p)
double DrawCbDistForXSelection(double X1, double X2, Option_t *opt="", Color_t color=kRed, const TString &title="")
bayesian_estimator(const FittingFunction &previous_fit, Bool_t integer_variable=false)
double b_dist_for_X_selection(double *x, double *p)
impact_parameter_distribution & GetIPDist()
void GetMeanAndSigmaBDistForXSelection(KVValueRange< double > Xrange, double &mean, double &sigma)
double cb_integrated_P_X(double *x, double *p)
double P_X_cb_for_X_integral(double *x, double *par)
void DrawNormalisedMeanXvsb(const TString &title, Color_t color, Option_t *opt)
double cb_dist_for_arb_X_selection(double *x, double *p)
double mean_X_vs_cb(double *x, double *par)
TGraph * GraphBDistForXSelection(KVValueRange< double > Xrange, int npts=500)
void DrawBDistForSelectionFromIPHisto(TH1 *sel, TH1 *incl, double &mean, double &sigma, Option_t *opt="", Color_t color=kRed, const TString &title="")
double P_X_cb_for_X_integral_with_selection(double *x, double *par)
TGraph * GraphP_XForGivenB(double b, KVValueRange< double > Xrange, int npts=500)
TF2 * GetJointProbabilityDistribution(KVValueRange< double > b_range, KVValueRange< double > X_range)
void DrawMeanXvsCb(const TString &title="", Color_t color=-1, Option_t *opt="")
TH2 * TransformXaxisToBaxis(const TH2 *obs_vs_X, int baxis_nbins=100, double baxis_bmin=0, double baxis_bmax=1)
void DrawFittedP_X(double norm=1.0, Option_t *opt="", Color_t color=kRed, const TString &title="")
Fluctuation kernel using gamma distribution for use with bayesian_estimator.
double operator()(double X, double mean, double reduced_variance)
Class implementing parametrizable impact parameter distributions.
void SetDeltaB_WithConstantCrossSection(Double_t deltab, Double_t sigmaR=0)
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
Range of values specified by minimum, maximum.
Definition: KVValueRange.h:19
ValueType Max() const
Definition: KVValueRange.h:48
ValueType ValueIofN(Int_t i, Int_t n) const
Definition: KVValueRange.h:60
ValueType Min() const
Definition: KVValueRange.h:44
virtual void SetLineColor(Color_t lcolor)
virtual Double_t GetBinCenter(Int_t bin) const
virtual Double_t GetBinLowEdge(Int_t bin) const
virtual Double_t GetBinWidth(Int_t bin) const
virtual Double_t GetBinUpEdge(Int_t bin) const
virtual Double_t Mean(Double_t a, Double_t b, const Double_t *params=nullptr, Double_t epsilon=0.000001)
virtual TH1 * GetHistogram() const
virtual void SetRange(Double_t xmin, Double_t xmax)
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
void SetTitle(const char *title="") override
void Draw(Option_t *option="") override
virtual Double_t Variance(Double_t a, Double_t b, const Double_t *params=nullptr, Double_t epsilon=0.000001)
virtual TF1 * DrawCopy(Option_t *option="") const
virtual Double_t GetRandom(Double_t xmin, Double_t xmax, TRandom *rng=nullptr, Option_t *opt=nullptr)
virtual void SetParameters(const Double_t *params)
virtual void SetParNames(const char *name0="p0", const char *name1="p1", const char *name2="p2", const char *name3="p3", const char *name4="p4", const char *name5="p5", const char *name6="p6", const char *name7="p7", const char *name8="p8", const char *name9="p9", const char *name10="p10")
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
virtual void SetParameter(const TString &name, Double_t value)
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
virtual Double_t GetBinCenter(Int_t bin) const
virtual Int_t GetNbinsY() const
TAxis * GetXaxis()
TObject * FindObject(const char *name) const override
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
virtual Int_t GetNbinsX() const
TAxis * GetYaxis()
virtual Double_t GetBinLowEdge(Int_t bin) const
virtual Double_t Integral(Int_t binx1, Int_t binx2, Option_t *option="") const
virtual Double_t GetBinContent(Int_t bin) const
virtual Double_t GetBinWidth(Int_t bin) const
virtual void Scale(Double_t c1=1, Option_t *option="")
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
virtual Double_t GetBinContent(Int_t bin) const
const char * GetTitle() const override
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual Double_t Uniform(Double_t x1, Double_t x2)
Bool_t IsNull() const
double binomial_pdf(unsigned int k, double p, unsigned int n)
double negative_binomial_pdf(unsigned int k, double p, double n)
double gamma_pdf(double x, double alpha, double theta, double x0=0)
RVec< PromoteTypes< T0, T1 > > pow(const T0 &x, const RVec< T1 > &v)
const Double_t sigma
Double_t x[n]
TGraphErrors * gr
TH1 * h
fit(model, train_loader, val_loader, num_epochs, batch_size, optimizer, criterion, save_best, scheduler)
Int_t Nint(T x)
Double_t Sqrt(Double_t x)