13 void HighlightBinId(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y);
17 auto dir = gROOT->GetTutorialDir();
18 dir.Append(
"/hsimple.C");
19 dir.ReplaceAll(
"/./",
"/");
20 if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
21 auto file = (TFile*)gROOT->ProcessLineFast(
"hsimple(1)");
24 file->GetObject(
"ntuple", ntuple);
27 TCanvas *Canvas1 =
new TCanvas(
"Canvas1",
"Canvas1", 0, 0, 500, 500);
28 const char *cut =
"pz > 3.0";
29 ntuple->Draw(
"px:py", cut);
30 TGraph *graph = (TGraph *)gPad->FindObject(
"Graph");
32 auto info =
new TText(0.0, 4.5,
"please move the mouse over the graph");
33 info->SetTextAlign(22);
34 info->SetTextSize(0.03);
35 info->SetTextColor(kRed+1);
36 info->SetBit(kCannotPick);
39 graph->SetHighlight();
40 Canvas1->HighlightConnect(
"HighlightBinId(TVirtualPad*,TObject*,Int_t,Int_t)");
42 auto Canvas2 =
new TCanvas(
"Canvas2",
"Canvas2", 505, 0, 600, 400);
43 ntuple->Draw(
"TMath::Sqrt(px*px + py*py + pz*pz)>>histo(100, 0, 15)", cut);
46 ntuple->Draw(
"px:py:pz:i", cut,
"goff");
50 void HighlightBinId(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y)
52 auto Canvas2 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject(
"Canvas2");
54 auto histo = (TH1F *)Canvas2->FindObject(
"histo");
57 Double_t px = ntuple->GetV1()[ihp];
58 Double_t py = ntuple->GetV2()[ihp];
59 Double_t pz = ntuple->GetV3()[ihp];
60 Double_t i = ntuple->GetV4()[ihp];
61 Double_t p = TMath::Sqrt(px*px + py*py + pz*pz);
62 Int_t hbin = histo->FindBin(p);
64 Bool_t redraw = kFALSE;
65 auto bh = (TBox *)Canvas2->FindObject(
"TBox");
68 bh->SetFillColor(kBlack);
69 bh->SetFillStyle(3001);
70 bh->SetBit(kCannotPick);
71 bh->SetBit(kCanDelete);
74 bh->SetX1(histo->GetBinLowEdge(hbin));
75 bh->SetY1(histo->GetMinimum());
76 bh->SetX2(histo->GetBinWidth(hbin) + histo->GetBinLowEdge(hbin));
77 bh->SetY2(histo->GetBinContent(hbin));
79 auto th = (TText *)Canvas2->FindObject(
"TText");
83 th->SetTextColor(bh->GetFillColor());
84 th->SetBit(kCanDelete);
87 th->SetText(histo->GetXaxis()->GetXmax()*0.75, histo->GetMaximum()*0.5,
88 TString::Format(
"id = %d", (Int_t)i));