39 if (gPad ==
nullptr) {
40 Info(
"Cmd",
"warning: no pad");
44 TObject *hist_now = gPad->GetPrimitive(
"htemp");
46 hist_now = TCatHistManager::Instance()->GetCurrent();
47 if (!hist_now || !hist_now->InheritsFrom(
"TH1")) {
48 Info(
"Cmd",
"warning: no hist, please check using ls command");
53 if (!hist_now->InheritsFrom(TH2::Class())) {
54 Info(
"Cmd",
"warning: The current hist does not inherit from TH2 class");
58 TString xname = ((TH2 *)hist_now)->GetXaxis()->GetTitle();
59 TString yname = ((TH2 *)hist_now)->GetYaxis()->GetTitle();
60 if (xname ==
"" || yname ==
"") {
61 TString title = ((TH2 *)hist_now)->GetTitle();
62 yname = title(0, title.First(
":"));
63 if (title.Contains(
' ')) {
64 TString tmp = title(title.First(
":") + 1, title.Length());
65 xname = tmp(0, tmp.First(
' '));
67 xname = title(title.First(
":") + 1, title.Length());
70 Info(
"Cmd",
"Xaxis name : %s Yaxis name : %s", xname.Data(), yname.Data());
72 Double_t ix = 0.0, iy = 0.0, x = 0.0, y = 0.0, bx = 0.0, by = 0.0;
74 std::vector<TLine *> lines;
75 TCutG *cutg =
new TCutG();
79 Info(
"Cmd",
"When you have finished specifying the area (last point), double-click on it.");
84 Info(
"Cmd",
"(x, y) = (%lf, %lf)", x, y);
86 TLine *line =
new TLine(bx, by, x, y);
87 lines.push_back(line);
88 lines[i - 1]->SetLineColor(kRed);
89 lines[i - 1]->SetLineWidth(2);
90 lines[i - 1]->Draw(
"same");
98 cutg->SetPoint(i, x, y);
103 cutg->RemovePoint(i - 1);
104 cutg->SetPoint(i - 1, ix, iy);
106 for (Size_t l = 0; l < lines.size(); l++) {
109 cutg->SetLineColor(kRed);
110 cutg->SetLineWidth(2);
111 cutg->Draw(
"l same");
112 std::this_thread::sleep_for(std::chrono::milliseconds(10));
116 std::cout <<
"if you want to save it, input the TCutG name [name/exit] ";
118 if (input ==
"exit" || input ==
"") {
119 Info(
"Cmd",
"exit, not saved");
123 cutg->SetName(input);
124 TFile *file =
new TFile(
"gate/" + input +
".root",
"recreate");
125 Info(
"Cmd",
"Created gate/%s.root", input.Data());
164 const Int_t
event = gPad->GetEvent();
165 const Int_t px = gPad->GetEventX();
166 const Double_t xx = gPad->AbsPixeltoX(px);
167 const Double_t x = gPad->PadtoX(xx);
168 const Int_t py = gPad->GetEventY();
169 const Double_t yy = gPad->AbsPixeltoY(py);
170 const Double_t y = gPad->PadtoY(yy);
173 TLine *line =
new TLine(
fX,
fY, x, y);
174 line->SetLineColor(kBlack);
180 if (event == kButton1Double) {
183 }
else if (event != kButton1Up)
186 gPad->DeleteExec(
"ex_setxy");
190 gPad->GetListOfPrimitives()->AddLast(
new TNamed(
"setxy",
"setxy"));