ROOT
master
Reference Guide
Loading...
Searching...
No Matches
hist008_TH1_zoom.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_hist
3
/// \notebook -js
4
/// Changing the Range on the X-Axis of a Histogram
5
///
6
/// Image produced by `.x ZoomHistogram.C`
7
///
8
/// This demonstrates how to zoom into a histogram by
9
/// changing the range on one of the axes (or both).
10
///
11
/// \macro_image
12
/// \macro_code
13
///
14
/// \date November 2024
15
/// \author Advait Dhingra
16
17
void
hist008_TH1_zoom
()
18
{
19
// Create and fill a histogram
20
TH1F
*
orig
=
new
TH1F
(
"Normal Histogram"
,
"Normal Histogram"
, 100, 0, 100);
21
22
TRandom3
rng
;
23
for
(
int
i = 0; i < 1000; ++i) {
24
double
x
=
rng
.Gaus(50, 10);
25
orig
->Fill(
x
);
26
}
27
28
// Clone the histogram into one called "zoom"
29
TH1F
*
zoom
=
static_cast<
TH1F
*
>
(
orig
->Clone(
"zoom"
));
30
zoom
->SetTitle(
"Zoomed-in Histogram"
);
31
// "Zoom" in the histogram by setting a new range to the X axis
32
zoom
->GetXaxis()->SetRangeUser(50, 100);
33
34
// Draw both histograms to a canvas
35
TCanvas
*
c1
=
new
TCanvas
(
"c1"
,
"Histogram"
, 1500, 700);
36
// split the canvas horizontally in 2
37
int
nsubdivX
= 2;
38
int
nsubdivY
= 1;
39
c1
->Divide(
nsubdivX
,
nsubdivY
);
40
41
c1
->cd(1);
42
orig
->Draw();
43
c1
->cd(2);
44
zoom
->Draw();
45
}
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:645
TRandom3
Random number generator class based on M.
Definition
TRandom3.h:27
c1
return c1
Definition
legend1.C:41
x
Double_t x[n]
Definition
legend1.C:17
tutorials
hist
hist008_TH1_zoom.C
ROOT master - Reference Guide Generated on Fri Jan 24 2025 04:37:19 (GVA Time) using Doxygen 1.10.0