Get integral of the histogram from TDirectory


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!


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

$ 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())
1 Like

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