AttributeError: 'TObject' object has no attribute 'SetDirectory'

Dear experts, I have a python script that is attempting to create Data cards from a hadded root file, but when I attempt to access SetDirectory for the root file, my error occurs. My code portion that is relevant is:

 self._outFile = ROOT.TFile.Open(outputDirDatacard + "/" + cutName + "/" + variableName + "/shapes/histos_" + tagNameToAppearInDatacard + ".root", 'recreate')


And, when I open my input hadded root file, I see:

TFile**		rootFile/plots_ggH2018_v7_11_11.root	
 TFile*		rootFile/plots_ggH2018_v7_11_11.root	
  KEY: TDirectoryFile	test;1	test

I suspect I’m trying to point it to the wrong thing. Any suggestions would be really appreciated! I am using ROOT 6.14/09 within the LXPlus cluster.


That error indicates that you tried to get a histogram from a ROOT file in Python, but that operation did not succeed and what you got back is a null pointer (to a TObject), and then you try to invoke SetDirectory on it. Can you print histoUp and histoDown to verify they actually point to something?

Hi, etejedor!

Thank you for your response! I ended up revamping an input file that was making some of my histograms come back unfilled. So, the error was actually legitimately useful yesterday (who would’ve thought, right?).

Thank you for your time!