// Example displaying a 2D histogram with its two projections. { TCanvas *c1 = new TCanvas("c1", "c1",900,900); gStyle->SetOptStat(0); // Create the three pads TPad *center_pad = new TPad("center_pad", "center_pad",0.0,0.0,0.6,0.6); center_pad->Draw(); right_pad = new TPad("right_pad", "right_pad",0.55,0.0,1.0,0.6); right_pad->Draw(); top_pad = new TPad("top_pad", "top_pad",0.0,0.55,0.6,1.0); top_pad->Draw(); // Create, fill and project a 2D histogram. TH2F *h2 = new TH2F("h2","",100, 0, 3.5, 100, 0, 3.5); h2->GetXaxis()->SetTitle("M^{2}_{K^{-}#pi^{+}} [GeV^{2}/c^{4}]"); h2->GetYaxis()->SetTitle("M^{2}_{K^{-}#pi^{0}} [GeV^{2}/c^{4}]"); h2->GetXaxis()->SetTitleSize(0.04); h2->GetYaxis()->SetTitleSize(0.04); h2->SetMarkerStyle(7); h2->GetXaxis()->CenterTitle(); h2->GetYaxis()->CenterTitle(); TH1D *h3 = new TH1D("h3","",100, 0, 3.5); TFile *f = new TFile("total_ntuple_allisSignal.root"); TTree *tree = (TTree*)f->Get("tree"); Double_t deltaM, M2_Kpi, M2_Kpi0; tree->SetBranchAddress("deltaM",&deltaM); tree->SetBranchAddress("M2_Kpi",&M2_Kpi); tree->SetBranchAddress("M2_Kpi0",&M2_Kpi0); Int_t nentries = (Int_t)tree->GetEntries(); for (Int_t i=0; iGetEntry(i); { h2->Fill(M2_Kpi, M2_Kpi0); } } TH1D * projh2X = h2->ProjectionX(); TH1D * projh2Y = h2->ProjectionY(); // Drawing center_pad->cd(); gStyle->SetPalette(1); // h2->Draw("TEXT"); h2->Draw("CONTZ"); // projection of x and y top_pad->cd(); projh2X->SetFillColor(kBlue+2); // projh2X->SetMarkerStyle(20); // projh2X->Draw("bar"); projh2X->Draw("bar"); right_pad->cd(); projh2Y->SetFillColor(kBlue+2); // projh2Y->SetMarkerStyle(20); // projh2Y->Draw("hbar"); projh2Y->Draw("hbar"); c1->cd(); TLatex *t = new TLatex(); t->SetTextFont(42); t->SetTextSize(0.02); }