2.3.3. Import data from a TNtuple/TDSNtuple/TTree
From a TTree object (or any of its derived-object) contained in a ROOT-file, it is possible to
import data, with or without selection of a variable and addition of other ones through formula then
deletions of patterns ensuring a criterion
using namespace URANIE::DataServer; // (1)
TDataServer * tds = new TDataServer(); // (2)
tds->ntupleDataRead("hsimple.root","ntuple","px*px:*:py*py", "px*px+py*py < 2.0"); // (3)
tds->draw("py:px"); // (4)
Description of data importation of a TTree from a ROOT file
Specification of the namespace.
Creation of a pointer tds to an object of type
TDataServerwithout name and title.Fill the
TDataServerwith all branches contained in the tree ntuple that is contained inhsimple.root. Two new attributes are computed on the fly and a selection is applied on the patterns to be kept;Plots scatterplot of the variable py versus the variable px
In this case, tds is constructed from the TTree ntuple contained in the file hsimple.root
where all initial variables are kept (* character). Figure 2.37 shows the
content of the ntuple. Two new variables are then added on top, defined by the equations “px*py”
and “py*px” on both side of the “*” string. A cut is finally done, to exclude all data that would
satisfy the following equation \(px^2 + py^2 < 2\)
Figure 2.37 Content of the ntuple tree contained in “hsimple.root” file.
The obtained graph is as follow:
Figure 2.38 Data importation from a TNtuple
Summary: Loading data ( TNtupleD of ROOT in a TFile)
ntupleDataRead(const char * file, const char * tree, const char * svar=”*”, const char * cut=””)Loads the data contained in the
TNtupleD treeof file ROOTTFile fileby selecting/creating the list of variablessvar(the variables are separated by the “:” character, and “*” character means recalling all variables of the TNtupleD) and by deleting all patterns ensuring the criterioncut.