Logo ROOT  
Reference Guide
hlHisto2.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 and drawn with the "col" option. Then an highlight method is connected to the histogram. Moving the mouse on the histogram open a new canvas displaying the two X and Y projections at the highlighted bin.

void Highlight2(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb);
TText *info;
void hlHisto2()
{
auto Canvas = new TCanvas("Canvas", "Canvas", 0, 0, 500, 500);
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("col");
info = new TText(0.0, -4.0, "please move the mouse over the frame");
info->SetTextAlign(22);
info->SetTextSize(0.04);
info->SetTextColor(kRed+1);
info->Draw();
Canvas->Update();
h2->SetHighlight();
Canvas->HighlightConnect("Highlight2(TVirtualPad*,TObject*,Int_t,Int_t)");
}
void Highlight2(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb)
{
auto h2 = (TH2F *)obj;
if(!h2) return;
auto CanvasProj = (TCanvas *) gROOT->GetListOfCanvases()->FindObject("CanvasProj");
if (!h2->IsHighlight()) { // after highlight disabled
if (CanvasProj) delete CanvasProj;
return;
}
info->SetTitle("");
auto px = h2->ProjectionX("_px", yhb, yhb);
auto py = h2->ProjectionY("_py", xhb, xhb);
px->SetTitle(TString::Format("ProjectionX of biny[%02d]", yhb));
py->SetTitle(TString::Format("ProjectionY of binx[%02d]", xhb));
if (!CanvasProj) {
CanvasProj = new TCanvas("CanvasProj", "CanvasProj", 505, 0, 600, 600);
CanvasProj->Divide(1, 2);
CanvasProj->cd(1);
px->Draw();
CanvasProj->cd(2);
py->Draw();
}
CanvasProj->GetPad(1)->Modified();
CanvasProj->GetPad(2)->Modified();
CanvasProj->Update();
}
Date
March 2018
Author
Jan Musinsky

Definition in file hlHisto2.C.

TRandom::Gaus
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
TH2F
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
Int_t
int Int_t
Definition: RtypesCore.h:45
TString::Format
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2311
TH1::SetTitle
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6344
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
TH1::SetHighlight
virtual void SetHighlight(Bool_t set=kTRUE)
Set highlight (enable/disable) mode for the histogram by default highlight mode is disable.
Definition: TH1.cxx:4337
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3274
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
kRed
@ kRed
Definition: Rtypes.h:66
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TH1::IsHighlight
virtual Bool_t IsHighlight() const
Definition: TH1.h:331
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
TText
Definition: TText.h:22
TVirtualPad
Definition: TVirtualPad.h:50
TCanvas
Definition: TCanvas.h:23
TObject
Definition: TObject.h:37
kCannotPick
@ kCannotPick
Definition: TObject.h:344
gROOT
#define gROOT
Definition: TROOT.h:406
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997