35 if (gPad ==
nullptr) {
36 Info(
"Cmd",
"warning: no pad");
40 TObject *hist_now = gPad->GetPrimitive(
"htemp");
42 hist_now = TCatHistManager::Instance()->GetCurrent();
43 if (!hist_now || !hist_now->InheritsFrom(
"TH1")) {
44 Info(
"Cmd",
"warning: no hist, please check using ls command");
49 if (!hist_now->InheritsFrom(TH2::Class())) {
50 Info(
"Cmd",
"warning: The current hist does not inherit from TH2 class");
54 Double_t x1 = 0., y1 = 0., x2 = 0., y2 = 0.;
55 Info(
"Cmd",
"click on one corner: ");
56 TCatCmdXval::Instance()->Run(&x1, &y1);
57 Info(
"Cmd",
"X1: %g, Y1: %g", x1, y1);
59 Info(
"Cmd",
"click on the other corner: ");
60 TCatCmdXval::Instance()->Run(&x2, &y2);
61 Info(
"Cmd",
"X2: %g, Y2: %g", x2, y2);
75 static TLine *lines[4];
76 for (Int_t i = 0; i < 4; ++i) {
82 lines[0] =
new TLine(x1, y1, x2, y1);
83 lines[1] =
new TLine(x1, y2, x2, y2);
84 lines[2] =
new TLine(x1, y1, x1, y2);
85 lines[3] =
new TLine(x2, y1, x2, y2);
87 for (Int_t i = 0; i < 4; ++i) {
88 lines[i]->SetLineColor(kRed);
92 Int_t x1bin, x2bin, y1bin, y2bin;
93 x1bin =
dynamic_cast<TH2 *
>(hist_now)->GetXaxis()->FindBin(x1);
94 x2bin =
dynamic_cast<TH2 *
>(hist_now)->GetXaxis()->FindBin(x2);
95 y1bin =
dynamic_cast<TH2 *
>(hist_now)->GetYaxis()->FindBin(y1);
96 y2bin =
dynamic_cast<TH2 *
>(hist_now)->GetYaxis()->FindBin(y2);
98 Int_t selected = (Int_t)(
dynamic_cast<TH2 *
>(hist_now)->Integral(x1bin, x2bin, y1bin, y2bin));
99 Int_t total = (Int_t)(
dynamic_cast<TH2 *
>(hist_now)->Integral());
100 Double_t ratio = 0.0;
102 std::cout <<
"------------------" << std::endl;
103 std::cout <<
"selected = " << selected <<
", total = " << total << std::endl;
105 ratio = (Double_t)selected / total;
106 std::cout <<
"ratio = " << ratio <<
" (" << ratio * 100 <<
"%)" << std::endl;
107 TCmdComment::Instance()->Run(TString::Format(
"[xstatus] %d/%d: ratio=%g", selected, total, ratio));
109 std::cout <<
"ratio = " <<
"NaN" << std::endl;
110 TCmdComment::Instance()->Run(TString::Format(
"[xstatus] %d/%d: ratio=NaN", selected, total));