TTreePlayer
class description - source file - inheritance tree
protected:
const char* GetNameByIndex(TString& varexp, Int_t* index, Int_t colindex) const
virtual void MakeIndex(TString& varexp, Int_t* index)
void TakeAction(Int_t nfill, Int_t& npoints, Int_t& action, TObject* obj, Option_t* option)
void TakeEstimate(Int_t nfill, Int_t& npoints, Int_t action, TObject* obj, Option_t* option)
public:
TTreePlayer TTreePlayer()
TTreePlayer TTreePlayer(TTreePlayer&)
virtual void ~TTreePlayer()
static TClass* Class()
virtual void ClearFormula()
virtual void CompileVariables(const char* varexp, const char* selection)
virtual TTree* CopyTree(const char* selection, Option_t* option, Int_t nentries = 1000000000, Int_t firstentry = 0)
virtual void CreatePacketGenerator(Int_t nentries, Stat_t firstEntry)
virtual Int_t DrawSelect(const char* varexp, const char* selection, Option_t* option, Int_t nentries = 1000000000, Int_t firstentry = 0)
virtual void EntryLoop(Int_t& action, TObject* obj, Int_t nentries = 1000000000, Int_t firstentry = 0, Option_t* option)
virtual void EstimateLimits(Int_t estimate, Int_t nentries = 1000000000, Int_t firstentry = 0)
void FindGoodLimits(Int_t nbins, Int_t& newbins, Double_t& xmin, Double_t& xmax)
virtual Int_t Fit(const char* formula, const char* varexp, const char* selection, Option_t* option, Option_t* goption, Int_t nentries, Int_t firstentry)
virtual Int_t GetDimension() const
virtual TH1* GetHistogram() const
TTreeFormula* GetMultiplicity() const
virtual void GetNextPacket(TSlave* sl, Int_t& nentries, Stat_t& firstentry, Stat_t& processed)
TPacketGenerator* GetPacketGenerator() const
virtual Int_t GetPacketSize() const
virtual TTreeFormula* GetSelect() const
virtual Int_t GetSelectedRows() const
virtual Double_t* GetV1() const
virtual Double_t* GetV2() const
virtual Double_t* GetV3() const
virtual TTreeFormula* GetVar1() const
virtual TTreeFormula* GetVar2() const
virtual TTreeFormula* GetVar3() const
virtual TTreeFormula* GetVar4() const
virtual Double_t* GetW() const
virtual TClass* IsA() const
virtual void Loop(Option_t* option, Int_t nentries = 1000000000, Int_t firstentry = 0)
virtual Int_t MakeClass(const char* classname = 0, Option_t* option)
virtual Int_t MakeCode(const char* filename = 0)
virtual TPrincipal* Principal(const char* varexp, const char* selection, Option_t* option = np, Int_t nentries = 1000000000, Int_t firstentry = 0)
virtual Int_t Process(const char* filename, Option_t* option, Int_t nentries = 1000000000, Int_t firstentry = 0)
virtual Int_t Process(TSelector* selector, Option_t* option, Int_t nentries = 1000000000, Int_t firstentry = 0)
virtual TSQLResult* Query(const char* varexp, const char* selection, Option_t* option, Int_t nentries = 1000000000, Int_t firstentry = 0)
virtual Int_t Scan(const char* varexp, const char* selection, Option_t* option, Int_t nentries = 1000000000, Int_t firstentry = 0)
virtual void SetEstimate(Int_t n)
virtual void SetPacketSize(Int_t size = 100)
virtual void SetTree(TTree* t)
virtual void ShowMembers(TMemberInspector& insp, char* parent)
virtual void StartViewer(Int_t ww, Int_t wh)
virtual void Streamer(TBuffer& b)
void StreamerNVirtual(TBuffer& b)
virtual Int_t UnbinnedFit(const char* formula, const char* varexp, const char* selection, Option_t* option, Int_t nentries, Int_t firstentry)
protected:
TTree* fTree Pointer to current Tree
TTreeFormula* fVar1 Pointer to first variable formula
TTreeFormula* fVar2 Pointer to second variable formula
TTreeFormula* fVar3 Pointer to third variable formula
TTreeFormula* fVar4 Pointer to fourth variable formula
TTreeFormula* fSelect Pointer to selection formula
TTreeFormula* fMultiplicity Pointer to formula giving ndata per entry
Int_t fDraw ! Last entry loop number when object was drawn
Int_t fNfill ! Local for EntryLoop
Int_t fDimension Dimension of the current expression
Int_t fSelectedRows Number of selected entries
Int_t fPacketSize Number of entries in one packet for parallel root
Int_t fNbins[4] Number of bins per dimension
Double_t fVmin[4] Minima of varexp columns
Double_t fVmax[4] Maxima of varexp columns
Double_t* fV1 [fSelectedRows]Local buffer for variable 1
Double_t* fV2 [fSelectedRows]Local buffer for variable 2
Double_t* fV3 [fSelectedRows]Local buffer for variable 3
Double_t* fW [fSelectedRows]Local buffer for weights
TPacketGenerator* fPacketGen ! Packet generator
TH1* fHistogram ! Pointer to histogram used for the projection
TTree
a TTree object has a header with a name and a title.
It consists of a list of independent branches (TBranch). Each branch
has its own definition and list of buffers. Branch buffers may be
automatically written to disk or kept in memory until the Tree 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 one single branch and one single buffer can be the right choice
when one wants to process only a subset of all entries in the tree.
(you know for example the list of entry numbers you want to process).
Making several branches is particularly interesting in the data analysis
phase, when one wants to histogram some attributes of an object (entry)
without reading all the attributes.
/*
*/
==> TTree *tree = new TTree(name, title, maxvirtualsize)
Creates a Tree with name and title. Maxvirtualsize is by default 64Mbytes,
maxvirtualsize = 64000000(default) means: Keeps as many buffers in memory until
the sum of all buffers is greater than 64 Megabyte. When this happens,
memory buffers are written to disk and deleted until the size of all
buffers is again below the threshold.
maxvirtualsize = 0 means: keep only one buffer in memory.
Various kinds of branches can be added to a tree:
A - simple structures or list of variables. (may be for C or Fortran structures)
B - any object (inheriting from TObject). (we expect this option be the most frequent)
C - a ClonesArray. (a specialized object for collections of same class objects)
==> Case A
======
TBranch *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 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)
- D : a 64 bit floating point (Double_t)
==> Case B
======
TBranch *branch = tree->Branch(branchname,className,object, bufsize, splitlevel)
object is the address of a pointer to an existing object (derived from TObject).
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=0, the object is serialized in the branch buffer.
==> Case C
======
TBranch *branch = tree->Branch(branchname,clonesarray, bufsize, splitlevel)
clonesarray is the address of a pointer to a TClonesArray.
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.
==> 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.
==> tree->Fill()
loops on all defined branches and for each branch invokes the Fill function.
See also the class TNtuple (a simple Tree with only one branch)
/*
*/
=============================================================================
______________________________________________________________________________
*-*-*-*-*-*-*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 "TROOT.h"
#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
#include "TProfile.h"
#include "TRandom.h"
#include "TTree.h"
TROOT simple("simple","Histograms and trees");
//______________________________________________________________________________
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 = new TH1F("hpx","This is the px distribution",100,-4,4);
TH2F *hpxpy = new TH2F("hpxpy","py ps px",40,-4,4,40,-4,4);
TProfile *hprof = new TProfile("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;
static POINT point;
static EVENTN eventn;
// Create a ROOT Tree
TTree *tree = new TTree("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;
static Float_t p[3];
//--------------------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;
Float_t random = gRandom->::Rndm(1);
// Fill histograms
hpx->Fill(px);
hpxpy->Fill(px,py,1);
hprof->Fill(px,pz,1);
// Fill structures
p[0] = px;
p[1] = py;
p[2] = pz;
point.x
point.y
point.z
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.
hfile.Close();
return 0;
}
TTreePlayer()
*-*-*-*-*-*-*-*-*-*-*Default Tree constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ========================
~TTreePlayer()
*-*-*-*-*-*-*-*-*-*-*Tree destructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =================
void ClearFormula()
*-*-*-*-*-*-*Delete internal buffers*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =======================
void CompileVariables(const char *varexp, const char *selection)
*-*-*-*-*-*-*Compile input variables and selection expression*-*-*-*-*-*
*-* ================================================
varexp is an expression of the general form e1:e2:e3
where e1,etc is a formula referencing a combination of the columns
Example:
varexp = x simplest case: draw a 1-Dim distribution of column named x
= sqrt(x) : draw distribution of sqrt(x)
= x*y/z
= y:sqrt(x) 2-Dim dsitribution of y versus sqrt(x)
selection is an expression with a combination of the columns
Example:
selection = "x<y && sqrt(z)>3.2"
in a selection all the C++ operators are authorized
TTree* CopyTree(const char *selection, Option_t *option, Int_t nentries, Int_t firstentry)
copy a Tree with selection
make a clone of this Tree header.
then copy the selected entries
selection is a standard selection expression (see TTreePlayer::Draw)
option is reserved for possible future use
nentries is the number of entries to process (default is all)
first is the first entry to process (default is 0)
Note that the branch addresses must be correctly set before calling this function
The following example illustrates how to copy some events from the Tree
generated in $ROOTSYS/test/Event
gSystem->Load("libEvent");
TFile f("Event.root");
TTree *T = (TTree*)f.Get("T");
Event *event = new Event();
T->SetBranchAddress("event",&event);
TFile f2("Event2.root","recreate");
TTree *T2 = T->CopyTree("fNtrack<595");
T2->Write();
void CreatePacketGenerator(Int_t nentries, Stat_t firstEntry)
Create or reset the packet generator.
Int_t DrawSelect(const char *varexp0, const char *selection, Option_t *option,Int_t nentries, Int_t firstentry)
*-*-*-*-*-*-*-*-*-*-*Draw expression varexp for specified entries-*-*-*-*-*
*-* ===========================================
varexp is an expression of the general form e1:e2:e3
where e1,etc is a formula referencing a combination of the columns
Example:
varexp = x simplest case: draw a 1-Dim distribution of column named x
= sqrt(x) : draw distribution of sqrt(x)
= x*y/z
= y:sqrt(x) 2-Dim dsitribution of y versus sqrt(x)
Note that the variables e1, e2 or e3 may contain a selection.
example, if e1= x*(y<0), the value histogrammed will be x if y<0
and will be 0 otherwise.
selection is an expression with a combination of the columns.
In a selection all the C++ operators are authorized.
The value corresponding to the selection expression is used as a weight
to fill the histogram.
If the expression includes only boolean operations, the result
is 0 or 1. If the result is 0, the histogram is not filled.
In general, the expression may be of the form:
value*(boolean expression)
if boolean expression is true, the histogram is filled with
a weight = value.
Examples:
selection1 = "x<y && sqrt(z)>3.2"
selection2 = "(x+y)*(sqrt(z)>3.2"
selection1 returns a weigth = 0 or 1
selection2 returns a weight = x+y if sqrt(z)>3.2
returns a weight = 0 otherwise.
option is the drawing option
see TH1::Draw for the list of all drawing options.
If option contains the string "goff", no graphics is generated.
nentries is the number of entries to process (default is all)
first is the 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.
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
In summary, TTree::Draw loops through all un-specified 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])
}
}
Saving the result of Draw to an histogram
=========================================
By default the temporary histogram created is called htemp.
If varexp0 contains >>hnew (following the variable(s) name(s),
the new histogram created is called hnew and it is kept in the current
directory.
Example:
tree.Draw("sqrt(x)>>hsqrt","y>0")
will draw sqrt(x) and save the histogram as "hsqrt" in the current
directory.
By default, the specified histogram is reset.
To continue to append data to an existing histogram, use "+" in front
of the histogram name;
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.
Making a Profile histogram
==========================
In case of a 2-Dim expression, one can generate a TProfile histogram
instead of a TH2F histogram by specyfying option=prof or option=profs.
The option=prof is automatically selected in case of y:x>>pf
where pf is an existing TProfile histogram.
Saving the result of Draw to a TEventList
=========================================
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.
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.
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 as Input
===========================
Once a TEventList object has been generated, it can be used as input
for TTree::Draw. Use TTree::SetEventList to set the current event list
Example:
TEventList *elist = (TEventList*)gDirectory->Get("yplus");
tree->SetEventList(elist);
tree->Draw("py");
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 entries accepted by the
//selection expression. In case where no selection
//was specified, returns the number of entries processed.
-GetV1() //returns a pointer to the float array of V1
-GetV2() //returns a pointer to the float array of V2
-GetV3() //returns a pointer to the float array of V3
-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",selection);
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
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 GetV1, GetV2, GetV3, GetW with a length corresponding to the
parameter fEstimate. By default fEstimate=10000 and can be modified
via TTree::SetEstimate. A possible recipee is to do
tree->SetEstimate(tree->GetEntries());
You must call SetEstimate if the expected number of selected rows
is greater than 10000.
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();"
void EntryLoop(Int_t &action, TObject *obj, Int_t nentries, Int_t firstentry, Option_t *option)
*-*-*-*-*-*-*-*-*-*-*-*-*Loop on all entries*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ==================
nentries is the number of entries to process (default is all)
first is the first entry to process (default is 0)
action = 1 Fill 1-D histogram obj
= 2 Fill 2-D histogram obj
= 3 Fill 3-D histogram obj
= 4 Fill Profile histogram obj
= 5 Fill a TEventlist
= 11 Estimate Limits
= 12 Fill 2-D PolyMarker obj
= 13 Fill 3-D PolyMarker obj
action < 0 Evaluate Limits for case abs(action)
void EstimateLimits(Int_t, Int_t nentries, Int_t firstentry)
*-*-*-*-*Estimate histogram limits for conditions of input parameters*-*-*-*
*-* ============================================================
The estimation of the limits is based on estimate entries
The first estimate/2 and the last esstimate/2 entries are used.
This algorithm is in general good enough to make a reasonable estimation
with a small number of entries.
nentries is the number of entries to process (default is all)
first is the first entry to process (default is 0)
void FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax)
*-*-*-*-*-*-*-*-*Find reasonable bin values*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ==========================
Int_t Fit(const char *formula ,const char *varexp, const char *selection,Option_t *option ,Option_t *goption,Int_t nentries, Int_t firstentry)
*-*-*-*-*-*-*-*-*Fit a projected item(s) from a Tree*-*-*-*-*-*-*-*-*-*
*-* ======================================
formula is a TF1 expression.
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.
Example:
tree.Fit("pol4","sqrt(x)>>hsqrt","y>0")
will fit sqrt(x) and save the histogram as "hsqrt" in the current
directory.
const char* GetNameByIndex(TString &varexp, Int_t *index,Int_t colindex)
*-*-*-*-*-*-*-*-*Return name corresponding to colindex in varexp*-*-*-*-*-*
*-* ===============================================
varexp is a string of names separated by :
index is an array with pointers to the start of name[i] in varexp
void GetNextPacket(TSlave *sl, Int_t &nentries, Stat_t &firstentry, Stat_t &processed)
Return in nentries and firstentry the optimal range of entries (packet)
to be processed by slave sl. See TPacketGenerator for the algorithm
used to get the packet size.
void Loop(Option_t *option, Int_t nentries, Int_t firstentry)
*-*-*-*-*-*-*-*-*Loop on nentries of this tree starting at firstentry
*-* ===================================================
Int_t MakeClass(const char *classname, const char *option)
====>
*-*-*-*-*-*-*Generate skeleton analysis class for this Tree*-*-*-*-*-*-*
*-* ==============================================
The following files are produced: classname.h and classname.C
if classname is NULL, classname will be nameoftree.
When the option "selector" is specified, the function generates the
selector class described in TTree::MakeSelector.
The generated code in classname.h includes the following:
- Identification of the original Tree and Input file name
- Definition of analysis class (data and functions)
- the following class functions:
-constructor (connecting by default the Tree file)
-GetEntry(Int_t entry)
-Init(TTree *tree) to initialize a new TTree
-Show(Int_t entry) to read and Dump entry
The generated code in classname.C includes only the main
analysis function Loop.
To use this function:
- connect your Tree file (eg: TFile f("myfile.root");)
- T->MakeClass("MyClass");
where T is the name of the Tree 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
Root > t.GetEntry(12); // Fill t data members 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
====>
Int_t MakeCode(const char *filename)
====>
*-*-*-*-*-*-*-*-*Generate skeleton function for this Tree*-*-*-*-*-*-*
*-* ========================================
The function code is written on filename
if filename is NULL, filename will be nameoftree.C
The generated code includes the following:
- Identification of the original Tree and Input file name
- Connection of the Tree file
- Declaration of Tree variables
- Setting of branches addresses
- a skeleton for the entry loop
To use this function:
- connect your Tree file (eg: TFile f("myfile.root");)
- T->MakeCode("user.C");
where T is the name of the Tree in file myfile.root
and user.C the name of the file created by this function.
NOTE: Since the implementation of this function, new and better
function TTree::MakeClass and TTree::MakeSelector have been developped.
Author: Rene Brun
====>
void MakeIndex(TString &varexp, Int_t *index)
*-*-*-*-*-*-*-*-*Build Index array for names in varexp*-*-*-*-*-*-*-*-*-*-*
*-* =====================================
TPrincipal* Principal(const char *varexp, const char *selection, Option_t *option, Int_t nentries, Int_t firstentry)
*-*-*-*-*-*-*-*-*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 responsability
to delete this object.
The option default value is "np"
see TTreePlayer::DrawSelect for explanation of the other parameters.
Int_t Process(const char *filename,Option_t *option, Int_t nentries, Int_t firstentry)
*-*-*-*-*-*-*-*-*Process this tree executing the code in filename*-*-*-*-*
*-* ================================================
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:
void TSelector::Begin(). This function is called before looping on the
events in the Tree. The user can create his histograms in this function.
Bool_t TSelector::Notify(). This function is called at the first entry
of a new file in a chain.
Bool_t TSelector::ProcessCut(Int_t tentry). This function is called
before processing tentry. It is the user's responsability to read
the corresponding entry in memory (may be just a partial read).
The function returns kTRUE if the entry must be processed,
kFALSE otherwise. tentry is the entry number in the current Tree.
void TSelector::ProcessFill(Int_t tentry). This function is called for
all selected events. User fills histograms in this function.
void TSelector::Terminate(). This function is called at the end of
the loop on all events.
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. The corresponding binary file and shared library
will be deleted at the end of the function.
if filename is of the form file.C+, the file file.C will be compiled
and dynamically loaded. The corresponding binary file and shared library
will be kept at the end of the function. 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.
Int_t Process(TSelector *selector,Option_t *option, Int_t nentries, Int_t firstentry)
*-*-*-*-*-*-*-*-*Process this tree executing the code in selector*-*-*-*-*
*-* ================================================
The TSelector class has the following member functions:
void TSelector::Begin(). This function is called before looping on the
events in the Tree. The user can create his histograms in this function.
Bool_t TSelector::Notify(). This function is called at the first entry
of a new file in a chain.
Bool_t TSelector::ProcessCut(Int_t tentry). This function is called
before processing tentry. It is the user's responsability to read
the corresponding entry in memory (may be just a partial read).
The function returns kTRUE if the entry must be processed,
kFALSE otherwise. tentry is the entry number in the current Tree.
void TSelector::ProcessFill(Int_t tentry). This function is called for
all selected events. User fills histograms in this function.
void TSelector::Terminate(). This function is called at the end of
the loop on all events.
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.
Int_t Scan(const char *varexp, const char *selection, Option_t *,
Int_t nentries, Int_t firstentry)
Loop on Tree 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".
TSQLResult* Query(const char *varexp, const char *selection,
Option_t *, Int_t nentries, Int_t firstentry)
Loop on Tree and return TSQLResult object containing 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". In case of error 0 is returned otherwise
a TSQLResult object which must be deleted by the user.
void SetEstimate(Int_t )
*-*-*-*-*-*-*-*-*Set number of entries to estimate variable limits*-*-*-*
*-* ================================================
void SetPacketSize(Int_t size)
*-*-*-*-*-*-*-*-*Set number of entries per packet for parallel root*-*-*-*-*
*-* =================================================
void StartViewer(Int_t ww, Int_t wh)
*-*-*-*-*-*-*-*-*Start the TTreeViewer on this TTree*-*-*-*-*-*-*-*-*-*
*-* ===================================
ww is the width of the canvas in pixels
wh is the height of the canvas in pixels
void TakeAction(Int_t nfill, Int_t &npoints, Int_t &action, TObject *obj, Option_t *option)
*-*-*-*-*-*Execute action for object obj nfill times*-*-*-*-*-*-*-*-*-*
*-* =========================================
void TakeEstimate(Int_t nfill, Int_t &, Int_t action, TObject *obj, Option_t *option)
*-*-*-*-*-*Estimate limits for 1-D, 2-D or 3-D objects*-*-*-*-*-*-*-*-*-*
*-* ===========================================
Int_t UnbinnedFit(const char *funcname ,const char *varexp, const char *selection,Option_t *option ,Int_t nentries, Int_t firstentry)
*-*-*-*-*-*Unbinned fit of one or more variable(s) from a Tree*-*-*-*-*-*
*-* ===================================================
funcname is a TF1 function.
See 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)
= "V" Verbose mode (default is between Q and V)
= "E" Perform better Errors estimation using Minos technique
= "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.
In practice it is convenient 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");
1, 2 and 3 Dimensional fits are supported.
See also TTree::Fit
Inline Functions
Int_t GetDimension() const
TH1* GetHistogram() const
TTreeFormula* GetMultiplicity() const
TPacketGenerator* GetPacketGenerator() const
Int_t GetPacketSize() const
TTreeFormula* GetSelect() const
Int_t GetSelectedRows() const
TTreeFormula* GetVar1() const
TTreeFormula* GetVar2() const
TTreeFormula* GetVar3() const
TTreeFormula* GetVar4() const
Double_t* GetV1() const
Double_t* GetV2() const
Double_t* GetV3() const
Double_t* GetW() const
void SetTree(TTree* t)
TClass* Class()
TClass* IsA() const
void ShowMembers(TMemberInspector& insp, char* parent)
void Streamer(TBuffer& b)
void StreamerNVirtual(TBuffer& b)
TTreePlayer TTreePlayer(TTreePlayer&)
Author: Rene Brun 12/01/96
Last update: root/treeplayer:$Name: $:$Id: TTreePlayer.cxx,v 1.33 2000/12/21 14:03:39 brun Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
ROOT page - Class index - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.