Binning of a 2D histogram

hi,
I want to bin a 2D histogram so that it will look like the plot attached below. Bet when I run my macro it will not plot any thing. Also it is taking a long time in processing. I do not know what i am doing wrong.
I am attaching my macro below.

 #include "TLegend.h"
 #include "TCanvas.h"
 #include "TROOT.h"
 #include "TAxis.h"
 #include <vector>
 #include <iostream>
 #include <sstream>
 #include <iomanip>
 #include <math.h>
 #include "TH2F.h"

void pt_eta_selmu()

 {

   TFile *f = new TFile("May26_2.root");

  if(!f) {
    std::cout<<"FILE CAN'T BE OPENED"<<std::endl;
   }

   TTree *t2 = (TTree*)f->Get("demo/AnaTree");

   TH2F *h1 = new TH2F("h1","hist_SelMu",100,0,300,100,-3,3);
   
     t2->Draw("SelMu_eta:SelMu_pt >> h1","","TextE COL Z");
//   h1->GetXaxis()->SetTitle("SelMu_pt");
//   h1->GetYaxis()->SetTitle("SelMu_eta");
      

  for (int i=0;i<=h1->GetXaxis()->GetNbins();i++)

         {

            for (int j=0;j<=h1->GetYaxis()->GetNbins();j++)

         {

     double Num  = h1->GetBinContent(i,j);

         }

        }

  // h1->GetXaxis()->SetTitle("SelMu_pt");
  // h1->GetYaxis()->SetTitle("SelMu_eta");

//   t2->Draw("SelMu_eta:SelMu_pt >> h1","","TextE COL Z");
h1->Draw("TextE COL Z");
         cout<< "--------------- Entries of Neumerator   -------------------- " <<endl;
int NXx =  h1->GetXaxis()->GetNbins();
int NYy =  h1->GetYaxis()->GetNbins();
 cout<< "Nx " <<NXx<<endl;
 cout<< "Ny " <<NYy<<endl;
 for (int i=1;i<=NXx;i++) {
   for (int j=1;j<=NYy;j++) {

}
   cout<< " " <<endl;
}

h1->SetXTitle(" Pt_{T} [GeV/c] ");
h1->SetYTitle(" #eta ");
//h1-> SetTitleSize(0.05, "Y");
//h1-> SetTitleSize(0.05, "X");


}

Cheers,
Nab

{ double bins_x[] = {10, 20, 40, 70, 100}; double bins_y[] = {0, 1, 1.5, 2.5}; TH2D *h = new TH2D("all tight", "tight_ttbar_Z;Pt_{T}^{} [GeV/c];#eta", (sizeof(bins_x) / sizeof(bins_x[0]) - 1), bins_x, (sizeof(bins_y) / sizeof(bins_y[0]) - 1), bins_y); for (int i = 1; i <= h->GetNbinsX(); i++) for (int j = 1; j <= h->GetNbinsY(); j++) h->SetBinContent(i, j, (i * i + j * j * j)); h->Draw("colz text e"); }

Thanks While_E_Coyote…

hi Coyote,

I used your suggested method to bin a 2D histogram, but I am getting the same plot for all three cases.
Kindly see it

fakeratio_tqz1.cc (2.3 KB)

fakeratio_tqz1.cc (1.5 KB)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.