Logo ROOT   6.18/05
Reference Guide
hlHisto1.C File Reference

Detailed Description

This tutorial demonstrates how the highlight mechanism can be used on an histogram.

A 2D histogram is booked an filled with a random gaussian distribution. Then an highlight method is connected to the histogram. Moving the mouse on the histogram will update the histogram title in real time according to the highlighted bin.

void HighlightTitle(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb);
TText *info;
void hlHisto1()
{
auto Canvas = new TCanvas();
auto h2 = new TH2F("h2", "", 50, -5.0, 5.0, 50, -5.0, 5.0);
for (Int_t i = 0; i < 10000; i++) h2->Fill(gRandom->Gaus(), gRandom->Gaus());
h2->Draw();
info = new TText(0.0, -4.0, "please move the mouse over the frame");
info->SetTextAlign(22);
info->SetTextColor(kRed+1);
info->Draw();
Canvas->Update();
h2->SetHighlight();
Canvas->HighlightConnect("HighlightTitle(TVirtualPad*,TObject*,Int_t,Int_t)");
}
void HighlightTitle(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb)
{
auto h2 = (TH2F *)obj;
if (!h2) return;
if (!h2->IsHighlight()) { // after highlight disabled
h2->SetTitle("");
return;
}
info->SetTitle("");
t.Form("bin[%02d, %02d] (%5.2f, %5.2f) content %g", xhb, yhb,
h2->GetXaxis()->GetBinCenter(xhb), h2->GetYaxis()->GetBinCenter(yhb),
h2->GetBinContent(xhb, yhb));
h2->SetTitle(t.Data());
pad->Update();
}
int Int_t
Definition: RtypesCore.h:41
@ kRed
Definition: Rtypes.h:64
@ kCannotPick
Definition: TObject.h:344
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
The Canvas class.
Definition: TCanvas.h:31
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:248
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
Mother of all ROOT objects.
Definition: TObject.h:37
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:263
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2289
Base class for several text objects.
Definition: TText.h:23
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:50
virtual void Update()=0
Date
March 2018
Author
Jan Musinsky

Definition in file hlHisto1.C.