Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TTree Class Reference

A TTree represents a columnar dataset.

Any C++ type can be stored in its columns.

A TTree, often called in jargon tree, consists of a list of independent columns or branches, represented by the TBranch class. Behind each branch, buffers are allocated automatically by ROOT. Such buffers are automatically written to disk or kept in memory until the size stored in the attribute fMaxVirtualSize is reached. Variables of one branch are written to the same buffer. A branch buffer is automatically compressed if the file compression attribute is set (default). Branches may be written to different files (see TBranch::SetFile).

The ROOT user can decide to make one single branch and serialize one object into one single I/O buffer or to make several branches. Making several branches is particularly interesting in the data analysis phase, when it is desirable to have a high reading rate and not all columns are equally interesting

Create a TTree to store columnar data

Construct a TTree

TTree tree(name, title)
char name[80]
Definition TGX11.cxx:110
A TTree represents a columnar dataset.
Definition TTree.h:79
Definition tree.py:1

Creates a Tree with name and title.

Various kinds of branches can be added to a tree:

  • Variables representing fundamental types, simple classes/structures or list of variables: for example for C or Fortran structures.
  • Any C++ object or collection, provided by the STL or ROOT.

In the following, the details about the creation of different types of branches are given.

Add a column ("branch") holding fundamental types and arrays thereof

This strategy works also for lists of variables, e.g. to describe simple structures. It is strongly recommended to persistify those as objects rather than lists of leaves.

auto branch = tree.Branch(branchname, address, leaflist, bufsize)
  • address is the address of the first item of a structure
  • leaflist is the concatenation of all the variable names and types separated by a colon character : The variable name and the variable type are separated by a slash (/). The variable type must be 1 character. (Characters after the first are legal and will be appended to the visible name of the leaf, but have no effect.) If no type is given, the type of the variable is assumed to be the same as the previous variable. If the first variable does not have a type, it is assumed of type F by default. The list of currently supported types is given below:

    • C : a character string terminated by the 0 character
    • B : an 8 bit signed integer (Char_t)
    • b : an 8 bit unsigned integer (UChar_t)
    • S : a 16 bit signed integer (Short_t)
    • s : a 16 bit unsigned integer (UShort_t)
    • I : a 32 bit signed integer (Int_t)
    • i : a 32 bit unsigned integer (UInt_t)
    • F : a 32 bit floating point (Float_t)
    • f : a 24 bit floating point with truncated mantissa (Float16_t)
    • D : a 64 bit floating point (Double_t)
    • d : a 24 bit truncated floating point (Double32_t)
    • L : a 64 bit signed integer (Long64_t)
    • l : a 64 bit unsigned integer (ULong64_t)
    • G : a long signed integer, stored as 64 bit (Long_t)
    • g : a long unsigned integer, stored as 64 bit (ULong_t)
    • O : [the letter o, not a zero] a boolean (Bool_t)

    Examples:

    • A int: "myVar/I"
    • A float array with fixed size: "myArrfloat[42]/F"
    • An double array with variable size, held by the myvar column: "myArrdouble[myvar]/D"
    • An Double32_t array with variable size, held by the myvar column , with values between 0 and 16: "myArr[myvar]/d[0,10]"
  • If the address points to a single numerical variable, the leaflist is optional:
    int value;
    tree->Branch(branchname, &value);
    Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
  • If the address points to more than one numerical variable, we strongly recommend that the variable be sorted in decreasing order of size. Any other order will result in a non-portable TTree (i.e. you will not be able to read it back on a platform with a different padding strategy). We recommend to persistify objects rather than composite leaflists.
  • In case of the truncated floating point types (Float16_t and Double32_t) you can furthermore specify the range in the style [xmin,xmax] or [xmin,xmax,nbits] after the type character. For example, for storing a variable size array myArr of Double32_t with values within a range of [0, 2*pi] and the size of which is stored in a branch called myArrSize, the syntax for the leaflist string would be: myArr[myArrSize]/d[0,twopi]. Of course the number of bits could be specified, the standard rules of opaque typedefs annotation are valid. For example, if only 18 bits were sufficient, the syntax would become: myArr[myArrSize]/d[0,twopi,18]

Adding a column holding STL collection instances (e.g. std::vector, std::list, std::unordered_map)

auto branch = tree.Branch( branchname, STLcollection, buffsize, splitlevel);

STLcollection is the address of a pointer to std::vector, std::list, std::deque, std::set or std::multiset containing pointers to objects. If the splitlevel is a value bigger than 100 (TTree::kSplitCollectionOfPointers) then the collection will be written in split mode, e.g. if it contains objects of any types deriving from TTrack this function will sort the objects based on their type and store them in separate branches in split mode.

branch->SetAddress(void *address)

In case of dynamic structures changing with each entry for example, one must redefine the branch address before filling the branch again. This is done via the TBranch::SetAddress member function.

Add a column holding objects

MyClass object;
auto branch = tree.Branch(branchname, &object, bufsize, splitlevel)

Note: The 2nd parameter must be the address of a valid object. The object must not be destroyed (i.e. be deleted) until the TTree is deleted or TTree::ResetBranchAddress is called.

  • if splitlevel=0, the object is serialized in the branch buffer.
  • if splitlevel=1 (default), this branch will automatically be split into subbranches, with one subbranch for each data member or object of the object itself. In case the object member is a TClonesArray, the mechanism described in case C is applied to this array.
  • if splitlevel=2 ,this branch will automatically be split into subbranches, with one subbranch for each data member or object of the object itself. In case the object member is a TClonesArray, it is processed as a TObject*, only one branch.

Another available syntax is the following:

auto branch = tree.Branch(branchname, &p_object, bufsize, splitlevel)
auto branch = tree.Branch(branchname, className, &p_object, bufsize, splitlevel)
  • p_object is a pointer to an object.
  • If className is not specified, Branch uses the type of p_object to determine the type of the object.
  • If className is used to specify explicitly the object type, the className must be of a type related to the one pointed to by the pointer. It should be either a parent or derived class.

Note: The pointer whose address is passed to TTree::Branch must not be destroyed (i.e. go out of scope) until the TTree is deleted or TTree::ResetBranchAddress is called.

Note: The pointer p_object must be initialized before calling TTree::Branch

  • Do either:
    MyDataClass* p_object = nullptr;
    tree.Branch(branchname, &p_object);
  • Or:
    auto p_object = new MyDataClass;
    tree.Branch(branchname, &p_object);
    Whether the pointer is set to zero or not, the ownership of the object is not taken over by the TTree. I.e. even though an object will be allocated by TTree::Branch if the pointer p_object is zero, the object will not be deleted when the TTree is deleted.

Add a column holding TClonesArray instances

It is recommended to use STL containers instead of TClonesArrays*.

// clonesarray is the address of a pointer to a TClonesArray.
auto branch = tree.Branch(branchname,clonesarray, bufsize, splitlevel)

The TClonesArray is a direct access list of objects of the same class. For example, if the TClonesArray is an array of TTrack objects, this function will create one subbranch for each data member of the object TTrack.

Fill the Tree

A TTree instance is filled with the invocation of the TTree::Fill method:

tree.Fill()

Upon its invocation, a loop on all defined branches takes place that for each branch invokes the TBranch::Fill method.

Add a column to an already existing Tree

You may want to add a branch to an existing tree. For example, if one variable in the tree was computed with a certain algorithm, you may want to try another algorithm and compare the results. One solution is to add a new branch, fill it, and save the tree. The code below adds a simple branch to an existing tree. Note the kOverwrite option in the Write method, it overwrites the existing tree. If it is not specified, two copies of the tree headers are saved.

void tree3AddBranch() {
TFile f("tree3.root", "update");
Float_t new_v;
auto t3 = f->Get<TTree>("t3");
auto newBranch = t3->Branch("new_v", &new_v, "new_v/F");
Long64_t nentries = t3->GetEntries(); // read the number of entries in the t3
for (Long64_t i = 0; i < nentries; i++) {
new_v = gRandom->Gaus(0, 1);
newBranch->Fill();
}
t3->Write("", TObject::kOverwrite); // save only the new version of the tree
}
#define f(i)
Definition RSha256.hxx:104
float Float_t
Definition RtypesCore.h:57
long long Long64_t
Definition RtypesCore.h:80
int nentries
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:51
@ kOverwrite
overwrite existing object with same name
Definition TObject.h:92
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition TRandom.cxx:274
virtual Int_t Fill()
Fill all branches.
Definition TTree.cxx:4594
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.
Definition TTree.h:350

It is not always possible to add branches to existing datasets stored in TFiles: for example, these files might not be writeable, just readable. In addition, modifying in place a TTree causes a new TTree instance to be written and the previous one to be deleted. For this reasons, ROOT offers the concept of friends for TTree and TChain: if is good practice to rely on friend trees rather than adding a branch manually.

An Example

// A simple example with histograms and a tree
//
// This program creates :
// - a one dimensional histogram
// - a two dimensional histogram
// - a profile histogram
// - a tree
//
// These objects are filled with some random numbers and saved on a file.
#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
#include "TProfile.h"
#include "TRandom.h"
#include "TTree.h"
//__________________________________________________________________________
main(int argc, char **argv)
{
// Create a new ROOT binary machine independent file.
// Note that this file may contain any kind of ROOT objects, histograms,trees
// pictures, graphics objects, detector geometries, tracks, events, etc..
// This file is now becoming the current directory.
TFile hfile("htree.root","RECREATE","Demo ROOT file with histograms & trees");
// Create some histograms and a profile histogram
TH1F hpx("hpx","This is the px distribution",100,-4,4);
TH2F hpxpy("hpxpy","py ps px",40,-4,4,40,-4,4);
TProfile hprof("hprof","Profile of pz versus px",100,-4,4,0,20);
// Define some simple structures
typedef struct {Float_t x,y,z;} POINT;
typedef struct {
Int_t ntrack,nseg,nvertex;
UInt_t flag;
Float_t temperature;
} EVENTN;
POINT point;
EVENTN eventn;
// Create a ROOT Tree
TTree tree("T","An example of ROOT tree with a few branches");
tree.Branch("point",&point,"x:y:z");
tree.Branch("eventn",&eventn,"ntrack/I:nseg:nvertex:flag/i:temperature/F");
tree.Branch("hpx","TH1F",&hpx,128000,0);
Float_t px,py,pz;
// Here we start a loop on 1000 events
for ( Int_t i=0; i<1000; i++) {
gRandom->Rannor(px,py);
pz = px*px + py*py;
const auto random = gRandom->::Rndm(1);
// Fill histograms
hpx.Fill(px);
hpxpy.Fill(px,py,1);
hprof.Fill(px,pz,1);
// Fill structures
point.x = 10*(random-1);
point.y = 5*random;
point.z = 20*random;
eventn.ntrack = Int_t(100*random);
eventn.nseg = Int_t(2*eventn.ntrack);
eventn.nvertex = 1;
eventn.flag = Int_t(random+0.5);
eventn.temperature = 20+random;
// Fill the tree. For each event, save the 2 structures and 3 objects
// In this simple example, the objects hpx, hprof and hpxpy are slightly
// different from event to event. We expect a big compression factor!
tree->Fill();
}
// End of the loop
tree.Print();
// Save all objects in this file
hfile.Write();
// Close the file. Note that this is automatically done when you leave
// the application upon file destruction.
hfile.Close();
return 0;
}
int main()
Definition Prototype.cxx:12
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:577
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:257
Profile Histogram.
Definition TProfile.h:32
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition TRandom.cxx:500
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17

PyROOT

The TTree class has several additions for its use from Python, which are also available in its subclasses e.g. TChain and TNtuple.

First, TTree instances are iterable in Python. Therefore, assuming t is a TTree instance, we can do:

for entry in t:
x = entry.branch_name
...

At each iteration, a new entry of the tree will be read. In the code above, entry allows to access the branch values for the current entry. This can be done with the syntax entry.branch_name or, if the branch name is incompatible with Python naming rules, with e.g. "getattr(entry, '1_branch_name')".

Please note that iterating in Python can be slow, so only iterate over a tree as described above if performance is not an issue or when dealing with a small dataset. To read and process the entries of a tree in a much faster way, please use ROOT::RDataFrame.

Second, a couple of TTree methods have been modified to facilitate their use from Python: TTree::Branch and TTree::SetBranchAddress.

Regarding TTree::Branch, the following example shows how we can create different types of branches of a TTree. Note that Branch will just link the new branch with a given Python object, so it is still necessary to fill such object with the desired content before calling TTree::Fill.

from array import array
import numpy as np
import ROOT
from ROOT import addressof
# Basic type branch (float) - use array of length 1
n = array('f', [ 1.5 ])
t.Branch('floatb', n, 'floatb/F')
# Array branch - use array of length N
N = 10
a = array('d', N*[ 0. ])
t.Branch('arrayb', a, 'arrayb[' + str(N) + ']/D')
# Array branch - use NumPy array of length N
npa = np.array(N*[ 0. ])
t.Branch('nparrayb', npa, 'nparrayb[' + str(N) + ']/D')
# std::vector branch
v = ROOT.std.vector('double')(N*[ 0. ])
t.Branch('vectorb0', v)
# Class branch / struct in single branch
cb = ROOT.MyClass()
t.Branch('classb', cb)
# Struct as leaflist
# Assuming:
# struct MyStruct {
# int myint;
# float myfloat;
# };
ms = ROOT.MyStruct()
t.Branch('structll', ms, 'myint/I:myfloat/F')
# Store struct members individually
ms = ROOT.MyStruct()
# Use `addressof` to get the address of the struct members
t.Branch('myintb', addressof(ms, 'myint'), 'myint/I')
t.Branch('myfloatb', addressof(ms, 'myfloat'), 'myfloat/F')

Concerning TTree::SetBranchAddress, below is an example of prepare the reading of different types of branches of a TTree. Note that SetBranchAddress will just link a given branch with a certain Python object; after that, in order to read the content of such branch for a given TTree entry x, TTree::GetEntry(x) must be invoked.

from array import array
import numpy as np
import ROOT
# Basic type branch (float) - use array of length 1
n = array('f', [ 0. ])
t.SetBranchAddress('floatb', n)
# Array branch - use array of length N
N = 10
a = array('d', N*[ 0. ])
t.SetBranchAddress('arrayb', a)
# Array branch - use NumPy array of length N
npa = np.array(N*[ 0. ])
t.SetBranchAddress('nparrayb', a)
# std::vector branch
v = ROOT.std.vector('double')()
t.SetBranchAddress('vectorb', v)
# Class branch
cb = ROOT.MyClass()
t.SetBranchAddress('classb', cb)
# Struct branch (both single-branch and leaf list)
ms = ROOT.MyStruct()
ds.SetBranchAddress('structb', ms)

Definition at line 79 of file TTree.h.

Classes

class  TClusterIterator
 Helper class to iterate over cluster of baskets. More...
 
class  TFriendLock
 Helper class to prevent infinite recursion in the usage of TTree Friends. More...
 

Public Types

enum  { kSplitCollectionOfPointers = 100 }
 
enum  ESetBranchAddressStatus {
  kMissingBranch = -5 , kInternalError = -4 , kMissingCompiledCollectionProxy = -3 , kMismatch = -2 ,
  kClassMismatch = -1 , kMatch = 0 , kMatchConversion = 1 , kMatchConversionCollection = 2 ,
  kMakeClass = 3 , kVoidPtr = 4 , kNoCheck = 5 , kNeedEnableDecomposedObj = (1ULL << ( 29 )) ,
  kNeedDisableDecomposedObj = (1ULL << ( 30 )) , kDecomposedObjMask = kNeedEnableDecomposedObj | kNeedDisableDecomposedObj
}
 
enum  EStatusBits { kForceRead = (1ULL << ( 11 )) , kCircular = (1ULL << ( 12 )) , kOnlyFlushAtCluster = (1ULL << ( 14 )) , kEntriesReshuffled = (1ULL << ( 19 )) }
 
- Public Types inherited from TObject
enum  {
  kIsOnHeap = 0x01000000 , kNotDeleted = 0x02000000 , kZombie = 0x04000000 , kInconsistent = 0x08000000 ,
  kBitMask = 0x00ffffff
}
 
enum  { kSingleKey = (1ULL << ( 0 )) , kOverwrite = (1ULL << ( 1 )) , kWriteDelete = (1ULL << ( 2 )) }
 
enum  EDeprecatedStatusBits { kObjInCanvas = (1ULL << ( 3 )) }
 
enum  EStatusBits {
  kCanDelete = (1ULL << ( 0 )) , kMustCleanup = (1ULL << ( 3 )) , kIsReferenced = (1ULL << ( 4 )) , kHasUUID = (1ULL << ( 5 )) ,
  kCannotPick = (1ULL << ( 6 )) , kNoContextMenu = (1ULL << ( 8 )) , kInvalidObject = (1ULL << ( 13 ))
}
 

Public Member Functions

 TTree ()
 Default constructor and I/O constructor.
 
 TTree (const char *name, const char *title, Int_t splitlevel=99, TDirectory *dir=(::ROOT::Internal::TDirectoryAtomicAdapter{}))
 Normal tree constructor.
 
 TTree (const TTree &tt)=delete
 
virtual ~TTree ()
 Destructor.
 
void AddAllocationCount (UInt_t count)
 
virtual Int_t AddBranchToCache (const char *bname, Bool_t subbranches=kFALSE)
 Add branch with name bname to the Tree cache.
 
virtual Int_t AddBranchToCache (TBranch *branch, Bool_t subbranches=kFALSE)
 Add branch b to the Tree cache.
 
void AddClone (TTree *)
 Add a cloned tree to our list of trees to be notified whenever we change our branch addresses or when we are deleted.
 
virtual TFriendElementAddFriend (const char *treename, const char *filename="")
 Add a TFriendElement to the list of friends.
 
virtual TFriendElementAddFriend (const char *treename, TFile *file)
 Add a TFriendElement to the list of friends.
 
virtual TFriendElementAddFriend (TTree *tree, const char *alias="", Bool_t warn=kFALSE)
 Add a TFriendElement to the list of friends.
 
virtual void AddTotBytes (Int_t tot)
 
virtual void AddZipBytes (Int_t zip)
 
virtual Long64_t AutoSave (Option_t *option="")
 AutoSave tree header every fAutoSave bytes.
 
virtual Int_t Branch (const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
 Create one branch for each element in the folder.
 
TBranchBranch (const char *name, char *address, const char *leaflist, Int_t bufsize=32000)
 
template<class T >
TBranchBranch (const char *name, const char *classname, T **addobj, Int_t bufsize=32000, Int_t splitlevel=99)
 
template<class T >
TBranchBranch (const char *name, const char *classname, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
 
virtual TBranchBranch (const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=99)
 Create a new branch with the object of class classname at address addobj.
 
TBranchBranch (const char *name, int address, const char *leaflist, Int_t bufsize=32000)
 
TBranchBranch (const char *name, Longptr_t address, const char *leaflist, Int_t bufsize=32000)
 
template<typename T , std::size_t N>
TBranchBranch (const char *name, std::array< T, N > *obj, Int_t bufsize=32000, Int_t splitlevel=99)
 
template<class T >
TBranchBranch (const char *name, T **addobj, Int_t bufsize=32000, Int_t splitlevel=99)
 Add a new branch, and infer the data type from the array addobj being passed.
 
template<class T >
TBranchBranch (const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
 Add a new branch, and infer the data type from the type of obj being passed.
 
virtual TBranchBranch (const char *name, void *address, const char *leaflist, Int_t bufsize=32000)
 Create a new TTree Branch.
 
virtual Int_t Branch (TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
 Create one branch for each element in the collection.
 
virtual Int_t Branch (TList *list, Int_t bufsize=32000, Int_t splitlevel=99)
 Deprecated function. Use next function instead.
 
virtual TBranchBranchOld (const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=1)
 Create a new TTree BranchObject.
 
virtual TBranchBranchRef ()
 Build the optional branch supporting the TRefTable.
 
virtual TBranchBronch (const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=99)
 Create a new TTree BranchElement.
 
void Browse (TBrowser *) override
 Browse content of the TTree.
 
virtual Int_t BuildIndex (const char *majorname, const char *minorname="0")
 Build a Tree Index (default is TTreeIndex).
 
TStreamerInfoBuildStreamerInfo (TClass *cl, void *pointer=nullptr, Bool_t canOptimize=kTRUE)
 Build StreamerInfo for class cl.
 
virtual TFileChangeFile (TFile *file)
 Called by TTree::Fill() when file has reached its maximum fgMaxTreeSize.
 
virtual TTreeCloneTree (Long64_t nentries=-1, Option_t *option="")
 Create a clone of this tree and copy nentries.
 
virtual void CopyAddresses (TTree *, Bool_t undo=kFALSE)
 Set branch addresses of passed tree equal to ours.
 
virtual Long64_t CopyEntries (TTree *tree, Long64_t nentries=-1, Option_t *option="", Bool_t needCopyAddresses=false)
 Copy nentries from given tree to this tree.
 
virtual TTreeCopyTree (const char *selection, Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Copy a tree with selection.
 
virtual TBasketCreateBasket (TBranch *)
 Create a basket for this tree and given branch.
 
Int_t Debug () const
 
void Delete (Option_t *option="") override
 Delete this tree from memory or/and disk.
 
virtual void DirectoryAutoAdd (TDirectory *)
 Called by TKey and TObject::Clone to automatically add us to a directory when we are read from a file.
 
virtual Long64_t Draw (const char *varexp, const char *selection, Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Draw expression varexp for entries and objects that pass a (optional) selection.
 
virtual Long64_t Draw (const char *varexp, const TCut &selection, Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Draw expression varexp for specified entries.
 
void Draw (Option_t *opt) override
 Default Draw method for all objects.
 
virtual void DropBaskets ()
 Remove some baskets from memory.
 
virtual Int_t DropBranchFromCache (const char *bname, Bool_t subbranches=kFALSE)
 Remove the branch with name 'bname' from the Tree cache.
 
virtual Int_t DropBranchFromCache (TBranch *branch, Bool_t subbranches=kFALSE)
 Remove the branch b from the Tree cache.
 
virtual void DropBuffers (Int_t nbytes)
 Drop branch buffers to accommodate nbytes below MaxVirtualsize.
 
Bool_t EnableCache ()
 Enable the TTreeCache unless explicitly disabled for this TTree by a prior call to SetCacheSize(0).
 
virtual Int_t Fill ()
 Fill all branches.
 
virtual TBranchFindBranch (const char *name)
 Return the branch that correspond to the path 'branchname', which can include the name of the tree or the omitted name of the parent branches.
 
virtual TLeafFindLeaf (const char *name)
 Find leaf..
 
virtual Int_t Fit (const char *funcname, const char *varexp, const char *selection="", Option_t *option="", Option_t *goption="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Fit a projected item(s) from a tree.
 
virtual Int_t FlushBaskets (Bool_t create_cluster=true) const
 Write to disk all the basket that have not yet been individually written and create an event cluster boundary (by default).
 
virtual const char * GetAlias (const char *aliasName) const
 Returns the expanded value of the alias. Search in the friends if any.
 
UInt_t GetAllocationCount () const
 
virtual Long64_t GetAutoFlush () const
 
virtual Long64_t GetAutoSave () const
 
virtual TBranchGetBranch (const char *name)
 Return pointer to the branch with the given name in this tree or its friends.
 
virtual TBranchRefGetBranchRef () const
 
virtual Bool_t GetBranchStatus (const char *branchname) const
 Return status of branch with name branchname.
 
virtual Long64_t GetCacheSize () const
 
virtual Long64_t GetChainEntryNumber (Long64_t entry) const
 
virtual Long64_t GetChainOffset () const
 
virtual TClusterIterator GetClusterIterator (Long64_t firstentry)
 Return an iterator over the cluster of baskets starting at firstentry.
 
virtual Bool_t GetClusterPrefetch () const
 
TFileGetCurrentFile () const
 Return pointer to the current file.
 
Long64_t GetDebugMax () const
 
Long64_t GetDebugMin () const
 
Int_t GetDefaultEntryOffsetLen () const
 
TDirectoryGetDirectory () const
 
virtual Long64_t GetEntries () const
 
virtual Long64_t GetEntries (const char *selection)
 Return the number of entries matching the selection.
 
virtual Long64_t GetEntriesFast () const
 
virtual Long64_t GetEntriesFriend () const
 Return pointer to the 1st Leaf named name in any Branch of this Tree or any branch in the list of friend trees.
 
virtual Int_t GetEntry (Long64_t entry, Int_t getall=0)
 Read all branches of entry and return total number of bytes read.
 
virtual TEntryListGetEntryList ()
 Returns the entry list assigned to this tree.
 
virtual Long64_t GetEntryNumber (Long64_t entry) const
 Return entry number corresponding to entry.
 
virtual Long64_t GetEntryNumberWithBestIndex (Long64_t major, Long64_t minor=0) const
 Return entry number corresponding to major and minor number.
 
virtual Long64_t GetEntryNumberWithIndex (Long64_t major, Long64_t minor=0) const
 Return entry number corresponding to major and minor number.
 
virtual Int_t GetEntryWithIndex (Int_t major, Int_t minor=0)
 Read entry corresponding to major and minor number.
 
virtual Long64_t GetEstimate () const
 
Int_t GetEvent (Long64_t entry, Int_t getall=0)
 
TEventListGetEventList () const
 
virtual Int_t GetFileNumber () const
 
virtual TTreeGetFriend (const char *) const
 Return a pointer to the TTree friend whose name or alias is friendname.
 
virtual const char * GetFriendAlias (TTree *) const
 If the 'tree' is a friend, this method returns its alias name.
 
TH1GetHistogram ()
 
virtual Bool_t GetImplicitMT ()
 
virtual Int_tGetIndex ()
 
virtual Double_tGetIndexValues ()
 
ROOT::TIOFeatures GetIOFeatures () const
 Returns the current set of IO settings.
 
virtual TIteratorGetIteratorOnAllLeaves (Bool_t dir=kIterForward)
 Creates a new iterator that will go through all the leaves on the tree itself and its friend.
 
virtual TLeafGetLeaf (const char *branchname, const char *leafname)
 Return pointer to the 1st Leaf named name in any Branch of this Tree or any branch in the list of friend trees.
 
virtual TLeafGetLeaf (const char *name)
 Return pointer to first leaf named "name" in any branch of this tree or its friend trees.
 
virtual TListGetListOfAliases () const
 
virtual TObjArrayGetListOfBranches ()
 
virtual TListGetListOfClones ()
 
virtual TListGetListOfFriends () const
 
virtual TObjArrayGetListOfLeaves ()
 
Int_t GetMakeClass () const
 
virtual Long64_t GetMaxEntryLoop () const
 
virtual Double_t GetMaximum (const char *columname)
 Return maximum of column with name columname.
 
virtual Long64_t GetMaxVirtualSize () const
 
virtual Double_t GetMinimum (const char *columname)
 Return minimum of column with name columname.
 
virtual Int_t GetNbranches ()
 
TObjectGetNotify () const
 
virtual Int_t GetPacketSize () const
 
virtual TVirtualPerfStatsGetPerfStats () const
 
TVirtualTreePlayerGetPlayer ()
 Load the TTreePlayer (if not already done).
 
TTreeCacheGetReadCache (TFile *file) const
 Find and return the TTreeCache registered with the file and which may contain branches for us.
 
TTreeCacheGetReadCache (TFile *file, Bool_t create)
 Find and return the TTreeCache registered with the file and which may contain branches for us.
 
virtual Long64_t GetReadEntry () const
 
virtual Long64_t GetReadEvent () const
 
virtual Int_t GetScanField () const
 
TTreeFormulaGetSelect ()
 
virtual Long64_t GetSelectedRows ()
 
Float_t GetTargetMemoryRatio () const
 
virtual Int_t GetTimerInterval () const
 
virtual Long64_t GetTotBytes () const
 
TBufferGetTransientBuffer (Int_t size)
 Returns the transient buffer currently used by this TTree for reading/writing baskets.
 
virtual TTreeGetTree () const
 
virtual TVirtualIndexGetTreeIndex () const
 
virtual Int_t GetTreeNumber () const
 
virtual Int_t GetUpdate () const
 
virtual TListGetUserInfo ()
 Return a pointer to the list containing user objects associated to this tree.
 
virtual Double_tGetV1 ()
 
virtual Double_tGetV2 ()
 
virtual Double_tGetV3 ()
 
virtual Double_tGetV4 ()
 
virtual Double_tGetVal (Int_t i)
 
TTreeFormulaGetVar (Int_t i)
 
TTreeFormulaGetVar1 ()
 
TTreeFormulaGetVar2 ()
 
TTreeFormulaGetVar3 ()
 
TTreeFormulaGetVar4 ()
 
virtual Double_tGetW ()
 
virtual Double_t GetWeight () const
 
virtual Long64_t GetZipBytes () const
 
virtual void IncrementTotalBuffers (Int_t nbytes)
 
virtual Bool_t InPlaceClone (TDirectory *newdirectory, const char *options="")
 Copy the content to a new new file, update this TTree with the new location information and attach this TTree to the new directory.
 
TClassIsA () const override
 
Bool_t IsFolder () const override
 Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
 
virtual Int_t LoadBaskets (Long64_t maxmemory=2000000000)
 Read in memory all baskets from all branches up to the limit of maxmemory bytes.
 
virtual Long64_t LoadTree (Long64_t entry)
 Set current entry.
 
virtual Long64_t LoadTreeFriend (Long64_t entry, TTree *T)
 Load entry on behalf of our master tree, we may use an index.
 
virtual Int_t MakeClass (const char *classname=nullptr, Option_t *option="")
 Generate a skeleton analysis class for this tree.
 
virtual Int_t MakeCode (const char *filename=nullptr)
 Generate a skeleton function for this tree.
 
virtual Int_t MakeProxy (const char *classname, const char *macrofilename=nullptr, const char *cutfilename=nullptr, const char *option=nullptr, Int_t maxUnrolling=3)
 Generate a skeleton analysis class for this Tree using TBranchProxy.
 
virtual Int_t MakeSelector (const char *selector=nullptr, Option_t *option="")
 Generate skeleton selector class for this tree.
 
Bool_t MemoryFull (Int_t nbytes)
 Check if adding nbytes to memory we are still below MaxVirtualsize.
 
virtual Long64_t Merge (TCollection *list, Option_t *option="")
 Merge the trees in the TList into this tree.
 
virtual Long64_t Merge (TCollection *list, TFileMergeInfo *info)
 Merge the trees in the TList into this tree.
 
Bool_t Notify () override
 Function called when loading a new class library.
 
TTreeoperator= (const TTree &tt)=delete
 
virtual void OptimizeBaskets (ULong64_t maxMemory=10000000, Float_t minComp=1.1, Option_t *option="")
 This function may be called after having filled some entries in a Tree.
 
TPrincipalPrincipal (const char *varexp="", const char *selection="", Option_t *option="np", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Interface to the Principal Components Analysis class.
 
void Print (Option_t *option="") const override
 Print a summary of the tree contents.
 
virtual void PrintCacheStats (Option_t *option="") const
 Print statistics about the TreeCache for this tree.
 
virtual Long64_t Process (const char *filename, Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Process this tree executing the TSelector code in the specified filename.
 
virtual Long64_t Process (TSelector *selector, Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Process this tree executing the code in the specified selector.
 
virtual Long64_t Project (const char *hname, const char *varexp, const char *selection="", Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Make a projection of a tree using selections.
 
virtual TSQLResultQuery (const char *varexp="", const char *selection="", Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Loop over entries and return a TSQLResult object containing entries following selection.
 
virtual Long64_t ReadFile (const char *filename, const char *branchDescriptor="", char delimiter=' ')
 Create or simply read branches from filename.
 
virtual Long64_t ReadStream (std::istream &inputStream, const char *branchDescriptor="", char delimiter=' ')
 Create or simply read branches from an input stream.
 
void RecursiveRemove (TObject *obj) override
 Make sure that obj (which is being deleted or will soon be) is no longer referenced by this TTree.
 
virtual void Refresh ()
 Refresh contents of this tree and its branches from the current status on disk.
 
virtual void RegisterExternalFriend (TFriendElement *)
 Record a TFriendElement that we need to warn when the chain switches to a new file (typically this is because this chain is a friend of another TChain)
 
virtual void RemoveExternalFriend (TFriendElement *)
 Removes external friend.
 
virtual void RemoveFriend (TTree *)
 Remove a friend from the list of friends.
 
virtual void Reset (Option_t *option="")
 Reset baskets, buffers and entries count in all branches and leaves.
 
virtual void ResetAfterMerge (TFileMergeInfo *)
 Resets the state of this TTree after a merge (keep the customization but forget the data).
 
virtual void ResetBranchAddress (TBranch *)
 Tell all of our branches to set their addresses to zero.
 
virtual void ResetBranchAddresses ()
 Tell all of our branches to drop their current objects and allocate new ones.
 
virtual Long64_t Scan (const char *varexp="", const char *selection="", Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Loop over tree entries and print entries passing selection.
 
virtual Bool_t SetAlias (const char *aliasName, const char *aliasFormula)
 Set a tree variable alias.
 
virtual void SetAutoFlush (Long64_t autof=-30000000)
 This function may be called at the start of a program to change the default value for fAutoFlush.
 
virtual void SetAutoSave (Long64_t autos=-300000000)
 In case of a program crash, it will be possible to recover the data in the tree up to the last AutoSave point.
 
virtual void SetBasketSize (const char *bname, Int_t buffsize=16000)
 Set a branch's basket size.
 
template<class T >
Int_t SetBranchAddress (const char *bname, T **add, TBranch **ptr=nullptr)
 
template<class T >
Int_t SetBranchAddress (const char *bname, T *add, TBranch **ptr=nullptr)
 
virtual Int_t SetBranchAddress (const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, Bool_t isptr)
 Verify the validity of the type of addr before calling SetBranchAddress.
 
virtual Int_t SetBranchAddress (const char *bname, void *add, TBranch **ptr=nullptr)
 Change branch address, dealing with clone trees properly.
 
virtual Int_t SetBranchAddress (const char *bname, void *add, TClass *realClass, EDataType datatype, Bool_t isptr)
 Verify the validity of the type of addr before calling SetBranchAddress.
 
virtual void SetBranchStatus (const char *bname, Bool_t status=1, UInt_t *found=nullptr)
 Set branch status to Process or DoNotProcess.
 
virtual Int_t SetCacheEntryRange (Long64_t first, Long64_t last)
 interface to TTreeCache to set the cache entry range
 
virtual void SetCacheLearnEntries (Int_t n=10)
 Interface to TTreeCache to set the number of entries for the learning phase.
 
virtual Int_t SetCacheSize (Long64_t cachesize=-1)
 Set maximum size of the file cache .
 
virtual void SetChainOffset (Long64_t offset=0)
 
virtual void SetCircular (Long64_t maxEntries)
 Enable/Disable circularity for this tree.
 
virtual void SetClusterPrefetch (Bool_t enabled)
 
virtual void SetDebug (Int_t level=1, Long64_t min=0, Long64_t max=9999999)
 Set the debug level and the debug range.
 
virtual void SetDefaultEntryOffsetLen (Int_t newdefault, Bool_t updateExisting=kFALSE)
 Update the default value for the branch's fEntryOffsetLen.
 
virtual void SetDirectory (TDirectory *dir)
 Change the tree's directory.
 
virtual Long64_t SetEntries (Long64_t n=-1)
 Change number of entries in the tree.
 
virtual void SetEntryList (TEntryList *list, Option_t *opt="")
 Set an EntryList.
 
virtual void SetEstimate (Long64_t nentries=1000000)
 Set number of entries to estimate variable limits.
 
virtual void SetEventList (TEventList *list)
 This function transfroms the given TEventList into a TEntryList The new TEntryList is owned by the TTree and gets deleted when the tree is deleted.
 
virtual void SetFileNumber (Int_t number=0)
 Set fFileNumber to number.
 
virtual void SetImplicitMT (Bool_t enabled)
 
ROOT::TIOFeatures SetIOFeatures (const ROOT::TIOFeatures &)
 Provide the end-user with the ability to enable/disable various experimental IO features for this TTree.
 
virtual void SetMakeClass (Int_t make)
 Set all the branches in this TTree to be in decomposed object mode (also known as MakeClass mode).
 
virtual void SetMaxEntryLoop (Long64_t maxev=kMaxEntries)
 
virtual void SetMaxVirtualSize (Long64_t size=0)
 
void SetName (const char *name) override
 Change the name of this tree.
 
virtual void SetNotify (TObject *obj)
 Sets the address of the object to be notified when the tree is loaded.
 
virtual void SetObject (const char *name, const char *title)
 Change the name and title of this tree.
 
virtual void SetParallelUnzip (Bool_t opt=kTRUE, Float_t RelSize=-1)
 Enable or disable parallel unzipping of Tree buffers.
 
virtual void SetPerfStats (TVirtualPerfStats *perf)
 Set perf stats.
 
virtual void SetScanField (Int_t n=50)
 
void SetTargetMemoryRatio (Float_t ratio)
 
virtual void SetTimerInterval (Int_t msec=333)
 
virtual void SetTreeIndex (TVirtualIndex *index)
 The current TreeIndex is replaced by the new index.
 
virtual void SetUpdate (Int_t freq=0)
 
virtual void SetWeight (Double_t w=1, Option_t *option="")
 Set tree weight.
 
virtual void Show (Long64_t entry=-1, Int_t lenmax=20)
 Print values of all active leaves for entry.
 
virtual void StartViewer ()
 Start the TTreeViewer on this tree.
 
virtual Int_t StopCacheLearningPhase ()
 Stop the cache learning phase.
 
void Streamer (TBuffer &) override
 Stream a class object.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
virtual Int_t UnbinnedFit (const char *funcname, const char *varexp, const char *selection="", Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
 Unbinned fit of one or more variable(s) from a tree.
 
void UseCurrentStyle () override
 Replace current attributes by current style.
 
Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
 Write this object to the current directory.
 
Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
 Write this object to the current directory.
 
- Public Member Functions inherited from TNamed
 TNamed ()
 
 TNamed (const char *name, const char *title)
 
 TNamed (const TNamed &named)
 TNamed copy ctor.
 
 TNamed (const TString &name, const TString &title)
 
virtual ~TNamed ()
 TNamed destructor.
 
void Clear (Option_t *option="") override
 Set name and title to empty strings ("").
 
TObjectClone (const char *newname="") const override
 Make a clone of an object using the Streamer facility.
 
Int_t Compare (const TObject *obj) const override
 Compare two TNamed objects.
 
void Copy (TObject &named) const override
 Copy this to obj.
 
virtual void FillBuffer (char *&buffer)
 Encode TNamed into output buffer.
 
const char * GetName () const override
 Returns name of object.
 
const char * GetTitle () const override
 Returns title of object.
 
ULong_t Hash () const override
 Return hash value for this object.
 
Bool_t IsSortable () const override
 
void ls (Option_t *option="") const override
 List TNamed name and title.
 
TNamedoperator= (const TNamed &rhs)
 TNamed assignment operator.
 
virtual void SetNameTitle (const char *name, const char *title)
 Set all the TNamed parameters (name and title).
 
virtual void SetTitle (const char *title="")
 Set the title of the TNamed.
 
virtual Int_t Sizeof () const
 Return size of the TNamed part of the TObject.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TObject
 TObject ()
 TObject constructor.
 
 TObject (const TObject &object)
 TObject copy ctor.
 
virtual ~TObject ()
 TObject destructor.
 
void AbstractMethod (const char *method) const
 Use this method to implement an "abstract" method that you don't want to leave purely abstract.
 
virtual void AppendPad (Option_t *option="")
 Append graphics object to current pad.
 
ULong_t CheckedHash ()
 Check and record whether this class has a consistent Hash/RecursiveRemove setup (*) and then return the regular Hash value for this object.
 
virtual const char * ClassName () const
 Returns name of class to which the object belongs.
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 Computes distance from point (px,py) to the object.
 
virtual void DrawClass () const
 Draw class inheritance tree of the class to which this object belongs.
 
virtual TObjectDrawClone (Option_t *option="") const
 Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
 
virtual void Dump () const
 Dump contents of object on stdout.
 
virtual void Error (const char *method, const char *msgfmt,...) const
 Issue error message.
 
virtual void Execute (const char *method, const char *params, Int_t *error=nullptr)
 Execute method on this object with the given parameter string, e.g.
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=nullptr)
 Execute method on this object with parameters stored in the TObjArray.
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 Execute action corresponding to an event at (px,py).
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 Issue fatal error message.
 
virtual TObjectFindObject (const char *name) const
 Must be redefined in derived classes.
 
virtual TObjectFindObject (const TObject *obj) const
 Must be redefined in derived classes.
 
virtual Option_tGetDrawOption () const
 Get option used by the graphics system to draw this object.
 
virtual const char * GetIconName () const
 Returns mime type name of object.
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 Returns string containing info about the object at position (px,py).
 
virtual Option_tGetOption () const
 
virtual UInt_t GetUniqueID () const
 Return the unique object id.
 
virtual Bool_t HandleTimer (TTimer *timer)
 Execute action in response of a timer timing out.
 
Bool_t HasInconsistentHash () const
 Return true is the type of this object is known to have an inconsistent setup for Hash and RecursiveRemove (i.e.
 
virtual void Info (const char *method, const char *msgfmt,...) const
 Issue info message.
 
virtual Bool_t InheritsFrom (const char *classname) const
 Returns kTRUE if object inherits from class "classname".
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 Returns kTRUE if object inherits from TClass cl.
 
virtual void Inspect () const
 Dump contents of this object in a graphics canvas.
 
void InvertBit (UInt_t f)
 
Bool_t IsDestructed () const
 IsDestructed.
 
virtual Bool_t IsEqual (const TObject *obj) const
 Default equal comparison (objects are equal if they have the same address in memory).
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
void MayNotUse (const char *method) const
 Use this method to signal that a method (defined in a base class) may not be called in a derived class (in principle against good design since a child class should not provide less functionality than its parent, however, sometimes it is necessary).
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 Use this method to declare a method obsolete.
 
void operator delete (void *ptr)
 Operator delete.
 
void operator delete[] (void *ptr)
 Operator delete [].
 
void * operator new (size_t sz)
 
void * operator new (size_t sz, void *vp)
 
void * operator new[] (size_t sz)
 
void * operator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 TObject assignment operator.
 
virtual void Paint (Option_t *option="")
 This method must be overridden if a class wants to paint itself.
 
virtual void Pop ()
 Pop on object drawn in a pad to the top of the display list.
 
virtual Int_t Read (const char *name)
 Read contents of object with specified name from the current directory.
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 Save this object in the file specified by filename.
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 Save a primitive as a C++ statement(s) on output stream "out".
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 Set or unset the user status bits as specified in f.
 
virtual void SetDrawOption (Option_t *option="")
 Set drawing option for object.
 
virtual void SetUniqueID (UInt_t uid)
 Set the unique object id.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 Issue system error message.
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 Issue warning message.
 
- Public Member Functions inherited from TAttLine
 TAttLine ()
 AttLine default constructor.
 
 TAttLine (Color_t lcolor, Style_t lstyle, Width_t lwidth)
 AttLine normal constructor.
 
virtual ~TAttLine ()
 AttLine destructor.
 
void Copy (TAttLine &attline) const
 Copy this line attributes to a new TAttLine.
 
Int_t DistancetoLine (Int_t px, Int_t py, Double_t xp1, Double_t yp1, Double_t xp2, Double_t yp2)
 Compute distance from point px,py to a line.
 
virtual Color_t GetLineColor () const
 Return the line color.
 
virtual Style_t GetLineStyle () const
 Return the line style.
 
virtual Width_t GetLineWidth () const
 Return the line width.
 
virtual void Modify ()
 Change current line attributes if necessary.
 
virtual void ResetAttLine (Option_t *option="")
 Reset this line attributes to default values.
 
virtual void SaveLineAttributes (std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
 Save line attributes as C++ statement(s) on output stream out.
 
virtual void SetLineAttributes ()
 Invoke the DialogCanvas Line attributes.
 
virtual void SetLineColor (Color_t lcolor)
 Set the line color.
 
virtual void SetLineColorAlpha (Color_t lcolor, Float_t lalpha)
 Set a transparent line color.
 
virtual void SetLineStyle (Style_t lstyle)
 Set the line style.
 
virtual void SetLineWidth (Width_t lwidth)
 Set the line width.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TAttFill
 TAttFill ()
 AttFill default constructor.
 
 TAttFill (Color_t fcolor, Style_t fstyle)
 AttFill normal constructor.
 
virtual ~TAttFill ()
 AttFill destructor.
 
void Copy (TAttFill &attfill) const
 Copy this fill attributes to a new TAttFill.
 
virtual Color_t GetFillColor () const
 Return the fill area color.
 
virtual Style_t GetFillStyle () const
 Return the fill area style.
 
virtual Bool_t IsTransparent () const
 
virtual void Modify ()
 Change current fill area attributes if necessary.
 
virtual void ResetAttFill (Option_t *option="")
 Reset this fill attributes to default values.
 
virtual void SaveFillAttributes (std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
 Save fill attributes as C++ statement(s) on output stream out.
 
virtual void SetFillAttributes ()
 Invoke the DialogCanvas Fill attributes.
 
virtual void SetFillColor (Color_t fcolor)
 Set the fill area color.
 
virtual void SetFillColorAlpha (Color_t fcolor, Float_t falpha)
 Set a transparent fill color.
 
virtual void SetFillStyle (Style_t fstyle)
 Set the fill area style.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TAttMarker
 TAttMarker ()
 TAttMarker default constructor.
 
 TAttMarker (Color_t color, Style_t style, Size_t msize)
 TAttMarker normal constructor.
 
virtual ~TAttMarker ()
 TAttMarker destructor.
 
void Copy (TAttMarker &attmarker) const
 Copy this marker attributes to a new TAttMarker.
 
virtual Color_t GetMarkerColor () const
 Return the marker color.
 
virtual Size_t GetMarkerSize () const
 Return the marker size.
 
virtual Style_t GetMarkerStyle () const
 Return the marker style.
 
virtual void Modify ()
 Change current marker attributes if necessary.
 
virtual void ResetAttMarker (Option_t *toption="")
 Reset this marker attributes to the default values.
 
virtual void SaveMarkerAttributes (std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
 Save line attributes as C++ statement(s) on output stream out.
 
virtual void SetMarkerAttributes ()
 Invoke the DialogCanvas Marker attributes.
 
virtual void SetMarkerColor (Color_t mcolor=1)
 Set the marker color.
 
virtual void SetMarkerColorAlpha (Color_t mcolor, Float_t malpha)
 Set a transparent marker color.
 
virtual void SetMarkerSize (Size_t msize=1)
 Set the marker size.
 
virtual void SetMarkerStyle (Style_t mstyle=1)
 Set the marker style.
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 

Static Public Member Functions

static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static Int_t GetBranchStyle ()
 Static function returning the current branch style.
 
static Long64_t GetMaxTreeSize ()
 Static function which returns the tree file size limit in bytes.
 
static TTreeMergeTrees (TList *list, Option_t *option="")
 Static function merging the trees in the TList into a new tree.
 
static void SetBranchStyle (Int_t style=1)
 Set the current branch style.
 
static void SetMaxTreeSize (Long64_t maxsize=100000000000LL)
 Set the maximum size in bytes of a Tree file (static function).
 
- Static Public Member Functions inherited from TNamed
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TObject
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static Longptr_t GetDtorOnly ()
 Return destructor only flag.
 
static Bool_t GetObjectStat ()
 Get status of object stat flag.
 
static void SetDtorOnly (void *obj)
 Set destructor only flag.
 
static void SetObjectStat (Bool_t stat)
 Turn on/off tracking of objects in the TObjectTable.
 
- Static Public Member Functions inherited from TAttLine
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TAttFill
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TAttMarker
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static Width_t GetMarkerLineWidth (Style_t style)
 Internal helper function that returns the line width of the given marker style (0 = filled marker)
 
static Style_t GetMarkerStyleBase (Style_t style)
 Internal helper function that returns the corresponding marker style with line width 1 for the given style.
 

Static Public Attributes

static constexpr Long64_t kMaxEntries = TVirtualTreePlayer::kMaxEntries
 

Protected Types

enum  ELockStatusBits {
  kFindBranch = (1ULL << ( 0 )) , kFindLeaf = (1ULL << ( 1 )) , kGetAlias = (1ULL << ( 2 )) , kGetBranch = (1ULL << ( 3 )) ,
  kGetEntry = (1ULL << ( 4 )) , kGetEntryWithIndex = (1ULL << ( 5 )) , kGetFriend = (1ULL << ( 6 )) , kGetFriendAlias = (1ULL << ( 7 )) ,
  kGetLeaf = (1ULL << ( 8 )) , kLoadTree = (1ULL << ( 9 )) , kPrint = (1ULL << ( 10 )) , kRemoveFriend = (1ULL << ( 11 )) ,
  kSetBranchStatus = (1ULL << ( 12 ))
}
 
- Protected Types inherited from TObject
enum  { kOnlyPrepStep = (1ULL << ( 3 )) }
 

Protected Member Functions

virtual TBranchBranchImp (const char *branchname, const char *classname, TClass *ptrClass, void *addobj, Int_t bufsize, Int_t splitlevel)
 Same as TTree::Branch() with added check that addobj matches className.
 
virtual TBranchBranchImp (const char *branchname, TClass *ptrClass, void *addobj, Int_t bufsize, Int_t splitlevel)
 Same as TTree::Branch but automatic detection of the class name.
 
virtual TBranchBranchImpArr (const char *branchname, EDataType datatype, std::size_t N, void *addobj, Int_t bufsize, Int_t splitlevel)
 
virtual TBranchBranchImpRef (const char *branchname, const char *classname, TClass *ptrClass, void *addobj, Int_t bufsize, Int_t splitlevel)
 Same as TTree::Branch but automatic detection of the class name.
 
virtual TBranchBranchImpRef (const char *branchname, TClass *ptrClass, EDataType datatype, void *addobj, Int_t bufsize, Int_t splitlevel)
 Same as TTree::Branch but automatic detection of the class name.
 
virtual TBranchBronchExec (const char *name, const char *classname, void *addobj, Bool_t isptrptr, Int_t bufsize, Int_t splitlevel)
 Helper function implementing TTree::Bronch and TTree::Branch(const char *name, T &obj);.
 
virtual Int_t CheckBranchAddressType (TBranch *branch, TClass *ptrClass, EDataType datatype, Bool_t ptr)
 Check whether or not the address described by the last 3 parameters matches the content of the branch.
 
Long64_t GetCacheAutoSize (Bool_t withDefault=kFALSE)
 Used for automatic sizing of the cache.
 
virtual TLeafGetLeafImpl (const char *branchname, const char *leafname)
 Return pointer to the 1st Leaf named name in any Branch of this Tree or any branch in the list of friend trees.
 
char GetNewlineValue (std::istream &inputStream)
 Determine which newline this file is using.
 
void ImportClusterRanges (TTree *fromtree)
 Appends the cluster range information stored in 'fromtree' to this tree, including the value of fAutoFlush.
 
virtual void KeepCircular ()
 Keep a maximum of fMaxEntries in memory.
 
void MoveReadCache (TFile *src, TDirectory *dir)
 Move a cache from a file to the current file in dir.
 
Int_t SetBranchAddressImp (TBranch *branch, void *addr, TBranch **ptr)
 Change branch address, dealing with clone trees properly.
 
Int_t SetCacheSizeAux (Bool_t autocache=kTRUE, Long64_t cacheSize=0)
 Set the size of the file cache and create it if possible.
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 Interface to ErrorHandler (protected).
 
void MakeZombie ()
 

Protected Attributes

TListfAliases
 List of aliases for expressions based on the tree branches.
 
std::atomic< UInt_tfAllocationCount {0}
 indicates basket should be resized to exact memory usage, but causes significant
 
Long64_t fAutoFlush
 Auto-flush tree when fAutoFlush entries written or -fAutoFlush (compressed) bytes produced.
 
Long64_t fAutoSave
 Autosave tree when fAutoSave entries written or -fAutoSave (compressed) bytes produced.
 
TObjArray fBranches
 List of Branches.
 
TBranchReffBranchRef
 Branch supporting the TRefTable (if any)
 
Bool_t fCacheDoAutoInit
 ! true if cache auto creation or resize check is needed
 
Bool_t fCacheDoClusterPrefetch
 ! true if cache is prefetching whole clusters
 
Long64_t fCacheSize
 ! Maximum size of file buffers
 
Bool_t fCacheUserSet
 ! true if the cache setting was explicitly given by user
 
Long64_t fChainOffset
 ! Offset of 1st entry of this Tree in a TChain
 
TListfClones
 ! List of cloned trees which share our addresses
 
Long64_tfClusterRangeEnd
 [fNClusterRange] Last entry of a cluster range.
 
Long64_tfClusterSize
 [fNClusterRange] Number of entries in each cluster for a given range.
 
Int_t fDebug
 ! Debug level
 
Long64_t fDebugMax
 ! Last entry number to debug
 
Long64_t fDebugMin
 ! First entry number to debug
 
Int_t fDefaultEntryOffsetLen
 Initial Length of fEntryOffset table in the basket buffers.
 
TDirectoryfDirectory
 ! Pointer to directory holding this tree
 
Long64_t fEntries
 Number of entries.
 
TEntryListfEntryList
 ! Pointer to event selection list (if one)
 
Long64_t fEstimate
 Number of entries to estimate histogram limits.
 
TEventListfEventList
 ! Pointer to event selection list (if one)
 
TListfExternalFriends
 ! List of TFriendsElement pointing to us and need to be notified of LoadTree. Content not owned.
 
Int_t fFileNumber
 ! current file number (if file extensions)
 
Long64_t fFlushedBytes
 Number of auto-flushed bytes.
 
UInt_t fFriendLockStatus
 ! Record which method is locking the friend recursion
 
TListfFriends
 pointer to list of friend elements
 
Bool_t fIMTEnabled
 ! true if implicit multi-threading is enabled for this tree
 
TArrayI fIndex
 Index of sorted values.
 
TArrayD fIndexValues
 Sorted index values.
 
TIOFeatures fIOFeatures {0}
 IO features to define for newly-written baskets and branches.
 
TObjArray fLeaves
 Direct pointers to individual branch leaves.
 
Int_t fMakeClass
 ! not zero when processing code generated by MakeClass
 
Int_t fMaxClusterRange
 ! Memory allocated for the cluster range.
 
Long64_t fMaxEntries
 Maximum number of entries in case of circular buffers.
 
Long64_t fMaxEntryLoop
 Maximum number of entries to process.
 
Long64_t fMaxVirtualSize
 Maximum total size of buffers kept in memory.
 
Int_t fNClusterRange
 Number of Cluster range in addition to the one defined by 'AutoFlush'.
 
UInt_t fNEntriesSinceSorting
 ! Number of entries processed since the last re-sorting of branches
 
Int_t fNfill
 ! Local for EntryLoop
 
TObjectfNotify
 ! Object to be notified when loading a Tree
 
Int_t fPacketSize
 ! Number of entries in one packet for parallel root
 
TVirtualPerfStatsfPerfStats
 ! pointer to the current perf stats object
 
TVirtualTreePlayerfPlayer
 ! Pointer to current Tree player
 
Long64_t fReadEntry
 ! Number of the entry being processed
 
Long64_t fSavedBytes
 Number of autosaved bytes.
 
Int_t fScanField
 Number of runs before prompting in Scan.
 
std::vector< TBranch * > fSeqBranches
 ! Branches to be processed sequentially when IMT is on
 
std::vector< std::pair< Long64_t, TBranch * > > fSortedBranches
 ! Branches to be processed in parallel when IMT is on, sorted by average task time
 
Float_t fTargetMemoryRatio {1.1f}
 ! Ratio for memory usage in uncompressed buffers versus actual occupancy.
 
Int_t fTimerInterval
 Timer interval in milliseconds.
 
std::atomic< Long64_tfTotalBuffers
 ! Total number of bytes in branch buffers
 
Long64_t fTotBytes
 Total number of bytes in all branches before compression.
 
TBufferfTransientBuffer
 ! Pointer to the current transient buffer.
 
TVirtualIndexfTreeIndex
 Pointer to the tree Index (if any)
 
Int_t fUpdate
 Update frequency for EntryLoop.
 
TListfUserInfo
 pointer to a list of user objects associated to this Tree
 
Double_t fWeight
 Tree weight (see TTree::SetWeight)
 
Long64_t fZipBytes
 Total number of bytes in all branches after compression.
 
- Protected Attributes inherited from TNamed
TString fName
 
TString fTitle
 
- Protected Attributes inherited from TAttLine
Color_t fLineColor
 Line color.
 
Style_t fLineStyle
 Line style.
 
Width_t fLineWidth
 Line width.
 
- Protected Attributes inherited from TAttFill
Color_t fFillColor
 Fill area color.
 
Style_t fFillStyle
 Fill area style.
 
- Protected Attributes inherited from TAttMarker
Color_t fMarkerColor
 Marker color.
 
Size_t fMarkerSize
 Marker size.
 
Style_t fMarkerStyle
 Marker style.
 

Static Protected Attributes

static Int_t fgBranchStyle = 1
 Old/New branch style.
 
static Long64_t fgMaxTreeSize = 100000000000LL
 Maximum size of a file containing a Tree.
 

Private Types

using TIOFeatures = ROOT::TIOFeatures
 

Private Member Functions

Int_t FlushBasketsImpl () const
 Internal implementation of the FlushBaskets algorithm.
 
Long64_t GetMedianClusterSize ()
 Estimate the median cluster size for the TTree.
 
void InitializeBranchLists (bool checkLeafCount)
 Divides the top-level branches into two vectors: (i) branches to be processed sequentially and (ii) branches to be processed in parallel.
 
void MarkEventCluster ()
 Mark the previous event as being at the end of the event cluster.
 
void SortBranchesByTime ()
 Sorts top-level branches by the last average task time recorded per branch.
 

Private Attributes

Bool_t fIMTFlush {false}
 ! True if we are doing a multithreaded flush.
 
std::atomic< Long64_tfIMTTotBytes
 ! Total bytes for the IMT flush baskets
 
std::atomic< Long64_tfIMTZipBytes
 ! Zip bytes for the IMT flush baskets.
 

Friends

class TChainIndex
 
class TFriendLock
 
TBranchTTreeBranchImpRef (TTree *tree, const char *branchname, TClass *ptrClass, EDataType datatype, void *addobj, Int_t bufsize, Int_t splitlevel)
 
class TTreeCloner
 
class TTreeIndex
 

#include <TTree.h>

Inheritance diagram for TTree:
[legend]

Member Typedef Documentation

◆ TIOFeatures

Definition at line 81 of file TTree.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSplitCollectionOfPointers 

Definition at line 262 of file TTree.h.

◆ ELockStatusBits

enum TTree::ELockStatusBits
protected
Enumerator
kFindBranch 
kFindLeaf 
kGetAlias 
kGetBranch 
kGetEntry 
kGetEntryWithIndex 
kGetFriend 
kGetFriendAlias 
kGetLeaf 
kLoadTree 
kPrint 
kRemoveFriend 
kSetBranchStatus 

Definition at line 208 of file TTree.h.

◆ ESetBranchAddressStatus

Enumerator
kMissingBranch 
kInternalError 
kMissingCompiledCollectionProxy 
kMismatch 
kClassMismatch 
kMatch 
kMatchConversion 
kMatchConversionCollection 
kMakeClass 
kVoidPtr 
kNoCheck 
kNeedEnableDecomposedObj 
kNeedDisableDecomposedObj 
kDecomposedObjMask 

Definition at line 229 of file TTree.h.

◆ EStatusBits

Enumerator
kForceRead 
kCircular 
kOnlyFlushAtCluster 

If set, the branch's buffers will grow until an event cluster boundary is hit, guaranteeing a basket per cluster.

This mode does not provide any guarantee on the memory bounds in the case of extremely large events.

kEntriesReshuffled 

If set, signals that this TTree is the output of the processing of another TTree, and the entries are reshuffled w.r.t.

to the original TTree. As a safety measure, a TTree with this bit set cannot add friends nor can be added as a friend. If you know what you are doing, you can manually unset this bit with ResetBit(EStatusBits::kEntriesReshuffled).

Definition at line 247 of file TTree.h.

Constructor & Destructor Documentation

◆ TTree() [1/3]

TTree::TTree ( )

Default constructor and I/O constructor.

Note: We do not insert ourself into the current directory.

Definition at line 736 of file TTree.cxx.

◆ TTree() [2/3]

TTree::TTree ( const char *  name,
const char *  title,
Int_t  splitlevel = 99,
TDirectory dir = (::ROOT::Internal::TDirectoryAtomicAdapter{}) 
)

Normal tree constructor.

The tree is created in the current directory. Use the various functions Branch below to add branches to this tree.

If the first character of title is a "/", the function assumes a folder name. In this case, it creates automatically branches following the folder hierarchy. splitlevel may be used in this case to control the split level.

Definition at line 816 of file TTree.cxx.

◆ ~TTree()

TTree::~TTree ( )
virtual

Destructor.

Definition at line 919 of file TTree.cxx.

◆ TTree() [3/3]

TTree::TTree ( const TTree tt)
delete

Member Function Documentation

◆ AddAllocationCount()

void TTree::AddAllocationCount ( UInt_t  count)
inline

Definition at line 334 of file TTree.h.

◆ AddBranchToCache() [1/2]

Int_t TTree::AddBranchToCache ( const char *  bname,
Bool_t  subbranches = kFALSE 
)
virtual

Add branch with name bname to the Tree cache.

If bname="*" all branches are added to the cache. if subbranches is true all the branches of the subbranches are also put to the cache.

Returns:

  • 0 branch added or already included
  • -1 on error

Definition at line 1058 of file TTree.cxx.

◆ AddBranchToCache() [2/2]

Int_t TTree::AddBranchToCache ( TBranch b,
Bool_t  subbranches = kFALSE 
)
virtual

Add branch b to the Tree cache.

if subbranches is true all the branches of the subbranches are also put to the cache.

Returns:

  • 0 branch added or already included
  • -1 on error

Definition at line 1097 of file TTree.cxx.

◆ AddClone()

void TTree::AddClone ( TTree clone)

Add a cloned tree to our list of trees to be notified whenever we change our branch addresses or when we are deleted.

Definition at line 1218 of file TTree.cxx.

◆ AddFriend() [1/3]

TFriendElement * TTree::AddFriend ( const char *  treename,
const char *  filename = "" 
)
virtual

Add a TFriendElement to the list of friends.

This function:

  • opens a file if filename is specified
  • reads a Tree with name treename from the file (current directory)
  • adds the Tree to the list of friends see other AddFriend functions

A TFriendElement TF describes a TTree object TF in a file. When a TFriendElement TF is added to the list of friends of an existing TTree T, any variable from TF can be referenced in a query to T.

A tree keeps a list of friends. In the context of a tree (or a chain), friendship means unrestricted access to the friends data. In this way it is much like adding another branch to the tree without taking the risk of damaging it. To add a friend to the list, you can use the TTree::AddFriend method. The tree in the diagram below has two friends (friend_tree1 and friend_tree2) and now has access to the variables a,b,c,i,j,k,l and m.

The AddFriend method has two parameters, the first is the tree name and the second is the name of the ROOT file where the friend tree is saved. AddFriend automatically opens the friend file. If no file name is given, the tree called ft1 is assumed to be in the same file as the original tree.

tree.AddFriend("ft1","friendfile1.root"); If the friend tree has the same name as the original tree, you can give it an alias in the context of the friendship:

tree.AddFriend("tree1 = tree","friendfile1.root"); Once the tree has friends, we can use TTree::Draw as if the friend's variables were in the original tree. To specify which tree to use in the Draw method, use the syntax:

<treeName>.<branchname>.<varname>

If the variablename is enough to uniquely identify the variable, you can leave out the tree and/or branch name. For example, these commands generate a 3-d scatter plot of variable "var" in the TTree tree versus variable v1 in TTree ft1 versus variable v2 in TTree ft2.

tree.AddFriend("ft1","friendfile1.root");
tree.AddFriend("ft2","friendfile2.root");
tree.Draw("var:ft1.v1:ft2.v2");

The picture illustrates the access of the tree and its friends with a Draw command. When AddFriend is called, the ROOT file is automatically opened and the friend tree (ft1) is read into memory. The new friend (ft1) is added to the list of friends of tree. The number of entries in the friend must be equal or greater to the number of entries of the original tree. If the friend tree has fewer entries a warning is given and the missing entries are not included in the histogram. To retrieve the list of friends from a tree use TTree::GetListOfFriends. When the tree is written to file (TTree::Write), the friends list is saved with it. And when the tree is retrieved, the trees on the friends list are also retrieved and the friendship restored. When a tree is deleted, the elements of the friend list are also deleted. It is possible to declare a friend tree that has the same internal structure (same branches and leaves) as the original tree, and compare the same values by specifying the tree.

tree.Draw("var:ft1.var:ft2.var")

Reimplemented in TChain.

Definition at line 1330 of file TTree.cxx.

◆ AddFriend() [2/3]

TFriendElement * TTree::AddFriend ( const char *  treename,
TFile file 
)
virtual

Add a TFriendElement to the list of friends.

The TFile is managed by the user (e.g. the user must delete the file). For complete description see AddFriend(const char *, const char *). This function:

  • reads a Tree with name treename from the file
  • adds the Tree to the list of friends

Reimplemented in TChain.

Definition at line 1364 of file TTree.cxx.

◆ AddFriend() [3/3]

TFriendElement * TTree::AddFriend ( TTree tree,
const char *  alias = "",
Bool_t  warn = kFALSE 
)
virtual

Add a TFriendElement to the list of friends.

The TTree is managed by the user (e.g., the user must delete the file). For a complete description see AddFriend(const char *, const char *).

Reimplemented in TChain.

Definition at line 1395 of file TTree.cxx.

◆ AddTotBytes()

virtual void TTree::AddTotBytes ( Int_t  tot)
inlinevirtual

Definition at line 328 of file TTree.h.

◆ AddZipBytes()

virtual void TTree::AddZipBytes ( Int_t  zip)
inlinevirtual

Definition at line 329 of file TTree.h.

◆ AutoSave()

Long64_t TTree::AutoSave ( Option_t option = "")
virtual

AutoSave tree header every fAutoSave bytes.

When large Trees are produced, it is safe to activate the AutoSave procedure. Some branches may have buffers holding many entries. If fAutoSave is negative, AutoSave is automatically called by TTree::Fill when the number of bytes generated since the previous AutoSave is greater than -fAutoSave bytes. If fAutoSave is positive, AutoSave is automatically called by TTree::Fill every N entries. This function may also be invoked by the user. Each AutoSave generates a new key on the file. Once the key with the tree header has been written, the previous cycle (if any) is deleted.

Note that calling TTree::AutoSave too frequently (or similarly calling TTree::SetAutoSave with a small value) is an expensive operation. You should make tests for your own application to find a compromise between speed and the quantity of information you may loose in case of a job crash.

In case your program crashes before closing the file holding this tree, the file will be automatically recovered when you will connect the file in UPDATE mode. The Tree will be recovered at the status corresponding to the last AutoSave.

if option contains "SaveSelf", gDirectory->SaveSelf() is called. This allows another process to analyze the Tree while the Tree is being filled.

if option contains "FlushBaskets", TTree::FlushBaskets is called and all the current basket are closed-out and written to disk individually.

By default the previous header is deleted after having written the new header. if option contains "Overwrite", the previous Tree header is deleted before written the new header. This option is slightly faster, but the default option is safer in case of a problem (disk quota exceeded) when writing the new header.

The function returns the number of bytes written to the file. if the number of bytes is null, an error has occurred while writing the header to the file.

How to write a Tree in one process and view it from another process

The following two scripts illustrate how to do this. The script treew.C is executed by process1, treer.C by process2

script treew.C:

void treew() {
TFile f("test.root","recreate");
TNtuple *ntuple = new TNtuple("ntuple","Demo","px:py:pz:random:i");
Float_t px, py, pz;
for ( Int_t i=0; i<10000000; i++) {
gRandom->Rannor(px,py);
pz = px*px + py*py;
Float_t random = gRandom->Rndm(1);
ntuple->Fill(px,py,pz,random,i);
if (i%1000 == 1) ntuple->AutoSave("SaveSelf");
}
}
A simple TTree restricted to a list of float variables only.
Definition TNtuple.h:28
Int_t Fill() override
Fill a Ntuple with current values in fArgs.
Definition TNtuple.cxx:169
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:552
virtual Long64_t AutoSave(Option_t *option="")
AutoSave tree header every fAutoSave bytes.
Definition TTree.cxx:1498

script treer.C:

void treer() {
TFile f("test.root");
TTree *ntuple = (TTree*)f.Get("ntuple");
Int_t first = 0;
while(1) {
if (first == 0) ntuple->Draw("px>>hpx", "","",10000000,first);
else ntuple->Draw("px>>+hpx","","",10000000,first);
first = (Int_t)ntuple->GetEntries();
c1.Update();
gSystem->Sleep(1000); //sleep 1 second
ntuple->Refresh();
}
}
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
The Canvas class.
Definition TCanvas.h:23
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:440
void Draw(Option_t *opt) override
Default Draw method for all objects.
Definition TTree.h:428
virtual Long64_t GetEntries() const
Definition TTree.h:460
virtual void Refresh()
Refresh contents of this tree and its branches from the current status on disk.
Definition TTree.cxx:7907
return c1
Definition legend1.C:41
Definition first.py:1

Definition at line 1498 of file TTree.cxx.

◆ Branch() [1/13]

Int_t TTree::Branch ( const char *  foldername,
Int_t  bufsize = 32000,
Int_t  splitlevel = 99 
)
virtual

Create one branch for each element in the folder.

Returns the total number of branches created.

Reimplemented in TTreeSQL.

Definition at line 1878 of file TTree.cxx.

◆ Branch() [2/13]

TBranch * TTree::Branch ( const char *  name,
char *  address,
const char *  leaflist,
Int_t  bufsize = 32000 
)
inline

Definition at line 376 of file TTree.h.

◆ Branch() [3/13]

template<class T >
TBranch * TTree::Branch ( const char *  name,
const char *  classname,
T **  addobj,
Int_t  bufsize = 32000,
Int_t  splitlevel = 99 
)
inline

Definition at line 397 of file TTree.h.

◆ Branch() [4/13]

template<class T >
TBranch * TTree::Branch ( const char *  name,
const char *  classname,
T *  obj,
Int_t  bufsize = 32000,
Int_t  splitlevel = 99 
)
inline

Definition at line 392 of file TTree.h.

◆ Branch() [5/13]

TBranch * TTree::Branch ( const char *  name,
const char *  classname,
void *  addobj,
Int_t  bufsize = 32000,
Int_t  splitlevel = 99 
)
virtual

Create a new branch with the object of class classname at address addobj.

WARNING:

Starting with Root version 3.01, the Branch function uses the new style branches (TBranchElement). To get the old behaviour, you can:

  • call BranchOld or
  • call TTree::SetBranchStyle(0)

Note that with the new style, classname does not need to derive from TObject. It must derived from TObject if the branch style has been set to 0 (old)

Note: See the comments in TBranchElement::SetAddress() for a more detailed discussion of the meaning of the addobj parameter in the case of new-style branches.

Use splitlevel < 0 instead of splitlevel=0 when the class has a custom Streamer

Note: if the split level is set to the default (99), TTree::Branch will not issue a warning if the class can not be split.

Reimplemented in TTreeSQL.

Definition at line 2018 of file TTree.cxx.

◆ Branch() [6/13]

TBranch * TTree::Branch ( const char *  name,
int  address,
const char *  leaflist,
Int_t  bufsize = 32000 
)
inline

Definition at line 386 of file TTree.h.

◆ Branch() [7/13]

TBranch * TTree::Branch ( const char *  name,
Longptr_t  address,
const char *  leaflist,
Int_t  bufsize = 32000 
)
inline

Definition at line 381 of file TTree.h.

◆ Branch() [8/13]

template<typename T , std::size_t N>
TBranch * TTree::Branch ( const char *  name,
std::array< T, N > *  obj,
Int_t  bufsize = 32000,
Int_t  splitlevel = 99 
)
inline

Definition at line 402 of file TTree.h.

◆ Branch() [9/13]

template<class T >
TBranch * TTree::Branch ( const char *  name,
T **  addobj,
Int_t  bufsize = 32000,
Int_t  splitlevel = 99 
)
inline

Add a new branch, and infer the data type from the array addobj being passed.

Note
This and the previous overload should cover most cases for creating a branch. Try to use these two whenever possible, unless e.g. type conversions are needed.
Parameters
[in]nameName of the branch to be created.
[in]addobjArray of the objects to be added. When calling Fill(), the current value of the type/object will be saved.
[in]bufsizehe buffer size in bytes for this branch. When the buffer is full, it is compressed and written to disc. The default value of 32000 bytes and should be ok for most simple types. Larger buffers (e.g. 256000) if your Tree is not split and each entry is large (Megabytes). A small value for bufsize is beneficial if entries in the Tree are accessed randomly and the Tree is in split mode.
[in]splitlevelIf T is a class or struct and splitlevel > 0, the members of the object are serialised as separate branches.
Returns
Pointer to the TBranch that was created. The branch is owned by the tree.

Definition at line 367 of file TTree.h.

◆ Branch() [10/13]

template<class T >
TBranch * TTree::Branch ( const char *  name,
T *  obj,
Int_t  bufsize = 32000,
Int_t  splitlevel = 99 
)
inline

Add a new branch, and infer the data type from the type of obj being passed.

Note
This and the next overload should cover most cases for creating a branch. Try to use these two whenever possible, unless e.g. type conversions are needed.
Parameters
[in]nameName of the branch to be created.
[in]objAddress of the object to be added. Make sure to pass a pointer to the actual type/class that should be stored in the tree (no pointers to base classes). When calling Fill(), the current value of the type/object will be saved.
[in]bufsizeThe buffer size in bytes for this branch. When the buffer is full, it is compressed and written to disc. The default value of 32000 bytes and should be ok for most simple types. Larger buffers (e.g. 256000) if your Tree is not split and each entry is large (Megabytes). A small value for bufsize is beneficial if entries in the Tree are accessed randomly and the Tree is in split mode.
[in]splitlevelIf T is a class or struct and splitlevel > 0, the members of the object are serialised as separate branches.
Returns
Pointer to the TBranch that was created. The branch is owned by the tree.

Definition at line 350 of file TTree.h.

◆ Branch() [11/13]

TBranch * TTree::Branch ( const char *  name,
void *  address,
const char *  leaflist,
Int_t  bufsize = 32000 
)
virtual

Create a new TTree Branch.

This Branch constructor is provided to support non-objects in a Tree. The variables described in leaflist may be simple variables or structures. // See the two following constructors for writing objects in a Tree.

By default the branch buffers are stored in the same file as the Tree. use TBranch::SetFile to specify a different file

  • address is the address of the first item of a structure.
  • leaflist is the concatenation of all the variable names and types separated by a colon character : The variable name and the variable type are separated by a slash (/). The variable type may be 0,1 or 2 characters. If no type is given, the type of the variable is assumed to be the same as the previous variable. If the first variable does not have a type, it is assumed of type F by default. The list of currently supported types is given below:

    • C : a character string terminated by the 0 character
    • B : an 8 bit signed integer (Char_t)
    • b : an 8 bit unsigned integer (UChar_t)
    • S : a 16 bit signed integer (Short_t)
    • s : a 16 bit unsigned integer (UShort_t)
    • I : a 32 bit signed integer (Int_t)
    • i : a 32 bit unsigned integer (UInt_t)
    • F : a 32 bit floating point (Float_t)
    • f : a 24 bit floating point with truncated mantissa (Float16_t)
    • D : a 64 bit floating point (Double_t)
    • d : a 24 bit truncated floating point (Double32_t)
    • L : a 64 bit signed integer (Long64_t)
    • l : a 64 bit unsigned integer (ULong64_t)
    • G : a long signed integer, stored as 64 bit (Long_t)
    • g : a long unsigned integer, stored as 64 bit (ULong_t)
    • O : [the letter o, not a zero] a boolean (Bool_t)

    Arrays of values are supported with the following syntax:

    • If leaf name has the form var[nelem], where nelem is alphanumeric, then if nelem is a leaf name, it is used as the variable size of the array, otherwise return 0.
    • If leaf name has the form var[nelem], where nelem is a non-negative integer, then it is used as the fixed size of the array.
    • If leaf name has the form of a multi-dimensional array (e.g. var[nelem][nelem2]) where nelem and nelem2 are non-negative integer) then it is used as a 2 dimensional array of fixed size.
    • In case of the truncated floating point types (Float16_t and Double32_t) you can furthermore specify the range in the style [xmin,xmax] or [xmin,xmax,nbits] after the type character. See TStreamerElement::GetRange() for further information.

    Any of other form is not supported.

Note that the TTree will assume that all the item are contiguous in memory. On some platform, this is not always true of the member of a struct or a class, due to padding and alignment. Sorting your data member in order of decreasing sizeof usually leads to their being contiguous in memory.

  • bufsize is the buffer size in bytes for this branch The default value is 32000 bytes and should be ok for most cases. You can specify a larger value (e.g. 256000) if your Tree is not split and each entry is large (Megabytes) A small value for bufsize is optimum if you intend to access the entries in the Tree randomly and your Tree is in split mode.

Reimplemented in TTreeSQL.

Definition at line 1983 of file TTree.cxx.

◆ Branch() [12/13]

Int_t TTree::Branch ( TCollection li,
Int_t  bufsize = 32000,
Int_t  splitlevel = 99,
const char *  name = "" 
)
virtual

Create one branch for each element in the collection.

Each entry in the collection becomes a top level branch if the corresponding class is not a collection. If it is a collection, the entry in the collection becomes in turn top level branches, etc. The splitlevel is decreased by 1 every time a new collection is found. For example if list is a TObjArray*

  • if splitlevel = 1, one top level branch is created for each element of the TObjArray.
  • if splitlevel = 2, one top level branch is created for each array element. if, in turn, one of the array elements is a TCollection, one top level branch will be created for each element of this collection.

In case a collection element is a TClonesArray, the special Tree constructor for TClonesArray is called. The collection itself cannot be a TClonesArray.

The function returns the total number of branches created.

If name is given, all branch names will be prefixed with name_.

IMPORTANT NOTE1: This function should not be called with splitlevel < 1.

IMPORTANT NOTE2: The branches created by this function will have names corresponding to the collection or object names. It is important to give names to collections to avoid misleading branch names or identical branch names. By default collections have a name equal to the corresponding class name, e.g. the default name for a TList is "TList".

And in general, in case two or more master branches contain subbranches with identical names, one must add a "." (dot) character at the end of the master branch name. This will force the name of the subbranches to be of the form master.subbranch instead of simply subbranch. This situation happens when the top level object has two or more members referencing the same class. For example, if a Tree has two branches B1 and B2 corresponding to objects of the same class MyClass, one can do:

tree.Branch("B1.","MyClass",&b1,8000,1);
tree.Branch("B2.","MyClass",&b2,8000,1);

if MyClass has 3 members a,b,c, the two instructions above will generate subbranches called B1.a, B1.b ,B1.c, B2.a, B2.b, B2.c

Example:

{
TTree T("T","test list");
TList *list = new TList();
TObjArray *a1 = new TObjArray();
a1->SetName("a1");
list->Add(a1);
TH1F *ha1a = new TH1F("ha1a","ha1",100,0,1);
TH1F *ha1b = new TH1F("ha1b","ha1",100,0,1);
a1->Add(ha1a);
a1->Add(ha1b);
TObjArray *b1 = new TObjArray();
b1->SetName("b1");
list->Add(b1);
TH1F *hb1a = new TH1F("hb1a","hb1",100,0,1);
TH1F *hb1b = new TH1F("hb1b","hb1",100,0,1);
b1->Add(hb1a);
b1->Add(hb1b);
TObjArray *a2 = new TObjArray();
a2->SetName("a2");
list->Add(a2);
TH1S *ha2a = new TH1S("ha2a","ha2",100,0,1);
TH1S *ha2b = new TH1S("ha2b","ha2",100,0,1);
a2->Add(ha2a);
a2->Add(ha2b);
T.Branch(list,16000,2);
T.Print();
}
void SetName(const char *name)
1-D histogram with a short per channel (see TH1 documentation)
Definition TH1.h:495
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
An array of TObjects.
Definition TObjArray.h:31
void Add(TObject *obj) override
Definition TObjArray.h:68

Reimplemented in TTreeSQL.

Definition at line 1831 of file TTree.cxx.

◆ Branch() [13/13]

Int_t TTree::Branch ( TList list,
Int_t  bufsize = 32000,
Int_t  splitlevel = 99 
)
virtual

Deprecated function. Use next function instead.

Reimplemented in TTreeSQL.

Definition at line 1747 of file TTree.cxx.

◆ BranchImp() [1/2]

TBranch * TTree::BranchImp ( const char *  branchname,
const char *  classname,
TClass ptrClass,
void *  addobj,
Int_t  bufsize,
Int_t  splitlevel 
)
protectedvirtual

Same as TTree::Branch() with added check that addobj matches className.

See also
TTree::Branch() for other details.

Reimplemented in TTreeSQL.

Definition at line 1552 of file TTree.cxx.

◆ BranchImp() [2/2]

TBranch * TTree::BranchImp ( const char *  branchname,
TClass ptrClass,
void *  addobj,
Int_t  bufsize,
Int_t  splitlevel 
)
protectedvirtual

Same as TTree::Branch but automatic detection of the class name.

See also
TTree::Branch for other details.

Reimplemented in TTreeSQL.

Definition at line 1600 of file TTree.cxx.

◆ BranchImpArr()

TBranch * TTree::BranchImpArr ( const char *  branchname,
EDataType  datatype,
std::size_t  N,
void *  addobj,
Int_t  bufsize,
Int_t  splitlevel 
)
protectedvirtual

Definition at line 1729 of file TTree.cxx.

◆ BranchImpRef() [1/2]

TBranch * TTree::BranchImpRef ( const char *  branchname,
const char *  classname,
TClass ptrClass,
void *  addobj,
Int_t  bufsize,
Int_t  splitlevel 
)
protectedvirtual

Same as TTree::Branch but automatic detection of the class name.

See also
TTree::Branch for other details.

Definition at line 1633 of file TTree.cxx.

◆ BranchImpRef() [2/2]

TBranch * TTree::BranchImpRef ( const char *  branchname,
TClass ptrClass,
EDataType  datatype,
void *  addobj,
Int_t  bufsize,
Int_t  splitlevel 
)
protectedvirtual

Same as TTree::Branch but automatic detection of the class name.

See also
TTree::Branch for other details.

Definition at line 1693 of file TTree.cxx.

◆ BranchOld()

TBranch * TTree::BranchOld ( const char *  name,
const char *  classname,
void *  addobj,
Int_t  bufsize = 32000,
Int_t  splitlevel = 1 
)
virtual

Create a new TTree BranchObject.

Build a TBranchObject for an object of class classname. addobj is the address of a pointer to an object of class classname. IMPORTANT: classname must derive from TObject. The class dictionary must be available (ClassDef in class header).

This option requires access to the library where the corresponding class is defined. Accessing one single data member in the object implies reading the full object. See the next Branch constructor for a more efficient storage in case the entry consists of arrays of identical objects.

By default the branch buffers are stored in the same file as the Tree. use TBranch::SetFile to specify a different file

IMPORTANT NOTE about branch names:

And in general, in case two or more master branches contain subbranches with identical names, one must add a "." (dot) character at the end of the master branch name. This will force the name of the subbranches to be of the form master.subbranch instead of simply subbranch. This situation happens when the top level object has two or more members referencing the same class. For example, if a Tree has two branches B1 and B2 corresponding to objects of the same class MyClass, one can do:

tree.Branch("B1.","MyClass",&b1,8000,1);
tree.Branch("B2.","MyClass",&b2,8000,1);

if MyClass has 3 members a,b,c, the two instructions above will generate subbranches called B1.a, B1.b ,B1.c, B2.a, B2.b, B2.c

bufsize is the buffer size in bytes for this branch The default value is 32000 bytes and should be ok for most cases. You can specify a larger value (e.g. 256000) if your Tree is not split and each entry is large (Megabytes) A small value for bufsize is optimum if you intend to access the entries in the Tree randomly and your Tree is in split mode.

Reimplemented in TTreeSQL.

Definition at line 2071 of file TTree.cxx.

◆ BranchRef()

TBranch * TTree::BranchRef ( )
virtual

Build the optional branch supporting the TRefTable.

This branch will keep all the information to find the branches containing referenced objects.

At each Tree::Fill, the branch numbers containing the referenced objects are saved to the TBranchRef basket. When the Tree header is saved (via TTree::Write), the branch is saved keeping the information with the pointers to the branches having referenced objects.

Definition at line 2325 of file TTree.cxx.

◆ Bronch()

TBranch * TTree::Bronch ( const char *  name,
const char *  classname,
void *  addr,
Int_t  bufsize = 32000,
Int_t  splitlevel = 99 
)
virtual

Create a new TTree BranchElement.

WARNING about this new function

This function is designed to replace the internal implementation of the old TTree::Branch (whose implementation has been moved to BranchOld).

NOTE: The 'Bronch' method supports only one possible calls signature (where the object type has to be specified explicitly and the address must be the address of a pointer). For more flexibility use 'Branch'. Use Bronch only in (rare) cases (likely to be legacy cases) where both the new and old implementation of Branch needs to be used at the same time.

This function is far more powerful than the old Branch function. It supports the full C++, including STL and has the same behaviour in split or non-split mode. classname does not have to derive from TObject. The function is based on the new TStreamerInfo.

Build a TBranchElement for an object of class classname.

addr is the address of a pointer to an object of class classname. The class dictionary must be available (ClassDef in class header).

Note: See the comments in TBranchElement::SetAddress() for a more detailed discussion of the meaning of the addr parameter.

This option requires access to the library where the corresponding class is defined. Accessing one single data member in the object implies reading the full object.

By default the branch buffers are stored in the same file as the Tree. use TBranch::SetFile to specify a different file

IMPORTANT NOTE about branch names:

And in general, in case two or more master branches contain subbranches with identical names, one must add a "." (dot) character at the end of the master branch name. This will force the name of the subbranches to be of the form master.subbranch instead of simply subbranch. This situation happens when the top level object has two or more members referencing the same class. For example, if a Tree has two branches B1 and B2 corresponding to objects of the same class MyClass, one can do:

tree.Branch("B1.","MyClass",&b1,8000,1);
tree.Branch("B2.","MyClass",&b2,8000,1);

if MyClass has 3 members a,b,c, the two instructions above will generate subbranches called B1.a, B1.b ,B1.c, B2.a, B2.b, B2.c

bufsize is the buffer size in bytes for this branch The default value is 32000 bytes and should be ok for most cases. You can specify a larger value (e.g. 256000) if your Tree is not split and each entry is large (Megabytes) A small value for bufsize is optimum if you intend to access the entries in the Tree randomly and your Tree is in split mode.

Use splitlevel < 0 instead of splitlevel=0 when the class has a custom Streamer

Note: if the split level is set to the default (99), TTree::Branch will not issue a warning if the class can not be split.

Reimplemented in TTreeSQL.

Definition at line 2401 of file TTree.cxx.

◆ BronchExec()

TBranch * TTree::BronchExec ( const char *  name,
const char *  classname,
void *  addobj,
Bool_t  isptrptr,
Int_t  bufsize,
Int_t  splitlevel 
)
protectedvirtual

Helper function implementing TTree::Bronch and TTree::Branch(const char *name, T &obj);.

Definition at line 2409 of file TTree.cxx.

◆ Browse()

void TTree::Browse ( TBrowser b)
overridevirtual

Browse content of the TTree.

Reimplemented from TObject.

Definition at line 2606 of file TTree.cxx.

◆ BuildIndex()

Int_t TTree::BuildIndex ( const char *  majorname,
const char *  minorname = "0" 
)
virtual

Build a Tree Index (default is TTreeIndex).

See a description of the parameters and functionality in TTreeIndex::TTreeIndex().

The return value is the number of entries in the Index (< 0 indicates failure).

A TTreeIndex object pointed by fTreeIndex is created. This object will be automatically deleted by the TTree destructor. If an index is already existing, this is replaced by the new one without being deleted. This behaviour prevents the deletion of a previously external index assigned to the TTree via the TTree::SetTreeIndex() method.

See also
also comments in TTree::SetTreeIndex().

Definition at line 2634 of file TTree.cxx.

◆ BuildStreamerInfo()

TStreamerInfo * TTree::BuildStreamerInfo ( TClass cl,
void *  pointer = nullptr,
Bool_t  canOptimize = kTRUE 
)

Build StreamerInfo for class cl.

pointer is an optional argument that may contain a pointer to an object of cl.

Definition at line 2649 of file TTree.cxx.

◆ ChangeFile()

TFile * TTree::ChangeFile ( TFile file)
virtual

Called by TTree::Fill() when file has reached its maximum fgMaxTreeSize.

Create a new file. If the original file is named "myfile.root", subsequent files are named "myfile_1.root", "myfile_2.root", etc.

Returns a pointer to the new file.

Currently, the automatic change of file is restricted to the case where the tree is in the top level directory. The file should not contain sub-directories.

Before switching to a new file, the tree header is written to the current file, then the current file is closed.

To process the multiple files created by ChangeFile, one must use a TChain.

The new file name has a suffix "_N" where N is equal to fFileNumber+1. By default a Root session starts with fFileNumber=0. One can set fFileNumber to a different value via TTree::SetFileNumber. In case a file named "_N" already exists, the function will try a file named "__N", then "___N", etc.

fgMaxTreeSize can be set via the static function TTree::SetMaxTreeSize. The default value of fgMaxTreeSize is 100 Gigabytes.

If the current file contains other objects like TH1 and TTree, these objects are automatically moved to the new file.

Warning
Be careful when writing the final Tree header to the file! Don't do:
TFile *file = new TFile("myfile.root","recreate");
TTree *T = new TTree("T","title");
T->Fill(); // Loop
file->Write();
file->Close();
TTree()
Default constructor and I/O constructor.
Definition TTree.cxx:736
Definition file.py:1
but do the following:
TFile *file = new TFile("myfile.root","recreate");
TTree *T = new TTree("T","title");
T->Fill(); // Loop
file = T->GetCurrentFile(); // To get the pointer to the current file
file->Write();
file->Close();
Note
This method is never called if the input file is a TMemFile or derivate.

Definition at line 2746 of file TTree.cxx.

◆ CheckBranchAddressType()

Int_t TTree::CheckBranchAddressType ( TBranch branch,
TClass ptrClass,
EDataType  datatype,
Bool_t  isptr 
)
protectedvirtual

Check whether or not the address described by the last 3 parameters matches the content of the branch.

If a Data Model Evolution conversion is involved, reset the fInfo of the branch. The return values are:

  • kMissingBranch (-5) : Missing branch
  • kInternalError (-4) : Internal error (could not find the type corresponding to a data type number)
  • kMissingCompiledCollectionProxy (-3) : Missing compiled collection proxy for a compiled collection
  • kMismatch (-2) : Non-Class Pointer type given does not match the type expected by the branch
  • kClassMismatch (-1) : Class Pointer type given does not match the type expected by the branch
  • kMatch (0) : perfect match
  • kMatchConversion (1) : match with (I/O) conversion
  • kMatchConversionCollection (2) : match with (I/O) conversion of the content of a collection
  • kMakeClass (3) : MakeClass mode so we can not check.
  • kVoidPtr (4) : void* passed so no check was made.
  • kNoCheck (5) : Underlying TBranch not yet available so no check was made. In addition this can be multiplexed with the two bits:
  • kNeedEnableDecomposedObj : in order for the address (type) to be 'usable' the branch needs to be in Decomposed Object (aka MakeClass) mode.
  • kNeedDisableDecomposedObj : in order for the address (type) to be 'usable' the branch needs to not be in Decomposed Object (aka MakeClass) mode. This bits can be masked out by using kDecomposedObjMask

Definition at line 2864 of file TTree.cxx.

◆ Class()

static TClass * TTree::Class ( )
static
Returns
TClass describing this class

◆ Class_Name()

static const char * TTree::Class_Name ( )
static
Returns
Name of this class

◆ Class_Version()

static constexpr Version_t TTree::Class_Version ( )
inlinestaticconstexpr
Returns
Version of this class

Definition at line 654 of file TTree.h.

◆ CloneTree()

TTree * TTree::CloneTree ( Long64_t  nentries = -1,
Option_t option = "" 
)
virtual

Create a clone of this tree and copy nentries.

By default copy all entries. The compression level of the cloned tree is set to the destination file's compression level.

NOTE: Only active branches are copied. NOTE: If the TTree is a TChain, the structure of the first TTree is used for the copy.

IMPORTANT: The cloned tree stays connected with this tree until this tree is deleted. In particular, any changes in branch addresses in this tree are forwarded to the clone trees, unless a branch in a clone tree has had its address changed, in which case that change stays in effect. When this tree is deleted, all the addresses of the cloned tree are reset to their default values.

If 'option' contains the word 'fast' and nentries is -1, the cloning will be done without unzipping or unstreaming the baskets (i.e., a direct copy of the raw bytes on disk).

When 'fast' is specified, 'option' can also contain a sorting order for the baskets in the output file.

There are currently 3 supported sorting order:

  • SortBasketsByOffset (the default)
  • SortBasketsByBranch
  • SortBasketsByEntry

When using SortBasketsByOffset the baskets are written in the output file in the same order as in the original file (i.e. the baskets are sorted by their offset in the original file; Usually this also means that the baskets are sorted by the index/number of the last entry they contain)

When using SortBasketsByBranch all the baskets of each individual branches are stored contiguously. This tends to optimize reading speed when reading a small number (1->5) of branches, since all their baskets will be clustered together instead of being spread across the file. However it might decrease the performance when reading more branches (or the full entry).

When using SortBasketsByEntry the baskets with the lowest starting entry are written first. (i.e. the baskets are sorted by the index/number of the first entry they contain). This means that on the file the baskets will be in the order in which they will be needed when reading the whole tree sequentially.

For examples of CloneTree, see tutorials:

  • copytree.C: A macro to copy a subset of a TTree to a new TTree. The input file has been generated by the program in $ROOTSYS/test/Event with: Event 1000 1 1 1
  • copytree2.C: A macro to copy a subset of a TTree to a new TTree. One branch of the new Tree is written to a separate file. The input file has been generated by the program in $ROOTSYS/test/Event with: Event 1000 1 1 1

Reimplemented in TNtuple.

Definition at line 3133 of file TTree.cxx.

◆ CopyAddresses()

void TTree::CopyAddresses ( TTree tree,
Bool_t  undo = kFALSE 
)
virtual

Set branch addresses of passed tree equal to ours.

If undo is true, reset the branch addresses instead of copying them. This ensures 'separation' of a cloned tree from its original.

Definition at line 3293 of file TTree.cxx.

◆ CopyEntries()

Long64_t TTree::CopyEntries ( TTree tree,
Long64_t  nentries = -1,
Option_t option = "",
Bool_t  needCopyAddresses = false 
)
virtual

Copy nentries from given tree to this tree.

This routines assumes that the branches that intended to be copied are already connected. The typical case is that this tree was created using tree->CloneTree(0).

By default copy all entries.

Returns number of bytes copied to this tree.

If 'option' contains the word 'fast' and nentries is -1, the cloning will be done without unzipping or unstreaming the baskets (i.e., a direct copy of the raw bytes on disk).

When 'fast' is specified, 'option' can also contains a sorting order for the baskets in the output file.

There are currently 3 supported sorting order:

  • SortBasketsByOffset (the default)
  • SortBasketsByBranch
  • SortBasketsByEntry

See TTree::CloneTree for a detailed explanation of the semantics of these 3 options.

If the tree or any of the underlying tree of the chain has an index, that index and any index in the subsequent underlying TTree objects will be merged.

There are currently three 'options' to control this merging:

  • NoIndex : all the TTreeIndex object are dropped.
  • DropIndexOnError : if any of the underlying TTree object do no have a TTreeIndex, they are all dropped.
  • AsIsIndexOnError [default]: In case of missing TTreeIndex, the resulting TTree index has gaps.
  • BuildIndexOnError : If any of the underlying TTree objects do not have a TTreeIndex, all TTreeIndex are 'ignored' and the missing piece are rebuilt.

Definition at line 3528 of file TTree.cxx.

◆ CopyTree()

TTree * TTree::CopyTree ( const char *  selection,
Option_t option = "",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)
virtual

Copy a tree with selection.

Important:

The returned copied tree stays connected with the original tree until the original tree is deleted. In particular, any changes to the branch addresses in the original tree are also made to the copied tree. Any changes made to the branch addresses of the copied tree are overridden anytime the original tree changes its branch addresses. When the original tree is deleted, all the branch addresses of the copied tree are set to zero.

For examples of CopyTree, see the tutorials:

  • copytree.C: Example macro to copy a subset of a tree to a new tree. The input file was generated by running the program in $ROOTSYS/test/Event in this way:
    ./Event 1000 1 1 1
  • copytree2.C Example macro to copy a subset of a tree to a new tree. One branch of the new tree is written to a separate file. The input file was generated by running the program in $ROOTSYS/test/Event in this way:
    ./Event 1000 1 1 1
  • copytree3.C Example macro to copy a subset of a tree to a new tree. Only selected entries are copied to the new tree. NOTE that only the active branches are copied.

Definition at line 3713 of file TTree.cxx.

◆ CreateBasket()

TBasket * TTree::CreateBasket ( TBranch branch)
virtual

Create a basket for this tree and given branch.

Reimplemented in TTreeSQL.

Definition at line 3725 of file TTree.cxx.

◆ Debug()

Int_t TTree::Debug ( ) const
inline

Definition at line 426 of file TTree.h.

◆ DeclFileName()

static const char * TTree::DeclFileName ( )
inlinestatic
Returns
Name of the file containing the class declaration

Definition at line 654 of file TTree.h.

◆ Delete()

void TTree::Delete ( Option_t option = "")
overridevirtual

Delete this tree from memory or/and disk.

  • if option == "all" delete Tree object from memory AND from disk all baskets on disk are deleted. All keys with same name are deleted.
  • if option =="" only Tree object in memory is deleted.

Reimplemented from TObject.

Definition at line 3741 of file TTree.cxx.

◆ DirectoryAutoAdd()

void TTree::DirectoryAutoAdd ( TDirectory dir)
virtual

Called by TKey and TObject::Clone to automatically add us to a directory when we are read from a file.

Reimplemented in TChain.

Definition at line 3813 of file TTree.cxx.

◆ Draw() [1/3]

Long64_t TTree::Draw ( const char *  varexp,
const char *  selection,
Option_t option = "",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)
virtual

Draw expression varexp for entries and objects that pass a (optional) selection.

Returns
-1 in case of error or number of selected events in case of success.
Parameters
[in]varexpA string that takes one of these general forms:
  • "e1" produces a 1-d histogram (TH1F) of expression "e1"
  • "e1:e2" produces an unbinned 2-d scatter-plot (TGraph) of "e1" on the y-axis versus "e2" on the x-axis
  • "e1:e2:e3" produces an unbinned 3-d scatter-plot (TPolyMarker3D) of "e1" vs "e2" vs "e3" on the z-, y-, x-axis, respectively
  • "e1:e2:e3:e4" produces an unbinned 3-d scatter-plot (TPolyMarker3D) of "e1" vs "e2" vs "e3" and "e4" mapped on the current color palette. (to create histograms in the 2, 3, and 4 dimensional case, see section "Saving the result of Draw to an histogram")

    Examples:

    • "x": the simplest case, it draws a 1-Dim histogram of column x
    • "sqrt(x)", "x*y/z": draw histogram with the values of the specified numerical expression across TTree events
    • "y:sqrt(x)": 2-Dim histogram of y versus sqrt(x)
    • "px:py:pz:2.5*E": produces a 3-d scatter-plot of px vs py ps pz and the color number of each marker will be 2.5*E. If the color number is negative it is set to 0. If the color number is greater than the current number of colors it is set to the highest color number. The default number of colors is 50. See TStyle::SetPalette for setting a new color palette.

    The expressions can use all the operations and built-in functions supported by TFormula (see TFormula::Analyze()), including free functions taking numerical arguments (e.g. TMath::Bessel()). In addition, you can call member functions taking numerical arguments. For example, these are two valid expressions:

    event.GetHistogram()->GetXaxis()->GetXmax()
    TH1 * GetHistogram()
    Definition TTree.h:476
    Double_t BreitWigner(Double_t x, Double_t mean=0, Double_t gamma=1)
    Calculates a Breit Wigner function with mean and gamma.
    Definition TMath.cxx:442
[in]selectionA string containing a selection expression. In a selection all usual C++ mathematical and logical operators are allowed. The value corresponding to the selection expression is used as a weight to fill the histogram (a weight of 0 is equivalent to not filling the histogram).

Examples:
  • "x<y && sqrt(z)>3.2": returns a weight = 0 or 1
  • "(x+y)*(sqrt(z)>3.2)": returns a weight = x+y if sqrt(z)>3.2, 0 otherwise

    If the selection expression returns an array, it is iterated over in sync with the array returned by the varexp argument (as described below in "Drawing expressions using arrays and array elements"). For example, if, for a given event, varexp evaluates to {1., 2., 3.} and selection evaluates to {0, 1, 0}, the resulting histogram is filled with the value 2. For example, for each event here we perform a simple object selection:
    // Muon_pt is an array: fill a histogram with the array elements > 100 in each event
    tree->Draw('Muon_pt', 'Muon_pt > 100')
[in]optionThe drawing option.
  • When an histogram is produced it can be any histogram drawing option listed in THistPainter.
  • when no option is specified:
    • the default histogram drawing option is used if the expression is of the form "e1".
    • if the expression is of the form "e1:e2"or "e1:e2:e3" a cloud of unbinned 2D or 3D points is drawn respectively.
    • if the expression has four fields "e1:e2:e3:e4" a cloud of unbinned 3D points is produced with e1 vs e2 vs e3, and e4 is mapped on the current color palette.
  • If option COL is specified when varexp has three fields:
    tree.Draw("e1:e2:e3","","col");
    a 2D scatter is produced with e1 vs e2, and e3 is mapped on the current color palette. The colors for e3 are evaluated once in linear scale before painting. Therefore changing the pad to log scale along Z as no effect on the colors.
  • if expression has more than four fields the option "PARA"or "CANDLE" can be used.
  • If option contains the string "goff", no graphics is generated.
[in]nentriesThe number of entries to process (default is all)
[in]firstentryThe first entry to process (default is 0)

Drawing expressions using arrays and array elements

Let assumes, a leaf fMatrix, on the branch fEvent, which is a 3 by 3 array, or a TClonesArray. In a TTree::Draw expression you can now access fMatrix using the following syntaxes:

String passed What is used for each entry of the tree
fMatrix the 9 elements of fMatrix
fMatrix[][] the 9 elements of fMatrix
fMatrix[2][2] only the elements fMatrix[2][2]
fMatrix[1] the 3 elements fMatrix[1][0], fMatrix[1][1] and fMatrix[1][2]
fMatrix[1][] the 3 elements fMatrix[1][0], fMatrix[1][1] and fMatrix[1][2]
fMatrix[][0] the 3 elements fMatrix[0][0], fMatrix[1][0] and fMatrix[2][0]

"fEvent.fMatrix...." same as "fMatrix..." (unless there is more than one leaf named fMatrix!).

In summary, if a specific index is not specified for a dimension, TTree::Draw will loop through all the indices along this dimension. Leaving off the last (right most) dimension of specifying then with the two characters '[]' is equivalent. For variable size arrays (and TClonesArray) the range of the first dimension is recalculated for each entry of the tree. You can also specify the index as an expression of any other variables from the tree.

TTree::Draw also now properly handling operations involving 2 or more arrays.

Let assume a second matrix fResults[5][2], here are a sample of some of the possible combinations, the number of elements they produce and the loop used:

expression element(s) Loop
fMatrix[2][1] - fResults[5][2] one no loop
fMatrix[2][] - fResults[5][2] three on 2nd dim fMatrix
fMatrix[2][] - fResults[5][] two on both 2nd dimensions
fMatrix[][2] - fResults[][1] three on both 1st dimensions
fMatrix[][2] - fResults[][] six on both 1st and 2nd dimensions of fResults
fMatrix[][2] - fResults[3][] two on 1st dim of fMatrix and 2nd of fResults (at the same time)
fMatrix[][] - fResults[][] six on 1st dim then on 2nd dim
fMatrix[][fResult[][]] 30 on 1st dim of fMatrix then on both dimensions of fResults. The value if fResults[j][k] is used as the second index of fMatrix.

In summary, TTree::Draw loops through all unspecified dimensions. To figure out the range of each loop, we match each unspecified dimension from left to right (ignoring ALL dimensions for which an index has been specified), in the equivalent loop matched dimensions use the same index and are restricted to the smallest range (of only the matched dimensions). When involving variable arrays, the range can of course be different for each entry of the tree.

So the loop equivalent to "fMatrix[][2] - fResults[3][]" is:

for (Int_t i0; i < min(3,2); i++) {
use the value of (fMatrix[i0][2] - fMatrix[3][i0])
}

So the loop equivalent to "fMatrix[][2] - fResults[][]" is:

for (Int_t i0; i < min(3,5); i++) {
for (Int_t i1; i1 < 2; i1++) {
use the value of (fMatrix[i0][2] - fMatrix[i0][i1])
}
}

So the loop equivalent to "fMatrix[][] - fResults[][]" is:

for (Int_t i0; i < min(3,5); i++) {
for (Int_t i1; i1 < min(3,2); i1++) {
use the value of (fMatrix[i0][i1] - fMatrix[i0][i1])
}
}

So the loop equivalent to "fMatrix[][fResults[][]]" is:

for (Int_t i0; i0 < 3; i0++) {
for (Int_t j2; j2 < 5; j2++) {
for (Int_t j3; j3 < 2; j3++) {
i1 = fResults[j2][j3];
use the value of fMatrix[i0][i1]
}
}

Retrieving the result of Draw

By default a temporary histogram called htemp is created. It will be:

  • A TH1F* in case of a mono-dimensional distribution: Draw("e1"),
  • A TH2F* in case of a bi-dimensional distribution: Draw("e1:e2"),
  • A TH3F* in case of a three-dimensional distribution: Draw("e1:e2:e3").

In the one dimensional case the htemp is filled and drawn whatever the drawing option is.

In the two and three dimensional cases, with the default drawing option (""), a cloud of points is drawn and the histogram htemp is not filled. For all the other drawing options htemp will be filled.

In all cases htemp can be retrieved by calling:

auto htemp = (TH1F*)gPad->GetPrimitive("htemp"); // 1D
auto htemp = (TH2F*)gPad->GetPrimitive("htemp"); // 2D
auto htemp = (TH3F*)gPad->GetPrimitive("htemp"); // 3D
#define gPad
3-D histogram with a float per channel (see TH1 documentation)}
Definition TH3.h:268

In the two dimensional case (Draw("e1;e2")), with the default drawing option, the data is filled into a TGraph named Graph. This TGraph can be retrieved by calling

auto graph = (TGraph*)gPad->GetPrimitive("Graph");
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
Definition graph.py:1

For the three and four dimensional cases, with the default drawing option, an unnamed TPolyMarker3D is produced, and therefore cannot be retrieved.

In all cases htemp can be used to access the axes. For instance in the 2D case:

auto htemp = (TH2F*)gPad->GetPrimitive("htemp");
auto xaxis = htemp->GetXaxis();

When the option "A" is used (with TGraph painting option) to draw a 2D distribution:

tree.Draw("e1:e2","","A*");

a scatter plot is produced (with stars in that case) but the axis creation is delegated to TGraph and htemp is not created.

Saving the result of Draw to a histogram

If varexp contains >>hnew (following the variable(s) name(s)), the new histogram called hnew is created and it is kept in the current directory (and also the current pad). This works for all dimensions.

Example:

tree.Draw("sqrt(x)>>hsqrt","y>0")

will draw sqrt(x) and save the histogram as "hsqrt" in the current directory. To retrieve it do:

TH1F *hsqrt = (TH1F*)gDirectory->Get("hsqrt");
#define gDirectory
Definition TDirectory.h:386

The binning information is taken from the environment variables

Hist.Binning.?D.?

In addition, the name of the histogram can be followed by up to 9 numbers between '(' and ')', where the numbers describe the following:

  • 1 - bins in x-direction
  • 2 - lower limit in x-direction
  • 3 - upper limit in x-direction
  • 4-6 same for y-direction
  • 7-9 same for z-direction

When a new binning is used the new value will become the default. Values can be skipped.

Example:

tree.Draw("sqrt(x)>>hsqrt(500,10,20)")
// plot sqrt(x) between 10 and 20 using 500 bins
tree.Draw("sqrt(x):sin(y)>>hsqrt(100,10,60,50,.1,.5)")
// plot sqrt(x) against sin(y)
// 100 bins in x-direction; lower limit on x-axis is 10; upper limit is 60
// 50 bins in y-direction; lower limit on y-axis is .1; upper limit is .5

By default, the specified histogram is reset. To continue to append data to an existing histogram, use "+" in front of the histogram name.

A '+' in front of the histogram name is ignored, when the name is followed by binning information as described in the previous paragraph.

tree.Draw("sqrt(x)>>+hsqrt","y>0")

will not reset hsqrt, but will continue filling. This works for 1-D, 2-D and 3-D histograms.

Accessing collection objects

TTree::Draw default's handling of collections is to assume that any request on a collection pertain to it content. For example, if fTracks is a collection of Track objects, the following:

tree->Draw("event.fTracks.fPx");

will plot the value of fPx for each Track objects inside the collection. Also

tree->Draw("event.fTracks.size()");

would plot the result of the member function Track::size() for each Track object inside the collection. To access information about the collection itself, TTree::Draw support the '@' notation. If a variable which points to a collection is prefixed or postfixed with '@', the next part of the expression will pertain to the collection object. For example:

tree->Draw("event.@fTracks.size()");

will plot the size of the collection referred to by fTracks (i.e the number of Track objects).

Drawing 'objects'

When a class has a member function named AsDouble or AsString, requesting to directly draw the object will imply a call to one of the 2 functions. If both AsDouble and AsString are present, AsDouble will be used. AsString can return either a char*, a std::string or a TString.s For example, the following

tree->Draw("event.myTTimeStamp");

will draw the same histogram as

tree->Draw("event.myTTimeStamp.AsDouble()");

In addition, when the object is a type TString or std::string, TTree::Draw will call respectively TString::Data and std::string::c_str()

If the object is a TBits, the histogram will contain the index of the bit that are turned on.

Retrieving information about the tree itself.

You can refer to the tree (or chain) containing the data by using the string 'This'. You can then could any TTree methods. For example:

tree->Draw("This->GetReadEntry()");

will display the local entry numbers be read.

tree->Draw("This->GetUserInfo()->At(0)->GetName()");

will display the name of the first 'user info' object.

Special functions and variables

Entry$: A TTree::Draw formula can use the special variable Entry$ to access the entry number being read. For example to draw every other entry use:

tree.Draw("myvar","Entry$%2==0");
  • Entry$ : return the current entry number (== TTree::GetReadEntry())
  • LocalEntry$ : return the current entry number in the current tree of a chain (== GetTree()->GetReadEntry())
  • Entries$ : return the total number of entries (== TTree::GetEntries())
  • LocalEntries$ : return the total number of entries in the current tree of a chain (== GetTree()->TTree::GetEntries())
  • Length$ : return the total number of element of this formula for this entry (==TTreeFormula::GetNdata())
  • Iteration$ : return the current iteration over this formula for this entry (i.e. varies from 0 to Length$).
  • Length$(formula ) : return the total number of element of the formula given as a parameter.
  • Sum$(formula ) : return the sum of the value of the elements of the formula given as a parameter. For example the mean for all the elements in one entry can be calculated with: Sum$(formula )/Length$(formula )
  • Min$(formula ) : return the minimum (within one TTree entry) of the value of the elements of the formula given as a parameter.
  • Max$(formula ) : return the maximum (within one TTree entry) of the value of the elements of the formula given as a parameter.
  • MinIf$(formula,condition)
  • MaxIf$(formula,condition) : return the minimum (maximum) (within one TTree entry) of the value of the elements of the formula given as a parameter if they match the condition. If no element matches the condition, the result is zero. To avoid the resulting peak at zero, use the pattern:
    tree->Draw("MinIf$(formula,condition)","condition");
    which will avoid calculation MinIf$ for the entries that have no match for the condition.
  • Alt$(primary,alternate) : return the value of "primary" if it is available for the current iteration otherwise return the value of "alternate". For example, with arr1[3] and arr2[2]
    tree->Draw("arr1+Alt$(arr2,0)");
    will draw arr1[0]+arr2[0] ; arr1[1]+arr2[1] and arr1[2]+0 Or with a variable size array arr3
    tree->Draw("Alt$(arr3[0],0)+Alt$(arr3[1],0)+Alt$(arr3[2],0)");
    will draw the sum arr3 for the index 0 to min(2,actual_size_of_arr3-1) As a comparison
    tree->Draw("arr3[0]+arr3[1]+arr3[2]");
    will draw the sum arr3 for the index 0 to 2 only if the actual_size_of_arr3 is greater or equal to 3. Note that the array in 'primary' is flattened/linearized thus using Alt$ with multi-dimensional arrays of different dimensions in unlikely to yield the expected results. To visualize a bit more what elements would be matched by TTree::Draw, TTree::Scan can be used:
    tree->Scan("arr1:Alt$(arr2,0)");
    will print on one line the value of arr1 and (arr2,0) that will be matched by
    tree->Draw("arr1-Alt$(arr2,0)");
    The ternary operator is not directly supported in TTree::Draw however, to plot the equivalent of var2<20 ? -99 : var1, you can use:
    tree->Draw("(var2<20)*99+(var2>=20)*var1","");

Drawing a user function accessing the TTree data directly

If the formula contains a file name, TTree::MakeProxy will be used to load and execute this file. In particular it will draw the result of a function with the same name as the file. The function will be executed in a context where the name of the branches can be used as a C++ variable.

For example draw px using the file hsimple.root (generated by the hsimple.C tutorial), we need a file named hsimple.cxx:

double hsimple() {
return px;
}

MakeProxy can then be used indirectly via the TTree::Draw interface as follow:

new TFile("hsimple.root")
ntuple->Draw("hsimple.cxx");
th1 Draw()

A more complete example is available in the tutorials directory: h1analysisProxy.cxx, h1analysProxy.h and h1analysisProxyCut.C which reimplement the selector found in h1analysis.C

The main features of this facility are:

  • on-demand loading of branches
  • ability to use the 'branchname' as if it was a data member
  • protection against array out-of-bound
  • ability to use the branch data as object (when the user code is available)

See TTree::MakeProxy for more details.

Making a Profile histogram

In case of a 2-Dim expression, one can generate a TProfile histogram instead of a TH2F histogram by specifying option=prof or option=profs or option=profi or option=profg ; the trailing letter select the way the bin error are computed, See TProfile2D::SetErrorOption for details on the differences. The option=prof is automatically selected in case of y:x>>pf where pf is an existing TProfile histogram.

Making a 2D Profile histogram

In case of a 3-Dim expression, one can generate a TProfile2D histogram instead of a TH3F histogram by specifying option=prof or option=profs. or option=profi or option=profg ; the trailing letter select the way the bin error are computed, See TProfile2D::SetErrorOption for details on the differences. The option=prof is automatically selected in case of z:y:x>>pf where pf is an existing TProfile2D histogram.

Making a 5D plot using GL

If option GL5D is specified together with 5 variables, a 5D plot is drawn using OpenGL. See $ROOTSYS/tutorials/tree/staff.C as example.

Making a parallel coordinates plot

In case of a 2-Dim or more expression with the option=para, one can generate a parallel coordinates plot. With that option, the number of dimensions is arbitrary. Giving more than 4 variables without the option=para or option=candle or option=goff will produce an error.

Making a candle sticks chart

In case of a 2-Dim or more expression with the option=candle, one can generate a candle sticks chart. With that option, the number of dimensions is arbitrary. Giving more than 4 variables without the option=para or option=candle or option=goff will produce an error.

Normalizing the output histogram to 1

When option contains "norm" the output histogram is normalized to 1.

Saving the result of Draw to a TEventList, a TEntryList or a TEntryListArray

TTree::Draw can be used to fill a TEventList object (list of entry numbers) instead of histogramming one variable. If varexp0 has the form >>elist , a TEventList object named "elist" is created in the current directory. elist will contain the list of entry numbers satisfying the current selection. If option "entrylist" is used, a TEntryList object is created If the selection contains arrays, vectors or any container class and option "entrylistarray" is used, a TEntryListArray object is created containing also the subentries satisfying the selection, i.e. the indices of the branches which hold containers classes. Example:

tree.Draw(">>yplus","y>0")

will create a TEventList object named "yplus" in the current directory. In an interactive session, one can type (after TTree::Draw)

yplus.Print("all")

to print the list of entry numbers in the list.

tree.Draw(">>yplus", "y>0", "entrylist")

will create a TEntryList object names "yplus" in the current directory

tree.Draw(">>yplus", "y>0", "entrylistarray")

will create a TEntryListArray object names "yplus" in the current directory

By default, the specified entry list is reset. To continue to append data to an existing list, use "+" in front of the list name;

tree.Draw(">>+yplus","y>0")

will not reset yplus, but will enter the selected entries at the end of the existing list.

Using a TEventList, TEntryList or TEntryListArray as Input

Once a TEventList or a TEntryList object has been generated, it can be used as input for TTree::Draw. Use TTree::SetEventList or TTree::SetEntryList to set the current event list

Example 1:

TEventList *elist = (TEventList*)gDirectory->Get("yplus");
tree->SetEventList(elist);
tree->Draw("py");
A TEventList object is a list of selected events (entries) in a TTree.
Definition TEventList.h:31

Example 2:

TEntryList *elist = (TEntryList*)gDirectory->Get("yplus");
tree->SetEntryList(elist);
tree->Draw("py");
A List of entry numbers in a TTree or TChain.
Definition TEntryList.h:26

If a TEventList object is used as input, a new TEntryList object is created inside the SetEventList function. In case of a TChain, all tree headers are loaded for this transformation. This new object is owned by the chain and is deleted with it, unless the user extracts it by calling GetEntryList() function. See also comments to SetEventList() function of TTree and TChain.

If arrays are used in the selection criteria and TEntryListArray is not used, all the entries that have at least one element of the array that satisfy the selection are entered in the list.

Example:

tree.Draw(">>pyplus","fTracks.fPy>0");
tree->SetEventList(pyplus);
tree->Draw("fTracks.fPy");

will draw the fPy of ALL tracks in event with at least one track with a positive fPy.

To select only the elements that did match the original selection use TEventList::SetReapplyCut or TEntryList::SetReapplyCut.

Example:

tree.Draw(">>pyplus","fTracks.fPy>0");
pyplus->SetReapplyCut(kTRUE);
tree->SetEventList(pyplus);
tree->Draw("fTracks.fPy");
constexpr Bool_t kTRUE
Definition RtypesCore.h:100

will draw the fPy of only the tracks that have a positive fPy.

To draw only the elements that match a selection in case of arrays, you can also use TEntryListArray (faster in case of a more general selection).

Example:

tree.Draw(">>pyplus","fTracks.fPy>0", "entrylistarray");
tree->SetEntryList(pyplus);
tree->Draw("fTracks.fPy");

will draw the fPy of only the tracks that have a positive fPy, but without redoing the selection.

Note: Use tree->SetEventList(0) if you do not want use the list as input.

How to obtain more info from TTree::Draw

Once TTree::Draw has been called, it is possible to access useful information still stored in the TTree object via the following functions:

  • GetSelectedRows() // return the number of values accepted by the selection expression. In case where no selection was specified, returns the number of values processed.
  • GetV1() // returns a pointer to the double array of V1
  • GetV2() // returns a pointer to the double array of V2
  • GetV3() // returns a pointer to the double array of V3
  • GetV4() // returns a pointer to the double array of V4
  • GetW() // returns a pointer to the double array of Weights where weight equal the result of the selection expression.

where V1,V2,V3 correspond to the expressions in

TTree::Draw("V1:V2:V3:V4",selection);

If the expression has more than 4 component use GetVal(index)

Example:

Root > ntuple->Draw("py:px","pz>4");
Root > TGraph *gr = new TGraph(ntuple->GetSelectedRows(),
ntuple->GetV2(), ntuple->GetV1());
Root > gr->Draw("ap"); //draw graph in current pad
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:808
TGraphErrors * gr
Definition legend1.C:25

A more complete complete tutorial (treegetval.C) shows how to use the GetVal() method.

creates a TGraph object with a number of points corresponding to the number of entries selected by the expression "pz>4", the x points of the graph being the px values of the Tree and the y points the py values.

Important note: By default TTree::Draw creates the arrays obtained with GetW, GetV1, GetV2, GetV3, GetV4, GetVal with a length corresponding to the parameter fEstimate. The content will be the last GetSelectedRows() % GetEstimate() values calculated. By default fEstimate=1000000 and can be modified via TTree::SetEstimate. To keep in memory all the results (in case where there is only one result per entry), use

tree->SetEstimate(tree->GetEntries()+1); // same as tree->SetEstimate(-1);

You must call SetEstimate if the expected number of selected rows you need to look at is greater than 1000000.

You can use the option "goff" to turn off the graphics output of TTree::Draw in the above example.

Automatic interface to TTree::Draw via the TTreeViewer

A complete graphical interface to this function is implemented in the class TTreeViewer. To start the TTreeViewer, three possibilities:

  • select TTree context menu item "StartViewer"
  • type the command "TTreeViewer TV(treeName)"
  • execute statement "tree->StartViewer();"

Reimplemented in TChain, and TProofChain.

Definition at line 4498 of file TTree.cxx.

◆ Draw() [2/3]

Long64_t TTree::Draw ( const char *  varexp,
const TCut selection,
Option_t option = "",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)
virtual

Draw expression varexp for specified entries.

Returns
-1 in case of error or number of selected events in case of success.

This function accepts TCut objects as arguments. Useful to use the string operator +

Example:

ntuple.Draw("x",cut1+cut2+cut3);

Reimplemented in TChain, and TProofChain.

Definition at line 3849 of file TTree.cxx.

◆ Draw() [3/3]

void TTree::Draw ( Option_t option)
inlineoverridevirtual

Default Draw method for all objects.

Reimplemented from TObject.

Definition at line 428 of file TTree.h.

◆ DropBaskets()

void TTree::DropBaskets ( )
virtual

Remove some baskets from memory.

Definition at line 4509 of file TTree.cxx.

◆ DropBranchFromCache() [1/2]

Int_t TTree::DropBranchFromCache ( const char *  bname,
Bool_t  subbranches = kFALSE 
)
virtual

Remove the branch with name 'bname' from the Tree cache.

If bname="*" all branches are removed from the cache. if subbranches is true all the branches of the subbranches are also removed from the cache.

Returns:

  • 0 branch dropped or not in cache
  • -1 on error

Definition at line 1141 of file TTree.cxx.

◆ DropBranchFromCache() [2/2]

Int_t TTree::DropBranchFromCache ( TBranch b,
Bool_t  subbranches = kFALSE 
)
virtual

Remove the branch b from the Tree cache.

if subbranches is true all the branches of the subbranches are also removed from the cache.

Returns:

  • 0 branch dropped or not in cache
  • -1 on error

Definition at line 1180 of file TTree.cxx.

◆ DropBuffers()

void TTree::DropBuffers ( Int_t  nbytes)
virtual

Drop branch buffers to accommodate nbytes below MaxVirtualsize.

Definition at line 4522 of file TTree.cxx.

◆ EnableCache()

Bool_t TTree::EnableCache ( )

Enable the TTreeCache unless explicitly disabled for this TTree by a prior call to SetCacheSize(0).

If the environment variable ROOT_TTREECACHE_SIZE or the rootrc config TTreeCache.Size has been set to zero, this call will over-ride them with a value of 1.0 (i.e. use a cache size to hold 1 cluster)

Return true if there is a cache attached to the TTree (either pre-exisiting or created as part of this call)

Definition at line 2682 of file TTree.cxx.

◆ Fill()

Int_t TTree::Fill ( )
virtual

Fill all branches.

This function loops on all the branches of this tree. For each branch, it copies to the branch buffer (basket) the current values of the leaves data types. If a leaf is a simple data type, a simple conversion to a machine independent format has to be done.

This machine independent version of the data is copied into a basket (each branch has its own basket). When a basket is full (32k worth of data by default), it is then optionally compressed and written to disk (this operation is also called committing or 'flushing' the basket). The committed baskets are then immediately removed from memory.

The function returns the number of bytes committed to the individual branches.

If a write error occurs, the number of bytes returned is -1.

If no data are written, because, e.g., the branch is disabled, the number of bytes returned is 0.

The baskets are flushed and the Tree header saved at regular intervals

At regular intervals, when the amount of data written so far is greater than fAutoFlush (see SetAutoFlush) all the baskets are flushed to disk. This makes future reading faster as it guarantees that baskets belonging to nearby entries will be on the same disk region. When the first call to flush the baskets happen, we also take this opportunity to optimize the baskets buffers. We also check if the amount of data written is greater than fAutoSave (see SetAutoSave). In this case we also write the Tree header. This makes the Tree recoverable up to this point in case the program writing the Tree crashes. The decisions to FlushBaskets and Auto Save can be made based either on the number of bytes written (fAutoFlush and fAutoSave negative) or on the number of entries written (fAutoFlush and fAutoSave positive). Note that the user can decide to call FlushBaskets and AutoSave in her event loop base on the number of events written instead of the number of bytes written.

Note
Calling TTree::FlushBaskets too often increases the IO time.
Calling TTree::AutoSave too often increases the IO time and also the file size.
This method calls TTree::ChangeFile when the tree reaches a size greater than TTree::fgMaxTreeSize. This doesn't happen if the tree is attached to a TMemFile or derivate.

Reimplemented in TChain, TNtuple, TNtupleD, and TTreeSQL.

Definition at line 4594 of file TTree.cxx.

◆ FindBranch()

TBranch * TTree::FindBranch ( const char *  branchname)
virtual

Return the branch that correspond to the path 'branchname', which can include the name of the tree or the omitted name of the parent branches.

In case of ambiguity, returns the first match.

Reimplemented in TProofChain, and TChain.

Definition at line 4832 of file TTree.cxx.

◆ FindLeaf()

TLeaf * TTree::FindLeaf ( const char *  name)
virtual

Find leaf..

Reimplemented in TProofChain, and TChain.

Definition at line 4907 of file TTree.cxx.

◆ Fit()

Int_t TTree::Fit ( const char *  funcname,
const char *  varexp,
const char *  selection = "",
Option_t option = "",
Option_t goption = "",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)
virtual

Fit a projected item(s) from a tree.

funcname is a TF1 function.

See TTree::Draw() for explanations of the other parameters.

By default the temporary histogram created is called htemp. If varexp contains >>hnew , the new histogram created is called hnew and it is kept in the current directory.

The function returns the number of selected entries.

Example:

tree.Fit(pol4,"sqrt(x)>>hsqrt","y>0")

will fit sqrt(x) and save the histogram as "hsqrt" in the current directory.

See also TTree::UnbinnedFit

Return status

The function returns the status of the histogram fit (see TH1::Fit) If no entries were selected, the function returns -1; (i.e. fitResult is null if the fit is OK)

Definition at line 5070 of file TTree.cxx.

◆ FlushBaskets()

Int_t TTree::FlushBaskets ( Bool_t  create_cluster = true) const
virtual

Write to disk all the basket that have not yet been individually written and create an event cluster boundary (by default).

If the caller wishes to flush the baskets but not create an event cluster, then set create_cluster to false.

If ROOT has IMT-mode enabled, this will launch multiple TBB tasks in parallel via TThreadExecutor to do this operation; one per basket compression. If the caller utilizes TBB also, care must be taken to prevent deadlocks.

For example, let's say the caller holds mutex A and calls FlushBaskets; while TBB is waiting for the ROOT compression tasks to complete, it may decide to run another one of the user's tasks in this thread. If the second user task tries to acquire A, then a deadlock will occur. The example call sequence looks like this:

  • User acquires mutex A
  • User calls FlushBaskets.
  • ROOT launches N tasks and calls wait.
  • TBB schedules another user task, T2.
  • T2 tries to acquire mutex A.

At this point, the thread will deadlock: the code may function with IMT-mode disabled if the user assumed the legacy code never would run their own TBB tasks.

SO: users of TBB who want to enable IMT-mode should carefully review their locking patterns and make sure they hold no coarse-grained application locks when they invoke ROOT.

Return the number of bytes written or -1 in case of write error.

Definition at line 5120 of file TTree.cxx.

◆ FlushBasketsImpl()

Int_t TTree::FlushBasketsImpl ( ) const
private

Internal implementation of the FlushBaskets algorithm.

Unlike the public interface, this does NOT create an explicit event cluster boundary; it is up to the (internal) caller to determine whether that should done.

Otherwise, the comments for FlushBaskets applies.

Definition at line 5137 of file TTree.cxx.

◆ GetAlias()

const char * TTree::GetAlias ( const char *  aliasName) const
virtual

Returns the expanded value of the alias. Search in the friends if any.

Reimplemented in TChain.

Definition at line 5217 of file TTree.cxx.

◆ GetAllocationCount()

UInt_t TTree::GetAllocationCount ( ) const
inline

Definition at line 440 of file TTree.h.

◆ GetAutoFlush()

virtual Long64_t TTree::GetAutoFlush ( ) const
inlinevirtual

Definition at line 444 of file TTree.h.

◆ GetAutoSave()

virtual Long64_t TTree::GetAutoSave ( ) const
inlinevirtual

Definition at line 445 of file TTree.h.

◆ GetBranch()

TBranch * TTree::GetBranch ( const char *  name)
virtual

Return pointer to the branch with the given name in this tree or its friends.

The search is done breadth first.

Reimplemented in TProofChain, and TChain.

Definition at line 5285 of file TTree.cxx.

◆ GetBranchRef()

virtual TBranchRef * TTree::GetBranchRef ( ) const
inlinevirtual

Definition at line 447 of file TTree.h.

◆ GetBranchStatus()

Bool_t TTree::GetBranchStatus ( const char *  branchname) const
virtual

Return status of branch with name branchname.

  • 0 if branch is not activated
  • 1 if branch is activated

Reimplemented in TProofChain, and TChain.

Definition at line 5371 of file TTree.cxx.

◆ GetBranchStyle()

Int_t TTree::GetBranchStyle ( )
static

Static function returning the current branch style.

  • style = 0 old Branch
  • style = 1 new Bronch

Definition at line 5386 of file TTree.cxx.

◆ GetCacheAutoSize()

Long64_t TTree::GetCacheAutoSize ( Bool_t  withDefault = kFALSE)
protected

Used for automatic sizing of the cache.

Estimates a suitable size for the tree cache based on AutoFlush. A cache sizing factor is taken from the configuration. If this yields zero and withDefault is true the historical algorithm for default size is used.

Definition at line 5398 of file TTree.cxx.

◆ GetCacheSize()

virtual Long64_t TTree::GetCacheSize ( ) const
inlinevirtual

Reimplemented in TChain.

Definition at line 450 of file TTree.h.

◆ GetChainEntryNumber()

virtual Long64_t TTree::GetChainEntryNumber ( Long64_t  entry) const
inlinevirtual

Reimplemented in TChain.

Definition at line 452 of file TTree.h.

◆ GetChainOffset()

virtual Long64_t TTree::GetChainOffset ( ) const
inlinevirtual

Definition at line 453 of file TTree.h.

◆ GetClusterIterator()

TTree::TClusterIterator TTree::GetClusterIterator ( Long64_t  firstentry)
virtual

Return an iterator over the cluster of baskets starting at firstentry.

This iterator is not yet supported for TChain object.

TTree::TClusterIterator clusterIter = tree->GetClusterIterator(entry);
Long64_t clusterStart;
while( (clusterStart = clusterIter()) < tree->GetEntries() ) {
printf("The cluster starts at %lld and ends at %lld (inclusive)\n",clusterStart,clusterIter.GetNextEntry()-1);
}
Helper class to iterate over cluster of baskets.
Definition TTree.h:267
Long64_t GetNextEntry()
Definition TTree.h:304

Reimplemented in TChain.

Definition at line 5458 of file TTree.cxx.

◆ GetClusterPrefetch()

virtual Bool_t TTree::GetClusterPrefetch ( ) const
inlinevirtual

Definition at line 454 of file TTree.h.

◆ GetCurrentFile()

TFile * TTree::GetCurrentFile ( ) const

Return pointer to the current file.

Definition at line 5470 of file TTree.cxx.

◆ GetDebugMax()

Long64_t TTree::GetDebugMax ( ) const
inline

Definition at line 457 of file TTree.h.

◆ GetDebugMin()

Long64_t TTree::GetDebugMin ( ) const
inline

Definition at line 458 of file TTree.h.

◆ GetDefaultEntryOffsetLen()

Int_t TTree::GetDefaultEntryOffsetLen ( ) const
inline

Definition at line 456 of file TTree.h.

◆ GetDirectory()

TDirectory * TTree::GetDirectory ( ) const
inline

Definition at line 459 of file TTree.h.

◆ GetEntries() [1/2]

virtual Long64_t TTree::GetEntries ( ) const
inlinevirtual

Reimplemented in TProofChain, TChain, and TTreeSQL.

Definition at line 460 of file TTree.h.

◆ GetEntries() [2/2]

Long64_t TTree::GetEntries ( const char *  selection)
virtual

Return the number of entries matching the selection.

Return -1 in case of errors.

If the selection uses any arrays or containers, we return the number of entries where at least one element match the selection. GetEntries is implemented using the selector class TSelectorEntries, which can be used directly (see code in TTreePlayer::GetEntries) for additional option. If SetEventList was used on the TTree or TChain, only that subset of entries will be considered.

Reimplemented in TProofChain, TChain, and TTreeSQL.

Definition at line 5490 of file TTree.cxx.

◆ GetEntriesFast()

virtual Long64_t TTree::GetEntriesFast ( ) const
inlinevirtual

Reimplemented in TTreeSQL.

Definition at line 462 of file TTree.h.

◆ GetEntriesFriend()

Long64_t TTree::GetEntriesFriend ( ) const
virtual

Return pointer to the 1st Leaf named name in any Branch of this Tree or any branch in the list of friend trees.

Definition at line 5503 of file TTree.cxx.

◆ GetEntry()

Int_t TTree::GetEntry ( Long64_t  entry,
Int_t  getall = 0 
)
virtual

Read all branches of entry and return total number of bytes read.

  • getall = 0 : get only active branches
  • getall = 1 : get all branches

The function returns the number of bytes read from the input buffer. If entry does not exist the function returns 0. If an I/O error occurs, the function returns -1.

If the Tree has friends, also read the friends entry.

To activate/deactivate one or more branches, use TBranch::SetBranchStatus For example, if you have a Tree with several hundred branches, and you are interested only by branches named "a" and "b", do

mytree.SetBranchStatus("*",0); //disable all branches
mytree.SetBranchStatus("a",1);
mytree.SetBranchStatus("b",1);

when calling mytree.GetEntry(i); only branches "a" and "b" will be read.

WARNING!! If your Tree has been created in split mode with a parent branch "parent.",

mytree.SetBranchStatus("parent",1);

will not activate the sub-branches of "parent". You should do:

mytree.SetBranchStatus("parent*",1);

Without the trailing dot in the branch creation you have no choice but to call SetBranchStatus explicitly for each of the sub branches.

An alternative is to call directly

brancha.GetEntry(i)
branchb.GetEntry(i);

IMPORTANT NOTE

By default, GetEntry reuses the space allocated by the previous object for each branch. You can force the previous object to be automatically deleted if you call mybranch.SetAutoDelete(kTRUE) (default is kFALSE).

Example:

Consider the example in $ROOTSYS/test/Event.h The top level branch in the tree T is declared with:

Event *event = 0; //event must be null or point to a valid object
//it must be initialized
T.SetBranchAddress("event",&event);

When reading the Tree, one can choose one of these 3 options:

OPTION 1

for (Long64_t i=0;i<nentries;i++) {
T.GetEntry(i);
// the object event has been filled at this point
}

The default (recommended). At the first entry an object of the class Event will be created and pointed by event. At the following entries, event will be overwritten by the new data. All internal members that are TObject* are automatically deleted. It is important that these members be in a valid state when GetEntry is called. Pointers must be correctly initialized. However these internal members will not be deleted if the characters "->" are specified as the first characters in the comment field of the data member declaration.

If "->" is specified, the pointer member is read via pointer->Streamer(buf). In this case, it is assumed that the pointer is never null (case of pointer TClonesArray *fTracks in the Event example). If "->" is not specified, the pointer member is read via buf >> pointer. In this case the pointer may be null. Note that the option with "->" is faster to read or write and it also consumes less space in the file.

OPTION 2

The option AutoDelete is set

TBranch *branch = T.GetBranch("event");
branch->SetAddress(&event);
for (Long64_t i=0;i<nentries;i++) {
T.GetEntry(i);
// the object event has been filled at this point
}
A TTree is a list of TBranches.
Definition TBranch.h:89
virtual void SetAutoDelete(Bool_t autodel=kTRUE)
Set the automatic delete bit.
Definition TBranch.cxx:2662
virtual void SetAddress(void *add)
Set address of this branch.
Definition TBranch.cxx:2628

In this case, at each iteration, the object event is deleted by GetEntry and a new instance of Event is created and filled.

OPTION 3

Same as option 1, but you delete yourself the event.
for (Long64_t i=0;i<nentries;i++) {
delete event;
event = 0; // EXTREMELY IMPORTANT
T.GetEntry(i);
// the object event has been filled at this point
}
Option_t Option_t option

It is strongly recommended to use the default option 1. It has the additional advantage that functions like TTree::Draw (internally calling TTree::GetEntry) will be functional even when the classes in the file are not available.

Note: See the comments in TBranchElement::SetAddress() for the object ownership policy of the underlying (user) data.

Reimplemented in TChain, THbookTree, and TTreeSQL.

Definition at line 5629 of file TTree.cxx.

◆ GetEntryList()

TEntryList * TTree::GetEntryList ( )
virtual

Returns the entry list assigned to this tree.

Definition at line 5845 of file TTree.cxx.

◆ GetEntryNumber()

Long64_t TTree::GetEntryNumber ( Long64_t  entry) const
virtual

Return entry number corresponding to entry.

if no TEntryList set returns entry else returns the entry number corresponding to the list index=entry

Reimplemented in TChain.

Definition at line 5856 of file TTree.cxx.

◆ GetEntryNumberWithBestIndex()

Long64_t TTree::GetEntryNumberWithBestIndex ( Long64_t  major,
Long64_t  minor = 0 
) const
virtual

Return entry number corresponding to major and minor number.

Note that this function returns only the entry number, not the data To read the data corresponding to an entry number, use TTree::GetEntryWithIndex the BuildIndex function has created a table of Long64_t* of sorted values corresponding to val = major<<31 + minor; The function performs binary search in this sorted table. If it finds a pair that matches val, it returns directly the index in the table. If an entry corresponding to major and minor is not found, the function returns the index of the major,minor pair immediately lower than the requested value, ie it will return -1 if the pair is lower than the first entry in the index.

See also GetEntryNumberWithIndex

Definition at line 5881 of file TTree.cxx.

◆ GetEntryNumberWithIndex()

Long64_t TTree::GetEntryNumberWithIndex ( Long64_t  major,
Long64_t  minor = 0 
) const
virtual

Return entry number corresponding to major and minor number.

Note that this function returns only the entry number, not the data To read the data corresponding to an entry number, use TTree::GetEntryWithIndex the BuildIndex function has created a table of Long64_t* of sorted values corresponding to val = major<<31 + minor; The function performs binary search in this sorted table. If it finds a pair that matches val, it returns directly the index in the table, otherwise it returns -1.

See also GetEntryNumberWithBestIndex

Definition at line 5901 of file TTree.cxx.

◆ GetEntryWithIndex()

Int_t TTree::GetEntryWithIndex ( Int_t  major,
Int_t  minor = 0 
)
virtual

Read entry corresponding to major and minor number.

The function returns the total number of bytes read. If the Tree has friend trees, the corresponding entry with the index values (major,minor) is read. Note that the master Tree and its friend may have different entry serial numbers corresponding to (major,minor).

Reimplemented in TChain.

Definition at line 5918 of file TTree.cxx.

◆ GetEstimate()

virtual Long64_t TTree::GetEstimate ( ) const
inlinevirtual

Definition at line 464 of file TTree.h.

◆ GetEvent()

Int_t TTree::GetEvent ( Long64_t  entry,
Int_t  getall = 0 
)
inline

Definition at line 466 of file TTree.h.

◆ GetEventList()

TEventList * TTree::GetEventList ( ) const
inline

Definition at line 470 of file TTree.h.

◆ GetFileNumber()

virtual Int_t TTree::GetFileNumber ( ) const
inlinevirtual

Definition at line 473 of file TTree.h.

◆ GetFriend()

TTree * TTree::GetFriend ( const char *  friendname) const
virtual

Return a pointer to the TTree friend whose name or alias is friendname.

Definition at line 5966 of file TTree.cxx.

◆ GetFriendAlias()

const char * TTree::GetFriendAlias ( TTree tree) const
virtual

If the 'tree' is a friend, this method returns its alias name.

This alias is an alternate name for the tree.

It can be used in conjunction with a branch or leaf name in a TTreeFormula, to specify in which particular tree the branch or leaf can be found if the friend trees have branches or leaves with the same name as the master tree.

It can also be used in conjunction with an alias created using TTree::SetAlias in a TTreeFormula, e.g.:

maintree->Draw("treealias.fPx - treealias.myAlias");

where fPx is a branch of the friend tree aliased as 'treealias' and 'myAlias' was created using TTree::SetAlias on the friend tree.

However, note that 'treealias.myAlias' will be expanded literally, without remembering that it comes from the aliased friend and thus the branch name might not be disambiguated properly, which means that you may not be able to take advantage of this feature.

Definition at line 6023 of file TTree.cxx.

◆ GetHistogram()

TH1 * TTree::GetHistogram ( )
inline

Definition at line 476 of file TTree.h.

◆ GetImplicitMT()

virtual Bool_t TTree::GetImplicitMT ( )
inlinevirtual

Definition at line 477 of file TTree.h.

◆ GetIndex()

virtual Int_t * TTree::GetIndex ( )
inlinevirtual

Definition at line 478 of file TTree.h.

◆ GetIndexValues()

virtual Double_t * TTree::GetIndexValues ( )
inlinevirtual

Definition at line 479 of file TTree.h.

◆ GetIOFeatures()

ROOT::TIOFeatures TTree::GetIOFeatures ( ) const

Returns the current set of IO settings.

Definition at line 6065 of file TTree.cxx.

◆ GetIteratorOnAllLeaves()

TIterator * TTree::GetIteratorOnAllLeaves ( Bool_t  dir = kIterForward)
virtual

Creates a new iterator that will go through all the leaves on the tree itself and its friend.

Definition at line 6073 of file TTree.cxx.

◆ GetLeaf() [1/2]

TLeaf * TTree::GetLeaf ( const char *  branchname,
const char *  leafname 
)
virtual

Return pointer to the 1st Leaf named name in any Branch of this Tree or any branch in the list of friend trees.

The leaf name can contain the name of a friend tree with the syntax: friend_dir_and_tree.full_leaf_name the friend_dir_and_tree can be of the form:

TDirectoryName/TreeName 

Reimplemented in TChain.

Definition at line 6186 of file TTree.cxx.

◆ GetLeaf() [2/2]

TLeaf * TTree::GetLeaf ( const char *  name)
virtual

Return pointer to first leaf named "name" in any branch of this tree or its friend trees.

Parameters
[in]namemay be in the form 'branch/leaf'

Reimplemented in TChain.

Definition at line 6206 of file TTree.cxx.

◆ GetLeafImpl()

TLeaf * TTree::GetLeafImpl ( const char *  branchname,
const char *  leafname 
)
protectedvirtual

Return pointer to the 1st Leaf named name in any Branch of this Tree or any branch in the list of friend trees.

The leaf name can contain the name of a friend tree with the syntax: friend_dir_and_tree.full_leaf_name the friend_dir_and_tree can be of the form:

TDirectoryName/TreeName

Definition at line 6089 of file TTree.cxx.

◆ GetListOfAliases()

virtual TList * TTree::GetListOfAliases ( ) const
inlinevirtual

Reimplemented in TProofChain.

Definition at line 488 of file TTree.h.

◆ GetListOfBranches()

virtual TObjArray * TTree::GetListOfBranches ( )
inlinevirtual

Reimplemented in TProofChain, and TChain.

Definition at line 485 of file TTree.h.

◆ GetListOfClones()

virtual TList * TTree::GetListOfClones ( )
inlinevirtual

Reimplemented in TProofChain.

Definition at line 484 of file TTree.h.

◆ GetListOfFriends()

virtual TList * TTree::GetListOfFriends ( ) const
inlinevirtual

Reimplemented in TProofChain.

Definition at line 487 of file TTree.h.

◆ GetListOfLeaves()

virtual TObjArray * TTree::GetListOfLeaves ( )
inlinevirtual

Reimplemented in TProofChain, and TChain.

Definition at line 486 of file TTree.h.

◆ GetMakeClass()

Int_t TTree::GetMakeClass ( ) const
inline

Definition at line 492 of file TTree.h.

◆ GetMaxEntryLoop()

virtual Long64_t TTree::GetMaxEntryLoop ( ) const
inlinevirtual

Definition at line 494 of file TTree.h.

◆ GetMaximum()

Double_t TTree::GetMaximum ( const char *  columname)
virtual

Return maximum of column with name columname.

if the Tree has an associated TEventList or TEntryList, the maximum is computed for the entries in this list.

Reimplemented in TChain.

Definition at line 6226 of file TTree.cxx.

◆ GetMaxTreeSize()

Long64_t TTree::GetMaxTreeSize ( )
static

Static function which returns the tree file size limit in bytes.

Definition at line 6256 of file TTree.cxx.

◆ GetMaxVirtualSize()

virtual Long64_t TTree::GetMaxVirtualSize ( ) const
inlinevirtual

Definition at line 497 of file TTree.h.

◆ GetMedianClusterSize()

Long64_t TTree::GetMedianClusterSize ( )
private

Estimate the median cluster size for the TTree.

This value provides e.g. a reasonable cache size default if other heuristics fail. Clusters with size 0 and the very last cluster range, that might not have been committed to fClusterSize yet, are ignored for the purposes of the calculation.

Definition at line 8283 of file TTree.cxx.

◆ GetMinimum()

Double_t TTree::GetMinimum ( const char *  columname)
virtual

Return minimum of column with name columname.

if the Tree has an associated TEventList or TEntryList, the minimum is computed for the entries in this list.

Reimplemented in TChain.

Definition at line 6266 of file TTree.cxx.

◆ GetNbranches()

virtual Int_t TTree::GetNbranches ( )
inlinevirtual

Reimplemented in TChain.

Definition at line 499 of file TTree.h.

◆ GetNewlineValue()

char TTree::GetNewlineValue ( std::istream &  inputStream)
protected

Determine which newline this file is using.

Return '\r' for Windows '\r\n' as that already terminates.

Definition at line 7579 of file TTree.cxx.

◆ GetNotify()

TObject * TTree::GetNotify ( ) const
inline

Definition at line 500 of file TTree.h.

◆ GetPacketSize()

virtual Int_t TTree::GetPacketSize ( ) const
inlinevirtual

Definition at line 502 of file TTree.h.

◆ GetPerfStats()

virtual TVirtualPerfStats * TTree::GetPerfStats ( ) const
inlinevirtual

Definition at line 503 of file TTree.h.

◆ GetPlayer()

TVirtualTreePlayer * TTree::GetPlayer ( )

Load the TTreePlayer (if not already done).

Definition at line 6296 of file TTree.cxx.

◆ GetReadCache() [1/2]

TTreeCache * TTree::GetReadCache ( TFile file) const

Find and return the TTreeCache registered with the file and which may contain branches for us.

Definition at line 6309 of file TTree.cxx.

◆ GetReadCache() [2/2]

TTreeCache * TTree::GetReadCache ( TFile file,
Bool_t  create 
)

Find and return the TTreeCache registered with the file and which may contain branches for us.

If create is true and there is no cache a new cache is created with default size.

Definition at line 6322 of file TTree.cxx.

◆ GetReadEntry()

virtual Long64_t TTree::GetReadEntry ( ) const
inlinevirtual

Reimplemented in TProofChain, and TChain.

Definition at line 506 of file TTree.h.

◆ GetReadEvent()

virtual Long64_t TTree::GetReadEvent ( ) const
inlinevirtual

Definition at line 507 of file TTree.h.

◆ GetScanField()

virtual Int_t TTree::GetScanField ( ) const
inlinevirtual

Definition at line 508 of file TTree.h.

◆ GetSelect()

TTreeFormula * TTree::GetSelect ( )
inline

Definition at line 509 of file TTree.h.

◆ GetSelectedRows()

virtual Long64_t TTree::GetSelectedRows ( )
inlinevirtual

Definition at line 510 of file TTree.h.

◆ GetTargetMemoryRatio()

Float_t TTree::GetTargetMemoryRatio ( ) const
inline

Definition at line 517 of file TTree.h.

◆ GetTimerInterval()

virtual Int_t TTree::GetTimerInterval ( ) const
inlinevirtual

Definition at line 511 of file TTree.h.

◆ GetTotBytes()

virtual Long64_t TTree::GetTotBytes ( ) const
inlinevirtual

Definition at line 513 of file TTree.h.

◆ GetTransientBuffer()

TBuffer * TTree::GetTransientBuffer ( Int_t  size)

Returns the transient buffer currently used by this TTree for reading/writing baskets.

Definition at line 1036 of file TTree.cxx.

◆ GetTree()

virtual TTree * TTree::GetTree ( ) const
inlinevirtual

Reimplemented in TChain.

Definition at line 514 of file TTree.h.

◆ GetTreeIndex()

virtual TVirtualIndex * TTree::GetTreeIndex ( ) const
inlinevirtual

Definition at line 515 of file TTree.h.

◆ GetTreeNumber()

virtual Int_t TTree::GetTreeNumber ( ) const
inlinevirtual

Reimplemented in TChain.

Definition at line 516 of file TTree.h.

◆ GetUpdate()

virtual Int_t TTree::GetUpdate ( ) const
inlinevirtual

Definition at line 518 of file TTree.h.

◆ GetUserInfo()

TList * TTree::GetUserInfo ( )
virtual

Return a pointer to the list containing user objects associated to this tree.

The list is automatically created if it does not exist.

WARNING: By default the TTree destructor will delete all objects added to this list. If you do not want these objects to be deleted, call:

mytree->GetUserInfo()->Clear();

before deleting the tree.

Definition at line 6347 of file TTree.cxx.

◆ GetV1()

virtual Double_t * TTree::GetV1 ( )
inlinevirtual

Definition at line 533 of file TTree.h.

◆ GetV2()

virtual Double_t * TTree::GetV2 ( )
inlinevirtual

Definition at line 535 of file TTree.h.

◆ GetV3()

virtual Double_t * TTree::GetV3 ( )
inlinevirtual

Definition at line 537 of file TTree.h.

◆ GetV4()

virtual Double_t * TTree::GetV4 ( )
inlinevirtual

Definition at line 539 of file TTree.h.

◆ GetVal()

virtual Double_t * TTree::GetVal ( Int_t  i)
inlinevirtual

Definition at line 531 of file TTree.h.

◆ GetVar()

TTreeFormula * TTree::GetVar ( Int_t  i)
inline

Definition at line 521 of file TTree.h.

◆ GetVar1()

TTreeFormula * TTree::GetVar1 ( )
inline

Definition at line 523 of file TTree.h.

◆ GetVar2()

TTreeFormula * TTree::GetVar2 ( )
inline

Definition at line 525 of file TTree.h.

◆ GetVar3()

TTreeFormula * TTree::GetVar3 ( )
inline

Definition at line 527 of file TTree.h.

◆ GetVar4()

TTreeFormula * TTree::GetVar4 ( )
inline

Definition at line 529 of file TTree.h.

◆ GetW()

virtual Double_t * TTree::GetW ( )
inlinevirtual

Definition at line 540 of file TTree.h.

◆ GetWeight()

virtual Double_t TTree::GetWeight ( ) const
inlinevirtual

Reimplemented in TChain.

Definition at line 541 of file TTree.h.

◆ GetZipBytes()

virtual Long64_t TTree::GetZipBytes ( ) const
inlinevirtual

Definition at line 542 of file TTree.h.

◆ ImportClusterRanges()

void TTree::ImportClusterRanges ( TTree fromtree)
protected

Appends the cluster range information stored in 'fromtree' to this tree, including the value of fAutoFlush.

This is used when doing a fast cloning (by TTreeCloner). See also fAutoFlush and fAutoSave if needed.

Definition at line 6363 of file TTree.cxx.

◆ IncrementTotalBuffers()

virtual void TTree::IncrementTotalBuffers ( Int_t  nbytes)
inlinevirtual

Definition at line 543 of file TTree.h.

◆ InitializeBranchLists()

void TTree::InitializeBranchLists ( bool  checkLeafCount)
private

Divides the top-level branches into two vectors: (i) branches to be processed sequentially and (ii) branches to be processed in parallel.

Even if IMT is on, some branches might need to be processed first and in a sequential fashion: in the parallelization of GetEntry, those are the branches that store the size of another branch for every entry (e.g. the size of an array branch). If such branches were processed in parallel with the rest, there could be two threads invoking TBranch::GetEntry on one of them at the same time, since a branch that depends on a size (or count) branch will also invoke GetEntry on the latter. This method can be invoked several times during the event loop if the TTree is being written, for example when adding new branches. In these cases, the checkLeafCount parameter is false.

Parameters
[in]checkLeafCountTrue if we need to check whether some branches are count leaves.

Definition at line 5772 of file TTree.cxx.

◆ InPlaceClone()

Bool_t TTree::InPlaceClone ( TDirectory newdirectory,
const char *  options = "" 
)
virtual

Copy the content to a new new file, update this TTree with the new location information and attach this TTree to the new directory.

options: Indicates a basket sorting method, see TTreeCloner::TTreeCloner for details

If new and old directory are in the same file, the data is untouched, this "just" does a call to SetDirectory. Equivalent to an "in place" cloning of the TTree.

Reimplemented in TChain.

Definition at line 7003 of file TTree.cxx.

◆ IsA()

TClass * TTree::IsA ( ) const
inlineoverridevirtual
Returns
TClass describing current object

Reimplemented from TNamed.

Reimplemented in TTreeSQL.

Definition at line 654 of file TTree.h.

◆ IsFolder()

Bool_t TTree::IsFolder ( ) const
inlineoverridevirtual

Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).

Reimplemented from TObject.

Definition at line 544 of file TTree.h.

◆ KeepCircular()

void TTree::KeepCircular ( )
protectedvirtual

Keep a maximum of fMaxEntries in memory.

Definition at line 6406 of file TTree.cxx.

◆ LoadBaskets()

Int_t TTree::LoadBaskets ( Long64_t  maxmemory = 2000000000)
virtual

Read in memory all baskets from all branches up to the limit of maxmemory bytes.

If maxmemory is non null and positive SetMaxVirtualSize is called with this value. Default for maxmemory is 2000000000 (2 Gigabytes). The function returns the total number of baskets read into memory if negative an error occurred while loading the branches. This method may be called to force branch baskets in memory when random access to branch entries is required. If random access to only a few branches is required, you should call directly TBranch::LoadBaskets.

Reimplemented in TChain.

Definition at line 6442 of file TTree.cxx.

◆ LoadTree()

Long64_t TTree::LoadTree ( Long64_t  entry)
virtual

Set current entry.

Returns -2 if entry does not exist (just as TChain::LoadTree()). Returns -6 if an error occurs in the notification callback (just as TChain::LoadTree()).

Note: This function is overloaded in TChain.

Reimplemented in TChain, and TTreeSQL.

Definition at line 6464 of file TTree.cxx.

◆ LoadTreeFriend()

Long64_t TTree::LoadTreeFriend ( Long64_t  entry,
TTree masterTree 
)
virtual

Load entry on behalf of our master tree, we may use an index.

Called by LoadTree() when the masterTree looks for the entry number in a friend tree (us) corresponding to the passed entry number in the masterTree.

If we have no index, our entry number and the masterTree entry number are the same.

If we do have an index, we must find the (major, minor) value pair in masterTree to locate our corresponding entry.

Definition at line 6548 of file TTree.cxx.

◆ MakeClass()

Int_t TTree::MakeClass ( const char *  classname = nullptr,
Option_t option = "" 
)
virtual

Generate a skeleton analysis class for this tree.

The following files are produced: classname.h and classname.C. If classname is 0, classname will be called "nameoftree".

The generated code in classname.h includes the following:

  • Identification of the original tree and the input file name.
  • Definition of an analysis class (data members and member functions).
  • The following member functions:
    • constructor (by default opening the tree file),
    • GetEntry(Long64_t entry),
    • Init(TTree* tree) to initialize a new TTree,
    • Show(Long64_t entry) to read and dump entry.

The generated code in classname.C includes only the main analysis function Loop.

To use this function:

  • Open your tree file (eg: TFile f("myfile.root");)
  • T->MakeClass("MyClass");

where T is the name of the TTree in file myfile.root, and MyClass.h, MyClass.C the name of the files created by this function. In a ROOT session, you can do:

root > .L MyClass.C
root > MyClass* t = new MyClass;
root > t->GetEntry(12); // Fill data members of t with entry number 12.
root > t->Show(); // Show values of entry 12.
root > t->Show(16); // Read and show values of entry 16.
root > t->Loop(); // Loop on all entries.

NOTE: Do not use the code generated for a single TTree which is part of a TChain to process that entire TChain. The maximum dimensions calculated for arrays on the basis of a single TTree from the TChain might be (will be!) too small when processing all of the TTrees in the TChain. You must use myChain.MakeClass() to generate the code, not myTree.MakeClass(...).

Definition at line 6598 of file TTree.cxx.

◆ MakeCode()

Int_t TTree::MakeCode ( const char *  filename = nullptr)
virtual

Generate a skeleton function for this tree.

The function code is written on filename. If filename is 0, filename will be called nameoftree.C

The generated code includes the following:

  • Identification of the original Tree and Input file name,
  • Opening the Tree file,
  • Declaration of Tree variables,
  • Setting of branches addresses,
  • A skeleton for the entry loop.

To use this function:

  • Open your Tree file (eg: TFile f("myfile.root");)
  • T->MakeCode("MyAnalysis.C");

where T is the name of the TTree in file myfile.root and MyAnalysis.C the name of the file created by this function.

NOTE: Since the implementation of this function, a new and better function TTree::MakeClass() has been developed.

Definition at line 6631 of file TTree.cxx.

◆ MakeProxy()

Int_t TTree::MakeProxy ( const char *  proxyClassname,
const char *  macrofilename = nullptr,
const char *  cutfilename = nullptr,
const char *  option = nullptr,
Int_t  maxUnrolling = 3 
)
virtual

Generate a skeleton analysis class for this Tree using TBranchProxy.

TBranchProxy is the base of a class hierarchy implementing an indirect access to the content of the branches of a TTree.

"proxyClassname" is expected to be of the form:

[path/]fileprefix

The skeleton will then be generated in the file:

fileprefix.h

located in the current directory or in 'path/' if it is specified. The class generated will be named 'fileprefix'

"macrofilename" and optionally "cutfilename" are expected to point to source files which will be included by the generated skeleton. Method of the same name as the file(minus the extension and path) will be called by the generated skeleton's Process method as follow:

[if (cutfilename())] htemp->Fill(macrofilename());

"option" can be used select some of the optional features during the code generation. The possible options are:

  • nohist : indicates that the generated ProcessFill should not fill the histogram.

'maxUnrolling' controls how deep in the class hierarchy does the system 'unroll' classes that are not split. Unrolling a class allows direct access to its data members (this emulates the behavior of TTreeFormula).

The main features of this skeleton are:

  • on-demand loading of branches
  • ability to use the 'branchname' as if it was a data member
  • protection against array out-of-bounds errors
  • ability to use the branch data as an object (when the user code is available)

For example with Event.root, if

Double_t somePx = fTracks.fPx[2];

is executed by one of the method of the skeleton, somePx will updated with the current value of fPx of the 3rd track.

Both macrofilename and the optional cutfilename are expected to be the name of source files which contain at least a free standing function with the signature:

x_t macrofilename(); // i.e function with the same name as the file

and

y_t cutfilename(); // i.e function with the same name as the file

x_t and y_t needs to be types that can convert respectively to a double and a bool (because the skeleton uses:

if (cutfilename()) htemp->Fill(macrofilename());

These two functions are run in a context such that the branch names are available as local variables of the correct (read-only) type.

Note that if you use the same 'variable' twice, it is more efficient to 'cache' the value. For example:

Int_t n = fEventNumber; // Read fEventNumber
if (n<10 || n>10) { ... }
const Int_t n
Definition legend1.C:16

is more efficient than

if (fEventNumber<10 || fEventNumber>10)

Also, optionally, the generated selector will also call methods named macrofilename_methodname in each of 6 main selector methods if the method macrofilename_methodname exist (Where macrofilename is stripped of its extension).

Concretely, with the script named h1analysisProxy.C,

  • The method calls the method (if it exist)
  • Begin -> void h1analysisProxy_Begin(TTree*);
  • SlaveBegin -> void h1analysisProxy_SlaveBegin(TTree*);
  • Notify -> Bool_t h1analysisProxy_Notify();
  • Process -> Bool_t h1analysisProxy_Process(Long64_t);
  • SlaveTerminate -> void h1analysisProxy_SlaveTerminate();
  • Terminate -> void h1analysisProxy_Terminate();

If a file name macrofilename.h (or .hh, .hpp, .hxx, .hPP, .hXX) exist it is included before the declaration of the proxy class. This can be used in particular to insure that the include files needed by the macro file are properly loaded.

The default histogram is accessible via the variable named 'htemp'.

If the library of the classes describing the data in the branch is loaded, the skeleton will add the needed include statements and give the ability to access the object stored in the branches.

To draw px using the file hsimple.root (generated by the hsimple.C tutorial), we need a file named hsimple.cxx:

double hsimple() {
return px;
}

MakeProxy can then be used indirectly via the TTree::Draw interface as follow:

new TFile("hsimple.root")
ntuple->Draw("hsimple.cxx");

A more complete example is available in the tutorials directory: h1analysisProxy.cxx , h1analysProxy.h and h1analysisProxyCut.C which reimplement the selector found in h1analysis.C

Definition at line 6759 of file TTree.cxx.

◆ MakeSelector()

Int_t TTree::MakeSelector ( const char *  selector = nullptr,
Option_t option = "" 
)
virtual

Generate skeleton selector class for this tree.

The following files are produced: selector.h and selector.C. If selector is 0, the selector will be called "nameoftree". The option can be used to specify the branches that will have a data member.

  • If option is "=legacy", a pre-ROOT6 selector will be generated (data members and branch pointers instead of TTreeReaders).
  • If option is empty, readers will be generated for each leaf.
  • If option is "@", readers will be generated for the topmost branches.
  • Individual branches can also be picked by their name:
    • "X" generates readers for leaves of X.
    • "@X" generates a reader for X as a whole.
    • "@X;Y" generates a reader for X as a whole and also readers for the leaves of Y.
  • For further examples see the figure below.

The generated code in selector.h includes the following:

  • Identification of the original Tree and Input file name
  • Definition of selector class (data and functions)
  • The following class functions:
    • constructor and destructor
    • void Begin(TTree *tree)
    • void SlaveBegin(TTree *tree)
    • void Init(TTree *tree)
    • Bool_t Notify()
    • Bool_t Process(Long64_t entry)
    • void Terminate()
    • void SlaveTerminate()

The class selector derives from TSelector. The generated code in selector.C includes empty functions defined above.

To use this function:

  • connect your Tree file (eg: TFile f("myfile.root");)
  • T->MakeSelector("myselect");

where T is the name of the Tree in file myfile.root and myselect.h, myselect.C the name of the files created by this function. In a ROOT session, you can do:

root > T->Process("myselect.C")

Definition at line 6813 of file TTree.cxx.

◆ MarkEventCluster()

void TTree::MarkEventCluster ( )
private

Mark the previous event as being at the end of the event cluster.

So, if fEntries is set to 10 (and this is the first cluster) when MarkEventCluster is called, then the first cluster has 9 events.

Definition at line 8244 of file TTree.cxx.

◆ MemoryFull()

Bool_t TTree::MemoryFull ( Int_t  nbytes)

Check if adding nbytes to memory we are still below MaxVirtualsize.

Definition at line 6828 of file TTree.cxx.

◆ Merge() [1/2]

Long64_t TTree::Merge ( TCollection li,
Option_t options = "" 
)
virtual

Merge the trees in the TList into this tree.

Returns the total number of entries in the merged tree.

Reimplemented in TChain.

Definition at line 6881 of file TTree.cxx.

◆ Merge() [2/2]

Long64_t TTree::Merge ( TCollection li,
TFileMergeInfo info 
)
virtual

Merge the trees in the TList into this tree.

If info->fIsFirst is true, first we clone this TTree info the directory info->fOutputDirectory and then overlay the new TTree information onto this TTree object (so that this TTree object is now the appropriate to use for further merging).

Returns the total number of entries in the merged tree.

Reimplemented in TChain.

Definition at line 6918 of file TTree.cxx.

◆ MergeTrees()

TTree * TTree::MergeTrees ( TList li,
Option_t options = "" 
)
static

Static function merging the trees in the TList into a new tree.

Trees in the list can be memory or disk-resident trees. The new tree is created in the current directory (memory if gROOT).

Definition at line 6842 of file TTree.cxx.

◆ MoveReadCache()

void TTree::MoveReadCache ( TFile src,
TDirectory dir 
)
protected

Move a cache from a file to the current file in dir.

if src is null no operation is done, if dir is null or there is no current file the cache is deleted.

Definition at line 6974 of file TTree.cxx.

◆ Notify()

Bool_t TTree::Notify ( )
overridevirtual

Function called when loading a new class library.

Reimplemented from TObject.

Definition at line 7024 of file TTree.cxx.

◆ operator=()

TTree & TTree::operator= ( const TTree tt)
delete

◆ OptimizeBaskets()

void TTree::OptimizeBaskets ( ULong64_t  maxMemory = 10000000,
Float_t  minComp = 1.1,
Option_t option = "" 
)
virtual

This function may be called after having filled some entries in a Tree.

Using the information in the existing branch buffers, it will reassign new branch buffer sizes to optimize time and memory.

The function computes the best values for branch buffer sizes such that the total buffer sizes is less than maxMemory and nearby entries written at the same time. In case the branch compression factor for the data written so far is less than compMin, the compression is disabled.

if option ="d" an analysis report is printed.

Definition at line 7048 of file TTree.cxx.

◆ Principal()

TPrincipal * TTree::Principal ( const char *  varexp = "",
const char *  selection = "",
Option_t option = "np",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)

Interface to the Principal Components Analysis class.

Create an instance of TPrincipal

Fill it with the selected variables

  • if option "n" is specified, the TPrincipal object is filled with normalized variables.
  • If option "p" is specified, compute the principal components
  • If option "p" and "d" print results of analysis
  • If option "p" and "h" generate standard histograms
  • If option "p" and "c" generate code of conversion functions
  • return a pointer to the TPrincipal object. It is the user responsibility
  • to delete this object.
  • The option default value is "np"

see TTree::Draw for explanation of the other parameters.

The created object is named "principal" and a reference to it is added to the list of specials Root objects. you can retrieve a pointer to the created object via:

(TPrincipal*)gROOT->GetListOfSpecials()->FindObject("principal");
#define gROOT
Definition TROOT.h:405
Principal Components Analysis (PCA)
Definition TPrincipal.h:21

Definition at line 7191 of file TTree.cxx.

◆ Print()

void TTree::Print ( Option_t option = "") const
overridevirtual

Print a summary of the tree contents.

  • If option contains "all" friend trees are also printed.
  • If option contains "toponly" only the top level branches are printed.
  • If option contains "clusters" information about the cluster of baskets is printed.

Wildcarding can be used to print only a subset of the branches, e.g., T.Print("Elec*") will print all branches with name starting with "Elec".

Reimplemented from TNamed.

Definition at line 7210 of file TTree.cxx.

◆ PrintCacheStats()

void TTree::PrintCacheStats ( Option_t option = "") const
virtual

Print statistics about the TreeCache for this tree.

Like:

******TreeCache statistics for file: cms2.root ******
Reading 73921562 bytes in 716 transactions
Average transaction = 103.242405 Kbytes
Number of blocks in current cache: 202, total size : 6001193
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
static unsigned int total
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t bytes
void statistics(struct mesh *m, struct behavior *b)
Definition triangle.c:15546

if option = "a" the list of blocks in the cache is printed

Definition at line 7361 of file TTree.cxx.

◆ Process() [1/2]

Long64_t TTree::Process ( const char *  filename,
Option_t option = "",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)
virtual

Process this tree executing the TSelector code in the specified filename.

The return value is -1 in case of error and TSelector::GetStatus() in in case of success.

The code in filename is loaded (interpreted or compiled, see below), filename must contain a valid class implementation derived from TSelector, where TSelector has the following member functions:

  • Begin(): called every time a loop on the tree starts, a convenient place to create your histograms.
  • SlaveBegin(): called after Begin(), when on PROOF called only on the slave servers.
  • Process(): called for each event, in this function you decide what to read and fill your histograms.
  • SlaveTerminate: called at the end of the loop on the tree, when on PROOF called only on the slave servers.
  • Terminate(): called at the end of the loop on the tree, a convenient place to draw/fit your histograms.

If filename is of the form file.C, the file will be interpreted.

If filename is of the form file.C++, the file file.C will be compiled and dynamically loaded.

If filename is of the form file.C+, the file file.C will be compiled and dynamically loaded. At next call, if file.C is older than file.o and file.so, the file.C is not compiled, only file.so is loaded.

NOTE1

It may be more interesting to invoke directly the other Process function accepting a TSelector* as argument.eg

MySelector *selector = (MySelector*)TSelector::GetSelector(filename);
selector->CallSomeFunction(..);
mytree.Process(selector,..);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
virtual Bool_t Process(Long64_t)
The Process() function is called for each entry in the tree (or possibly keyed object in the case of ...
static TSelector * GetSelector(const char *filename)
The code in filename is loaded (interpreted or compiled, see below), filename must contain a valid cl...

NOTE2

One should not call this function twice with the same selector file in the same script. If this is required, proceed as indicated in NOTE1, by getting a pointer to the corresponding TSelector,eg

Workaround 1

void stubs1() {
TSelector *selector = TSelector::GetSelector("h1test.C");
TFile *f1 = new TFile("stubs_nood_le1.root");
TTree *h1 = (TTree*)f1->Get("h1");
h1->Process(selector);
TFile *f2 = new TFile("stubs_nood_le1_coarse.root");
TTree *h2 = (TTree*)f2->Get("h1");
h2->Process(selector);
}
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A TSelector object is used by the TTree::Draw, TTree::Scan, TTree::Process to navigate in a TTree and...
Definition TSelector.h:31
virtual Long64_t Process(const char *filename, Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
Process this tree executing the TSelector code in the specified filename.
Definition TTree.cxx:7441
TH1F * h1
Definition legend1.C:5
TF1 * f1
Definition legend1.C:11

or use ACLIC to compile the selector

Workaround 2

void stubs2() {
TFile *f1 = new TFile("stubs_nood_le1.root");
TTree *h1 = (TTree*)f1->Get("h1");
h1->Process("h1test.C+");
TFile *f2 = new TFile("stubs_nood_le1_coarse.root");
TTree *h2 = (TTree*)f2->Get("h1");
h2->Process("h1test.C+");
}

Reimplemented in TChain, and TProofChain.

Definition at line 7441 of file TTree.cxx.

◆ Process() [2/2]

Long64_t TTree::Process ( TSelector selector,
Option_t option = "",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)
virtual

Process this tree executing the code in the specified selector.

The return value is -1 in case of error and TSelector::GetStatus() in in case of success.

The TSelector class has the following member functions:

  • Begin(): called every time a loop on the tree starts, a convenient place to create your histograms.
  • SlaveBegin(): called after Begin(), when on PROOF called only on the slave servers.
  • Process(): called for each event, in this function you decide what to read and fill your histograms.
  • SlaveTerminate: called at the end of the loop on the tree, when on PROOF called only on the slave servers.
  • Terminate(): called at the end of the loop on the tree, a convenient place to draw/fit your histograms.

    If the Tree (Chain) has an associated EventList, the loop is on the nentries of the EventList, starting at firstentry, otherwise the loop is on the specified Tree entries.

Reimplemented in TChain, and TProofChain.

Definition at line 7472 of file TTree.cxx.

◆ Project()

Long64_t TTree::Project ( const char *  hname,
const char *  varexp,
const char *  selection = "",
Option_t option = "",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)
virtual

Make a projection of a tree using selections.

Depending on the value of varexp (described in Draw) a 1-D, 2-D, etc., projection of the tree will be filled in histogram hname. Note that the dimension of hname must match with the dimension of varexp.

Definition at line 7489 of file TTree.cxx.

◆ Query()

TSQLResult * TTree::Query ( const char *  varexp = "",
const char *  selection = "",
Option_t option = "",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)
virtual

Loop over entries and return a TSQLResult object containing entries following selection.

Definition at line 7504 of file TTree.cxx.

◆ ReadFile()

Long64_t TTree::ReadFile ( const char *  filename,
const char *  branchDescriptor = "",
char  delimiter = ' ' 
)
virtual

Create or simply read branches from filename.

if branchDescriptor = "" (default), it is assumed that the Tree descriptor is given in the first line of the file with a syntax like

A/D:Table[2]/F:Ntracks/I:astring/C
#define F(x, y, z)
#define I(x, y, z)

otherwise branchDescriptor must be specified with the above syntax.

  • If the type of the first variable is not specified, it is assumed to be "/F"
  • If the type of any other variable is not specified, the type of the previous variable is assumed. eg
    • x:y:z (all variables are assumed of type "F")
    • x/D:y:z (all variables are of type "D")
    • x:y/D:z (x is type "F", y and z of type "D")

delimiter allows for the use of another delimiter besides whitespace. This provides support for direct import of common data file formats like csv. If delimiter != ' ' and branchDescriptor == "", then the branch description is taken from the first line in the file, but delimiter is used for the branch names tokenization rather than ':'. Note however that if the values in the first line do not use the /[type] syntax, all variables are assumed to be of type "F". If the filename ends with extensions .csv or .CSV and a delimiter is not specified (besides ' '), the delimiter is automatically set to ','.

Lines in the input file starting with "#" are ignored. Leading whitespace for each column data is skipped. Empty lines are skipped.

A TBranch object is created for each variable in the expression. The total number of rows read from the file is returned.

FILLING a TTree WITH MULTIPLE INPUT TEXT FILES

To fill a TTree with multiple input text files, proceed as indicated above for the first input file and omit the second argument for subsequent calls

T.ReadFile("file1.dat","branch descriptor");
T.ReadFile("file2.dat");

Definition at line 7555 of file TTree.cxx.

◆ ReadStream()

Long64_t TTree::ReadStream ( std::istream &  inputStream,
const char *  branchDescriptor = "",
char  delimiter = ' ' 
)
virtual

Create or simply read branches from an input stream.

See also
reference information for TTree::ReadFile

Reimplemented in TNtuple, and TNtupleD.

Definition at line 7606 of file TTree.cxx.

◆ RecursiveRemove()

void TTree::RecursiveRemove ( TObject obj)
overridevirtual

Make sure that obj (which is being deleted or will soon be) is no longer referenced by this TTree.

Reimplemented from TObject.

Definition at line 7872 of file TTree.cxx.

◆ Refresh()

void TTree::Refresh ( )
virtual

Refresh contents of this tree and its branches from the current status on disk.

One can call this function in case the tree file is being updated by another process.

Reimplemented in TTreeSQL.

Definition at line 7907 of file TTree.cxx.

◆ RegisterExternalFriend()

void TTree::RegisterExternalFriend ( TFriendElement fe)
virtual

Record a TFriendElement that we need to warn when the chain switches to a new file (typically this is because this chain is a friend of another TChain)

Definition at line 7948 of file TTree.cxx.

◆ RemoveExternalFriend()

void TTree::RemoveExternalFriend ( TFriendElement fe)
virtual

Removes external friend.

Definition at line 7959 of file TTree.cxx.

◆ RemoveFriend()

void TTree::RemoveFriend ( TTree oldFriend)
virtual

Remove a friend from the list of friends.

Reimplemented in TChain.

Definition at line 7968 of file TTree.cxx.

◆ Reset()

void TTree::Reset ( Option_t option = "")
virtual

Reset baskets, buffers and entries count in all branches and leaves.

Reimplemented in TChain.

Definition at line 7994 of file TTree.cxx.

◆ ResetAfterMerge()

void TTree::ResetAfterMerge ( TFileMergeInfo info)
virtual

Resets the state of this TTree after a merge (keep the customization but forget the data).

Reimplemented in TChain.

Definition at line 8025 of file TTree.cxx.

◆ ResetBranchAddress()

void TTree::ResetBranchAddress ( TBranch br)
virtual

Tell all of our branches to set their addresses to zero.

Note: If any of our branches own any objects, they are deleted.

Reimplemented in TChain, TNtuple, and TNtupleD.

Definition at line 8056 of file TTree.cxx.

◆ ResetBranchAddresses()

void TTree::ResetBranchAddresses ( )
virtual

Tell all of our branches to drop their current objects and allocate new ones.

Reimplemented in TChain, TNtuple, and TNtupleD.

Definition at line 8066 of file TTree.cxx.

◆ Scan()

Long64_t TTree::Scan ( const char *  varexp = "",
const char *  selection = "",
Option_t option = "",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)
virtual

Loop over tree entries and print entries passing selection.

  • If varexp is 0 (or "") then print only first 8 columns.
  • If varexp = "*" print all columns.

Otherwise a columns selection can be made using "var1:var2:var3".

See also
TTreePlayer::Scan for more information

Reimplemented in TChain.

Definition at line 8085 of file TTree.cxx.

◆ SetAlias()

Bool_t TTree::SetAlias ( const char *  aliasName,
const char *  aliasFormula 
)
virtual

Set a tree variable alias.

Set an alias for an expression/formula based on the tree 'variables'.

The content of 'aliasName' can be used in TTreeFormula (i.e. TTree::Draw, TTree::Scan, TTreeViewer) and will be evaluated as the content of 'aliasFormula'.

If the content of 'aliasFormula' only contains symbol names, periods and array index specification (for example event.fTracks[3]), then the content of 'aliasName' can be used as the start of symbol.

If the alias 'aliasName' already existed, it is replaced by the new value.

When being used, the alias can be preceded by an eventual 'Friend Alias' (see TTree::GetFriendAlias)

Return true if it was added properly.

For example:

tree->SetAlias("x1","(tdc1[1]-tdc1[0])/49");
tree->SetAlias("y1","(tdc1[3]-tdc1[2])/47");
tree->SetAlias("x2","(tdc2[1]-tdc2[0])/49");
tree->SetAlias("y2","(tdc2[3]-tdc2[2])/47");
tree->Draw("y2-y1:x2-x1");
tree->SetAlias("theGoodTrack","event.fTracks[3]");
tree->Draw("theGoodTrack.fPx"); // same as "event.fTracks[3].fPx"

Definition at line 8127 of file TTree.cxx.

◆ SetAutoFlush()

void TTree::SetAutoFlush ( Long64_t  autof = -30000000)
virtual

This function may be called at the start of a program to change the default value for fAutoFlush.

CASE 1 : autof > 0

autof is the number of consecutive entries after which TTree::Fill will flush all branch buffers to disk.

CASE 2 : autof < 0

When filling the Tree the branch buffers will be flushed to disk when more than autof bytes have been written to the file. At the first FlushBaskets TTree::Fill will replace fAutoFlush by the current value of fEntries.

Calling this function with autof<0 is interesting when it is hard to estimate the size of one entry. This value is also independent of the Tree.

The Tree is initialized with fAutoFlush=-30000000, ie that, by default, the first AutoFlush will be done when 30 MBytes of data are written to the file.

CASE 3 : autof = 0

The AutoFlush mechanism is disabled.

Flushing the buffers at regular intervals optimize the location of consecutive entries on the disk by creating clusters of baskets.

A cluster of baskets is a set of baskets that contains all the data for a (consecutive) set of entries and that is stored consecutively on the disk. When reading all the branches, this is the minimum set of baskets that the TTreeCache will read.

Definition at line 8182 of file TTree.cxx.

◆ SetAutoSave()

void TTree::SetAutoSave ( Long64_t  autos = -300000000)
virtual

In case of a program crash, it will be possible to recover the data in the tree up to the last AutoSave point.

This function may be called before filling a TTree to specify when the branch buffers and TTree header are flushed to disk as part of TTree::Fill(). The default is -300000000, ie the TTree will write data to disk once it exceeds 300 MBytes. CASE 1: If fAutoSave is positive the watermark is reached when a multiple of fAutoSave entries have been filled. CASE 2: If fAutoSave is negative the watermark is reached when -fAutoSave bytes can be written to the file. CASE 3: If fAutoSave is 0, AutoSave() will never be called automatically as part of TTree::Fill().

Definition at line 8328 of file TTree.cxx.

◆ SetBasketSize()

void TTree::SetBasketSize ( const char *  bname,
Int_t  buffsize = 16000 
)
virtual

Set a branch's basket size.

bname is the name of a branch.

  • if bname="*", apply to all branches.
  • if bname="xxx*", apply to all branches with name starting with xxx

see TRegexp for wildcarding options buffsize = branc basket size

Definition at line 8344 of file TTree.cxx.

◆ SetBranchAddress() [1/5]

template<class T >
Int_t TTree::SetBranchAddress ( const char *  bname,
T **  add,
TBranch **  ptr = nullptr 
)
inline

Definition at line 585 of file TTree.h.

◆ SetBranchAddress() [2/5]

template<class T >
Int_t TTree::SetBranchAddress ( const char *  bname,
T *  add,
TBranch **  ptr = nullptr 
)
inline

Definition at line 594 of file TTree.h.

◆ SetBranchAddress() [3/5]

Int_t TTree::SetBranchAddress ( const char *  bname,
void *  addr,
TBranch **  ptr,
TClass ptrClass,
EDataType  datatype,
Bool_t  isptr 
)
virtual

Verify the validity of the type of addr before calling SetBranchAddress.

See TTree::CheckBranchAddressType for the semantic of the return value.

Note: See the comments in TBranchElement::SetAddress() for the meaning of the addr parameter and the object ownership policy.

Reimplemented in TChain.

Definition at line 8401 of file TTree.cxx.

◆ SetBranchAddress() [4/5]

Int_t TTree::SetBranchAddress ( const char *  bname,
void *  addr,
TBranch **  ptr = nullptr 
)
virtual

Change branch address, dealing with clone trees properly.

See TTree::CheckBranchAddressType for the semantic of the return value.

Note: See the comments in TBranchElement::SetAddress() for the meaning of the addr parameter and the object ownership policy.

Reimplemented in TChain.

Definition at line 8371 of file TTree.cxx.

◆ SetBranchAddress() [5/5]

Int_t TTree::SetBranchAddress ( const char *  bname,
void *  addr,
TClass ptrClass,
EDataType  datatype,
Bool_t  isptr 
)
virtual

Verify the validity of the type of addr before calling SetBranchAddress.

See TTree::CheckBranchAddressType for the semantic of the return value.

Note: See the comments in TBranchElement::SetAddress() for the meaning of the addr parameter and the object ownership policy.

Reimplemented in TChain.

Definition at line 8389 of file TTree.cxx.

◆ SetBranchAddressImp()

Int_t TTree::SetBranchAddressImp ( TBranch branch,
void *  addr,
TBranch **  ptr 
)
protected

Change branch address, dealing with clone trees properly.

See TTree::CheckBranchAddressType for the semantic of the return value.

Note: See the comments in TBranchElement::SetAddress() for the meaning of the addr parameter and the object ownership policy.

Definition at line 8431 of file TTree.cxx.

◆ SetBranchStatus()

void TTree::SetBranchStatus ( const char *  bname,
Bool_t  status = 1,
UInt_t found = nullptr 
)
virtual

Set branch status to Process or DoNotProcess.

When reading a Tree, by default, all branches are read. One can speed up considerably the analysis phase by activating only the branches that hold variables involved in a query.

bname is the name of a branch.

  • if bname="*", apply to all branches.
  • if bname="xxx*", apply to all branches with name starting with xxx

see TRegexp for wildcarding options

  • status = 1 branch will be processed
  • = 0 branch will not be processed

Example:

Assume a tree T with sub-branches a,b,c,d,e,f,g,etc.. when doing T.GetEntry(i) all branches are read for entry i. to read only the branches c and e, one can do

T.SetBranchStatus("*",0); //disable all branches
T.SetBranchStatus("c",1);
T.setBranchStatus("e",1);
T.GetEntry(i);

bname is interpreted as a wild-carded TRegexp (see TRegexp::MakeWildcard). Thus, "a*b" or "a.*b" matches branches starting with "a" and ending with "b", but not any other branch with an "a" followed at some point by a "b". For this second behavior, use "*a*b*". Note that TRegExp does not support '|', and so you cannot select, e.g. track and shower branches with "track|shower".

WARNING! WARNING! WARNING!

SetBranchStatus is matching the branch based on match of the branch 'name' and not on the branch hierarchy! In order to be able to selectively enable a top level object that is 'split' you need to make sure the name of the top level branch is prefixed to the sub-branches' name (by adding a dot ('.') at the end of the Branch creation and use the corresponding bname.

I.e If your Tree has been created in split mode with a parent branch "parent." (note the trailing dot).

T.SetBranchStatus("parent",1);

will not activate the sub-branches of "parent". You should do:

T.SetBranchStatus("parent*",1);

Without the trailing dot in the branch creation you have no choice but to call SetBranchStatus explicitly for each of the sub branches.

An alternative to this function is to read directly and only the interesting branches. Example:

TBranch *brc = T.GetBranch("c");
TBranch *bre = T.GetBranch("e");
brc->GetEntry(i);
bre->GetEntry(i);
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all leaves of entry and return total number of bytes read.
Definition TBranch.cxx:1652

If found is not 0, the number of branch(es) found matching the regular expression is returned in *found AND the error message 'unknown branch' is suppressed.

Reimplemented in TChain.

Definition at line 8520 of file TTree.cxx.

◆ SetBranchStyle()

void TTree::SetBranchStyle ( Int_t  style = 1)
static

Set the current branch style.

(static function)

  • style = 0 old Branch
  • style = 1 new Bronch

Definition at line 8651 of file TTree.cxx.

◆ SetCacheEntryRange()

Int_t TTree::SetCacheEntryRange ( Long64_t  first,
Long64_t  last 
)
virtual

interface to TTreeCache to set the cache entry range

Returns:

  • 0 entry range set
  • -1 on error

Definition at line 8812 of file TTree.cxx.

◆ SetCacheLearnEntries()

void TTree::SetCacheLearnEntries ( Int_t  n = 10)
virtual

Interface to TTreeCache to set the number of entries for the learning phase.

Definition at line 8846 of file TTree.cxx.

◆ SetCacheSize()

Int_t TTree::SetCacheSize ( Long64_t  cacheSize = -1)
virtual

Set maximum size of the file cache .

  • if cachesize = 0 the existing cache (if any) is deleted.
  • if cachesize = -1 (default) it is set to the AutoFlush value when writing the Tree (default is 30 MBytes).

Returns:

  • 0 size set, cache was created if possible
  • -1 on error

Reimplemented in TChain.

Definition at line 8667 of file TTree.cxx.

◆ SetCacheSizeAux()

Int_t TTree::SetCacheSizeAux ( Bool_t  autocache = kTRUE,
Long64_t  cacheSize = 0 
)
protected

Set the size of the file cache and create it if possible.

If autocache is true: this may be an autocreated cache, possibly enlarging an existing autocreated cache. The size is calculated. The value passed in cacheSize:

  • cacheSize = 0 make cache if default cache creation is enabled
  • cacheSize = -1 make a default sized cache in any case

If autocache is false: this is a user requested cache. cacheSize is used to size the cache. This cache should never be automatically adjusted.

Returns:

  • 0 size set, or existing autosized cache almost large enough. (cache was created if possible)
  • -1 on error

Definition at line 8693 of file TTree.cxx.

◆ SetChainOffset()

virtual void TTree::SetChainOffset ( Long64_t  offset = 0)
inlinevirtual

Definition at line 606 of file TTree.h.

◆ SetCircular()

void TTree::SetCircular ( Long64_t  maxEntries)
virtual

Enable/Disable circularity for this tree.

if maxEntries > 0 a maximum of maxEntries is kept in one buffer/basket per branch in memory. Note that when this function is called (maxEntries>0) the Tree must be empty or having only one basket per branch. if maxEntries <= 0 the tree circularity is disabled.

NOTE 1:

Circular Trees are interesting in online real time environments to store the results of the last maxEntries events.

NOTE 2:

Calling SetCircular with maxEntries <= 0 is necessary before merging circular Trees that have been saved on files.

NOTE 3:

SetCircular with maxEntries <= 0 is automatically called by TChain::Merge

NOTE 4:

A circular Tree can still be saved in a file. When read back, it is still a circular Tree and can be filled again.

Definition at line 8873 of file TTree.cxx.

◆ SetClusterPrefetch()

virtual void TTree::SetClusterPrefetch ( Bool_t  enabled)
inlinevirtual

Definition at line 608 of file TTree.h.

◆ SetDebug()

void TTree::SetDebug ( Int_t  level = 1,
Long64_t  min = 0,
Long64_t  max = 9999999 
)
virtual

Set the debug level and the debug range.

For entries in the debug range, the functions TBranchElement::Fill and TBranchElement::GetEntry will print the number of bytes filled or read for each branch.

Reimplemented in TProofChain.

Definition at line 8909 of file TTree.cxx.

◆ SetDefaultEntryOffsetLen()

void TTree::SetDefaultEntryOffsetLen ( Int_t  newdefault,
Bool_t  updateExisting = kFALSE 
)
virtual

Update the default value for the branch's fEntryOffsetLen.

If updateExisting is true, also update all the existing branches. If newdefault is less than 10, the new default value will be 10.

Definition at line 8921 of file TTree.cxx.

◆ SetDirectory()

void TTree::SetDirectory ( TDirectory dir)
virtual

Change the tree's directory.

Remove reference to this tree from current directory and add reference to new directory dir. The dir parameter can be 0 in which case the tree does not belong to any directory.

Reimplemented in TChain.

Definition at line 8947 of file TTree.cxx.

◆ SetEntries()

Long64_t TTree::SetEntries ( Long64_t  n = -1)
virtual

Change number of entries in the tree.

If n >= 0, set number of entries in the tree = n.

If n < 0, set number of entries in the tree to match the number of entries in each branch. (default for n is -1)

This function should be called only when one fills each branch independently via TBranch::Fill without calling TTree::Fill. Calling TTree::SetEntries() make sense only if the number of entries in each branch is identical, a warning is issued otherwise. The function returns the number of entries.

Reimplemented in THbookTree.

Definition at line 8992 of file TTree.cxx.

◆ SetEntryList()

void TTree::SetEntryList ( TEntryList list,
Option_t opt = "" 
)
virtual

Set an EntryList.

Reimplemented in TChain.

Definition at line 9027 of file TTree.cxx.

◆ SetEstimate()

void TTree::SetEstimate ( Long64_t  n = 1000000)
virtual

Set number of entries to estimate variable limits.

If n is -1, the estimate is set to be the current maximum for the tree (i.e. GetEntries() + 1) If n is less than -1, the behavior is undefined.

Definition at line 9091 of file TTree.cxx.

◆ SetEventList()

void TTree::SetEventList ( TEventList evlist)
virtual

This function transfroms the given TEventList into a TEntryList The new TEntryList is owned by the TTree and gets deleted when the tree is deleted.

This TEntryList can be returned by GetEntryList() function.

Reimplemented in TProofChain, and TChain.

Definition at line 9050 of file TTree.cxx.

◆ SetFileNumber()

void TTree::SetFileNumber ( Int_t  number = 0)
virtual

Set fFileNumber to number.

fFileNumber is used by TTree::Fill to set the file name for a new file to be created when the current file exceeds fgTreeMaxSize. (see TTree::ChangeFile) if fFileNumber=10, the new file name will have a suffix "_11", ie, fFileNumber is incremented before setting the file name

Definition at line 9134 of file TTree.cxx.

◆ SetImplicitMT()

virtual void TTree::SetImplicitMT ( Bool_t  enabled)
inlinevirtual

Definition at line 618 of file TTree.h.

◆ SetIOFeatures()

ROOT::TIOFeatures TTree::SetIOFeatures ( const ROOT::TIOFeatures features)

Provide the end-user with the ability to enable/disable various experimental IO features for this TTree.

Returns all the newly-set IO settings.

Definition at line 9111 of file TTree.cxx.

◆ SetMakeClass()

void TTree::SetMakeClass ( Int_t  make)
virtual

Set all the branches in this TTree to be in decomposed object mode (also known as MakeClass mode).

For MakeClass mode 0, the TTree expects the address where the data is stored to be set by either the user or the TTree to the address of a full object through the top level branch. For MakeClass mode 1, this address is expected to point to a numerical type or C-style array (variable or not) of numerical type, representing the primitive data members. The function's primary purpose is to allow the user to access the data directly with numerical type variable rather than having to have the original set of classes (or a reproduction thereof).

Reimplemented in TChain.

Definition at line 9158 of file TTree.cxx.

◆ SetMaxEntryLoop()

virtual void TTree::SetMaxEntryLoop ( Long64_t  maxev = kMaxEntries)
inlinevirtual

Definition at line 620 of file TTree.h.

◆ SetMaxTreeSize()

void TTree::SetMaxTreeSize ( Long64_t  maxsize = 100000000000LL)
static

Set the maximum size in bytes of a Tree file (static function).

The default size is 100000000000LL, ie 100 Gigabytes.

In TTree::Fill, when the file has a size > fgMaxTreeSize, the function closes the current file and starts writing into a new file with a name of the style "file_1.root" if the original requested file name was "file.root".

Definition at line 9178 of file TTree.cxx.

◆ SetMaxVirtualSize()

virtual void TTree::SetMaxVirtualSize ( Long64_t  size = 0)
inlinevirtual

Definition at line 622 of file TTree.h.

◆ SetName()

void TTree::SetName ( const char *  name)
overridevirtual

Change the name of this tree.

Reimplemented from TNamed.

Definition at line 9186 of file TTree.cxx.

◆ SetNotify()

virtual void TTree::SetNotify ( TObject obj)
inlinevirtual

Sets the address of the object to be notified when the tree is loaded.

The method TObject::Notify is called for the given object when the tree is loaded. Specifically this occurs in the TTree::LoadTree method. To remove the notification call this method with nullptr:

tree->SetNotify(nullptr);
Parameters
[in]objPointer to a TObject to be notified.

Definition at line 635 of file TTree.h.

◆ SetObject()

void TTree::SetObject ( const char *  name,
const char *  title 
)
virtual

Change the name and title of this tree.

Definition at line 9215 of file TTree.cxx.

◆ SetParallelUnzip()

void TTree::SetParallelUnzip ( Bool_t  opt = kTRUE,
Float_t  RelSize = -1 
)
virtual

Enable or disable parallel unzipping of Tree buffers.

Definition at line 9246 of file TTree.cxx.

◆ SetPerfStats()

void TTree::SetPerfStats ( TVirtualPerfStats perf)
virtual

Set perf stats.

Definition at line 9284 of file TTree.cxx.

◆ SetScanField()

virtual void TTree::SetScanField ( Int_t  n = 50)
inlinevirtual

Definition at line 640 of file TTree.h.

◆ SetTargetMemoryRatio()

void TTree::SetTargetMemoryRatio ( Float_t  ratio)
inline

Definition at line 641 of file TTree.h.

◆ SetTimerInterval()

virtual void TTree::SetTimerInterval ( Int_t  msec = 333)
inlinevirtual

Definition at line 642 of file TTree.h.

◆ SetTreeIndex()

void TTree::SetTreeIndex ( TVirtualIndex index)
virtual

The current TreeIndex is replaced by the new index.

Note that this function does not delete the previous index. This gives the possibility to play with more than one index, e.g.,

TVirtualIndex* oldIndex = tree.GetTreeIndex();
tree.SetTreeIndex(newIndex);
tree.Draw();
tree.SetTreeIndex(oldIndex);
tree.Draw(); etc
Abstract interface for Tree Index.

Definition at line 9301 of file TTree.cxx.

◆ SetUpdate()

virtual void TTree::SetUpdate ( Int_t  freq = 0)
inlinevirtual

Definition at line 645 of file TTree.h.

◆ SetWeight()

void TTree::SetWeight ( Double_t  w = 1,
Option_t option = "" 
)
virtual

Set tree weight.

The weight is used by TTree::Draw to automatically weight each selected entry in the resulting histogram.

For example the equivalent of:

T.Draw("x", "w")

is:

T.SetWeight(w);
T.Draw("x");

This function is redefined by TChain::SetWeight. In case of a TChain, an option "global" may be specified to set the same weight for all trees in the TChain instead of the default behaviour using the weights of each tree in the chain (see TChain::SetWeight).

Reimplemented in TChain.

Definition at line 9329 of file TTree.cxx.

◆ Show()

void TTree::Show ( Long64_t  entry = -1,
Int_t  lenmax = 20 
)
virtual

Print values of all active leaves for entry.

  • if entry==-1, print current entry (default)
  • if a leaf is an array, a maximum of lenmax elements is printed.

Definition at line 9340 of file TTree.cxx.

◆ SortBranchesByTime()

void TTree::SortBranchesByTime ( )
private

Sorts top-level branches by the last average task time recorded per branch.

Definition at line 5825 of file TTree.cxx.

◆ StartViewer()

void TTree::StartViewer ( )
virtual

Start the TTreeViewer on this tree.

  • ww is the width of the canvas in pixels
  • wh is the height of the canvas in pixels

Definition at line 9414 of file TTree.cxx.

◆ StopCacheLearningPhase()

Int_t TTree::StopCacheLearningPhase ( )
virtual

Stop the cache learning phase.

Returns:

  • 0 learning phase stopped or not active
  • -1 on error

Definition at line 9429 of file TTree.cxx.

◆ Streamer()

void TTree::Streamer ( TBuffer b)
overridevirtual

Stream a class object.

Reimplemented from TNamed.

Reimplemented in TTreeSQL.

Definition at line 9500 of file TTree.cxx.

◆ StreamerNVirtual()

void TTree::StreamerNVirtual ( TBuffer ClassDef_StreamerNVirtual_b)
inline

Definition at line 654 of file TTree.h.

◆ UnbinnedFit()

Int_t TTree::UnbinnedFit ( const char *  funcname,
const char *  varexp,
const char *  selection = "",
Option_t option = "",
Long64_t  nentries = kMaxEntries,
Long64_t  firstentry = 0 
)
virtual

Unbinned fit of one or more variable(s) from a tree.

funcname is a TF1 function.

See also
TTree::Draw for explanations of the other parameters.

Fit the variable varexp using the function funcname using the selection cuts given by selection.

The list of fit options is given in parameter option.

  • option = "Q" Quiet mode (minimum printing)
  • option = "V" Verbose mode (default is between Q and V)
  • option = "E" Perform better Errors estimation using Minos technique
  • option = "M" More. Improve fit results

You can specify boundary limits for some or all parameters via

func->SetParLimits(p_number, parmin, parmax);

if parmin>=parmax, the parameter is fixed

Note that you are not forced to fix the limits for all parameters. For example, if you fit a function with 6 parameters, you can do:

func->SetParameters(0,3.1,1.e-6,0.1,-8,100);
func->SetParLimits(4,-10,-4);
func->SetParLimits(5, 1,1);

With this setup:

  • Parameters 0->3 can vary freely
  • Parameter 4 has boundaries [-10,-4] with initial value -8
  • Parameter 5 is fixed to 100.

For the fit to be meaningful, the function must be self-normalized.

i.e. It must have the same integral regardless of the parameter settings. Otherwise the fit will effectively just maximize the area.

It is mandatory to have a normalization variable which is fixed for the fit. e.g.

TF1* f1 = new TF1("f1", "gaus(0)/sqrt(2*3.14159)/[2]", 0, 5);
f1->SetParameters(1, 3.1, 0.01);
f1->SetParLimits(0, 1, 1); // fix the normalization parameter to 1
data->UnbinnedFit("f1", "jpsimass", "jpsipt>3.0");
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
1-Dim function class
Definition TF1.h:213
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
Set lower and upper limits for parameter ipar.
Definition TF1.cxx:3499
virtual void SetParameters(const Double_t *params)
Definition TF1.h:649

1, 2 and 3 Dimensional fits are supported. See also TTree::Fit

Return status:

  • The function return the status of the fit in the following form fitResult = migradResult + 10*minosResult + 100*hesseResult + 1000*improveResult
  • The fitResult is 0 is the fit is OK.
  • The fitResult is negative in case of an error not connected with the fit.
  • The number of entries used in the fit can be obtained via mytree.GetSelectedRows();
  • If the number of selected entries is null the function returns -1

Definition at line 9657 of file TTree.cxx.

◆ UseCurrentStyle()

void TTree::UseCurrentStyle ( )
overridevirtual

Replace current attributes by current style.

Reimplemented from TObject.

Definition at line 9669 of file TTree.cxx.

◆ Write() [1/2]

Int_t TTree::Write ( const char *  name = nullptr,
Int_t  option = 0,
Int_t  bufsize = 0 
) const
overridevirtual

Write this object to the current directory.

For more see TObject::Write If option & kFlushBasket, call FlushBasket before writing the tree.

Reimplemented from TObject.

Definition at line 9696 of file TTree.cxx.

◆ Write() [2/2]

Int_t TTree::Write ( const char *  name = nullptr,
Int_t  option = 0,
Int_t  bufsize = 0 
)
overridevirtual

Write this object to the current directory.

For more see TObject::Write If option & kFlushBasket, call FlushBasket before writing the tree.

Reimplemented from TObject.

Definition at line 9708 of file TTree.cxx.

Friends And Related Symbol Documentation

◆ TChainIndex

friend class TChainIndex
friend

Definition at line 203 of file TTree.h.

◆ TFriendLock

friend class TFriendLock
friend

Definition at line 200 of file TTree.h.

◆ TTreeBranchImpRef

TBranch * TTreeBranchImpRef ( TTree tree,
const char *  branchname,
TClass ptrClass,
EDataType  datatype,
void *  addobj,
Int_t  bufsize,
Int_t  splitlevel 
)
friend

◆ TTreeCloner

friend class TTreeCloner
friend

Definition at line 205 of file TTree.h.

◆ TTreeIndex

friend class TTreeIndex
friend

Definition at line 202 of file TTree.h.

Member Data Documentation

◆ fAliases

TList* TTree::fAliases
protected

List of aliases for expressions based on the tree branches.

Definition at line 121 of file TTree.h.

◆ fAllocationCount

std::atomic<UInt_t> TTree::fAllocationCount {0}
mutableprotected

indicates basket should be resized to exact memory usage, but causes significant

memory churn. ! Number of reallocations basket memory buffers.

Definition at line 149 of file TTree.h.

◆ fAutoFlush

Long64_t TTree::fAutoFlush
protected

Auto-flush tree when fAutoFlush entries written or -fAutoFlush (compressed) bytes produced.

Definition at line 101 of file TTree.h.

◆ fAutoSave

Long64_t TTree::fAutoSave
protected

Autosave tree when fAutoSave entries written or -fAutoSave (compressed) bytes produced.

Definition at line 100 of file TTree.h.

◆ fBranches

TObjArray TTree::fBranches
protected

List of Branches.

Definition at line 119 of file TTree.h.

◆ fBranchRef

TBranchRef* TTree::fBranchRef
protected

Branch supporting the TRefTable (if any)

Definition at line 133 of file TTree.h.

◆ fCacheDoAutoInit

Bool_t TTree::fCacheDoAutoInit
protected

! true if cache auto creation or resize check is needed

Definition at line 136 of file TTree.h.

◆ fCacheDoClusterPrefetch

Bool_t TTree::fCacheDoClusterPrefetch
protected

! true if cache is prefetching whole clusters

Definition at line 137 of file TTree.h.

◆ fCacheSize

Long64_t TTree::fCacheSize
protected

! Maximum size of file buffers

Definition at line 105 of file TTree.h.

◆ fCacheUserSet

Bool_t TTree::fCacheUserSet
protected

! true if the cache setting was explicitly given by user

Definition at line 138 of file TTree.h.

◆ fChainOffset

Long64_t TTree::fChainOffset
protected

! Offset of 1st entry of this Tree in a TChain

Definition at line 106 of file TTree.h.

◆ fClones

TList* TTree::fClones
protected

! List of cloned trees which share our addresses

Definition at line 132 of file TTree.h.

◆ fClusterRangeEnd

Long64_t* TTree::fClusterRangeEnd
protected

[fNClusterRange] Last entry of a cluster range.

Definition at line 103 of file TTree.h.

◆ fClusterSize

Long64_t* TTree::fClusterSize
protected

[fNClusterRange] Number of entries in each cluster for a given range.

Definition at line 104 of file TTree.h.

◆ fDebug

Int_t TTree::fDebug
protected

! Debug level

Definition at line 111 of file TTree.h.

◆ fDebugMax

Long64_t TTree::fDebugMax
protected

! Last entry number to debug

Definition at line 113 of file TTree.h.

◆ fDebugMin

Long64_t TTree::fDebugMin
protected

! First entry number to debug

Definition at line 112 of file TTree.h.

◆ fDefaultEntryOffsetLen

Int_t TTree::fDefaultEntryOffsetLen
protected

Initial Length of fEntryOffset table in the basket buffers.

Definition at line 94 of file TTree.h.

◆ fDirectory

TDirectory* TTree::fDirectory
protected

! Pointer to directory holding this tree

Definition at line 118 of file TTree.h.

◆ fEntries

Long64_t TTree::fEntries
protected

Number of entries.

Definition at line 84 of file TTree.h.

◆ fEntryList

TEntryList* TTree::fEntryList
protected

! Pointer to event selection list (if one)

Definition at line 123 of file TTree.h.

◆ fEstimate

Long64_t TTree::fEstimate
protected

Number of entries to estimate histogram limits.

Definition at line 102 of file TTree.h.

◆ fEventList

TEventList* TTree::fEventList
protected

! Pointer to event selection list (if one)

Definition at line 122 of file TTree.h.

◆ fExternalFriends

TList* TTree::fExternalFriends
protected

! List of TFriendsElement pointing to us and need to be notified of LoadTree. Content not owned.

Definition at line 128 of file TTree.h.

◆ fFileNumber

Int_t TTree::fFileNumber
protected

! current file number (if file extensions)

Definition at line 116 of file TTree.h.

◆ fFlushedBytes

Long64_t TTree::fFlushedBytes
protected

Number of auto-flushed bytes.

Definition at line 89 of file TTree.h.

◆ fFriendLockStatus

UInt_t TTree::fFriendLockStatus
protected

! Record which method is locking the friend recursion

Definition at line 134 of file TTree.h.

◆ fFriends

TList* TTree::fFriends
protected

pointer to list of friend elements

Definition at line 127 of file TTree.h.

◆ fgBranchStyle

Int_t TTree::fgBranchStyle = 1
staticprotected

Old/New branch style.

Definition at line 151 of file TTree.h.

◆ fgMaxTreeSize

Long64_t TTree::fgMaxTreeSize = 100000000000LL
staticprotected

Maximum size of a file containing a Tree.

Definition at line 152 of file TTree.h.

◆ fIMTEnabled

Bool_t TTree::fIMTEnabled
protected

! true if implicit multi-threading is enabled for this tree

Definition at line 139 of file TTree.h.

◆ fIMTFlush

Bool_t TTree::fIMTFlush {false}
mutableprivate

! True if we are doing a multithreaded flush.

Definition at line 156 of file TTree.h.

◆ fIMTTotBytes

std::atomic<Long64_t> TTree::fIMTTotBytes
mutableprivate

! Total bytes for the IMT flush baskets

Definition at line 157 of file TTree.h.

◆ fIMTZipBytes

std::atomic<Long64_t> TTree::fIMTZipBytes
mutableprivate

! Zip bytes for the IMT flush baskets.

Definition at line 158 of file TTree.h.

◆ fIndex

TArrayI TTree::fIndex
protected

Index of sorted values.

Definition at line 125 of file TTree.h.

◆ fIndexValues

TArrayD TTree::fIndexValues
protected

Sorted index values.

Definition at line 124 of file TTree.h.

◆ fIOFeatures

TIOFeatures TTree::fIOFeatures {0}
protected

IO features to define for newly-written baskets and branches.

Definition at line 114 of file TTree.h.

◆ fLeaves

TObjArray TTree::fLeaves
protected

Direct pointers to individual branch leaves.

Definition at line 120 of file TTree.h.

◆ fMakeClass

Int_t TTree::fMakeClass
protected

! not zero when processing code generated by MakeClass

Definition at line 115 of file TTree.h.

◆ fMaxClusterRange

Int_t TTree::fMaxClusterRange
protected

! Memory allocated for the cluster range.

Definition at line 96 of file TTree.h.

◆ fMaxEntries

Long64_t TTree::fMaxEntries
protected

Maximum number of entries in case of circular buffers.

Definition at line 97 of file TTree.h.

◆ fMaxEntryLoop

Long64_t TTree::fMaxEntryLoop
protected

Maximum number of entries to process.

Definition at line 98 of file TTree.h.

◆ fMaxVirtualSize

Long64_t TTree::fMaxVirtualSize
protected

Maximum total size of buffers kept in memory.

Definition at line 99 of file TTree.h.

◆ fNClusterRange

Int_t TTree::fNClusterRange
protected

Number of Cluster range in addition to the one defined by 'AutoFlush'.

Definition at line 95 of file TTree.h.

◆ fNEntriesSinceSorting

UInt_t TTree::fNEntriesSinceSorting
protected

! Number of entries processed since the last re-sorting of branches

Definition at line 140 of file TTree.h.

◆ fNfill

Int_t TTree::fNfill
protected

! Local for EntryLoop

Definition at line 110 of file TTree.h.

◆ fNotify

TObject* TTree::fNotify
protected

! Object to be notified when loading a Tree

Definition at line 117 of file TTree.h.

◆ fPacketSize

Int_t TTree::fPacketSize
protected

! Number of entries in one packet for parallel root

Definition at line 109 of file TTree.h.

◆ fPerfStats

TVirtualPerfStats* TTree::fPerfStats
protected

! pointer to the current perf stats object

Definition at line 129 of file TTree.h.

◆ fPlayer

TVirtualTreePlayer* TTree::fPlayer
protected

! Pointer to current Tree player

Definition at line 131 of file TTree.h.

◆ fReadEntry

Long64_t TTree::fReadEntry
protected

! Number of the entry being processed

Definition at line 107 of file TTree.h.

◆ fSavedBytes

Long64_t TTree::fSavedBytes
protected

Number of autosaved bytes.

Definition at line 88 of file TTree.h.

◆ fScanField

Int_t TTree::fScanField
protected

Number of runs before prompting in Scan.

Definition at line 92 of file TTree.h.

◆ fSeqBranches

std::vector<TBranch*> TTree::fSeqBranches
protected

! Branches to be processed sequentially when IMT is on

Definition at line 142 of file TTree.h.

◆ fSortedBranches

std::vector<std::pair<