Skip to content

Instantly share code, notes, and snippets.

View pieterdavid's full-sized avatar

Pieter David pieterdavid

View GitHub Profile
@pieterdavid
pieterdavid / !install_correctionlib_CMSSW_py2.md
Last active January 4, 2024 02:00
Install correctionlib in python2 CMSSW releases

This script can be used to install correctionlib in a CMSSW release that does not have the py3-correctionlib tool installed, based on the instructions in this discussion.

The script should be sourced (. ./install_correctionlib.sh or source ./install_correctionlib), so it will run in the same shell from where it is called. The cleanest is to open a new shell after running it to install correctionlib, to prevent some variables from staying in the environment.

By default it will use the python version that CMSSW uses for configuration,

@pieterdavid
pieterdavid / CMakeLists.txt
Last active April 7, 2024 19:16
correctionlib RDataFrame examples
# Example commands to build the C++ example (df.cc):
# cmake $(correction config --cmake) .
# make
cmake_minimum_required(VERSION 3.11)
project(correctionlibexample LANGUAGES CXX)
find_package(correctionlib REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
@pieterdavid
pieterdavid / getTreeSizes.py
Last active October 2, 2018 15:41
CalibTree size script
#!/usr/bin/env python2
""" Print the sizes (in bytes, zipped) of TTrees in a TFile or in a set of TFiles with the same structure """
__author__ = "Pieter David <pieter.david@uclouvain.be>"
__date__ = "2 October 2018"
def iterTrees(tdir, prefix=""):
for ky in tdir.GetListOfKeys():
kyNm = ky.GetName()
clNm = ky.GetClassName()
if clNm == "TTree":
@pieterdavid
pieterdavid / ex_variablebinning.ipynb
Last active August 9, 2018 12:14
Non-uniform binnings in ROOT
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pieterdavid
pieterdavid / filetypeless.sh
Last active February 4, 2019 09:51
Git grep tricks for CMSSW
#!/bin/sh
# Shell script to start Vim with less.vim.
# Read stdin if no arguments were given and stdin was redirected.
## modified by Pieter David, June 2017: take a filename-like argument to deduct the filetype from, but always read from stdin
## suggested git alias: view = "!v() { git show $1 | ~/.vim/macros/filetypeless.sh $1; }; v"
if test -t 1; then
if test $# = 0; then
echo "Missing filename" 1>&2
@pieterdavid
pieterdavid / pixeltooltips.h
Created September 15, 2017 09:42
Hardcoded bitshift operations for pixel tooltips in fireworks
namespace PixelToolTips {
TString _pxbToolTip( unsigned int layer, unsigned int ladder, unsigned int module )
{
return TString::Format("Layer=%u, Ladder=%u, Module=%u", layer, ladder, module);
}
TString pxbToolTip_phase0( uint32_t detId )
{
unsigned int layer = ( detId >> 16 ) & 0xF ;
@pieterdavid
pieterdavid / ex_th1.ipynb
Last active October 17, 2019 10:36
mplbplot examples
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pieterdavid
pieterdavid / th2_rebin_numpy.py
Created July 18, 2017 08:06
Rebinning a TH2F in ROOT with numpy
"""
TH2F-to-numpy conversion methods, and rebinning of TH2F
"""
__author__ = "Pieter David <pieter.david@uclouvain.be>"
__date__ = "July 2017"
__all__ = ("th2_to_ndarray", "ndarray_to_th2")
import numpy as np
def th2_to_ndarray(hist):