Skip to content

Instantly share code, notes, and snippets.

View alexpearce's full-sized avatar

Alex Pearwin alexpearce

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alexpearce
alexpearce / histogram_sampling.ipynb
Created November 7, 2016 14:20
Notebook demonstrating sampling from a histogram PDF with probfit.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alexpearce
alexpearce / RooAsymGaussExp.cxx
Created July 7, 2016 19:21
The RooAsymGaussExp class, defining a Gaussian PDF with an asymmetric width and exponential tails
// Asymmetrical Gaussian with exponential tails
// parameters:
// mean - position at maximum
// sigma - sigma of the Gaussian
// asym - asymmetry of the Gaussian ( sigmaLeft = sigma * (1 - asym), sigmaRight = sigma * (1 + asym) )
// rhoL - number of sigmas from mean where left tail starts: mean - rhoL * sigmaLeft
// rhoR - number of sigmas from mean where right tail starts: mean + rhoR * sigmaRight
//
// Allowed values of parameters: sigma > 0, -1 < asym < 1, rhoL > 0, rhoR > 0
@alexpearce
alexpearce / setup_acron_vm.sh
Last active June 22, 2016 07:36
Set up a CERN OpenStack virtual machine to run acron jobs. See https://alexpearce.me/2016/06/creating-a-vm-for-acron-jobs/ for more.
#!/bin/sh
echo 'Provisioning acron VM'
# Install what we'll need
sudo yum install -y cern-config-users cern-get-keytab arc-server
# Make sure we ready for Kerberos-authenticated jobs
sudo cern-get-keytab --force
import numpy as np
import matplotlib.pyplot as plt
def normfactor(hist, edges):
a = np.sum(hist)*(edges[1:] - edges[:-1])
return a
def gauss(xs, loc=0.0, scale=1.0):
@alexpearce
alexpearce / binned_chi2.ipynb
Created May 4, 2016 06:53
Notebook to reproduce Alex Rogozhnikov's binned chi^2 demonstration plot
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alexpearce
alexpearce / open_eos.py
Created December 7, 2015 13:24
Interface to EOS files mimicking native `open`.
from distutils.spawn import find_executable
import logging as log
import os
import shutil
from subprocess import call
import tempfile
class open_eos(object):
"""An EOS file wrapper that acts like the native `open`.
@alexpearce
alexpearce / tbrowser.py
Last active November 23, 2015 09:00
Open ROOT files in an Python/IPython shell. Pops open a TBrowser automatically
#!/usr/bin/env python
"""Inspect ROOT files."""
from __future__ import print_function
import argparse
import sys
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('files', metavar='file', nargs='+',
help='ROOT file to inspect (ending in .root)')
@alexpearce
alexpearce / triple_gaussian.py
Created September 2, 2015 14:21
Define a triple Gaussian PDF in RooFit
# Name of the delta mass variable in the workspace
dmass_var = 'Dst_delta_M'
# Species of the PDF we're about to build
species = 'sig'
workspace.factory('mu_dm_{0}[141, 146]'.format(species))
workspace.factory('sigma_one_dm_{0}[1, 0, 5]'.format(species))
workspace.factory('nsigma_two_dm_{0}[1.5, 1, 3]'.format(species))
workspace.factory('nsigma_three_dm_{0}[1.5, 1, 3]'.format(species))
workspace.factory((
'expr::sigma_two_dm_{0}('
@alexpearce
alexpearce / boosting.py
Created May 9, 2015 10:11
Compare 2010 proton-proton collision CoM values with new method
# -*- coding: utf-8 -*-
from __future__ import print_function
from math import sqrt, sin
from array import array
import ROOT
# Proton mass in MeV
PROTON_MASS = 938.27