-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetLumi.py
44 lines (36 loc) · 1.28 KB
/
getLumi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#
# getLumi.py - Copyright 2010 Mario Kadastik
#
# Version 1.0, date 12 April 2010
#
# This is a temporary tool to calculate the integrated luminosity of CMS based on a JSON file
#
# Usage: python getLumi.py in.json
#
# Where the in.json is either a JSON file you get from CRAB by e.g. crab -report or a JSON listing the good runs from some other source
#
# The code requires lumi_by_LS.csv present in the current working directory. You can get the file from:
# https://twiki.cern.ch/twiki/bin/view/CMS/LumiWiki2010Data
#
import json, csv, sys
my_lumi_json=file(sys.argv[1],'r')
my_lumi_dict = json.load(my_lumi_json)
lumi_list_csv = open('lumi_by_LS.csv','rb')
# Skip first 5 lines, which are comments
for i in range(5):
lumi_list_csv.next()
lumi_dict = csv.DictReader(lumi_list_csv,delimiter=',',fieldnames=['Run','LS','HFC','VTXC','HFL','VTXL'])
lumi = {}
for l in lumi_dict:
kw="%d_%d" % (int(l['Run']),int(l['LS']))
lumi[kw]=float(l['VTXL'])
tot=1e-30
for k, v in my_lumi_dict.items():
for lumis in v:
if type(lumis) == type([]) and len(lumis) == 2:
for i in range(lumis[0], lumis[1] + 1):
kw="%d_%d" % (int(k),int(i))
if kw in lumi:
tot+=lumi[kw]
ll = tot / 4.29e+28
print "Total luminosity: %1.2f /ub, %1.2f /nb, %1.2e /pb, %1.2e /fb" % (ll,ll/1000,ll/1e+6,ll/1e+9)