5 from RecoLuminosity.LumiDB
import pileupParser
6 from RecoLuminosity.LumiDB
import selectionParser
12 output ({run:[ls:[inlumi, meanint]]})
14 selectf=open(inputfilename,
'r')
15 inputfilecontent=selectf.read()
19 runlsbyfile=p.runsandls()
33 cErf = 1.0 - (b1*T + b2*T*T + b3*T*T*T)*
exp(-1.0*X*X)
56 lumiinfo:[intlumi per LS, mean interactions ]
58 intlumi is the deadtime corrected average integraged lumi per lumisection
61 LSintLumi = lumiInfo[0]
62 RMSInt = lumiInfo[1]*minbXsec
63 AveNumInt = lumiInfo[2]*minbXsec
77 BinWidth = hist.GetBinWidth(1)
85 for obs
in range (Nbins):
91 left = hist.GetBinLowEdge(obs+1)
94 argR = (AveNumInt-right)/Sqrt2/RMSInt
98 argL = (AveNumInt-left)/Sqrt2/RMSInt
104 NewProb = (AreaL-AreaR)*0.5
106 ProbFromRMS.append(NewProb)
111 obs = hist.FindBin(AveNumInt)
112 for bin
in range (Nbins):
113 ProbFromRMS.append(0.0)
115 ProbFromRMS[obs] = 1.0
116 if AveNumInt < 1.0E-5:
117 ProbFromRMS[obs] = 0.
119 if calcOption ==
'true':
122 for obs
in range (Nbins):
123 prob = ProbFromRMS[obs]
124 val = hist.GetBinCenter(obs+1)
127 hist.Fill (val, prob * LSintLumi)
129 if 1.0-totalProb > 0.01:
130 print "Significant probability density outside of your histogram"
131 print "Consider using a higher value of --maxPileupBin"
132 print "Mean %f, RMS %f, Integrated probability %f" % (AveNumInt,RMSInt,totalProb)
135 hist.Fill(AveNumInt,LSintLumi)
139 BinWidth = hist.GetBinWidth(1)
140 for obs
in range (Nbins):
141 Peak = hist.GetBinCenter(obs+1)
142 RMSWeight = ProbFromRMS[obs]
143 for bin
in range (Nbins):
144 val = hist.GetBinCenter(bin+1)-0.5*BinWidth
145 prob = ROOT.TMath.Poisson (val, Peak)
147 hist.Fill (val, prob * LSintLumi * RMSWeight)
149 if 1.0-totalProb > 0.01:
150 print "Significant probability density outside of your histogram"
151 print "Consider using a higher value of --maxPileupBin"
166 if __name__ ==
'__main__':
168 parser = optparse.OptionParser (
"Usage: %prog [--options] output.root",
169 description =
"Script to estimate pileup distribution using xing instantaneous luminosity information and minimum bias cross section. Output is TH1D stored in root file")
172 CalculationModeChoices = [
'truth',
'observed']
182 parser.add_option(
'-o',dest=
'outputfile',action=
'store',
183 default=
'PileupCalc.root',
184 help=
'output root file')
185 parser.add_option(
'-i',dest=
'inputfile',action=
'store',
186 help=
'Input Run/LS file for your analysis in JSON format (required)')
187 parser.add_option(
'--inputLumiJSON',dest=
'inputLumiJSON',action=
'store',
188 help=
'Input Lumi/Pileup file in JSON format (required)')
189 parser.add_option(
'--calcMode',dest=
'calcMode',action=
'store',
190 help=
'Calculate either True ="true" or Observed="observed" distributions')
191 parser.add_option(
'--minBiasXsec',dest=
'minBiasXsec',action=
'store',
194 help=
'Minimum bias cross section assumed (in microbbarn), default %default microbarn')
195 parser.add_option(
'--maxPileupBin',dest=
'maxPileupBin',action=
'store',
198 help=
'Maximum value of pileup histogram, default %default')
199 parser.add_option(
'--numPileupBins',dest=
'numPileupBins',action=
'store',
202 help=
'number of bins in pileup histogram, default %default')
203 parser.add_option(
'--pileupHistName',dest=
'pileupHistName',action=
'store',
205 help=
'name of pileup histogram, default %default')
206 parser.add_option(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode for printing' )
210 (options, args) = parser.parse_args()
211 except Exception , e:
218 raise RuntimeError,
"Exactly one output file must be given"
224 print 'General configuration'
225 print '\toutputfile: ',options.outputfile
226 print '\tAction: ',options.calcMode,
'luminosity distribution will be calculated'
227 print '\tinput selection file: ',options.inputfile
228 print '\tMinBiasXsec: ',options.minBiasXsec
229 print '\tmaxPileupBin: ',options.maxPileupBin
230 print '\tnumPileupBins: ',options.numPileupBins
233 pileupHist = ROOT.TH1D (options.pileupHistName,options.pileupHistName,
234 options.numPileupBins,
235 0., options.maxPileupBin)
237 nbins = options.numPileupBins
238 upper = options.maxPileupBin
240 inpf = open (options.inputfile,
'r')
241 inputfilecontent = inpf.read()
246 if options.calcMode
in [
'true',
'observed']:
252 for (run, lslist)
in sorted (inputRange.iteritems() ):
255 if run
in inputPileupRange.keys():
257 LSPUlist = inputPileupRange[run]
259 for LSnumber
in lslist:
260 if LSnumber
in LSPUlist.keys():
262 lumiInfo = LSPUlist[LSnumber]
264 fillPileupHistogram (lumiInfo, options.calcMode,
265 pileupHist, options.minBiasXsec, nbins)
267 print "Run %d, LumiSection %d not found in Lumi/Pileup input file. Check your files!" \
271 print "Run %d not found in Lumi/Pileup input file. Check your files!" % (run)
278 histFile = ROOT.TFile.Open (output,
'recreate')
280 raise RuntimeError, \
281 "Could not open '%s' as an output root file" % output
289 print "must specify a pileup calculation mode via --calcMode true or --calcMode observed"