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' )
57 parser.add_option(
'--runperiod',dest=
'runperiod',action=
'store', default=
'Run1',help=
'select runperiod Run1 or Run2, default Run1' )
60 (options, args) = parser.parse_args()
61 except Exception
as e:
74 print 'General configuration'
75 print '\toutputfile: ',options.outputfile
76 print '\tinput selection file: ',options.inputfile
97 for (run, lslist)
in sorted (inputRange.iteritems() ):
100 if run
in inputPileupRange.keys():
101 OUTPUTLINE+= (
'"%d":' % run )
104 LSPUlist = inputPileupRange[run]
106 for LSnumber
in lslist:
107 if LSnumber
in LSPUlist.keys():
108 PUlumiInfo = LSPUlist[LSnumber]
109 HLTlumiInfo = lslist[LSnumber]
113 if PUlumiInfo[0] > 0.:
114 scale=HLTlumiInfo[1]/PUlumiInfo[0]
118 print 'Run %d, LS %d, HLT Scale (%f), HLTL (%f), PUL (%f) larger than one - please check!' % (run, LSnumber, scale, HLTlumiInfo[1],PUlumiInfo[0])
121 newIntLumi = scale*PUlumiInfo[0]
122 newRmsLumi = PUlumiInfo[1]
123 newInstLumi = PUlumiInfo[2]
125 newInstLumi = PUlumiInfo[2]
128 LumiString =
"[%d,%2.4e,%2.4e,%2.4e]," % (LSnumber, newIntLumi, newRmsLumi ,newInstLumi)
129 OUTPUTLINE += LumiString
138 LumiString =
"[%d,0.0,0.0,%2.4e]," % (LSnumber, newInstLumi)
139 OUTPUTLINE += LumiString
142 lastindex=len(OUTPUTLINE)-1
143 trunc = OUTPUTLINE[0:lastindex]
148 print "Run %d not found in Lumi/Pileup input file. Check your files!" % (run)
164 lastindex=len(OUTPUTLINE)-2
165 trunc = OUTPUTLINE[0:lastindex]
169 outputfile = open(options.outputfile,
'w')
171 raise RuntimeError(
"Could not open '%s' as an output JSON file" % output)
173 outputfile.write(OUTPUTLINE)