# Calling TBrowser + Filename directly in shell

**URL:** <https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936>\
**Category:** Newbie\
**Created:** [July 24, 2022, 7:39am UTC](https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936 "2022-07-24T07:39:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![xaratustra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xaratustra/32/13212_2.png) [@xaratustra](https://root-forum.cern.ch/u/xaratustra)\
**Post date:** [July 24, 2022, 7:39am UTC](https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936/1 "2022-07-24T07:39:50Z")

</div>

I successfully use:

```auto
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

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [July 24, 2022, 7:52am UTC](https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936/2 "2022-07-24T07:52:28Z")

</div>

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

```auto
root --web=off yourfile.root -e 'new TBrowser()'

```

---

<div class="post-metadata">

**Author:** ![xaratustra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xaratustra/32/13212_2.png) [@xaratustra](https://root-forum.cern.ch/u/xaratustra)\
**Post date:** [July 24, 2022, 8:13am UTC](https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936/3 "2022-07-24T08:13:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [July 24, 2022, 9:10am UTC](https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936/4 "2022-07-24T09:10:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![xaratustra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xaratustra/32/13212_2.png) [@xaratustra](https://root-forum.cern.ch/u/xaratustra)\
**Post date:** [July 25, 2022, 4:00pm UTC](https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936/5 "2022-07-25T16:00:38Z")

</div>

ok, I am almost there:

```auto
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

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [July 26, 2022, 4:41am UTC](https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936/6 "2022-07-26T04:41:55Z")

</div>

> [@xaratustra](#):
>
> all plots are plotted on the same canvas

> [@xaratustra](#):
>
> `canvas_list[ii].cd()`

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

---

<div class="post-metadata">

**Author:** ![xaratustra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xaratustra/32/13212_2.png) [@xaratustra](https://root-forum.cern.ch/u/xaratustra)\
**Post date:** [August 30, 2022, 1:49pm UTC](https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936/7 "2022-08-30T13:49:07Z")

</div>

well I actually thought that

```auto
 canvas_list[ii].cd()

```

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

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [August 31, 2022, 4:39am UTC](https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936/8 "2022-08-31T04:39:52Z")

</div>

> [@xaratustra](#):
>
> `ii` is the changing variable

Where is it changing?

---

<div class="post-metadata">

**Author:** ![xaratustra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xaratustra/32/13212_2.png) [@xaratustra](https://root-forum.cern.ch/u/xaratustra)\
**Post date:** [August 31, 2022, 10:54am UTC](https://root-forum.cern.ch/t/calling-tbrowser-filename-directly-in-shell/50936/9 "2022-08-31T10:54:11Z")

</div>

OMG! 🙀 I forgot to to do:

```auto
ii+=1

```

thanks!
