ROOT
Version v6.34
master
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
hlHisto1.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.
6
/// Then an highlight method is connected to the histogram. Moving the mouse
7
/// on the histogram will update the histogram title in real time according to
8
/// the highlighted bin.
9
///
10
/// \macro_code
11
///
12
/// \date March 2018
13
/// \author Jan Musinsky
14
15
TText
*
info
=
nullptr
;
16
17
void
HighlightTitle
(
TVirtualPad
*
pad
,
TObject
*obj,
Int_t
xhb
,
Int_t
yhb
)
18
{
19
auto
h2
=
dynamic_cast<
TH2F
*
>
(obj);
20
if
(!h2)
return
;
21
if
(!
h2
->IsHighlight()) {
// after highlight disabled
22
h2
->SetTitle(
"Disable highlight"
);
23
return
;
24
}
25
if
(
info
)
info
->SetTitle(
""
);
26
TString
t;
27
t.
Form
(
"bin[%02d, %02d] (%5.2f, %5.2f) content %g"
,
xhb
,
yhb
,
28
h2
->GetXaxis()->GetBinCenter(
xhb
),
h2
->GetYaxis()->GetBinCenter(
yhb
),
29
h2
->GetBinContent(
xhb
,
yhb
));
30
h2
->SetTitle(t.
Data
());
31
pad
->Update();
32
}
33
34
void
hlHisto1
()
35
{
36
auto
c1
=
new
TCanvas
();
37
c1
->HighlightConnect(
"HighlightTitle(TVirtualPad*,TObject*,Int_t,Int_t)"
);
38
39
auto
h2
=
new
TH2F
(
"h2"
,
""
, 50, -5.0, 5.0, 50, -5.0, 5.0);
40
for
(
Int_t
i = 0; i < 10000; i++)
h2
->Fill(
gRandom
->
Gaus
(),
gRandom
->
Gaus
());
41
h2
->Draw();
42
43
info
=
new
TText
(0.0, -4.0,
"please move the mouse over the frame"
);
44
info
->SetTextAlign(22);
45
info
->SetTextColor(
kRed
+1);
46
info
->SetBit(
kCannotPick
);
47
info
->Draw();
48
c1
->Update();
49
50
// call after update to apply changes in the histogram painter
51
h2
->SetHighlight();
52
}
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
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
Basic string class.
Definition
TString.h:139
TString::Data
const char * Data() const
Definition
TString.h:376
TString::Form
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition
TString.cxx:2356
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
hlHisto1.C
ROOT v6-34 - Reference Guide Generated on Sun Mar 30 2025 16:27:33 (GVA Time) using Doxygen 1.10.0