Getting x and x values from several different TH2 using loop to fill TH1 histograms

Hello All,

I have several TH2 histograms and I want to get values for x and y axis then use these values to plot new TH1.

I have tried:

 for (int isect=0; isect<NSECTORS;isect++)
  {

   name = "h_ntrig"; name += isect;
    h_ntrig[NSECTORS] =  new TH1F(name,name,1000,0,0.001);
    for(int iy = 0; iy<=h2_ntrig[isect]->GetNbinsX(); iy ++)
    {
      for(int iz = 0; iz<=h2_ntrig[isect]->GetNbinsY();iz++)
      {
        Double_t ntrig = h2_ntrig[isect]->GetBinContent(iz+1,iy+1);
        cout  << "NSECTORS = " <<"\t" << isect <<  "\t"  << "iy = "<<  "\t"
                << iy <<  "\t"  << "iz = " << "\t" << iz << endl;
            
      }

    }
}

Results is not correct because the same values print for each x and y of different sectors. Kindly help.
Thank you.

In your cout statement you print isect is it not ntrig you want to see ?

couet,

Oh yes thank you. That’s the information that I need per sector inorder to plot the TH1.

Thank you.