Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ZoomHistogram.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/// \author Advait Dhingra
15
16void ZoomHistogram() {
17
18 TH1F *norm = new TH1F("Normal Histogram", "Normal Histogram", 100, 0, 100);
19
20 for (int i = 0; i < 100; ++i) {
21 Double_t x = gRandom->Gaus(50, 10);
22 norm->Fill(x);
23 }
24
25 TH1F *zoom = (TH1F*) norm->Clone("zoom");
26 zoom->SetTitle("Zoomed-in Histogram");
27 zoom->GetXaxis()->SetRangeUser(50, 100);
28
29 TCanvas *c1 = new TCanvas("c1", "Histogram", 1500, 700);
30 c1->Divide(2, 1);
31
32 c1->cd(1);
33 norm->Draw();
34 c1->cd(2);
35 zoom->Draw();
36}
double Double_t
Definition RtypesCore.h:59
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Set the viewing range for the axis from ufirst to ulast (in user coordinates, that is,...
Definition TAxis.cxx:946
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition TH1.cxx:6667
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition TH1.h:320
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
Definition TH1.cxx:2741
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3351
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3074
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:274
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17