I try to save a canvas to a root tree:
TFile rootfile("testHistos.root","new");
/* more code */
rootfile.cd();
TCanvas* c1 = new TCanvas();
TH1D* h1 = new TH1D("ref","ref",1000,0,4000);
for (int ev=0;ev<par.N;ev++){
value = /*...*/
h1->Fill(value);
}
h1->Draw();
c1->Write();
but when I run this i get the error
Error in TFile::WriteTObject: Directory testHistos.root is not writable
I am sure that I have write access in that directory as I am writing other files in the same code. What could be the problem?
Also I wonder how to do the following:
In the same code I have functions that fill and display some histograms that I also want to save to the same file, but I dont know how to do it. It looks something like this:
void FillAndDrawHistograms(Data d){ /*... */ }
void thisIsMyMainFunction() {
TFile rootfile("testHistos.root","new");
/*...*/
FillAndDrawHistograms(d);
FillAndDrawHistograms(d2);
/*...*/
}
Do i have to pass the file to the function? Or can I simply call histogram->Write()
inside that function and it will be written to the file?