Skip to content

Instantly share code, notes, and snippets.

View alexpearce's full-sized avatar

Alex Pearwin alexpearce

View GitHub Profile
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 / 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
@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 / histogram_sampling.ipynb
Created November 7, 2016 14:20
Notebook demonstrating sampling from a histogram PDF with probfit.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alexpearce
alexpearce / splot_with_roofit.py
Created December 21, 2016 13:42
Ue RooFit PDFs with hep_ml.splot
def pdf_probabilities(xs, dependents, yields, pdfs):
"""Return an array of normalised PDF probabilities.
For a list of N yields, each y_i, and a list of N PDFs f_i, the probability
for the ith PDF at the (possibly vector) point x is defined as
p_{i} = \frac{N_{i}f_{i}}{\sum_{i}^{N} N_{i}f_{i}}
Keyword arguments:
xs -- List of values at which to evaluate the PDFs
@alexpearce
alexpearce / nb.ipynb
Last active January 30, 2017 16:54
Lil' notebook.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alexpearce
alexpearce / bcolz.ipynb
Created March 22, 2017 07:36
bcolz experiments
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alexpearce
alexpearce / gosu-entrypoint.sh
Created July 14, 2017 10:12
A entrypoint for a Docker container that can run commands as the user running Docker
#!/bin/bash
# Run commands in the Docker container with a particular UID and GID.
# The idea is to run the container like
# docker run -i \
# -v `pwd`:/work \
# -e LOCAL_USER_ID=`id -u $USER` \
# -e LOCAL_GROUP_ID=`id -g $USER` \
# image-name bash
# where the -e flags pass the env vars to the container, which are read by this script.
# By setting copying this script to the container and setting it to the