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

  1. Specification of the namespace.

  2. Creation of a pointer tds to an object of type TDataServer without name and title.

  3. Fill the TDataServer with all branches contained in the tree ntuple that is contained in hsimple.root. Two new attributes are computed on the fly and a selection is applied on the patterns to be kept;

  4. 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\)

../../_images/hsimplecontaint.png

Figure 2.37 Content of the ntuple tree contained in “hsimple.root” file.

The obtained graph is as follow:

../../_images/hsimple_scatterplot.png

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 tree of file ROOT TFile file by selecting/creating the list of variables svar (the variables are separated by the “:” character, and “*” character means recalling all variables of the TNtupleD) and by deleting all patterns ensuring the criterion cut.