# A basic question

I created a 1-D histogram TH1F *AxialTotalScatter = new TH1F(“AxialTotalScatter”,“Axial Total Scatter”,50,-200.,+200.); After looping scattering list, I filled a position into the histogram: AxialTotalScatter->Fill(Source1); Then plot it: AxialTotalScatter->Draw(); I can see the distribution of scatter events as a function of position. How can I obtain the number of scatter events (for instance, in the histogram, the number of scatter events is 3400 at position 5) happening at a specific position?

Can someone explain the relationship between the bin number 50 and the number of the scatter events? thanks in advance.

Hi,

serious question: isn’t that in the users guide?

When creating the histogram you tell it that the x-axis shall be divided into 50 equal bins between -200 and +200. Each bin is thus 400/50=8 wide. Bin counting starts at 1, so bin number 1 is between -200…-192; bin number 50 is between 192…200. You can get the content of bin 50 by calling AxialTotalScatter->GetBinContent(50). You can also draw it and then read off the content in the “event status bar” that you can enable using the view option in the menu.

Cheers, Axel.

Thanks for your prompt reply. I checked the user’s manual before I posted it. I know that we can get the content of each bin.

The problem is that I forget the actual number of scatter events is the scatter events in the histogram divided by the bin size.

From my simulations, the total number of scatters are about 6000. According to the distribution of scatter events as a function of position, it turns out the sum over 50 bins is about 50000 (not precise). This means 50000/8~6000. That’s to say, to obtain the right number of scatter events as a function of position, the scatter events has to be divided by the bin size, right? (I used root 5 years ago, I forget almost everything.)

Thanks,

[quote=“Axel”]Hi,

serious question: isn’t that in the users guide?

When creating the histogram you tell it that the x-axis shall be divided into 50 equal bins between -200 and +200. Each bin is thus 400/50=8 wide. Bin counting starts at 1, so bin number 1 is between -200…-192; bin number 50 is between 192…200. You can get the content of bin 50 by calling AxialTotalScatter->GetBinContent(50). You can also draw it and then read off the content in the “event status bar” that you can enable using the view option in the menu.

Cheers, Axel.[/quote]

Hi,

the sum over all bins’ content is the sum of all weights of all Fill() operations. I.e. if you call h->Fill(pos) 4200 times, the sum of bin content will be 4200. If some “pos” are out of the histogram’s range you also have some content in the under- and overflow bins (bin numbers 0, nbins). The width is not taken into account for the bin content; it can be taken into account using h->Integral(“width”). See the class doc at root.cern.ch/root/html/TH1.

Cheers, Axel.