#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TGaxis.h" #include "TRandom.h" #include "TLegend.h" #include "TPaveStats.h" char dataing[200]="D:/cors_plot-gamma.root"; char datainp[200]="D:/cors_plot-prot.root"; char dataout[200]= "D:/mu_distr_lat.png"; void distrlat() { TFile *g = TFile::Open(dataing); 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(datainp); 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 *hgamlatg = (TH1F *)g->Get("hgamlat"); if (hgamlatg == 0) { printf("Error getting an histogram from the file!\n"); return; } TH1F *helelatg = (TH1F *)g->Get("helelat"); if (helelatg == 0) { printf("Error getting an histogram from the file!\n"); return; } TH1F *hmuolatg = (TH1F *)g->Get("hmuolat"); if (hmuolatg == 0) { printf("Error getting an histogram from the file!\n"); return; } TH1F *hhadlatg = (TH1F *)g->Get("hhadlat"); if (hhadlatg == 0) { printf("Error getting an histogram from the file!\n"); return; } TH1F *hgamlatp = (TH1F *)p->Get("hgamlat"); if (hgamlatp == 0) { printf("Error getting an histogram from the file!\n"); return; } TH1F *helelatp = (TH1F *)p->Get("helelat"); if (helelatp == 0) { printf("Error getting an histogram from the file!\n"); return; } TH1F *hmuolatp = (TH1F *)p->Get("hmuolat"); if (hmuolatp == 0) { printf("Error getting an histogram from the file!\n"); return; } TH1F *hhadlatp = (TH1F *)p->Get("hhadlat"); if (hhadlatp == 0) { printf("Error getting an histogram from the file!\n"); return; } TH1F *hsumg = new TH1F(); hsumg->Fill(hgamlatg); hsumg->Fill(helelatg); hsumg->Fill(hmuolatg); hsumg->Fill(hhadlatg); TH1F *hsump = new TH1F(); hsump->Fill(hgamlatp); hsump->Fill(helelatp); hsump->Fill(hmuolatp); hsump->Fill(hhadlatp); TCanvas *c2 = new TCanvas("c2","hists with different scales",1280,1024); float offx=1.2; float offy=1.; float marg=0.15; c2->SetLogx(); c2->SetLogy(); gPad->SetRightMargin(marg); hsump->SetLineColor(kGreen+3); hsump->SetName("EAS ind. da p"); hsump->Draw(); c2->Update(); hsumg->SetTitle("Distribuzione laterale di #mu^{#pm} negli EAS indotti da #gamma e #font[12]{p} di energia 1 GeV- 1000 GeV"); hsumg->GetXaxis()->SetTitle("Distanza dal core (m)"); hsumg->GetYaxis()->SetTitle("Densita' (Particelle/m^{2})"); hsumg->GetXaxis()->SetTitle("Distanza dal core (m)"); hsumg->SetLineColor(kBlue); hsumg->GetXaxis()->SetTitleOffset(offx); hsumg->GetYaxis()->SetTitleOffset(offy); hsumg->SetName("EAS ind. da #gamma"); hsumg->Draw("sames"); c2->Update(); TLegend* leg = new TLegend(0.75, 0.7, .55, .8); leg->SetNColumns(1); leg->AddEntry(hsumg, "EAS indotti da #gamma", "lp"); leg->AddEntry(hsump, "EAS indotti da #font[12]{p}", "lp"); leg->Draw("same"); TPaveStats *stats1 = (TPaveStats*)hsumg->GetListOfFunctions()->FindObject("stats"); TPaveStats *stats2 = (TPaveStats*)hsump->GetListOfFunctions()->FindObject("stats"); stats1->SetTextColor(kBlue); stats2->SetTextColor(kGreen+3); stats1->SetX1NDC(0.80); stats1->SetX2NDC(0.98); stats1->SetY1NDC(0.93); stats1->SetY2NDC(0.83); stats2->SetX1NDC(0.80); stats2->SetX2NDC(0.98); stats2->SetY1NDC(0.82); stats2->SetY2NDC(0.72); c2->Update(); gROOT->SetBatch(); c2->Print("D:/mu_distr_lat.png"); delete c2; gROOT->SetBatch(); }