NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
HistTool.cxx
Go to the documentation of this file.
1//***************************************************************************************
4//***************************************************************************************
5
6#include "NAGASH/HistTool.h"
7
8using namespace NAGASH;
9using namespace std;
10
15void HistTool::ProcessHistLink(const TString &type, const std::vector<TH1 *> &input, TH1 *res)
16{
17 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ProcessHistLink");
18 if (type.TString::EqualTo("Asymmetry"))
19 {
20 if (input.size() != 2)
21 {
22 MSGUser()->MSG(MSGLevel::ERROR, "Hist Link Asymmetry needs two input hists, but now it is ", input.size());
23 return;
24 }
25 Asymmetry(input[0], input[1], res);
26 }
27 else if (type.TString::EqualTo("Delta"))
28 {
29 if (input.size() != 2)
30 {
31 MSGUser()->MSG(MSGLevel::ERROR, "Hist Link Delta needs two input hists, but now it is ", input.size());
32 return;
33 }
34 Delta(input[0], input[1], res);
35 }
36 else if (type.TString::EqualTo("Ratio"))
37 {
38 if (input.size() != 2)
39 {
40 MSGUser()->MSG(MSGLevel::ERROR, "Hist Link Ratio needs two input hists, but now it is ", input.size());
41 return;
42 }
43 Ratio(input[0], input[1], res);
44 }
45 else if (type.TString::EqualTo("Chi2"))
46 {
47 if (input.size() != 2)
48 {
49 MSGUser()->MSG(MSGLevel::ERROR, "Hist Link Chi2 needs two input hists, but now it is ", input.size());
50 return;
51 }
52 Chi2(input[0], input[1], res);
53 }
54 else if (type.TString::EqualTo("Pull"))
55 {
56 if (input.size() != 2)
57 {
58 MSGUser()->MSG(MSGLevel::ERROR, "Hist Link Pull needs two input hists, but now it is ", input.size());
59 return;
60 }
61 Pull(input[0], input[1], res);
62 }
63 else
64 MSGUser()->MSG(MSGLevel::ERROR, "Hist Link ", type.TString::Data(), " not supported!");
65}
66
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)
73{
74 auto titleguard = MSGUser()->StartTitleWithGuard("HistTool::ProcessHistLink");
75 // check if any hist is nullptr
76 for (size_t i = 0; i < input.size(); i++)
77 if (!input[i])
78 {
79 MSGUser()->MSG_ERROR("input hist ", i, " is nullptr");
80 return;
81 }
82
83 if (!res)
84 {
85 MSGUser()->MSG_ERROR("result hist is nullptr");
86 return;
87 }
88
89 // check the size of hists
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)
93 {
94 MSGUser()->MSG_ERROR("Input hist definition incorrect!!!");
95 return;
96 }
97
98 // fill content and error
99 for (int i = 1; i <= binnumx; i++)
100 for (int j = 1; j <= binnumy; j++)
101 for (int k = 1; k <= binnumz; k++)
102 {
103 std::vector<double> vcontent(input.size());
104 std::vector<double> verror(input.size());
105 for (size_t m = 0; m < input.size(); m++)
106 {
107 vcontent[m] = input[m]->GetBinContent(input[m]->GetBin(i, j, k));
108 verror[m] = input[m]->GetBinError(input[m]->GetBin(i, j, k));
109 }
110 res->SetBinContent(res->GetBin(i, j, k), contentfunction(vcontent));
111 res->SetBinError(res->GetBin(i, j, k), errorfunction(vcontent, verror));
112 }
113}
114
119void HistTool::ProcessHistLink(std::function<void(const std::vector<TH1 *> &, TH1 *)> func, const std::vector<TH1 *> &input, TH1 *res)
120{
121 auto titleguard = MSGUser()->StartTitleWithGuard("HistTool::ProcessHistLink");
122 // check if any hist is nullptr
123 for (size_t i = 0; i < input.size(); i++)
124 if (!input[i])
125 {
126 MSGUser()->MSG_ERROR("input hist ", i, " is nullptr");
127 return;
128 }
129
130 if (!res)
131 {
132 MSGUser()->MSG_ERROR("result hist is nullptr");
133 return;
134 }
135
136 func(input, res);
137}
138
143void HistTool::Asymmetry(TH1 *A, TH1 *B, TH1 *Asy)
144{
145 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::Asymmetry");
146 if (A == nullptr || B == nullptr)
147 {
148 MSGUser()->MSG_ERROR("Input hist not defined!!!");
149 return;
150 }
151 if (Asy == nullptr)
152 {
153 MSGUser()->MSG_ERROR("Result hist not defined!!!");
154 return;
155 }
156
157 int binnumx = A->GetNbinsX(), binnumy = A->GetNbinsY(), binnumz = A->GetNbinsZ();
158 if (B->GetNbinsX() != binnumx || B->GetNbinsY() != binnumy || B->GetNbinsZ() != binnumz)
159 {
160 MSGUser()->MSG_ERROR("Input hist definition incorrect!!!");
161 return;
162 }
163 if (Asy->GetNbinsX() != binnumx || Asy->GetNbinsY() != binnumy || Asy->GetNbinsZ() != binnumz)
164 {
165 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
166 return;
167 }
168
169 for (int i = 1; i <= A->GetNbinsX(); i++)
170 {
171 for (int j = 1; j <= A->GetNbinsY(); j++)
172 {
173 for (int k = 1; k <= A->GetNbinsZ(); k++)
174 {
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)
178 {
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));
181 }
182 else
183 {
184 Asy->SetBinContent(Asy->GetBin(i, j, k), 0);
185 Asy->SetBinError(Asy->GetBin(i, j, k), 0);
186 }
187 }
188 }
189 }
190}
191
197void HistTool::Delta(TH1 *A, TH1 *B, TH1 *D, bool dosep)
198{
199 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::Delta");
200 if (A == nullptr || B == nullptr)
201 {
202 MSGUser()->MSG_ERROR("Input hist not defined!!!");
203 return;
204 }
205 if (D == nullptr)
206 {
207 MSGUser()->MSG_ERROR("Result hist not defined!!!");
208 return;
209 }
210
211 int binnumx = A->GetNbinsX(), binnumy = A->GetNbinsY(), binnumz = A->GetNbinsZ();
212 if (B->GetNbinsX() != binnumx || B->GetNbinsY() != binnumy || B->GetNbinsZ() != binnumz)
213 {
214 MSGUser()->MSG_ERROR("Input hist definition incorrect!!!");
215 return;
216 }
217 if (D->GetNbinsX() != binnumx || D->GetNbinsY() != binnumy || D->GetNbinsZ() != binnumz)
218 {
219 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
220 return;
221 }
222
223 for (int i = 1; i <= binnumx; i++)
224 {
225 for (int j = 1; j <= binnumy; j++)
226 {
227 for (int k = 1; k <= binnumz; k++)
228 {
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)));
231
232 if (A == B && !dosep)
233 val_err = 0;
234
235 if (A == B && dosep)
236 val_err = A->GetBinError(A->GetBin(i, j, k));
237
238 if (A != B && dosep)
239 val_err = B->GetBinError(A->GetBin(i, j, k));
240
241 D->SetBinContent(D->GetBin(i, j, k), val);
242 D->SetBinError(D->GetBin(i, j, k), val_err);
243 }
244 }
245 }
246}
247
253void HistTool::Ratio(TH1 *A, TH1 *B, TH1 *R, bool dosep)
254{
255 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::Ratio");
256 if (A == nullptr || B == nullptr)
257 {
258 MSGUser()->MSG_ERROR("Input hist not defined!!!");
259 return;
260 }
261 if (R == nullptr)
262 {
263 MSGUser()->MSG_ERROR("Result hist not defined!!!");
264 return;
265 }
266
267 int binnumx = A->GetNbinsX(), binnumy = A->GetNbinsY(), binnumz = A->GetNbinsZ();
268 if (B->GetNbinsX() != binnumx || B->GetNbinsY() != binnumy || B->GetNbinsZ() != binnumz)
269 {
270 MSGUser()->MSG_ERROR("Input hist definition incorrect!!!");
271 return;
272 }
273 if (R->GetNbinsX() != binnumx || R->GetNbinsY() != binnumy || R->GetNbinsZ() != binnumz)
274 {
275 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
276 return;
277 }
278
279 bool NeedWARN = false;
280
281 double val;
282 double val_err;
283 for (int i = 1; i <= binnumx; i++)
284 {
285 for (int j = 1; j <= binnumy; j++)
286 {
287 for (int k = 1; k <= binnumz; k++)
288 {
289 if (B->GetBinContent(B->GetBin(i, j, k)) == 0)
290 {
291 if (A != B)
292 NeedWARN = true;
293 if (A == B)
294 {
295 R->SetBinContent(R->GetBin(i, j, k), 1);
296 R->SetBinError(R->GetBin(i, j, k), 0);
297 }
298 continue;
299 }
300 else
301 {
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)));
305 }
306
307 if (A == B && !dosep)
308 val_err = 0;
309
310 if (A == B && dosep)
311 val_err = A->GetBinError(A->GetBin(i, j, k)) / A->GetBinContent(A->GetBin(i, j, k));
312
313 if (A != B && dosep)
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)));
316
317 R->SetBinContent(R->GetBin(i, j, k), val);
318 R->SetBinError(R->GetBin(i, j, k), val_err);
319 }
320 }
321 }
322
323 if (NeedWARN)
324 MSGUser()->MSG_WARNING("Can not define a ratio for some bin!");
325}
326
331void HistTool::Chi2(TH1 *A, TH1 *B, TH1 *C)
332{
333 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::Chi2");
334 if (A == nullptr || B == nullptr)
335 {
336 MSGUser()->MSG_ERROR("Input hist not defined!!!");
337 return;
338 }
339 if (C == nullptr)
340 {
341 MSGUser()->MSG_ERROR("Result hist not defined!!!");
342 return;
343 }
344
345 int binnumx = A->GetNbinsX(), binnumy = A->GetNbinsY(), binnumz = A->GetNbinsZ();
346 if (B->GetNbinsX() != binnumx || B->GetNbinsY() != binnumy || B->GetNbinsZ() != binnumz)
347 {
348 MSGUser()->MSG_ERROR("Input hist definition incorrect!!!");
349 return;
350 }
351 if (C->GetNbinsX() != binnumx || C->GetNbinsY() != binnumy || C->GetNbinsZ() != binnumz)
352 {
353 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
354 return;
355 }
356
357 bool NeedWARN = false;
358 for (int i = 1; i <= A->GetNbinsX(); i++)
359 {
360 for (int j = 1; j <= A->GetNbinsY(); j++)
361 {
362 for (int k = 1; k <= A->GetNbinsZ(); k++)
363 {
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));
368 else
369 {
370 C->SetBinContent(C->GetBin(i, j, k), 0);
371 NeedWARN = true;
372 }
373 C->SetBinError(C->GetBin(i, j, k), 0);
374 }
375 }
376 }
377
378 if (NeedWARN)
379 MSGUser()->MSG_WARNING("Can not define a chi2 for some bin!");
380}
381
386void HistTool::Pull(TH1 *A, TH1 *B, TH1 *P)
387{
388 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::Pull");
389 if (A == nullptr || B == nullptr)
390 {
391 MSGUser()->MSG_ERROR("Input hist not defined!!!");
392 return;
393 }
394 if (P == nullptr)
395 {
396 MSGUser()->MSG_ERROR("Result hist not defined!!!");
397 return;
398 }
399
400 int binnumx = A->GetNbinsX(), binnumy = A->GetNbinsY(), binnumz = A->GetNbinsZ();
401 if (B->GetNbinsX() != binnumx || B->GetNbinsY() != binnumy || B->GetNbinsZ() != binnumz)
402 {
403 MSGUser()->MSG_ERROR("Input hist definition incorrect!!!");
404 return;
405 }
406 if (P->GetNbinsX() != binnumx || P->GetNbinsY() != binnumy || P->GetNbinsZ() != binnumz)
407 {
408 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
409 return;
410 }
411
412 bool NeedWARN = false;
413 for (int i = 1; i <= A->GetNbinsX(); i++)
414 {
415 for (int j = 1; j <= A->GetNbinsY(); j++)
416 {
417 for (int k = 1; k <= A->GetNbinsZ(); k++)
418 {
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));
423 else
424 {
425 P->SetBinContent(P->GetBin(i, j, k), 0);
426 NeedWARN = true;
427 }
428 P->SetBinError(P->GetBin(i, j, k), 0);
429 }
430 }
431 }
432 if (NeedWARN)
433 MSGUser()->MSG_WARNING("Can not define a pull for some bin!");
434}
435
442double HistTool::Chi2(TH1D *A, TH1D *B, TH2D *CorrA, TH2D *CorrB)
443{
444 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::Chi2");
445 if (A == nullptr || B == nullptr)
446 {
447 MSGUser()->MSG_ERROR("Input hist not defined!!!");
448 return 0;
449 }
450 int binnum = A->GetXaxis()->GetNbins();
451 if (B->GetXaxis()->GetNbins() != binnum)
452 {
453 MSGUser()->MSG_ERROR("Input hist definition incorrect!!!");
454 return 0;
455 }
456
457 if (CorrA)
458 if (CorrA->GetNbinsX() != binnum || CorrA->GetNbinsY() != binnum)
459 {
460 MSGUser()->MSG_ERROR("Input correlation histogram definition incorrect!!!");
461 return 0;
462 }
463
464 if (CorrB)
465 if (CorrB->GetNbinsX() != binnum || CorrB->GetNbinsY() != binnum)
466 {
467 MSGUser()->MSG_ERROR("Input correlation histogram definition incorrect!!!");
468 return 0;
469 }
470
471 TMatrixD covA(binnum, binnum);
472 TMatrixD covB(binnum, binnum);
473 TMatrixD totalcov(binnum, binnum);
474 if (CorrA)
475 covA = ConvertTH2DToMatrix(CorrA);
476 else
477 {
478 for (int i = 0; i < binnum; i++)
479 for (int j = 0; j < binnum; j++)
480 {
481 if (i != j)
482 covA(i, j) = 0;
483 else
484 covA(i, j) = 1;
485 }
486 }
487
488 if (CorrB)
489 covB = ConvertTH2DToMatrix(CorrB);
490 else
491 {
492 for (int i = 0; i < binnum; i++)
493 for (int j = 0; j < binnum; j++)
494 {
495 if (i != j)
496 covB(i, j) = 0;
497 else
498 covB(i, j) = 1;
499 }
500 }
501
502 for (int i = 0; i < binnum; i++)
503 for (int j = 0; j < binnum; j++)
504 {
505 covA(i, j) *= A->GetBinError(i + 1) * A->GetBinError(j + 1);
506 covB(i, j) *= B->GetBinError(i + 1) * B->GetBinError(j + 1);
507 }
508 totalcov = covA + covB;
509
510 auto invertedcov = totalcov.InvertFast();
511
512 // need to be modified to make correlation possible
513 double chi2 = 0;
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);
517
518 return chi2;
519}
520
524void HistTool::ConvertCovToCorr(TH2D *covar, TH2D *corr)
525{
526 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertCovToCorr");
527 if (covar == nullptr)
528 {
529 MSGUser()->MSG_ERROR("Input hist not defined!!!");
530 return;
531 }
532 if (corr == nullptr)
533 {
534 MSGUser()->MSG_ERROR("Result hist not defined!!!");
535 return;
536 }
537
538 int binnumx = covar->GetXaxis()->GetNbins(), binnumy = covar->GetYaxis()->GetNbins();
539 if (binnumx != binnumy)
540 {
541 MSGUser()->MSG_ERROR("Covariance matrix needs to be square matrix!!!");
542 return;
543 }
544 if (corr->GetXaxis()->GetNbins() != binnumx || corr->GetYaxis()->GetNbins() != binnumy)
545 {
546 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
547 return;
548 }
549
550 for (int i = 0; i < covar->GetXaxis()->GetNbins(); i++)
551 {
552 for (int j = 0; j < covar->GetYaxis()->GetNbins(); j++)
553 {
554 if (covar->GetBinContent(i + 1, i + 1) == 0 || covar->GetBinContent(j + 1, j + 1) == 0)
555 corr->SetBinContent(i + 1, j + 1, 0);
556 else
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);
559 }
560 }
561}
562
566void HistTool::ConvertCovToError(TH2D *hcov, TH1D *herr)
567{
568 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertCovToError");
569 if (hcov == nullptr)
570 {
571 MSGUser()->MSG_ERROR("Input hist not defined!!!");
572 return;
573 }
574 if (herr == nullptr)
575 {
576 MSGUser()->MSG_ERROR("Result hist not defined!!!");
577 return;
578 }
579
580 int binnumx = hcov->GetXaxis()->GetNbins(), binnumy = hcov->GetYaxis()->GetNbins();
581 if (binnumx != binnumy)
582 {
583 MSGUser()->MSG_ERROR("Covariance matrix needs to be square matrix!!!");
584 return;
585 }
586 if (herr->GetXaxis()->GetNbins() != binnumx)
587 {
588 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
589 return;
590 }
591
592 for (int i = 1; i <= hcov->GetNbinsX(); i++)
593 {
594 herr->SetBinContent(i, sqrt(hcov->GetBinContent(i, i)));
595 herr->SetBinError(i, 0);
596 }
597}
598
603void HistTool::ConvertCorrToCov(TH2D *corr, TH1D *h, TH2D *cov)
604{
605 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertCorrToCov");
606 if (corr == nullptr || h == nullptr)
607 {
608 MSGUser()->MSG_ERROR("Input hist not defined!!!");
609 return;
610 }
611 if (cov == nullptr)
612 {
613 MSGUser()->MSG_ERROR("Result hist not defined!!!");
614 return;
615 }
616
617 int binnumx = corr->GetXaxis()->GetNbins(), binnumy = corr->GetYaxis()->GetNbins();
618 if (binnumx != binnumy)
619 {
620 MSGUser()->MSG_ERROR("Correlation coefficient matrix needs to be square matrix!!!");
621 return;
622 }
623 if (h->GetXaxis()->GetNbins() != binnumx)
624 {
625 MSGUser()->MSG_ERROR("Input hist definition incorrect!!!");
626 return;
627 }
628 if (cov->GetXaxis()->GetNbins() != binnumx || cov->GetYaxis()->GetNbins() != binnumy)
629 {
630 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
631 return;
632 }
633
634 for (int i = 1; i <= cov->GetNbinsX(); i++)
635 {
636 for (int j = 1; j <= cov->GetNbinsY(); j++)
637 {
638 cov->SetBinContent(i, j, corr->GetBinContent(i, j) * h->GetBinError(i) * h->GetBinError(j));
639 cov->SetBinError(i, j, 0);
640 }
641 }
642}
643
648void HistTool::ConvertVectorToTH1D(TH1D *h1, const std::vector<double> &v1, const std::vector<double> &v1err)
649{
650 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertVectorToTH1D");
651 if (v1.empty())
652 {
653 MSGUser()->MSG_ERROR("Input vector is empty!!!");
654 return;
655 }
656 if (h1 == nullptr)
657 {
658 MSGUser()->MSG_ERROR("Result hist not defined!!!");
659 return;
660 }
661
662 int vecnum1 = v1.size();
663 if (vecnum1 != h1->GetXaxis()->GetNbins())
664 {
665 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
666 return;
667 }
668
669 for (size_t i = 0; i < v1.size(); i++)
670 {
671 h1->SetBinContent(i + 1, v1[i]);
672 h1->SetBinError(i + 1, 0);
673 }
674
675 for (size_t i = 0; i < v1err.size(); i++)
676 {
677 h1->SetBinError(i + 1, v1err[i]);
678 }
679}
680
685void HistTool::ConvertVectorToTH2D(TH2D *h2, const std::vector<std::vector<double>> &v2, const std::vector<std::vector<double>> &v2err)
686{
687 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertVectorToTH2D");
688 if (v2.empty())
689 {
690 MSGUser()->MSG_ERROR("Input vector is empty!!!");
691 return;
692 }
693 if (h2 == nullptr)
694 {
695 MSGUser()->MSG_ERROR("Result hist not defined!!!");
696 return;
697 }
698
699 int v2numx = v2.size();
700 int binnumx = h2->GetXaxis()->GetNbins(), binnumy = h2->GetYaxis()->GetNbins();
701 if (v2numx != binnumx)
702 {
703 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
704 return;
705 }
706
707 for (size_t i = 0; i < v2.size(); i++)
708 {
709 if ((int)v2.at(i).size() != binnumy)
710 {
711 MSGUser()->MSG_ERROR("Result hist definition incorrect or input vector incorrect!!!");
712 return;
713 }
714 }
715
716 for (size_t i = 0; i < v2.size(); i++)
717 {
718 for (size_t j = 0; j < v2.at(i).size(); j++)
719 {
720 h2->SetBinContent(i + 1, j + 1, v2[i][j]);
721 h2->SetBinError(i + 1, j + 1, 0);
722 }
723 }
724
725 for (size_t i = 0; i < v2err.size(); i++)
726 {
727 for (size_t j = 0; j < v2err.at(i).size(); j++)
728 {
729 h2->SetBinError(i + 1, j + 1, v2err[i][j]);
730 }
731 }
732}
733
738void HistTool::ConvertVectorToTH3D(TH3D *h3, const std::vector<std::vector<std::vector<double>>> &v3, const std::vector<std::vector<std::vector<double>>> &v3err)
739{
740 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertVectorToTH3D");
741 if (v3.empty())
742 {
743 MSGUser()->MSG_ERROR("Input vector is empty!!!");
744 return;
745 }
746 if (h3 == nullptr)
747 {
748 MSGUser()->MSG_ERROR("Result hist not defined!!!");
749 return;
750 }
751
752 int v3numx = v3.size();
753 int binnumx = h3->GetXaxis()->GetNbins(), binnumy = h3->GetYaxis()->GetNbins(), binnumz = h3->GetZaxis()->GetNbins();
754 if (v3numx != binnumx)
755 {
756 MSGUser()->MSG_ERROR("Result hist definition incorrect!!!");
757 return;
758 }
759
760 for (size_t i = 0; i < v3.size(); i++)
761 {
762 if (v3.at(i).empty())
763 {
764 MSGUser()->MSG_ERROR("Input vector is empty!!!");
765 return;
766 }
767 if ((int)v3.at(i).size() != binnumy)
768 {
769 MSGUser()->MSG_ERROR("Result hist definition incorrect or input vector incorrect!!!");
770 return;
771 }
772 for (size_t j = 0; j < v3.at(i).at(j).size(); j++)
773 {
774 if ((int)v3.at(i).at(j).size() != binnumz)
775 {
776 MSGUser()->MSG_ERROR("Result hist definition incorrect or input vector incorrect!!!");
777 return;
778 }
779 }
780 }
781
782 for (size_t i = 0; i < v3.size(); i++)
783 {
784 for (size_t j = 0; j < v3.at(i).size(); j++)
785 {
786 for (size_t k = 0; k < v3.at(j).at(j).size(); k++)
787 {
788 h3->SetBinContent(i + 1, j + 1, k + 1, v3[i][j][k]);
789 h3->SetBinError(i + 1, j + 1, k + 1, 0);
790 }
791 }
792 }
793
794 for (size_t i = 0; i < v3err.size(); i++)
795 {
796 for (size_t j = 0; j < v3err.at(i).size(); j++)
797 {
798 for (size_t k = 0; k < v3err.at(i).at(j).size(); k++)
799 {
800 h3->SetBinError(i + 1, j + 1, k + 1, v3err[i][j][k]);
801 }
802 }
803 }
804}
805
809std::vector<double> HistTool::ConvertTH1DToVector(TH1D *h1d)
810{
811 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertTH1DToVector");
812
813 std::vector<double> returnv1d;
814
815 if (h1d == nullptr)
816 {
817 MSGUser()->MSG_ERROR("Input hist not defined!!!");
818 return returnv1d;
819 }
820
821 for (int i = 1; i <= h1d->GetNbinsX(); i++)
822 returnv1d.emplace_back(h1d->GetBinContent(i));
823
824 return returnv1d;
825}
826
830std::vector<double> HistTool::ConvertTH1DErrorToVector(TH1D *h1d)
831{
832 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertTH1DErrorToVector");
833
834 std::vector<double> returnv1d;
835
836 if (h1d == nullptr)
837 {
838 MSGUser()->MSG_ERROR("Input hist not defined!!!");
839 return returnv1d;
840 }
841
842 for (int i = 1; i <= h1d->GetNbinsX(); i++)
843 returnv1d.emplace_back(h1d->GetBinError(i));
844
845 return returnv1d;
846}
847
852std::vector<std::vector<double>> HistTool::ConvertTH2DToVector(TH2D *h2d, const TString &priority)
853{
854 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertTH2DToVector");
855
856 std::vector<std::vector<double>> returnv2d;
857
858 if (h2d == nullptr)
859 {
860 MSGUser()->MSG_ERROR("Input hist not defined!!!");
861 return returnv2d;
862 }
863
864 if (priority == "XY")
865 {
866 for (int i = 1; i <= h2d->GetNbinsX(); i++)
867 {
868 std::vector<double> tempv1d;
869 for (int j = 1; j <= h2d->GetNbinsY(); j++)
870 {
871 tempv1d.emplace_back(h2d->GetBinContent(i, j));
872 }
873 returnv2d.emplace_back(tempv1d);
874 }
875 }
876 else if (priority == "YX")
877 {
878 for (int j = 1; j <= h2d->GetNbinsY(); j++)
879 {
880 std::vector<double> tempv1d;
881 for (int i = 1; i <= h2d->GetNbinsX(); i++)
882 {
883 tempv1d.emplace_back(h2d->GetBinContent(i, j));
884 }
885 returnv2d.emplace_back(tempv1d);
886 }
887 }
888 else
889 {
890 returnv2d = ConvertTH2DToVector(h2d);
891 }
892
893 return returnv2d;
894}
895
900std::vector<std::vector<double>> HistTool::ConvertTH2DErrorToVector(TH2D *h2d, const TString &priority)
901{
902 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertTH2DErrorToVector");
903
904 std::vector<std::vector<double>> returnv2d;
905
906 if (h2d == nullptr)
907 {
908 MSGUser()->MSG_ERROR("Input hist not defined!!!");
909 return returnv2d;
910 }
911
912 if (priority == "XY")
913 {
914 for (int i = 1; i <= h2d->GetNbinsX(); i++)
915 {
916 std::vector<double> tempv1d;
917 for (int j = 1; j <= h2d->GetNbinsY(); j++)
918 {
919 tempv1d.emplace_back(h2d->GetBinError(i, j));
920 }
921 returnv2d.emplace_back(tempv1d);
922 }
923 }
924 else if (priority == "YX")
925 {
926 for (int j = 1; j <= h2d->GetNbinsY(); j++)
927 {
928 std::vector<double> tempv1d;
929 for (int i = 1; i <= h2d->GetNbinsX(); i++)
930 {
931 tempv1d.emplace_back(h2d->GetBinError(i, j));
932 }
933 returnv2d.emplace_back(tempv1d);
934 }
935 }
936 else
937 {
938 returnv2d = ConvertTH2DErrorToVector(h2d);
939 }
940
941 return returnv2d;
942}
943
948std::vector<std::vector<std::vector<double>>> HistTool::ConvertTH3DToVector(TH3D *h3d, const TString &priority)
949{
950 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertTH3DToVector");
951
952 std::vector<std::vector<std::vector<double>>> returnv3d;
953
954 if (h3d == nullptr)
955 {
956 MSGUser()->MSG_ERROR("Input hist not defined!!!");
957 return returnv3d;
958 }
959
960 if (priority == "XYZ")
961 {
962 for (int i = 1; i <= h3d->GetNbinsX(); i++)
963 {
964 std::vector<std::vector<double>> tempv2d;
965 for (int j = 1; j <= h3d->GetNbinsY(); j++)
966 {
967 std::vector<double> tempv1d;
968 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
969 {
970 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
971 }
972 tempv2d.emplace_back(tempv1d);
973 }
974 returnv3d.emplace_back(tempv2d);
975 }
976 }
977 else if (priority == "XZY")
978 {
979 for (int i = 1; i <= h3d->GetNbinsX(); i++)
980 {
981 std::vector<std::vector<double>> tempv2d;
982 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
983 {
984 std::vector<double> tempv1d;
985 for (int j = 1; j <= h3d->GetNbinsY(); j++)
986 {
987 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
988 }
989 tempv2d.emplace_back(tempv1d);
990 }
991 returnv3d.emplace_back(tempv2d);
992 }
993 }
994 else if (priority == "ZXY")
995 {
996 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
997 {
998 std::vector<std::vector<double>> tempv2d;
999 for (int i = 1; i <= h3d->GetNbinsX(); i++)
1000 {
1001 std::vector<double> tempv1d;
1002 for (int j = 1; j <= h3d->GetNbinsY(); j++)
1003 {
1004 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
1005 }
1006 tempv2d.emplace_back(tempv1d);
1007 }
1008 returnv3d.emplace_back(tempv2d);
1009 }
1010 }
1011 else if (priority == "ZYX")
1012 {
1013 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
1014 {
1015 std::vector<std::vector<double>> tempv2d;
1016 for (int j = 1; j <= h3d->GetNbinsY(); j++)
1017 {
1018 std::vector<double> tempv1d;
1019 for (int i = 1; i <= h3d->GetNbinsX(); i++)
1020 {
1021 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
1022 }
1023 tempv2d.emplace_back(tempv1d);
1024 }
1025 returnv3d.emplace_back(tempv2d);
1026 }
1027 }
1028 else if (priority == "YZX")
1029 {
1030 for (int j = 1; j <= h3d->GetNbinsY(); j++)
1031 {
1032 std::vector<std::vector<double>> tempv2d;
1033 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
1034 {
1035 std::vector<double> tempv1d;
1036 for (int i = 1; i <= h3d->GetNbinsX(); i++)
1037 {
1038 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
1039 }
1040 tempv2d.emplace_back(tempv1d);
1041 }
1042 returnv3d.emplace_back(tempv2d);
1043 }
1044 }
1045 else if (priority == "YXZ")
1046 {
1047 for (int j = 1; j <= h3d->GetNbinsY(); j++)
1048 {
1049 std::vector<std::vector<double>> tempv2d;
1050 for (int i = 1; i <= h3d->GetNbinsX(); i++)
1051 {
1052 std::vector<double> tempv1d;
1053 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
1054 {
1055 tempv1d.emplace_back(h3d->GetBinContent(i, j, k));
1056 }
1057 tempv2d.emplace_back(tempv1d);
1058 }
1059 returnv3d.emplace_back(tempv2d);
1060 }
1061 }
1062 else
1063 {
1064 returnv3d = ConvertTH3DToVector(h3d);
1065 }
1066
1067 return returnv3d;
1068}
1069
1074std::vector<std::vector<std::vector<double>>> HistTool::ConvertTH3DErrorToVector(TH3D *h3d, const TString &priority)
1075{
1076 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertTH3DErrorToVector");
1077
1078 std::vector<std::vector<std::vector<double>>> returnv3d;
1079
1080 if (h3d == nullptr)
1081 {
1082 MSGUser()->MSG_ERROR("Input hist not defined!!!");
1083 return returnv3d;
1084 }
1085
1086 if (priority == "XYZ")
1087 {
1088 for (int i = 1; i <= h3d->GetNbinsX(); i++)
1089 {
1090 std::vector<std::vector<double>> tempv2d;
1091 for (int j = 1; j <= h3d->GetNbinsY(); j++)
1092 {
1093 std::vector<double> tempv1d;
1094 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
1095 {
1096 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1097 }
1098 tempv2d.emplace_back(tempv1d);
1099 }
1100 returnv3d.emplace_back(tempv2d);
1101 }
1102 }
1103 else if (priority == "XZY")
1104 {
1105 for (int i = 1; i <= h3d->GetNbinsX(); i++)
1106 {
1107 std::vector<std::vector<double>> tempv2d;
1108 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
1109 {
1110 std::vector<double> tempv1d;
1111 for (int j = 1; j <= h3d->GetNbinsY(); j++)
1112 {
1113 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1114 }
1115 tempv2d.emplace_back(tempv1d);
1116 }
1117 returnv3d.emplace_back(tempv2d);
1118 }
1119 }
1120 else if (priority == "ZXY")
1121 {
1122 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
1123 {
1124 std::vector<std::vector<double>> tempv2d;
1125 for (int i = 1; i <= h3d->GetNbinsX(); i++)
1126 {
1127 std::vector<double> tempv1d;
1128 for (int j = 1; j <= h3d->GetNbinsY(); j++)
1129 {
1130 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1131 }
1132 tempv2d.emplace_back(tempv1d);
1133 }
1134 returnv3d.emplace_back(tempv2d);
1135 }
1136 }
1137 else if (priority == "ZYX")
1138 {
1139 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
1140 {
1141 std::vector<std::vector<double>> tempv2d;
1142 for (int j = 1; j <= h3d->GetNbinsY(); j++)
1143 {
1144 std::vector<double> tempv1d;
1145 for (int i = 1; i <= h3d->GetNbinsX(); i++)
1146 {
1147 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1148 }
1149 tempv2d.emplace_back(tempv1d);
1150 }
1151 returnv3d.emplace_back(tempv2d);
1152 }
1153 }
1154 else if (priority == "YZX")
1155 {
1156 for (int j = 1; j <= h3d->GetNbinsY(); j++)
1157 {
1158 std::vector<std::vector<double>> tempv2d;
1159 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
1160 {
1161 std::vector<double> tempv1d;
1162 for (int i = 1; i <= h3d->GetNbinsX(); i++)
1163 {
1164 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1165 }
1166 tempv2d.emplace_back(tempv1d);
1167 }
1168 returnv3d.emplace_back(tempv2d);
1169 }
1170 }
1171 else if (priority == "YXZ")
1172 {
1173 for (int j = 1; j <= h3d->GetNbinsY(); j++)
1174 {
1175 std::vector<std::vector<double>> tempv2d;
1176 for (int i = 1; i <= h3d->GetNbinsX(); i++)
1177 {
1178 std::vector<double> tempv1d;
1179 for (int k = 1; k <= h3d->GetNbinsZ(); k++)
1180 {
1181 tempv1d.emplace_back(h3d->GetBinError(i, j, k));
1182 }
1183 tempv2d.emplace_back(tempv1d);
1184 }
1185 returnv3d.emplace_back(tempv2d);
1186 }
1187 }
1188 else
1189 {
1190 returnv3d = ConvertTH3DErrorToVector(h3d);
1191 }
1192
1193 return returnv3d;
1194}
1195
1199void HistTool::ConvertVectorTH1DToTH1D(const std::vector<TH1D *> &vh1d, TH1D *targeth1d)
1200{
1201 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertVectorTH1DToTH1D");
1202 if (vh1d.empty())
1203 {
1204 MSGUser()->MSG_ERROR("Input hist not defined!!!");
1205 return;
1206 }
1207
1208 std::vector<std::vector<double>> vc2d;
1209 std::vector<std::vector<double>> ve2d;
1210
1211 for (auto &h1d : vh1d)
1212 {
1213 vc2d.emplace_back(ConvertTH1DToVector(h1d));
1214 ve2d.emplace_back(ConvertTH1DErrorToVector(h1d));
1215 }
1216
1217 auto vc1d = ConvertVector2DToVector1D(vc2d);
1218 auto ve1d = ConvertVector2DToVector1D(ve2d);
1219
1220 ConvertVectorToTH1D(targeth1d, vc1d, ve1d);
1221}
1222
1227void HistTool::ConvertTH2DToVectorTH1D(TH2D *h2d, const std::vector<TH1D *> &vh1d, const TString &priority)
1228{
1229 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertTH2DToVectorTH1D");
1230 if (h2d == nullptr)
1231 {
1232 MSGUser()->MSG_ERROR("Input hist not defined!!!");
1233 return;
1234 }
1235 if (vh1d.empty())
1236 {
1237 MSGUser()->MSG_ERROR("Result vector is empty!!!");
1238 return;
1239 }
1240
1241 auto vc2d = ConvertTH2DToVector(h2d, priority);
1242 auto ve2d = ConvertTH2DErrorToVector(h2d, priority);
1243
1244 if (vh1d.size() != vc2d.size())
1245 {
1246 MSGUser()->MSG_ERROR("Result vector size incorrect or input hist incorrect!!!");
1247 return;
1248 }
1249
1250 for (size_t i = 0; i < vh1d.size(); i++)
1251 {
1252 ConvertVectorToTH1D(vh1d[i], vc2d[i], ve2d[i]);
1253 }
1254}
1255
1260void HistTool::ConvertTH3DToVectorTH1D(TH3D *h3d, const std::vector<std::vector<TH1D *>> &vh1d, const TString &priority)
1261{
1262 auto msgguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertTH3DToVectorTH1D");
1263 if (h3d == nullptr)
1264 {
1265 MSGUser()->MSG_ERROR("Input hist not defined!!!");
1266 return;
1267 }
1268 if (vh1d.empty())
1269 {
1270 MSGUser()->MSG_ERROR("Result vector is empty!!!");
1271 return;
1272 }
1273
1274 auto vc3d = ConvertTH3DToVector(h3d, priority);
1275 auto ve3d = ConvertTH3DErrorToVector(h3d, priority);
1276
1277 if (vh1d.size() != vc3d.size())
1278 {
1279 MSGUser()->MSG_ERROR("Result vector size incorrect or input hist incorrect!!!");
1280 return;
1281 }
1282
1283 for (size_t i = 0; i < vh1d.size(); i++)
1284 {
1285 if (vh1d[i].size() != vc3d[i].size())
1286 {
1287 MSGUser()->MSG_ERROR("Result vector size incorrect or input hist incorrect!!!");
1288 return;
1289 }
1290
1291 for (size_t j = 0; j < vh1d[i].size(); j++)
1292 {
1293 ConvertVectorToTH1D(vh1d[i][j], vc3d[i][j], ve3d[i][j]);
1294 }
1295 }
1296}
1297
1302{
1303 auto titleguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertTH2DToMatrix");
1304 if (!h2d)
1305 {
1306 MSGUser()->MSG_ERROR("Target TH2D does not exist");
1307 return TMatrixD(0, 0);
1308 }
1309
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);
1314
1315 return mat;
1316}
1317
1321void HistTool::ConvertMatrixToTH2D(const TMatrixD &mat, TH2D *h2d)
1322{
1323 auto titleguard = MSGUser()->StartTitleWithGuard("HistTool::ConvertMatrixToTH2D");
1324 if (!h2d)
1325 {
1326 MSGUser()->MSG_ERROR("Target TH2D does not exist");
1327 return;
1328 }
1329 if (h2d->GetNbinsX() != mat.GetNrows() || h2d->GetNbinsY() != mat.GetNcols())
1330 {
1331 MSGUser()->MSG_ERROR("Target TH2D does not match input matrix");
1332 return;
1333 }
1334
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));
1338}
void ConvertCorrToCov(TH2D *corr, TH1D *h, TH2D *cov)
Convert correlation matrix to covariance matrix.
Definition HistTool.cxx:603
void ConvertCovToError(TH2D *hcov, TH1D *herr)
Convert covariance matrix to error histogram.
Definition HistTool.cxx:566
std::vector< std::vector< double > > ConvertTH2DToVector(TH2D *h2d, const TString &priority="XY")
Convert the contents of a 2D histogram to a vector.
Definition HistTool.cxx:852
void ConvertVectorToTH3D(TH3D *h3, const std::vector< std::vector< std::vector< double > > > &v3, const std::vector< std::vector< std::vector< double > > > &v3err=std::vector< std::vector< std::vector< double > > >())
Convert vectors to a 3D histogram.
Definition HistTool.cxx:738
static std::vector< T > ConvertVector2DToVector1D(const std::vector< std::vector< T > > &v2d)
Flatten 2D vector to a 1D vector.
Definition HistTool.h:70
void Chi2(TH1 *A, TH1 *B, TH1 *C)
Calculate the between two histograms.
Definition HistTool.cxx:331
void Asymmetry(TH1 *A, TH1 *B, TH1 *Asy)
Calculate the asymmetry between two histograms.
Definition HistTool.cxx:143
void ConvertCovToCorr(TH2D *covar, TH2D *corr)
Convert covariance matrix to correlation matrix.
Definition HistTool.cxx:524
std::vector< double > ConvertTH1DToVector(TH1D *h1d)
Convert the contents of a 1D histogram to a vector.
Definition HistTool.cxx:809
void Ratio(TH1 *A, TH1 *B, TH1 *R, bool dosep=false)
Calculate the ratio between two histograms.
Definition HistTool.cxx:253
std::vector< double > ConvertTH1DErrorToVector(TH1D *h1d)
Convert the errors of a 1D histogram to a vector.
Definition HistTool.cxx:830
std::vector< std::vector< std::vector< double > > > ConvertTH3DErrorToVector(TH3D *h3d, const TString &priority="XYZ")
Convert the errors of a 3D histogram to a vector.
void ConvertTH3DToVectorTH1D(TH3D *h3d, const std::vector< std::vector< TH1D * > > &vh1d, const TString &priority="XYZ")
Convert a 3D histogram into a 2D vector of 1D histograms.
void Pull(TH1 *A, TH1 *B, TH1 *P)
Calculate the pull between two histograms.
Definition HistTool.cxx:386
Uncertainty unc
Definition HistTool.h:62
void ConvertVectorTH1DToTH1D(const std::vector< TH1D * > &vh1d, TH1D *targeth1d)
Fuse a vector of 1D histograms into one 1D histogram.
void ConvertVectorToTH2D(TH2D *h2, const std::vector< std::vector< double > > &v2, const std::vector< std::vector< double > > &v2err=std::vector< std::vector< double > >())
Convert vectors to a 2D histogram.
Definition HistTool.cxx:685
void ConvertMatrixToTH2D(const TMatrixD &mat, TH2D *h2d)
Convert a matrix to a 2D histogram.
TMatrixD ConvertTH2DToMatrix(TH2D *h2d)
Convert a 2D histogram to a matrix.
void ConvertTH2DToVectorTH1D(TH2D *h2d, const std::vector< TH1D * > &vh1d, const TString &priority="XY")
Convert a 2D histogram into a vector of 1D histograms.
void Delta(TH1 *A, TH1 *B, TH1 *D, bool dosep=false)
Calculate the difference between two histograms.
Definition HistTool.cxx:197
void ConvertVectorToTH1D(TH1D *h1, const std::vector< double > &v1, const std::vector< double > &v1err=std::vector< double >())
Convert vectors to a histogram.
Definition HistTool.cxx:648
std::vector< std::vector< double > > ConvertTH2DErrorToVector(TH2D *h2d, const TString &priority="XY")
Convert the errors of a 2D histogram to a vector.
Definition HistTool.cxx:900
std::vector< std::vector< std::vector< double > > > ConvertTH3DToVector(TH3D *h3d, const TString &priority="XYZ")
Convert the contents of a 3D histogram to a vector.
Definition HistTool.cxx:948
void ProcessHistLink(const TString &type, const std::vector< TH1 * > &input, TH1 *res)
constructor
Definition HistTool.cxx:15
std::shared_ptr< MSGTool > MSGUser()
return the MSGTool inside.
Definition Tool.h:91
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 .