Behavior of TChain when adding Trees which have friends already defined

_ROOT Version: 6.10.04-x86_64-slc6-gcc62-opt
_Platform: CentOS7, SL6 (same behavior on both)
_Compiler: pyROOT macro (with python 2.7.13-x86_64-slc6-gcc62)

Dear experts,

I realised I am using a TChain in what may be a quite special case so I would like to check with you the expected behavior:

mychain = TChain(mytreename)
for i in sorted_input_files:
    mychain.AddFile(i.filename, -1, mytreename)

In each file, the tree “mytreename” has a friend tree already defined, and depending on the file the branch “mybranch” is defined either in “mytreename” or in the friend tree, which is located elsewhere (“mytreename” knows about it) I will call it “myfriendtreename”.

Afterwards, I use TChain::Project to fill up some histograms, the command includes “mybranch”, used as a weight. I observe what appears to be a random behavior to me:

  • either mybranch is read correctly throughout the files, i.e. in “mytreename” or in “myfriendtreename” depending on the file, and the histogram is filled correctly

  • sometimes it seems “mybranch” is read only in “myfriendtreename” such that for the files where it is defined in “mytreename” it is set to 0, and the histograms is missing data

My question is:

  • is this an expected behavior and one should not use TChain this way?
  • what is your suggestion to fix the code (ideally in a minimal way, as this is part of a large software and any modification may break other things) and get histograms properly filled at all time?

Looking forward to hearing from your advice and suggestions
Cheers
Matthias


Maybe @pcanal can give some advice for this particular case

I would guess that the difference in behavior is trigger by whether the branch is in the main tree or in the friend tree in the first file (i.e. the recorded name might be “myfriendtreename.mybranch” rather than “mybranch”.

But in this case I would expect to have a reproducible behavior, right? This is not what I observe and I cannot find any logic in it:
It depends how I create the TChain (AddFile or create one TChain per file and then use TChain::Add to combine them), if I remove and recreate the same TChain the behavior changes sometimes …

I would be interesting to understand what is the expected behavior of TChain in this case, if defined.

In the meantime I changed the format of my inputs such that a given branch name is defined either in the original, or in the friend and this seems to fix the issue.

If you can provide a reproducer, I will take a closer look at the cause. Thanks.

Thank you for the reply and offering to have a look at this.

To transpose my setup to lxplus is not so trivial because my tree knows the absolute path of its friend. Do you have acces to the NAF facility by any chance?

Best wishes

I don’t think so.

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