i have two data to analyse .My purpose is to compare the two different data.So i want to plot them in the same picture.This is my programm:
I run it use root5.11 , it can use,but i download the root5.13, it can’t.
please you help me!
// Example of a canvas showing two histograms with different scales.
// The second histogram is drawn in a transparent pad
void t() {
TCanvas *c1 = new TCanvas(“c1”,“transparent pad”,200,10,700,500);
c1->SetFrameBorderMode(0);
c1->SetBorderMode(0);
c1->SetBorderSize(0);
//gStyle->SetOptStat(kFALSE);
TPad *pad1 = new TPad(“pad1”,"",0,0,1,1);
TPad *pad2 = new TPad(“pad2”,"",0,0,1,1);
// TPad *pad2 = new TPad(“pad2”,"",0.2,0.2,0.8,0.;
pad2->SetFillStyle(4000); //will be transparent
pad1->Draw();
gStyle->SetOptStat(kFALSE);
pad1->cd();
pad1->SetBorderMode(0);
pad1->SetBorderSize(0);
pad1->SetFillColor(10);
FILE *fp;
fp=fopen(“data.txt”,“r”);
// TH1F *h1 = new TH1F(“h1”,"",744,1,745);
// TH1F *h2 = new TH1F(“h2”,"",744,1,745);
TH1F *h1 = new TH1F(“h1”,"",744,1,32);
TH1F *h2 = new TH1F(“h2”,"",744,1,32);
Float_t x,y1,y2;
for (Int_t i=1;i<744>SetBinContent(i,y1);
h2->SetBinContent(i,y2);
}
h1->SetLineWidth(1);
h1->SetLineStyle(2);
// h1->SetMarkerStyle(2);
//h1->SetMarkerSize(1);
// h1->SetMarkerColor(4);
h1->GetXaxis()->SetTitle(“Time(day,UT)”);
h1->GetXaxis()->CenterTitle();
h1->GetXaxis()->SetNdivisions(31);
h1->GetXaxis()->SetLabelSize(0.03);
h1->GetXaxis()->SetRangeUser(1,31.9);
h1->GetYaxis()->SetTitle(“P(mb)”);
h1->GetYaxis()->CenterTitle();
h1->GetYaxis()->SetLabelSize(0.03);
//gPad->SetTicky(0);
h1->Draw();
// h2->Draw();
pad1->Modified();
c1->cd();
//compute the pad range with suitable margins
Double_t ymin = 2850;
Double_t ymax = 3300;
Double_t dy = (ymax-ymin)/0.8; //10 per cent margins top and bottom
Double_t xmin = 1; //0.041667,30.041667
Double_t xmax = 32;
Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
pad2->Range(xmin-0.1dx,ymin-0.1dy,xmax+0.1dx,ymax+0.1dy);
pad2->Draw();
pad2->cd();
pad2->SetBorderMode(0);
pad2->SetBorderSize(0);
pad2->SetFillColor(10);
//h2->SetLineColor(kBlue);
h2->SetLineStyle(1);
h2->SetLineWidth(2);
h2->Draw(“lsames”);
leg = new TLegend(0.78,0.78,0.89,0.89);
leg->AddEntry(h1,“p”,“l”);
leg->AddEntry(h2,“counts”,“l”);
leg->SetBorderSize(0);
leg->SetFillColor(10);
leg->Draw();
pad2->Update();
// draw axis on the right side of the pad
TGaxis *axis = new TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,510,"+L");
axis->SetTitle(“Counts”);
// axis->SetTitleColor(4);
// axis->SetLabelColor(4);
//axis->SetLineColor(4);
axis->CenterTitle();
axis->SetLabelSize(0.03);
//axis->SetTitleOffset(1);
axis->Draw();
}
nm.rar (9.42 KB)
nm.rar (9.42 KB)