Problems with TH2D plotting

Hello everyone!!
I need some help with TH2D plotting.

I have a TH2D histogram constructed from 2 branches (X and Y) of a TTree. What I want to do now is create a new TH2D but using the mean of Y in intervals of X. So, I want a new TH2D but now with the mean of Y vs X .Can I do it? If yes, how?

I tried to do this using the ProjectionY and calculate the mean but this is not working very well =/

this is what I tried to do

  TH2D *h2d_topo = new TH2D("h2d_topo","", 100,0,10, 1000,0,1000); 

  for(Long_t i=0; i<t3->GetEntries(); i++){
    t3->GetEntry(i);
    h2d_topo->Fill(XiPtTopo, fabs(DCATopo));
    }

  vector<TH1D *> hTopo(100);
  vector<Double_t> mean_topo(100);

  for(Int_t ii = 0; ii<100; ii++){
    hTopo[ii] = h2d_topo->ProjectionY(Form("h_%d",ii), ii, ii+1);
    mean_topo[ii] = hTopo[ii]->GetMean();
   // cout<<"media ii = " << mean_topo[ii] << endl;
  }

  TH2D *htest = new TH2D("htest", "", 100,0,10, 10, 0, 1000);

  for(Int_t ii = 0; ii<100; ii++){
    for(Long_t i=0; i<t3->GetEntries(); i++){
        htest->Fill(XiPtTopo, mean_topo[ii]);
    }  

Can someone help me?? I would be very grateful!!
Thank you!

How about: TProfile

This solves my problem! Thank you very much!!!