Skip to main content

LHCb style for ROOT plots

Project description

LHCbStyle

PyPI version Conda-Forge Python 3.7‒3.9

Packaged version of the lhcbStyle.C macro with a python wrapper and utilities.

Looking for just the macro itself? Click here

Installation

NB: if using lb-conda default, this package is already available.

Via package managers

The python module can be installed using pip:

pip install lhcbstyle

or conda (via conda-forge):

conda install -c conda-forge lhcbstyle

Installing the macro

NB: conda users can ignore this step. It is done automatically.

After installing the package with pip or from source, there is one last step to install the lhcbStyle.C macro to ROOT's macro path. This is done using the console command:

lhcbstyle install

The default directory is found using the PyROOT function gROOT.GetMacroDir(), which is typically somewhere like /usr/share/root/macros or $ROOTSYS/macros. If you don't have permission to write to this directory, or you want to install the macro to a different ROOT installation, you can set the destination with an environment variable:

ROOT_MACRO_DIR=/path/to/macros lhcbstyle install

or use the command-line option --macro-dir:

lhcbstyle install --macro-dir /path/to/macros

If your chosen path does not correspond to $ROOTSYS/macros, then you can add it to ROOT's macro paths using your ~/.rootrc file. For example, if you installed lhcbStyle.C to ~/.local/share/root/macros then add this line to ~/.rootrc:

Unix.*.Root.MacroPath: .:$(HOME)/.local/share/root/macros:$(ROOTSYS)/macros

Usage

In C++

With the macro successfully installed, you can call it in the usual way:

gROOT->ProcessLine(".L lhcbStyle.C");
lhcbStyle();

The function lhcbStyle() takes a boolean argument print_msg which controls whether a message is printed to stdout upon setting the style.

The TPaveText (lhcbName), TText (lhcbLabel) and TLatex (lhcbLatex) objects are now located in the LHCbStyle namespace.

For example, to draw the "LHCb" blurb on a plot, using the default position:

LHCbStyle::lhcbName->Draw("same");

The TStyle object (lhcbStyle) is also available in the same namespace.

For example, to adjust the style before calling lhcbStyle():

LHCbStyle::lhcbStyle->SetPadLeftMargin(0.16);

or after calling lhcbStyle():

gStyle->SetPadLeftMargin(0.16);

In python

Naturally, in PyROOT, you can execute the macro in much the same way as in C++:

ROOT.gROOT.ProcessLine(".L lhcbStyle.C")
ROOT.lhcbStyle()

However, the package includes a python class called LHCbStyle which adds context management, allowing the use of the with keyword, e.g.:

from lhcbstyle import LHCbStyle

with LHCbStyle() as lbs:
    can = ROOT.TCanvas()
    hist = make_plot()
    hist.Draw("E1")
    lbs.lhcbName.Draw("same")
    can.SaveAs("hist_lhcb.png")

From the command line

There is also a console command lhcbstyle plot which draws a plotable object saved to a ROOT file.

The positional arguments are:

  1. the ROOT file to open
  2. the name of the TObject to draw
  3. the output filename, without extension (optional, defaults to "plot")

The optional arguments are:

  • --draw-style, -D: option string to pass to the Draw() function
  • --formats, -F: file extensions to save the plot as

Additionally an label can be added to the plot with one of:

  • --official: draw "LHCb" label
  • --preliminary: draw "LHCb Preliminary" label
  • --simulation: draw "LHCb Simulation" label
  • --unofficial: draw "LHCb Unofficial" label
  • --no-label: don't draw any label (default)

For example, to open plot.root, extract a TH1D called hist and draw with error bars and save it as Fig1.pdf, Fig1.eps and Fig1.png:

lhcbstyle plot plot.root hist Fig1 --formats pdf eps png

See the full usage notes using

lhcbstyle plot -h

Contributing

Creating a development environment

ssh://git@gitlab.cern.ch:7999/lhcb-docs/lhcbstyle.git
cd lhcbstyle
mamba create --name test-env root pytest pip setuptools_scm
pip install -e .[testing]
pre-commit install
curl -o lb-check-copyright "https://gitlab.cern.ch/lhcb-core/LbDevTools/raw/master/LbDevTools/SourceTools.py?inline=false"
chmod +x lb-check-copyright

Running the tests:

pre-commit run --all-files
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lhcbstyle-0.1.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

lhcbstyle-0.1.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file lhcbstyle-0.1.0.tar.gz.

File metadata

  • Download URL: lhcbstyle-0.1.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10

File hashes

Hashes for lhcbstyle-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8e385afb6eb8afea177e6801d334cc855e774983cba48d9c1135a3fda96ead2d
MD5 a5503b5cc084c359b33545a7df87b20a
BLAKE2b-256 7213be0e4384a013a599f6a6629d6b9c7c058a5a577d9ad9054f048fa4bc83cb

See more details on using hashes here.

File details

Details for the file lhcbstyle-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lhcbstyle-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10

File hashes

Hashes for lhcbstyle-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 868a637f42d965f725019b76a53d65e811e2378ff7731eed6b8b7f7dc661a81e
MD5 64be983980350b6e7887cec9547e34a6
BLAKE2b-256 89fd30c5189e7c7b5ec54f4fae7349871ed19c7a626f104b490f9a8e72b974e7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page