ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
transpad.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// Example of a canvas showing two histograms with different scales.
4 /// The second histogram is drawn in a transparent pad
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Rene Brun
10 
11 void transpad() {
12  TCanvas *c1 = new TCanvas("c1","transparent pad",200,10,700,500);
13  TPad *pad1 = new TPad("pad1","",0,0,1,1);
14  TPad *pad2 = new TPad("pad2","",0,0,1,1);
15  pad2->SetFillStyle(4000); //will be transparent
16  pad1->Draw();
17  pad1->cd();
18 
19  TH1F *h1 = new TH1F("h1","h1",100,-3,3);
20  TH1F *h2 = new TH1F("h2","h2",100,-3,3);
21  TRandom r;
22  for (Int_t i=0;i<100000;i++) {
23  Double_t x1 = r.Gaus(-1,0.5);
24  Double_t x2 = r.Gaus(1,1.5);
25  if (i <1000) h1->Fill(x1);
26  h2->Fill(x2);
27  }
28  h1->Draw();
29  pad1->Update(); //this will force the generation of the "stats" box
30  TPaveStats *ps1 = (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats");
31  ps1->SetX1NDC(0.4); ps1->SetX2NDC(0.6);
32  pad1->Modified();
33  c1->cd();
34 
35  //compute the pad range with suitable margins
36  Double_t ymin = 0;
37  Double_t ymax = 2000;
38  Double_t dy = (ymax-ymin)/0.8; //10 per cent margins top and bottom
39  Double_t xmin = -3;
40  Double_t xmax = 3;
41  Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
42  pad2->Range(xmin-0.1*dx,ymin-0.1*dy,xmax+0.1*dx,ymax+0.1*dy);
43  pad2->Draw();
44  pad2->cd();
45  h2->SetLineColor(kRed);
46  h2->Draw("][sames");
47  pad2->Update();
48  TPaveStats *ps2 = (TPaveStats*)h2->GetListOfFunctions()->FindObject("stats");
49  ps2->SetX1NDC(0.65); ps2->SetX2NDC(0.85);
50  ps2->SetTextColor(kRed);
51 
52  // draw axis on the right side of the pad
53  TGaxis *axis = new TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,50510,"+L");
54  axis->SetLabelColor(kRed);
55  axis->Draw();
56 }
57 
58 
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
TList * GetListOfFunctions() const
Definition: TH1.h:244
float xmin
Definition: THbookFile.cxx:93
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:235
virtual void SetX2NDC(Double_t x2)
Definition: TPave.h:88
Definition: Rtypes.h:61
float ymin
Definition: THbookFile.cxx:93
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
virtual void Update()
Update pad.
Definition: TPad.cxx:2721
int Int_t
Definition: RtypesCore.h:41
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:254
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:497
The histogram statistics painter class.
Definition: TPaveStats.h:28
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:29
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1192
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Set world coordinate system for the pad.
Definition: TPad.cxx:4623
virtual void SetX1NDC(Double_t x1)
Definition: TPave.h:87
The most important graphics class in the ROOT system.
Definition: TPad.h:46
The axis painter class.
Definition: TGaxis.h:39
The Canvas class.
Definition: TCanvas.h:48
double Double_t
Definition: RtypesCore.h:55
virtual void SetFillStyle(Style_t fstyle)
Override TAttFill::FillStyle for TPad because we want to handle style=0 as style 4000.
Definition: TPad.cxx:5289
void SetLabelColor(Int_t labelcolor)
Definition: TGaxis.h:115
virtual void SetTextColor(Color_t tcolor=1)
Definition: TAttText.h:57
void Modified(Bool_t flag=1)
Definition: TPad.h:407