Hi all,
A part of my code involves writing the same named histograms on each other.
TH2D *myhist[56];
for(const int n=0; n<size; n++){
for (const int i=0; i<size2;i++ ) {
TFile *f = new TFile(fname);
read stuff iterated over ‘i’ and save to some buffer array;
f->Close();
TFile *fn = new TFile(“test.root”, “RECREATE”);
TString hiname = i; //because TH2D doesn’t take integer as title
myhist[i] = new TH2D(hiname,title,other parameters);
myhist[i]->Fill(n,i);
myhist[i]->Write();
fn->Close();
}}
It keeps on writing histos on themselvess and ends up with the last value of myhist[i] being written to file. When I change parameter “RECREATE” to “UPDATE”, it writes all the data but then the output takes the following format ;
hiname;1
hiname;2
.
.
hiname;n
having ‘1’ entry at each histogram (i*n histograms in total) instead of having ‘i’ histograms with n entries. After that I can combine those individual Trees but that is completely unnecessary. I can also achieve what I want by merging data by ‘htop’ but I don’t want to add extra phase to the analysis. Defining as a list and pushing ‘Addlist’ provided the same result as ‘UPDATE’ parameter option as well.
Also each iteration file I/O consumes time but myhist[i]->Write(); operates on the last file pointer by default thus reading/writing different files in the same loop is achieved like that. There should be a better way to do this.
Problems are ROOT specific, not ANSI C thus I think experienced users can save me some time on this.
Thanks.