Tchains and Branch access

Dear Rooters,

I’m trying to use TChain in orer to merge several root file and to access data splitted in 2 branches.
The code I’m using in ROOT 3.10 is :

#################################

TBranch* jetInfoBranch[2];
TChain MCchain(“MyTree”,“MyTree”);

MCchain.Add(“fileA.root”);
MCchain.Add(“fileB.root”);

cout << "Print MC chain : " << MCchain.Print() << endl;

cout << "List of files : " << endl;
MCchain.GetListOfFiles()->Print();
cout << “List of Branches : " << endl;
MCchain.GetListOfBranches()->Print();
cout << " List of Leaves :” << endl;
MCchain.GetListOfLeaves()->Print();

jetInfoBranch[0] = MCchain.GetBranch(“bJetsBranch”);
//jetInfoBranch[0]->SetAddress(&structA);
cout << "Jet entries : " << jetInfoBranch[0]->GetEntries() << endl;
jetInfoBranch[1] = MCchain.GetBranch(“OtherJetsBranch”);
jetInfoBranch[1]->SetAddress(&structB);
cout << "Jet 2 entries : " << jetInfoBranch[1]->GetEntries() << endl;
cout << "MC chain entries : " << MCchain.GetEntries() << endl;

//cout << "MC chain : " << MCchain.Print() << endl;
cout << "Number of trees : " << MCchain.GetNtrees() << endl;
cout << "Number of branches : " << MCchain.GetNbranches() << endl;
cout << "MC chain entries : " << MCchain.GetEntries() << endl;

cout << "Jet entries : " << jetInfoBranch[0]->GetEntries() << endl;
cout << "Jet 2 entries : " << jetInfoBranch[1]->GetEntries() << endl;
cout << "MC chain entries : " << MCchain.GetEntries() << endl;[i]

#################################

where structA and structB are standard C structures made of integers and doubles.

The output I obtain is tthe following :

#################################

Print MC chain : ******************************************************************************
*Tree :Calib Tree: Calib Tree *
*Entries : 6 : Total = 39964 bytes File Size = 1520 *

  •    :          : Tree compression factor =   1.00                       *
    

*Br 0 :CalibInfoBranch : inputColl/C:jetFindingAlgo/C:jetClusterAlgo/C: *

  •     | towerEtThreshold/D:conesize/D:seedEtCut/D:JetEtMin/D:JetEtaMin/D:*
    
  •     | JetEtaMax/D                                                      *
    

*Entries : 6 : Total Size= 13844 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 1 :bJetsBranch : eT/D:eta/D:genE/D:recE/D *
*Entries : 6 : Total Size= 12885 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 2 :OtherJetsBranch : eT/D:eta/D:genE/D:recE/D *
*Entries : 6 : Total Size= 12897 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *


*Tree :Calib Tree: Calib Tree *
*Entries : 11 : Total = 40724 bytes File Size = 1731 *

  •    :          : Tree compression factor =   1.00                       *
    

*Br 0 :CalibInfoBranch : inputColl/C:jetFindingAlgo/C:jetClusterAlgo/C: *

  •     | towerEtThreshold/D:conesize/D:seedEtCut/D:JetEtMin/D:JetEtaMin/D:*
    
  •     | JetEtaMax/D                                                      *
    

*Entries : 11 : Total Size= 14284 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 1 :bJetsBranch : eT/D:eta/D:genE/D:recE/D *
*Entries : 11 : Total Size= 13045 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 2 :OtherJetsBranch : eT/D:eta/D:genE/D:recE/D *
*Entries : 11 : Total Size= 13057 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

0
List of files :
OBJ: TChainElement Calib Tree jet3.root
OBJ: TChainElement Calib Tree jet4.root
List of Branches :
*Br 3 :CalibInfoBranch : inputColl/C:jetFindingAlgo/C:jetClusterAlgo/C: *

  •     | towerEtThreshold/D:conesize/D:seedEtCut/D:JetEtMin/D:JetEtaMin/D:*
    
  •     | JetEtaMax/D                                                      *
    

*Entries : 6 : Total Size= 13844 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 4 :bJetsBranch : eT/D:eta/D:genE/D:recE/D *
*Entries : 6 : Total Size= 12885 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 5 :OtherJetsBranch : eT/D:eta/D:genE/D:recE/D *
*Entries : 6 : Total Size= 12897 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

List of Leaves :
OBJ: TLeafC inputColl inputColl
OBJ: TLeafC jetFindingAlgo jetFindingAlgo
OBJ: TLeafC jetClusterAlgo jetClusterAlgo
OBJ: TLeafD towerEtThreshold towerEtThreshold
OBJ: TLeafD conesize conesize
OBJ: TLeafD seedEtCut seedEtCut
OBJ: TLeafD JetEtMin JetEtMin
OBJ: TLeafD JetEtaMin JetEtaMin
OBJ: TLeafD JetEtaMax JetEtaMax
OBJ: TLeafD eT eT
OBJ: TLeafD eta eta
OBJ: TLeafD genE genE
OBJ: TLeafD recE recE
OBJ: TLeafD eT eT
OBJ: TLeafD eta eta
OBJ: TLeafD genE genE
OBJ: TLeafD recE recE
Jet entries : 6
Jet 2 entries : 6
MC chain entries : 17
Number of trees : 2
Number of branches : 3
MC chain entries : 17
Jet entries : 0
Jet 2 entries : 0
MC chain entries : 17

#############################

So it seems that the 2 files are correctly read but that the access to the branch data is broken. There are 17 entries in the chain but depending where I’m asking for the jetinfoBranch[x]->GetEntries() the answer is different and never consistent with the TChain->GetEntries() (only one file seems to be accessible).

Do you have an idea of what happens and how I can solve this problem ?

In fact, I think that it is due to the GetBranch() method which returns a pointer to the branch of only one particular file… if that’s true is it possible to update automatically this pointer in order to be able to loop over all the files ?

Cheers,

Alain R.[/i]