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 HLT paths. 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' )
59 parser.add_option(
'--runperiod',dest=
'runperiod',action=
'store', default=
'Run1',help=
'select runperiod Run1 or Run2, default Run1' )
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)
99 for (run, lslist)
in sorted (six.iteritems(inputRange)):
102 if run
in inputPileupRange.keys():
103 OUTPUTLINE+= (
'"%d":' % run )
106 LSPUlist = inputPileupRange[run]
108 for LSnumber
in lslist:
109 if LSnumber
in LSPUlist.keys():
110 PUlumiInfo = LSPUlist[LSnumber]
111 HLTlumiInfo = lslist[LSnumber]
115 if PUlumiInfo[0] > 0.:
116 scale=HLTlumiInfo[1]/PUlumiInfo[0]
119 print(
'Run %d, LS %d, HLT Scale (%f), HLTL (%f), PUL (%f) larger than one - please check!' % (run, LSnumber, scale, HLTlumiInfo[1],PUlumiInfo[0]))
122 newIntLumi = scale*PUlumiInfo[0]
123 newRmsLumi = PUlumiInfo[1]
124 newInstLumi = PUlumiInfo[2]
126 newInstLumi = PUlumiInfo[2]
129 LumiString =
"[%d,%2.4e,%2.4e,%2.4e]," % (LSnumber, newIntLumi, newRmsLumi ,newInstLumi)
130 OUTPUTLINE += LumiString
139 LumiString =
"[%d,0.0,0.0,%2.4e]," % (LSnumber, newInstLumi)
140 OUTPUTLINE += LumiString
143 lastindex=len(OUTPUTLINE)-1
144 trunc = OUTPUTLINE[0:lastindex]
149 print(
"Run %d not found in Lumi/Pileup input file. Check your files!" % (run))
165 lastindex=len(OUTPUTLINE)-2
166 trunc = OUTPUTLINE[0:lastindex]
170 outputfile = open(options.outputfile,
'w')
172 raise RuntimeError(
"Could not open '%s' as an output JSON file" % output)
174 outputfile.write(OUTPUTLINE)
S & print(S &os, JobReport::InputFile const &f)
def parseInputFile(inputfilename)