Alex Pearwin

TBrowser shortcut

This post has been archived. It's pretty old and likely concerns topics that are avoidable by using more modern tools and techniques. The original text is preserved below for posterity but it may no longer be relevant or correct.

One of the nice features of ROOT, a data analysis framework commonly used in particle physics, is the TBrowser file browser.

Old familiar: a ROOT TBrowser

It lets you view the directory structure of ROOT files, as well as quickly create histograms of ntuple branches. It’s so useful that I use it a lot during the day, maybe 20 times or more. Using it then becomes a little tedious, as its instantiation is a little more verbose than I care for, particularly when I’m typing it all day.

$ root my_file.root
root [0] new TBrowser // Pointer, or
root [1] TBrowser asd // Reference

So I cobbled something together which requires minimal effort.

$ tb my_file.root

This starts ROOT and brings up a TBrowser with my_file.root loaded.

Implementation

There are probably a few ways to do this, but I went for a shell function and a ROOT macro.

In a file my shell looks at, such as .zshrc, I have the function tbrowser.

tbrowser () {
  # Check a file has been specified
  if (( $# == 0 )); then
    echo "No file(s) specified."
  else
    # For each file, check it exists
    for i; do
      if [ ! -f $i ]; then
        echo "Could not find file $i"
        return 1;
      fi
    done
    root -l $* $HOME/.macros/newBrowser.C
  fi
}

This calls a macro newBrowser.C in a hidden folder .macros in my home directory. All the macro does is create a TBrowser object, as you might expect.

void newBrowser() {
  new TBrowser;
}

As I really am lazy, I alias the tbrowser function to tb; again, in a file my shell looks at.

alias tb="tbrowser"

As an aside, if you haven’t already created an alias to hide that obnoxious ROOT splash screen, I’d recommend it.

alias root="root -l"