Exemplo n.º 1
0
def grabResult(isData, isBlind, filename):
    from B2DXFitters.FitResult import getDsHBlindFitResult
    from ROOT import TFile, RooFitResult, TClass
    import gc
    f = TFile(filename, "READ")
    # try to read cFit style fitresult
    for key in f.GetListOfKeys():
        if not TClass.GetClass(key.GetClassName()).InheritsFrom('RooFitResult'):
            continue
        fitresult = key.ReadObj()
        ROOT.SetOwnership(fitresult, True)
        retVal = getDsHBlindFitResult(isData, isBlind, fitresult)
        del fitresult
        f.Close()
        del f
        # make sure we don't run out of memory
        gc.collect()
        return retVal
    # ok, not successful, try sFit next
    for key in f.GetListOfKeys():
        if not TClass.GetClass(key.GetClassName()).InheritsFrom('RooWorkspace'):
            continue
        ws = key.ReadObj()
        if None == ws: continue
        ROOT.SetOwnership(ws, True)
        # ok, get list of objects in the workspace, and try to get a
        # RooFitResult from it
        l = ws.allGenericObjects()
        ROOT.SetOwnership(l, True)
        while not l.empty():
            obj = l.front()
            if None == obj or not obj.InheritsFrom('RooFitResult'):
                l.pop_front()
                continue
            retVal = getDsHBlindFitResult(isData, isBlind, obj)
            del obj
            del l
            del ws
            f.Close()
            del f
            # make sure we don't run out of memory
            gc.collect()
            return retVal
    # make sure we don't run out of memory
    gc.collect()
    return None
Exemplo n.º 2
0
    fitopts.append(
        RooFit.Verbose(not (config['IsData'] and config['Blinding'])))
    if config['IsData'] and config['Blinding']:
        from ROOT import RooMsgService
        RooMsgService.instance().setGlobalKillBelow(RooFit.WARNING)
        fitopts.append(RooFit.PrintLevel(-1))
    fitOpts = RooLinkedList()
    for o in fitopts:
        fitOpts.Add(o)

    # fit
    rawfitresult = fitpdf['pdf'].fitTo(tupleDataSet, fitOpts)

    # pretty-print the result
    from B2DXFitters.FitResult import getDsHBlindFitResult
    result = getDsHBlindFitResult(config['IsData'], config['Blinding'],
                                  rawfitresult)
    print result
    '''
    doubleCanvas = TCanvas();
        
    frameList = []
    print '\n\n',tupleDict.values(),'\n\n'

    doubleCanvas.Divide(3,3,0,0)

    for i in range(len(tupleDict)):
        #varName = tupleDict.keys()[i];
        frameList += [tupleDataSet.get().find(tupleDict.values()[i]).frame()];
        tupleDataSet.plotOn(frameList[i], RooFit.DrawOption('b'));
        doubleCanvas.cd(i+1);
        frameList[i].Draw();
Exemplo n.º 3
0
    RooFit.Offset(config['FitConfig']['Offset']),
    RooFit.NumCPU(config['FitConfig']['NumCPU']) ]

# set up blinding for data
fitopts.append(RooFit.Verbose(not (config['IsData'] and config['Blinding'])))
if config['IsData'] and config['Blinding']:
    from ROOT import RooMsgService
    RooMsgService.instance().setGlobalKillBelow(RooFit.WARNING)                                                                                                                             
    fitopts.append(RooFit.PrintLevel(-1))
fitOpts = RooLinkedList()
for o in fitopts: fitOpts.Add(o)

# fit
rawfitresult = fitpdf.fitTo(ds, fitOpts)

# pretty-print the result
from B2DXFitters.FitResult import getDsHBlindFitResult
result = getDsHBlindFitResult(config['IsData'], config['Blinding'],
    rawfitresult)
print result

# write raw fit result and workspace to separate ROOT files
from ROOT import TFile
f = TFile('fitresult001-%04d.root' % SEED, 'recreate')
f.WriteTObject(rawfitresult, 'fitresult001_%04d' % SEED)
f.Close()
del f
ws.writeToFile('workspace001_%04d.root' % SEED, True)

# all done