Getting bin content from a 2D histo and writing in ascii

Dear Rooters,
How to get the bin content from a 2D histogram and write in a file in ascii. I have attached the *.C file I am working on for you to understand. I am plotting a 2D scatter plot which is actually a coincident spectrum of 1st and 2nd hit of a multihit TDC. The plot comes out good as well as the gcut. Then I am also able to plot its X and Y projection in 1D and write it in a file in ascii. Now I am facing a problem. In the gcut I am plotting between 4200 to 5400 channels in X and 5900 to 7600 channels in Y. I have to plot a 1D histogram where the x-axis is the (Ychannel no. - Xchannel no.) of 2D plot , something like (t2-t1) and the Y is the bin content for the particular point in the 2D spectrum for which I am taking (t2-t1). I am only a learner in C++, so may be its a matter of few lines of programming that can get me through. Kindly help.

Thanks in advance,
Sankar De
add_histo_1.C (1.19 KB)

Apply the same logic to a 2-d case

for (i=binminx;i<=binmaxx;i++) { for (j=binminy;j<=binmaxy;j++) } fprintf (f11,"%g\n",h2->GetCellContent(i,j)); } } fclose (f11);