Skip to content

Instantly share code, notes, and snippets.

View cshimmin's full-sized avatar

Chase cshimmin

  • Yale University
  • New Haven, CT
View GitHub Profile
@cshimmin
cshimmin / tetris.py
Created May 2, 2012 20:55 — forked from silvasur/tetris.py
Tetris implementation in Python
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# NOTE FOR WINDOWS USERS:
# You can download a "exefied" version of this game at:
# http://kch42.de/progs/tetris_py_exefied.zip
# If a DLL is missing or something like this, write an E-Mail (kevin@kch42.de)
# or leave a comment on this gist.
# Very simple tetris implementation
@cshimmin
cshimmin / gist:7902405
Created December 10, 2013 23:39
basic example for using python to generate and submit template jobs
import subprocess
list_of_files = ['some', 'list', 'of', 'files', ...]
template = '''#!/bin/bash
# you can access python variables using named format strings
INPUT_FILES="%(input_files)s"
./run_analysis_program.py $INPUT_FILES
'''
@cshimmin
cshimmin / ttree_indexing.py
Last active January 3, 2016 09:59
Suppose you have a ROOT file containing 500 entries, and a list (say from a numpy file) that represents an index of the interesting entries: [12,129,391,446,484] You can subclass TChain and overload __iter__ to skip around and yield only the entries corresponding to the index.
#!/usr/bin/env python
''' quick proof-of-concept for indexed TChains '''
import sys
import argparse
import ROOT as r
import numpy as np
class IndexedChain(r.TChain):
@cshimmin
cshimmin / vnc_lxplus5
Created January 15, 2014 22:52
Simple script to log in to lxplus5 and initiate a vnc session. The vnc port will be forwarded locally to 5901. On mac, simply run the script and leave the window open. Next, open Finder, press CMD+K, and enter "vnc://localhost:5901" NB: You'll have to change the variable "prompt_match" to something that will match your bash prompt line.
#!/usr/bin/env expect
# this expect script will connect to an lxplus node,
# start a vncserver session, and then locally
# forward the vnc host to port 5901.
# the ssh session is left open with a kill command ready to go
# for easy cleanup.
set timeout 30
# set this to (uniquely) match your terminal prompt. if your
@cshimmin
cshimmin / vnc_lxplus6.exp
Created February 6, 2014 02:00
Simple script to log in to a random lxplus6 node and initiate a vnc session. The vnc port will be forwarded locally to 5901. On mac, simply run the script and leave the window open. Next, open Finder, press CMD+K, and enter "vnc://localhost:5901" NB: You'll have to change the variable "prompt_match" to something that will match your bash prompt …
#!/usr/bin/env expect
# this expect script will connect to an lxplus node,
# start a vncserver session, and then locally
# forward the vnc host to port 5901.
# the ssh session is left open with a kill command ready to go
# for easy cleanup.
set timeout 30
set local_user [lindex [array get env USER] 1]
@cshimmin
cshimmin / crap_mc.py
Last active August 29, 2015 13:56
crappy pixel noise simulation
#!/usr/bin/env python
import numpy as np
'''
Try to simulate the nearAvg5 distribution with pixel
noise modelled as a gamma distribution.
'''
def simulate_navg(threshold=40., nsamples=100000, mean=25., shape=2., gridsize=5):
if not gridsize%2:
@cshimmin
cshimmin / rootcore.py
Last active October 14, 2015 15:54
Example of loading RootCore packages from python.
import sys, os
import ROOT as r
# prohibit root from hijacking command-line args
r.PyConfig.IgnoreCommandLineOptions = True
try:
ROOTCORE_PATH = os.environ['ROOTCOREDIR']
except KeyError:
print >>sys.stderr, "Warning! $ROOTCOREDIR env. variable is not set. Did you configure RootCore?"
ROOTCORE_PATH = None

Keybase proof

I hereby claim:

  • I am cshimmin on github.
  • I am cshimmin (https://keybase.io/cshimmin) on keybase.
  • I have a public key whose fingerprint is 3B63 7F65 7C37 F6FE E1F5 963A 8BB0 5DAE 1977 9A91

To claim this, I am signing this object:

@cshimmin
cshimmin / mctruth.py
Created June 19, 2014 06:12
example of MC truth filtering using analysis_utils
import sys
import ROOT as r
from analysis_utils.root.dpd_object import get_objects, build_tlv
if __name__ == "__main__":
t = r.TChain("physics")
map(t.Add, sys.argv[1:])
for evt in t:
# pull lightweight 'objects' from the mc_* branches
@cshimmin
cshimmin / mctruth.py
Created June 19, 2014 06:12
example of MC truth filtering using analysis_utils
import sys
import ROOT as r
from analysis_utils.root.dpd_object import get_objects, build_tlv
if __name__ == "__main__":
t = r.TChain("physics")
map(t.Add, sys.argv[1:])
for evt in t:
# pull lightweight 'objects' from the mc_* branches