Hi,
I could use some pointers to read an array of histograms from a file. I wrote them out using the commands hist[j]->Write(); When I look at the file using TBrowser, the names have the form hist;1, hist;2, but that may be the way that I created them. My code to read them in is
for (int j=0;j<numhists;j++) {
TString xa=TString::Format("dstempright;%d",j+1);
cout<<"File names to read:"<<xa<<endl;
dsdtright[j] = (TH1F*)histfile->Get(xa);
TH1F* tempd = (TH1F*)histfile->Get(xa); *** Alternate version***
dsdtright[j]=tempd->Clone();
// dsdtright[j]=tempd;
}
I have tried a number of approaches to read in the histograms. The TH1F* tempd histogram is filled as expected, but I have not been able to either read the histogram into dsdtright[j], or to transfer the information from tempd to dsdtright[j], using either an equals sign or tempd-> Clone()
When I try dsdtright[j] = (TH1F*)histfile->Get(xa); I get a segmentation violation.
When I try dsdtright[j]=tempd->Clone(); the error message is: error: assigning to ‘TH1F *’ from incompatible type ‘TObject *’
I’d appreciate it if someone could tell me how to make this work. More generally, a tutorial on histogram arrays would be really useful. This seems like a fairly common technique, but there seem to be many subtleties.
Thanks.
Spencer Klein
_ROOT Version:6.06/08
_Platform:Mac High Sierra 10.13.6
Compiler: Not Provided