ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TCmdXstatus.cc
Go to the documentation of this file.
1/**
2 * @file TCmdXstatus.cc
3 * @brief
4 * @author Kodai Okawa <okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2023-06-13 10:54:46
6 * @note last modified: 2024-08-23 21:44:35
7 * @details
8 */
9
10#include "TCmdXstatus.h"
11
12#include <TCatCmdXval.h>
13#include <TCatHistManager.h>
14#include <TCmdComment.h>
15#include <TF1.h>
16#include <TH2.h>
17#include <TLine.h>
18#include <TPad.h>
19
21
23
24const char *TCmdXstatus::kFuncNameBase = "f";
25const char *TCmdXstatus::kLabelNameBase = "l";
26
28 SetName("xstatus");
29 SetTitle("get status (using mouse)");
30}
31
33
34Long_t TCmdXstatus::Cmd(vector<TString>) {
35 if (gPad == nullptr) {
36 Info("Cmd", "warning: no pad");
37 return 1;
38 }
39
40 TObject *hist_now = gPad->GetPrimitive("htemp");
41 if (!hist_now) {
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");
45 return 1;
46 }
47 }
48
49 if (!hist_now->InheritsFrom(TH2::Class())) {
50 Info("Cmd", "warning: The current hist does not inherit from TH2 class");
51 return 1;
52 }
53
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);
58
59 Info("Cmd", "click on the other corner: ");
60 TCatCmdXval::Instance()->Run(&x2, &y2);
61 Info("Cmd", "X2: %g, Y2: %g", x2, y2);
62
63 Double_t temp;
64 if (x1 > x2) {
65 temp = x1;
66 x1 = x2;
67 x2 = temp;
68 }
69 if (y1 > y2) {
70 temp = y1;
71 y1 = y2;
72 y2 = temp;
73 }
74
75 static TLine *lines[4];
76 for (Int_t i = 0; i < 4; ++i) {
77 if (lines[i]) {
78 delete lines[i];
79 }
80 }
81
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);
86
87 for (Int_t i = 0; i < 4; ++i) {
88 lines[i]->SetLineColor(kRed);
89 lines[i]->Draw();
90 }
91
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);
97
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;
101
102 std::cout << "------------------" << std::endl;
103 std::cout << "selected = " << selected << ", total = " << total << std::endl;
104 if (total != 0) {
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));
108 } else {
109 std::cout << "ratio = " << "NaN" << std::endl;
110 TCmdComment::Instance()->Run(TString::Format("[xstatus] %d/%d: ratio=NaN", selected, total));
111 }
112
113 return 1;
114}
115
117 std::cout << "count and ratio" << std::endl;
118}
ClassImp(TCmdXstatus)
Long_t Cmd(vector< TString >) override
void Help() override
static const char * kLabelNameBase
Definition TCmdXstatus.h:27
static const char * kFuncNameBase
Definition TCmdXstatus.h:26
return to the guide