Deactivating branches that are not filled

Hi

Say I want to fill a tree with the momentum of particles. For example “el_pt” should hold the pT of an electron and “mu_pt” should hold the pT of a muon. If there are e.g. no electrons in the event, how can I not fill the el_pt?

I think one solution to this could be to use vectors, and I would simply fill an empty vector. But I want to have a flat n-tuple, without using any vectors.

What I do right now is to give to fill everything with a nonphysical dummy variable. When looping again over the tree, I can then only select branches that don’t have this nonphysical dummy variable. This is cumbersome and error prone.

I then started implementing a loop over all branches that would check if the values are nonphysical and then would use TTree::SetBranchStatus() to deactivate them. I think that will work, but it is also cumbersome. I keep thinking what I want to achieve must have a simple solution.

How can this be achieved?

See documentation to TTree::Branch. You can have variable many entries: “If leaf name has the form var[nelem], where nelem is alphanumeric, then if nelem is a leaf name, it is used as the variable size of the array, otherwise return 0”

So in that case you need to store the number of electrons + the number of muons manually.

What is wrong with a vector?

[quote]I then started implementing a loop over all branches that would check if the values are nonphysical and then would use TTree::SetBranchStatus() to deactivate them. I think that will work, but it is also cumbersome. I keep thinking what I want to achieve must have a simple solution.
[/quote]
That doesn’t work. Your branches will be out of sync.

Thanks for the reply.

I’m afraid I don’t understand your suggestion. Are you suggesting to use arrays instead of doubles?

Vectors cannot be processed by my postprocessing program.

Why are the branches out of sync? When I use getEntry(i), does it not always get the entry i? Does it get out of sync if I deactivate a branch and activate it again later? Can you point me to documentation of that?

Why are the branches out of sync? When I use getEntry(i), does it not always get the entry i? Does it get out of sync if I deactivate a branch and activate it again later? Can you point me to documentation of that

if you do fill one branch 3 times and another branch just the 3rd time upon doing

b1->GetEntry(0);
b2->GetEntry(0);

instead of getting information about the ‘same’ event you will get information about the 1st event for b1 and about the 3rd event for b3 … Furthermore you will have no information about which event has been skipped for which branches …

If you can not use std::vector (with 0 or 1 element), then you other alternative is to have one tree per (group of) branch(es) with a special branch repeated in each tree containing the ‘event number’ or ‘event identifier’, you can then group the TTree using the AddFriend routine (re-read the User’s guide on this concept).

Cheers,
Philippe.

Thanks for the explanation. I see that TTree::SetBranchStatus() is not working. I guess it’s best to rewrite my postprocessing step, such that it accepts vectors (of length 1).

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