Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hlGraph1.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graPads
3///
4/// This tutorial demonstrates how to use the highlight mode on graph.
5///
6/// \macro_code
7///
8/// \date March 2018
9/// \author Jan Musinsky
10
11TList *l = nullptr;
12
13void HighlightHisto(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y)
14{
15 auto Pad = (TVirtualPad *)pad->FindObject("Pad");
16 if (!Pad) return;
17
18 if (ihp == -1) { // after highlight disabled
19 Pad->Clear();
20 return;
21 }
22
23 if (l && l->At(ihp)) {
24 Pad->cd();
25 l->At(ihp)->Draw();
26 gPad->Update();
27 }
28}
29
30void hlGraph1()
31{
32 auto Canvas = new TCanvas("Canvas", "Canvas", 0, 0, 700, 500);
33 Canvas->HighlightConnect("HighlightHisto(TVirtualPad*,TObject*,Int_t,Int_t)");
34 const Int_t n = 500;
35 Double_t x[n], y[n];
36 l = new TList();
37
38 for (Int_t i = 0; i < n; i++) {
39 auto h = new TH1F(TString::Format("h_%03d", i), "", 100, -3.0, 3.0);
40 h->FillRandom("gaus", 1000);
41 h->Fit("gaus", "Q");
42 h->SetMaximum(250.0); // for n > 200
43 l->Add(h);
44 x[i] = i;
45 y[i] = h->GetFunction("gaus")->GetParameter(2);
46 }
47
48 auto g = new TGraph(n, x, y);
49 g->SetMarkerStyle(6);
50 g->Draw("AP");
51
52 auto Pad = new TPad("Pad", "Pad", 0.3, 0.4, 1.0, 1.0);
53 Pad->SetFillColor(kBlue-10);
54 Pad->Draw();
55 Pad->cd();
56 auto info = new TText(0.5, 0.5, "please move the mouse over the graPad");
57 info->SetTextAlign(22);
58 info->Draw();
59 Canvas->cd();
60
61 g->SetHighlight();
62}
#define g(i)
Definition RSha256.hxx:105
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kBlue
Definition Rtypes.h:66
#define gPad
The Canvas class.
Definition TCanvas.h:23
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:621
A doubly linked list.
Definition TList.h:38
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Clear(Option_t *="")
Definition TObject.h:119
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:403
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
The most important graphics class in the ROOT system.
Definition TPad.h:28
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 x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4