How can I draw some branches from a tree with error bars

Hi there
I have a C macro which give me a Tree is called “tree”, this Tree has many branches “” k1.mean ,time, p, t, k1.error_mean , …etc"".
How can I draw one branch vs other branch but with error bar which take values from third branch.
example: I want to use “k1.error_mean"branch as error bar in k1.mean in this plot :


See the TTree HTML documentation and its member functions GetV1(), GetV2() …

Drawing a TGraphErrors seems to be a quite common thing. Couldn’t it be added as a simple Draw() option to a TTree?

Here is a really simple macro doing the job nicely. Put it in a file called Tree2Graph.C.

TGraphAsymmErrors* Tree2Graph(TTree* t, char* exp) {
    Int_t n = t->GetEntries();

    t->Draw(exp,"","para goff");

    TGraphAsymmErrors *g = new TGraphAsymmErrors(n,
                                                 t->GetVal(1), t->GetVal(2),
                                                 t->GetVal(3), t->GetVal(4),
                                                 t->GetVal(5), t->GetVal(6)
    return g;

To use it do (“ntuple” is the one in hsimple.root):

root [0] .L Tree2Graph.C
root [1] TGraphAsymmErrors *g
root [2] g = Tree2Graph(ntuple,"px:px:px:py:pz:px")
root [4] g->Draw("apl")

Of course it can be more clever and build a TGraph, TGraphError or TGraphAsymmErrors according to the number of variables in exp (it is enough to count the “:”).