2 from __future__
import print_function
3 from builtins
import range
7 from RecoLuminosity.LumiDB
import pileupParser
8 from RecoLuminosity.LumiDB
import selectionParser
15 output ({run:[ls:[inlumi, meanint]]}) 17 selectf=open(inputfilename,
'r') 18 inputfilecontent=selectf.read() 22 runlsbyfile=p.runsandls()
36 cErf = 1.0 - (b1*T + b2*T*T + b3*T*T*T)*
exp(-1.0*X*X)
59 lumiinfo:[intlumi per LS, mean interactions ] 61 intlumi is the deadtime corrected average integraged lumi per lumisection 64 LSintLumi = lumiInfo[0]
65 RMSInt = lumiInfo[1]*minbXsec
66 AveNumInt = lumiInfo[2]*minbXsec
80 BinWidth = hist.GetBinWidth(1)
88 for obs
in range (Nbins):
94 left = hist.GetBinLowEdge(obs+1)
97 argR = (AveNumInt-right)/Sqrt2/RMSInt
101 argL = (AveNumInt-left)/Sqrt2/RMSInt
107 NewProb = (AreaL-AreaR)*0.5
109 ProbFromRMS.append(NewProb)
114 obs = hist.FindBin(AveNumInt)
115 for bin
in range (Nbins):
116 ProbFromRMS.append(0.0)
118 ProbFromRMS[obs] = 1.0
119 if AveNumInt < 1.0E-5:
120 ProbFromRMS[obs] = 0.
122 if calcOption ==
'true':
125 for obs
in range (Nbins):
126 prob = ProbFromRMS[obs]
127 val = hist.GetBinCenter(obs+1)
130 hist.Fill (val, prob * LSintLumi)
132 if 1.0-totalProb > 0.01:
133 print(
"Significant probability density outside of your histogram")
134 print(
"Consider using a higher value of --maxPileupBin")
135 print(
"Mean %f, RMS %f, Integrated probability %f" % (AveNumInt,RMSInt,totalProb))
138 hist.Fill(AveNumInt,LSintLumi)
142 BinWidth = hist.GetBinWidth(1)
143 for obs
in range (Nbins):
144 Peak = hist.GetBinCenter(obs+1)
145 RMSWeight = ProbFromRMS[obs]
146 for bin
in range (Nbins):
147 val = hist.GetBinCenter(bin+1)-0.5*BinWidth
148 prob = ROOT.TMath.Poisson (val, Peak)
150 hist.Fill (val, prob * LSintLumi * RMSWeight)
152 if 1.0-totalProb > 0.01:
153 print(
"Significant probability density outside of your histogram")
154 print(
"Consider using a higher value of --maxPileupBin")
169 if __name__ ==
'__main__':
171 parser = optparse.OptionParser (
"Usage: %prog [--options] output.root",
172 description =
"Script to estimate pileup distribution using xing instantaneous luminosity information and minimum bias cross section. Output is TH1D stored in root file")
175 CalculationModeChoices = [
'truth',
'observed']
185 parser.add_option(
'-o',dest=
'outputfile',action=
'store',
186 default=
'PileupCalc.root',
187 help=
'output root file')
188 parser.add_option(
'-i',dest=
'inputfile',action=
'store',
189 help=
'Input Run/LS file for your analysis in JSON format (required)')
190 parser.add_option(
'--inputLumiJSON',dest=
'inputLumiJSON',action=
'store',
191 help=
'Input Lumi/Pileup file in JSON format (required)')
192 parser.add_option(
'--calcMode',dest=
'calcMode',action=
'store',
193 help=
'Calculate either True ="true" or Observed="observed" distributions')
194 parser.add_option(
'--minBiasXsec',dest=
'minBiasXsec',action=
'store',
197 help=
'Minimum bias cross section assumed (in microbbarn), default %default microbarn')
198 parser.add_option(
'--maxPileupBin',dest=
'maxPileupBin',action=
'store',
201 help=
'Maximum value of pileup histogram, default %default')
202 parser.add_option(
'--numPileupBins',dest=
'numPileupBins',action=
'store',
205 help=
'number of bins in pileup histogram, default %default')
206 parser.add_option(
'--pileupHistName',dest=
'pileupHistName',action=
'store',
208 help=
'name of pileup histogram, default %default')
209 parser.add_option(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode for printing' )
213 (options, args) = parser.parse_args()
214 except Exception
as e:
221 raise RuntimeError(
"Exactly one output file must be given")
227 print(
'General configuration')
228 print(
'\toutputfile: ',options.outputfile)
229 print(
'\tAction: ',options.calcMode,
'luminosity distribution will be calculated')
230 print(
'\tinput selection file: ',options.inputfile)
231 print(
'\tMinBiasXsec: ',options.minBiasXsec)
232 print(
'\tmaxPileupBin: ',options.maxPileupBin)
233 print(
'\tnumPileupBins: ',options.numPileupBins)
236 pileupHist = ROOT.TH1D (options.pileupHistName,options.pileupHistName,
237 options.numPileupBins,
238 0., options.maxPileupBin)
240 nbins = options.numPileupBins
241 upper = options.maxPileupBin
243 inpf = open (options.inputfile,
'r') 244 inputfilecontent = inpf.read() 249 if options.calcMode
in [
'true',
'observed']:
255 for (run, lslist)
in sorted (six.iteritems(inputRange)):
258 if run
in inputPileupRange.keys():
260 LSPUlist = inputPileupRange[run]
262 for LSnumber
in lslist:
263 if LSnumber
in LSPUlist.keys():
265 lumiInfo = LSPUlist[LSnumber]
267 fillPileupHistogram (lumiInfo, options.calcMode,
268 pileupHist, options.minBiasXsec, nbins)
270 print(
"Run %d, LumiSection %d not found in Lumi/Pileup input file. Check your files!" \
274 print(
"Run %d not found in Lumi/Pileup input file. Check your files!" % (run))
281 histFile = ROOT.TFile.Open (output,
'recreate')
283 raise RuntimeError(
"Could not open '%s' as an output root file" % output)
291 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)