Skip to content

Instantly share code, notes, and snippets.

@raggleton
raggleton / plot_two_pandas.py
Created April 21, 2015 09:57
Make 2 side-by-side hists or scatter plots from two pandas dataframes
def plot_two_hists(var, df1, df2, title1, title2, xlabel, ylabel, **kwargs):
"""function to make 2 side-by-side hists to compare 2 dataframes"""
fig2, ax2 = plt.subplots(nrows=1, ncols=2)
fig2.set_size_inches(24, 8)
plt.subplots_adjust(wspace=0.2)
df1[var].plot(kind="hist", ax=ax2[0], title=title1, **kwargs)
ax2[0].set_xlabel(xlabel)
ax2[0].set_ylabel(ylabel)
@raggleton
raggleton / performance_test.py
Last active January 4, 2016 11:26
Different ways to access TTree elements, some slow, some fast. Note cProfile doesn't work great here.
#!/usr/bin/env python
"""
Example ways to access tree elements, to test relative performance
"""
import ROOT
from array import array
# import cProfile
@raggleton
raggleton / check_sample_status.py
Last active March 7, 2016 13:43
Script to check whether samples are at a T2 (fully). Uses das_client.py
#!/usr/bin/env python
"""
Script to check whether samples are at a T2 (fully).
Run by doing:
./check_sample_status.py
For each dataset in SAMPLES, will print out the sample in red with a 'x'
if not fully at any T2.
If it is fully present at atleast 1 T2, then it will print in green with a 'v'.
@raggleton
raggleton / shutup_root.md
Created February 12, 2016 10:41
How to shut up ROOT

To turn off messages like:

Info in <TCanvas::Print>: png file my_plot.png has been created

add in:

gErrorIgnoreLevel = kWarning
#!/usr/bin/env python
"""
Example ways to access tree elements, to test relative performance
"""
import ROOT
from array import array
# import cProfile
#include "TFile.h"
#include "TTree.h"
#include "TH1F.h"
#include "TH2F.h"
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
//#include "L1AnalysisEventDataFormat.h"
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
pass
parser = argparse.ArgumentParser(description='test\ntest\ntest.',
epilog='test\ntest\ntest.',
formatter_class=CustomFormatter)
@raggleton
raggleton / word_counter.py
Last active April 13, 2016 17:29
Change MAIN_TEX_FILE and START_DATE to suit yourself
#!/usr/bin/env python
"""
Go through TeX files and count words, plot things.
TODO:
- only count commits where tex file changed?
"""
@raggleton
raggleton / more_curd.py
Last active August 10, 2016 10:02
Usual stuff for jupyter notebooks
from copy import deepcopy
from contextlib import contextmanager
import pandas as pd
import numpy as np
import matplotlib as mpl
from matplotlib.pyplot import cm
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from matplotlib.colors import LogNorm, Normalize
@raggleton
raggleton / jupyter_plot_save_helpers.py
Last active July 3, 2016 14:06
Functions/decorators to help make saving plots in ipython notebooks easier.
import os
from copy import deepcopy
from contextlib import contextmanager
# Global bool to turn on/off plot saving for all plots in notebook
SAVE_PLOTS = True
def save_plot(filename):