-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmyLumiCalc.py
executable file
·118 lines (85 loc) · 3.39 KB
/
myLumiCalc.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python
#usage: ./myLumiCalc.py JSONname=/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions12/8TeV/Prompt/Cert_190456-191859_8TeV_PromptReco_Collisions12_JSON.txt HLTpath="HLT_PFJet320_*" outfilename=Out.root
import os,sys,time
import coral
from ROOT import gROOT, TFile, TTree, AddressOf, TString, std
from ctypes import *
gROOT.Reset()
gROOT.ProcessLine(\
"struct MyStruct{\
UInt_t runnr;\
UInt_t luminosityBlock;\
Double_t intgRecLumi;\
Double_t HLTpresc;\
Double_t L1presc;\
};")
from ROOT import MyStruct
from FWCore.ParameterSet.VarParsing import VarParsing
options = VarParsing ('python')
options.register ('JSONname',
'',
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
'name of JSON file')
options.register ('HLTpath',
'HLT_*',
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
'name of HLT trigger path')
options.register ('outfilename',
'OutFile.root',
VarParsing.multiplicity.singleton,
VarParsing.varType.string,
'name of output root file')
options.parseArguments()
#os.system("lumiCalc2.py -i "+options.JSONname+" lumibyls -b stable --hltpath "+options.HLTpath+" -o TempOut.csv")
os.system("pixelLumiCalc.py -i "+options.JSONname+" lumibyls --hltpath "+options.HLTpath+" -o TempOut.csv")
ofile = TFile(options.outfilename,"RECREATE")
tr = TTree("AnalysisTree","AnalysisTree")
s = MyStruct()
hltpath = TString("")
tr.Branch('run',AddressOf(s,'runnr'),'runnr/i')
tr.Branch('luminosityBlock',AddressOf(s,'luminosityBlock'),'luminosityBlock/i')
tr.Branch("HLTpath","TString",hltpath)
#tr.Branch('L1bit','TString',l1bit)
tr.Branch('intgRecLumi',AddressOf(s,'intgRecLumi'),'intgRecLumi/D')
tr.Branch('HLTpresc',AddressOf(s,'HLTpresc'),'HLTpresc/D')
tr.Branch('L1presc',AddressOf(s,'L1presc'),'L1presc/D')
#'''
#input: {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),recordedlumi(6),calibratedlumierror(7),{hltpath:[l1name,l1prescale,hltprescale,efflumi]},bxdata,beamdata]}
#'''
#result=[]#[run,ls,hltpath,l1bitname,hltpresc,l1presc,efflumi]
infile = open("TempOut.csv", "r")
infile.readline()
for line in infile:
#print line
run = line[0:line.find(":")]
s.runnr = int(run)
line = line[len(run)+1:]
fill = line[0:line.find(",")]
line = line[len(fill)+1:]
lb = line[0:line.find(":")]
s.luminosityBlock = int(lb)
line = line[2*len(lb)+2:]
hltpathname = line[0:line.find(",")]
hltpath = TString(hltpathname)
hltpath = TString(hltpathname)
line = line[len(hltpathname)+1:]
if "HLT" not in hltpathname:
print "strange trigger name ("+hltpathname+") found for run "+run+" and lumiblock "+lb
continue
L1pathname = line[0:line.find(",")]
line = line[len(L1pathname)+1:]
hltprescale = line[0:line.find(",")]
s.HLTpresc = int(hltprescale)
line = line[len(hltprescale)+1:]
L1prescale = line[0:line.find(",")]
s.L1presc = int(L1prescale)
line = line[len(L1prescale)+1:]
intLumi = line[0:line.find(",")]
s.intgRecLumi = float(intLumi)
#print run +" "+lb+" "+hltpathname
tr.Fill()
ofile.Write()
ofile.Close()
os.system("rm TempOut.csv")