Reading Data of a inner folder on .root File

Hi,

I’m trying to read data from an inner folder on a .root file.

I know how to read data from Trees, but never had a root file with inner folders, like the one I’m sending. The folder is called Spectrum1, and was created automatically by Geant4. I would like to be able to read the two histograms inside it and get the total dose by summing all the entries.

Thank a lot for the help.
AT32UC3CDMC_TrpE_GOMX3_RMC.root (457 KB)

TFile *f = TFile::Open("AT32UC3CDMC_TrpE_GOMX3_RMC.root"); if (f) { f->cd("Spectrum1") TH1D *dose = (TH1D *)f->Get("TID_AT32UC3CDMC_dose"); TH1D *total = (TH1D *)f->Get("TID_AT32UC3CDMC_total_dose_vs_primary_kine"); }

{ TFile *f = TFile::Open("AT32UC3CDMC_TrpE_GOMX3_RMC.root"); TH1D *h1, *h2; f->GetObject("Spectrum1/TID_AT32UC3CDMC_dose", h1); f->GetObject("Spectrum1/TID_AT32UC3CDMC_total_dose_vs_primary_kine", h2); h1->Print(); std::cout << h1->Integral() << std::endl; h2->Print(); std::cout << h2->Integral() << std::endl; }

Oh, thank you for both answers!! :smiley: