Beginner: SetTitle in canvas doesn' t work


I am beginner in ROOT. I need to write simple macro. I am trying set title and name in Canvas but it is not correct.
Can anyone tell me how to correctly add a title and name in Canvas?
Thank you and best regards

void macros1() {
TFile f("Pion1GeV.root");
TTree * evt = (TTree*)f.Get("evt");

TCanvas c1("Pion E=1GeV", "Pion E=1GeV; z; x:z", 1600, 1000);
c1.SetTitle("Pion, E=1GeV");//doesn't work
c1.SetName("Pion, E=1GeV");//doesn't work

Welcome to the ROOT forum.

evt->GetHistogram()->SetTitle("Pion, E=1GeV");
1 Like

Now it is working ! Thank you very much Olivier Couet !

1 Like