I’m trying to call the TCanvas::Print method to save a histogram as a .png file. When I do it, it throws no errors, and each of the histograms appears normally in a window, but as far as I can tell the .png files aren’t saved anywhere.
The relevant code:
TCanvas* canvas = new TCanvas();
main_hist_raw->Draw();
main_hist_1b->SetLineColor(kRed);
main_hist_1b->Draw("SAME");
main_hist_2b->SetLineColor(kGreen);
main_hist_2b->Draw("SAME");
print_hists_and_error(("----" + cut_names[i] + "----").c_str(), main_hist_raw, main_hist_1b, main_hist_2b);
canvas->Print(("subtract_bg_" + cut_names[i]).c_str(), "png"); // Doesn't appear to do anything.
cut_names[i] is a std::string, and the main_hist_* files are TH1F pointers.
I’ve also tried SaveAs, but it doesn’t appear to do anything either. I’ve tried starting the file path with both “~/” and the absolute path of the save directory I wanted, but it didn’t appear there either.
Try to add: std::cout << "pwd = " << gSystem->pwd() << std::endl;
canvas->Modified(); canvas->Update(); right before "canvas->Print(…);"
Are you sure you have “write permissions” for the returned “pwd” path? Isn’t it “write protected”?
[quote=“Pepe Le Pew”]Try to add: std::cout << "pwd = " << gSystem->pwd() << std::endl;
canvas->Modified(); canvas->Update(); right before "canvas->Print(…);"
Are you sure you have “write permissions” for the returned “pwd” path? Isn’t it “write protected”?[/quote]
I ran that first line of code, and the directory it printed is one that I definitely have write permission to.