# Get integral of the histogram from TDirectory

**URL:** <https://root-forum.cern.ch/t/get-integral-of-the-histogram-from-tdirectory/48206>\
**Category:** Newbie\
**Created:** [December 28, 2021, 12:06pm UTC](https://root-forum.cern.ch/t/get-integral-of-the-histogram-from-tdirectory/48206 "2021-12-28T12:06:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [December 28, 2021, 12:06pm UTC](https://root-forum.cern.ch/t/get-integral-of-the-histogram-from-tdirectory/48206/1 "2021-12-28T12:06:23Z")

</div>

Hello,

I have an ntuple which has 2 subdirectories (TDirectoryFile) and in those subdirectories there are TH1 histograms. I want to access the integral of those histograms. Is it somehow possible to do this from the terminal, without writing a separate piece of code and accessing each histogram individually from the script?

I tried `cd()` to the subdirectory and then `hist->GetIntegral()` but I get as an output `(Double_t *) 0x55a39f1dfb70`, which does not give me any information.

Thank you in advance for your help!

---

<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:** [December 28, 2021, 12:31pm UTC](https://root-forum.cern.ch/t/get-integral-of-the-histogram-from-tdirectory/48206/2 "2021-12-28T12:31:10Z")

</div>

Hi,

sure, you can access your histograms and then get their integrals:

```auto
$ root -l yourFile.root
root [0] TH1F* myFirstHisto = static_cast<TH1F*>(_file0->Get("myFirstSubdirectory/hist1")); printf("Integral is %f\n", myFirstHisto->Integral())
...
root [1] TH1F* mySecondHisto = static_cast<TH1F*>(_file0->Get("mySecondSubdirectory/hist2")); printf("Integral is %f\n", mySecondHisto->Integral())
...

```

---

<div class="post-metadata">

**Author:** ![beg1nner](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/d26b3c/32.png) [@beg1nner](https://root-forum.cern.ch/u/beg1nner)\
**Post date:** [December 28, 2021, 12:35pm UTC](https://root-forum.cern.ch/t/get-integral-of-the-histogram-from-tdirectory/48206/3 "2021-12-28T12:35:28Z")

</div>

Thanks! I also tried with `cd()` and then just `hist->Integral()` , which worked. Apparently problem was in `GetIntegral()`.
