10#include "DividedHisto.h"
13#include "HistoStyle.h"
14#include "HistogramManager.h"
28#include <TCollection.h>
35#include <TObjString.h>
38#include <TVirtualPad.h>
71 for (
int i = 0; i <
fDim; i++) {
85 fBinomial(other.fBinomial),
88 fAxisName(other.fAxisName),
89 fComment(other.fComment),
91 if (other.
fLabels) { fLabels = (TList*) other.fLabels->Clone(); }
93 fNum = (TH1*) other.fNum->Clone();
97 fDen = (TH1*) other.fDen->Clone();
102 for (
int i = 0; i <
fDim; i++) {
110 for (
int i = 0; i <
fDim; i++) {
113 Double_t num =
fNum->Integral(binMinX, binMaxX);
116 Double_t den =
fDen->Integral(binMinX, binMaxX);
117 Double_t scale = 1.0;
119 Cout::PrintInfo(
"Numerator integral is zero, set scale to one", Hal::EInfo::kLowWarning);
124 Cout::PrintInfo(Form(
"Same norm min and norm max on %i axis", i), Hal::EInfo::kLowWarning);
127 if (scale == 0.0) scale = 1.0;
136 if (fNumIsCloned &&
fNum != NULL)
delete fNum;
138 Cout::PrintInfo(
"HalDividedHisto - trying to assign NULL Numerator", Hal::EInfo::kLowWarning);
142 TString option = opt;
143 if (option.EqualTo(
"clone")) {
144 fNumIsCloned = kTRUE;
145 fNum = (TH1*) num->Clone();
147 fNumIsCloned = kFALSE;
153 if (fDenIsCloned &&
fDen != NULL)
delete fDen;
155 Cout::PrintInfo(
"HalDividedHisto - trying to assign NULL Denominator", Hal::EInfo::kLowWarning);
159 TString option = opt;
160 if (option.EqualTo(
"clone")) {
161 fDenIsCloned = kTRUE;
162 fDen = (TH1*) den->Clone();
164 fDenIsCloned = kFALSE;
179 TH1* res = (TH1*)
fNum->Clone();
180 TString name = res->GetTitle();
181 name = name +
"Divided";
184 res->Divide(res,
fDen, 1, 1,
"B");
195 Cout::PrintInfo(
"HalDividedHisto too small norm axis", Hal::EInfo::kLowWarning);
197 }
else if (axis >
fDim) {
198 Cout::PrintInfo((
"HalDividedHist too large norm axis"), Hal::EInfo::kLowWarning);
204 }
else if (min == max) {
205 Cout::PrintInfo(
"HalDividedHisto min == max", Hal::EInfo::kLowWarning);
216 if (div->
fDim != this->fDim) {
217 Cout::PrintInfo(Form(
"Invalid dimensions in %s and %s", this->ClassName(), h->ClassName()), Hal::EInfo::kCriticalError);
219 for (
int i = 0; i <
fDim; i++) {
221 Cout::PrintInfo(
"Invalid minimum values in HalDividedHisto", Hal::EInfo::kError);
223 Cout::PrintInfo(
"Invalid maximum values in HalDividedHisto", Hal::EInfo::kError);
226 if ((this->
fScale == 0 && div->
fScale != 0) || (this->fScale > 0 && div->
fScale == 0)) {
242 case 1: h->GetYaxis()->SetTitle(
fAxisName);
break;
243 case 2: h->GetZaxis()->SetTitle(
fAxisName);
break;
252 Cout::PrintInfo(Form(
"%s::GetNormMin invalid no", ClassName()), Hal::EInfo::kLowWarning);
258 Cout::PrintInfo(Form(
"%s::GetNormMax invalid no", ClassName()), Hal::EInfo::kLowWarning);
265 Bool_t batch = gROOT->IsBatch();
266 TString path = Form(
"%s/divided_%i", dir.Data(), counter);
267 gSystem->MakeDirectory(path);
268 gROOT->SetBatch(kTRUE);
269 TCanvas* c1 =
new TCanvas(
"canvas",
"canvas", 0, 0, 1000, 1500);
275 TH1* num = (TH1*)
GetNum()->Clone();
276 TH1* den = (TH1*)
GetDen()->Clone();
277 den->SetLineColor(kRed);
278 num->SetLineColor(kGreen);
281 TLegend* leg =
new TLegend(0.4, 0.8, 0.9, 0.9);
282 leg->AddEntry(num,
"Numerator",
"LPM");
283 leg->AddEntry(den,
"Denominator",
"LPM");
285 gSystem->mkdir(path);
286 c1->SaveAs(Form(
"%s/divided.root", path.Data()));
292 gROOT->SetBatch(batch);
300 TString path = Form(
"%s/divided_%i", dir.Data(), counter);
301 gSystem->MakeDirectory(path);
302 TString filename = Form(
"%s/divided.html", path.Data());
305 Double_t* min =
new Double_t[dimN];
306 Double_t* max =
new Double_t[dimN];
307 for (
int i = 0; i < dimN; i++) {
312 HtmlRow row1(
"",
"dark_blue",
"");
316 HtmlRow row2(
"",
"dark_blue",
"");
320 HtmlRow row3(
"",
"dark_blue",
"");
325 HtmlRow rowS(
"",
"dark_blue",
"");
332 for (
int i = 0; i < dimN; i++) {
335 case 0: label =
"x";
break;
336 case 1: label =
"y";
break;
337 default: label =
"z";
break;
339 HtmlRow row4(
"",
"dark_blue",
"");
346 HtmlRow row5(
"",
"dark_blue",
"");
351 HtmlRow row5(
"",
"dark_blue",
"");
356 file.AddContent(table);
358 HtmlRow row2_1(
"",
"dark_blue",
"");
363 for (
int i = 0; i <
fLabels->GetEntries(); i++) {
364 TObjString* obj = (TObjString*)
fLabels->At(i);
365 HtmlRow singleRow(
"",
"light_blue",
"");
370 file.AddContent(table2);
371 TString file_name = Form(
"%s/divided.root", path.Data());
372 std::ifstream f(file_name.Data());
376 file.AddStringContent(
GetPic());
379 return HtmlCore::GetUrl(Form(
"divided_%i/divided.html", counter), this->ClassName());
383 TObjString* obj_str = (TObjString*)
fLabels->At(i);
384 if (obj_str == NULL)
return "";
385 return obj_str->GetString();
391 TIter iterator(collection);
401 TVirtualPad* c1 = gPad;
411 TString option = opt;
413 Cout::PrintInfo(
"lack of numerator and/or denominator folding cannot be done", Hal::EInfo::kLowWarning);
417 if (Hal::Std::FindParam(option,
"x")) {
418 ax =
fNum->GetXaxis();
419 }
else if (Hal::Std::FindParam(option,
"y")) {
420 ax =
fNum->GetYaxis();
421 }
else if (Hal::Std::FindParam(option,
"z")) {
422 ax =
fNum->GetZaxis();
424 Int_t bin = ax->FindBin(val);
425 Double_t cent = ax->GetBinCenter(bin);
426 Double_t low = ax->GetBinLowEdge(bin);
427 if (TMath::Abs(cent - val) > 1E-10 && TMath::Abs(low - val) > 1E-10) {
428 Cout::PrintInfo(
"value of folding is not equal a bin center of bin edge, folding "
430 Hal::EInfo::kLowWarning);
438 TH1* num_c = (TH1*)
fNum->Clone();
439 TH1* den_c = (TH1*)
fDen->Clone();
440 Double_t min =
fNum->GetXaxis()->GetBinLowEdge(1);
441 Double_t max =
fNum->GetXaxis()->GetBinUpEdge(
fNum->GetNbinsX());
442 Double_t period = max - min;
443 Double_t middle_bin =
fNum->GetXaxis()->FindBin(val);
444 middle_bin =
fNum->GetBinCenter(middle_bin);
445 for (
int i = 1; i <=
fNum->GetNbinsX(); i++) {
446 Double_t x =
fNum->GetBinCenter(i);
447 Double_t op_x = 2.0 * val - x;
448 if (op_x > max) op_x = op_x - period;
449 if (op_x <= min) op_x = op_x + period;
450 Int_t j =
fNum->FindBin(op_x);
451 Double_t N1 = num_c->GetBinContent(i);
452 Double_t NE1 = num_c->GetBinError(i);
453 Double_t D1 = den_c->GetBinContent(i);
454 Double_t DE1 = den_c->GetBinError(i);
455 Double_t N2 = num_c->GetBinContent(j);
456 Double_t NE2 = num_c->GetBinError(j);
457 Double_t D2 = den_c->GetBinContent(j);
458 Double_t DE2 = den_c->GetBinError(j);
459 Double_t Ncontent = N1 + N2;
460 Double_t Nerror = TMath::Sqrt(NE1 * NE1 + NE2 * NE2);
461 Double_t Dcontent = D1 + D2;
462 Double_t Derror = TMath::Sqrt(DE1 * DE1 + DE2 * DE2);
463 fNum->SetBinContent(i, Ncontent);
464 fNum->SetBinError(i, Nerror);
465 fDen->SetBinContent(i, Dcontent);
466 fDen->SetBinError(i, Derror);
472 DividedHisto1D::~DividedHisto1D() {
473 if (
fNum && fNumIsCloned) {
delete fNum; }
474 if (
fDen && fDenIsCloned) {
delete fDen; }
482 for (
int i = 0; i <
fDim; i++) {
483 Double_t scale = 1.0;
485 Cout::PrintInfo(Form(
"Same norm min and norm max on %i axis", i), Hal::EInfo::kLowWarning);
491 Double_t num = ((TH2*)
fNum)->Integral(binMinX, binMaxX, binMinY, binMaxY);
496 Double_t den = ((TH2*)
fDen)->Integral(binMinX, binMaxX, binMinY, binMaxY);
498 Cout::PrintInfo(
"Numerator integral is zero, set scale to one", Hal::EInfo::kLowWarning);
513 TString path = Form(
"%s/divided_%i", dir.Data(), counter);
514 gSystem->MakeDirectory(path);
515 Bool_t batch = gROOT->IsBatch();
516 gROOT->SetBatch(kTRUE);
517 TCanvas* c1 =
new TCanvas(
"canvas",
"canvas", 0, 0, 1000, 1500);
520 TH2* cf = (TH2*)
GetHist(kTRUE);
523 TH2* num = (TH2*)
GetNum()->Clone();
524 TH2* den = (TH2*)
GetDen()->Clone();
529 c1->SaveAs(Form(
"%s/divided_%i/divided.root", dir.Data(), counter));
531 gROOT->SetBatch(batch);
547 if (Hal::Std::FindParam(opt,
"x")) {
548 X =
fNum->GetXaxis();
549 Y =
fNum->GetYaxis();
552 Y =
fNum->GetXaxis();
553 X =
fNum->GetYaxis();
555 TH2* num_c = (TH2*)
fNum->Clone();
556 TH2* den_c = (TH2*)
fDen->Clone();
557 Double_t min = X->GetBinLowEdge(1);
558 Double_t max = X->GetBinUpEdge(X->GetNbins());
559 Double_t period = max - min;
560 Double_t middle_bin = X->FindBin(val);
561 middle_bin = X->GetBinCenter(middle_bin);
562 for (
int i = 1; i <= X->GetNbins(); i++) {
563 Double_t x = X->GetBinCenter(i);
564 Double_t op_x = 2.0 * val - x;
565 if (op_x > max) op_x = op_x - period;
566 if (op_x <= min) op_x = op_x + period;
567 Int_t j = X->FindBin(op_x);
568 for (
int k = 1; k <= Y->GetNbins(); k++) {
581 Double_t N1 = num_c->GetBinContent(a, b);
582 Double_t NE1 = num_c->GetBinError(a, b);
583 Double_t D1 = den_c->GetBinContent(a, b);
584 Double_t DE1 = den_c->GetBinError(a, b);
585 Double_t N2 = num_c->GetBinContent(c, d);
586 Double_t NE2 = num_c->GetBinError(c, d);
587 Double_t D2 = den_c->GetBinContent(c, d);
588 Double_t DE2 = den_c->GetBinError(c, d);
589 Double_t Ncontent = N1 + N2;
590 Double_t Nerror = TMath::Sqrt(NE1 * NE1 + NE2 * NE2);
591 Double_t Dcontent = D1 + D2;
592 Double_t Derror = TMath::Sqrt(DE1 * DE1 + DE2 * DE2);
593 fNum->SetBinContent(a, b, Ncontent);
594 fNum->SetBinError(a, b, Nerror);
595 fDen->SetBinContent(a, b, Dcontent);
596 fDen->SetBinError(a, b, Derror);
604 TString option = opt;
605 if (option.Length() == 1) {
610 TH2* num_c = (TH2*)
fNum->Clone();
611 TH2* den_c = (TH2*)
fDen->Clone();
612 Double_t minX =
fNum->GetXaxis()->GetBinLowEdge(1);
613 Double_t maxX =
fNum->GetXaxis()->GetBinUpEdge(
fNum->GetNbinsX());
614 Double_t minY =
fNum->GetYaxis()->GetBinLowEdge(1);
615 Double_t maxY =
fNum->GetYaxis()->GetBinUpEdge(
fNum->GetNbinsY());
616 Double_t periodX = maxX - minX;
617 Double_t periodY = maxY - minY;
618 for (
int i = 1; i <=
fNum->GetNbinsX(); i++) {
619 for (
int j = 1; j <=
fNum->GetNbinsY(); j++) {
620 Double_t x =
fNum->GetXaxis()->GetBinCenter(i);
621 Double_t y =
fNum->GetYaxis()->GetBinCenter(j);
622 Double_t op_x = 2.0 * valX - x;
623 Double_t op_y = 2.0 * valY - y;
624 if (op_x > maxX) op_x = op_x - periodX;
625 if (op_x <= minX) op_x = op_x + periodX;
626 if (op_y > maxY) op_y = op_y - periodY;
627 if (op_y <= minY) op_y = op_y + periodY;
628 Int_t k =
fNum->GetXaxis()->FindBin(op_x);
629 Int_t l =
fNum->GetYaxis()->FindBin(op_y);
630 Double_t N1 = num_c->GetBinContent(i, j);
631 Double_t NE1 = num_c->GetBinError(i, j);
632 Double_t D1 = den_c->GetBinContent(i, j);
633 Double_t DE1 = den_c->GetBinError(i, j);
634 Double_t N2 = num_c->GetBinContent(k, l);
635 Double_t NE2 = num_c->GetBinError(k, l);
636 Double_t D2 = den_c->GetBinContent(k, l);
637 Double_t DE2 = den_c->GetBinError(k, l);
638 Double_t Ncontent = N1 + N2;
639 Double_t Nerror = TMath::Sqrt(NE1 * NE1 + NE2 * NE2);
640 Double_t Dcontent = D1 + D2;
641 Double_t Derror = TMath::Sqrt(DE1 * DE1 + DE2 * DE2);
642 fNum->SetBinContent(i, j, Ncontent);
643 fNum->SetBinError(i, j, Nerror);
644 fDen->SetBinContent(i, j, Dcontent);
645 fDen->SetBinError(i, j, Derror);
653 TString option = opt;
655 Cout::PrintInfo(
"lack of numerator and/or denominator folding cannot be done", Hal::EInfo::kLowWarning);
660 if (option.EqualTo(
"yx")) {
661 Double_t temp = valX;
665 ax =
fNum->GetXaxis();
666 ay =
fNum->GetYaxis();
668 if (option.EqualTo(
"zy")) {
669 Double_t temp = valX;
673 ax =
fNum->GetYaxis();
674 ay =
fNum->GetZaxis();
676 if (option.EqualTo(
"zx")) {
677 Double_t temp = valX;
681 ax =
fNum->GetXaxis();
682 ay =
fNum->GetZaxis();
684 if (option.EqualTo(
"x")) {
685 ax =
fNum->GetYaxis();
686 ay =
fNum->GetZaxis();
688 if (option.EqualTo(
"y")) {
689 ax =
fNum->GetXaxis();
690 ay =
fNum->GetZaxis();
692 if (option.EqualTo(
"z")) {
693 ax =
fNum->GetXaxis();
694 ay =
fNum->GetYaxis();
696 if (option.EqualTo(
"xy")) {
697 ax =
fNum->GetXaxis();
698 ay =
fNum->GetYaxis();
700 if (option.EqualTo(
"yz")) {
701 ax =
fNum->GetYaxis();
702 ay =
fNum->GetZaxis();
704 if (option.EqualTo(
"xz")) {
705 ax =
fNum->GetXaxis();
706 ay =
fNum->GetZaxis();
708 if (ax == NULL || ay == NULL) {
709 Cout::PrintInfo(
"Wrong option in 2D folding", Hal::EInfo::kLowWarning);
712 Int_t binX = ax->FindBin(valX);
713 Int_t binY = ay->FindBin(valY);
714 Double_t centX = ax->GetBinCenter(binX);
715 Double_t lowX = ax->GetBinLowEdge(binX);
716 Double_t centY = ay->GetBinCenter(binY);
717 Double_t lowY = ay->GetBinLowEdge(binY);
718 if (TMath::Abs(centX - valX) > 1E-10 && TMath::Abs(lowX - valX) > 1E-10) {
719 Cout::PrintInfo(
"value of folding on X axis is not equal a bin center of bin edge, "
720 "folding cannot be done",
721 Hal::EInfo::kLowWarning);
724 if (TMath::Abs(centY - valY) > 1E-10 && TMath::Abs(lowY - valY) > 1E-10) {
725 Cout::PrintInfo(
"value of folding on Y axis is not equal a bin center of bin edge, "
726 "folding cannot be done",
727 Hal::EInfo::kLowWarning);
735 TVirtualPad* c1 = gPad;
736 if (!this->InheritsFrom(
"Hal::DividedHisto3D")) {
746 DividedHisto2D::~DividedHisto2D() {}
750 for (
int i = 0; i <
fDim; i++) {
751 Double_t scale = 1.0;
753 Cout::PrintInfo(Form(
"Same norm min and norm max on %i axis", i), Hal::EInfo::kLowWarning);
763 Double_t num = ((TH3*)
fNum)->Integral(binMinX, binMaxX, binMinY, binMaxY, binMinZ, binMaxZ);
772 Double_t den = ((TH3*)
fDen)->Integral(binMinX, binMaxX, binMinY, binMaxY, binMinZ, binMaxZ);
775 Cout::PrintInfo(
"Numerator integral is zero, set scale to one", Hal::EInfo::kLowWarning);
806 TString nameX = axX.GetName();
807 if (nameX.Length()) {
808 GetNum()->GetXaxis()->SetTitle(nameX);
809 GetDen()->GetXaxis()->SetTitle(nameX);
811 TString nameY = axY.GetName();
812 if (nameY.Length()) {
813 GetNum()->GetYaxis()->SetTitle(nameY);
814 GetDen()->GetYaxis()->SetTitle(nameY);
816 TString nameZ = axZ.GetName();
817 if (nameZ.Length()) {
818 GetNum()->GetZaxis()->SetTitle(nameZ);
819 GetDen()->GetZaxis()->SetTitle(nameZ);
824 TString path = Form(
"%s/divided_%i", dir.Data(), counter);
825 gSystem->MakeDirectory(path);
827 Bool_t batch = gROOT->IsBatch();
828 gROOT->SetBatch(kTRUE);
829 TString name =
"Divided 1D";
830 TCanvas* c1 =
new TCanvas(name, name, 0, 0, 800, 600);
833 TH3* num = (TH3*)
GetNum();
834 num->Draw(Draw_3D_option);
837 num->Draw(Draw_3D_option);
839 TH3* den = (TH3*)
GetDen();
840 den->Draw(Draw_3D_option);
843 den->Draw(Draw_3D_option);
845 TH3* fun = (TH3*)
GetHist(kTRUE);
846 fun->Draw(Draw_3D_option);
849 fun->Draw(Draw_3D_option);
850 c1->SaveAs(Form(
"%s/divided_%i/divided.png", dir.Data(), counter));
851 gROOT->SetBatch(batch);
856 TString option = opt;
858 if (Hal::Std::FindParam(option,
"num", kTRUE)) {
859 histo = (TH3*)
GetNum()->Clone();
860 }
else if (Hal::Std::FindParam(option,
"den", kTRUE)) {
861 histo = (TH3*)
GetDen()->Clone();
865 TH2D* proj = Hal::Std::GetProjection2D(histo, min, max, opt);
879 if (Hal::Std::FindParam(opt,
"x")) {
880 X =
fNum->GetXaxis();
881 Y =
fNum->GetYaxis();
882 Z =
fNum->GetZaxis();
883 }
else if (Hal::Std::FindParam(opt,
"y")) {
885 Y =
fNum->GetXaxis();
886 X =
fNum->GetYaxis();
887 Z =
fNum->GetZaxis();
888 }
else if (Hal::Std::FindParam(opt,
"z")) {
890 X =
fNum->GetZaxis();
891 Y =
fNum->GetYaxis();
892 Z =
fNum->GetXaxis();
895 Cout::PrintInfo(
"Wrong option in HalDividedHisto3D Folding", Hal::EInfo::kLowWarning);
897 Double_t middle_bin = X->FindBin(val);
898 middle_bin = X->GetBinCenter(middle_bin);
899 TH3* num_c = (TH3*)
fNum->Clone();
900 TH3* den_c = (TH3*)
fDen->Clone();
901 Double_t min = X->GetBinLowEdge(1);
902 Double_t max = X->GetBinUpEdge(
fNum->GetNbinsX());
903 Double_t period = max - min;
904 for (
int i = 1; i <= X->GetNbins(); i++) {
905 Double_t x = X->GetBinCenter(i);
906 Double_t op_x = 2.0 * val - x;
907 if (op_x > max) op_x = op_x - period;
908 if (op_x <= min) op_x = op_x + period;
909 Int_t j = X->FindBin(op_x);
910 for (
int k = 1; k <= Y->GetNbins(); k++) {
911 for (
int l = 1; l <= Z->GetNbins(); l++) {
912 Int_t a, b, c, d, e, f;
920 }
else if (order == 1) {
935 Double_t N1 = num_c->GetBinContent(a, b, c);
936 Double_t NE1 = num_c->GetBinError(a, b, c);
937 Double_t D1 = den_c->GetBinContent(a, b, c);
938 Double_t DE1 = den_c->GetBinError(a, b, c);
939 Double_t N2 = num_c->GetBinContent(d, e, f);
940 Double_t NE2 = num_c->GetBinError(d, e, f);
941 Double_t D2 = den_c->GetBinContent(d, e, f);
942 Double_t DE2 = den_c->GetBinError(d, e, f);
943 Double_t Ncontent = N1 + N2;
944 Double_t Nerror = TMath::Sqrt(NE1 * NE1 + NE2 * NE2);
945 Double_t Dcontent = D1 + D2;
946 Double_t Derror = TMath::Sqrt(DE1 * DE1 + DE2 * DE2);
947 fNum->SetBinContent(a, b, c, Ncontent);
948 fNum->SetBinError(a, b, c, Nerror);
949 fDen->SetBinContent(a, b, c, Dcontent);
950 fDen->SetBinError(a, b, c, Derror);
961 X =
fNum->GetXaxis();
962 Y =
fNum->GetYaxis();
963 Z =
fNum->GetZaxis();
964 TString option = opt;
965 if (option.EqualTo(
"xy")) {
967 }
else if (option.EqualTo(
"xz")) {
969 }
else if (option.EqualTo(
"yz")) {
971 }
else if (option.EqualTo(
"x")) {
975 }
else if (option.EqualTo(
"y")) {
979 }
else if (option.EqualTo(
"z")) {
987 case 'x': X =
fNum->GetXaxis();
break;
988 case 'y': X =
fNum->GetYaxis();
break;
989 case 'z': X =
fNum->GetZaxis();
break;
992 case 'y': Y =
fNum->GetYaxis();
break;
993 case 'z': Y =
fNum->GetZaxis();
break;
995 TH3* num_c = (TH3*)
fNum->Clone();
996 TH3* den_c = (TH3*)
fDen->Clone();
997 Double_t minX = X->GetBinLowEdge(1);
998 Double_t maxX = X->GetBinUpEdge(X->GetNbins());
999 Double_t periodX = maxX - minX;
1000 Double_t minY = Y->GetBinLowEdge(1);
1001 Double_t maxY = Y->GetBinUpEdge(Y->GetNbins());
1002 Double_t periodY = maxY - minY;
1003 for (
int i = 1; i <= X->GetNbins(); i++) {
1004 Double_t x = X->GetBinCenter(i);
1005 Double_t op_x = 2.0 * valX - x;
1006 if (op_x > maxX) op_x = op_x - periodX;
1007 if (op_x <= minX) op_x = op_x + periodX;
1008 Int_t u = X->FindBin(op_x);
1009 for (
int j = 1; j <= Y->GetNbins(); j++) {
1010 Double_t y = Y->GetBinCenter(j);
1011 Double_t op_y = 2.0 * valY - y;
1012 if (op_y > maxY) op_y = op_y - periodY;
1013 if (op_y <= minY) op_y = op_y + periodY;
1014 Int_t v = Y->FindBin(op_y);
1015 for (
int k = 1; k <= Z->GetNbins(); k++) {
1016 Int_t a, b, c, d, e, f;
1046 Double_t N1 = num_c->GetBinContent(a, b, c);
1047 Double_t NE1 = num_c->GetBinError(a, b, c);
1048 Double_t D1 = den_c->GetBinContent(a, b, c);
1049 Double_t DE1 = den_c->GetBinError(a, b, c);
1050 Double_t N2 = num_c->GetBinContent(d, e, f);
1051 Double_t NE2 = num_c->GetBinError(d, e, f);
1052 Double_t D2 = den_c->GetBinContent(d, e, f);
1053 Double_t DE2 = den_c->GetBinError(d, e, f);
1055 Double_t Ncontent = N1 + N2;
1056 Double_t Nerror = TMath::Sqrt(NE1 * NE1 + NE2 * NE2);
1057 Double_t Dcontent = D1 + D2;
1058 Double_t Derror = TMath::Sqrt(DE1 * DE1 + DE2 * DE2);
1059 fNum->SetBinContent(a, b, c, Ncontent);
1060 fNum->SetBinError(a, b, c, Nerror);
1061 fDen->SetBinContent(a, b, c, Dcontent);
1062 fDen->SetBinError(a, b, c, Derror);
1071 TString option = opt;
1072 if (option.EqualTo(
"xyz")) {
1073 TH3* num_c = (TH3*)
fNum->Clone();
1074 TH3* den_c = (TH3*)
fDen->Clone();
1075 TAxis* X =
fNum->GetXaxis();
1076 TAxis* Y =
fNum->GetYaxis();
1077 TAxis* Z =
fNum->GetZaxis();
1078 Double_t minX = X->GetBinLowEdge(1);
1079 Double_t maxX = X->GetBinUpEdge(X->GetNbins());
1080 Double_t periodX = maxX - minX;
1081 Double_t minY = Y->GetBinLowEdge(1);
1082 Double_t maxY = Y->GetBinUpEdge(Y->GetNbins());
1083 Double_t periodY = maxY - minY;
1084 Double_t minZ = Z->GetBinLowEdge(1);
1085 Double_t maxZ = Z->GetBinUpEdge(Z->GetNbins());
1086 Double_t periodZ = maxZ - minZ;
1087 for (
int i = 1; i <= X->GetNbins(); i++) {
1088 Double_t x = X->GetBinCenter(i);
1089 Double_t op_x = 2.0 * valX - x;
1090 if (op_x > maxX) op_x = op_x - periodX;
1091 if (op_x <= minX) op_x = op_x + periodX;
1092 Int_t u = X->FindBin(op_x);
1093 for (
int j = 1; j <= Y->GetNbins(); j++) {
1094 Double_t y = Y->GetBinCenter(j);
1095 Double_t op_y = 2.0 * valY - y;
1096 if (op_y > maxY) op_y = op_y - periodY;
1097 if (op_y <= minY) op_y = op_y + periodY;
1098 Int_t v = Y->FindBin(op_y);
1099 for (
int k = 1; k <= Z->GetNbins(); k++) {
1100 Double_t z = Z->GetBinCenter(k);
1101 Double_t op_z = 2.0 * valZ - z;
1102 if (op_z > maxZ) op_z = op_z - periodZ;
1103 if (op_z <= minZ) op_z = op_z + periodZ;
1104 Int_t w = Z->FindBin(op_z);
1106 Double_t N1 = num_c->GetBinContent(i, j, k);
1107 Double_t NE1 = num_c->GetBinError(i, j, k);
1108 Double_t D1 = den_c->GetBinContent(i, j, k);
1109 Double_t DE1 = den_c->GetBinError(i, j, k);
1110 Double_t N2 = num_c->GetBinContent(u, v, w);
1111 Double_t NE2 = num_c->GetBinError(u, v, w);
1112 Double_t D2 = den_c->GetBinContent(u, v, w);
1113 Double_t DE2 = den_c->GetBinError(u, v, w);
1115 Double_t Ncontent = N1 + N2;
1116 Double_t Nerror = TMath::Sqrt(NE1 * NE1 + NE2 * NE2);
1117 Double_t Dcontent = D1 + D2;
1118 Double_t Derror = TMath::Sqrt(DE1 * DE1 + DE2 * DE2);
1119 fNum->SetBinContent(i, j, k, Ncontent);
1120 fNum->SetBinError(i, j, k, Nerror);
1121 fDen->SetBinContent(i, j, k, Dcontent);
1122 fDen->SetBinError(i, j, k, Derror);
1135 DividedHisto3D::~DividedHisto3D() {}
1142 TString option = opt;
1143 Bool_t num_rebin = Hal::Std::FindParam(option,
"num");
1144 Bool_t den_rebin = Hal::Std::FindParam(option,
"den");
1145 if ((!num_rebin) && (!den_rebin)) {
1149 if (num_rebin &&
fNum != NULL) {
fNum->Rebin(ngroup); }
1150 if (den_rebin &&
fDen != NULL) {
fDen->Rebin(ngroup); }
1154 TString option = opt;
1155 Bool_t num_rebin = Hal::Std::FindParam(option,
"num");
1156 Bool_t den_rebin = Hal::Std::FindParam(option,
"den");
1157 Bool_t rebin_x = kFALSE;
1158 Bool_t rebin_y = kFALSE;
1159 if (Hal::Std::FindParam(option,
"y")) {
1164 if ((!num_rebin) && (!den_rebin)) {
1168 if (num_rebin &&
fNum != NULL) {
1169 if (rebin_x) ((TH2*)
fNum)->RebinX(ngroup);
1170 if (rebin_y) ((TH2*)
fNum)->RebinY(ngroup);
1172 if (den_rebin &&
fDen != NULL) {
1173 if (rebin_x) ((TH2*)
fDen)->RebinX(ngroup);
1174 if (rebin_y) ((TH2*)
fDen)->RebinY(ngroup);
1179 TString option = opt;
1180 Bool_t num_rebin = Hal::Std::FindParam(option,
"num");
1181 Bool_t den_rebin = Hal::Std::FindParam(option,
"den");
1182 Bool_t rebin_x = kFALSE;
1183 Bool_t rebin_y = kFALSE;
1184 Bool_t rebin_z = kFALSE;
1185 if (option.Contains(
"x") || option.Contains(
"X")) { rebin_x = kTRUE; }
1186 if (option.Contains(
"y") || option.Contains(
"Y")) { rebin_y = kTRUE; }
1187 if (option.Contains(
"z") || option.Contains(
"Z")) { rebin_z = kTRUE; }
1188 if (rebin_y == kFALSE && rebin_z == kFALSE) { rebin_x = kTRUE; }
1189 if ((!num_rebin) && (!den_rebin)) {
1193 if (num_rebin &&
fNum != NULL) {
1194 if (rebin_x) ((TH3*)
fNum)->RebinX(ngroup);
1195 if (rebin_y) ((TH3*)
fNum)->RebinY(ngroup);
1196 if (rebin_z) ((TH3*)
fNum)->RebinZ(ngroup);
1198 if (den_rebin &&
fDen != NULL) {
1199 if (rebin_x) ((TH3*)
fDen)->RebinX(ngroup);
1200 if (rebin_y) ((TH3*)
fDen)->RebinY(ngroup);
1201 if (rebin_z) ((TH3*)
fDen)->RebinZ(ngroup);
1208 if (
this != &other) {
1211 if (other.
fNum != NULL)
fNum = (TH1*) other.
fNum->Clone();
1212 if (other.
fDen != NULL)
fDen = (TH1*) other.
fDen->Clone();
1213 for (
int i = 0; i <
fDim; i++) {
1230 if (gPad == NULL)
new TCanvas();
1231 TString option = opt;
1232 if (Hal::Std::FindParam(option,
"num", kTRUE)) {
1234 }
else if (Hal::Std::FindParam(option,
"den", kTRUE)) {
1236 }
else if (Hal::Std::FindParam(option,
"all", kTRUE)) {
1237 TVirtualPad* c1 = gPad;
1238 if (gPad->GetListOfPrimitives()->GetEntries() < 4) gPad->Divide(2, 2);
1244 TH1* h = this->
GetHist(kTRUE);
1248 TH1* num_copy = (TH1*)
fNum->Clone(
"temp_num");
1249 TH1* den_copy = (TH1*)
fDen->Clone(
"temp_den");
1250 num_copy->GetYaxis()->SetTitle(Form(
"%s (scaled)",
fNum->GetYaxis()->GetTitle()));
1251 num_copy->SetLineColor(kRed + 1);
1252 den_copy->SetLineColor(kGreen + 1);
1253 Double_t num_scale = 1.0 / num_copy->GetEntries();
1254 Double_t den_scale = 1.0 / den_copy->GetEntries();
1255 num_copy->Scale(num_scale);
1256 den_copy->Scale(den_scale);
1257 num_copy->SetStats(kFALSE);
1258 TLegend* leg =
new TLegend(0.4, 0.8, 0.9, 0.9);
1259 leg->AddEntry(num_copy, Form(
"Numerator x %E", num_scale),
"LPM");
1260 leg->AddEntry(den_copy, Form(
"Denominator x %E", den_scale),
"LPM");
1261 num_copy->Draw(option);
1262 den_copy->Draw(
"SAME");
1263 leg->SetFillStyle(3002);
1279 return Form(
"<img border=\"0\" src=\"divided.png\" width=\"996\" height=\"1472\">");
1283 std::vector<TString> out;
1284 out = Hal::Std::ExplodeString(name,
';');
1285 TString x_axis, y_axis;
1286 if (out.size() > 1) {
1290 if (out.size() > 2) y_axis = out[2];
1293 fNum =
new TH1D(name +
"_Num", name +
"_Num", nbins, min, max);
1294 fDen =
new TH1D(name +
"_Den", name +
"_Den", nbins, min, max);
1297 fNum =
new TH1I(name +
"_Num", name +
"_Num", nbins, min, max);
1298 fDen =
new TH1I(name +
"_Den", name +
"_Den", nbins, min, max);
1301 fNum =
new TH1F(name +
"_Num", name +
"_Num", nbins, min, max);
1302 fDen =
new TH1F(name +
"_Den", name +
"_Den", nbins, min, max);
1305 fNum =
new TH1D(name +
"_Num", name +
"_Num", nbins, min, max);
1306 fDen =
new TH1D(name +
"_Den", name +
"_Den", nbins, min, max);
1309 if (out.size() > 1) {
1310 fNum->GetXaxis()->SetTitle(x_axis);
1311 fDen->GetXaxis()->SetTitle(x_axis);
1313 if (out.size() > 2) {
1314 fNum->GetYaxis()->SetTitle(y_axis);
1315 fDen->GetYaxis()->SetTitle(y_axis);
1317 fNumIsCloned = fDenIsCloned = kTRUE;
1321 DividedHisto1D(name, conf.GetNBins(), conf.GetMin(), conf.GetMax(), type) {
1322 TString nameX = conf.GetName();
1323 if (nameX.Length()) {
1324 GetNum()->GetXaxis()->SetTitle(nameX);
1325 GetDen()->GetXaxis()->SetTitle(nameX);
1338 std::vector<TString> out = Hal::Std::ExplodeString(name,
';');
1339 TString x_axis, y_axis, z_axis;
1340 if (out.size() > 1) {
1344 if (out.size() > 2) y_axis = out[2];
1345 if (out.size() > 3) z_axis = out[3];
1348 fNum =
new TH2D(name +
"_Num", name +
"_Num", binsX, minX, maxX, binsY, minY, maxY);
1349 fDen =
new TH2D(name +
"_Den", name +
"_Den", binsX, minX, maxX, binsY, minY, maxY);
1352 fNum =
new TH2I(name +
"_Num", name +
"_Num", binsX, minX, maxX, binsY, minY, maxY);
1353 fDen =
new TH2I(name +
"_Den", name +
"_Den", binsX, minX, maxX, binsY, minY, maxY);
1356 fNum =
new TH2F(name +
"_Num", name +
"_Num", binsX, minX, maxX, binsY, minY, maxY);
1357 fDen =
new TH2F(name +
"_Den", name +
"_Den", binsX, minX, maxX, binsY, minY, maxY);
1360 fNum =
new TH2D(name +
"_Num", name +
"_Num", binsX, minX, maxX, binsY, minY, maxY);
1361 fDen =
new TH2D(name +
"_Den", name +
"_Den", binsX, minX, maxX, binsY, minY, maxY);
1364 if (out.size() > 1) {
1365 fNum->GetXaxis()->SetTitle(x_axis);
1366 fDen->GetXaxis()->SetTitle(x_axis);
1368 if (out.size() > 2) {
1369 fNum->GetYaxis()->SetTitle(y_axis);
1370 fDen->GetYaxis()->SetTitle(y_axis);
1372 if (out.size() > 3) {
1373 fNum->GetZaxis()->SetTitle(z_axis);
1374 fDen->GetZaxis()->SetTitle(z_axis);
1379 DividedHisto2D(name, axX.GetNBins(), axX.GetMin(), axX.GetMax(), axY.GetNBins(), axY.GetMin(), axY.GetMax(), type) {
1380 TString nameX = axX.GetName();
1381 if (nameX.Length()) {
1382 GetNum()->GetXaxis()->SetTitle(nameX);
1383 GetDen()->GetXaxis()->SetTitle(nameX);
1385 TString nameY = axY.GetName();
1386 if (nameY.Length()) {
1387 GetNum()->GetYaxis()->SetTitle(nameY);
1388 GetDen()->GetYaxis()->SetTitle(nameY);
1404 std::vector<TString> out = Hal::Std::ExplodeString(name,
';');
1405 TString x_axis, y_axis, z_axis;
1406 if (out.size() > 1) {
1410 if (out.size() > 2) y_axis = out[2];
1411 if (out.size() > 3) z_axis = out[3];
1414 fNum =
new TH3D(name +
"_Num", name +
"_Num", binsX, minX, maxX, binsY, minY, maxY, binsZ, minZ, maxZ);
1415 fDen =
new TH3D(name +
"_Den", name +
"_Den", binsX, minX, maxX, binsY, minY, maxY, binsZ, minZ, maxZ);
1418 fNum =
new TH3I(name +
"_Num", name +
"_Num", binsX, minX, maxX, binsY, minY, maxY, binsZ, minZ, maxZ);
1419 fDen =
new TH3I(name +
"_Den", name +
"_Den", binsX, minX, maxX, binsY, minY, maxY, binsZ, minZ, maxZ);
1422 fNum =
new TH3F(name +
"_Num", name +
"_Num", binsX, minX, maxX, binsY, minY, maxY, binsZ, minZ, maxZ);
1423 fDen =
new TH3F(name +
"_Den", name +
"_Den", binsX, minX, maxX, binsY, minY, maxY, binsZ, minZ, maxZ);
1426 fNum =
new TH3D(name +
"_Num", name +
"_Num", binsX, minX, maxX, binsY, minY, maxY, binsZ, minZ, maxZ);
1427 fDen =
new TH3D(name +
"_Den", name +
"_Den", binsX, minX, maxX, binsY, minY, maxY, binsZ, minZ, maxZ);
1430 if (out.size() > 1) {
1431 fNum->GetXaxis()->SetTitle(x_axis);
1432 fDen->GetXaxis()->SetTitle(x_axis);
1434 if (out.size() > 2) {
1435 fNum->GetYaxis()->SetTitle(y_axis);
1436 fDen->GetYaxis()->SetTitle(y_axis);
1438 if (out.size() > 3) {
1439 fNum->GetZaxis()->SetTitle(z_axis);
1440 fDen->GetZaxis()->SetTitle(z_axis);
1450 Int_t binA =
fNum->GetXaxis()->FindBin(min);
1451 Int_t binB =
fNum->GetXaxis()->FindBin(max);
1454 for (
int i = binA; i <= binB; i++) {
1455 N +=
fNum->GetBinContent(i);
1456 D +=
fDen->GetBinContent(i);
1462 Int_t binXm =
fNum->GetXaxis()->FindBin(minX);
1463 Int_t binXM =
fNum->GetXaxis()->FindBin(maxX);
1464 Int_t binYm =
fNum->GetYaxis()->FindBin(minY);
1465 Int_t binYM =
fNum->GetYaxis()->FindBin(maxY);
1468 for (
int i = binXm; i <= binXM; i++) {
1469 for (
int j = binYm; j <= binYM; j++) {
1470 N +=
fNum->GetBinContent(i, j);
1471 D +=
fDen->GetBinContent(i, j);
1479 Int_t binXm =
fNum->GetXaxis()->FindBin(minX);
1480 Int_t binXM =
fNum->GetXaxis()->FindBin(maxX);
1481 Int_t binYm =
fNum->GetYaxis()->FindBin(minY);
1482 Int_t binYM =
fNum->GetYaxis()->FindBin(maxY);
1483 Int_t binZm =
fNum->GetZaxis()->FindBin(minZ);
1484 Int_t binZM =
fNum->GetZaxis()->FindBin(maxZ);
1487 for (
int i = binXm; i <= binXM; i++) {
1488 for (
int j = binYm; j <= binYM; j++) {
1489 for (
int k = binZm; k <= binZM; k++) {
1490 N +=
fNum->GetBinContent(i, j, k);
1491 D +=
fDen->GetBinContent(i, j, k);
1499 TString option = opt;
1501 if (Hal::Std::FindParam(option,
"num", kTRUE)) {
1502 histo = (TH2*)
GetNum()->Clone();
1503 }
else if (Hal::Std::FindParam(option,
"den", kTRUE)) {
1504 histo = (TH2*)
GetDen()->Clone();
1506 histo = (TH2*)
GetHist(kTRUE);
1508 TH1D* projection = Hal::Std::GetProjection1D(histo, min, max, option);
1514 TString option = opt;
1516 if (Hal::Std::FindParam(option,
"num", kTRUE)) {
1517 histo = (TH3*)
GetNum()->Clone();
1518 }
else if (Hal::Std::FindParam(option,
"den", kTRUE)) {
1519 histo = (TH3*)
GetDen()->Clone();
1520 }
else if (Hal::Std::FindParam(option,
"separate", kTRUE)) {
1521 TH1D* num1d = Hal::Std::GetProjection1D((TH3*)
fNum, min1, max1, min2, max2, option);
1522 TH1D* den1d = Hal::Std::GetProjection1D((TH3*)
fDen, min1, max1, min2, max2, option);
1523 num1d->Divide(den1d);
1527 histo = (TH3*)
GetHist(kTRUE);
1529 TH1D* projection = Hal::Std::GetProjection1D(histo, min1, max1, min2, max2, option);
1534 void DividedHisto1D::Print(Option_t* )
const {
1536 if (
GetNum() !=
nullptr) {
1537 const TAxis* x =
GetNum()->GetXaxis();
1538 TString bins = Form(
"Nbins: %i", x->GetNbins());
1539 TString min = Form(
"Xmin:%4.3f", x->GetBinLowEdge(1));
1540 TString max = Form(
"Xmax:%4.3f", x->GetBinUpEdge(x->GetNbins()));
1545 const TAxis* y =
GetNum()->GetYaxis();
1546 bins = Form(
"Nbins: %i", y->GetNbins());
1547 min = Form(
"Ymin:%4.3f", y->GetBinLowEdge(1));
1548 max = Form(
"Ymax:%4.3f", y->GetBinUpEdge(y->GetNbins()));
1554 const TAxis* z =
GetNum()->GetZaxis();
1555 bins = Form(
"Nbins: %i", z->GetNbins());
1556 min = Form(
"Zmin:%4.3f", z->GetBinLowEdge(1));
1557 max = Form(
"Zmax:%4.3f", z->GetBinUpEdge(z->GetNbins()));
1568 TString className = ClassName();
1569 TString otherClassName = other.ClassName();
1570 if (className != otherClassName) {
1572 Form(
"%s %i: probably wrong AddScaled %s + %s", __FILE__, __LINE__, className.Data(), other.ClassName()), EInfo::kError);
1582 if (
fNum && fNumIsCloned)
fNum->SetDirectory(dir);
1583 if (
fDen && fDenIsCloned)
fDen->SetDirectory(dir);
static void Text(TString text, TString option="L", Color_t color=-1)
static void PrintInfo(TString text, Hal::EInfo status)
void SetScale(Double_t scale)
void SetAxisName(TString name)
virtual TString CommonExtract(Int_t counter, TString dir) const
virtual void AddNum(TH1 *num, Option_t *opt="")
Double_t CalculateNorm(Double_t min, Double_t max) const
Double_t GetNormMax(Int_t no=0) const
TString GetLabel(Int_t i) const
virtual void ApplyStyle(const HistoStyle &h)
void SetComment(TString comment)
Double_t GetNormMin(Int_t no=0) const
virtual TString HTMLExtract(Int_t counter=0, TString dir=" ") const
virtual void SetDirectory(TDirectory *dir=nullptr)
virtual void Normalize(TH1 *h) const
void AddLabel(TString label)
TString GetExtractType() const
virtual void SetHistoName(TH1 *h) const
virtual void Rebin(Int_t ngroup, Option_t *opt)
Int_t GetLabelsNo() const
void Fold1D(Double_t val, Option_t *opt="x")
void SetNorm(Double_t min, Double_t max, Int_t axis=0)
void SetOwner(Bool_t own)
Double_t GetScale() const
virtual void Draw(Option_t *opt="all")
TH1 * GetHist(Bool_t normalized=kTRUE) const
virtual void AddNumDen(TH1 *num, TH1 *den, Option_t *opt="")
virtual void Add(const Object *h)
virtual TString GetPic() const
virtual void AddScaled(const DividedHisto1D &other, Double_t scale=1)
virtual void AddDen(TH1 *den, Option_t *opt="")
virtual void Browse(TBrowser *b)
virtual void Folding1D(Double_t val, Option_t *axis)
void SetBinomial(Bool_t binomial)
virtual Long64_t Merge(TCollection *collection)
DividedHisto1D & operator=(const DividedHisto1D &other)
virtual void Folding1D(Double_t val, Option_t *axis)
virtual void Rebin(Int_t ngroup, Option_t *opt)
void Fold2D(Double_t valX, Double_t valY, Option_t *opt="xy")
Double_t CalculateNorm(Double_t minX, Double_t maxX, Double_t minY, Double_t maxY) const
virtual void Normalize(TH1 *h) const
virtual void Browse(TBrowser *b)
virtual TString HTMLExtract(Int_t counter=0, TString dir=" ") const
TH1D * Projection2DTo1D(Double_t min, Double_t max, Option_t *opt) const
virtual void SetHistoName(TH1 *h) const
virtual void Folding2D(Double_t valX, Double_t valY, Option_t *opt)
DividedHisto2D & operator=(const DividedHisto2D &other)
virtual void Folding1D(Double_t val, Option_t *axis)
virtual void SetHistoName(TH1 *h) const
virtual void Fold3D(Double_t valX, Double_t valY, Double_t valZ, Option_t *opt)
virtual TH1D * Projection3DTo1D(Double_t min1, Double_t max1, Double_t min2, Double_t max2, Option_t *opt) const
virtual void Folding2D(Double_t valX, Double_t valY, Option_t *opt)
virtual TString HTMLExtract(Int_t counter=0, TString dir=" ") const
virtual TH2D * GetProjection2D(Double_t min, Double_t max, Option_t *opt) const
Double_t CalculateNorm(Double_t minX, Double_t maxX, Double_t minY, Double_t maxY, Double_t minZ, Double_t maxZ) const
virtual void Rebin(Int_t ngroup, Option_t *opt)
DividedHisto3D & operator=(const DividedHisto3D &other)
void Normalize(TH1 *h) const
static TString GetUrl(TString adress, TString text)
static TString GetJsDiv(TString root_file, TString object_name, TString draw_opt="colz", TString draw_div_name="drawing")
virtual void AddContent(const HtmlObject &obj)
virtual void AddContent(const HtmlObject &obj)