Skip to content

Instantly share code, notes, and snippets.

View mgmarino's full-sized avatar

Michael Marino mgmarino

View GitHub Profile
@mgmarino
mgmarino / TF1s with PyROOT
Created April 6, 2011 16:01
How to make a TF1 that calls to python code
import ROOT
class PoissonClass:
def __init__(self, upper_range, tag = ''):
self.function = ROOT.TF1('py_poisson' + tag, self, 0, upper_range, 2)
self.function.SetParName(0, 'Overall Normalization')
self.function.SetParName(1, 'Lambda')
def __call__(self, x, par):
res = 0.0
import ROOT
ROOT.gSystem.Load("libEXOROOT")
class model:
def __init__(self,RC_tau_1,RC_tau_2,CR_tau_1,CR_tau_2,CR_tau_3,baseline,lower_range,upper_range,size):
self.function = ROOT.TF1('function',self,lower_range,upper_range,size)
self.function.SetParName(0, 'number of signals')
self.cm = ROOT.EXOChannelManager()
self.cm.initialize(RC_tau_1,RC_tau_2,CR_tau_1,CR_tau_2,CR_tau_3)
@mgmarino
mgmarino / Make a bunch of points in EXOAnalysis
Created April 7, 2011 09:42
Make random charge depositions. Distribute across cores
from subprocess import Popen, PIPE, STDOUT
import random
import math
import ROOT
# Following in mm
lx_radius = 185.7248
z_height = 180.00
voxel_size = 0.5
@mgmarino
mgmarino / gist:944074
Created April 27, 2011 11:20
Pulser file
import ROOT
class MGMPulserFile:
_mydict = None
@classmethod
def get_event(cls, timestamp ):
if not cls._mydict: cls.setup_file()
return cls._mydict[ timestamp ]
@classmethod
@mgmarino
mgmarino / gist:946442
Created April 28, 2011 14:25
Get livetime, cut (tier2) time for a CoGeNT *day* range...
import datetime as dat
import csv
class CoGeNTCutLiveTime():
_livetime_dict = None
@classmethod
def get_livetime_dict(cls):
if cls._livetime_dict != None: return cls._livetime_dict
readit = csv.reader(open('livetime.txt'), delimiter='\t')
temp = [row for row in readit][1:]
@mgmarino
mgmarino / gist:968225
Created May 12, 2011 09:15
Sort Juan events
import csv
cleaned_file = 'before_fire_LG_cleaned.txt'
all_events_file = 'LE4.txt'
output_file = 'LE5MGM.txt'
cleaned = csv.reader(open(cleaned_file), delimiter='\t')
clean_events = dict( [ (row[0], {'ts' : row[0],
'energy' : row[1],
'line' : ' '.join(row[:2]) } )
for row in cleaned] )
@mgmarino
mgmarino / gist:982903
Created May 20, 2011 13:40
Makefile example
# Makefile
#
ROOTCFLAGS = $(shell root-config --cflags)
ROOTLIBS = $(shell root-config --libs) -lNew
ROOTGLIBS = $(shell root-config --glibs)
MYOS := $(subst -,,$(shell uname))
@mgmarino
mgmarino / gist:995831
Created May 27, 2011 18:21
calibclass header
#include <TSystem.h>
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <string>
#include <TRef.h>
#include <TRefArray.h>
#include <TTree.h>
#include "EXOUtilities/EXOEventData.hh"
@mgmarino
mgmarino / gist:997845
Created May 29, 2011 15:12
Reading large number of data from file.
import ROOT
import numpy
ROOT.gROOT.SetBatch()
ROOT.gSystem.Load("libEXOUtilities")
ROOT.gROOT.ProcessLine(".L $EXOLIB/htmldoc/exo_tree_alias.C")
chain = ROOT.TChain("tree")
chain.Add("/nfs/slac/g/exo/exo_data/data/MC/ATeamBackgrounds/MC_Background_0000*.root")
ROOT.SetEXOAlias(chain)
@mgmarino
mgmarino / gist:1048407
Created June 27, 2011 06:40
Rescaling frame from RooFit
def rescale_frame(canvas, frame, scale, title):
"""
HACK
Takes a frame and rescales it to arbitrary coordinates.
This is helpful when dealing with RooPlot to get the axes
correct. Returns axis in case anything else needs to be done.
"""
import ROOT
yaxis = frame.GetYaxis()
yaxis.SetTickLength(0)