Skip to content

Instantly share code, notes, and snippets.

@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 / 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?
"""
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
pass
parser = argparse.ArgumentParser(description='test\ntest\ntest.',
epilog='test\ntest\ntest.',
formatter_class=CustomFormatter)
#include "TFile.h"
#include "TTree.h"
#include "TH1F.h"
#include "TH2F.h"
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
//#include "L1AnalysisEventDataFormat.h"
#!/usr/bin/env python
"""
Example ways to access tree elements, to test relative performance
"""
import ROOT
from array import array
# import cProfile
@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
@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 / 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 / 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 / slider.py
Created March 23, 2015 09:40
Show fn, fit it, show the fit. Not perfect. For exploring possible shapes of fns.
from collections import namedtuple
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
from scipy.optimize import curve_fit
from itertools import izip
# 0 to 0.347
xpt = [20.9499,20.7179,21.4734,22.0312,22.9523,24.6784,26.0982,28.7842,31.0813,33.0672,35.4857,38.3296,40.9982,43.7918,46.1765,49.2252,52.6305,55.078,58.345,61.1288,63.9831,67.1981,70.5813,73.5319,76.9119,79.7721,82.9528,86.3631,89.1184,93.0097,96.0561,99.2763,103.673,105.919,109.948,112.495,116.37,119.104,122.172,126.262,129.863,133.374,135.358,140.215,143.906,146.964,151.518,152.608,157.312,161.298,163.645,168.758,171.285,174.861,179.208,182.253,186.099,189.914,193.942]
ypt = [0.903289,1.31444,1.48306,1.57877,1.67689,1.75208,1.81371,1.78577,1.78443,1.77425,1.76701,1.74634,1.72242,1.68689,1.67924,1.66272,1.63702,1.62118,1.59681,1.5808,1.57993,1.55617,1.54106,1.53675,1.52014,1.50499,1.49345,1.48556,1.46981,1.46973,1.46255,1.45699,1.43602,1.42543,1.42378,1.42657,1.4099,1.40933,1.39935,1.387