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 external corrections (Pixel luminosity, for example). 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' )
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)
99 for (run, LSPUlist)
in sorted (inputPileupRange.items()):
102 if run
in inputRange.keys():
103 OUTPUTLINE+= (
'"%d":' % run )
106 lslist = inputRange[run]
108 for LSnumber
in LSPUlist:
109 if LSnumber
in lslist.keys():
110 PUlumiInfo = LSPUlist[LSnumber]
111 PixlumiInfo = lslist[LSnumber]
115 if PUlumiInfo[0] > 0.:
116 scale=PixlumiInfo[1]/PUlumiInfo[0]
118 if scale !=0
and (scale < 0.2
or scale > 5.0):
119 print(
'Run %d, LS %d, Scale (%f), PixL (%f), PUL (%f) big change - please check!' % (run, LSnumber, scale, PixlumiInfo[1],PUlumiInfo[0]))
122 newIntLumi = scale*PUlumiInfo[0]
123 newRmsLumi = scale*PUlumiInfo[1]
124 newInstLumi = scale*PUlumiInfo[2]
126 newIntLumi = PUlumiInfo[0]
127 newRmsLumi = PUlumiInfo[1]
128 newInstLumi = PUlumiInfo[2]
130 print(
'Run %d, LS %d, Scale (%f), PixL (%f), PUL (%f) - 0 please check!' % (run, LSnumber, scale, PixlumiInfo[1],PUlumiInfo[0]))
131 LumiString =
"[%d,%2.4e,%2.4e,%2.4e]," % (LSnumber, newIntLumi, newRmsLumi ,newInstLumi)
132 OUTPUTLINE += LumiString
138 newIntLumi = PUlumiInfo[0]
139 newRmsLumi = PUlumiInfo[1]
140 newInstLumi = PUlumiInfo[2]
143 LumiString =
"[%d,%2.4e,%2.4e,%2.4e]," % (LSnumber, newIntLumi, newRmsLumi ,newInstLumi)
144 OUTPUTLINE += LumiString
147 lastindex=len(OUTPUTLINE)-1
148 trunc = OUTPUTLINE[0:lastindex]
153 print(
"Run %d not found in Lumi/Pileup input file. Check your files!" % (run))
169 lastindex=len(OUTPUTLINE)-2
170 trunc = OUTPUTLINE[0:lastindex]
174 outputfile = open(options.outputfile,
'w')
176 raise RuntimeError(
"Could not open '%s' as an output JSON file" % output)
178 outputfile.write(OUTPUTLINE)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def parseInputFile(inputfilename)