17 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ProcessHistLink");
18 if (type.TString::EqualTo(
"Asymmetry"))
20 if (input.size() != 2)
22 MSGUser()->MSG(
MSGLevel::ERROR,
"Hist Link Asymmetry needs two input hists, but now it is ", input.size());
27 else if (type.TString::EqualTo(
"Delta"))
29 if (input.size() != 2)
34 Delta(input[0], input[1], res);
36 else if (type.TString::EqualTo(
"Ratio"))
38 if (input.size() != 2)
43 Ratio(input[0], input[1], res);
45 else if (type.TString::EqualTo(
"Chi2"))
47 if (input.size() != 2)
52 Chi2(input[0], input[1], res);
54 else if (type.TString::EqualTo(
"Pull"))
56 if (input.size() != 2)
61 Pull(input[0], input[1], res);
72void HistTool::ProcessHistLink(std::function<
double(
const std::vector<double> &)> contentfunction, std::function<
double(
const std::vector<double> &,
const std::vector<double> &)> errorfunction,
const std::vector<TH1 *> &input, TH1 *res)
74 auto titleguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ProcessHistLink");
76 for (
size_t i = 0; i < input.size(); i++)
79 MSGUser()->MSG_ERROR(
"input hist ", i,
" is nullptr");
85 MSGUser()->MSG_ERROR(
"result hist is nullptr");
90 int binnumx = res->GetNbinsX(), binnumy = res->GetNbinsY(), binnumz = res->GetNbinsZ();
91 for (
size_t i = 0; i < input.size(); i++)
92 if (input[i]->GetNbinsX() != binnumx || input[i]->GetNbinsY() != binnumy || input[i]->GetNbinsZ() != binnumz)
94 MSGUser()->MSG_ERROR(
"Input hist definition incorrect!!!");
99 for (
int i = 1; i <= binnumx; i++)
100 for (
int j = 1; j <= binnumy; j++)
101 for (
int k = 1; k <= binnumz; k++)
103 std::vector<double> vcontent(input.size());
104 std::vector<double> verror(input.size());
105 for (
size_t m = 0; m < input.size(); m++)
107 vcontent[m] = input[m]->GetBinContent(input[m]->GetBin(i, j, k));
108 verror[m] = input[m]->GetBinError(input[m]->GetBin(i, j, k));
110 res->SetBinContent(res->GetBin(i, j, k), contentfunction(vcontent));
111 res->SetBinError(res->GetBin(i, j, k), errorfunction(vcontent, verror));
121 auto titleguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ProcessHistLink");
123 for (
size_t i = 0; i < input.size(); i++)
126 MSGUser()->MSG_ERROR(
"input hist ", i,
" is nullptr");
132 MSGUser()->MSG_ERROR(
"result hist is nullptr");
145 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::Asymmetry");
146 if (A ==
nullptr || B ==
nullptr)
148 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
153 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
157 int binnumx = A->GetNbinsX(), binnumy = A->GetNbinsY(), binnumz = A->GetNbinsZ();
158 if (B->GetNbinsX() != binnumx || B->GetNbinsY() != binnumy || B->GetNbinsZ() != binnumz)
160 MSGUser()->MSG_ERROR(
"Input hist definition incorrect!!!");
163 if (Asy->GetNbinsX() != binnumx || Asy->GetNbinsY() != binnumy || Asy->GetNbinsZ() != binnumz)
165 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
169 for (
int i = 1; i <= A->GetNbinsX(); i++)
171 for (
int j = 1; j <= A->GetNbinsY(); j++)
173 for (
int k = 1; k <= A->GetNbinsZ(); k++)
175 double ContentA = A->GetBinContent(A->GetBin(i, j, k)), ContentB = B->GetBinContent(B->GetBin(i, j, k));
176 double ErrorA = A->GetBinError(A->GetBin(i, j, k)), ErrorB = B->GetBinError(B->GetBin(i, j, k));
177 if (ContentA != 0 || ContentB != 0)
179 Asy->SetBinContent(Asy->GetBin(i, j, k), (ContentA - ContentB) / (ContentA + ContentB));
180 Asy->SetBinError(Asy->GetBin(i, j, k),
unc.
AminusBoverAplusB(ContentA, ContentB, ErrorA, ErrorB));
184 Asy->SetBinContent(Asy->GetBin(i, j, k), 0);
185 Asy->SetBinError(Asy->GetBin(i, j, k), 0);
199 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::Delta");
200 if (A ==
nullptr || B ==
nullptr)
202 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
207 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
211 int binnumx = A->GetNbinsX(), binnumy = A->GetNbinsY(), binnumz = A->GetNbinsZ();
212 if (B->GetNbinsX() != binnumx || B->GetNbinsY() != binnumy || B->GetNbinsZ() != binnumz)
214 MSGUser()->MSG_ERROR(
"Input hist definition incorrect!!!");
217 if (D->GetNbinsX() != binnumx || D->GetNbinsY() != binnumy || D->GetNbinsZ() != binnumz)
219 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
223 for (
int i = 1; i <= binnumx; i++)
225 for (
int j = 1; j <= binnumy; j++)
227 for (
int k = 1; k <= binnumz; k++)
229 double val = A->GetBinContent(A->GetBin(i, j, k)) - B->GetBinContent(B->GetBin(i, j, k));
230 double val_err = sqrt(A->GetBinError(A->GetBin(i, j, k)) * A->GetBinError(A->GetBin(i, j, k)) + B->GetBinError(B->GetBin(i, j, k)) * B->GetBinError(B->GetBin(i, j, k)));
232 if (A == B && !dosep)
236 val_err = A->GetBinError(A->GetBin(i, j, k));
239 val_err = B->GetBinError(A->GetBin(i, j, k));
241 D->SetBinContent(D->GetBin(i, j, k), val);
242 D->SetBinError(D->GetBin(i, j, k), val_err);
255 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::Ratio");
256 if (A ==
nullptr || B ==
nullptr)
258 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
263 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
267 int binnumx = A->GetNbinsX(), binnumy = A->GetNbinsY(), binnumz = A->GetNbinsZ();
268 if (B->GetNbinsX() != binnumx || B->GetNbinsY() != binnumy || B->GetNbinsZ() != binnumz)
270 MSGUser()->MSG_ERROR(
"Input hist definition incorrect!!!");
273 if (R->GetNbinsX() != binnumx || R->GetNbinsY() != binnumy || R->GetNbinsZ() != binnumz)
275 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
279 bool NeedWARN =
false;
283 for (
int i = 1; i <= binnumx; i++)
285 for (
int j = 1; j <= binnumy; j++)
287 for (
int k = 1; k <= binnumz; k++)
289 if (B->GetBinContent(B->GetBin(i, j, k)) == 0)
295 R->SetBinContent(R->GetBin(i, j, k), 1);
296 R->SetBinError(R->GetBin(i, j, k), 0);
302 val = A->GetBinContent(A->GetBin(i, j, k)) / B->GetBinContent(B->GetBin(i, j, k));
303 val_err =
unc.
AoverB(A->GetBinContent(A->GetBin(i, j, k)), B->GetBinContent(B->GetBin(i, j, k)),
304 A->GetBinError(A->GetBin(i, j, k)), B->GetBinError(B->GetBin(i, j, k)));
307 if (A == B && !dosep)
311 val_err = A->GetBinError(A->GetBin(i, j, k)) / A->GetBinContent(A->GetBin(i, j, k));
314 val_err =
unc.
AoverB(A->GetBinContent(A->GetBin(i, j, k)), B->GetBinContent(B->GetBin(i, j, k)),
315 0, B->GetBinError(B->GetBin(i, j, k)));
317 R->SetBinContent(R->GetBin(i, j, k), val);
318 R->SetBinError(R->GetBin(i, j, k), val_err);
324 MSGUser()->MSG_WARNING(
"Can not define a ratio for some bin!");
333 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::Chi2");
334 if (A ==
nullptr || B ==
nullptr)
336 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
341 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
345 int binnumx = A->GetNbinsX(), binnumy = A->GetNbinsY(), binnumz = A->GetNbinsZ();
346 if (B->GetNbinsX() != binnumx || B->GetNbinsY() != binnumy || B->GetNbinsZ() != binnumz)
348 MSGUser()->MSG_ERROR(
"Input hist definition incorrect!!!");
351 if (C->GetNbinsX() != binnumx || C->GetNbinsY() != binnumy || C->GetNbinsZ() != binnumz)
353 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
357 bool NeedWARN =
false;
358 for (
int i = 1; i <= A->GetNbinsX(); i++)
360 for (
int j = 1; j <= A->GetNbinsY(); j++)
362 for (
int k = 1; k <= A->GetNbinsZ(); k++)
364 double ContentA = A->GetBinContent(A->GetBin(i, j, k)), ContentB = B->GetBinContent(B->GetBin(i, j, k));
365 double ErrorA = A->GetBinError(A->GetBin(i, j, k)), ErrorB = B->GetBinError(B->GetBin(i, j, k));
366 if (ErrorA != 0 || ErrorB != 0)
367 C->SetBinContent(C->GetBin(i, j, k), pow((ContentA - ContentB) /
unc.
AminusB(ErrorA, ErrorB), 2));
370 C->SetBinContent(C->GetBin(i, j, k), 0);
373 C->SetBinError(C->GetBin(i, j, k), 0);
379 MSGUser()->MSG_WARNING(
"Can not define a chi2 for some bin!");
388 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::Pull");
389 if (A ==
nullptr || B ==
nullptr)
391 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
396 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
400 int binnumx = A->GetNbinsX(), binnumy = A->GetNbinsY(), binnumz = A->GetNbinsZ();
401 if (B->GetNbinsX() != binnumx || B->GetNbinsY() != binnumy || B->GetNbinsZ() != binnumz)
403 MSGUser()->MSG_ERROR(
"Input hist definition incorrect!!!");
406 if (P->GetNbinsX() != binnumx || P->GetNbinsY() != binnumy || P->GetNbinsZ() != binnumz)
408 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
412 bool NeedWARN =
false;
413 for (
int i = 1; i <= A->GetNbinsX(); i++)
415 for (
int j = 1; j <= A->GetNbinsY(); j++)
417 for (
int k = 1; k <= A->GetNbinsZ(); k++)
419 double ContentA = A->GetBinContent(A->GetBin(i, j, k)), ContentB = B->GetBinContent(B->GetBin(i, j, k));
420 double ErrorA = A->GetBinError(A->GetBin(i, j, k)), ErrorB = B->GetBinError(B->GetBin(i, j, k));
421 if (ErrorA != 0 || ErrorB != 0)
422 P->SetBinContent(P->GetBin(i, j, k), (ContentA - ContentB) /
unc.
AminusB(ErrorA, ErrorB));
425 P->SetBinContent(P->GetBin(i, j, k), 0);
428 P->SetBinError(P->GetBin(i, j, k), 0);
433 MSGUser()->MSG_WARNING(
"Can not define a pull for some bin!");
444 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::Chi2");
445 if (A ==
nullptr || B ==
nullptr)
447 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
450 int binnum = A->GetXaxis()->GetNbins();
451 if (B->GetXaxis()->GetNbins() != binnum)
453 MSGUser()->MSG_ERROR(
"Input hist definition incorrect!!!");
458 if (CorrA->GetNbinsX() != binnum || CorrA->GetNbinsY() != binnum)
460 MSGUser()->MSG_ERROR(
"Input correlation histogram definition incorrect!!!");
465 if (CorrB->GetNbinsX() != binnum || CorrB->GetNbinsY() != binnum)
467 MSGUser()->MSG_ERROR(
"Input correlation histogram definition incorrect!!!");
471 TMatrixD covA(binnum, binnum);
472 TMatrixD covB(binnum, binnum);
473 TMatrixD totalcov(binnum, binnum);
478 for (
int i = 0; i < binnum; i++)
479 for (
int j = 0; j < binnum; j++)
492 for (
int i = 0; i < binnum; i++)
493 for (
int j = 0; j < binnum; j++)
502 for (
int i = 0; i < binnum; i++)
503 for (
int j = 0; j < binnum; j++)
505 covA(i, j) *= A->GetBinError(i + 1) * A->GetBinError(j + 1);
506 covB(i, j) *= B->GetBinError(i + 1) * B->GetBinError(j + 1);
508 totalcov = covA + covB;
510 auto invertedcov = totalcov.InvertFast();
514 for (
int ibin = 0; ibin < binnum; ibin++)
515 for (
int jbin = 0; jbin < binnum; jbin++)
516 chi2 += (A->GetBinContent(ibin + 1) - B->GetBinContent(ibin + 1)) * (A->GetBinContent(jbin + 1) - B->GetBinContent(jbin + 1)) * invertedcov(ibin, jbin);
526 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertCovToCorr");
527 if (covar ==
nullptr)
529 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
534 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
538 int binnumx = covar->GetXaxis()->GetNbins(), binnumy = covar->GetYaxis()->GetNbins();
539 if (binnumx != binnumy)
541 MSGUser()->MSG_ERROR(
"Covariance matrix needs to be square matrix!!!");
544 if (corr->GetXaxis()->GetNbins() != binnumx || corr->GetYaxis()->GetNbins() != binnumy)
546 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
550 for (
int i = 0; i < covar->GetXaxis()->GetNbins(); i++)
552 for (
int j = 0; j < covar->GetYaxis()->GetNbins(); j++)
554 if (covar->GetBinContent(i + 1, i + 1) == 0 || covar->GetBinContent(j + 1, j + 1) == 0)
555 corr->SetBinContent(i + 1, j + 1, 0);
557 corr->SetBinContent(i + 1, j + 1, covar->GetBinContent(i + 1, j + 1) / sqrt(covar->GetBinContent(i + 1, i + 1) * covar->GetBinContent(j + 1, j + 1)));
558 corr->SetBinError(i + 1, j + 1, 0);
568 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertCovToError");
571 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
576 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
580 int binnumx = hcov->GetXaxis()->GetNbins(), binnumy = hcov->GetYaxis()->GetNbins();
581 if (binnumx != binnumy)
583 MSGUser()->MSG_ERROR(
"Covariance matrix needs to be square matrix!!!");
586 if (herr->GetXaxis()->GetNbins() != binnumx)
588 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
592 for (
int i = 1; i <= hcov->GetNbinsX(); i++)
594 herr->SetBinContent(i, sqrt(hcov->GetBinContent(i, i)));
595 herr->SetBinError(i, 0);
605 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertCorrToCov");
606 if (corr ==
nullptr || h ==
nullptr)
608 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
613 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
617 int binnumx = corr->GetXaxis()->GetNbins(), binnumy = corr->GetYaxis()->GetNbins();
618 if (binnumx != binnumy)
620 MSGUser()->MSG_ERROR(
"Correlation coefficient matrix needs to be square matrix!!!");
623 if (h->GetXaxis()->GetNbins() != binnumx)
625 MSGUser()->MSG_ERROR(
"Input hist definition incorrect!!!");
628 if (cov->GetXaxis()->GetNbins() != binnumx || cov->GetYaxis()->GetNbins() != binnumy)
630 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
634 for (
int i = 1; i <= cov->GetNbinsX(); i++)
636 for (
int j = 1; j <= cov->GetNbinsY(); j++)
638 cov->SetBinContent(i, j, corr->GetBinContent(i, j) * h->GetBinError(i) * h->GetBinError(j));
639 cov->SetBinError(i, j, 0);
650 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertVectorToTH1D");
653 MSGUser()->MSG_ERROR(
"Input vector is empty!!!");
658 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
662 int vecnum1 = v1.size();
663 if (vecnum1 != h1->GetXaxis()->GetNbins())
665 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
669 for (
size_t i = 0; i < v1.size(); i++)
671 h1->SetBinContent(i + 1, v1[i]);
672 h1->SetBinError(i + 1, 0);
675 for (
size_t i = 0; i < v1err.size(); i++)
677 h1->SetBinError(i + 1, v1err[i]);
687 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertVectorToTH2D");
690 MSGUser()->MSG_ERROR(
"Input vector is empty!!!");
695 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
699 int v2numx = v2.size();
700 int binnumx = h2->GetXaxis()->GetNbins(), binnumy = h2->GetYaxis()->GetNbins();
701 if (v2numx != binnumx)
703 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
707 for (
size_t i = 0; i < v2.size(); i++)
709 if ((
int)v2.at(i).size() != binnumy)
711 MSGUser()->MSG_ERROR(
"Result hist definition incorrect or input vector incorrect!!!");
716 for (
size_t i = 0; i < v2.size(); i++)
718 for (
size_t j = 0; j < v2.at(i).size(); j++)
720 h2->SetBinContent(i + 1, j + 1, v2[i][j]);
721 h2->SetBinError(i + 1, j + 1, 0);
725 for (
size_t i = 0; i < v2err.size(); i++)
727 for (
size_t j = 0; j < v2err.at(i).size(); j++)
729 h2->SetBinError(i + 1, j + 1, v2err[i][j]);
738void HistTool::ConvertVectorToTH3D(TH3D *h3,
const std::vector<std::vector<std::vector<double>>> &v3,
const std::vector<std::vector<std::vector<double>>> &v3err)
740 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertVectorToTH3D");
743 MSGUser()->MSG_ERROR(
"Input vector is empty!!!");
748 MSGUser()->MSG_ERROR(
"Result hist not defined!!!");
752 int v3numx = v3.size();
753 int binnumx = h3->GetXaxis()->GetNbins(), binnumy = h3->GetYaxis()->GetNbins(), binnumz = h3->GetZaxis()->GetNbins();
754 if (v3numx != binnumx)
756 MSGUser()->MSG_ERROR(
"Result hist definition incorrect!!!");
760 for (
size_t i = 0; i < v3.size(); i++)
762 if (v3.at(i).empty())
764 MSGUser()->MSG_ERROR(
"Input vector is empty!!!");
767 if ((
int)v3.at(i).size() != binnumy)
769 MSGUser()->MSG_ERROR(
"Result hist definition incorrect or input vector incorrect!!!");
772 for (
size_t j = 0; j < v3.at(i).at(j).size(); j++)
774 if ((
int)v3.at(i).at(j).size() != binnumz)
776 MSGUser()->MSG_ERROR(
"Result hist definition incorrect or input vector incorrect!!!");
782 for (
size_t i = 0; i < v3.size(); i++)
784 for (
size_t j = 0; j < v3.at(i).size(); j++)
786 for (
size_t k = 0; k < v3.at(j).at(j).size(); k++)
788 h3->SetBinContent(i + 1, j + 1, k + 1, v3[i][j][k]);
789 h3->SetBinError(i + 1, j + 1, k + 1, 0);
794 for (
size_t i = 0; i < v3err.size(); i++)
796 for (
size_t j = 0; j < v3err.at(i).size(); j++)
798 for (
size_t k = 0; k < v3err.at(i).at(j).size(); k++)
800 h3->SetBinError(i + 1, j + 1, k + 1, v3err[i][j][k]);
811 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertTH1DToVector");
813 std::vector<double> returnv1d;
817 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
821 for (
int i = 1; i <= h1d->GetNbinsX(); i++)
822 returnv1d.emplace_back(h1d->GetBinContent(i));
832 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertTH1DErrorToVector");
834 std::vector<double> returnv1d;
838 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
842 for (
int i = 1; i <= h1d->GetNbinsX(); i++)
843 returnv1d.emplace_back(h1d->GetBinError(i));
854 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertTH2DToVector");
856 std::vector<std::vector<double>> returnv2d;
860 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
864 if (priority ==
"XY")
866 for (
int i = 1; i <= h2d->GetNbinsX(); i++)
868 std::vector<double> tempv1d;
869 for (
int j = 1; j <= h2d->GetNbinsY(); j++)
871 tempv1d.emplace_back(h2d->GetBinContent(i, j));
873 returnv2d.emplace_back(tempv1d);
876 else if (priority ==
"YX")
878 for (
int j = 1; j <= h2d->GetNbinsY(); j++)
880 std::vector<double> tempv1d;
881 for (
int i = 1; i <= h2d->GetNbinsX(); i++)
883 tempv1d.emplace_back(h2d->GetBinContent(i, j));
885 returnv2d.emplace_back(tempv1d);
902 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertTH2DErrorToVector");
904 std::vector<std::vector<double>> returnv2d;
908 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
912 if (priority ==
"XY")
914 for (
int i = 1; i <= h2d->GetNbinsX(); i++)
916 std::vector<double> tempv1d;
917 for (
int j = 1; j <= h2d->GetNbinsY(); j++)
919 tempv1d.emplace_back(h2d->GetBinError(i, j));
921 returnv2d.emplace_back(tempv1d);
924 else if (priority ==
"YX")
926 for (
int j = 1; j <= h2d->GetNbinsY(); j++)
928 std::vector<double> tempv1d;
929 for (
int i = 1; i <= h2d->GetNbinsX(); i++)
931 tempv1d.emplace_back(h2d->GetBinError(i, j));
933 returnv2d.emplace_back(tempv1d);
950 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertTH3DToVector");
952 std::vector<std::vector<std::vector<double>>> returnv3d;
956 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
960 if (priority ==
"XYZ")
962 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
964 std::vector<std::vector<double>> tempv2d;
965 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
967 std::vector<double> tempv1d;
968 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
970 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
972 tempv2d.emplace_back(tempv1d);
974 returnv3d.emplace_back(tempv2d);
977 else if (priority ==
"XZY")
979 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
981 std::vector<std::vector<double>> tempv2d;
982 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
984 std::vector<double> tempv1d;
985 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
987 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
989 tempv2d.emplace_back(tempv1d);
991 returnv3d.emplace_back(tempv2d);
994 else if (priority ==
"ZXY")
996 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
998 std::vector<std::vector<double>> tempv2d;
999 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
1001 std::vector<double> tempv1d;
1002 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
1004 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
1006 tempv2d.emplace_back(tempv1d);
1008 returnv3d.emplace_back(tempv2d);
1011 else if (priority ==
"ZYX")
1013 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
1015 std::vector<std::vector<double>> tempv2d;
1016 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
1018 std::vector<double> tempv1d;
1019 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
1021 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
1023 tempv2d.emplace_back(tempv1d);
1025 returnv3d.emplace_back(tempv2d);
1028 else if (priority ==
"YZX")
1030 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
1032 std::vector<std::vector<double>> tempv2d;
1033 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
1035 std::vector<double> tempv1d;
1036 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
1038 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
1040 tempv2d.emplace_back(tempv1d);
1042 returnv3d.emplace_back(tempv2d);
1045 else if (priority ==
"YXZ")
1047 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
1049 std::vector<std::vector<double>> tempv2d;
1050 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
1052 std::vector<double> tempv1d;
1053 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
1055 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
1057 tempv2d.emplace_back(tempv1d);
1059 returnv3d.emplace_back(tempv2d);
1076 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertTH3DErrorToVector");
1078 std::vector<std::vector<std::vector<double>>> returnv3d;
1082 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
1086 if (priority ==
"XYZ")
1088 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
1090 std::vector<std::vector<double>> tempv2d;
1091 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
1093 std::vector<double> tempv1d;
1094 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
1096 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1098 tempv2d.emplace_back(tempv1d);
1100 returnv3d.emplace_back(tempv2d);
1103 else if (priority ==
"XZY")
1105 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
1107 std::vector<std::vector<double>> tempv2d;
1108 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
1110 std::vector<double> tempv1d;
1111 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
1113 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1115 tempv2d.emplace_back(tempv1d);
1117 returnv3d.emplace_back(tempv2d);
1120 else if (priority ==
"ZXY")
1122 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
1124 std::vector<std::vector<double>> tempv2d;
1125 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
1127 std::vector<double> tempv1d;
1128 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
1130 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1132 tempv2d.emplace_back(tempv1d);
1134 returnv3d.emplace_back(tempv2d);
1137 else if (priority ==
"ZYX")
1139 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
1141 std::vector<std::vector<double>> tempv2d;
1142 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
1144 std::vector<double> tempv1d;
1145 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
1147 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1149 tempv2d.emplace_back(tempv1d);
1151 returnv3d.emplace_back(tempv2d);
1154 else if (priority ==
"YZX")
1156 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
1158 std::vector<std::vector<double>> tempv2d;
1159 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
1161 std::vector<double> tempv1d;
1162 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
1164 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1166 tempv2d.emplace_back(tempv1d);
1168 returnv3d.emplace_back(tempv2d);
1171 else if (priority ==
"YXZ")
1173 for (
int j = 1; j <= h3d->GetNbinsY(); j++)
1175 std::vector<std::vector<double>> tempv2d;
1176 for (
int i = 1; i <= h3d->GetNbinsX(); i++)
1178 std::vector<double> tempv1d;
1179 for (
int k = 1; k <= h3d->GetNbinsZ(); k++)
1181 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1183 tempv2d.emplace_back(tempv1d);
1185 returnv3d.emplace_back(tempv2d);
1201 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertVectorTH1DToTH1D");
1204 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
1208 std::vector<std::vector<double>> vc2d;
1209 std::vector<std::vector<double>> ve2d;
1211 for (
auto &h1d : vh1d)
1229 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertTH2DToVectorTH1D");
1232 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
1237 MSGUser()->MSG_ERROR(
"Result vector is empty!!!");
1244 if (vh1d.size() != vc2d.size())
1246 MSGUser()->MSG_ERROR(
"Result vector size incorrect or input hist incorrect!!!");
1250 for (
size_t i = 0; i < vh1d.size(); i++)
1262 auto msgguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertTH3DToVectorTH1D");
1265 MSGUser()->MSG_ERROR(
"Input hist not defined!!!");
1270 MSGUser()->MSG_ERROR(
"Result vector is empty!!!");
1277 if (vh1d.size() != vc3d.size())
1279 MSGUser()->MSG_ERROR(
"Result vector size incorrect or input hist incorrect!!!");
1283 for (
size_t i = 0; i < vh1d.size(); i++)
1285 if (vh1d[i].size() != vc3d[i].size())
1287 MSGUser()->MSG_ERROR(
"Result vector size incorrect or input hist incorrect!!!");
1291 for (
size_t j = 0; j < vh1d[i].size(); j++)
1303 auto titleguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertTH2DToMatrix");
1306 MSGUser()->MSG_ERROR(
"Target TH2D does not exist");
1307 return TMatrixD(0, 0);
1310 TMatrixD mat(h2d->GetNbinsX(), h2d->GetNbinsY());
1311 for (
int i = 0; i < h2d->GetNbinsX(); i++)
1312 for (
int j = 0; j < h2d->GetNbinsY(); j++)
1313 mat(i, j) = h2d->GetBinContent(i + 1, j + 1);
1323 auto titleguard =
MSGUser()->StartTitleWithGuard(
"HistTool::ConvertMatrixToTH2D");
1326 MSGUser()->MSG_ERROR(
"Target TH2D does not exist");
1329 if (h2d->GetNbinsX() != mat.GetNrows() || h2d->GetNbinsY() != mat.GetNcols())
1331 MSGUser()->MSG_ERROR(
"Target TH2D does not match input matrix");
1335 for (
int i = 0; i < h2d->GetNbinsX(); i++)
1336 for (
int j = 0; j < h2d->GetNbinsY(); j++)
1337 h2d->SetBinContent(i + 1, j + 1, mat(i, j));
static double AminusBoverAplusB(double A, double B, double A_err, double B_err)
Calculate the uncertainty of .
static double AoverB(double A, double B, double A_err, double B_err)
Calculate the uncertainty of .
static double AminusB(double A_err, double B_err)
Calculate the uncertainty of .