Logo ROOT  
Reference Guide
hlHisto4.C File Reference

Detailed Description

This tutorial demonstrates how the highlight mechanism can be used on an histogram. A 1D histogram is created. Then an highlight method is connected to the histogram. Moving the mouse on the histogram will open a new canvas showing in real time a zoom around the highlighted bin.

void HighlightZoom(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb);
TText *info;
void hlHisto4()
{
auto Canvas1 = new TCanvas("Canvas1", "", 0, 0, 600, 400);
auto f1 = new TF1("f1", "x*gaus(0) + [3]*abs(sin(x)/x)", -50.0, 50.0);
f1->SetParameters(20.0, 4.0, 1.0, 20.0);
auto h1 = new TH1F("h1", "Test random numbers", 200, -50.0, 50.0);
h1->FillRandom("f1", 100000);
h1->Draw();
h1->Fit(f1, "Q");
Canvas1->SetGrid();
info = new TText(0.0, h1->GetMaximum()*0.7, "please move the mouse over the frame");
info->SetTextSize(0.04);
info->SetTextAlign(22);
info->SetTextColor(kRed-1);
info->Draw();
Canvas1->Update();
Canvas1->HighlightConnect("HighlightZoom(TVirtualPad*,TObject*,Int_t,Int_t)");
}
void HighlightZoom(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb)
{
auto h = (TH1F *)obj;
if(!h) return;
auto Canvas2 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("Canvas2");
static TH1 *hz = 0;
if (!h->IsHighlight()) { // after highlight disabled
if (Canvas2) delete Canvas2;
if (hz) { delete hz; hz = 0; }
return;
}
info->SetTitle("");
if (!Canvas2) {
Canvas2 = new TCanvas("Canvas2", "Canvas2", 605, 0, 400, 400);
Canvas2->SetGrid();
if (hz) hz->Draw(); // after reopen this canvas
}
if (!hz) {
hz = (TH1 *)h->Clone("hz");
hz->SetTitle(TString::Format("%s (zoomed)", hz->GetTitle()));
hz->Draw();
Canvas2->Update();
}
Int_t zf = hz->GetNbinsX()*0.05; // zoom factor
hz->GetXaxis()->SetRange(xhb-zf, xhb+zf);
Canvas2->Modified();
Canvas2->Update();
}
Date
March 2018
Author
Jan Musinsky

Definition in file hlHisto4.C.

TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:54
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
h1
TH1F * h1
Definition: legend1.C:5
TF1::SetParameters
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:640
TH1::SetTitle
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6344
TPad::Modified
void Modified(Bool_t flag=1)
Definition: TPad.h:414
TAxis::SetRange
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition: TAxis.cxx:920
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
h
#define h(i)
Definition: RSha256.hxx:124
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
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
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
TStyle::SetGridColor
void SetGridColor(Color_t color=0)
Definition: TStyle.h:353
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::SetStats
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8445
TH1::FillRandom
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3444
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
TText
Definition: TText.h:22
f1
TF1 * f1
Definition: legend1.C:11
TVirtualPad
Definition: TVirtualPad.h:50
TCanvas
Definition: TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
TObject
Definition: TObject.h:37
TH1
Definition: TH1.h:57
TCanvas::Update
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2500
kCannotPick
@ kCannotPick
Definition: TObject.h:344
TPad::SetGrid
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:327
kGray
@ kGray
Definition: Rtypes.h:65
TH1::Fit
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
Definition: TH1.cxx:3807
TF1
1-Dim function class
Definition: TF1.h:212
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:317
TH1::GetMaximum
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition: TH1.cxx:8005
TCanvas::HighlightConnect
virtual void HighlightConnect(const char *slot)
This is "simplification" for function TCanvas::Connect with Highlighted signal for specific slot.
Definition: TCanvas.cxx:1629
TH1::GetNbinsX
virtual Int_t GetNbinsX() const
Definition: TH1.h:293
gROOT
#define gROOT
Definition: TROOT.h:406
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997