Hello everyone,
I need to import some root files and convert trees to arrays. To do that, I must pass a TTree object to tree2array() function. According to most tutorials, the TFile.Get() method automatically returns a TTree object if the the path provided points to a TTree. But this doesn’t seem to be the case with me:
>>> tree = tfile.2los_1tau_forBDTTraining.sel.evtntuple.signal.evtTree
File "<stdin>", line 1
tree = tfile.2los_1tau_forBDTTraining.sel.evtntuple.signal.evtTree
^
SyntaxError: invalid syntax
PyROOT casts objects to the actual one, so Get() normally works fine. Above, you only print the type, but I’m willing to bet that it’s a nullptr: auto-casting can’t work unless there is an actual object to retrieve the type from. (Check ‘not not tree’, ‘tree == None’, or simply print ‘tree’ instead of ‘type(tree)’.)
thanks for your responses but it’s my stupidity that caused the problem. Turns out, the directory structure string “2los_1tau_forBDTTraining/sel/evtntuple/signal/evtTree” is case-sensitive and since i put it in by hand, there was a mistake it really is ‘2los_1tau_forBDTtraining’, not 2los_1tau_forBDTTraining’’. Sorry for my baseless complaint guys, it works now.