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 external corrections (Pixel luminosity, for example). 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()
61 except Exception
as e:
74 print 'General configuration'
75 print '\toutputfile: ',options.outputfile
76 print '\tinput selection file: ',options.inputfile
98 for (run, LSPUlist)
in sorted (inputPileupRange.iteritems() ):
101 if run
in inputRange.keys():
102 OUTPUTLINE+= (
'"%d":' % run )
105 lslist = inputRange[run]
107 for LSnumber
in LSPUlist:
108 if LSnumber
in lslist.keys():
109 PUlumiInfo = LSPUlist[LSnumber]
110 PixlumiInfo = lslist[LSnumber]
114 if PUlumiInfo[0] > 0.:
115 scale=PixlumiInfo[1]/PUlumiInfo[0]
117 if scale !=0
and (scale < 0.2
or scale > 5.0):
118 print 'Run %d, LS %d, Scale (%f), PixL (%f), PUL (%f) big change - please check!' % (run, LSnumber, scale, PixlumiInfo[1],PUlumiInfo[0])
121 newIntLumi = scale*PUlumiInfo[0]
122 newRmsLumi = scale*PUlumiInfo[1]
123 newInstLumi = scale*PUlumiInfo[2]
125 newIntLumi = PUlumiInfo[0]
126 newRmsLumi = PUlumiInfo[1]
127 newInstLumi = PUlumiInfo[2]
129 print 'Run %d, LS %d, Scale (%f), PixL (%f), PUL (%f) - 0 please check!' % (run, LSnumber, scale, PixlumiInfo[1],PUlumiInfo[0])
130 LumiString =
"[%d,%2.4e,%2.4e,%2.4e]," % (LSnumber, newIntLumi, newRmsLumi ,newInstLumi)
131 OUTPUTLINE += LumiString
137 newIntLumi = PUlumiInfo[0]
138 newRmsLumi = PUlumiInfo[1]
139 newInstLumi = PUlumiInfo[2]
142 LumiString =
"[%d,%2.4e,%2.4e,%2.4e]," % (LSnumber, newIntLumi, newRmsLumi ,newInstLumi)
143 OUTPUTLINE += LumiString
146 lastindex=len(OUTPUTLINE)-1
147 trunc = OUTPUTLINE[0:lastindex]
152 print "Run %d not found in Lumi/Pileup input file. Check your files!" % (run)
168 lastindex=len(OUTPUTLINE)-2
169 trunc = OUTPUTLINE[0:lastindex]
173 outputfile = open(options.outputfile,
'w')
175 raise RuntimeError(
"Could not open '%s' as an output JSON file" % output)
177 outputfile.write(OUTPUTLINE)