Summing energies from two branches under certain conditions

Dear,

I have a root file with two TTree (e.g. Tree1 and Tree2) with the following TBranch:
energy
eventID
detectorID
blockID

I want to create a new file with a TTree (TreeTotal) with the same architecture (energy; eventID; detectorID; blockID), but the TBranch energy from Tree1 and Tree2 will be the summed when they have the same eventID, detectorID and blockID. If this situation is not satisfied, then the data will be just copied to TreeTotal. For instance:

Tree1 has:
energy: 2.0; 5.0; 7.0; 4.0
eventID: 1 ; 2 ; 3 ; 4
detectorID: 2 ; 5 ; 9 ; 3
blockID: 1 ; 4 ; 3 ; 2

Tree2 has:
energy: 4.0; 1.0; 3.0; 5.0
eventID: 2 ; 4 ; 5 ; 6
detectorID: 5 ; 3 ; 8 ; 9
blockID: 4 ; 1 ; 2 ; 3

TreeTotal will have:
energy: 2.0; 9.0; 7.0; 4.0; 1.0; 3.0; 5.0
eventID: 1 ; 2 ; 3 ; 4 ; 4 ; 5 ; 6
detectorID: 2 ; 5 ; 9 ; 3 ; 3 ; 8 ; 9
blockID: 1 ; 4 ; 3 ; 2 ; 1 ; 2 ; 3

Please, notice that the summing happens only for event 2, which is the one that all the IDs are the same.
I would like if this can be done in pyRoot and if RDataFrame is suitable for this.


Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

ROOT Version: 6.28/04
Platform: Linux Mint
Compiler: g++


Dear @DBoni ,

Thanks for reaching out. I understand your problem and I think it potentially can be solved with TTreeIndex and RDataFrame (see a somewhat related post at Modification of a RDataFrame with an extracted column).

Although the application is not trivial so I need to spend some time trying to frame your problem. Meanwhile let me know if the material above helps you in finding some possible solution.

Cheers,
Vincenzo

Dear Vicenzo,

Thank you for the guidance. It seems that I have found a workaround here, but I will read the post you mentioned to see if I can solve the problem in another way.

Cheers,
Daniel

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