Open multiple .root files and create a plot

Hello,

I’m a ROOT beginner, and have a question which is maybe trivial.

I’m working with GRAS (Geant4 Radiation Analysis for Space) and I can have a ROOT file (.root) as output.

The thing is that I could open each file with TBrowser b, but I have 100 files for each energy of the simulation. Each file have 1 data that I want to store in a vector and later plot as function of the energies.

Could someone give me a north from where to start with ROOT to accomplish this?

Thank you very much.

Best Regards.
Leonardo

Hi Leonardo,

from what I understand, you would like during the execution of a compiled program to open several rootfiles (O(100)) and read from each of them an object: is that accurate?
If yes, I agree: TBrowser is not the right way to go.
Why not opening the files and reading objects with the TFile interface?

TFile myInputFile("myrootfile.root");
MyClass *obj;
myInputFile.GetObject("theNameOfYourObject",obj);
if(!obj){
// Handle error.....
}

More here: nbviewer.ipython.org/urls/root.c … file.ipynb

Cheers,
Danilo

Hello Danilo,

Thank you very for your help.

I’ll try this approach right now and come back when its done.

Cheers,
Leonardo.

Dear Danilo,

Thank you for your help.

This is my piece of code:

#include “Riostream.h”
#include <stdio.h>

void ValidationTotalDose(){

Char_t File [50];

for(Int_t i=0;i<=10;i++){
Int_t N;
N = sprintf(File,“TotalDose/GEANT4/TrappedElectrons/%dmm_trpe.root”,i);
TFile infile(File);
TH1D* A = NULL;
infile.GetObject(“doseTarget_total_dose_vs_primary_kine”,A);

Float_t TotalDose = A->GetSum();
Float_t RMS = A->GetRMS();
cout<<TotalDose<<"  "<<RMS<<endl;    

}

I worked flawlessly. :smiley:

Best Regards.
Leonardo