How to make LEGO plots using my own table data?

Hi,
I have a 2D data set which is saved as .txt file. The dimension is 17x24. When I use the following command lines to load the data and assign the data to the pointer hist like this

std::ifstream input_file("mytxt.txt"); // there are 17 x 24 values in the .txt file, the delimiter is " ". 
// one value in the file could be 100.5, or 200, or 12. 
TH2D *hist = new TH2D("hist", "2D Histogram from Text File", 17, 0, 17, 24, 0, 24);

the generated histogram is not correct. Since there would be 17x24 grids, for each grid, the height value would be assigned the specific value extracted from the .txt file.

How can I generate such a LEGO


plot. Since I am a newbie in ROOT, could you please give me more details.

Thank you very much.

Wei

_ROOT Version:_6.32
Platform: ubuntu
Compiler: g++

Use SetBinContent(binx,biny,value) to assign each data value from the file to each bin. E.g.

   for (Int_t i = 1; i <= nbinsx; i++) {
      for(Int_t j = 1; j <= nbinsy; j++){
         histo->SetBinContent(i, j, value_for_bin_i_j);
      }
   }

Notice that binx and biny are bin numbers, not the values seen on the x and y axis labels, and bin numbers in x and y go from 1 to NbinsX and NbinsY, respectively. So you somehow have to know or determine the corresponding bin number in order to send each data to its correct bin.
Note also, as the name implies, that SetBinContent overwites any existing bin contents on the bin; so if your data happens to contain several entries for one same bin (x,y), it will just be overwritten every time you use SetBinContent on that same bin.