Exemplo n.º 1
0
def __find_param(var, input_cats, split_pars_dict, split_cat_pars):
    from P2VV.RooFitWrappers import RooObject
    ws = RooObject.ws()
    split_cats = split_pars_dict.get( ws[ var.GetName() ], set() )
    if not var.isFundamental() :
        split = False
        for splVar, splCats in split_pars_dict.iteritems() :
            if var.dependsOn(splVar) : split = True
            split_cats |= splCats
        if not split : split_cats = set()
    if not split_cats :
        return var
    else :
        catLabels = [(cat.GetName(), cat.getLabel()) for cat in input_cats if cat in split_cats]
        catsStr = ';'.join(lab[1] for lab in catLabels)
        if len(catLabels) > 1 : catsStr = '{' + catsStr + '}'
        from P2VV.Utilities.General import getSplitPar
        splitVar = getSplitPar(var.GetName(), catsStr, split_cat_pars)
        assert splitVar, 'P2VV - ERROR: Bs2Jpsiphi_PdfBuilder: parameter "%s" is set to be constrained for category "%s", but it is not found in PDF'\
               % (var.GetName(), catsStr)
        from ROOT import RooRealVar, RooCategory, RooFormulaVar
        from P2VV.RooFitWrappers import RealVar, Category, FormulaVar
        wrappers = { RooRealVar : RealVar, RooCategory : Category, RooFormulaVar : FormulaVar }
        assert type(splitVar) in wrappers\
               , 'P2VV - ERROR: Bs2Jpsiphi_PdfBuilder: wrapping of RooFit object "%s" of type "%s" not implemented (yet)'\
                 % ( splitVar.GetName(), type(splitVar) )
        return wrappers[ type(splitVar) ]( Name = splitVar.GetName() )
Exemplo n.º 2
0
###########################################################################################################################################
## read data ##
###############

from P2VV.Load import RooFitOutput, LHCbStyle

# create list of required observables
reqObsList  = [ 'index', 'runPeriod', 'mass', 'KKMass', 'tagDecOS', 'tagDecSS', 'wTagOS', 'wTagSS', 'hlt1ExclB', 'hlt2B' ]
reqObsList += [ args.weightIn ] if args.weightIn else [ ]
reqObsList += [ '%s_P%s' % ( part, comp ) for part in [ 'Kplus', 'Kminus', 'muplus', 'muminus' ] for comp in ( 'X', 'Y', 'Z' ) ]\
              if addMomenta else [ ]

# create workspace
from P2VV.RooFitWrappers import RooObject
ws = RooObject(workspace = 'JpsiKKWS').ws()

# create observables
from P2VV.RooFitWrappers import RealVar, Category
observables  = { }
observables['index'] = RealVar( 'index', Title = 'event index', Observable = True, Value = 0., MinMax = ( -RooInf, +RooInf ) )
obsSetPreDS  = [ observables['index'] ]
if args.weightIn :
    observables[args.weightIn] = RealVar( args.weightIn, Title = 'weight', Observable = True, Value = 0., MinMax = ( -RooInf, +RooInf ) )
    obsSetPreDS.append( observables[args.weightIn] )
obsSetNTuple = [ ]
for obs in obsKeys + reqObsList :
    if obs in observables : continue
    if obs == 'KKMassCat' : continue

    if type( obsDict[obs][2] ) == dict or type( obsDict[obs][2] ) == list :
Exemplo n.º 3
0

###########################################################################################################################################
## read data ##
###############

from P2VV.Load import RooFitOutput, LHCbStyle

# create list of required observables
reqObsList = [ 'index', 'mass', 'KKMass', 'tagDecOS', 'tagDecSS', 'wTagOS', 'wTagSS' ]
reqObsList += ['runPeriod'] if runPeriods else [ ]
reqObsList += ['hlt1ExclB'] if triggerSel == 'paper2012' else [ 'hlt1ExclB', 'hlt2B' ] if triggerSel == 'timeEffFit' else [ ]

# create workspace
from P2VV.RooFitWrappers import RooObject
ws = RooObject(workspace = 'JpsiphiWorkspace').ws()

# create observables
from P2VV.RooFitWrappers import RealVar, Category
observables  = { }
observables['index'] = RealVar( 'index', Title = 'event index', Observable = True, Value = 0., MinMax = ( -RooInf, +RooInf ) )
obsSetPreDS  = [ observables['index'] ]
obsSetNTuple = [ ]
for obs in obsKeys + reqObsList :
    if obs in observables : continue

    if obs.startswith('sigWeight') :
        observables[obs] = RealVar( obs, Title = 'signal sWeight', Observable = True, Value = 1. )

    elif type( obsDict[obs][2] ) == dict or type( obsDict[obs][2] ) == list :
        observables[obs] = Category( obsDict[obs][0], Title = obsDict[obs][1], Observable = True, States = obsDict[obs][2] )
Exemplo n.º 4
0
nEvents = 20000
nIters  = 1

# create workspace and observable
from P2VV.RooFitWrappers import RooObject, RealVar
ws = RooObject(workspace = 'momentsWS').ws()
obs = RealVar( Name = 'x', Value = 0., MinMax = ( -1., +1. ) )
weight = RealVar( Name = 'weight', Value = 0. )
ws.defineSet( 'obsSet', 'x' )
ws.defineSet( 'obsWSet', 'x,weight' )
obsSet = ws.set('obsSet')
obsWSet = ws.set('obsWSet')

# build some functions
from math import pi
funcNames = [ 'one', 'cos', 'sin', 'sin2' ]
funcMeans = { 'one' : 1., 'cos' : 1. / 3., 'sin' : pi / 4., 'sin2' : pi / 8. }

ws.factory('Legendre::one(x,0,0)')                        # 1
ws.factory('Legendre::cos(x,1,0)')                        # x = cos(theta)
ws.factory('prod::sin(minus[-1.],Legendre::P11(x,1,1))')  # sqrt(1 - x^2) = sin(theta)
ws.factory('prod::sin2(min23[0.],Legendre::P21(x,2,1))')  # 2x * sqrt(1 - x^2) = sin(2*theta)
ws['min23'].setVal( -2. / 3. )

# create data sets
from ROOT import RooDataSet
noWeightData = RooDataSet( 'noWeightData', 'noWeightData', obsSet            )
weightData   = RooDataSet( 'weightData',   'weightData',   obsWSet, 'weight' )

# build moments builders
from P2VV.Utilities.DataMoments import RealMomentsBuilder
Exemplo n.º 5
0
# 2nd GExp
rlife2 = RooRealVar("rlife2", "rlife2", 6.07734, 0.1, 10)
gexp2 = RooGExpModel("gexp2", "gexp2", t_diff_st, mean_gexp, sigma_gexp, rlife2, one, one, one, False, RooGExpModel.Flipped)

frac_gexp2 = RooRealVar("frac_gexp2", "frac_gexp2", 0.184357, 0.01, 0.99)
gexps = RooAddPdf("gexps", "gexps", RooArgList(gexp2, gexp1), RooArgList(frac_gexp2))

frac_gexps = RooRealVar("frac_gexps", "frac_gexps", 0.0118392, 0.001, 0.99)
model = RooAddPdf("model", "model", RooArgList(gexps, gaussians), RooArgList(frac_gexps))
model.setParameterizeIntegral(RooArgSet(st))


from P2VV import RooFitDecorators
from ROOT import RooWorkspace
from P2VV.RooFitWrappers import RooObject
obj = RooObject(workspace = 'w')
w = obj.ws()
w.put(model)
w.put(sdata)

from ROOT import TPaveText
if options.momentum_calib:
    year_label = TPaveText(0.71, 0.32, 0.89, 0.45, "NDC")
else:
    year_label = TPaveText(0.71, 0.72, 0.89, 0.85, "NDC")

year_label.SetFillColor(0)
pos = args[0].find('201')
year_label.AddText(args[0][pos : pos + 4])
year_label.SetBorderSize(0)
Exemplo n.º 6
0
print '  dataset file: ' + dataSetFilePath
print '  parameter file: ' + parFilePath
print '  apply plot weights: %s' % ( 'yes' if applyPlotWeights else 'no' )
print '  blinded parameters: %s' % ', '.join( par for par in blindVars )
print '  Deltam = %.5f / ps' % Deltam
print '  oscillation period = %.3f ps' % oscPeriod
print '  total number of time bins: %d' % numTimeBinsTot
print '  time bins: %s' % ', '.join( '%d' % bin for bin in timeBins )
print '  periods: %s' % ', '.join( '%d' % per for per in periods )
print '  time offset (bins) = %.3f' % binOffset
print '  PDF time points: %s' % ', '.join( '%.2f' % frac for frac in timeFracs )
print '  output file: ' + pdfValsFilePath

# workspace
from P2VV.RooFitWrappers import RooObject
ws = RooObject( workspace = 'JpsiphiWorkspace' ).ws()

# read data set with events in two asymmetry categories
print 'pdfAsymmetry: reading dataset with events in two asymmetry categories'
from ROOT import TFile
dataFile = TFile.Open(dataSetFilePath)
dataSetAsym = dataFile.Get('asymData')
dataFile.Close()
dataSetAsym.Print()

# create weighted data set
from ROOT import RooProduct, RooArgSet, RooArgList
obsSet = RooArgSet( dataSetAsym.get() )
prodList = RooArgList( obsSet.find('sigWeight') )
if applyPlotWeights : prodList.add( obsSet.find('dilution') )
weightVar = RooProduct( 'weightVar', 'weightVar', prodList )
Exemplo n.º 7
0
condObsVars = dict(  runPeriod = ( 'runPeriod', )
                   , HLT1Cat   = ( 'hlt1_excl_biased', )
                   , KKMass    = ( 'mdau2', )
                   , sigmat    = ( 'sigmat', )
                   , etaTag    = ( 'tagomega_os_cb', 'tagomega_ss_nn' )
                   , OSSSTagEq = ( 'iTagOS', 'iTagSS' )
                  )


###########################################################################################################################################
## build J/psiKK mass PDF ##
############################

# create workspace
from P2VV.RooFitWrappers import RooObject
ws = RooObject( workspace = 'JpsiKKWS' ).ws()

# read data set
from P2VV.Utilities.DataHandling import readData
dataSet = readData( filePath = args.dataPathIn, dataSetName = args.datasetName,  NTuple = False )

# get observables
from P2VV.RooFitWrappers import RealVar, Category
observables = dict( mass = RealVar('mass'), runPeriod = Category('runPeriod'), KKMassCat = Category('KKMassCat') )

# initialize PDF components
from P2VV.RooFitWrappers import Component
nSig = dataSet.sumEntries()
nTot = float( dataSet.numEntries() )
sigMassComps  = Component( 'sigMass',  [ ], Yield = ( nSig,        0., nTot ) )
cbkgMassComps = Component( 'cbkgMass', [ ], Yield = ( nTot - nSig, 0., nTot ) )