5 from RecoLuminosity.LumiDB
import pileupParser
6 from RecoLuminosity.LumiDB
import selectionParser
7 from RecoLuminosity.LumiDB
import csvLumibyLSParser
13 output ({run:[ls:[inlumi, meanint]]})
15 selectf=open(inputfilename,
'r')
16 inputfilecontent=selectf.read()
20 runlsbyfile=p.runsandls()
33 if __name__ ==
'__main__':
35 parser = optparse.OptionParser (
"Usage: %prog [--options]",
36 description =
"Script to rescale pileup distributions using inputs derived by calculating luminosity for a given set of HLT paths. Input format must be -lumibyls-")
39 CalculationModeChoices = [
'truth',
'observed']
49 parser.add_option(
'-o',dest=
'outputfile',action=
'store',
50 default=
'PileupRecalcJSON.txt',
51 help=
'output pileup JSON file')
52 parser.add_option(
'-i',dest=
'inputfile',action=
'store',
53 help=
'Input Run/LS/lumis file for your trigger selection (required)')
54 parser.add_option(
'--inputLumiJSON',dest=
'inputLumiJSON',action=
'store',
55 help=
'Input Lumi/Pileup file in JSON format (required)')
56 parser.add_option(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode for printing' )
60 (options, args) = parser.parse_args()
74 print 'General configuration'
75 print '\toutputfile: ',options.outputfile
76 print '\tinput selection file: ',options.inputfile
96 for (run, lslist)
in sorted (inputRange.iteritems() ):
99 if run
in inputPileupRange.keys():
100 OUTPUTLINE+= (
'"%d":' % run )
103 LSPUlist = inputPileupRange[run]
105 for LSnumber
in lslist:
106 if LSnumber
in LSPUlist.keys():
107 PUlumiInfo = LSPUlist[LSnumber]
108 HLTlumiInfo = lslist[LSnumber]
112 if PUlumiInfo[0] > 0.:
113 scale=HLTlumiInfo[1]/PUlumiInfo[0]
116 print 'Run %d, LS %d, HLT Scale (%f), HLTL (%f), PUL (%f) larger than one - please check!' % (run, LSnumber, scale, HLTlumiInfo[1],PUlumiInfo[0])
119 newIntLumi = scale*PUlumiInfo[0]
120 newRmsLumi = PUlumiInfo[1]
121 newInstLumi = PUlumiInfo[2]
123 newInstLumi = PUlumiInfo[2]
126 LumiString =
"[%d,%2.4e,%2.4e,%2.4e]," % (LSnumber, newIntLumi, newRmsLumi ,newInstLumi)
127 OUTPUTLINE += LumiString
136 LumiString =
"[%d,0.0,0.0,%2.4e]," % (LSnumber, newInstLumi)
137 OUTPUTLINE += LumiString
140 lastindex=len(OUTPUTLINE)-1
141 trunc = OUTPUTLINE[0:lastindex]
146 print "Run %d not found in Lumi/Pileup input file. Check your files!" % (run)
162 lastindex=len(OUTPUTLINE)-2
163 trunc = OUTPUTLINE[0:lastindex]
167 outputfile = open(options.outputfile,
'w')
169 raise RuntimeError, \
170 "Could not open '%s' as an output JSON file" % output
172 outputfile.write(OUTPUTLINE)