Bin content is zero but plot is non zero

Hi,

I’ve generated a class in ROOT. I fill my histogram then loop of the number of bins and get the contents of each bin, when I print the bin contents to the screen it is zero for each bin but when I draw the plot I find that this isn’t the case. My code is:

for (Long64_t jentry=0; jentry<nentries;jentry++) { // this line is generated by root



sim_hwStripPhi->Fill(hwStrip);
double nbins = sim_hwStripPhi->GetXaxis()->GetNbins();
for(int j=0; j<nbins; ++j){
double binContent = sim_hwStripPhi->GetBinContent(j);
std::cout << binContent << std::endl;
}

Any ideas as to what is causing this?

Many thanks,

Lisa

After further investigation I’ve found that it loops over my data x many times because its in the Loop() function generated by ROOT. The last time it loops over it the bin contents printed out is the same as the contents of the histogram. I would like to set the histogram bins with zero entries to a random number but the code changes the contents of every bin. How do I get it to only take into account the final iteration of this loop?

[quote] How do I get it to only take into account the final iteration of this loop?[/quote]What about moving your code (which loops of the bins of the histograms) after the end of the loop over the entries of the tree?

Philippe