Error using SetDirectory

I’m getting this error when I try to run a python plotting script:

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

Here is the part of the script for fetching the histograms / where I’m getting the error:

fileName1 = "20200311_histos.root"
variable1 = "recpt"
file1 = ROOT.TFile.Open(fileName1,"READ")
h1 = file1.Get(variable1)
if (file1.IsOpen()):

and the lines used for fetching python / importing ROOT:

#!usr/bin/env python
import os
import sys
import numpy as np
import math
from array import array
import ROOT

(I installed ROOT with homebrew.)

Does anyone know how to solve this?

It is true that TObject does not have a SetDirectory method. It looks like your object h1 is considered as a TObject it should be a TH1. (@etejedor ?)


I believe the problem is that the histogram is not retrieved correctly from the file, at this line:

h1 = file1.Get(variable1)

Can you double check that “recpt” exists in the file? You can do file1->ls().