Ejemplo n.º 1
0
## 3. Use data 1 to build Keys PDF k1(x|s1,m1)
k = KeysPdf('k', 'k', x, data1, KeysPdf.NoMirror, 2)

## 4. Use k to build HistPDF with _transformed_ x variable t = (x-m)/s
##    h1((x-hm)/hs|m1,s1)
t = w.factory('FormulaVar::t("(x - hm) / hs", {x, hm[0,-5,5], hs[1,0.1,3]})')
hist = k.createHistogram('x', 10000)
dh = DataHist('dh', 'dh', ArgList(x), hist)
h = HistPdf('h', 'h', ArgList(t), ArgList(x), dh, 2)

## 5. Plot results
f1 = x.frame()
f1.SetTitle('Training Data')
data1.plotOn(f1)
g.plotOn(f1)
k.plotOn(f1, LineColor(kRed), LineStyle(kDashed))
h.plotOn(f1, LineColor(kBlack), LineStyle(kDashed))
canvases.next('Training_Data')
f1.Draw()

## 6. Fit h1 to data2 to simulate a "measurement" of m2, s2.
h.fitTo(data2)

f2 = x.frame()
f2.SetTitle('Test Data')
data2.plotOn(f2)
h.plotOn(f2)
h.paramOn(f2)
canvases.next('Test_Data')
f2.Draw()
## Find the mode of the tmodel.
mmgMode.setVal(modelHist.GetBinCenter(modelHist.GetMaximumBin()))
mmgMode.setConstant(True)
fPho.setConstant(True)

## Fit the photon scale
phoScale.setConstant(False)
mmgScale.setConstant(True)

## Make plots
canvases.next('nominal')
mmgFrame = mmgMass.frame(Range(60,120))
mmgData.plotOn(mmgFrame)
phoScale.setVal(0)
model.plotOn(mmgFrame)
tmodel.plotOn(mmgFrame, LineStyle(kDashed), LineColor(kRed))
mmgFrame.Draw()

## Get the test datasets and models
dataCollection = []
models = []
sFitted = []
sFittedErr = []
for i, (fac, s) in enumerate(zip(fTest, sTest)):
    mmgMass.SetTitle('scaledMmgMass3(%f, mmgMass, mmMass)' % fac)
    phoPtRangeMod = (phoPtRange[0] * fac, phoPtRange[1] * fac)
    cutsMod = cuts[:] + ['%f < phoPt & phoPt < %f' % phoPtRangeMod]
    data = dataset.get(variable=mmgMass, cuts=cutsMod)
    ## Import the data in the workspace
    data.SetName('data%d' % i)