コード例 #1
0
ファイル: variables.py プロジェクト: OstapHEP/ostap
def two_yields(total, fraction):
    """Construct two yields from the total yield and fraction
    >>> total = ...
    >>> fraction = ...
    >>> y1 , y2 = two_yields ( total , fraction )
    """
    var1 = total
    var2 = fraction

    vnames = var1.name, var2.name

    name = 'Yield1_%s_%s' % vnames
    title = 'Yield1 (%s) and (%s)' % vnames

    yield1 = scale_var(total, fraction, name, title)

    name = 'Yield2_%s_%s' % vnames
    title = 'Yield2 (%s) and (%s)' % vnames

    formula = '(%s)*(1-(%s))' % vnames
    varlist = ROOT.RooArgList(var1, var2)
    yield2 = Ostap.FormulaVar(name, title, formula, varlist)

    yield2._varlist = [var1, var2, varlist]

    return yield1, yield2
コード例 #2
0
def var_from_name ( w , varset ) :
    """ Convert name/expression into variable/formula
    """
    w = w.strip() 
    if    0 <= w.find('(') < what.find(')') : pass
    elif  0 <  w.find('*')                  : pass
    elif  0 <  w.find('/')                  : pass
    elif  0 <  w.find('%')                  : pass 
    elif  0 <  w.find('+')                  : pass
    elif  0 <  w.find('-')                  : pass
    else :
        v = varset[w]
        return v
    ##
    
    vlst = ROOT.RooArgList()
    for s in varset : vlst.add ( s )
    #
    f = Ostap.FormulaVar( w , w , vlst )
    return f 
コード例 #3
0
ファイル: specific.py プロジェクト: OstapHEP/ostap
    def __init__(self,
                 mass,
                 name='Y',
                 power=0,
                 m1s=None,
                 sigma=None,
                 alphaL=1.5462,
                 alphaR=1.6952,
                 nL=1.3110,
                 nR=1.5751e+01):

        #
        PDF.__init__(self, name, mass)
        #
        if 9460. in self.mass and 10023. in self.mass and 10355. in self.mass:
            gev_ = 1000
        elif 9.460 in self.mass and 10.023 in self.mass and 10.355 in self.mass:
            gev_ = 1
        else:
            raise AttributeError("Illegal mass range %s<m<%s" % self.xminmax())

        m_y1s = 9.46030 * gev_
        s_y1s = 4.03195e-02 * gev_
        dm_y2s = 10.02326 * gev_ - m_y1s
        dm_y3s = 10.3552 * gev_ - m_y1s

        # =====================================================================

        # =====================================================================
        ## Y(1S)
        # =====================================================================
        self.__aL = self.make_var(alphaL, "aL_%s" % name,
                                  "#alpha_{L}(%s)" % name, alphaL, 1.5462, 0.1,
                                  10)
        self.__nL = self.make_var(nL, "nL_%s" % name, "n_{L}(%s)" % name, nL,
                                  1.3119, 1.e-5, 25)
        self.__aR = self.make_var(alphaR, "aR_%s" % name,
                                  "#alpha_{R}(%s)" % name, alphaR, 1.6952e+00,
                                  0.1, 10)
        self.__nR = self.make_var(nR, "nR_%s" % name, "n_{R}(%s)" % name, nR,
                                  1.5751e+01, 1.e-5, 25)

        self.__m1s = self.make_var(m1s, "m1S_%s" % name, "mass Y1S(%s)" % name,
                                   m1s, m_y1s, m_y1s - 0.15 * s_y1s,
                                   m_y1s + 0.15 * s_y1s)

        self.__s1s = self.make_var(sigma, "s1S_%s" % name,
                                   "sigma Y1S(%s)" % name, sigma, s_y1s,
                                   0.3 * s_y1s, 4 * s_y1s)
        self.__sigma = self.__s1s

        self.__Y1S = CB2_pdf(name + '1S',
                             xvar=self.mass,
                             mean=self.__m1s,
                             sigma=self.__s1s,
                             alphaL=self.__aL,
                             alphaR=self.__aR,
                             nL=self.__nL,
                             nR=self.__nR)

        # =====================================================================
        ## Y(2S)
        # =====================================================================
        self.__dm2s = self.make_var(None, "dm2s" + name, "dm2s(%s)" % name,
                                    dm_y2s, dm_y2s - 0.20 * s_y1s,
                                    dm_y2s + 0.20 * s_y1s)

        self.__aset11 = ROOT.RooArgList(self.__m1s, self.__dm2s)

        ## self.__m2s    = ROOT.RooFormulaVar (
        ##     "m_" + name + '2S'   ,
        ##     "m2s(%s)"  % name    ,
        ##     "%s+%s" % ( self.__m1s.GetName() , self.__dm2s.GetName()  ) ,
        ##    self.__aset11       )
        self.__m2s = Ostap.MoreRooFit.Addition("m_" + name + '2S',
                                               "m2s(%s)" % name, self.__m1s,
                                               self.__dm2s)

        self.__aset12 = ROOT.RooArgList(self.__sigma, self.__m1s, self.__m2s)
        self.s2s = Ostap.FormulaVar(
            "sigma_" + name + '2S', "#sigma_{Y2S}(%s)" % name,
            "%s*(%s/%s)" % (self.__sigma.GetName(), self.__m2s.GetName(),
                            self.__m1s.GetName()), self.__aset12)

        self.__Y2S = CB2_pdf(name + '2S',
                             xvar=self.mass,
                             mean=self.__m2s,
                             sigma=self.__s2s,
                             alphaL=self.__aL,
                             alphaR=self.__aR,
                             nL=self.__nL,
                             nR=self.__nR)

        # =====================================================================
        ## Y(3S)
        # =====================================================================
        self.__dm3s = self.make_var(None, "dm3s" + name, "dm3s(%s)" % name,
                                    dm_y3s, dm_y3s - 0.20 * s_y1s,
                                    dm_y3s + 0.20 * s_y1s)

        self.__aset21 = ROOT.RooArgList(self.__m1s, self.__dm3s)
        ## self.__m3s    = ROOT.RooFormulaVar (
        ##    "m_"       + name + '(3S)' ,
        ##    "m3s(%s)"  % name          ,
        ##    "%s+%s" % ( self.__m1s.GetName() , self.__dm3s.GetName() ) ,
        ##    self.__aset21       )
        self.__m3s = Ostap.MoreRooFit.Addition("m_" + name + '3S',
                                               "m3s(%s)" % name, self.__m1s,
                                               self.__dm3s)

        self.__aset22 = ROOT.RooArgList(self.__sigma, self.__m1s, self.__m3s)
        self.__s3s = Ostap.FormulaVar(
            "sigma_" + name + '3S', "#sigma_{Y3S}(%s)" % name,
            "%s*(%s/%s)" % (self.__sigma.GetName(), self.__m3s.GetName(),
                            self.__m1s.GetName()), self.__aset22)

        self.__Y3S = CB2_pdf(name + '3S',
                             xvar=self.mass,
                             mean=self.__m3s,
                             sigma=self.__s3s,
                             alphaL=self.__aL,
                             alphaR=self.__aR,
                             nL=self.__nL,
                             nR=self.__nR)

        #
        ## the actual signal PDFs
        #
        self.__y1s = self.__Y1S.pdf
        self.__y2s = self.__Y2S.pdf
        self.__y3s = self.__Y3S.pdf

        ## use helper function to create background
        self.background = self.make_bkg(power, 'Bkg%s' % name, self.mass)

        self.__n1s = self.make_var(None, "N1S" + name, "Signal(Y1S)", None,
                                   1000, 0, 1.e+7)
        self.__n2s = self.make_var(None, "N2S" + name, "Signal(Y2S)", None,
                                   300, 0, 1.e+6)
        self.__n3s = self.make_var(None, "N3S" + name, "Signal(Y3S)", None,
                                   100, 0, 1.e+6)
        self.__b = self.make_var(None, "B" + name, "Background", None, 100, 0,
                                 1.e+8)

        self.alist1 = ROOT.RooArgList(self.__y1s, self.__y2s, self.__y3s)
        self.alist2 = ROOT.RooArgList(self.__n1s, self.__n2s, self.__n3s)

        self.alist1.add(self.background.pdf)
        self.alist2.add(self.__b)

        self.pdf = ROOT.RooAddPdf("manca_%s" % name, "manca(%s)" % name,
                                  self.alist1, self.alist2)

        self.__dm2s.setConstant(True)
        self.__dm3s.setConstant(True)

        self._splots = []

        self.s1_name = self.N1S.GetName()
        self.s2_name = self.N2S.GetName()
        self.s3_name = self.N3S.GetName()
        self.b_name = self.B.GetName()

        #
        ## finally declare components
        #
        self.signals().add(self.__y1s)
        self.signals().add(self.__y2s)
        self.signals().add(self.__y3s)
        self.backgrounds().add(self.background.pdf)

        ## save configurtaion
        self.config = {
            'mass': self.mass,
            'name': self.name,
            'power': self.power,
            'm1s': self.m1s,
            'sigma': self.sigma,
            'alphaL': self.aL,
            'alphaR': self.aR,
            'nL': self.nL,
            'nR': self.nR,
        }
コード例 #4
0
ファイル: specific.py プロジェクト: OstapHEP/ostap
    def __init__(self,
                 mass,
                 name='Y',
                 power=0,
                 m1s=None,
                 sigma=None,
                 a0=1.91,
                 a1=None,
                 a2=None):

        #
        PDF.__init__(self, name, mass)
        #
        if 9460. in self.mass and 10023. in self.mass and 10355. in self.mass:
            gev_ = 1000
        elif 9.460 in self.mass and 10.023 in self.mass and 10.355 in self.mass:
            gev_ = 1
        else:
            raise AttributeError("Illegal mass range %s<m<%s" % self.xminmax())

        m_y1s = 9.46030 * gev_
        s_y1s = 4.3679e-02 * gev_
        dm_y2s = 10.02326 * gev_ - m_y1s
        dm_y3s = 10.3552 * gev_ - m_y1s

        # =====================================================================
        ## Y(1S)
        # =====================================================================

        self.__a0 = self.make_var(a0, 'a0m_%s' % name,
                                  "a0 for Needham's function", a0, 1.91, 0.1,
                                  3.0)

        self.__a1 = self.make_var(a1, 'a1m_%s' % name,
                                  "a1 for Needham's function", a1,
                                  1.1174 / gev_, -10.0 / gev_, 10.0 / gev_)

        self.__a2 = self.make_var(a2, 'a2m_%s' % name,
                                  "a2 for Needham's function", a2,
                                  -5.299 / gev_**2, -100.0 / gev_**2,
                                  100.0 / gev_**2)

        ## default logic does not work nicely here, therefore we need to be explicit:
        if a0 is None and not self.a0.isConstant(): self.a0.fix(1.91)
        if a1 is None and not self.a1.isConstant(): self.a1.fix(1.1174 / gev_)
        if a2 is None and not self.a2.isConstant():
            self.a2.fix(-5.299 / gev_**2)

        self.__m1s = self.make_var(m1s, "m1S_%s" % name, "mass Y1S(%s)" % name,
                                   m1s, m_y1s, m_y1s - 0.15 * s_y1s,
                                   m_y1s + 0.15 * s_y1s)

        self.__s1s = self.make_var(sigma, "s1S_%s" % name,
                                   "sigma Y1S(%s)" % name, sigma, s_y1s,
                                   0.3 * s_y1s, 4 * s_y1s)

        self.__sigma = self.s1s
        self.__Y1S = Needham_pdf(name + '1S',
                                 xvar=self.mass,
                                 mean=self.m1s,
                                 sigma=self.s1s,
                                 a0=self.a0,
                                 a1=self.a1,
                                 a2=self.a2)

        # =====================================================================
        ## Y(2S)
        # =====================================================================
        self.__dm2s = self.make_var(None, "dm2s" + name, "dm2s(%s)" % name,
                                    dm_y2s, dm_y2s - 0.20 * s_y1s,
                                    dm_y2s + 0.20 * s_y1s)

        self.__aset11 = ROOT.RooArgList(self.__m1s, self.__dm2s)

        ## self.__m2s    = ROOT.RooFormulaVar (
        ## "m_" + name + '2S'   ,
        ## "m2s(%s)"  % name    ,
        ## "%s+%s" % ( self.__m1s.GetName() , self.__dm2s.GetName()  ) ,
        ## self.__aset11       )
        self.__m2s = Ostap.MoreRooFit.Addition("m_" + name + '2S',
                                               "m2s(%s)" % name, self.__m1s,
                                               self.__dm2s)

        self.__aset12 = ROOT.RooArgList(self.__sigma, self.__m1s, self.__m2s)
        self.__s2s = Ostap.FormulaVar(
            "sigma_" + name + '2S', "#sigma_{Y2S}(%s)" % name,
            "%s*(%s/%s)" % (self.__sigma.GetName(), self.__m2s.GetName(),
                            self.__m1s.GetName()), self.__aset12)

        self.__Y2S = Needham_pdf(name + '2S',
                                 xvar=self.mass,
                                 mean=self.m2s,
                                 sigma=self.s2s,
                                 a0=self.a0,
                                 a1=self.a1,
                                 a2=self.a2)

        # =====================================================================
        ## Y(3S)
        # =====================================================================
        self.__dm3s = self.make_var(None, "dm3s" + name, "dm3s(%s)" % name,
                                    dm_y3s, dm_y3s - 0.20 * s_y1s,
                                    dm_y3s + 0.20 * s_y1s)

        self.__aset21 = ROOT.RooArgList(self.__m1s, self.__dm3s)
        ## self.__m3s    = ROOT.RooFormulaVar (
        ## "m_"       + name + '(3S)' ,
        ## "m3s(%s)"  % name          ,
        ## "%s+%s" % ( self.__m1s.GetName() , self.__dm3s.GetName() ) ,
        ## self.__aset21       )
        self.__m3s = Ostap.MoreRooFit.Addition("m_" + name + '3S',
                                               "m3s(%s)" % name, self.__m1s,
                                               self.__dm3s)

        self.__aset22 = ROOT.RooArgList(self.__sigma, self.__m1s, self.__m3s)
        self.__s3s = Ostap.FormulaVar(
            "sigma_" + name + '3S', "#sigma_{Y3S}(%s)" % name,
            "%s*(%s/%s)" % (self.__sigma.GetName(), self.__m3s.GetName(),
                            self.__m1s.GetName()), self.__aset22)

        self.Y3S = Needham_pdf(name + '3S',
                               xvar=self.mass,
                               mean=self.m3s,
                               sigma=self.s3s,
                               a0=self.a0,
                               a1=self.a1,
                               a2=self.a2)

        #
        ## the actual signal PDFs
        #
        self.__y1s = self.Y1S.pdf
        self.__y2s = self.Y2S.pdf
        self.__y3s = self.Y3S.pdf

        self.__power = power
        ## use helper function to create background
        self.background = self.make_bkg(power, 'Bkg%s' % name, self.mass)

        self.__n1s = self.make_var(None, "N1S" + name, "Signal(Y1S)", None,
                                   1000, 0, 1.e+8)
        self.__n2s = self.make_var(None, "N2S" + name, "Signal(Y2S)", None,
                                   300, 0, 1.e+7)
        self.__n3s = self.make_var(None, "N3S" + name, "Signal(Y3S)", None,
                                   100, 0, 1.e+6)
        self.__b = self.make_var(None, "B" + name, "Background", None, 100, 0,
                                 1.e+8)

        self.alist1 = ROOT.RooArgList(self.__y1s, self.__y2s, self.__y3s)
        self.alist2 = ROOT.RooArgList(self.__n1s, self.__n2s, self.__n3s)

        self.alist1.add(self.background.pdf)
        self.alist2.add(self.__b)

        self.pdf = ROOT.RooAddPdf("manca_%s" % name, "manca(%s)" % name,
                                  self.alist1, self.alist2)

        self.__dm2s.setConstant(True)
        self.__dm3s.setConstant(True)

        self._splots = []

        self.s1_name = self.__n1s.GetName()
        self.s2_name = self.__n2s.GetName()
        self.s3_name = self.__n3s.GetName()

        #
        ## finally declare components
        #
        self.signals().add(self.__y1s)
        self.signals().add(self.__y2s)
        self.signals().add(self.__y3s)
        self.backgrounds().add(self.background.pdf)

        ## save configurtaion
        self.config = {
            'mass': self.mass,
            'name': self.name,
            'power': self.power,
            'm1s': self.m1s,
            'sigma': self.sigma,
            'a0': self.a0,
            'a1': self.a1,
            'a2': self.a2,
        }