5 Command line tool to extract desired vertices from a beam spot fitter
6 ntuple, store them in a standalone ntuple for use in RooFit, and run
7 different RooFit beam spot fits.
9 __author__ =
'Juerg Beringer'
10 __version__ =
'$Id: fitman.py 721742 2016-02-03 23:34:44Z beringer $'
11 __usage__ =
"""%prog [options] [cmd ...]
15 extract Extract selected vertices into vertex ntuple
16 (if given, must be first command)
17 stdfit Standard beam spot fit (except for outlier removal)
18 stdfitvzz Dito, but includes z resolution
19 mypdf Similar to stdfit, but uses dedicated BeamSpotPdf class
20 (fast, but doesn't implement all integrals for plotting yet)
21 2gauss Double Gaussian fit - NOT YET WORKING
22 plot[xyz] Plot data and fit of x, y, and z, or single plot
23 data Histograms of x, y, z
24 cov Histograms of vertex error covariance
25 vtxerr Histograms of vertex errors in x, y, z
26 vtxerrxy Histograms of vertex errors in x, y
30 from array
import array
31 from math
import sqrt, floor
40 if re.search(
'\s|\*|\?',s):
42 qargv.append(
'"%s"' % re.sub(
'"',
"'",s))
44 qargv.append(
"'%s'" % re.sub(
"'",
'"',s))
53 from optparse
import OptionParser
54 parser = OptionParser(usage=__usage__, version=__version__)
55 parser.add_option(
'-e',
'--srcnt', dest=
'srcNtName', default=
None, help=
'extract: file name of source beam spot fitter ntuple')
56 parser.add_option(
'',
'--srctree', dest=
'srcTreeName', default=
'Beamspot/Vertices', help=
'extract: tree name of vertex ntuple (default: Beamspot/Vertices)')
57 parser.add_option(
'-l',
'--lbl', dest=
'lbMin', type=
'int', default=0, help=
'extract: minimum LB number (inclusive)')
58 parser.add_option(
'-u',
'--lbu', dest=
'lbMax', type=
'int', default=9999, help=
'extract: maximum LB number (inclusive)')
59 parser.add_option(
'',
'--bcid', dest=
'bcid', type=
'int', default=
None, help=
'extract: BCID')
60 parser.add_option(
'-t',
'--vtype', dest=
'vType', type=
'int', default=
None, help=
'extract: vertex type (1=PriVtx, 3=PileUp)')
61 parser.add_option(
'-n',
'--ntracks', dest=
'nTracks', type=
'int', default=
None, help=
'extract: min number of tracks per vertex')
62 parser.add_option(
'-p',
'--passed', dest=
'passed', type=
'int', default=
None, help=
'extract: passed flag (use only vertices passing InDetBeamSpotFinder selection)')
63 parser.add_option(
'',
'--rndfrac', dest=
'rndFrac', type=
'float', default=
None, help=
'extract: pick given fraction of random vertices after all other selections')
64 parser.add_option(
'',
'--prescale', dest=
'prescale', type=
'int', default=
None, help=
'extract: prescale selected vertices')
65 parser.add_option(
'',
'--nblk', dest=
'nblk', type=
'int', default=
None, help=
'extract: number of selected vertices per block (default: not used)')
66 parser.add_option(
'',
'--iblk', dest=
'iblk', type=
'int', default=0, help=
'extract: block number to use (default: 0)')
67 parser.add_option(
'',
'--chi2ndf', dest=
'chi2ndf', type=
'float', default=
None, help=
'extract: max chi2/ndf')
68 parser.add_option(
'',
'--chi2prob', dest=
'chi2prob', type=
'float', default=
None, help=
'extract: min chi2 probability')
69 parser.add_option(
'',
'--maxvtxerr', dest=
'maxvtxerr', type=
'float', default=
None, help=
'extract: max allowed transverse vertex error')
70 parser.add_option(
'',
'--minvtxerr', dest=
'minvtxerr', type=
'float', default=
None, help=
'extract: min allowed transverse vertex error')
71 parser.add_option(
'',
'--xmin', dest=
'xmin', type=
'float', default=
None, help=
'extract: lower cut on x')
72 parser.add_option(
'',
'--xmax', dest=
'xmax', type=
'float', default=
None, help=
'extract: upper cut on x')
73 parser.add_option(
'',
'--ymin', dest=
'ymin', type=
'float', default=
None, help=
'extract: lower cut on y')
74 parser.add_option(
'',
'--ymax', dest=
'ymax', type=
'float', default=
None, help=
'extract: upper cut on y')
75 parser.add_option(
'',
'--zmin', dest=
'zmin', type=
'float', default=
None, help=
'extract: lower cut on z')
76 parser.add_option(
'',
'--zmax', dest=
'zmax', type=
'float', default=
None, help=
'extract: upper cut on z')
77 parser.add_option(
'-f',
'--nt', dest=
'ntName', default=
'vtx.root', help=
'file name vertex ntuple (default: vtx.root)')
78 parser.add_option(
'-g',
'--nttree', dest=
'ntTree', default=
"Vertices", help=
'name of TTree with vertices')
79 parser.add_option(
'',
'--plot', dest=
'plot', default=
'ALL', help=
'what to plot (default: ALL)')
80 parser.add_option(
'',
'--canvas', dest=
'canvas', default=
'default', help=
'canvas size: default, page, wide, extrawide or square')
81 parser.add_option(
'',
'--lsize', dest=
'lsize', type=
'float', default=0.05, help=
'axis label size')
82 parser.add_option(
'',
'--hnbins', dest=
'hnbins', type=
'int', default=
None, help=
'number of histogram bins')
83 parser.add_option(
'',
'--hmin', dest=
'hmin', type=
'float', default=
None, help=
'histogram x axis minimum')
84 parser.add_option(
'',
'--hmax', dest=
'hmax', type=
'float', default=
None, help=
'histogram x axis maximum')
85 parser.add_option(
'',
'--hrange', dest=
'hrange', type=
'float', default=
None, help=
'histogram x axis range')
86 parser.add_option(
'',
'--fixK', dest=
'fixK', type=
'float', default=
None, help=
'stdfit: fix k factor in fit')
87 parser.add_option(
'',
'--showbs', dest=
'showbs', action=
'store_true', default=
False, help=
'show beam spot')
88 parser.add_option(
'',
'--showratio', dest=
'showratio', action=
'store_true', default=
False, help=
'show ratio data/fit')
89 parser.add_option(
'',
'--minrange', dest=
'minrange', type=
'float', default=0.1, help=
'min range of x-axis on plots')
90 parser.add_option(
'',
'--logy', dest=
'logy', action=
'store_true', default=
False, help=
'log scale')
91 parser.add_option(
'-s',
'--stats', dest=
'stats', action=
'store_true', default=
False, help=
'show statistics box on plot')
92 parser.add_option(
'',
'--optstat', dest=
'optstat', default=
'emruo', help=
'default OptStat value (Default: emruo)')
93 parser.add_option(
'',
'--prelim', dest=
'prelim', action=
'store_true', default=
False, help=
'add ATLAS Preliminary to figure')
94 parser.add_option(
'',
'--approval', dest=
'approval', action=
'store_true', default=
False, help=
'Label figure ATLAS for approval')
95 parser.add_option(
'',
'--published', dest=
'published', action=
'store_true', default=
False, help=
'add ATLAS to figure')
96 parser.add_option(
'',
'--atlasx', dest=
'atlasx', type=
'float', default=0.2, help=
'x position for drawing ATLAS (Preliminary) label')
97 parser.add_option(
'',
'--atlasy', dest=
'atlasy', type=
'float', default=0.85, help=
'y position for drawing ATLAS (Preliminary) label')
98 parser.add_option(
'',
'--atlasdx', dest=
'atlasdx', type=
'float', default=0.115, help=
'x position offset for drawing Preliminary label')
99 parser.add_option(
'',
'--comment', dest=
'comment', default=
'', help=
'additional text (use semicolon to indicate line breaks)')
100 parser.add_option(
'',
'--commentx', dest=
'commentx', type=
'float', default=0.2, help=
'x position for additional text')
101 parser.add_option(
'',
'--commenty', dest=
'commenty', type=
'float', default=0.69, help=
'y position for additional text')
102 parser.add_option(
'',
'--legendx', dest=
'legendx', type=
'float', default=0.70, help=
'x position of legend')
103 parser.add_option(
'',
'--legendy', dest=
'legendy', type=
'float', default=0.93, help=
'y position of legend')
104 parser.add_option(
'',
'--name', dest=
'name', default=
'fitman', help=
'name for set of plots (default: fitman)')
105 parser.add_option(
'-o',
'--output', dest=
'output', default=
'.gif', help=
'comma-separated list of output files or formats (default: .gif)')
106 parser.add_option(
'-c',
'--cpu', dest=
'nCpu', type=
'int', default=2, help=
'number of CPUs to use for RooFit')
107 parser.add_option(
'-v',
'--verbose', dest=
'verbose', action=
'store_true', default=
False, help=
'verbose output')
108 parser.add_option(
'-i',
'--interactive', dest=
'interactive', action=
'store_true', default=
False, help=
'interactive')
109 parser.add_option(
'-b',
'--batch', dest=
'batch', action=
'store_true', default=
False, help=
'run in batch mode')
110 (options,args) = parser.parse_args()
112 parser.error(
'wrong number of command line arguments')
113 if options.srcNtName
and not 'extract' in args:
114 parser.error(
'must give extract command when using -e or --srcnt')
115 if options.interactive:
116 os.environ[
'PYTHONINSPECT'] =
'1'
121 os.unsetenv(
'DISPLAY')
127 ROOT.gStyle.SetOptStat(options.optstat)
134 log =
open(
'%s.txt' % options.name,
'w')
139 out = ROOT.std.stringstream()
140 fitresult.printStream(out,fitresult.defaultPrintContents(
''),fitresult.defaultPrintStyle(
''))
147 vtxData.Draw(what,
'%s > %s && %s < %s' % (what,wmin,what,wmax),
'goff')
148 h = ROOT.gROOT.FindObject(
'htemp')
149 print 'Histogram for %s: mean = %7.4f rms = %1.4f' % (what,h.GetMean(),h.GetRMS())
150 return h.Clone(
'tmp-'+what)
158 def __init__(self, name = options.name, whatList = []):
166 mainPad = self.
protect( ROOT.TPad(
"mainPad",
"mainPad",0.,0.3,1.,1.) )
167 mainPad.SetBottomMargin(0.03)
174 ROOT.gROOT.ProcessLine(
".L ratioPlot.C+")
175 axisTitle = frame.GetXaxis().GetTitle()
176 frame.GetXaxis().SetTitle(
'')
177 frame.GetXaxis().SetLabelSize(0.)
178 frame.GetYaxis().SetTitleOffset(1.0)
179 canvas = ROOT.gPad.GetCanvas()
181 ratioPad = self.
protect( ROOT.TPad(
"ratioPad",
"ratioPad",0.,0.,1.,0.3) )
182 ratioPad.SetTopMargin(0.)
183 ratioPad.SetBottomMargin(0.3)
186 dataHist = frame.getObject(0)
187 fitCurve = frame.getObject(1)
191 ratio = ROOT.ratioPlot(dataHist,fitCurve)
194 ratio.GetXaxis().SetLimits(hmin,hmax)
196 size = scale*options.lsize
197 ratio.GetXaxis().SetLabelSize(size)
198 ratio.GetXaxis().SetTitle(axisTitle)
199 ratio.GetXaxis().SetTitleSize(size)
200 ratio.GetXaxis().SetTitleOffset(1.)
201 ratio.GetYaxis().SetRangeUser(0.3,1.7)
202 ratio.GetYaxis().SetLabelSize(size)
203 ratio.GetYaxis().SetTitle(
'Data / fit')
205 ratio.GetYaxis().SetTitleSize(size)
206 ratio.GetYaxis().SetTitleOffset(1.0/scale)
207 ratio.GetYaxis().SetNdivisions(504)
208 ratio.SetMarkerSize(0.7)
209 line = self.
protect( ROOT.TLine(hmin,1,hmax,1) )
216 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
True,offset=options.atlasdx,energy=8,size=options.lsize)
218 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
False,offset=options.atlasdx,isForApproval=
True,energy=8,size=options.lsize)
219 if options.published:
220 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
False,offset=options.atlasdx,energy=8,size=options.lsize)
226 legendList.append([frame.getObject(0),
'Data',
'P'])
227 legendList.append([frame.getObject(1),
'Fit projection',
'L'])
229 legendList.append([frame.getObject(2),
'Beam spot',
'L'])
230 legendMinY =
max(options.legendy-options.lsize*1.4*len(legendList),0.2)
236 if options.hmin
is not None or options.hmax
is not None or options.hnbins
is not None:
237 options.hmin = options.hmin
if options.hmin
is not None else 0.
238 options.hmax = options.hmax
if options.hmax
is not None else 1.
239 options.hnbins = options.hnbins
if options.hnbins
is not None else 40
241 options.hnbins,options.hmin,options.hmax))
242 vtxData.Draw(
'%s >> tmp' % what)
246 ROOT.gPad.SetLogy(options.logy)
249 if options.showratio:
251 dx = options.hrange/2
if options.hrange
else max(options.minrange/2.,8.*sx.getVal())
252 hmin = options.hmin
if options.hmin
is not None else mx.getVal()-dx
253 hmax = options.hmax
if options.hmax
is not None else mx.getVal()+dx
255 xframe = self.
protect( x.frame(hmin,hmax) )
256 if options.hnbins
is not None:
257 binning = ROOT.RooBinning(hmin, hmax)
258 binning.addUniform(options.hnbins, hmin, hmax)
259 data.plotOn(xframe,RooFit.Binning(binning))
260 xbinWidth = (hmax-hmin)/
float(options.hnbins)
263 xbinWidth = xframe.GetXaxis().GetBinWidth(1)
265 xframe.GetYaxis().SetTitle(
"Events / %1.0f #mum" %
round(1000.*xbinWidth,1))
266 xframe.GetYaxis().SetLabelSize(options.lsize)
267 xframe.GetYaxis().SetTitleSize(options.lsize)
270 cov = RooArgSet(vxx,vyy,vxy)
271 fitmodel.plotOn(xframe,RooFit.ProjWData(cov,data),
272 RooFit.NumCPU(options.nCpu))
275 fitmodel.plotOn(xframe,RooFit.ProjWData(cov,data),
276 RooFit.NumCPU(options.nCpu),
277 RooFit.LineStyle(RooFit.kDashed))
280 ROOT.gPad.SetLogy(options.logy)
283 if options.showratio:
287 if options.showratio:
289 dy = options.hrange/2
if options.hrange
else max(options.minrange/2.,8.*sy.getVal())
290 hmin = options.hmin
if options.hmin
is not None else my.getVal()-dy
291 hmax = options.hmax
if options.hmax
is not None else my.getVal()+dy
293 yframe = self.
protect( y.frame(hmin,hmax) )
294 if options.hnbins
is not None:
295 binning = ROOT.RooBinning(hmin, hmax)
296 binning.addUniform(options.hnbins, hmin, hmax)
297 data.plotOn(yframe,RooFit.Binning(binning))
298 ybinWidth = (hmax-hmin)/
float(options.hnbins)
301 ybinWidth = yframe.GetXaxis().GetBinWidth(1)
303 yframe.GetYaxis().SetTitle(
"Events / %1.0f #mum" %
round(1000.*ybinWidth,1))
304 yframe.GetYaxis().SetLabelSize(options.lsize)
305 yframe.GetYaxis().SetTitleSize(options.lsize)
308 cov = RooArgSet(vxx,vyy,vxy)
309 fitmodel.plotOn(yframe,RooFit.ProjWData(cov,data),
310 RooFit.NumCPU(options.nCpu))
313 fitmodel.plotOn(yframe,RooFit.ProjWData(cov,data),
314 RooFit.NumCPU(options.nCpu),
315 RooFit.LineStyle(RooFit.kDashed))
318 ROOT.gPad.SetLogy(options.logy)
321 if options.showratio:
325 if options.showratio:
327 dz = options.hrange/2
if options.hrange
else max(options.minrange/2.,8.*sz.getVal())
328 hmin = options.hmin
if options.hmin
is not None else mz.getVal()-dz
329 hmax = options.hmax
if options.hmax
is not None else mz.getVal()+dz
331 zframe = self.
protect( z.frame(hmin,hmax) )
332 if options.hnbins
is not None:
333 binning = ROOT.RooBinning(hmin, hmax)
334 binning.addUniform(options.hnbins, hmin, hmax)
335 data.plotOn(zframe,RooFit.Binning(binning))
336 zbinWidth = (hmax-hmin)/
float(options.hnbins)
339 zbinWidth = zframe.GetXaxis().GetBinWidth(1)
341 zframe.GetYaxis().SetLabelSize(options.lsize)
342 zframe.GetYaxis().SetTitleSize(options.lsize)
343 zframe.GetYaxis().SetTitle(
"Events / %1.0f mm" %
round(zbinWidth,1))
346 cov = RooArgSet(vxx,vyy,vxy)
347 fitmodel.plotOn(zframe,RooFit.ProjWData(cov,data),
348 RooFit.NumCPU(options.nCpu))
351 fitmodel.plotOn(zframe,RooFit.ProjWData(cov,data),
352 RooFit.NumCPU(options.nCpu),
353 RooFit.LineStyle(RooFit.kDashed))
356 ROOT.gPad.SetLogy(options.logy)
359 if options.showratio:
367 if cmdList[0] ==
'extract':
369 if not options.srcNtName:
370 parser.error(
'must specify --srcnt for extract command')
371 if not os.path.exists(options.srcNtName):
372 sys.exit(
'ERROR: source ROOT file %s not found' % options.srcNtName)
373 srcFile = ROOT.TFile(options.srcNtName)
374 srcNt = srcFile.Get(options.srcTreeName)
375 nEntries = srcNt.GetEntries()
376 print '\nCuts for extracting vertices from: %s:' % options.srcNtName
377 print ' %i <= LB <= %i' % (options.lbMin, options.lbMax)
379 print ' BCID == %i' % options.bcid
381 print ' vertex type == %i' % options.vType
383 print ' nTracks >= %i' % options.nTracks
385 print ' passed == %i' % options.passed
387 print ' chi2/ndf <= %s' % options.chi2ndf
389 print ' chi2prob >= %s' % options.chi2prob
390 if options.minvtxerr:
391 print ' transverse vertex errors >= %s' % options.minvtxerr
392 if options.maxvtxerr:
393 print ' transverse vertex errors < %s' % options.maxvtxerr
394 if options.rndFrac
is not None:
395 print ' using fraction %1.3f of selected vertices' % options.rndFrac
396 if options.nblk
is not None:
397 print ' using block %i of blocks of %i selected vertices' % (options.iblk,options.nblk)
399 print ' prescaling selected vertices by factor %i' % options.prescale
400 if options.xmin
is not None or options.xmax
is not None:
401 print ' %s <= x <= %s' % (options.xmin,options.xmax)
402 if options.ymin
is not None or options.ymax
is not None:
403 print ' %s <= y <= %s' % (options.ymin,options.ymax)
404 if options.zmin
is not None or options.zmax
is not None:
405 print ' %s <= z <= %s' % (options.zmin,options.zmax)
407 print '\nProcessing %i entries found in source ntuple ...' % nEntries
408 dstFile = ROOT.TFile(options.ntName,
'recreate')
409 dstNt = ROOT.TTree(options.ntTree,
'Vertices')
410 bx =
array(
'd',[0]); dstNt.Branch(
'x',bx,
'x/D')
411 by =
array(
'd',[0]); dstNt.Branch(
'y',by,
'y/D')
412 bz =
array(
'd',[0]); dstNt.Branch(
'z',bz,
'z/D')
413 bvxx =
array(
'd',[0]); dstNt.Branch(
'vxx',bvxx,
'vxx/D')
414 bvyy =
array(
'd',[0]); dstNt.Branch(
'vyy',bvyy,
'vyy/D')
415 bvxy =
array(
'd',[0]); dstNt.Branch(
'vxy',bvxy,
'vxy/D')
416 bvxz =
array(
'd',[0]); dstNt.Branch(
'vxz',bvxz,
'vxz/D')
417 bvyz =
array(
'd',[0]); dstNt.Branch(
'vyz',bvyz,
'vyz/D')
418 bvzz =
array(
'd',[0]); dstNt.Branch(
'vzz',bvzz,
'vzz/D')
421 if options.maxvtxerr:
422 maxVtxErr2 = options.maxvtxerr*options.maxvtxerr
423 if options.minvtxerr:
424 minVtxErr2 = options.minvtxerr*options.minvtxerr
425 for j
in xrange(nEntries):
427 if srcNt.lb < options.lbMin:
429 if srcNt.lb > options.lbMax:
431 if options.bcid
and srcNt.tck!=options.bcid:
433 if options.vType
and srcNt.vType!=options.vType:
435 if options.nTracks
and srcNt.nTracks<options.nTracks:
437 if options.passed
and srcNt.passed!=options.passed:
439 if options.chi2ndf
and srcNt.chi2/srcNt.ndf>options.chi2ndf:
444 if options.chi2prob
and ROOT.TMath.Prob(srcNt.chi2,
int(floor(srcNt.ndf+0.5)))<options.chi2prob:
446 if options.maxvtxerr
and (srcNt.vxx>=maxVtxErr2
or srcNt.vyy>=maxVtxErr2):
448 if options.minvtxerr
and (srcNt.vxx<minVtxErr2
or srcNt.vyy<minVtxErr2):
450 if options.xmin
is not None and srcNt.x<
float(options.xmin):
452 if options.xmax
is not None and srcNt.x>
float(options.xmax):
454 if options.ymin
is not None and srcNt.y<
float(options.ymin):
456 if options.ymax
is not None and srcNt.y>
float(options.ymax):
458 if options.zmin
is not None and srcNt.z<
float(options.zmin):
460 if options.zmax
is not None and srcNt.z>
float(options.zmax):
465 if options.rndFrac
is not None:
466 if random.random() > options.rndFrac:
468 if options.prescale
and (nSelected % options.prescale):
470 if options.nblk
is not None and not (options.iblk*options.nblk <= nSelected < (options.iblk+1)*options.nblk):
487 print '%i vertices selected, %i vertices after prescales and block selection written to %s\n' % (nSelected,nWritten,options.ntName)
493 from ROOT
import kTRUE
494 from ROOT
import RooFit, RooRealVar, RooDataSet, RooFormulaVar, RooArgList, RooArgSet
495 from ROOT
import RooAddPdf
501 x = RooRealVar(
"x",
"x [mm]",-3,3)
502 y = RooRealVar(
"y",
"y [mm]",-3,3)
503 z = RooRealVar(
"z",
"z [mm]",-300,300)
504 vxx = RooRealVar(
"vxx",
"vxx",-3,3)
505 vyy = RooRealVar(
"vyy",
"vyy",-3,3)
506 vxy = RooRealVar(
"vxy",
"vxy",-3,3)
507 vxz = RooRealVar(
"vxz",
"vxz",-3,3)
508 vyz = RooRealVar(
"vyz",
"vyz",-3,3)
509 vzz = RooRealVar(
"vzz",
"vzz",-3,3)
511 vtxDataFile = ROOT.TFile(options.ntName)
512 vtxData = vtxDataFile.Get(options.ntTree)
513 print '\nUsing %i input vertices from ntuple %s ...\n' % (vtxData.GetEntries(),options.ntName)
517 data = RooDataSet(
"data",
"data", vtxData, RooArgSet(x,y,z,vxx,vyy,vxy,vzz))
520 mx = RooRealVar(
"mx",
"Mean x", hx.GetMean(), -2, 2)
521 sx = RooRealVar(
"sx",
"Sigma x", hx.GetRMS(), 0, 1)
522 ax = RooRealVar(
"ax",
"Tilt x", 0, -1e-3, 1e-3)
523 my = RooRealVar(
"my",
"Mean y", hy.GetMean(), -2, 2)
524 sy = RooRealVar(
"sy",
"Sigma y", hy.GetRMS(), 0, 1)
525 ay = RooRealVar(
"ay",
"Tilt y", 0, -1e-3, 1e-3)
526 mz = RooRealVar(
"mz",
"Mean z", hz.GetMean(), -300, 300)
527 sz = RooRealVar(
"sz",
"Sigma z", hz.GetRMS(), 0, 100)
528 k = RooRealVar(
"k",
"Error scale factor", 1, 0.0, 3)
530 k.setVal(options.fixK)
532 rho = RooRealVar(
"rho",
"Correlation coefficient", 0, -1, 1)
535 f = RooRealVar(
"f",
"Fraction of 1st Gauss", 0.9, 0., 1)
536 mx2 = RooRealVar(
"mx2",
"Mean x", -0.05, -2, 2)
537 sx2 = RooRealVar(
"sx2",
"Sigma x", 0.10, 0, 1)
538 ax2 = RooRealVar(
"ax2",
"Tilt x", 0, -1e-3, 1e-3)
539 my2 = RooRealVar(
"my2",
"Mean y", 1, -2, 2)
540 sy2 = RooRealVar(
"sy2",
"Sigma y", 0.10, 0, 1)
541 ay2 = RooRealVar(
"ay2",
"Tilt y", 0, -1e-3, 1e-3)
542 mz2 = RooRealVar(
"mz2",
"Mean z", -3, -300, 300)
543 sz2 = RooRealVar(
"sz2",
"Sigma z", 60, 0, 100)
544 rho2 = RooRealVar(
"rho2",
"Correlation coefficient", 0, -1, 1)
547 mux = RooFormulaVar(
"mux",
"@0+@1*(@2-@3)",RooArgList(mx,ax,z,mz))
548 muy = RooFormulaVar(
"muy",
"@0+@1*(@2-@3)",RooArgList(my,ay,z,mz))
549 cxx = RooFormulaVar(
"cxx",
"@0*@0+@1*@1*@2",RooArgList(sx,k,vxx))
550 cxy = RooFormulaVar(
"cxy",
"@0*@1*@2+@3*@3*@4",RooArgList(rho,sx,sy,k,vxy))
551 cyy = RooFormulaVar(
"cyy",
"@0*@0+@1*@1*@2",RooArgList(sy,k,vyy))
552 czz = RooFormulaVar(
"czz",
"@0*@0",RooArgList(sz))
553 czzv = RooFormulaVar(
"czz",
"@0*@0+@1",RooArgList(sz,vzz))
556 mux2 = RooFormulaVar(
"mux2",
"@0+@1*(@2-@3)",RooArgList(mx2,ax,z,mz))
557 muy2 = RooFormulaVar(
"muy2",
"@0+@1*(@2-@3)",RooArgList(my2,ay,z,mz))
558 cxx2 = RooFormulaVar(
"cxx2",
"@0*@0+@1*@1*@2",RooArgList(sx2,k,vxx))
559 cxy2 = RooFormulaVar(
"cxy2",
"@0*@1*@2+@3*@3*@4",RooArgList(rho,sx2,sy2,k,vxy))
560 cyy2 = RooFormulaVar(
"cyy2",
"@0*@0+@1*@1*@2",RooArgList(sy2,k,vyy))
561 czz2 = RooFormulaVar(
"czz",
"@0*@0",RooArgList(sz))
565 dummyMatrix = ROOT.TMatrixDSym(3)
566 dummyMatrix[0][0] = 1
567 dummyMatrix[1][1] = 1
568 dummyMatrix[2][2] = 1
583 ROOT.gROOT.ProcessLine(
".L GenGauss3D.cxx+")
584 fitmodel = ROOT.GenGauss3D(
"fitmodel",
"Full beam spot PDF",
586 RooArgList(mux,muy,mz),
587 cxx,cxy,RooFit.RooConst(0),cyy,RooFit.RooConst(0),czz,
590 fitresult = fitmodel.fitTo(data,RooFit.ConditionalObservables(RooArgSet(vxx,vyy,vxy)),
591 RooFit.NumCPU(options.nCpu), RooFit.Timer(kTRUE), RooFit.Save())
596 ROOT.gROOT.ProcessLine(
".L BeamSpotPdf.cxx+")
597 fitmodel = ROOT.BeamSpotPdf(
"fitmodel",
"Full beam spot PDF",
598 x,y,z,vxx,vyy,vxy,mx,sx,ax,my,sy,ay,mz,sz,k,rho)
599 fitresult = fitmodel.fitTo(data,RooFit.ConditionalObservables(RooArgSet(vxx,vyy,vxy)),
600 RooFit.NumCPU(options.nCpu), RooFit.Timer(kTRUE), RooFit.Save())
603 if cmd ==
'stdfitvzz':
605 ROOT.gROOT.ProcessLine(
".L GenGauss3D.cxx+")
606 fitmodel = ROOT.GenGauss3D(
"fitmodel",
"Full beam spot PDF",
608 RooArgList(mux,muy,mz),
609 cxx,cxy,RooFit.RooConst(0),cyy,RooFit.RooConst(0),czzv,
611 fitresult = fitmodel.fitTo(data,RooFit.ConditionalObservables(RooArgSet(vxx,vyy,vxy,vzz)),
612 RooFit.NumCPU(options.nCpu), RooFit.Timer(kTRUE), RooFit.Save())
617 ROOT.gROOT.ProcessLine(
".L GenGauss3D.cxx+")
618 ROOT.gROOT.ProcessLine(
".L GenGauss3Dclone.cxx+")
619 g1 = ROOT.GenGauss3D(
"g1",
"Full beam spot PDF",
621 RooArgList(mux,muy,mz),
622 cxx,cxy,RooFit.RooConst(0),cyy,RooFit.RooConst(0),czz,
624 g2 = ROOT.GenGauss3Dclone(
"g2",
"Full beam spot PDF",
626 RooArgList(mux,muy,mz),
627 cxx2,cxy2,RooFit.RooConst(0),cyy2,RooFit.RooConst(0),czz2,
630 fitmodel = RooAddPdf(
"fitmodel",
"sum",g1,g2,f)
632 fitresult = fitmodel.fitTo(data,RooFit.ConditionalObservables(RooArgSet(vxx,vyy,vxy)),
633 RooFit.NumCPU(options.nCpu), RooFit.Timer(kTRUE), RooFit.Save())
638 plots =
Plots(whatList = [
'x',
'y',
'z'])
639 plots.saveAsList = options.output.split(
',')
640 plots.gPadSaveAsList = options.output.split(
',')
641 plots.genPlot(options.plot)
643 if cmd==
'plotx' or cmd==
'ploty' or cmd==
'plotz':
646 plots.saveAsList = options.output.split(
',')
647 plots.genPlot(cmd[-1])
651 plots =
Plots(whatList = [
'x',
'y',
'z'])
652 plots.saveAsList = [
'%s-data%s' % (options.name,ext)
for ext
in options.output.split(
',')]
654 plots.genPlot(options.plot,
'hist')
658 plots =
Plots(whatList = [
'vxx',
'vxy',
'vxz',
None,
'vyy',
'vyz',
None,
None,
'vzz'])
659 plots.allCanvasDivs = (3,3)
660 plots.saveAsList = [
'%s-cov%s' % (options.name,ext)
for ext
in options.output.split(
',')]
662 plots.genPlot(options.plot,
'hist')
666 plots =
Plots(whatList = [
'sqrt(vxx)',
'sqrt(vyy)',
'sqrt(vzz)'])
667 plots.allCanvasSize =
'wide'
668 plots.allCanvasDivs = (3,1)
669 plots.saveAsList = [
'%s-vtxerr%s' % (options.name,ext)
for ext
in options.output.split(
',')]
671 plots.genPlot(options.plot,
'hist')
673 if cmd ==
'vtxerrxy':
675 plots =
Plots(whatList = [
'sqrt(vxx)',
'sqrt(vyy)'])
676 plots.allCanvasSize =
'wide'
677 plots.allCanvasDivs = (2,1)
678 plots.saveAsList = [
'%s-vtxerr%s' % (options.name,ext)
for ext
in options.output.split(
',')]
680 plots.genPlot(options.plot,
'hist')
686 print 'ERROR: unknown command: %s' % cmd