Disappearing Canvas

Hi everybody,
I have a problem with saving my data to a root file. I am creating a several canvas in a loop all consisting of three Histogramms, which I all save to a .root file. When I am naming the canvas all the same (e.g. “TCanvas *c = new TCanvas(“Canvas”,“Canvas”,800,1400);”), everything works fine, and the Canvas get labelled as Canvas;1 Canvas ;2 etc. No I tried to change the name doing the following:

const char* Canvasname = std::to_string(Energy).c_str();
TCanvas *c = new TCanvas(Canvasname,“Canvas”,800,1400);

where Energy is an integer. This leads to the following problem: When opening the root file, I do get the Canvas named as wished but when I try to open them in the TBrowser they appear for a second and then vanish. Also there seems to be only one Histogram in each canvas suddenly. I do not understand, why changing the name should lead to this problem. Maybe somebody knows an answer to this.

Thank you!

ROOT Version: 7
Platform: MacOs
Compiler: Not Provided

TCanvas *c = new TCanvas(TString("Canvas_") + Energy, "Canvas", 800, 1400);

1 Like

Thank you so much, that solves the problem very quick.
Have a nice day

Sorry to bother everybody again with a similar problem, but I do not understand, what I did wrong this time. Since I have an energy range, I tried to make the title more precise:

TCanvas *c = new TCanvas(TString(“NoCutsBKGpoly_”)+EnergyLow+TString(“-”)+EnergyHigh,TString(“NoCutsBKGpoly_”)+EnergyLow+TString(“-”)+EnergyHigh,800,1400);

This leads to the same problem I had before. Is it not possible to add several TStrings?

TString("NoCutsBKGpoly_") + EnergyLow + "_" + EnergyHigh

1 Like