void example() { TCanvas* canvas = new TCanvas("myCanvas", "My Canvas", 800, 600); cout << "Canvas name: " << canvas->GetName() << endl; }
TFile* file = new TFile("histograms.root", "READ"); TH1F* hist = (TH1F*)file->Get("myHistogram"); TCanvas* canvas = new TCanvas("myCanvas", "My Canvas", 800, 600); hist->Draw(); canvas->SaveAs("myHistogram.png"); cout << "Canvas name: " << canvas->GetName() << endl;In this example, we open a ROOT file containing a histogram object called "myHistogram". We then create a canvas object called "myCanvas" and draw the histogram onto it. We save the canvas as a PNG file and print out the canvas name to the console.