# Content per bins do not fit with the Histogram

**URL:** <https://root-forum.cern.ch/t/content-per-bins-do-not-fit-with-the-histogram/59234>\
**Category:** Newbie\
**Created:** [May 6, 2024, 12:12pm UTC](https://root-forum.cern.ch/t/content-per-bins-do-not-fit-with-the-histogram/59234 "2024-05-06T12:12:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 6, 2024, 12:12pm UTC](https://root-forum.cern.ch/t/content-per-bins-do-not-fit-with-the-histogram/59234/1 "2024-05-06T12:12:01Z")

</div>

Can someone pleas explain me why the value of my content per bins dosn’t fit with my histogram ?

```auto
TFile f{"RAW148OS_treeFF01.root"};
std::unique_ptr<TTree> tv__tree{static_cast<TTree*>(f.Get("Analysis_All"))};
tv__tree->Draw("Psd_All_Shift>>h1(7500,500,8000)","","colz");

TH1 *h1 = dynamic_cast<TH1*>(gPad->GetPrimitive("h1")); // Obtention de l'histogramme h1

// Vérifiez si l’histogramme existe
if (h1) { // Utilisation de h1 pour vérifier si l'histogramme existe
    // Accédez aux données de l’histogramme
    int nbins = h1->GetNbinsX();
    for (int i = 1; i <= nbins; ++i) {
        double binContent = h1->GetBinContent(i);
        // Faites quelque chose avec le contenu du bin, par exemple, l’afficher
        std::cout << "Contenu du bin " << i << " : " << binContent << std::endl;
    }
} else {
    std::cout << "L’histogramme n’a pas été trouvé." << std::endl;
}

```

---

<div class="post-metadata">

**Author:** ![Dilicus](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dilicus/32/14338_2.png) [@Dilicus](https://root-forum.cern.ch/u/Dilicus)\
**Post date:** [May 6, 2024, 1:03pm UTC](https://root-forum.cern.ch/t/content-per-bins-do-not-fit-with-the-histogram/59234/2 "2024-05-06T13:03:20Z")

</div>

Hi @KillianUB,  
could you provide the root file you are using, it is difficult to say something without data.

From waht I can see the code seems correct overall, the only thing I will modify is the decalration of the histogram from a generic TH1 to TH1D or TH1F

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 6, 2024, 1:12pm UTC](https://root-forum.cern.ch/t/content-per-bins-do-not-fit-with-the-histogram/59234/3 "2024-05-06T13:12:29Z")

</div>

The DATA is unfortunatly to heavy to be provided even with dropbox or wetransfer. But i can show you that ;

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/b/b/bba52f611ee0a344b2262d9307ade69a672c4489.png)

As you can see, it dosnt makes sense at all. Even worst , if I change from all detector to only one detector the resultat stay the same what ever i change.

---

<div class="post-metadata">

**Author:** ![Dilicus](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dilicus/32/14338_2.png) [@Dilicus](https://root-forum.cern.ch/u/Dilicus)\
**Post date:** [May 6, 2024, 1:47pm UTC](https://root-forum.cern.ch/t/content-per-bins-do-not-fit-with-the-histogram/59234/4 "2024-05-06T13:47:38Z")

</div>

I just noticed that you used `colz` option that is meant for TH2 histograms, I do not know if this can cause prblems.

In any case I suggest you to change `dynamic_cast<TH1*>(gPad->GetPrimitive("h1"))` to  
`(TH1F*)gPad->GetPrimitive("h1")` that is the method described in the [Tree::Draw()](https://root.cern.ch/doc/master/classTTree.html#a73450649dc6e54b5b94516c468523e45) method on the ROOT page.

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 6, 2024, 1:59pm UTC](https://root-forum.cern.ch/t/content-per-bins-do-not-fit-with-the-histogram/59234/5 "2024-05-06T13:59:24Z")

</div>

Problem has been solved. There has a shift of 500 bins wish is why the content per bins dosnt fitted with histogram. I just changed

`tv__tree->Draw("Psd_All_Shift>>h1(8000,0,8000)","","colz");`

and then it worked.

Thx for your help !

---

<div class="post-metadata">

**Author:** ![FoxWise](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxwise/32/37588_2.png) [@FoxWise](https://root-forum.cern.ch/u/FoxWise)\
**Post date:** [May 6, 2024, 2:01pm UTC](https://root-forum.cern.ch/t/content-per-bins-do-not-fit-with-the-histogram/59234/6 "2024-05-06T14:01:29Z")

</div>

You can crop the TTree with `RDataFrame` and share a small reproducible.

```auto
ROOT::RDataFrame df("Analysis_All", "RAW148OS_treeFF01.root").Range(100).Snapshot(""Analysis_All", "RAW148OS_treeFF01_cropped.root"")

```
