Calling TBrowser + Filename directly in shell

I successfully use:

root --web=off -e 'new TBrowser()'

to open a TBrowser directly from shell. But then I have to navigate and find my root file and open it by double click. My question is, is it possible to pass the filename as well, so that TBrowser already has that file open and shows the histogram in it? all in one go?

_ROOT Version: 6.26/04
Platform: osx
Compiler: PyROOT

Just add the name of the root file (before opening the new TBrowser)

root --web=off yourfile.root -e 'new TBrowser()'
1 Like

that’s great. Now it appears in the navigation tree under ROOT Files. But is there any way to actually display the histogram in it? Like adding a command after new TBrowser() to actually search for whatever histogram or graph is inside the root file and actually plot it on canvas?

The idea is to have this in one go.

At this point it’s better to just write a small macro
https://root.cern/doc/master/h1ReadAndDraw_8C.html
(Basically, use TFile, Get/GetObject, Draw)

1 Like

ok, I am almost there:

def plot_all(filename):
    f = TFile(filename)
    canvas_list = []
    for ii in range (f.GetNkeys()):
        canvas_list.append(TCanvas(f'c{ii}', f'c{ii}', 900, 600))
    
    ii = 0
    for k in f.GetListOfKeys():
        if k.GetClassName().lower().startswith('th') or k.GetClassName().lower().startswith('tgraph'):
            el = f.Get(f'{k.GetName()}')

            canvas_list[ii].cd()
            canvas_list[ii].GetCanvasImp().ShowMenuBar()
            canvas_list[ii].GetCanvasImp().ShowToolBar()
            canvas_list[ii].GetCanvasImp().ShowStatusBar()
            canvas_list[ii].GetCanvasImp().ShowEditor()

            el.Draw()
            canvas_list[ii].Draw()

which works, but has 2 problems:

  • all plots are plotted on the same canvas, it seems that cd() gets ignored
  • In the batch mode, I have to somehow tell the python interpreter to wait after plotting, not just create and close

If you run in batch mode, save them to image files (e.g. canvas.SaveAs("plot.png"))

well I actually thought that

 canvas_list[ii].cd()

does the job of cd-ing to the next canvas, because ii is the changing variable, doesn’t it?

Where is it changing?

OMG! :scream_cat: I forgot to to do:

ii+=1

thanks!