In simple cases, the data consist of a sequence of n-tuples (i.e. ordered collections of the values of n variables). The simplest example is that of a text file containing several lines, each of them showing a fixed number of entries (appearing like a "table" when visualized). We can create a ROOT tree containing all values with a couple of commands:
root[] TTree *T = new TTree("ntuple","data from ascii file"); root[] Long64_t nlines = T->ReadFile("basic.dat","x:y:z"); root[] T->Draw("x:y"); // distribution of projections in (x,y) plane root[] T->Draw("x:y","z>0"); // the same, when z>0
The creation of a TTree requires a name (as for every ROOT object) and a title. The method TTree:ReadFile(...) requires the name of the file and the list of variables, that are assumed to be float by default. This list is a single string in which the names of the variables are separated by columns (`:'). As shown in the TTree:ReadFile(...) documentation, we can specify different types and even define arrays in place of simple variables.
In a compiled application, during the loop over all events, the user will save the current values of the ordered list of the variables by invoking the TTree::Fill method. In contrast with TH1::Fill, that simply increments the bin corresponding to the input values (up to 3 values for 3-dimensional histograms, followed by the weight) discarding the values themselves, TTree::Fill saves the actual values. This means that the size of a histogram never changes, whereas the size (on disk, not in memory!) of a TTree increases almost linearly with the number of saved events.
Using a tree, the user may save data of any type, including his own classes, and benefit of a highly optimized read access (orders of magnitude faster than with database tables). We will speak again about trees in the section about input/output. Several examples of increasing complexity about using ROOT trees are provided together with the ROOT framework, and can be found in the $ROOTSYS/tutorials/tree/ directory. Other guides are availble among the Tutorials and the HowTo's.