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 "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 = 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 = 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. hfile.Close(); return 0; }
TTreePlayer() | |
virtual | ~TTreePlayer() |
void | TObject::AbstractMethod(const char* method) const |
virtual void | TObject::AppendPad(Option_t* option = "") |
virtual void | TObject::Browse(TBrowser* b) |
virtual TVirtualIndex* | BuildIndex(const TTree* T, const char* majorname, const char* minorname) |
virtual TVirtualIndex* | TVirtualTreePlayer::BuildIndex(const TTree* T, const char* majorname, const char* minorname) |
static TClass* | Class() |
static TClass* | TVirtualTreePlayer::Class() |
static TClass* | TObject::Class() |
virtual const char* | TObject::ClassName() const |
virtual void | TObject::Clear(Option_t* = "") |
virtual TObject* | TObject::Clone(const char* newname = "") const |
virtual Int_t | TObject::Compare(const TObject* obj) const |
virtual void | TObject::Copy(TObject& object) const |
virtual TTree* | CopyTree(const char* selection, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual TTree* | TVirtualTreePlayer::CopyTree(const char* selection, Option_t* option = "", Long64_t nentries = 1000000000, Long64_t firstentry = 0) |
virtual void | TObject::Delete(Option_t* option = "")MENU |
virtual Int_t | TObject::DistancetoPrimitive(Int_t px, Int_t py) |
virtual void | TObject::Draw(Option_t* option = "") |
virtual void | TObject::DrawClass() constMENU |
virtual TObject* | TObject::DrawClone(Option_t* option = "") constMENU |
virtual Long64_t | DrawScript(const char* wrapperPrefix, const char* macrofilename, const char* cutfilename, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual Long64_t | TVirtualTreePlayer::DrawScript(const char* wrapperPrefix, const char* macrofilename, const char* cutfilename, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual Long64_t | DrawSelect(const char* varexp, const char* selection, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual Long64_t | TVirtualTreePlayer::DrawSelect(const char* varexp, const char* selection, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual void | TObject::Dump() constMENU |
virtual void | TObject::Error(const char* method, const char* msgfmt) const |
virtual void | TObject::Execute(const char* method, const char* params, Int_t* error = 0) |
virtual void | TObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0) |
virtual void | TObject::ExecuteEvent(Int_t event, Int_t px, Int_t py) |
virtual void | TObject::Fatal(const char* method, const char* msgfmt) const |
virtual TObject* | TObject::FindObject(const char* name) const |
virtual TObject* | TObject::FindObject(const TObject* obj) const |
virtual Int_t | Fit(const char* formula, const char* varexp, const char* selection, Option_t* option, Option_t* goption, Long64_t nentries, Long64_t firstentry) |
virtual Int_t | TVirtualTreePlayer::Fit(const char* formula, const char* varexp, const char* selection, Option_t* option, Option_t* goption, Long64_t nentries, Long64_t firstentry) |
static TVirtualTreePlayer* | TVirtualTreePlayer::GetCurrentPlayer() |
virtual Int_t | GetDimension() const |
virtual Int_t | TVirtualTreePlayer::GetDimension() const |
virtual Option_t* | TObject::GetDrawOption() const |
static Long_t | TObject::GetDtorOnly() |
virtual Long64_t | GetEntries(const char* selection) |
virtual Long64_t | TVirtualTreePlayer::GetEntries(const char*) |
virtual Long64_t | GetEntriesToProcess(Long64_t firstentry, Long64_t nentries) const |
virtual TH1* | GetHistogram() const |
virtual TH1* | TVirtualTreePlayer::GetHistogram() const |
virtual const char* | TObject::GetIconName() const |
virtual const char* | TObject::GetName() const |
virtual Int_t | GetNfill() const |
virtual Int_t | TVirtualTreePlayer::GetNfill() const |
virtual char* | TObject::GetObjectInfo(Int_t px, Int_t py) const |
static Bool_t | TObject::GetObjectStat() |
virtual Option_t* | TObject::GetOption() const |
const char* | GetScanFileName() const |
virtual TTreeFormula* | GetSelect() const |
virtual TTreeFormula* | TVirtualTreePlayer::GetSelect() const |
virtual Long64_t | GetSelectedRows() const |
virtual Long64_t | TVirtualTreePlayer::GetSelectedRows() const |
TSelector* | GetSelector() const |
TSelector* | GetSelectorFromFile() const |
virtual const char* | TObject::GetTitle() const |
virtual UInt_t | TObject::GetUniqueID() const |
virtual Double_t* | GetV1() const |
virtual Double_t* | TVirtualTreePlayer::GetV1() const |
virtual Double_t* | GetV2() const |
virtual Double_t* | TVirtualTreePlayer::GetV2() const |
virtual Double_t* | GetV3() const |
virtual Double_t* | TVirtualTreePlayer::GetV3() const |
virtual Double_t* | GetV4() const |
virtual Double_t* | TVirtualTreePlayer::GetV4() const |
virtual Double_t* | GetVal(Int_t i) const |
virtual Double_t* | TVirtualTreePlayer::GetVal(Int_t) const |
virtual TTreeFormula* | GetVar(Int_t i) const |
virtual TTreeFormula* | TVirtualTreePlayer::GetVar(Int_t) const |
virtual TTreeFormula* | GetVar1() const |
virtual TTreeFormula* | TVirtualTreePlayer::GetVar1() const |
virtual TTreeFormula* | GetVar2() const |
virtual TTreeFormula* | TVirtualTreePlayer::GetVar2() const |
virtual TTreeFormula* | GetVar3() const |
virtual TTreeFormula* | TVirtualTreePlayer::GetVar3() const |
virtual TTreeFormula* | GetVar4() const |
virtual TTreeFormula* | TVirtualTreePlayer::GetVar4() const |
virtual Double_t* | GetW() const |
virtual Double_t* | TVirtualTreePlayer::GetW() const |
virtual Bool_t | TObject::HandleTimer(TTimer* timer) |
virtual ULong_t | TObject::Hash() const |
virtual void | TObject::Info(const char* method, const char* msgfmt) const |
virtual Bool_t | TObject::InheritsFrom(const char* classname) const |
virtual Bool_t | TObject::InheritsFrom(const TClass* cl) const |
virtual void | TObject::Inspect() constMENU |
void | TObject::InvertBit(UInt_t f) |
virtual TClass* | IsA() const |
virtual TClass* | TVirtualTreePlayer::IsA() const |
virtual TClass* | TObject::IsA() const |
virtual Bool_t | TObject::IsEqual(const TObject* obj) const |
virtual Bool_t | TObject::IsFolder() const |
Bool_t | TObject::IsOnHeap() const |
virtual Bool_t | TObject::IsSortable() const |
Bool_t | TObject::IsZombie() const |
virtual void | TObject::ls(Option_t* option = "") const |
virtual Int_t | MakeClass(const char* classname, Option_t* option) |
virtual Int_t | TVirtualTreePlayer::MakeClass(const char* classname, const char* option) |
virtual Int_t | MakeCode(const char* filename) |
virtual Int_t | TVirtualTreePlayer::MakeCode(const char* filename) |
virtual Int_t | MakeProxy(const char* classname, const char* macrofilename = 0, const char* cutfilename = 0, const char* option = 0, Int_t maxUnrolling = 3) |
virtual Int_t | TVirtualTreePlayer::MakeProxy(const char* classname, const char* macrofilename = 0, const char* cutfilename = 0, const char* option = 0, Int_t maxUnrolling = 3) |
void | TObject::MayNotUse(const char* method) const |
virtual Bool_t | TObject::Notify() |
static void | TObject::operator delete(void* ptr) |
static void | TObject::operator delete(void* ptr, void* vp) |
static void | TObject::operator delete[](void* ptr) |
static void | TObject::operator delete[](void* ptr, void* vp) |
void* | TObject::operator new(size_t sz) |
void* | TObject::operator new(size_t sz, void* vp) |
void* | TObject::operator new[](size_t sz) |
void* | TObject::operator new[](size_t sz, void* vp) |
TVirtualTreePlayer& | TVirtualTreePlayer::operator=(const TVirtualTreePlayer&) |
TObject& | TObject::operator=(const TObject& rhs) |
virtual void | TObject::Paint(Option_t* option = "") |
virtual void | TObject::Pop() |
virtual TPrincipal* | Principal(const char* varexp, const char* selection, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual TPrincipal* | TVirtualTreePlayer::Principal(const char* varexp = "", const char* selection = "", Option_t* option = "np", Long64_t nentries = 1000000000, Long64_t firstentry = 0) |
virtual void | TObject::Print(Option_t* option = "") const |
virtual Long64_t | Process(const char* filename, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual Long64_t | Process(TSelector* selector, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual Long64_t | TVirtualTreePlayer::Process(const char* filename, Option_t* option = "", Long64_t nentries = 1000000000, Long64_t firstentry = 0) |
virtual Long64_t | TVirtualTreePlayer::Process(TSelector* selector, Option_t* option = "", Long64_t nentries = 1000000000, Long64_t firstentry = 0) |
virtual TSQLResult* | Query(const char* varexp, const char* selection, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual TSQLResult* | TVirtualTreePlayer::Query(const char* varexp, const char* selection, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual Int_t | TObject::Read(const char* name) |
virtual void | RecursiveRemove(TObject* obj) |
virtual void | TObject::RecursiveRemove(TObject* obj) |
void | TObject::ResetBit(UInt_t f) |
virtual void | TObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU |
virtual void | TObject::SavePrimitive(basic_ostream<char,char_traits<char> >& out, Option_t* option = "") |
virtual Long64_t | Scan(const char* varexp, const char* selection, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual Long64_t | TVirtualTreePlayer::Scan(const char* varexp, const char* selection, Option_t* option, Long64_t nentries, Long64_t firstentry) |
Bool_t | ScanRedirected() |
void | TObject::SetBit(UInt_t f) |
void | TObject::SetBit(UInt_t f, Bool_t set) |
virtual void | TObject::SetDrawOption(Option_t* option = "")MENU |
static void | TObject::SetDtorOnly(void* obj) |
virtual void | SetEstimate(Long64_t n) |
virtual void | TVirtualTreePlayer::SetEstimate(Long64_t n) |
static void | TObject::SetObjectStat(Bool_t stat) |
static void | TVirtualTreePlayer::SetPlayer(const char* player) |
void | SetScanFileName(const char* name) |
void | SetScanRedirect(Bool_t on = kFALSE) |
virtual void | SetTree(TTree* t) |
virtual void | TVirtualTreePlayer::SetTree(TTree* t) |
virtual void | TObject::SetUniqueID(UInt_t uid) |
virtual void | ShowMembers(TMemberInspector& insp, char* parent) |
virtual void | TVirtualTreePlayer::ShowMembers(TMemberInspector& insp, char* parent) |
virtual void | TObject::ShowMembers(TMemberInspector& insp, char* parent) |
virtual void | StartViewer(Int_t ww, Int_t wh) |
virtual void | Streamer(TBuffer& b) |
virtual void | TVirtualTreePlayer::Streamer(TBuffer& b) |
virtual void | TObject::Streamer(TBuffer& b) |
void | StreamerNVirtual(TBuffer& b) |
void | TVirtualTreePlayer::StreamerNVirtual(TBuffer& b) |
void | TObject::StreamerNVirtual(TBuffer& b) |
virtual void | TObject::SysError(const char* method, const char* msgfmt) const |
Bool_t | TObject::TestBit(UInt_t f) const |
Int_t | TObject::TestBits(UInt_t f) const |
static TVirtualTreePlayer* | TVirtualTreePlayer::TreePlayer(TTree* obj) |
virtual Int_t | UnbinnedFit(const char* formula, const char* varexp, const char* selection, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual Int_t | TVirtualTreePlayer::UnbinnedFit(const char* formula, const char* varexp, const char* selection, Option_t* option, Long64_t nentries, Long64_t firstentry) |
virtual void | UpdateFormulaLeaves() |
virtual void | TVirtualTreePlayer::UpdateFormulaLeaves() |
virtual void | TObject::UseCurrentStyle() |
virtual void | TObject::Warning(const char* method, const char* msgfmt) const |
virtual Int_t | TObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) |
virtual Int_t | TObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const |
void | DeleteSelectorFromFile() |
virtual void | TObject::DoError(int level, const char* location, const char* fmt, va_list va) const |
const char* | GetNameByIndex(TString& varexp, Int_t* index, Int_t colindex) |
void | TObject::MakeZombie() |
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) |
TTreePlayer(const TTreePlayer&) | |
TTreePlayer& | operator=(const TTreePlayer&) |
enum TObject::EStatusBits { | kCanDelete | |
kMustCleanup | ||
kObjInCanvas | ||
kIsReferenced | ||
kHasUUID | ||
kCannotPick | ||
kNoContextMenu | ||
kInvalidObject | ||
}; | ||
enum TObject::[unnamed] { | kIsOnHeap | |
kNotDeleted | ||
kZombie | ||
kBitMask | ||
kSingleKey | ||
kOverwrite | ||
kWriteDelete | ||
}; |
Int_t | fDimension | Dimension of the current expression |
TList* | fFormulaList | ! Pointer to a list of coordinated list TTreeFormula (used by Scan and Query) |
TH1* | fHistogram | ! Pointer to histogram used for the projection |
TList* | fInput | ! input list to the selector |
const char* | fScanFileName | Name of the file where Scan is redirected |
Bool_t | fScanRedirect | Switch to redirect TTree::Scan output to a file |
Long64_t | fSelectedRows | Number of selected entries |
TSelectorDraw* | fSelector | ! Pointer to current selector |
TClass* | fSelectorClass | ! Pointer to the actual class of the TSelectorFromFile |
TSelector* | fSelectorFromFile | ! Pointer to a user defined selector created by this TTreePlayer object |
TSelector* | fSelectorUpdate | ! Set to the selector address when it's entry list needs to be updated by the UpdateFormulaLeaves function |
TTree* | fTree | ! Pointer to current Tree |
Build the index for the tree (see TTree::BuildIndex)
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) IMPORTANT: The copied 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. Any changes made to the branch addresses of the copied trees are over-ridden anytime this tree changes its branch addresses. Once this tree is deleted, all the addresses of the copied tree are reset to their default values. 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();
Delete any selector created by this object. The selector has been created using TSelector::GetSelector(file)
Draw the result of a C++ script. The macrofilename and optionally cutfilename are assumed to contain at least a method with the same name as the file. The method should return a value that can be automatically cast to respectively a double and a boolean. Both methods will be executed in a context such that the branch names can be used as C++ variables. This is accomplished by generating a TTreeProxy (see MakeProxy) and including the files in the proper location. If the branch name can not be used a proper C++ symbol name, it will be modified as follow: - white spaces are removed - if the leading character is not a letter, an underscore is inserted - < and > are replace by underscores - * is replaced by st - & is replaced by rf If a cutfilename is specified, for each entry, we execute if (cutfilename()) htemp->Fill(macrofilename()); If no cutfilename is specified, for each entry we execute htemp(macrofilename()); The default for the histogram are the same as for TTreePlayer::DrawSelect
Draw expression varexp for specified entries Returns -1 in case of error or number of selected events in case of success. varexp is an expression of the general form - "e1" produces a 1-d histogram of expression "e1" - "e1:e2" produces a 2-d histogram (or profile) of "e1" versus "e2" - "e1:e2:e3" produces a 3-d scatter-plot of "e1" versus "e2" versus "e3" - "e1:e2:e3:e4" produces a 3-d scatter-plot of "e1" versus "e2" versus "e3" and "e4" mapped on the color number. 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 distribution 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. 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. The expressions can use all the operations and build-in functions supported by TFormula (See TFormula::Analyze), including free standing function taking numerical arguments (TMath::Bessel). In addition, you can call member functions taking numerical arguments. For example: - "TMath::BreitWigner(fPx,3,2)" - "event.GetHistogram().GetXaxis().GetXmax()" - "event.GetTrack(fMax).GetPx() The 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 weight = 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 assume, 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 now also properly handles 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 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; i0 < min(3,2); i0++) { use the value of (fMatrix[i0][2] - fMatrix[3][i0]) } So the loop equivalent to "fMatrix[][2] - fResults[][]" is: for (Int_t i0; i0 < min(3,5); i0++) { 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; i0 < min(3,5); i0++) { for (Int_t i1; i1 < min(3,2); i1++) { use the value of (fMatrix[i0][i1] - fResults[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] } } Saving the result of Draw to an histogram By default the temporary histogram created is called htemp. One can retrieve a pointer to this histogram with: TH1F *htemp = (TH1F*)gPad->GetPrimitive("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 (and also the current pad). 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"); 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 refered 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()) 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) 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 arr[0]+arr2[0] ; arr[1]+arr2[1] and arr[1]+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)"); 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"); 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. 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. The option=prof is automatically selected in case of z:y:x>>pf where pf is an existing TProfile2D histogram. Making a 5-D plot with GL When the option "gl5d" is specified and the dimension of the query is 5 a 5-d plot is created using GL, eg T->Draw("x:y:z:u:w","","gl5d") 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. Saving the result of Draw to a TEventList or a TEntryList 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 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 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 or a TEntryList 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 Example1: TEventList *elist = (TEventList*)gDirectory->Get("yplus"); tree->SetEventList(elist); tree->Draw("py"); Example2: TEntryList *elist = (TEntryList*)gDirectory->Get("yplus"); tree->SetEntryList(elist); tree->Draw("py"); 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 critera, the event entered in the list are all the event that have at least one element of the array that satisfy the selection. 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. Example: tree.Draw(">>pyplus","fTracks.fPy>0"); pyplus->SetReapplyCut(kTRUE); tree->SetEventList(pyplus); tree->Draw("fTracks.fPy"); will draw the fPy of only the tracks that have a positive fPy. 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 double array of V1 -GetV2() //returns a pointer to the double array of V2 -GetV3() //returns a pointer to the double 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();"
Fit a projected item(s) from a Tree. Returns -1 in case of error or number of selected events in case of success. The 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. 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)
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.
return the number of entries to be processed this function checks that nentries is not bigger than the number of entries in the Tree or in the associated TEventlist
-*-*-*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
Generate 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 Input file name - Definition of analysis class (data and functions) - the following class functions: - constructor (connecting by default 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: - 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 NOTE: Do not use the code generated for one Tree in case of a TChain. Maximum dimensions calculated on the basis of one TTree only might be too small when processing all the TTrees in one TChain. Instead of myTree.MakeClass(.., use myChain.MakeClass(..
Generate 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 - 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("anal.C"); where T is the name of the Tree in file myfile.root and anal.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.
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 file which will be included in by the generated skeletong. 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' class that are not split. 'unrolling' a class will allow direct access to its data members a class (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-bound * ability to use the branch data as 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 be 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()); This 2 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) { ... } is more efficient than if (fEventNumber<10 || fEventNumber>10) Access to TClonesArray. If a branch (or member) is a TClonesArray (let's say fTracks), you can access the TClonesArray itself by using ->: fTracks->GetLast(); However this will load the full TClonesArray object and its content. To quickly read the size of the TClonesArray use (note the dot): fTracks.GetEntries(); This will read only the size from disk if the TClonesArray has been split. To access the content of the TClonesArray, use the [] operator: float px = fTracks[i].fPx; // fPx of the i-th track Warning: The variable actually use for access are 'wrapper' around the real data type (to add autoload for example) and hence getting to the data involves the implicit call to a C++ conversion operator. This conversion is automatic in most case. However it is not invoked in a few cases, in particular in variadic function (like printf). So when using printf you should either explicitly cast the value or use any intermediary variable: fprintf(stdout,"trs[%d].a = %d\n",i,(int)trs.a[i]); 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
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 TTreePlayer::DrawSelect for explanation of the other parameters.
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,..); 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); } 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+"); }
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.
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". The function returns the number of entries passing the selection. By default 50 rows are shown and you are asked for <CR> to see the next 50 rows. You can change the default number of rows to be shown before <CR> via mytree->SetScanfield(maxrows) where maxrows is 50 by default. if maxrows is set to 0 all rows of the Tree are shown. This option is interesting when dumping the contents of a Tree to an ascii file, eg from the command line tree->SetScanField(0); tree->Scan("*"); >tree.log will create a file tree.log Arrays (within an entry) are printed in their linear forms. If several arrays with multiple dimensions are printed together, they will NOT be synchronized. For example print arr1[4][2] and arr2[2][3] will results in a printing similar to: * Row * Instance * arr1 * arr2 * * x * 0 * arr1[0][0]* arr2[0][0]* * x * 1 * arr1[0][1]* arr2[0][1]* * x * 2 * arr1[1][0]* arr2[0][2]* * x * 3 * arr1[1][1]* arr2[1][0]* * x * 4 * arr1[2][0]* arr2[1][1]* * x * 5 * arr1[2][1]* arr2[1][2]* * x * 6 * arr1[3][0]* * * x * 7 * arr1[3][1]* * However, if there is a selection criterion which is an array, then all the formulas will be synchronized with the selection criterion (see TTreePlayer::DrawSelect for more information). The options string can contains the following parameters: lenmax=dd Where 'dd' is the maximum number of elements per array that should be printed. If 'dd' is 0, all elements are printed (this is the default) colsize=ss Where 'ss' will be used as the default size for all the column If this options is not specified, the default column size is 9 precision=pp Where 'pp' will be used as the default 'precision' for the printing format. col=xxx Where 'xxx' is colon (:) delimited list of printing format for each column. The format string should follow the printf format specification. The value given will be prefixed by % and, if no conversion specifier is given, will be suffixed by the letter g. before being passed to fprintf. If no format is specified for a column, the default is used (aka ${colsize}.${precision}g ) For example: tree->Scan("a:b:c","","colsize=30 precision=3 col=::20.10:#x:5ld"); Will print 3 columns, the first 2 columns will be 30 characters long, the third columns will be 20 characters long. The printing format used for the columns (assuming they are numbers) will be respectively: %30.3g %30.3g %20.10g %#x %5ld
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.
-*-*-*-*-*Set number of entries to estimate variable limits *-* ================================================
Start the TTreeViewer on this TTree*- *-* =================================== ww is the width of the canvas in pixels wh is the height of the canvas in pixels
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 = "D" Draw the projected histogram with the fitted function normalized to the number of selected rows and multiplied by the bin width 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"); 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
this function is called by TChain::LoadTree when a new Tree is loaded. Because Trees in a TChain may have a different list of leaves, one must update the leaves numbers in the TTreeFormula used by the TreePlayer.