How to analyze a TTree data of different number of entries?


I want to analyse TTree data of different length. E.g: “ABC.root” file having two TTrees “tree1” and “tree2”. For filling the data in “tree1” its referring to .data file named as “dataTree1” which contains 10000 entries. For filling the data in “tree2” its referring to .data file as “dataTree2” which contains 15000 entries.

Code is as below:

void drawGraph()
TFile *f1 = TFile::Open(“ABC.root”);
TTree T1 = (TTree)f1->Get(“tree1”);
T1->AddFriend(“tree2”, “ABC.root”);
TCanvas *c = new TCanvas(“c”, “c”, 0, 0, 800, 800);
TGraph *gr = new TGraph(T1->GetSelectedRows(),T1->GetV2(), T1->GetV1());
TF1 *f = new TF1(“f”, “exp([0]+[1]*x)”, -1, 6.10);
gr->Fit(f, “R”);

This works fine. But for the data above 10000 its showing a line on zero. My logic is to get a numberOfEntries in “tree2” and “tree1”. Take a difference of numberOfEntries. and assign that much zero entries to “tree1”.

Is it a right approach? OR How can I analyze a TTree data of different number of entries?

I come back because I still have not found a solution.

T1->Draw(“element1:tree2.element1”, “Entry$ < Entries$”);
T1->Draw(“element1:tree2.element1”, TString::Format(“Entry$ < %ld”, T1->GetEntries()));

See “Special functions and variables” in the TTree::Draw method description.

Thanks for the reply. But it’s not working. For analysis of TTree of different lenghts, I have to add zero’s in .data file to make it of equal length.


If the 2 TTree that are friends are different lengths (different number of entries), you must give some information on ‘which’ are the missing entries (are they missing at the beginning and the end, somewhere in the middle, arbritrarily)?

The usual way of doing so is to build an index (see TTree::BuildIndex) on the friend tree which will give the system a way to associate two entries in each tree (usual the one that have the same run and even number).