2 from __future__
import print_function
6 from RecoLuminosity.LumiDB
import pileupParser
7 from RecoLuminosity.LumiDB
import selectionParser
8 from RecoLuminosity.LumiDB
import csvLumibyLSParser
14 output ({run:[ls:[inlumi, meanint]]})
16 selectf=open(inputfilename,
'r')
17 inputfilecontent=selectf.read()
21 runlsbyfile=p.runsandls()
34 if __name__ ==
'__main__':
36 parser = optparse.OptionParser (
"Usage: %prog [--options]",
37 description =
"Script to rescale pileup distributions using inputs derived by calculating luminosity for a given set of HLT paths. Input format must be -lumibyls-")
40 CalculationModeChoices = [
'truth',
'observed']
50 parser.add_option(
'-o',dest=
'outputfile',action=
'store',
51 default=
'PileupRecalcJSON.txt',
52 help=
'output pileup JSON file')
53 parser.add_option(
'-i',dest=
'inputfile',action=
'store',
54 help=
'Input Run/LS/lumis file for your trigger selection (required)')
55 parser.add_option(
'--inputLumiJSON',dest=
'inputLumiJSON',action=
'store',
56 help=
'Input Lumi/Pileup file in JSON format (required)')
57 parser.add_option(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode for printing' )
58 parser.add_option(
'--runperiod',dest=
'runperiod',action=
'store', default=
'Run1',help=
'select runperiod Run1 or Run2, default Run1' )
61 (options, args) = parser.parse_args()
62 except Exception
as e:
75 print(
'General configuration')
76 print(
'\toutputfile: ',options.outputfile)
77 print(
'\tinput selection file: ',options.inputfile)
98 for (run, lslist)
in sorted (inputRange.items()):
101 if run
in inputPileupRange.keys():
102 OUTPUTLINE+= (
'"%d":' % run )
105 LSPUlist = inputPileupRange[run]
107 for LSnumber
in lslist:
108 if LSnumber
in LSPUlist.keys():
109 PUlumiInfo = LSPUlist[LSnumber]
110 HLTlumiInfo = lslist[LSnumber]
114 if PUlumiInfo[0] > 0.:
115 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)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)