Changing number of bins change the y-axis

Hello root users.

I am an engineer new to using root. I am using root for analyzing geant4 simulation data. What I’m doing is I extract data using geant4 then use root to draw the data into a graph.

My question is that when I change the number of bins the y-axis changes dramatically. Maybe I am understanding the concept of bins wrong but I am under the impressions that high number of bins equal to higher number of coordinates (x,y spot). So for example if I do 50 bins, it will draw only 50 points, with presumably higher y-axis value since it has higher number of things in it then if spread out if 100 bins.

However, as one can see from my attached file [1;1 total energy deposit], it works in the opposite way. When I increase the bin number it increases the y-axis value and vice versa.

What I want to do is since I am simulating 5000 particles, I want 5000 points. You can see from the box on the top right that entries is 5000 and average is 0.2726 which amounts to roughly 1361 but the graph doesn’t reflect that.

I hope I made sense and thank you in advance for the help!
bin1000.root (35 KB)
bin100.root (34.2 KB)

You need to see the part of the code which fills your histograms (I guess it uses “weights”, or maybe the histogram is “scaled” using bin “width”, afterwards).
BTW. You should name your histograms starting with a letter, so “h1”, “h2”,… (not “1”, “2”, …).

[quote=“Pepe Le Pew”]You need to see the part of the code which fills your histograms (I guess it uses “weights”, or maybe the histogram is “scaled” using bin “width”, afterwards).
BTW. You should name your histograms starting with a letter, so “h1”, “h2”,… (not “1”, “2”, …).[/quote]

Thanks for your reply. I am using a modified version of an example build provided by geant4 so I am not completely sure how the root is used here. I attached the histomanager.cc c++ file used in the simulation build. Let me know if this helps at all or if you need other information.
HistoManager.cc (4.42 KB)

This file does not contain any source code which fills these histograms, but I guess you can correct their names here: const G4String id[] = {"h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "h9", "h10", "h11", "h12", "h13"};

[quote=“Pepe Le Pew”]This file does not contain any source code which fills these histograms, but I guess you can correct their names here: const G4String id[] = {"h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "h9", "h10", "h11", "h12", "h13"};[/quote]

I’ve been looking at the simulation code to find the source code for these histograms. I found this where it normalizes the histograms. Could this be the reason? I am pretty new to computer coding and having problem finding the issue.

//normalize histograms
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
for (G4int ih=1; ih<14; ih++) {
G4double binWidth = analysisManager->GetH1Width(ih);
G4double unit = analysisManager->GetH1Unit(ih);
G4double fac = unit/binWidth;
///G4double fac = unit/(numberOfEventbinWidth);
if (ih == 2) fac = (1./(numberOfEvent
binWidth))*(mm/MeV);
analysisManager->ScaleH1(ih,fac);

Yep, this code looks reasonable.