Hello,
I am trying to make a program that takes different root files with histograms and combines them together (different than hadd.C). All these files have the same format. This program reads in a text file which states the names of the files I want to merge, the histograms in those files I want to merge…etc. I have checked to make sure these are all spelled correctly.
I open this text file and store the filenames and histogram names in some vectors of strings. I want to put these in a for loop that would just open all of these files automatically. The problem is that when I try to open these files in the for loop, it says error histogramgenjets.root (the file name) does not exist. However, when I open all the files manually, it works. Here is a code snippet:
filenamelist is a vector of strings with the names of all the files I want to open, and numfiles is the number of files I want to open. finalhistograms.root is where I want to put all the stuff in the end. rhoHist1 is the name of a histogram in both files.
In general, it just keeps on telling me that the files in filenamelist don’t exist, even though they do. However, as I said, if I open them manually (instead of using filenamelist[j], it works.)
TFile* s[numfiles];
for (Int_t j = 0; j <numfiles; j++)
{
s[j] = TFile::Open(filenamelist[j].c_str(), "read");
if (j == 0)
{
TFile* d = new TFile ("finalhistograms.root", "recreate");
hs1[0]->Add((TH1F*)s[j]->Get(histlist[0].c_str()));
onedhists[0] = (TH1F*)s[j]->Get("rhoHist1");
onedhists[0]->Write();
d->Close();
}
else
{
TFile *d = new TFile ("finalhistograms.root", "update");
hs1[0]->Add((TH1F*)s[j]->Get(histlist[0].c_str()));
onedhists[0] = (TH1F*)s[j]->Get("rhoHist1");
onedhists[0]->Write();
d->Close();
}
}