#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_plotgamma.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_plotprot.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 (hnethetag == 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); Double_t lambda = 106.; Double_t X_0 = 4300.; TF1 *fitspettro = new TF1("fitspettro", "[0] * TMath::Exp(-x * [2] / [1])", 0, 1e3); fitspettro->SetParNames("N_{e}^{}(0)", "#lambda", "X_{0}^{}"); fitspettro->SetParameters(0., lambda, X_0); fitspettro->FixParameter(2, X_0); // fix "X_0" 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("EAS ind #gamma"); hnthetap->SetName(" EAS ind. #font[12]{p}"); hnethetag->Draw(); fitspettro->SetParameters(1., lambda, X_0); fitspettro->SetParameter(0, hnethetag->GetBinContent(1)/fitspettro->Eval(hnethetag->GetBinCenter(1))); hnethetag->Fit(fitspettro); c3->Update(); hnthetap->SetLineColor(kGreen); hnthetap->Draw("sames"); fitspettro->SetParameters(1., lambda, X_0); fitspettro->SetParameter(0, hnthetap->GetBinContent(1)/fitspettro->Eval(hnthetap->GetBinCenter(1))); 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(); }