New branch

I want to add a branch to the tree as a column of identical numbers (in my case, this number is 562). Then subtract another branch from one, thereby creating another branch. How can this be implemented?


ROOT Version: 6.26/10
Platform: pycharm community

The best way to handle depends on ‘why’ you want to do this and how you will end up using the result (for example, the solution might be to use aliases).

I have a file that has two main trees. Each tree has several branches that contain data from certain detectors. The data is presented as a dependence of the voltage amplitude on time (in nanoseconds). About 10,000 points in each branch. Depending on the branch name, I need to shift the time values by a certain delay time (for example, by 562 nanoseconds). To do this, I decided to create a new file and create two trees in it, in which there will be branches with columns containing the desired delay time values. Then I want to copy two trees from the source file and subtract new columns from the original columns. Eventually, time-shifted histograms should be obtained (by calling rootbrowse in the terminal).

myFile = ROOT.TFile.Open(“/home/erg/po_1_event/Oct__13070311.root”)
Tree = myFile.Get(“FADCData 882”)
tree = myFile.Get(“myTree”)

ch0 = Tree.GetBranch(“Channel0”)
br0 = tree.GetBranch(“branch0”)
wor = array.array(‘i’, [0])
tree.Branch(“barn0”, wor, “barn0/I”)
for i in range(10230):
wor[0] = ch0 - br0
tree.Fill()

tree.Write()

tree.Scan()

@eguiraud Maybe some RDataFrame expert can help in creating a Snapshot with some “new” and/or “recomputed” branches.

You can do that with a:

df.Define("newcolumn", ...)
  .Redefine("existing_column", ...)
  .Snapshot("newtree", "newfile.root", column_list)

(info about each of the methods is available from the links you shared).

Cheers,
Enrico

Before that, I created the /home/erg/po_1_event/Oct_13070311.root file with the FData882 tree and the trench0 branch in it.

import ROOT
import numpy as np
import array

myFile = ROOT.TFile.Open(“/home/erg/po_1_event/Oct__13070311.root”)
Tree = myFile.Get(“FADCData 882”)
tree = myFile.Get(“myTree”)

ch0 = Tree.GetBranch(“Channel0”)
br0 = tree.GetBranch(“branch0”)

tom = ROOT.RDataFrame(“FADCData 882”, “/home/erg/po_1_event/Oct__13070311.root”).Redefine(“Channel0”, “Channel0 - 562”).Snapshot(“FData882”, “/home/erg/po_1_event/Oct_13070311.root”, {“trench0”})

TypeError: Template method resolution failed:
none of the 3 overloaded methods succeeded.
TypeError: could not convert argument 3
Failed to instantiate “Snapshot(std::string,std::string,set)”

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