LHCb style for ROOT plots
Project description
LHCbStyle
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:
- the ROOT file to open
- the name of the
TObject
to draw - the output filename, without extension (optional, defaults to "plot")
The optional arguments are:
--draw-style
,-D
: option string to pass to theDraw()
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lhcbstyle-0.0.0.tar.gz
.
File metadata
- Download URL: lhcbstyle-0.0.0.tar.gz
- Upload date:
- Size: 5.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | a781d910fa93fa0ee2972f7057a542ed3c6ffbd76385a36510d07f4bbe4c7d04 |
|
MD5 | 75248729afa1e384174ae6b7e6bb5fc2 |
|
BLAKE2b-256 | f7ea5534aa69e6d902f6322bcc3624bd357be9ffaaee6fa29575628907b2d67e |
File details
Details for the file lhcbstyle-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: lhcbstyle-0.0.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f978992100a7a24bba2d8f8571f56dd141fdb721a1d6df7492e55bd09a1f320 |
|
MD5 | 9b2841161a78c4481e8b49eab79d2871 |
|
BLAKE2b-256 | 64baaa0aa9ed4942eb7461f15bed53d10d00eec3f6eac22cb8bd6e8ad63b8c44 |