Dynamic text/Legend in ROOT


I have spent half an hour trying to figure out how to do in ROOT someting I know
how to do in PAW without sucess … ;8-(

I want to place the text or Legend on the histogram canvas dynamically.
Say, I fit the exponential decay histogram, get the lifetime and now, in
a root code want to write this fitted lifetime value in the corner of the canvas.

In PAW I would use the substitution scheme using [] and $ like in

macro phase_space 1=1 2=401 3=1001 4=2001 5=-65 6=-100


text [zp] -0.107 [zt] 0.5

How do I do similar things in ROOT?
For example, in the command

l.DrawLatex (70,0.8*h6002->GetMaximum(),"#tau_{#pi}=25.6#pm 0.3 ns");

how would I avoid hard-wireng 25.6 and 0.3 in text and use the actual
fitted values from the code preceeding l.DrawLatex?

                                                                         Cheers, Emil

The simplest way to plot fit results is to use


See: root.cern.ch/root/htmldoc/TStyle … :SetOptFit

This is the equivalent of the PAW command “OPTION FIT”

More generally, if you want to plot any numeric value using TLatex (like your PAW example suggested), you should use Form():

l.DrawLatex (70,0.8*h6002->GetMaximum(),Form("#tau_{#pi}=%g #pm %g ns",val1,val2));