Logo ROOT  
Reference Guide
hlHisto3.C File Reference

Detailed Description

This tutorial demonstrates how the highlight mechanism can be used on a ntuple.

The ntuple in hsimple.root is drawn with three differents selection. Moving the mouse ove the two 1D representation display the on 2D plot the events contributing to the highlighted bin.

TList *list1 = nullptr, *list2 = nullptr;
TList *InitGraphs(TNtuple *nt, TH1F *histo, Bool_t is_top)
Double_t *px = nt->GetV1();
Double_t *py = nt->GetV2();
Double_t *pz = nt->GetV3();
auto list = new TList();
Int_t nbins = histo->GetNbinsX();
for (Int_t bin = 0; bin < nbins; bin++) {
auto g = new TGraph();
g->SetName(TString::Format("g%sbin_%d", histo->GetName(), bin+1));
for (Long64_t ie = 0; ie < nev; ie++) {
Double_t value = is_top ? pz[ie] : px[ie]*py[ie]*pz[ie];
Int_t bin = histo->FindBin(value) - 1;
auto g = dynamic_cast<TGraph *>(list->At(bin));
if (g) g->SetPoint(g->GetN(), py[ie], px[ie]);
return list;
void Highlight3(TVirtualPad *pad, TObject *obj, Int_t xhb, Int_t yhb)
auto histo = dynamic_cast<TH1F *>(obj);
if(!histo) return;
TCanvas *Canvas2 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("Canvas2");
if (!Canvas2) return;
TGraph *gcommon = (TGraph *)Canvas2->FindObject("Graph");
if (!gcommon) return;
TList *list = nullptr;
if (!strcmp(histo->GetName(), "histo1"))
list = list1;
else if (!strcmp(histo->GetName(), "histo2"))
list = list2;
if (!list) return;
TGraph *g = (TGraph *)list->At(xhb);
if (!g) return;
TVirtualPad *savepad = gPad;
//gcommon->SetTitle(TString::Format("%d / %d", g->GetN(), gcommon->GetN()));
if (histo->IsHighlight()) // don't draw g after highlight disabled
if (g->GetN() > 0)
if (savepad) savepad->cd();
void hlHisto3()
auto dir = gROOT->GetTutorialDir();
if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
auto file = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
if (!file) return;
TNtuple *ntuple;
file->GetObject("ntuple", ntuple);
if (!ntuple) return;
const char *cut = "pz > 3.0";
TCanvas *Canvas1 = new TCanvas("Canvas1", "Canvas1", 0, 0, 700, 500);
Canvas1->Divide(1, 2);
TCanvas *Canvas2 = new TCanvas("Canvas2", "Canvas2", 705, 0, 500, 500);
// Case1, histo1, pz distribution
ntuple->Draw("pz>>histo1(100, 2.0, 12.0)", cut);
auto histo1 = (TH1F *)gPad->FindObject("histo1");
auto info1 = new TText(7.0, histo1->GetMaximum()*0.6,
"please move the mouse over the frame");
// Case2, histo2, px*py*pz distribution
ntuple->Draw("(px*py*pz)>>histo2(100, -50.0, 50.0)", cut);
auto histo2 = (TH1F *)gPad->FindObject("histo2");
auto info2 = new TText(10.0, histo2->GetMaximum()*0.6, info1->GetTitle());
// set highlight after first drawing completed
// Common graph (all entries, all histo bins)
ntuple->Draw("px:py", cut);
auto gcommon = (TGraph *)gPad->FindObject("Graph");
gcommon->SetBit(kCanDelete, kFALSE); // will be redraw
auto htemp = (TH2F *)gPad->FindObject("htemp");
// Must be last
ntuple->Draw("px:py:pz", cut, "goff");
list1 = InitGraphs(ntuple, histo1, true);
list2 = InitGraphs(ntuple, histo2, false);
bool Bool_t
Definition: RtypesCore.h:63
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
double Double_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:80
@ kGreen
Definition: Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t g
#define gInterpreter
Definition: TInterpreter.h:564
@ kCanDelete
Definition: TObject.h:354
@ kCannotPick
Definition: TObject.h:359
#define gROOT
Definition: TROOT.h:404
#define gPad
Definition: TVirtualPad.h:288
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
The Canvas class.
Definition: TCanvas.h:23
virtual void HighlightConnect(const char *slot)
This is "simplification" for function TCanvas::Connect with Highlighted signal for specific slot.
Definition: TCanvas.cxx:1631
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition: TCanvas.cxx:706
void Update() override
Update canvas pad buffers.
Definition: TCanvas.cxx:2502
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition: TGraph.cxx:806
TAxis * GetXaxis() const
Get x axis of the graph.
Definition: TGraph.cxx:1552
TAxis * GetYaxis() const
Get y axis of the graph.
Definition: TGraph.cxx:1562
void SetTitle(const char *title="") override
Change (i.e.
Definition: TGraph.cxx:2337
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:574
virtual Int_t GetNbinsX() const
Definition: TH1.h:295
virtual Bool_t IsHighlight() const
Definition: TH1.h:333
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
Definition: TH1.cxx:3678
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:257
A doubly linked list.
Definition: TList.h:38
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:357
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
A simple TTree restricted to a list of float variables only.
Definition: TNtuple.h:28
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:696
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition: TPad.cxx:1169
TObject * FindObject(const char *name) const override
Search if object named name is inside this pad or in pads inside this pad.
Definition: TPad.cxx:2621
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:2336
Base class for several text objects.
Definition: TText.h:22
virtual Long64_t GetSelectedRows()
Definition: TTree.h:509
void Draw(Option_t *opt) override
Default Draw method for all objects.
Definition: TTree.h:428
virtual Double_t * GetV3()
Definition: TTree.h:536
virtual Double_t * GetV1()
Definition: TTree.h:532
virtual Double_t * GetV2()
Definition: TTree.h:534
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:51
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
Definition: file.py:1
March 2018
Jan Musinsky

Definition in file hlHisto3.C.