2 from __future__
import print_function
6 from RecoLuminosity.LumiDB
import pileupParser
7 from RecoLuminosity.LumiDB
import selectionParser
14 output ({run:[ls:[inlumi, meanint]]}) 16 selectf=open(inputfilename,
'r') 17 inputfilecontent=selectf.read() 21 runlsbyfile=p.runsandls()
35 cErf = 1.0 - (b1*T + b2*T*T + b3*T*T*T)*
exp(-1.0*X*X)
58 lumiinfo:[intlumi per LS, mean interactions ] 60 intlumi is the deadtime corrected average integraged lumi per lumisection 63 LSintLumi = lumiInfo[0]
64 RMSInt = lumiInfo[1]*minbXsec
65 AveNumInt = lumiInfo[2]*minbXsec
79 BinWidth = hist.GetBinWidth(1)
87 for obs
in range (Nbins):
93 left = hist.GetBinLowEdge(obs+1)
96 argR = (AveNumInt-right)/Sqrt2/RMSInt
100 argL = (AveNumInt-left)/Sqrt2/RMSInt
106 NewProb = (AreaL-AreaR)*0.5
108 ProbFromRMS.append(NewProb)
113 obs = hist.FindBin(AveNumInt)
114 for bin
in range (Nbins):
115 ProbFromRMS.append(0.0)
117 ProbFromRMS[obs] = 1.0
118 if AveNumInt < 1.0E-5:
119 ProbFromRMS[obs] = 0.
121 if calcOption ==
'true':
124 for obs
in range (Nbins):
125 prob = ProbFromRMS[obs]
126 val = hist.GetBinCenter(obs+1)
129 hist.Fill (val, prob * LSintLumi)
131 if 1.0-totalProb > 0.01:
132 print(
"Significant probability density outside of your histogram")
133 print(
"Consider using a higher value of --maxPileupBin")
134 print(
"Mean %f, RMS %f, Integrated probability %f" % (AveNumInt,RMSInt,totalProb))
137 hist.Fill(AveNumInt,LSintLumi)
141 BinWidth = hist.GetBinWidth(1)
142 for obs
in range (Nbins):
143 Peak = hist.GetBinCenter(obs+1)
144 RMSWeight = ProbFromRMS[obs]
145 for bin
in range (Nbins):
146 val = hist.GetBinCenter(bin+1)-0.5*BinWidth
147 prob = ROOT.TMath.Poisson (val, Peak)
149 hist.Fill (val, prob * LSintLumi * RMSWeight)
151 if 1.0-totalProb > 0.01:
152 print(
"Significant probability density outside of your histogram")
153 print(
"Consider using a higher value of --maxPileupBin")
168 if __name__ ==
'__main__':
170 parser = optparse.OptionParser (
"Usage: %prog [--options] output.root",
171 description =
"Script to estimate pileup distribution using xing instantaneous luminosity information and minimum bias cross section. Output is TH1D stored in root file")
174 CalculationModeChoices = [
'truth',
'observed']
184 parser.add_option(
'-o',dest=
'outputfile',action=
'store',
185 default=
'PileupCalc.root',
186 help=
'output root file')
187 parser.add_option(
'-i',dest=
'inputfile',action=
'store',
188 help=
'Input Run/LS file for your analysis in JSON format (required)')
189 parser.add_option(
'--inputLumiJSON',dest=
'inputLumiJSON',action=
'store',
190 help=
'Input Lumi/Pileup file in JSON format (required)')
191 parser.add_option(
'--calcMode',dest=
'calcMode',action=
'store',
192 help=
'Calculate either True ="true" or Observed="observed" distributions')
193 parser.add_option(
'--minBiasXsec',dest=
'minBiasXsec',action=
'store',
196 help=
'Minimum bias cross section assumed (in microbbarn), default %default microbarn')
197 parser.add_option(
'--maxPileupBin',dest=
'maxPileupBin',action=
'store',
200 help=
'Maximum value of pileup histogram, default %default')
201 parser.add_option(
'--numPileupBins',dest=
'numPileupBins',action=
'store',
204 help=
'number of bins in pileup histogram, default %default')
205 parser.add_option(
'--pileupHistName',dest=
'pileupHistName',action=
'store',
207 help=
'name of pileup histogram, default %default')
208 parser.add_option(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode for printing' )
212 (options, args) = parser.parse_args()
213 except Exception
as e:
220 raise RuntimeError(
"Exactly one output file must be given")
226 print(
'General configuration')
227 print(
'\toutputfile: ',options.outputfile)
228 print(
'\tAction: ',options.calcMode,
'luminosity distribution will be calculated')
229 print(
'\tinput selection file: ',options.inputfile)
230 print(
'\tMinBiasXsec: ',options.minBiasXsec)
231 print(
'\tmaxPileupBin: ',options.maxPileupBin)
232 print(
'\tnumPileupBins: ',options.numPileupBins)
235 pileupHist = ROOT.TH1D (options.pileupHistName,options.pileupHistName,
236 options.numPileupBins,
237 0., options.maxPileupBin)
239 nbins = options.numPileupBins
240 upper = options.maxPileupBin
242 inpf = open (options.inputfile,
'r') 243 inputfilecontent = inpf.read() 248 if options.calcMode
in [
'true',
'observed']:
254 for (run, lslist)
in sorted (six.iteritems(inputRange)):
257 if run
in inputPileupRange.keys():
259 LSPUlist = inputPileupRange[run]
261 for LSnumber
in lslist:
262 if LSnumber
in LSPUlist.keys():
264 lumiInfo = LSPUlist[LSnumber]
266 fillPileupHistogram (lumiInfo, options.calcMode,
267 pileupHist, options.minBiasXsec, nbins)
269 print(
"Run %d, LumiSection %d not found in Lumi/Pileup input file. Check your files!" \
273 print(
"Run %d not found in Lumi/Pileup input file. Check your files!" % (run))
280 histFile = ROOT.TFile.Open (output,
'recreate')
282 raise RuntimeError(
"Could not open '%s' as an output root file" % output)
290 print(
"must specify a pileup calculation mode via --calcMode true or --calcMode observed")
def parseInputFile(inputfilename)
def fillPileupHistogram(lumiInfo, calcOption, hist, minbXsec, Nbins)
S & print(S &os, JobReport::InputFile const &f)
Abs< T >::type abs(const T &t)