Skip to content

Instantly share code, notes, and snippets.

@jdbrice
jdbrice / pythia.C
Created February 1, 2017 03:39
Code to skim Pythia events with muons and use some Toy MC to test pair background mehtods
#define pythia_cxx
#include "pythia.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
void pythia::Loop()
{
// In a ROOT session, you can do:
// root> .L pythia.C
@jdbrice
jdbrice / calc_cholesky.cpp
Created September 22, 2016 14:17
Calculates the Cholesky decomposition
void calcCholesky( int nP, double * fCov, double* fCovSqrt ){
double *C = fCovSqrt;
double *V = fCov;
// calculate sqrt(V) as lower diagonal matrix
for( int i = 0; i < nP; ++i ) {
for( int j = 0; j < nP; ++j ) {
C[i*nP+j] = 0;
}
@jdbrice
jdbrice / cldoc_clang_sanitize.py
Created September 20, 2016 18:05
Python script for sanitizing Clang / ClDoc documentation XML output. Great for improving the readability of ClDoc documentation webpages
#!/usr/bin/python
# for command line args
import sys
# for regex
import re
#for JSON parsing
import json
# for dir searching
import glob
@jdbrice
jdbrice / MathJax_bootstrap.js
Created September 20, 2016 03:27
scripts to bootstrap most pages wth inline math
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
processEnvironments: true
},
// Center justify equations in code and markdown cells. Elsewhere
@jdbrice
jdbrice / jupyter_markdown_output.js
Created September 19, 2016 17:30
Mystical Magical way that Jupyter handles MathJax in markdown
// SEE : notebook/notebook/static/notebook/js/outputarea.js
// around line 632
var append_markdown = function(markdown, md, element) {
var type = MIME_MARKDOWN;
var toinsert = this.create_output_subarea(md, "output_markdown rendered_html", type);
var text_and_math = mathjaxutils.remove_math(markdown);
var text = text_and_math[0];
var math = text_and_math[1];
marked(text, function (err, html) {
html = mathjaxutils.replace_math(html, math);
@jdbrice
jdbrice / dbash.sh
Created September 10, 2016 18:16
Jump into a docker exec bash shell
#!/bin/bash
docker exec -ti $1 /bin/bash
@jdbrice
jdbrice / multiprocessing_example.py
Created September 6, 2016 15:40
Python example of multiprocessing lib. This is for Glauber but decently simple example for anything
import subprocess as sp
import os
from multiprocessing import Pool, Queue
def nbd( npp, k ) :
cmd_template = """root4star -b -q 'macros/doNbdFitMaker.C("all_mb_fit_center_{npp}_{k}.root", 1000000, "all_mb.root", "hNCollNPart/hNCollNPart_nominal.root", "B_hRefMult_center", 50, {npp}, {k}, 0.12, 0.05, 1.0, 0 )'"""
print cmd_template.format( npp=npp, k=k )
os.system( cmd_template.format( npp=npp, k=k ) )
#include <map>
#include <unordered_map>
#include <vector>
map<int, bool> runNumbers;
vector<int> runNumbersInFile( string fn ) {
TFile * f = new TFile( fn.c_str(), "READ" );
#include "TFile.h"
#include "TH1F.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"
#include <unordered_map>
#include <fstream>
@jdbrice
jdbrice / custom.js
Created February 9, 2016 19:50
Sublime Keymap for Jupyter Notebooks
require(["codemirror/keymap/sublime", "notebook/js/cell", "base/js/namespace"],
function(sublime_keymap, cell, IPython) {
require("notebook/js/cell").Cell
setTimeout(function(){ // uncomment line to fake race-condition
require("notebook/js/cell").Cell.options_default.cm_config.keyMap = 'sublime';
var cells = IPython.notebook.get_cells();
for(var c=0; c<cells.length ; c++){
console.log( "Setting Sublime" )
cells[c].code_mirror.setOption('keyMap', 'sublime');
}