Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
hlGraph2.C File Reference

Detailed Description

This tutorial demonstrates how to use the highlight mode on graph.

TNtuple *ntuple = nullptr;
{
auto Canvas2 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("Canvas2");
if (!Canvas2) return;
auto histo = (TH1F *)Canvas2->FindObject("histo");
if (!histo) return;
Double_t px = ntuple->GetV1()[ihp];
Double_t py = ntuple->GetV2()[ihp];
Double_t pz = ntuple->GetV3()[ihp];
Double_t i = ntuple->GetV4()[ihp];
Double_t p = TMath::Sqrt(px*px + py*py + pz*pz);
Int_t hbin = histo->FindBin(p);
auto bh = (TBox *)Canvas2->FindObject("TBox");
if (!bh) {
bh = new TBox();
bh->SetFillColor(kBlack);
bh->SetFillStyle(3001);
bh->SetBit(kCannotPick);
bh->SetBit(kCanDelete);
}
bh->SetX1(histo->GetBinLowEdge(hbin));
bh->SetY1(histo->GetMinimum());
bh->SetX2(histo->GetBinWidth(hbin) + histo->GetBinLowEdge(hbin));
bh->SetY2(histo->GetBinContent(hbin));
auto th = (TText *)Canvas2->FindObject("TText");
if (!th) {
th = new TText();
th->SetName("TText");
th->SetTextColor(bh->GetFillColor());
th->SetBit(kCanDelete);
}
th->SetText(histo->GetXaxis()->GetXmax()*0.75, histo->GetMaximum()*0.5,
TString::Format("id = %d", (Int_t)i));
if (ihp == -1) { // after highlight disabled
delete bh;
delete th;
}
Canvas2->Modified();
Canvas2->Update();
if (!redraw) return;
auto savepad = gPad;
Canvas2->cd();
bh->Draw();
th->Draw();
Canvas2->Update();
savepad->cd();
}
void hlGraph2()
{
auto dir = gROOT->GetTutorialDir();
dir.Append("/hsimple.C");
dir.ReplaceAll("/./","/");
if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
auto file = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
if (!file) return;
file->GetObject("ntuple", ntuple);
if (!ntuple) return;
TCanvas *Canvas1 = new TCanvas("Canvas1", "Canvas1", 0, 0, 500, 500);
Canvas1->HighlightConnect("HighlightBinId(TVirtualPad*,TObject*,Int_t,Int_t)");
const char *cut = "pz > 3.0";
ntuple->Draw("px:py", cut);
TGraph *graph = (TGraph *)gPad->FindObject("Graph");
auto info = new TText(0.0, 4.5, "please move the mouse over the graph");
info->SetTextAlign(22);
info->SetTextSize(0.03);
info->SetTextColor(kRed+1);
info->SetBit(kCannotPick);
info->Draw();
graph->SetHighlight();
auto Canvas2 = new TCanvas("Canvas2", "Canvas2", 505, 0, 600, 400);
ntuple->Draw("TMath::Sqrt(px*px + py*py + pz*pz)>>histo(100, 0, 15)", cut);
// Must be last
ntuple->Draw("px:py:pz:i", cut, "goff");
}
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
@ kRed
Definition Rtypes.h:66
@ kBlack
Definition Rtypes.h:65
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
#define gInterpreter
@ kCanDelete
Definition TObject.h:367
@ kCannotPick
Definition TObject.h:372
#define gROOT
Definition TROOT.h:406
#define gPad
Create a Box.
Definition TBox.h:22
The Canvas class.
Definition TCanvas.h:23
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:622
A simple TTree restricted to a list of float variables only.
Definition TNtuple.h:28
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
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
Double_t y[n]
Definition legend1.C:17
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
Definition graph.py:1
Date
March 2018
Author
Jan Musinsky

Definition in file hlGraph2.C.