Independent analysis of identical root trees

I am currently in need of some advice. I am using a root macro i wrote to analyse some data. It uses TChain to read in multiple data files, and run over all of them. a_1.root, a_2.root etc. It then produces the analysed output as a .root file.
To complicate matters, due to a technicality i have to run this 10 times, changing some details each time. The output is still in the identical format to each of the 10 .root files i now have.
Now what i need to do, is in a different macro, read in these 10 identical files to work on the data. But, they are all called the same, just in different directories. Along with the branches internally containing the same variables.
I need to be able to treat inside my macro each of these 10 identical .root files as separate objects. Linking them together as one would not be of use. As i need to use conditions on each of the separate items with variables from that specific run, then merge them at the end, after conditions in each sub-set have been met.
I hope i have explained this well enough. I realise this may be a simple thing to achieve, but i have not had any luck yet. I look forward to your help.

This is what i have started, please let me know if i am heading in the wrong direction! :slight_smile:

void tree_work() {

TFile *f_3 = new TFile("October_replay/3/3_all.root");
TTree *t_3 = (TTree*)f_3->Get("Prismsa Processed");
TFile *f_4 = new TFile("October_replay/4/4_all.root");
TTree *t_4 = (TTree*)f_4->Get("Prismsa Processed");
TFile *f_5 = new TFile("October_replay/5/5_all.root");
TTree *t_5 = (TTree*)f_5->Get("Prismsa Processed");
TFile *f_6 = new TFile("October_replay/6/6_all.root");
TTree *t_6 = (TTree*)f_6->Get("Prismsa Processed");
TFile *f_7 = new TFile("October_replay/7/7_all.root");
TTree *t_7 = (TTree*)f_7->Get("Prismsa Processed");

Float_t a_over_q_3;
Float_t a_over_q_4;
Float_t a_over_q_5;
Float_t a_over_q_6;
Float_t a_over_q_7;

Float_t E_correct_beam_3;
Float_t E_correct_beam_4;
Float_t E_correct_beam_5;
Float_t E_correct_beam_6;
Float_t E_correct_beam_7;

TBranch *b_a_over_q_3 = t_3->GetBranch("a_over_q_tree");
TBranch *b_a_over_q_4 = t_4->GetBranch("a_over_q_tree");
TBranch *b_a_over_q_5 = t_5->GetBranch("a_over_q_tree");
TBranch *b_a_over_q_6 = t_6->GetBranch("a_over_q_tree");
TBranch *b_a_over_q_7 = t_7->GetBranch("a_over_q_tree");

TBranch *b_E_correct_beam_3 = t_3->GetBranch("E_correct_beam");
TBranch *b_E_correct_beam_4 = t_4->GetBranch("E_correct_beam");
TBranch *b_E_correct_beam_5 = t_5->GetBranch("E_correct_beam");
TBranch *b_E_correct_beam_6 = t_6->GetBranch("E_correct_beam");
TBranch *b_E_correct_beam_7 = t_7->GetBranch("E_correct_beam");

b_a_over_q_3->SetAddress(&a_over_q_3);
b_a_over_q_3->SetAddress(&a_over_q_4);
b_a_over_q_3->SetAddress(&a_over_q_5);
b_a_over_q_3->SetAddress(&a_over_q_6);
b_a_over_q_3->SetAddress(&a_over_q_7);

b_E_correct_beam_3->SetAddress(&E_correct_beam_3);
b_E_correct_beam_4->SetAddress(&E_correct_beam_4);
b_E_correct_beam_5->SetAddress(&E_correct_beam_5);
b_E_correct_beam_6->SetAddress(&E_correct_beam_6);
b_E_correct_beam_7->SetAddress(&E_correct_beam_7);

Int_t nevent = (Int_t)t_5->GetEntries();

for (Int_t i=0; i<nevent; i++ )  {

b_E_correct_beam_3->GetEntry(i);
b_E_correct_beam_4->GetEntry(i);
b_E_correct_beam_5->GetEntry(i);
b_E_correct_beam_6->GetEntry(i);
b_E_correct_beam_7->GetEntry(i);

b_a_over_q_3->GetEntry(i);
b_a_over_q_4->GetEntry(i);
b_a_over_q_5->GetEntry(i);
b_a_over_q_6->GetEntry(i);
b_a_over_q_7->GetEntry(i);
// Test below, but in theory i can now do what i require.
cout << E_correct_beam_3 << endl;

}

}

I can then work in the “for” loop applying my conditions and cuts etc, then on to making a new root tree.

[quote]I need to be able to treat inside my macro each of these 10 identical .root files as separate objects. [/quote]Then you are on the right track (a slight improvement would be to use TTree::SetBranchAddress rather than GetBranch/SetAddress).

Cheers,
Philippe.