Hi,
I am trying to output some fit parameters to an ascii file. Therefore I am calling root with a given tree (e.g. root test.root), access histograms with TH1F* hist = (TH1F*)gROOT->FindObject(histname);
fit those and write the parameters to a file with
ofstream fout;
ostringstream ostr_fname("");
ostr_fname << “par_”<<runtime<<"_"<<smthits<<".txt";
fout.open(ostr_fname.str().c_str());
TFile *ofile = new TFile(ostr_fname.str().c_str(),"RECREATE");
…
fout<<"Parameter “<<i<<” “<<k<<”: "<<cstr_par1<Write();
That works fine if I try it only once, but I have the whole stuff in a large loop and the second time I call
TH1F* hist = (TH1F*)gROOT->FindObject(histname);
Root does not find the histogram anymore as the current directory was changed to my output ascii-file and I get an interpretor error.
I do not want to specify the input file name INSIDE my macro (so that I could use infile->cd()), so my question is, how I can get the name of the input file from Root at the beginning, when it is correct and set back to it at the end of the first loop run?
Thanks in advance
Petra