#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" char dataout[200]="G:/cors/prot/gammaprot_netheta.png"; float offx=1.1; float offy=1.; float margr=0.3; float margl=0.12; void netheta() { 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:/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 *hnethetag = (TH1F *)g->Get("hnetheta"); if (hnetheta == 0) { printf("Error getting an histogram from the file!\n"); return; } TH1F *hnthetap = (TH1F *)p->Get("hnetheta"); if (hnthetap == 0) { printf("Error getting an histogram from the file!\n"); return; } gStyle->SetOptFit(); TCanvas *c3 = new TCanvas("c3","hists with different scales",1280,1024); c3->SetLogx(); c3->SetLogy(); //gPad->SetLeftMargin(margl); //gPad->SetRightMargin(margr); TF1 *fitspettro = new TF1("fitspettro", "[0] * TMath::Power(2.71828 18284, -4300/[1]*x)", 0, 1e3); fitspettro->SetParameters(2e4,106); fitspettro->SetParName(0,"N"); fitspettro->SetParName(1,"#lambda"); hnethetag->SetLineColor(kBlue); hnethetag->SetTitle("Title"); hnethetag.GetXaxis()->SetTitle("x title"); hnethetag.GetYaxis()->SetTitle("y title"); hnethetag->GetXaxis()->SetTitleOffset(offx); hnethetag->GetYaxis()->SetTitleOffset(offy); hnethetag->SetName("Name"); hnthetap->SetName("#font[12]{p}"); hnethetag->Draw(); hnethetag->Fit("fitspettro"); c3->Update(); hnthetap->SetLineColor(kGreen); hnthetap->Draw("sames"); hnthetap->Fit("fitspettro"); c3->Update(); TLegend* leg = new TLegend(0.6, 0.7, .4, .80); leg->SetNColumns(1); leg->AddEntry(hnethetag, "#gamma", "l"); leg->AddEntry(hnthetap, "#font[12]{p}", "l"); leg->Draw("same"); TPaveStats *stats1 = (TPaveStats*)hnethetag->GetListOfFunctions()->FindObject("stats"); TPaveStats *stats2 = (TPaveStats*)hnthetap->GetListOfFunctions()->FindObject("stats"); stats1->SetTextColor(kBlue); stats2->SetTextColor(kGreen); stats1->SetX1NDC(0.80); stats1->SetX2NDC(0.98); stats1->SetY1NDC(0.77); stats1->SetY2NDC(0.92); stats2->SetX1NDC(0.80); stats2->SetX2NDC(0.98); stats2->SetY1NDC(0.60); stats2->SetY2NDC(0.75); c3->Update(); gROOT->ProcessLine("gROOT->SetBatch()"); c3.Print(dataout); delete c3; gROOT->ProcessLine("gROOT->SetBatch(kFALSE)"); exit(); }