Link two TTrees through events number

Dear,

I’m looping over two containers (jets and electrons) in each event, and I’m storing some kinematic variables of these two objects. However the size of the container is not the same per event (e.g. 7 jets and 4 electrons in a particular event), so I’m storing their variables in two different TTree’s (I think it was recommended, correct me if I’m wrong).

Now I want to calculate some variables, such as the angular separation of electrons and jets in each event, and I was wondering how I can link these two Tree’s. (Or how do you deal with this case in a more efficient way?)

Many thanks!

If your “event numbers” are just the raw entry numbers of these trees then you want to play with tree friends.

BTW. A tree may contain branches with variable lengths so you can have all your “containers” in the same tree (i.e. no need to create separate trees).

Hi Wile, thanks a lot for your answer, but when I fill the tree it does include all the branches(variables), so how do I fill the branches individually in order to have branches with variable lengths?

E.g :

tree = new TTree(“tree”, “tree”);

tree->Branch(“xp”,&get_xp);
tree->Branch(“yp”,&get_yp); // sometimes there is no value for this variable in an event

for iev in events:
get_xp = x_value(iev);
get_yp = y_value(iev);
tree->Fill();

std::vector<double> xp;
std::vector<double> yp;

tree->Branch("xp",&xp);
tree->Branch("yp",&yp); 

for iev in events:
   xp.clear();
   yp.clear();
   if (has value for get xp) 
       xp.push_back(x_value(iev))
   if (has value for get yp) 
       yp.push_back(y_value(iev))
   tree->Fill();

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.