5 from RecoLuminosity.LumiDB
import pileupParser
6 from RecoLuminosity.LumiDB
import selectionParser
13 output ({run:[ls:[inlumi, meanint]]}) 15 selectf=open(inputfilename,
'r') 16 inputfilecontent=selectf.read() 20 runlsbyfile=p.runsandls()
34 cErf = 1.0 - (b1*T + b2*T*T + b3*T*T*T)*
exp(-1.0*X*X)
57 lumiinfo:[intlumi per LS, mean interactions ] 59 intlumi is the deadtime corrected average integraged lumi per lumisection 62 LSintLumi = lumiInfo[0]
63 RMSInt = lumiInfo[1]*minbXsec
64 AveNumInt = lumiInfo[2]*minbXsec
78 BinWidth = hist.GetBinWidth(1)
86 for obs
in range (Nbins):
92 left = hist.GetBinLowEdge(obs+1)
95 argR = (AveNumInt-right)/Sqrt2/RMSInt
99 argL = (AveNumInt-left)/Sqrt2/RMSInt
105 NewProb = (AreaL-AreaR)*0.5
107 ProbFromRMS.append(NewProb)
112 obs = hist.FindBin(AveNumInt)
113 for bin
in range (Nbins):
114 ProbFromRMS.append(0.0)
116 ProbFromRMS[obs] = 1.0
117 if AveNumInt < 1.0E-5:
118 ProbFromRMS[obs] = 0.
120 if calcOption ==
'true':
123 for obs
in range (Nbins):
124 prob = ProbFromRMS[obs]
125 val = hist.GetBinCenter(obs+1)
128 hist.Fill (val, prob * LSintLumi)
130 if 1.0-totalProb > 0.01:
131 print "Significant probability density outside of your histogram" 132 print "Consider using a higher value of --maxPileupBin" 133 print "Mean %f, RMS %f, Integrated probability %f" % (AveNumInt,RMSInt,totalProb)
136 hist.Fill(AveNumInt,LSintLumi)
140 BinWidth = hist.GetBinWidth(1)
141 for obs
in range (Nbins):
142 Peak = hist.GetBinCenter(obs+1)
143 RMSWeight = ProbFromRMS[obs]
144 for bin
in range (Nbins):
145 val = hist.GetBinCenter(bin+1)-0.5*BinWidth
146 prob = ROOT.TMath.Poisson (val, Peak)
148 hist.Fill (val, prob * LSintLumi * RMSWeight)
150 if 1.0-totalProb > 0.01:
151 print "Significant probability density outside of your histogram" 152 print "Consider using a higher value of --maxPileupBin" 167 if __name__ ==
'__main__':
169 parser = optparse.OptionParser (
"Usage: %prog [--options] output.root",
170 description =
"Script to estimate pileup distribution using xing instantaneous luminosity information and minimum bias cross section. Output is TH1D stored in root file")
173 CalculationModeChoices = [
'truth',
'observed']
183 parser.add_option(
'-o',dest=
'outputfile',action=
'store',
184 default=
'PileupCalc.root',
185 help=
'output root file')
186 parser.add_option(
'-i',dest=
'inputfile',action=
'store',
187 help=
'Input Run/LS file for your analysis in JSON format (required)')
188 parser.add_option(
'--inputLumiJSON',dest=
'inputLumiJSON',action=
'store',
189 help=
'Input Lumi/Pileup file in JSON format (required)')
190 parser.add_option(
'--calcMode',dest=
'calcMode',action=
'store',
191 help=
'Calculate either True ="true" or Observed="observed" distributions')
192 parser.add_option(
'--minBiasXsec',dest=
'minBiasXsec',action=
'store',
195 help=
'Minimum bias cross section assumed (in microbbarn), default %default microbarn')
196 parser.add_option(
'--maxPileupBin',dest=
'maxPileupBin',action=
'store',
199 help=
'Maximum value of pileup histogram, default %default')
200 parser.add_option(
'--numPileupBins',dest=
'numPileupBins',action=
'store',
203 help=
'number of bins in pileup histogram, default %default')
204 parser.add_option(
'--pileupHistName',dest=
'pileupHistName',action=
'store',
206 help=
'name of pileup histogram, default %default')
207 parser.add_option(
'--verbose',dest=
'verbose',action=
'store_true',help=
'verbose mode for printing' )
211 (options, args) = parser.parse_args()
212 except Exception
as e:
219 raise RuntimeError(
"Exactly one output file must be given")
225 print 'General configuration' 226 print '\toutputfile: ',options.outputfile
227 print '\tAction: ',options.calcMode,
'luminosity distribution will be calculated' 228 print '\tinput selection file: ',options.inputfile
229 print '\tMinBiasXsec: ',options.minBiasXsec
230 print '\tmaxPileupBin: ',options.maxPileupBin
231 print '\tnumPileupBins: ',options.numPileupBins
234 pileupHist = ROOT.TH1D (options.pileupHistName,options.pileupHistName,
235 options.numPileupBins,
236 0., options.maxPileupBin)
238 nbins = options.numPileupBins
239 upper = options.maxPileupBin
241 inpf = open (options.inputfile,
'r') 242 inputfilecontent = inpf.read() 247 if options.calcMode
in [
'true',
'observed']:
253 for (run, lslist)
in sorted (six.iteritems(inputRange)) ):
256 if run
in inputPileupRange.keys():
258 LSPUlist = inputPileupRange[run]
260 for LSnumber
in lslist:
261 if LSnumber
in LSPUlist.keys():
263 lumiInfo = LSPUlist[LSnumber]
265 fillPileupHistogram (lumiInfo, options.calcMode,
266 pileupHist, options.minBiasXsec, nbins)
268 print "Run %d, LumiSection %d not found in Lumi/Pileup input file. Check your files!" \
272 print "Run %d not found in Lumi/Pileup input file. Check your files!" % (run)
279 histFile = ROOT.TFile.Open (output,
'recreate')
281 raise RuntimeError(
"Could not open '%s' as an output root file" % output)
289 print "must specify a pileup calculation mode via --calcMode true or --calcMode observed" def parseInputFile(inputfilename)
def fillPileupHistogram(lumiInfo, calcOption, hist, minbXsec, Nbins)
Abs< T >::type abs(const T &t)