00001
00002 #include "TCanvas.h"
00003 #include "TStyle.h"
00004 #include "TH1.h"
00005 #include "TGaxis.h"
00006 #include "TRandom.h"
00007
00008 void twoscales()
00009 {
00010
00011
00012
00013
00014
00015 TCanvas *c1 = new TCanvas("c1","hists with different scales",600,400);
00016
00017
00018 gStyle->SetOptStat(kFALSE);
00019 TH1F *h1 = new TH1F("h1","my histogram",100,-3,3);
00020 Int_t i;
00021 for (i=0;i<10000;i++) h1->Fill(gRandom->Gaus(0,1));
00022 h1->Draw();
00023 c1->Update();
00024
00025
00026 TH1F *hint1 = new TH1F("hint1","h1 bins integral",100,-3,3);
00027 Float_t sum = 0;
00028 for (i=1;i<=100;i++) {
00029 sum += h1->GetBinContent(i);
00030 hint1->SetBinContent(i,sum);
00031 }
00032
00033
00034 Float_t rightmax = 1.1*hint1->GetMaximum();
00035 Float_t scale = gPad->GetUymax()/rightmax;
00036 hint1->SetLineColor(kRed);
00037 hint1->Scale(scale);
00038 hint1->Draw("same");
00039
00040
00041 TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
00042 gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"+L");
00043 axis->SetLineColor(kRed);
00044 axis->SetLabelColor(kRed);
00045 axis->Draw();
00046 }