Text on every Canvas with rootlogon.C


I’m trying to create a standard rootlogon.C file for an experiment. It should show a standard text on every canvas which is created. I was trying the following in my rootlogon.C:

TPaveText* Text = new TPaveText(0.5,0.92,0.9,0.96,"nbNDC");
Text->AddText("My Experiment");


This causes a segfault. I further tried Add(Text->Clone()) and AddLast with the same result (I guess the gPad list of primitives doesn’t exist at this stage).

Am I going down the right road with TPaveText? How can such a standard text be implemented in a rootlogon.C file?

Many thanks

Try: if (gPad) gPad->GetListOfPrimitives()->Add(Text); else std::cout << "You MUST create a canvas FIRST!" << std::endl; … or simply … Text->Draw();

Well, this is not what I have in mind. I want the text to be on all my canvases I create later on. That’s why I use the rootlogon file. I want it to be in the gStyle somehow.

Let me rephrase my question:

Is it possible to change the gStyle such, that a text appears on every canvas produced later in the code?

The simplest way would be to declare a function in rootlogon.C which creates a TCanvas and add a text on it. Then you can use it each time you need to create a canvas instead of using TCanvas ctor.

Thanks, this is indeed an option. The problem is, this rootlogon file should be used by every collaborator including old professors, who probably won’t change their habits. But I guess there is no foolproof option.


I do not see why that should be a problem even for “old professors”. If you declare this new function they are not oblige to use it. If they understand that will provide us some functionality they needed I bet they will use it :slight_smile:. Old professors are wise :wink: