Skip to content

Instantly share code, notes, and snippets.

View mastbaum's full-sized avatar

Andy Mastbaum mastbaum

  • Rutgers University
  • New Brunswick, NJ
View GitHub Profile
@mastbaum
mastbaum / Makefile
Created July 3, 2013 14:50
Example of fitting in ROOT
ifndef ROOTSYS
$(error ROOTSYS is not defined)
endif
all: minuit_example
minuit_example:
g++ -o minuit_example minuit_example.cpp `root-config --libs --cflags` -lMinuit
clean:
@mastbaum
mastbaum / evcount.cxx
Created January 8, 2014 21:16
Looping over a TTree
// Find the number of events simulated and the efficiency for a set of ntuples
// Usage: root -b -q "evcount.cxx([filename], rate=0)" # "filename" can have wildcards
// If provided, rate is events/detector-year
void evcount(TString filenames, float rate=0) {
TChain tc("output");
tc.Add(filenames);
int entries = tc.GetEntries();
cout << "Total entries: " << entries << endl;
// ROOT branch pointers
@mastbaum
mastbaum / gist:6300550
Last active December 21, 2015 11:39
Specification for ln Backends
Backend.get_data_source_list()
Returns: list of data source names
Backend.create_data_source(name, type, reduction, interpolation, unit, description)
Returns: None
Backend.add_data(source_name, time, value)
Returns: (index, url) tuple, where index is index of data point and url is an image URL or None
Raises:
- TimeOrderError: The timestamp for the data point is before the last recorded data point
@mastbaum
mastbaum / nested_class.cpp
Created July 31, 2013 19:03
A nested C++ class "using private members of its parent"
#include <iostream>
class Foo {
public:
class Bar {
public:
Bar(Foo* owner) : owner(owner) {}
int getter() { return owner->a; }
private:
Foo* const owner;
@mastbaum
mastbaum / nhit_cut.py
Created June 12, 2013 21:36
An example PyROOT analysis which applies several different NHIT cuts, calculates the fraction of events failing, and produces a plot.
'''An example PyROOT analysis which applies several different NHIT cuts,
calculates the fraction of events failing, and produces a plot.
'''
import sys
import array
from rat import ROOT
def fast_dsreader(filename):
@mastbaum
mastbaum / tntuple_correlation.h
Last active December 18, 2015 03:19
Compute a correlation matrix for pairs of variables in a ROOT TNtuple.
/** Get a value from a TNtuple by event id and name */
float get_ntuple_entry(TNtuple* nt, int i, std::string field) {
float v;
nt->SetBranchAddress(field.c_str(), &v);
nt->GetEvent(i);
nt->ResetBranchAddresses();
return v;
}
@mastbaum
mastbaum / hough.cpp
Created December 4, 2015 21:44
Hough transform for QEvents
#include <cmath>
#include <TH2F.h>
#include <TVector3.h>
#include <QEvent.h>
#include <QGlobals.h>
#include <QPMTxyz.h>
TH2F* hough(const QEvent* event, TVector3& vfit, float tres_cut, bool qweight) {
// Calculate Cherenkov angle using FTK energy
float beta = sqrt(1.0 - (0.511 / (0.511 + e)) * (0.511 / (0.511 + e)));
@mastbaum
mastbaum / Dockerfile
Last active November 1, 2015 18:28
Dockerfile for Ubuntu 14.04 SLURM
FROM ubuntu:14.04
RUN apt-get update && apt-get -y install munge slurm-llnl
RUN mkdir -p /var/run/munge && \
chown munge:munge /var/run/munge && \
chmod 0700 /etc/munge && \
chmod 0711 /var/lib/munge && \
chmod 0700 /var/log/munge && \
chmod 0755 /var/run/munge && \
@mastbaum
mastbaum / mkdoc.sh
Created October 15, 2015 22:50
Markdown lab notebook generator
#!/bin/bash
# Collect the Markdown. Webpage it.
#
# Searches subdirectories for Markdown files and creates a static webpage
# with frames for navigation in a new directory _notebook/. Also copies
# over any images referenced in the md source.
#
# A. Mastbaum <mastbaum@hep.upenn.edu>, 10/2015
#
@mastbaum
mastbaum / matplotlib_legend.py
Created November 28, 2012 16:21
labeling only some plots in matplotlib
'''Example of labeling only some plots in a matplotlib legend.
Tested with matplotlib==1.0.1
'''
from matplotlib import pyplot as plt
plt.figure(1, facecolor='white')
plt.plot([1,2,3,4], [1,2,3,4], label='foo')
plt.plot([1,2,3,4], [2,4,6,8])