예제 #1
0
    def run(self, **kwargs):
        from ROOT import RooArgSet

        __check_req_kw__("Observables", kwargs)
        __check_req_kw__("Pdf", kwargs)
        __check_req_kw__("Sigmat", kwargs)
        __check_req_kw__("Time", kwargs)
        __check_req_kw__("SigmaGen", kwargs)
        sigma_gen = kwargs.pop("SigmaGen")
        observables = kwargs.pop("Observables")
        obs_set = RooArgSet(*observables)

        pdf = kwargs.pop("Pdf")
        sigmat = kwargs.pop("Sigmat")
        time = kwargs.pop("Time")

        gen_obs_set = RooArgSet(*observables)

        # Make another ArgSet to put the fit results in
        result_params = RooArgSet("result_params")

        from P2VV.RooFitWrappers import RealVar

        da = RealVar("da", Observable=True, MinMax=(0.01, 1.1))
        dft = RealVar("dft", Observable=True, MinMax=(0.01, 1.1))
        result_params.add(da._target_())
        result_params.add(dft._target_())

        transform = self.transform()
        if transform:
            trans_params = transform.gen_params(gen_obs_set)
            self._gen_params.extend(trans_params)
            for p in trans_params:
                result_params.add(p)

        # Some extra numbers of interest
        from ROOT import RooRealVar

        seed = RooRealVar("seed", "random seed", 0.0)
        result_params.add(seed)

        # The dataset to store the results
        from ROOT import RooDataSet

        self._data = RooDataSet("result_data", "result_data", result_params)
        data_params = self._data.get()

        from ROOT import RooRandom
        import struct, os

        # Reset pdf parameters to initial values. Note: this does not reset the estimated errors...
        args = dict(NumEvents=self.options().nevents)
        if "ProtoData" in kwargs:
            args["ProtoData"] = kwargs.pop("ProtoData")
        spec = pdf.prepareMultiGen(obs_set, **args)

        while self._data.numEntries() < self.options().ntoys:
            # Get a good random seed, set it and store it
            s = struct.unpack("I", os.urandom(4))[0]
            RooRandom.randomGenerator().SetSeed(s)
            seed.setVal(s)

            data = pdf.generate(spec)
            if self.transform():
                old_data = data
                data = self.transform()(old_data)
                if not data:
                    transform.set_params(data_params)
                    self._data.add(data_params)
                    continue

            from P2VV import Dilution

            d_ft = Dilution.dilution_ft(data, time, t_range=2, quiet=True)
            d_a = Dilution.signal_dilution_dg(data, sigmat, *sigma_gen)
            da.setVal(d_a[0])
            da.setError(d_a[1] if d_a[1] != None else 0.0)
            dft.setVal(d_ft[0])
            dft.setError(d_ft[1] if d_ft[1] != None else 0.0)

            if transform:
                transform.set_params(data_params)

            self._data.add(result_params)

        return self.data()
예제 #2
0
# angular functions
if transAngles :
    from P2VV.Parameterizations.AngularFunctions import JpsiphiTransversityAngles as AngleFuncs
    angleFuncs = AngleFuncs( cpsi = 'trcospsi', ctheta = 'trcostheta', phi = 'trphi' )
else :
    from P2VV.Parameterizations.AngularFunctions import JpsiphiHelicityAngles as AngleFuncs
    angleFuncs = AngleFuncs( cpsi = 'helcosthetaK', ctheta = 'helcosthetaL', phi = 'helphi' )
    #angleFuncs = AngleFuncs( cpsi = 'ctkRecoLHCb', ctheta = 'ctlRecoLHCb', phi = 'phiRecoLHCb' )
    #angleFuncs = AngleFuncs( cpsi = 'ctkTrueCalc', ctheta = 'ctlTrueCalc', phi = 'phiTrueCalc' )

# variables in PDF
from P2VV.RooFitWrappers import RealVar, Category
time      = RealVar(  'time',      Title = 'Decay time',      Unit = 'ps', Observable = True, Value = 0.5,  MinMax = ( 0.3,    14.  ) )
trueTime  = RealVar(  'truetime',  Title = 'True decay time', Unit = 'ps', Observable = True, Value = 0.,   MinMax = ( 0.,     20.  ) )
sigmat    = RealVar(  'sigmat',    Title = 'Time resolution', Unit = 'ps', Observable = True, Value = 0.01, MinMax = ( 0.0001, 0.12 ) )
iTag      = Category( 'iTag',      Title = 'Initial state flavour tag', Observable = True, States = { 'Untagged' : 0 } )
runPeriod = Category( 'runPeriod', Title = 'Running period',            Observable = True, States = runPeriodStates )
KKMassCat = Category( 'KKMassCat', Title = 'KK-mass category',          Observable = True, States = KKMassStates )
angles    = [ angleFuncs.angles['cpsi'], angleFuncs.angles['ctheta'], angleFuncs.angles['phi'] ]
if weightVar :
    weight = RealVar( weightVar, Title = 'Signal weight', Observable = True, Value = 1. )

sigmat.setBins( 40, 'cache' )

obsSet = [ time if tResModel in [ 'Gauss', '3fb' ] else trueTime ] + angles + [ runPeriod, KKMassCat ]
if tResModel == '3fb' : obsSet.append(sigmat)
if tResPars : obsSet.append(runPeriod)
if SWaveAmps : obsSet.append(KKMassCat)
if weightVar : obsSet.append(weight)
예제 #3
0
            , decTimeRes  = 'B_s0_LOKI_DTF_CTAUERR/0.299792458 < 0.12'
            , HLT1        = '(B_s0_Hlt1DiMuonHighMassDecision_TOS == 1 || B_s0_Hlt1TrackMuonDecision_TOS == 1 || B_s0_Hlt1TrackAllL0Decision_TOS == 1)'
            , HLT2        = '(B_s0_Hlt2DiMuonJPsiDecision_TOS == 1 || B_s0_Hlt2DiMuonDetachedJPsiDecision_TOS == 1)'
           )
cutCombs = dict(  none    = [ 'psiKKMass' ]
                , trigger = [ 'psiKKMass', 'HLT1', 'HLT2' ]
                , KKPT    = [ 'psiKKMass', 'HLT1', 'HLT2', 'KKPT' ]
                , vertex  = [ 'psiKKMass', 'HLT1', 'HLT2', 'KKPT', 'psiKKVertex' ]
                , time    = [ 'psiKKMass', 'HLT1', 'HLT2', 'KKPT', 'psiKKVertex', 'decTime' ]
                , all     = [ name for name in cuts.keys() ]
               )

from ROOT import TFile
from P2VV.RooFitWrappers import RooObject, RealVar
ws = RooObject(workspace = 'JpsiphiWorkspace').ws()
mass = RealVar( Name = 'mass', Title = 'm(J/psiKK)', MinMax = ( massRange[0], massRange[1] ), Observable = True )
if not readData :
    print 'reading file "%s"' % DTTPath
    DTTFile = TFile.Open(DTTPath)
    DTT = DTTFile.Get(treeName)
    
    print 'create mass datasets'
    from ROOT import RooDataSet, RooArgSet, RooRealVar, gDirectory
    from P2VV.RooFitWrappers import __dref__
    massSet = RooArgSet( __dref__(mass) )
    dataSets = { }
    import sys
    for key, comb in cutCombs.iteritems() :
        print '--> creating dataset for "%s" selection' % key
        DTT.Draw( '>>selList', ' && '.join( cuts[cutName] for cutName in comb ), 'entrylist' )
        selList = gDirectory.Get('selList')
예제 #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
예제 #5
0
from P2VV.RooFitWrappers import RooObject
ws = RooObject( workspace = 'JpsiphiWorkspace' ).ws()

# read data set from file
from P2VV.Utilities.DataHandling import readData
if drawTotalDists:
    data = readData( filePath = dataSetFile, dataSetName = 'JpsiKK', NTuple = False )
    data = data.reduce('hlt2_biased==1 && mass>5338. && mass<5398.')
    data.Print()
sigData = readData( filePath = dataSetFile, dataSetName = 'JpsiKK_sigSWeight', NTuple = False )
sigData = sigData.reduce('hlt2_biased==1')
sigData.Print()

# get observables
from P2VV.RooFitWrappers import RealVar
mumuMass = RealVar('mdau1')
KKMass   = RealVar('mdau2')

# LHCb label
labelText = '' # 'LHCb'
if labelText :
    from ROOT import TLatex
    label = TLatex()
    label.SetTextAlign(12)
    label.SetTextSize(0.072)


###########################################################################################################################################
## Make mumu mass plots ##
##########################
예제 #6
0
ws = RooObject( workspace = 'JpsiphiWorkspace' ).ws()

from ROOT import TFile, RooDataSet, TObject
from P2VV.RooFitWrappers import __dref__
if createDataSets :
    # read data set from file
    dataFile = TFile.Open(dataSetFileIn)
    dataSet = dataFile.Get(dataSetName)
    dataFile.Close()
    dataSet.Print()

    # get set of observables in data set
    from ROOT import RooArgSet
    from P2VV.RooFitWrappers import RealVar, Category
    obsSet = RooArgSet( dataSet.get() )
    sigWeight  = RealVar( Name = 'sigWeight',  Value = 1. )
    dilution = RealVar( Name = 'dilution', Value = 1. )
    asymCat = Category( Name = 'asymCat', States = dict( plus = +1, minus = -1 ) )
    obsSet.add( __dref__(sigWeight)  )
    obsSet.add( __dref__(dilution) )
    obsSet.add( __dref__(asymCat)    )
    if applyAngWeights :
        angWeight = RealVar( Name = 'angWeight_%s' % applyAngWeights, Value = 1. )
        obsSet.add( __dref__(angWeight)  )

    # create data set with events in two asymmetry categories
    print 'plotAsymmetry: creating dataset with events in two asymmetry categories'
    dataSetAsym = RooDataSet( 'asymData', 'asymData', obsSet )
    from math import exp
    for evSet in dataSet :
        # get dilution from resolution