#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TH2.h" #include "TH3.h" #include "TGaxis.h" #include "TRandom.h" #include "TLegend.h" #include "TPaveStats.h" #include "TGraph.h" void hfirstint() { TFile *g = TFile::Open("G:/cors/gamma/gammatot/cors_plot-gammatot.root"); if (g == 0) { // if we cannot open the file, print an error message and return immediatly printf("Error: cannot open cors_plot.root!\n"); return; } g->ls(); TFile *p = TFile::Open("G:/cors/prot/prottot/cors_plot-prottot.root"); if (p == 0) { // if we cannot open the file, print an error message and return immediatly printf("Error: cannot open cors_plot.root!\n"); return; } p->ls(); TH1F *hfirstintg = (TH1F *)g->Get("hfirstint"); if (hene == 0) { printf("Error getting an histogram from the file!\n"); return; } TH1F *hfirstintp = (TH1F *)p->Get("hfirstint"); if (hene == 0) { printf("Error getting an histogram from the file!\n"); return; } float offx=1.2; float offy=1; float marg=0.15; TCanvas *c2 = new TCanvas("c2","hists with different scales",1280,1024); TPad *pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0); pad1->SetBottomMargin(0); // Upper and lower plot are joined pad1->SetGridx(); // Vertical grid pad1->Draw(); // Draw the upper pad: pad1 pad1->cd(); // pad1 becomes the current pad // hfirstintg->SetStats(0); // No statistics on upper plot //c2->SetLogx(); //c2->SetLogy(); //hfirstintg->SetMaximum(5.5e4); hfirstintg->SetLineColor(kBlack); hfirstintg->SetTitle("Quota di prima interazione dei #gamma e #font[12]{p} primari"); hfirstintg.GetXaxis()->SetTitle("Altezza (Km)"); hfirstintg.GetYaxis()->SetTitle("N_{part}"); hfirstintg->GetYaxis()->SetTitleOffset(offy); c2->SetLeftMargin(marg); hfirstintg->Draw(); c2->Update(); hfirstintp->SetLineColor(kBlue); hfirstintp->Draw("sames"); // Do not draw the Y axis label on the upper plot and redraw a small // axis instead, in order to avoid the first label (0) to be clipped. hfirstintg->GetYaxis()->SetLabelSize(0.); TGaxis *axis = new TGaxis( -5, 20, -5, 220, 20,220,510,""); axis->SetLabelFont(43); // Absolute font size in pixel (precision 3) axis->SetLabelSize(15); axis->Draw(); c2->Update(); c2->cd(); // Go back to the main canvas before defining pad2 TPad *pad2 = new TPad("pad2", "pad2", 0, 0.05, 1, 0.3); pad2->SetTopMargin(0); pad2->SetBottomMargin(0.2); pad2->SetGridx(); // vertical grid pad2->Draw(); pad2->cd(); // pad2 becomes the current pad c2->Update(); // Define the ratio plot TLegend* leg = new TLegend(0.6, 0.7, .4, .80); leg->SetNColumns(1); leg->AddEntry(hfirstintg, "#gamma", "l"); leg->AddEntry(hfirstintp, "#font[12]{p}", "l"); leg->Draw("same"); TPaveStats *stats1 = (TPaveStats*)hfirstintg->GetListOfFunctions()->FindObject("stats"); TPaveStats *stats2 = (TPaveStats*)hfirstintp->GetListOfFunctions()->FindObject("stats"); stats1->SetTextColor(kBlack); stats2->SetTextColor(kBlue); stats1->SetX1NDC(0.80); stats1->SetX2NDC(0.98); stats1->SetY1NDC(0.79); stats1->SetY2NDC(0.94); stats2->SetX1NDC(0.80); stats2->SetX2NDC(0.98); stats2->SetY1NDC(0.62); stats2->SetY2NDC(0.77); c2->Update(); TH1F *h3 = (TH1F*)hfirstintg->Clone("h3"); h3->SetLineColor(kBlack); h3->SetMinimum(0); // Define Y .. h3->SetMaximum(15.); // .. range h3->Sumw2(); h3->SetStats(0); // No statistics on lower plot h3->Divide(hfirstintp); h3->SetMarkerStyle(21); h3->Draw("ep"); // Draw the ratio plot // Ratio plot (h3) settings h3->SetTitle(""); // Remove the ratio title // Y axis ratio plot settings h3->GetYaxis()->SetTitle("h_{#gamma}/h_{p} "); h3->GetYaxis()->SetNdivisions(505); h3->GetYaxis()->SetTitleSize(20); h3->GetYaxis()->SetTitleFont(43); h3->GetYaxis()->SetTitleOffset(1.55); h3->GetYaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3) h3->GetYaxis()->SetLabelSize(15); // X axis ratio plot settings h3->GetXaxis()->SetTitleSize(20); h3->GetXaxis()->SetTitleFont(43); h3->GetXaxis()->SetTitleOffset(4.); h3->GetXaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3) h3->GetXaxis()->SetLabelSize(15); gROOT->ProcessLine("gROOT->SetBatch()"); c2.Print("G:/cors/gamma/gammaeprot_tot_firstint.pdf"); delete c2; gROOT->ProcessLine("gROOT->SetBatch(kFALSE)"); }