I have several root files where (apart from some TTrees), some TH2 objects are stored. I want to add all those TH2 objects without _hadd_ing all the root files as that will make the output file large.
I have attached a small macro representing my issue. When I take filename from a list (reco.txt), it gives me error:
Error in TFile::TFile: file name is not specified
Error in TH2F::Add: Attempt to add a non-existing histogram
But when I write exact location in TFile as TFile* f1 = new TFile("some/location/file.root");
it works. Can someone please explain the issue?
Attached are the list file, macro, and the root file which were able to produce the said outputs. addhisto.C (483 Bytes) trialreco.root (17.1 KB) reco.txt (51 Bytes)
I checked reco.txt but I don’t see any extra blank line there which should give me this error. So, is there a reason (code or the editor) that within the while loop an extra line is seen?
I tried by replacing while with a for loop with the number of iterations = number of lines in the file. But that is like a forced measure even though a simple measure.