Filling 2D histogram with TCutG condition

Dear Rooters,
I want to fill a new 2D histogram by choosing a specific area of an already drawn 2D spectrum. I defined the area by a polygon using a mouse and saved the values as a graphical cut. Using TCutG, I can draw the new histogram with “thresh_cut->Draw(“colz,[cut31_1]”);”. Now I want to write (x,y,bincontent) values in an ASCII file. But when I am looping over the NbinsX and NbinsY of thresh_cut, it is scanning over the whole region and writing it in the file. I want to write only the (x,y,bincontent) values within the cut31_1 area with applying some threshold conditions.

TCutG *cutg = new TCutG(“cut31_1”,5);

Please give me some idea on how to do so.

thresh_cut->Draw(“colz,[cut31_1]”); just draws the specific area. I want the bincontent of only that area.

Thanks in advance.

When you loop on the bins of your 2-d histogram, you can do
something like:

for (i=1;i<nbinsx>GetXaxis()->GetBinCenter(i);
   for (j=1;j<nbinsy>GetYaxis()->GetBinCenter(j);
      if (!cutg->IsInside(x,y) continue;
      cout <<x<<y<...