22 void FitParabola(Double_t x1,
57 Int_t SolveParabola(Double_t a, Double_t b, Double_t c, Double_t& x1, Double_t& x2) {
58 Double_t Delta = b * b - 4.0 * a * c;
59 if (Delta < 0)
return 0;
61 x1 = x2 = -b / (2.0 * a);
64 Delta = TMath::Sqrt(Delta);
65 x1 = (-b - Delta) / (2.0 * a);
66 x2 = (-b + Delta) / (2.0 * a);
70 Int_t Bin3dToBin1d(Int_t nbinsX, Int_t nBinsY, Int_t binX, Int_t binY, Int_t binZ, Bool_t root) {
72 return (binX - 1) * nbinsX * nBinsY + (binY - 1) * nBinsY + binZ - 1;
74 return binX * nbinsX * nBinsY + binY * nBinsY + binZ;
78 TVector3 Bin1dToBin3d(Int_t nbinsX, Int_t nBinsY, Int_t bin, Bool_t root) {
79 Int_t XY = nBinsY * nbinsX;
80 Int_t alpha = TMath::Floor(bin / XY);
81 Int_t beta = TMath::Floor((bin - alpha * XY) / nbinsX);
82 Int_t gamma = bin - alpha * XY - beta * nbinsX;
84 return TVector3(alpha + 1, beta + 1, gamma + 1);
86 return TVector3(alpha, beta, gamma);
90 TMatrixD GetVec(
const TH1& h, Bool_t horizontal) {
92 TMatrixD vect(1, h.GetNbinsX());
93 for (
int i = 1; i <= h.GetNbinsX(); i++) {
94 vect[0][i - 1] = h.GetBinContent(i);
98 TMatrixD vect(h.GetNbinsX(), 1);
99 for (
int i = 1; i <= h.GetNbinsX(); i++) {
100 vect[i - 1][0] = h.GetBinContent(i);
106 TMatrixD GetMatrix(
const TH2& h, Bool_t swap) {
108 double minX, minY, maxX, maxY;
109 Hal::Std::GetAxisPar(h, binX, minX, maxX,
"x");
110 Hal::Std::GetAxisPar(h, binY, minY, maxY,
"y");
113 return TMatrixD(1, 1);
115 if (minY != minX || maxX != maxY) {
116 Hal::Cout::PrintInfo(
"Wrong histogram Hal::Std::GetMatrix min/max are not equal", EInfo::kWarning);
118 TMatrixD vect(binX, binX);
119 for (
int i = 1; i <= binX; i++) {
120 for (
int j = 1; j <= binX; j++) {
122 vect[binX - j][i - 1] = h.GetBinContent(i, j);
124 vect[j - 1][i - 1] = h.GetBinContent(i, j);
131 Double_t Discretize(Int_t areas, Double_t min, Double_t max, Double_t val, Char_t type) {
132 Double_t step_size = (max - min) / ((Double_t) areas);
133 Double_t step = (val - min) / step_size;
140 step = TMath::Ceil(step);
143 step = TMath::Floor(step);
146 step = std::round(step);
148 default:
return 0;
break;
150 Double_t res = min + step * step_size;
151 if (res < min)
return min;
152 if (res > max)
return max;
156 Double_t StatError2Var(Char_t ope, Double_t x, Double_t y, Double_t dx, Double_t dy) {
157 if (dx < 0) dx = TMath::Sqrt(TMath::Abs(x));
158 if (dy < 0) dy = TMath::Sqrt(TMath::Abs(y));
159 Double_t dfx = 0, dfy = 0;
179 return TMath::Sqrt(dfx * dfx * dx * dx + dfy * dfy * dy * dy);
182 Int_t MultiToOneDimIndex(
const std::vector<int>& size,
const std::vector<int>& position) {
183 if (size.size() != position.size())
return -1;
186 for (
int i = size.size() - 1; i >= 0; i--) {
187 pos = pos + position[i] * step;
188 step = step * size[i];
193 std::vector<int> OneToMultiDimIndex(
const std::vector<int>& size, Int_t n) {
194 std::vector<int> res(size.size());
195 for (
int i = size.size() - 1; i >= 0; i--) {
196 Int_t pos = n % size[i];
197 n = (n - pos) / size[i];
203 std::pair<Int_t, Int_t> Division(Int_t num, Int_t div) {
204 std::pair<Int_t, Int_t> res;
205 Int_t reminder = num % div;
206 res.second = reminder;
207 Int_t afdiv = (num - reminder) / div;
static void PrintInfo(TString text, Hal::EInfo status)