2 from __future__
import print_function
6 from RecoLuminosity.LumiDB
import pileupParser
7 from RecoLuminosity.LumiDB
import selectionParser
8 from RecoLuminosity.LumiDB
import csvLumibyLSParser
15 output ({run:[ls:[inlumi, meanint]]})
17 selectf=open(inputfilename,
'r')
18 inputfilecontent=selectf.read()
22 runlsbyfile=p.runsandls()
35 if __name__ ==
'__main__':
37 parser = optparse.OptionParser (
"Usage: %prog [--options]",
38 description =
"Script to rescale pileup distributions using inputs derived by calculating luminosity for a given set of external corrections (Pixel luminosity, for example). Input format must be -lumibyls-")
41 CalculationModeChoices = [
'truth',
'observed']
51 parser.add_option(
'-o',dest=
'outputfile',action=
'store',
52 default=
'PileupRecalcJSON.txt',
53 help=
'output pileup JSON file')
54 parser.add_option(
'-i',dest=
'inputfile',action=
'store',
55 help=
'Input Run/LS/lumis file for your trigger selection (required)')
56 parser.add_option(
'--inputLumiJSON',dest=
'inputLumiJSON',action=
'store',
57 help=
'Input Lumi/Pileup file in JSON format (required)')
58 parser.add_option(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode for printing' )
62 (options, args) = parser.parse_args()
63 except Exception
as e:
76 print(
'General configuration')
77 print(
'\toutputfile: ',options.outputfile)
78 print(
'\tinput selection file: ',options.inputfile)
100 for (run, LSPUlist)
in sorted (six.iteritems(inputPileupRange)):
103 if run
in inputRange.keys():
104 OUTPUTLINE+= (
'"%d":' % run )
107 lslist = inputRange[run]
109 for LSnumber
in LSPUlist:
110 if LSnumber
in lslist.keys():
111 PUlumiInfo = LSPUlist[LSnumber]
112 PixlumiInfo = lslist[LSnumber]
116 if PUlumiInfo[0] > 0.:
117 scale=PixlumiInfo[1]/PUlumiInfo[0]
119 if scale !=0
and (scale < 0.2
or scale > 5.0):
120 print(
'Run %d, LS %d, Scale (%f), PixL (%f), PUL (%f) big change - please check!' % (run, LSnumber, scale, PixlumiInfo[1],PUlumiInfo[0]))
123 newIntLumi = scale*PUlumiInfo[0]
124 newRmsLumi = scale*PUlumiInfo[1]
125 newInstLumi = scale*PUlumiInfo[2]
127 newIntLumi = PUlumiInfo[0]
128 newRmsLumi = PUlumiInfo[1]
129 newInstLumi = PUlumiInfo[2]
131 print(
'Run %d, LS %d, Scale (%f), PixL (%f), PUL (%f) - 0 please check!' % (run, LSnumber, scale, PixlumiInfo[1],PUlumiInfo[0]))
132 LumiString =
"[%d,%2.4e,%2.4e,%2.4e]," % (LSnumber, newIntLumi, newRmsLumi ,newInstLumi)
133 OUTPUTLINE += LumiString
139 newIntLumi = PUlumiInfo[0]
140 newRmsLumi = PUlumiInfo[1]
141 newInstLumi = PUlumiInfo[2]
144 LumiString =
"[%d,%2.4e,%2.4e,%2.4e]," % (LSnumber, newIntLumi, newRmsLumi ,newInstLumi)
145 OUTPUTLINE += LumiString
148 lastindex=len(OUTPUTLINE)-1
149 trunc = OUTPUTLINE[0:lastindex]
154 print(
"Run %d not found in Lumi/Pileup input file. Check your files!" % (run))
170 lastindex=len(OUTPUTLINE)-2
171 trunc = OUTPUTLINE[0:lastindex]
175 outputfile = open(options.outputfile,
'w')
177 raise RuntimeError(
"Could not open '%s' as an output JSON file" % output)
179 outputfile.write(OUTPUTLINE)