Dear all,
I have created a tree with 3 branches x, y, yerror and then i want to read the branches and make a plot with errors.I do the following and it doesn’t work:
TBranch *TX=tree->GetBranch("X");
TBranch *TY=tree->GetBranch("Y");
TBranch *TYerror=tree->GetBranch("Yerror");
double x[N],y[N],yerr[N];
TX->SetAddress(&x);
TY->SetAddress(&y);
TYerror->SetAddress(&yerr);
for (int k=0;k<N;k++)
{
x[k]=TX->GetEntry(k);
y[k]=TY->GetEntry(k);
yerr[k]=TYerror->GetEntry(k);
}
TCanvas *c1 = new TCanvas("c1","Radon",200,10,700,500);
TGraphErrors *gr = new TGraphErrors(N,x,y,yerr);
the branches have the correct values (i can verify this with the TBrowser) but if i plot it like this i get crazy values
thanks
t
Hallo rene,
thanks for the quick reply.
The First solution did not work but the second one did.
I cannot keep thinking why the first solution didn’t work.can you please revise it and give me any more ideas?
also is there a way to smooth the lines in the TGraphError directly, i.e. take the mean of each 10 points, or i have to do it before in the trees.
thanks again,
cheers
thodoros
Could you post your exact first version? In particular, did you notice teh difference between my first version and yours, in particular TX->SetAddress(x); TY->SetAddress(y); TYerror->SetAddress(yerr);
instead of TX->SetAddress(&x); TY->SetAddress(&y); TYerror->SetAddress(&yerr);
Rene
TBranch::GetEntry returns the number of bytes read from the disk (after decompression), so doing x[k]=TX->GetEntry(k); is clearly not what you intended. Instead use:
TBranch *TX=tree->GetBranch("X");
TBranch *TY=tree->GetBranch("Y");
TBranch *TYerror=tree->GetBranch("Yerror");
double xval,yval,yerrval
double x[N],y[N],yerr[N];
// Here guessing that the branch contains each a single double.
TX->SetAddress(&xval);
TY->SetAddress(&yval);
TYerror->SetAddress(&yerr);
for (int k=0;k<N;k++) {
TX->GetEntry(k);
x[k] = xval;
TY->GetEntry(k);
y[k] = yval;
TYerror->GetEntry(k);
yerr[k] = yerrval;
}
TCanvas *c1 = new TCanvas("c1","Radon",200,10,700,500);
TGraphErrors *gr = new TGraphErrors(N,x,y,yerr);[/code]