#include "vector" #include "time.h" #include "stdio.h" #include "stdlib.h" void xy_proj() { TCanvas *c=new TCanvas("c","c",900,900); //FILE *fid=fopen("/Users/stefanodilorenzo/Documents/Root macros/gauss_file.txt", "r"); TH2D *hist2D = new TH2D("","",200,-5,5,200,-5,5); //initialization of random generator TRandom3 r; char s[200]; double x,y; //fill of th2 histogram for (int k=0; k<50000; k++) hist2D->Fill(r.Gaus(0,1),r.Gaus(0,1)); //creation on projection histograms TH1D *hist2D_px=hist2D->ProjectionX("Hist2_px",0,-1,"oe"); TH1D *hist2D_py=hist2D->ProjectionY("Hist2_py",0,-1,"oe"); //Setting drwa option projY hist2D_py->SetFillColor(kBlue); hist2D_py->SetLineColor(kBlack); hist2D_py->GetXaxis()->SetLabelSize(0.07); hist2D_py->GetYaxis()->SetLabelSize(0.07); hist2D_py->GetXaxis()->SetTitle("label y/LABEL Y"); hist2D_py->GetXaxis()->SetTitleSize(0.09); hist2D_py->GetXaxis()->SetTitleOffset(0.67); //Setting drwa option projX hist2D_px->SetFillColor(kBlue); hist2D_px->SetLineColor(kBlack); hist2D_px->GetXaxis()->SetLabelSize(0.07); hist2D_px->GetYaxis()->SetLabelSize(0.07); hist2D_px->GetXaxis()->SetTitle("label x/LABEL X"); hist2D_px->GetXaxis()->SetTitleSize(0.09); hist2D_px->GetXaxis()->SetTitleOffset(0.67); //Setting opzioni TH2D hist2D->GetXaxis()->SetLabelSize(0); hist2D->GetYaxis()->SetLabelSize(0); c->Divide(2,2,0.001,0.001); //set pad dimension c->cd(1)->SetPad(0.00,0.25,0.25,1); c->cd(2)->SetPad(0.25,0.25,1,1); c->cd(3)->SetPad(0.00,0.00,0.25,0.25); c->cd(4)->SetPad(0.25,0.00,1,0.25); //set pad margins /* Pad organized in this way _____________ | | | | 1 | 2 | |___|_______| | 3 | 4 | ------------- */ c->cd(2)->SetMargin(0.,0.1,0.0,0.05); c->cd(1)->SetMargin(0.15,0.,0.,0.05); c->cd(4)->SetMargin(0.,0.1,0.15,0.0); c->cd(3)->SetMargin(0.5,0.05,0.05,0.05); //TPaveText creation TPaveText *tp=new TPaveText(0.2,0.2,0.9,0.88 ,"NDC"); tp->SetShadowColor(kWhite); tp->AddText("Title line #1"); tp->AddText("Title line #2"); tp->AddText("Title line #3"); //Drawing on pad4 c->cd(4)->SetGrid(); hist2D_px->Draw("BAR HIST Y+"); //Drawing on pad2 c->cd(2)->SetGrid(); gStyle->SetOptStat("mr"); hist2D->Draw("colz"); //Drawing on pad1 c->cd(1)->SetGrid(); //hbar draw the histograms in horizontal hist2D_py->Draw("HBAR X+"); //Drawing on pad3 c->cd(3); TLine *line=new TLine(0.15,1,1.1,1); tp->Draw(); line->Draw("same"); }