Multiple lines with TText

Hi all,

I would like to print multiple variables next to the histograms I produce. I’ve looked at the following thread


and this works perfectly for one variable. Is there a nice way of doing this for multiple variables, without having to create a new TText object each time?

I’ve looked into using TPaveText, but the AddText function doesn’t take variables as input (and converting everything to strings for function input is messy).

Hi,

I think this post treats this topic: Split lines in TText or TLatex

Danilo

Hi Danilo,

Unfortunately, I think the post you linked to solved the user’s problem by applying a right alignment to his text, along with using a string splitting function in some instances. However, since I’m using double/float variables rather than strings, string split wouldn’t be viable (unless I converted everything to strings first, which seems cumbersome).

Ideally, I’d like to have multiple TText lines, but without having to create a large number of TText objects. Do you have any other ideas?

Perhaps using TLatex is a good choice (Split lines in TText or TLatex)

Danilo

Is there a command within the TLatex class that takes a variable as an argument, and plots it to the canvas? I’ve had a look at the documentation, and all I can find is something like DrawLatex or DrawText, which aren’t suitable.

For example, if I wanted to plot the number of entries of my histogram on the canvas, how would I go about doing that using TLatex, without having to manually type it in myself after running the code once already?

Hi,

perhaps the number of entries is a bad example since this is displayed in the stats panel.
If you want to format a string which is the input of TLatex you can either use the traditional stl classes, e.g. std::string, or some ROOT building blocks such as root.cern.ch/doc/master/classTS … fbb7a3db70 .

Cheers,
Danilo

Hi,

an example of usage of TString::Form:

root [2] const char* name="The name"
(const char *) "The name"
root [3] s = TString::Format("Hello %s", name)
(TString &) @0x10f6c4648
root [4] cout << s.Data() << endl;
Hello The name
root [5] int i = 3
(int) 3
root [6] s = TString::Format("Hello %d", i)
(TString &) @0x10f6c4648
root [7] cout << s.Data() << endl;
Hello 3

Danilo