Skip to content

Instantly share code, notes, and snippets.

View alexpearce's full-sized avatar

Alex Pearwin alexpearce

View GitHub Profile
@alexpearce
alexpearce / rootdocs.sh
Created March 11, 2013 14:37
RootDocs is a tiny bash script for launching documentation for ROOT classes.
#!/bin/bash
function bail {
echo You did not enter a valid ROOT class $1
exit 1
}
if [ -n "$1" ]; then
if [ `expr match $1 T` == 1 ]; then
status_code=`curl -o /dev/null -sIw "%{http_code}" http://root.cern.ch/root/html/$1.html`
@alexpearce
alexpearce / test.cpp
Created January 20, 2014 10:30
This is an example C++ class using C++11 features and ROOT.
#include "iostream"
#include "map"
#include "TString.h"
int main(int argc, char const *argv[])
{
std::map<int, TString>myMap {
{2, "Hello"},
{4, "There"},
{8, "Stranger"},
@alexpearce
alexpearce / offset_text.py
Last active November 5, 2020 07:03
Nice offset label formatting in matplotlib. See [the blog post](https://alexpearce.me/2014/04/exponent-label-in-matplotlib/) for more.
import numpy as np
from matplotlib import pyplot as plt
fig = plt.figure(figsize=(5, 4))
# Generate some data
mu, sigma = 1e7, 1e6
s = np.random.normal(mu, sigma, 10000)
# Plot it
plt.hist(s, 30, histtype='step')
# Format it
@alexpearce
alexpearce / sqlite3_example.py
Last active August 29, 2015 14:08
Creating and manipulating a run number database.
import sqlite3
import random
# Create the database
con = sqlite3.connect('/path/to/database.db')
con.execute('CREATE TABLE runs (run INTEGER PRIMARY KEY)')
# Insert many runs...
runs = range(int(1e3))
random.shuffle(runs)
@alexpearce
alexpearce / sqlite3_timing.py
Created October 27, 2014 10:44
Timing operations on an SQLite database.
import timeit
import os
DB_PATH = 'database.db'
# Number of runs to generate
NRUNS = int(1e6)
insert_setup = """import sqlite3
con = sqlite3.connect('{0}')
con.execute('CREATE TABLE runs (run INTEGER PRIMARY KEY)')
@alexpearce
alexpearce / ssotutorial.apacheconf
Last active October 21, 2021 02:31
Apache configuration file for a virtual host running Flask behind a uWSGI server, authentication with Shibboleth SSO
# Apache server configuration for ssotutorial.
# This sets up a Flask application over SSL with CERN SSO authentication via
# Shibboleth.
# Load the SSL and Shibboleth modules
LoadModule ssl_module modules/mod_ssl.so
LoadModule mod_shib /usr/lib64/shibboleth/mod_shib_22.so
# Disable TRACE HTTP requests on CERN advice
TraceEnable Off
@alexpearce
alexpearce / __init__.py
Created October 30, 2014 16:05
A Flask application configured to accept Shibboleth SSO headers to authenticate users.
from datetime import datetime
from flask import Flask, session, redirect
from flask_sso import SSO
def get_user_session_info(key):
return session['user'].get(
key,
'Key `{0}` not found in user session info'.format(key)
@alexpearce
alexpearce / root.rb
Created November 20, 2014 14:02
Homebrew ROOT formula for installing ROOT 6.02.00
require 'formula'
class Root < Formula
homepage 'http://root.cern.ch'
url 'ftp://root.cern.ch/root/root_v6.02.00.source.tar.gz'
mirror 'http://ftp.riken.jp/pub/ROOT/root_v6.02.00.source.tar.gz'
version '6.02.00'
sha1 '98449e9a4d91cc487c5ae59c1128d20286f134cc'
head 'https://github.com/root-mirror/root.git', :branch => 'v6-02-00-patches'
# url "ftp://root.cern.ch/root/root_v5.34.22.source.tar.gz"
@alexpearce
alexpearce / .ganga.py
Created November 21, 2014 10:36
Method loaded by Ganga for automatically downloading job output
from os import makedirs
def download_lfns(job, path="/afs/cern.ch/work/a/apearce/Ganga"):
"""Downloads all Dirac files for all subjobs of a given job.
Keyword arguments:
job -- Ganga Job object. Only completed jobs/subjobs will be downloaded
path -- Prefix path to download to, will be suffixed by job_id/subjob_id
"""
print "Downloading LFNs to {0}/{1}".format(path, job.id)
@alexpearce
alexpearce / test_smeared_chisq.py
Created December 16, 2014 12:18
Test smeared log IP chi^2 shape
import ROOT
from ROOT import RooFit as RF
ROOT.gROOT.ProcessLine('#include "charmproduction/fitting/shape_classes/RooSmearedLogChiSquared.cxx"')
w = ROOT.RooWorkspace('w')
w.factory('x[-5, 5]')
w.factory('mu_ip[2, -10, 10]')
w.factory('alphaL_ip[1, 0.1, 10]')
w.factory('alphaR_ip[1, 0.1, 10]')
w.factory('RooSmearedLogChiSquared::pdf_ip(x, mu_ip, alphaL_ip, alphaR_ip)')