Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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.

TText *info = nullptr;
TH1 *hz = nullptr;
{
auto h = dynamic_cast<TH1F *>(obj);
if(!h) return;
auto Canvas2 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("Canvas2");
if (!h->IsHighlight()) { // after highlight disabled
if (Canvas2) delete Canvas2;
if (hz) { delete hz; hz = nullptr; }
return;
}
if (info) 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->SetStats(kFALSE);
hz->Draw();
Canvas2->Update();
hz->SetHighlight(kFALSE);
}
Int_t zf = hz->GetNbinsX()*0.05; // zoom factor
hz->GetXaxis()->SetRange(xhb-zf, xhb+zf);
Canvas2->Modified();
Canvas2->Update();
}
void hlHisto4()
{
auto Canvas1 = new TCanvas("Canvas1", "", 0, 0, 600, 400);
Canvas1->HighlightConnect("HighlightZoom(TVirtualPad*,TObject*,Int_t,Int_t)");
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->SetBit(kCannotPick);
info->Draw();
Canvas1->Update();
// configure highlight at the end when histogram is already painted
}
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
@ kGray
Definition Rtypes.h:65
@ kRed
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kCannotPick
Definition TObject.h:372
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:233
virtual void SetParameters(const Double_t *params)
Definition TF1.h:670
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:621
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3519
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:3898
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:8513
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
virtual void SetHighlight(Bool_t set=kTRUE)
Set highlight (enable/disable) mode for the histogram by default highlight mode is disable.
Definition TH1.cxx:4459
Mother of all ROOT objects.
Definition TObject.h:41
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:2378
void SetGridColor(Color_t color=0)
Definition TStyle.h:367
Base class for several text objects.
Definition TText.h:22
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
TH1F * h1
Definition legend1.C:5
TF1 * f1
Definition legend1.C:11
Date
March 2018
Author
Jan Musinsky

Definition in file hlHisto4.C.