Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
hlHisto1.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 ///
4 /// This tutorial demonstrates how the highlight mechanism can be used on an histogram.
5 /// A 2D histogram is booked an filled with a random gaussian distribution.
6 /// Then an highlight method is connected to the histogram. Moving the mouse
7 /// on the histogram will update the histogram title in real time according to
8 /// the highlighted bin.
9 ///
10 /// \macro_code
11 ///
12 /// \date March 2018
13 /// \author Jan Musinsky
14 
15 void HighlightTitle(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb);
16 
17 TText *info;
18 
19 
20 void hlHisto1()
21 {
22  auto Canvas = new TCanvas();
23  auto h2 = new TH2F("h2", "", 50, -5.0, 5.0, 50, -5.0, 5.0);
24  for (Int_t i = 0; i < 10000; i++) h2->Fill(gRandom->Gaus(), gRandom->Gaus());
25  h2->Draw();
26 
27  info = new TText(0.0, -4.0, "please move the mouse over the frame");
28  info->SetTextAlign(22);
29  info->SetTextColor(kRed+1);
30  info->SetBit(kCannotPick);
31  info->Draw();
32  Canvas->Update();
33 
34  h2->SetHighlight();
35  Canvas->HighlightConnect("HighlightTitle(TVirtualPad*,TObject*,Int_t,Int_t)");
36 }
37 
38 
39 void HighlightTitle(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb)
40 {
41  auto h2 = (TH2F *)obj;
42  if (!h2) return;
43  if (!h2->IsHighlight()) { // after highlight disabled
44  h2->SetTitle("");
45  return;
46  }
47  info->SetTitle("");
48  TString t;
49  t.Form("bin[%02d, %02d] (%5.2f, %5.2f) content %g", xhb, yhb,
50  h2->GetXaxis()->GetBinCenter(xhb), h2->GetYaxis()->GetBinCenter(yhb),
51  h2->GetBinContent(xhb, yhb));
52  h2->SetTitle(t.Data());
53  pad->Update();
54 }