Skip to content

Instantly share code, notes, and snippets.

@mgmarino
Created April 28, 2011 14:25
Show Gist options
  • Save mgmarino/946442 to your computer and use it in GitHub Desktop.
Save mgmarino/946442 to your computer and use it in GitHub Desktop.
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:]
cls._livetime_dict = dict([(int(row[0]), int(row[5])) for row in temp])
return cls._livetime_dict
@classmethod
def get_cut_time_and_livetime(cls, start_day, end_day):
"""
Gives the VI start and end time and associated livetime for this period of
time. Input is in days since day 1 of running,
"""
""" This is how miller does days:
event_time = tree.time/1.e3 - ((datetime.date(1970, 1, 1) - datetime.date(1904, 1, 1)).days*3600*24)
#and now orient this w.r.t December 3, 2009"
cogentdt = datetime.datetime(2009,12,3,0,0,0)
eventdt = datetime.datetime.fromtimestamp(event_time)
diffdt = eventdt - cogentdt
cogentday = diffdt.days #range:[0,...]
"""
cogentdt = dat.datetime(2009,12,4,0,0,0)
secs = (cogentdt - dat.datetime(1904, 1, 1,0,0,0)).days*3600*24
begin_time = start_day*3600*24 + secs
end_time = end_day*3600*24 + secs
live_dict = cls.get_livetime_dict()
return (begin_time*1000, end_time*1000, reduce(lambda a,b: a + b, [live_dict[day] for day in range(start_day, end_day)]))
print CoGeNTCutLiveTime.get_cut_time_and_livetime(1, 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment