// Example displaying a 2D histogram with its two projections. { TCanvas *c1 = new TCanvas("c1", "c1",900,900); gStyle->SetOptStat(0); // Create, fill and project a 2D histogram. TH1D *h1 = new TH1D("h1","",100, 0, 10); 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 *f1 = new TFile("script_read_RS_mc14ri_1ab_light-2112-uranus_with_MD0_cut.root"); TTree *tree1 = (TTree*)f1->Get("DstD0PiKPiPi0RS_withcut"); Double_t deltaM; tree1->SetBranchAddress("deltaM",&deltaM); TFile *f2 = new TFile("output.root"); TTree *tree2 = (TTree*)f2->Get("tree"); Double_t Weight; tree2->SetBranchAddress("Weight",&Weight); Int_t nentries = (Int_t)tree1->GetEntries(); for (Int_t i=0; iGetEntry(i); { h1->Fill(deltaM,Weight); // cout<< "GetBinContent =" << h1->GetBinContent(i) << endl; } } h1->Draw("HIST"); }