# ROOT Histogram Not Showing Data – Possible Issues?

**URL:** <https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237>\
**Category:** Newbie\
**Created:** [March 29, 2025, 12:17am UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237 "2025-03-29T00:17:41Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_ali/32/23290_2.png) [@Muhammad\_Ali](https://root-forum.cern.ch/u/Muhammad_Ali)\
**Post date:** [March 29, 2025, 12:17am UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/1 "2025-03-29T00:17:41Z")

</div>

Hi everyone,  
I am trying to plot energy deposited vs. transverse radius using ROOT, but I keep getting an empty histogram. I am new to ROOT and not very experienced in C++.  
My setup:

1. I have data on energy deposition in both the absorber and the gaps.

2. I calculate the transverse radius using the Pythagorean theorem:  
r=x2+y2  
radius\_hit = sqrt(pow(Gap\_X-\>at(nhit), 2) + pow(Gap\_Y-\>at(nhit), 2));

3. The applied energy is 2 GeV, and I expect to see how the deposited energy varies with transverse radius.

Problem:

```
My histogram is empty despite filling it in the code.

I suspect there might be an issue with how I am filling the histogram or how ROOT handles my data.

```

I am attaching the code. Kindly, help me in sorting out the code. Thanks !  
[GeV2\_NEG\_PION.C](https://root-forum.cern.ch/uploads/short-url/1kp9pijW9Wllf2Zyyvl8xzphsWO.C) (3.6 KB)

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [March 29, 2025, 6:03am UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/2 "2025-03-29T06:03:31Z")

</div>

You are not providing a stand-alone macro that shows the issue, so it’s hard to tell without knowing what happens in the rest of your code, but you can try printing out some messages and see if the code is even reaching the `Fill` or `SetBinContent` line. For instance, you have

```auto
    for (Long64_t jentry = 0; jentry < nentries; jentry++) {
      if (jentry >= 10) break;

```

so that could be leaving out many entries, and so on (check all your loops and if conditions and see if there is data surviving those)…  
One quick check, if you are getting a plot (you actually see the histo in a canvas, although without entries), is adding `gStyle->SetOptStat(111111);` before drawing, and check if the entries are in the under and/or overflow bins (meaning you are indeed filling, but the histogram lower/upper limits --in x-- are not wide enough for the data, or the bin numbers you have in `SetBinContent` are wrong).

---

<div class="post-metadata">

**Author:** ![Muhammad\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_ali/32/23290_2.png) [@Muhammad\_Ali](https://root-forum.cern.ch/u/Muhammad_Ali)\
**Post date:** [March 29, 2025, 12:26pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/3 "2025-03-29T12:26:24Z")

</div>

I tried changing the `jentry` iteration condition to `if (jentry > 100)` and adjusting the histogram’s lower and upper limits in the x-axis, but it is still empty. I also included `gStyle->SetOptStat(111111);`, and I can see that the histogram remains empty. I am attaching the PDF for reference.  
[unnamed (2).pdf](https://root-forum.cern.ch/uploads/short-url/d6LSXegbf5EgtR4PPGqIC2HTsBg.pdf) (13.4 KB)  
Maybe if you can help me in filling the histogram and loop adjusting?

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [March 29, 2025, 12:31pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/4 "2025-03-29T12:31:57Z")

</div>

As I wrote, add printouts at the appropriate points to check that things are going on as you expect. For example, print `nentries` as soon as you assign it a value and see if it’s correct, and so on at other points and variables; another example: just before or after `SetBinContent`, print out the bin number and the value you are trying to add to the histo and see what you have; etc.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_ali/32/23290_2.png) [@Muhammad\_Ali](https://root-forum.cern.ch/u/Muhammad_Ali)\
**Post date:** [March 29, 2025, 2:09pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/5 "2025-03-29T14:09:53Z")

</div>

Hi, I checked and I see the problem lies in  
if (radius\_hit \> radius[i] && radius\_hit \< radius[i + 1]) {  
Eabs\_r[i] += EAbs-\>at(nhit);}. It is not storing the nhits. I introduced vector std::vector\<std::vector\<size\_t\>\> nhit\_store(n\_radius); To store nhit indices

nhit\_store[i].push\_back(nhit). But still it is empty.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [March 29, 2025, 7:54pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/6 "2025-03-29T19:54:16Z")

</div>

It will be faster if you could upload all the files one would need to run your macro **and** explain how to run it. I will be able to take a look at this then.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_ali/32/23290_2.png) [@Muhammad\_Ali](https://root-forum.cern.ch/u/Muhammad_Ali)\
**Post date:** [March 29, 2025, 10:42pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/7 "2025-03-29T22:42:22Z")

</div>

Hi Yus,  
[GeV2\_NEG\_PION.C](https://root-forum.cern.ch/uploads/short-url/5iEL3MXyCplSBfeZwEIKtjLY5rv.C) (5.2 KB)  
[GeV2\_NEG\_PION.h](https://root-forum.cern.ch/uploads/short-url/ztzjpMqh7DxImi4lg5DQKyerSi3.h) (6.5 KB)  
I attached GeV2\_NEG\_PION.C , GeV2\_NEG\_PION.h. To run the macro. you need to follow the steps below:

1. root GeV2\_NEG\_PION.C
2. GeV2\_NEG\_PION t
3. t.Loop  
It will show the output. Thanks !!  
[GeV2\_NEG\_PION.root - Google Drive](https://drive.google.com/file/d/129ItAr134r6Z5WoezLNzCsHIxAI5kCEY/view?usp=sharing). GeV2\_NEG\_PION.root contains the root file which is the source file. I will be looking for the response.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [March 30, 2025, 12:48pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/8 "2025-03-30T12:48:00Z")

</div>

Hi Muhammad,

first, I guess the  
`t.Loop`  
in your instructions should have been  
`t.Loop()`

Second, your histogram is not exactly empty. Each bin is being filled with a zero.

Third, and most importantly, is the reason why each bin is filled with a zero. You have

```auto
std::vector<double> radius(n_radius, 0.0);
for (int i = 0; i < n_radius; i++) 
{
        radius[i] = i*10;
        ...
        if (radius_hit > radius[i] && radius_hit < radius[i + 1])
        {
             ... // things where you calculate what to fill the histogram with
        }
        ...
}

```

How is the code supposed to figure out `radius[i+1]` while you are at `i` in your loop?

---

<div class="post-metadata">

**Author:** ![Muhammad\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_ali/32/23290_2.png) [@Muhammad\_Ali](https://root-forum.cern.ch/u/Muhammad_Ali)\
**Post date:** [March 31, 2025, 8:43pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/9 "2025-03-31T20:43:35Z")

</div>

Hi Yus,  
Please, have a look at the code i modified. is that what you are suggesting. Attached is t  
[GeV2\_NEG\_PION \_modified.C](https://root-forum.cern.ch/uploads/short-url/WyrJ6NGMZvWFe1tsdApy54bva5.C) (3.8 KB)  
he code.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [March 31, 2025, 9:42pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/10 "2025-03-31T21:42:59Z")

</div>

Hi,

no, that’s not what I’m suggesting. You still have

```auto
std::vector<double> radius(n_radius + 1, 0.0);
...
for (int i = 0; i <= n_radius; i++) { // Note: loop goes up to <= n_radius
    radius[i] = i * 10;
    ...
    for (...) {
        ...
        for (...) {
            ...
            if (...) {
                ...
                for (...) {
                    ...
                    for (...) {
                        ...
                        if (radius_hit > radius[i] && radius_hit < radius[i + 1]) {
                            ...
                        }
                    }
                }
            }
        }
    }
}

```

For `i=0`, `raduis[i]=0*10=0` and `radius[i+1]=0` (because it is 0 by default  
and you do not assign it any other value by this iteration).  
For `i=1`, `raduis[i]=1*10=10` and `radius[i+1]=0`.  
For `i=2`, `raduis[i]=2*10=20` and `radius[i+1]=0`.  
and so on

And you require that `radius_hit < radius[i + 1]` where `radius_hit = sqrt(...)`, so it’s obviously a positive number. How can something positive be ever `< 0`?

---

<div class="post-metadata">

**Author:** ![Muhammad\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_ali/32/23290_2.png) [@Muhammad\_Ali](https://root-forum.cern.ch/u/Muhammad_Ali)\
**Post date:** [April 1, 2025, 3:13pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/11 "2025-04-01T15:13:47Z")

</div>

Hi Yus,  
Thanks for being so patient with me. I changed the if condition of radius hit:  
radius\_hit = if (radius\_hit \< radius[i-1] && radius\_hit \> radius[i]).  
Secondly, I am getting very high number Y-scale such that 10^6. I am expecting it within range  
(0-1). Kindly, can you have a look at the attached code as I trying to modify SetBinContent.  
[GeV5\_NEG\_PION.C](https://root-forum.cern.ch/uploads/short-url/edJva7OaGviDMmtHizPgAV7sC8v.C) (3.7 KB). Thank you so much !!!

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [April 1, 2025, 5:56pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/12 "2025-04-01T17:56:08Z")

</div>

Hi Muhammad,

not sure why you would expect energies from 0 to 1. First, it’s unphysical (why only from 0 to 1 GeV?). Second, you fill your `Edep` histogram with `totalEnergy[i]` values

```auto
Edep->SetBinContent(i , totalEnergy[i]);

```

, where the `totalEnergy[i]` values are calculated in a loop:

```auto
for (int i = 0; i < n_radius; i++) {
    double energy = (Eabs_r[i] + Egap_r[i]) / 2.0 * 1000.0;
    totalEnergy[i] += energy;
}

```

I checked that these `Eabs_r[i]` values can be as large as 300. So the `energy` value is at least 1.5e5. And you sum it up with the existing `totalEnergy[i]`. No wonder you get things like 12 PeV (petaelectronvolts)! 🤪

---

<div class="post-metadata">

**Author:** ![Muhammad\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_ali/32/23290_2.png) [@Muhammad\_Ali](https://root-forum.cern.ch/u/Muhammad_Ali)\
**Post date:** [April 2, 2025, 1:16pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/13 "2025-04-02T13:16:22Z")

</div>

Provided energy is just 2 GeV so it not possible to get deposited energy in that high scale. so i am confused in looping the code. it should be around (0-1) GeV.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [April 2, 2025, 5:48pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/14 "2025-04-02T17:48:31Z")

</div>

What is the dimension of `Egap` and `EAbs` from the `.root` file? Is it GeV?

Also please note that you have multiple loops and an addition assignment (`Eabs_r[i] += EAbs->at(nhit);`) inside the innermost loop. Do you have a rough estimate on how many times this line gets executed?

Finally, you multiply every energy value by 500 with

```auto
double energy = (Eabs_r[i] + Egap_r[i]) / 2.0 * 1000.0;

```

– are you sure this is correct?

---

<div class="post-metadata">

**Author:** ![Muhammad\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_ali/32/23290_2.png) [@Muhammad\_Ali](https://root-forum.cern.ch/u/Muhammad_Ali)\
**Post date:** [April 3, 2025, 7:39am UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/15 "2025-04-03T07:39:37Z")

</div>

1. Yes it is in GeV. ( 2 GeV ). It is geant4 based activity for 50,000 events.
2. No, i am expecting the output without any multiplication with 500.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [April 3, 2025, 10:19am UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/16 "2025-04-03T10:19:05Z")

</div>

If you don’t need the multiplication by 500 then please drop it from the code and upload a new version.

Also please note that your loop over `TTree` entries happens inside another loop over `i`, which runs from `0` to `80`. Are you sure you need that (usually you don’t)?

---

<div class="post-metadata">

**Author:** ![Muhammad\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/muhammad_ali/32/23290_2.png) [@Muhammad\_Ali](https://root-forum.cern.ch/u/Muhammad_Ali)\
**Post date:** [April 3, 2025, 12:22pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/17 "2025-04-03T12:22:43Z")

</div>

Hi yus, Sorry I just checked and observed i will need the multplication of 500 to normalize. And I am attaching my code. I made a modification and trying to store the data in double energy. Also I am attaching another code which i am trying to copy. Confinement  
[Containment.C](https://root-forum.cern.ch/uploads/short-url/rV4yWKH2t01bArxy9x91JRSnC4I.C) (4.1 KB)  
[GeV2\_NEG\_PION\_mod.C](https://root-forum.cern.ch/uploads/short-url/aLP4YF7V9iuqAbYin6PjlNVjHRp.C) (3.7 KB)  
.C

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [April 3, 2025, 2:17pm UTC](https://root-forum.cern.ch/t/root-histogram-not-showing-data-possible-issues/63237/18 "2025-04-03T14:17:55Z")

</div>

Hi Muhammad,

if your `GeV2_NEG_PION_mod.C` is supposed to be similar to the `Containment.C`, please note that they do not have the outermost loop `for (int i = 0; i < n_radius; i++) {...}`. Also, you have up to 5 nested `for` loops in your code, while they have up to 3.

Anyway, I believe you will have better luck asking your colleagues and/or your supervisor about this as this is not a technical issue but merely a question on how to analyze your data.
