ROOT
master
Reference Guide
Loading...
Searching...
No Matches
hist044_Graphics_highlight2D.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_hist
3
///
4
/// This tutorial demonstrates how the highlight mechanism can be used on an histogram.
5
/// A 2D histogram is booked an filled with a random gaussian distribution and
6
/// drawn with the "col" option.
7
/// Then an highlight method is connected to the histogram. Moving the mouse
8
/// on the histogram open a new canvas displaying the two X and Y projections
9
/// at the highlighted bin.
10
///
11
/// \macro_code
12
///
13
/// \date March 2018
14
/// \author Jan Musinsky
15
16
TText
*
info
=
nullptr
;
17
18
void
Highlight2
(
TVirtualPad
*
pad
,
TObject
*obj,
Int_t
xhb
,
Int_t
yhb
)
19
{
20
auto
h2
=
dynamic_cast<
TH2F
*
>
(obj);
21
if
(!h2)
22
return
;
23
auto
CanvasProj
= (
TCanvas
*)
gROOT
->GetListOfCanvases()->FindObject(
"CanvasProj"
);
24
if
(!
h2
->IsHighlight()) {
// after highlight disabled
25
if
(
CanvasProj
)
26
delete
CanvasProj
;
27
h2
->SetTitle(
"Disable highlight"
);
28
return
;
29
}
30
31
if
(
info
)
32
info
->SetTitle(
""
);
33
34
auto
px =
h2
->ProjectionX(
"_px"
,
yhb
,
yhb
);
35
auto
py =
h2
->ProjectionY(
"_py"
,
xhb
,
xhb
);
36
px->SetTitle(
TString::Format
(
"ProjectionX of biny[%02d]"
,
yhb
));
37
py->SetTitle(
TString::Format
(
"ProjectionY of binx[%02d]"
,
xhb
));
38
39
if
(!
CanvasProj
) {
40
CanvasProj
=
new
TCanvas
(
"CanvasProj"
,
"CanvasProj"
, 505, 0, 600, 600);
41
CanvasProj
->Divide(1, 2);
42
CanvasProj
->cd(1);
43
px->Draw();
44
CanvasProj
->cd(2);
45
py->Draw();
46
}
47
48
h2
->SetTitle(
TString::Format
(
"Highlight bin [%02d, %02d]"
,
xhb
,
yhb
).Data());
49
pad
->Modified();
50
pad
->Update();
51
52
CanvasProj
->GetPad(1)->Modified();
53
CanvasProj
->GetPad(2)->Modified();
54
CanvasProj
->Update();
55
}
56
57
void
hist044_Graphics_highlight2D
()
58
{
59
auto
c1
=
new
TCanvas
(
"Canvas"
,
"Canvas"
, 0, 0, 500, 500);
60
c1
->HighlightConnect(
"Highlight2(TVirtualPad*,TObject*,Int_t,Int_t)"
);
61
62
auto
h2
=
new
TH2F
(
"h2"
,
""
, 50, -5.0, 5.0, 50, -5.0, 5.0);
63
for
(
Int_t
i = 0; i < 10000; i++)
64
h2
->Fill(
gRandom
->
Gaus
(),
gRandom
->
Gaus
());
65
h2
->Draw(
"col"
);
66
67
info
=
new
TText
(0.0, -4.0,
"please move the mouse over the frame"
);
68
info
->SetTextAlign(22);
69
info
->SetTextSize(0.04);
70
info
->SetTextColor(
kRed
+ 1);
71
info
->SetBit(
kCannotPick
);
72
info
->Draw();
73
c1
->Update();
74
75
h2
->SetHighlight();
76
}
Int_t
int Int_t
Definition
RtypesCore.h:45
kRed
@ kRed
Definition
Rtypes.h:66
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
kCannotPick
@ kCannotPick
Definition
TObject.h:372
gROOT
#define gROOT
Definition
TROOT.h:406
gRandom
R__EXTERN TRandom * gRandom
Definition
TRandom.h:62
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TH2F
2-D histogram with a float per channel (see TH1 documentation)
Definition
TH2.h:307
TObject
Mother of all ROOT objects.
Definition
TObject.h:41
TRandom::Gaus
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition
TRandom.cxx:275
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:2378
TText
Base class for several text objects.
Definition
TText.h:22
TVirtualPad
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition
TVirtualPad.h:51
c1
return c1
Definition
legend1.C:41
TMVA_SOFIE_GNN_Parser.h2
h2
Definition
TMVA_SOFIE_GNN_Parser.py:188
tutorials
hist
hist044_Graphics_highlight2D.C
ROOT master - Reference Guide Generated on Thu Feb 13 2025 15:59:18 (GVA Time) using Doxygen 1.10.0