Ejemplo n.º 1
0
    def Process(self, entry):
        """
        Fills data set 
        """
        #
        # == getting the next entry from the tree
        #
        if self.GetEntry(entry) < 0:
            return 0  # RETURN
        #

        if not self._progress:
            self._total = self.fChain.GetEntries()
            logger.info('TChain entries: %d' % self._total)
            self._progress = ProgressBar(
                0,
                self._total,
                80,
                mode='fixed')

        if 0 == self._events % 1000:
            self._progress.increment_amount(1000)

        self._events += 1
        #
        # == for more convenience
        #
        bamboo = self.fChain

        if not self.mmin <= bamboo.DTFm_b < self.mmax:
            return 0
        #
        # apply cuts
        if not self . _cuts(bamboo):
            return 0

        # calculate & store the efficiency weight
        w = self._weight(bamboo)
        self._counter += 0 != w

        vv = self._mlp()
        # if vv < 0.75 : return 0


        self.mass   . setVal(bamboo.DTFm_b)

        for k, v in self.variables.items():
            if k in self.meta:
                v.setVal(getattr(bamboo, self.meta[k][0])[self.meta[k][1]])
            else:
                v.setVal(getattr(bamboo, k))
            # v.setVal(self.get_from_bamboo(k, bamboo))
        
        self.data .add(self.varset)

        return 1
Ejemplo n.º 2
0
class TrgSelector(Selector):

    """
    ROOT selector for getting Tis/Tos information from prompt charm particle  
    """
    # constructor from cuts and histogram bins
    #  @param var_    the prefix for trgger variable in n-tuple
    #  @param histo   the mass histogram template
    #  @param pt_axis the pt-axis binnig
    #  @param y_axis  the y-axis binnig
    #  @param l0      perform tistos'ing of L0
    #  @param l1      perform tistos'ing of L1
    #  @param l2      perform tistos'ing of L2
    #  @param cuts    the cuts (in any)

    def __init__(self,
                 var_,
                 histo,
                 pt_axis,
                 y_axis,
                 l0=True,
                 l1=True,
                 l2=True,
                 cuts=lambda s: True):

        Selector.__init__(self, None, self)  # initialize the base

        self._l0 = l0
        self._l1 = l1
        self._l2 = l2

        trg = self._l0 or self._l1 or self._l2
        if not trg:
            raise TypeError, 'Trigger is not specified '

        self._cuts = cuts
        self._pt_axis = pt_axis
        self. _y_axis = y_axis

        self._histos = {}
        self._events = 0L
        #
        self.pt_ = 'pt_' + var_
        self.y_ = 'y_' + var_
        self.m_ = 'm_' + var_
        #
        self.l0_tos = var_ + '_l0tos_1'
        self.l0_tis = var_ + '_l0tis_2'
        #
        self.l1_tos = var_ + '_l1tos_1'
        self.l1_tis = var_ + '_l1tis_2'
        #
        self.l2_tos = var_ + '_l2tos_1'
        self.l2_tis = var_ + '_l2tis_2'

        self._var = var_

        for iPt in pt_axis:

            for iY in y_axis:

                hTotal = histo.Clone(hID())
                hExTos = histo.Clone(hID())
                hTisTos = histo.Clone(hID())
                hExTis = histo.Clone(hID())
                hTob = histo.Clone(hID())

                hTotal  . SetTitle('Total')
                hExTis  . SetTitle('ExTis')
                hExTos  . SetTitle('ExTos')
                hTisTos . SetTitle('Tis&Tos')
                hTob    . SetTitle('Tob')

                self._histos[(iPt, iY)] = [
                    hTotal,
                    hExTos,
                    hTisTos,
                    hExTis,
                    hTob
                ]

        #
        ## global bin
        #
        hTotal = histo.Clone(hID())
        hExTos = histo.Clone(hID())
        hTisTos = histo.Clone(hID())
        hExTis = histo.Clone(hID())
        hTob = histo.Clone(hID())

        hTotal  . SetTitle('Total')
        hExTis  . SetTitle('ExTis')
        hExTos  . SetTitle('ExTos')
        hTisTos . SetTitle('Tis&Tos')
        hTob    . SetTitle('Tob')

        self._histos0 = [
            hTotal,
            hExTos,
            hTisTos,
            hExTis,
            hTob
        ]

        #
        # progress bar
        #
        self._progress = None
        self._events = 0

    def histos(self):
        print ' '
        return self._histos, self._pt_axis, self._y_axis, self._histos0

    # start processing
    def Begin(self):
        """
        Start processing
        """
        print 80 * '*'
        print 'Begin     %s    L0 %s  L1 %s  L2 %s ' % (self._var,
                                                        self._l0,
                                                        self._l1,
                                                        self._l2)
    # end processing

    def Terminate(self):
        """
        End processing
        """
        print '\nTerminate %s    L0 %s  L1 %s  L2 %s ' % (self._var,
                                                          self._l0,
                                                          self._l1,
                                                          self._l2)

        n_total = self._histos0[0] . accumulate()
        n_extos = self._histos0[1] . accumulate()
        n_tistos = self._histos0[2] . accumulate()
        n_extis = self._histos0[3] . accumulate()
        n_tob = self._histos0[4] . accumulate()

        print ' #tot %.0f #extos %.0f #tistos %.0f #extis %.f #tob %.0f ' % (n_total  . value(),
                                                                             n_extos  . value(
                                                                             ),
                                                                             n_tistos . value(
                                                                             ),
                                                                             n_extis  . value(
                                                                             ),
                                                                             n_tob    . value())
        eTOS = 1 / (1 + n_extis / n_tistos)
        eTIS = 1 / (1 + n_extos / n_tistos)

        print ' eTOS=%s%%  eTIS=%s%% ' % (eTOS * 100, eTIS * 100)

        print 80 * '*'

    # the only one important method
    def Process(self, entry):
        """
        Fills the histograms from a tree
        """
        #
        # == getting the next entry from the tree
        #
        if self.GetEntry(entry) <= 0:
            return 0  # RETURN

        if not self._progress:
            print ' Trg-Chain entries: %d' % self.fChain.GetEntries()
            self._progress = ProgressBar(
                0,
                self.fChain.GetEntries(),
                80,
                mode='fixed')

        self._events += 1
        if 0 == self._events % 1000:
            self._progress.increment_amount(1000)
            print self._progress, '\r',

        #
        # == for more convenience
        #
        bamboo = self.fChain

        #
        # apply trivial "acceptance" cuts
        #
        pt = getattr(bamboo, self.pt_)
        y = getattr(bamboo, self.y_)

        if not 2 <= y <= 4.5:
            return 0  # RETURN
        if not pt <= 12.0:
            return 0  # RETURN

        #
        # check cuts
        #
        if not self._cuts(bamboo):
            return 0  # RETURN

        #
        # Finally: find the histogram and  fill it !
        #

        ptBin = self._pt_axis . FindBin(pt)
        yBin = self. _y_axis . FindBin(y)

        key = (ptBin, yBin)
        if not key in self._histos:
            return 0
        histos = self._histos[key]
        histos0 = self._histos0

        #
        # extract TisTos information:
        #

        # ALL:
        tos = True
        tis = True

        #
        # L0
        if self._l0 and (tis or tos):
            #
            tos_l0 = 1 == getattr(bamboo, self.l0_tos)
            tis_l0 = 1 == getattr(bamboo, self.l0_tis)
            #
            tos = tos and tos_l0
            tis = tis and tis_l0

        #
        # HLT1
        if self._l1 and (tis or tos):
            #
            tos_l1 = 1 == getattr(bamboo, self.l1_tos)
            tis_l1 = 1 == getattr(bamboo, self.l1_tis)

            tos = tos and tos_l1
            tis = tis and tis_l1

        #
        # HLT2
        if self._l2 and (tis or tos):
            tos_l2 = 1 == getattr(bamboo, self.l2_tos)
            tis_l2 = 1 == getattr(bamboo, self.l2_tis)

            tos = tos and tos_l2
            tis = tis and tis_l2

        #
        # TIS/TOS categories
        exTos = tos and not tis
        exTis = tis and not tos
        tisTos = tis and tos

        mass = getattr(bamboo, self.m_)
        #
        # All:
        if True:
            histos[0] . Fill(mass)  # ALL
            histos0[0] . Fill(mass)  # ALL
        #
        # start TisTos'ing:
        if exTos:
            histos[1] . Fill(mass)  # ExTos
            histos0[1] . Fill(mass)  # ExTos
        elif tisTos:
            histos[2] . Fill(mass)  # Tis&Tos
            histos0[2] . Fill(mass)  # Tis&Tos
        elif exTis:
            histos[3] . Fill(mass)  # ExTis
            histos0[3] . Fill(mass)  # ExTis
        else:
            histos[4] . Fill(mass)  # Tob
            histos0[4] . Fill(mass)  # Tob
        #
        return 1
Ejemplo n.º 3
0
    def Process(self, entry):
        """
        Fills the histograms from a tree
        """
        #
        # == getting the next entry from the tree
        #
        if self.GetEntry(entry) <= 0:
            return 0  # RETURN

        if not self._progress:
            print ' Trg-Chain entries: %d' % self.fChain.GetEntries()
            self._progress = ProgressBar(
                0,
                self.fChain.GetEntries(),
                80,
                mode='fixed')

        self._events += 1
        if 0 == self._events % 1000:
            self._progress.increment_amount(1000)
            print self._progress, '\r',

        #
        # == for more convenience
        #
        bamboo = self.fChain

        #
        # apply trivial "acceptance" cuts
        #
        pt = getattr(bamboo, self.pt_)
        y = getattr(bamboo, self.y_)

        if not 2 <= y <= 4.5:
            return 0  # RETURN
        if not pt <= 12.0:
            return 0  # RETURN

        #
        # check cuts
        #
        if not self._cuts(bamboo):
            return 0  # RETURN

        #
        # Finally: find the histogram and  fill it !
        #

        ptBin = self._pt_axis . FindBin(pt)
        yBin = self. _y_axis . FindBin(y)

        key = (ptBin, yBin)
        if not key in self._histos:
            return 0
        histos = self._histos[key]
        histos0 = self._histos0

        #
        # extract TisTos information:
        #

        # ALL:
        tos = True
        tis = True

        #
        # L0
        if self._l0 and (tis or tos):
            #
            tos_l0 = 1 == getattr(bamboo, self.l0_tos)
            tis_l0 = 1 == getattr(bamboo, self.l0_tis)
            #
            tos = tos and tos_l0
            tis = tis and tis_l0

        #
        # HLT1
        if self._l1 and (tis or tos):
            #
            tos_l1 = 1 == getattr(bamboo, self.l1_tos)
            tis_l1 = 1 == getattr(bamboo, self.l1_tis)

            tos = tos and tos_l1
            tis = tis and tis_l1

        #
        # HLT2
        if self._l2 and (tis or tos):
            tos_l2 = 1 == getattr(bamboo, self.l2_tos)
            tis_l2 = 1 == getattr(bamboo, self.l2_tis)

            tos = tos and tos_l2
            tis = tis and tis_l2

        #
        # TIS/TOS categories
        exTos = tos and not tis
        exTis = tis and not tos
        tisTos = tis and tos

        mass = getattr(bamboo, self.m_)
        #
        # All:
        if True:
            histos[0] . Fill(mass)  # ALL
            histos0[0] . Fill(mass)  # ALL
        #
        # start TisTos'ing:
        if exTos:
            histos[1] . Fill(mass)  # ExTos
            histos0[1] . Fill(mass)  # ExTos
        elif tisTos:
            histos[2] . Fill(mass)  # Tis&Tos
            histos0[2] . Fill(mass)  # Tis&Tos
        elif exTis:
            histos[3] . Fill(mass)  # ExTis
            histos0[3] . Fill(mass)  # ExTis
        else:
            histos[4] . Fill(mass)  # Tob
            histos0[4] . Fill(mass)  # Tob
        #
        return 1
Ejemplo n.º 4
0
class SBT(SelectorWithCuts):

    """
    Create and fill the basic dataset for RooFit
    """
    def add_variable(self, name, description, low, high):
        self.variables[name] = ROOT.RooRealVar(filter_name(name), description, low, high)
        self.varset.add(self.variables[name])        

        index = self.num_re.search(name)
        if index:
            i = int(index.group(0))
            name_noindex = name.replace('[' + str(i) + ']', '')
            self.meta[name] = (name_noindex, i)


    def __init__(self,
                 mass,  # mass-variable
                 selection,  # Tree-selection
                 cuts=lambda s: True,
                 weight=lambda s: 1,
                 name='',
                 tmva_weights='',
                 short=False):

        if not name:
            name = hID()

        SelectorWithCuts.__init__(self, selection)  # initialize the base

        self.num_re = re.compile(r"[(\d)]")

        self._cuts = cuts
        self._weight = weight
        self._short = short

        self.variables = {}

        # meta info about vector-variables
        # contain pairs (name without `[N]`, N as int)
        self.meta = {} 

        self.mass = mass
        self.varset = ROOT.RooArgSet(self.mass)

        for v in varlist:
            self.add_variable(v[0], v[4], v[2] - 0.1, v[3] + 0.1,)

        self.data = ROOT.RooDataSet(
            #
            name,
            "Bu -> J/psi KK pi: " + self.mass.GetName(),
            #
            self.varset
        )

        ROOT.SetOwnership(self.data, False)

        self.mmin = self.mass.getMin()
        self.mmax = self.mass.getMax()

        self._events = 0
        self._counter = SE()
        self._progress = None
        self._total = 1

        self._tmva_weights = tmva_weights

    def __del__(self):

        self.data.Clear()
        self.data.reset()
        del self.data

    def dataset(self):
        return self.data

    def Terminate(self):
        print ''
        logger.info('Terminate:  %d/%d %s ' %
                    (self._events, self._total, self.cuts()))
        self.data.Print('v')

    def Init(self, chain):

        self._mlp = lambda: 0.5

        if chain and self._tmva_weights:

            from tmva_reader import Cutter

            self._mlp = Cutter(chain, self._tmva_weights)

        return SelectorWithCuts.Init(self, chain)

    # the only one important method
    def Process(self, entry):
        """
        Fills data set 
        """
        #
        # == getting the next entry from the tree
        #
        if self.GetEntry(entry) < 0:
            return 0  # RETURN
        #

        if not self._progress:
            self._total = self.fChain.GetEntries()
            logger.info('TChain entries: %d' % self._total)
            self._progress = ProgressBar(
                0,
                self._total,
                80,
                mode='fixed')

        if 0 == self._events % 1000:
            self._progress.increment_amount(1000)

        self._events += 1
        #
        # == for more convenience
        #
        bamboo = self.fChain

        if not self.mmin <= bamboo.DTFm_b < self.mmax:
            return 0
        #
        # apply cuts
        if not self . _cuts(bamboo):
            return 0

        # calculate & store the efficiency weight
        w = self._weight(bamboo)
        self._counter += 0 != w

        vv = self._mlp()
        # if vv < 0.75 : return 0


        self.mass   . setVal(bamboo.DTFm_b)

        for k, v in self.variables.items():
            if k in self.meta:
                v.setVal(getattr(bamboo, self.meta[k][0])[self.meta[k][1]])
            else:
                v.setVal(getattr(bamboo, k))
            # v.setVal(self.get_from_bamboo(k, bamboo))
        
        self.data .add(self.varset)

        return 1
Ejemplo n.º 5
0
class SpsiD(Selector):

    """
    Create and fill the basic dataset for RooFit
    """

    def __init__(self,
                 cuts,
                 dvar,
                 weight,
                 jvar="psi",
                 h1=None,
                 h2=None,
                 h3=None,
                 h4=None):

        Selector.__init__(self, None, self)  # initialize the base

        self._jvar = jvar

        self._cuts = cuts
        self._weight = weight

        self.m_2c = ROOT.RooRealVar(
            "m_2c", "mass(J/psiD)",  3.0,  100)
        self.m_psi = ROOT.RooRealVar(
            "m_psi", "mass(J/psi)",  3.0,  3.2)
        self.pt_psi = ROOT.RooRealVar("pt_psi", "pt(J/psi)",  0, 12.0)
        self.y_psi = ROOT.RooRealVar("y_psi", "y(J/psi)",  2.0,  4.5)
        self.lv01_psi = ROOT.RooRealVar(
            "lv01_psi", "lv01(J/psi)", -1.01,  1.01)
        self.chi2dtf = ROOT.RooRealVar(
            "chi2dtf", "chi2(dtf)/ndf",  0,  1.e+100)

        self._dvar = dvar[0]
        self.m_D = ROOT.RooRealVar(
            "m_" + dvar[0], "mass(D)", dvar[1], dvar[2])
        self.pt_D = ROOT.RooRealVar("pt_" + dvar[0], "pt(D)", 0, 12.0)
        self.y_D = ROOT.RooRealVar("y_" + dvar[0], "y(D)", 2.0,  4.5)

        self.weight = ROOT.RooRealVar("weight", "weight", 0.0,  1.e+20)
        self.dphi = ROOT.RooRealVar(
            "dphi", "|delta(phi)|/pi", 0.0,  1.0)

        self.varset = ROOT.RooArgSet(
            #
            self.m_2c,
            self.m_psi,
            self.pt_psi,
            self.y_psi,
            #
            self.m_D,
            self.pt_D,
            self.y_D,
            # efficiency weight
            self.weight
        )

        self.varset.add(self.lv01_psi)
        self.varset.add(self.dphi)
        self.varset.add(self.chi2dtf)

        self.nPV = ROOT.RooRealVar("nPV", 'n(PV)', 0,    20)
        self.nSpd = ROOT.RooRealVar("nSpd", 'n(Spd)', 0, 20000)
        self.nBest = ROOT.RooRealVar("nBest", 'n(Best)', 0,  5000)
        self.nLong = ROOT.RooRealVar("nLong", 'n(Long)', 0,  5000)
        self.nOT = ROOT.RooRealVar("nOT", 'n(OT)', 0, 50000)

        self.varset.add(self.nPV)
        self.varset.add(self.nSpd)
        self.varset.add(self.nBest)
        self.varset.add(self.nLong)
        self.varset.add(self.nOT)

        self.data = ROOT.RooDataSet(
            #
            "SpsiD",
            "Jpsi + Charm",
            #
            self.varset
        )
        #

        #
        # prepare the structure for slice fits:
        #   fill histos only in case both histo templates are supplied
        self.slices_raw = None
        self.slices_cor = None
        if h1 and h2:
            self.slices_raw = Slices(h1, h2)
        if h3 and h4:
            self.slices_cor = Slices(h3, h4)
        #
        self._events = 0
        self._counter = SE()
        #
        self._progress = None
        #
    #

    def dataset(self):
        return self.data

    # the only one important method
    def Process(self, entry):
        """
        Fills data set 
        """
        #
        # == getting the next entry from the tree
        #
        if self.GetEntry(entry) <= 0:
            return 0  # RETURN

        # if 0 == self._events % 100 :
        if not self._progress:
            self._progress = ProgressBar(0,
                                         self.fChain.GetEntries(),
                                         77,
                                         mode='fixed')

        self._progress.increment_amount()
        print self._progress, '\r',

        self._events += 1

        #
        # == for more convenience
        #
        bamboo = self.fChain

        #
        # J/psi  acceptance
        if not 12 > bamboo.pt_psi:
            return 0
        if not 2.0 < bamboo. y_psi <= 4.5:
            return 0
        #
        # "good" J/psi
        if not 1 == bamboo.good_psi:
            return 0  # Good J/psi

        #
        # apply cuts
        if not self . _cuts(bamboo):
            return 0

        # calculate & store the efficiency weight
        w = self._weight(bamboo)
        self._counter += 0 != w
        if 0 == w:
            return 0  # skip invalid weights

        self.weight    . setVal(w)

        self.m_2c      . setVal(bamboo.m_2c)

        m1 = getattr(bamboo, 'm_' + self._jvar)
        m2 = getattr(bamboo, 'm_' + self._dvar)

        self.m_psi     . setVal(m1)
        self.pt_psi    . setVal(getattr(bamboo, 'pt_' + self._jvar))
        self.y_psi     . setVal(getattr(bamboo, 'y_' + self._jvar))
        self.lv01_psi  . setVal(getattr(bamboo, 'lv01_' + self._jvar))

        self.chi2dtf   . setVal(bamboo.dtf_2c)

        self.m_D       . setVal(m2)
        self.pt_D      . setVal(getattr(bamboo, 'pt_' + self._dvar))
        self.y_D       . setVal(getattr(bamboo, 'y_' + self._dvar))

        self.dphi      . setVal(dphi(bamboo, self._jvar, self._dvar))

        # GEC
        self.nPV       . setVal(bamboo.nPV_rec)
        self.nSpd      . setVal(bamboo.nSpd_gec)
        self.nBest     . setVal(bamboo.nBest_rec)
        self.nLong     . setVal(bamboo.nLong_rec)
        self.nOT       . setVal(bamboo.nOT_gec)

        self.data .add(self.varset)

        if self.slices_raw:
            self.slices_raw.fill(m1, m2)
        if self.slices_cor:
            self.slices_cor.fill(m1, m2, w)

        return 1
Ejemplo n.º 6
0
    def Process(self, entry):
        """
        Fills data set 
        """
        #
        # == getting the next entry from the tree
        #
        if self.GetEntry(entry) <= 0:
            return 0  # RETURN

        self._events += 1
        # if 0 == self._events % 1000 :
        #    print self._events

        if not self._progress:
            self._progress = ProgressBar(0,
                                         self.fChain.GetEntries(),
                                         77,
                                         mode='fixed')

        self._progress.increment_amount()
        print self._progress, '\r',

        #
        # == for more convenience
        #
        bamboo = self.fChain

        #
        # apply cuts
        if not self . _cuts(bamboo):
            return 0

        # calculate & store the efficiency weight
        w = self._weight(bamboo)
        self._counter += 0 != w
        if 0 == w:
            return 0  # skip invalid weights
        self.weight    . setVal(w)

        self.m_2c      . setVal(bamboo.m_2c)

        m1 = getattr(bamboo, 'm_' + self._d1)

        self.m_D1      . setVal(m1)
        self.pt_D1     . setVal(getattr(bamboo, 'pt_' + self._d1))
        self.y_D1      . setVal(getattr(bamboo, 'y_' + self._d1))

        m2 = getattr(bamboo, 'm_' + self._d2)

        self.m_D2      . setVal(m2)
        self.pt_D2     . setVal(getattr(bamboo, 'pt_' + self._d2))
        self.y_D2      . setVal(getattr(bamboo, 'y_' + self._d2))

        self.chi2dtf   . setVal(bamboo.dtf_2c)

        self.dphi      . setVal(dphi(bamboo, self._d1, self._d2))

        pid1 = getattr(bamboo, 'pid_' + self._d1)
        pid2 = getattr(bamboo, 'pid_' + self._d2)

        ccbar = pid1 * pid2 < 0

        data = self.data1 if ccbar else self.data2

        # GEC
        self.nPV       . setVal(bamboo.nPV_rec)
        self.nSpd      . setVal(bamboo.nSpd_gec)
        self.nBest     . setVal(bamboo.nBest_rec)
        self.nLong     . setVal(bamboo.nLong_rec)
        self.nOT       . setVal(bamboo.nOT_gec)

        data .add(self.varset)

        if self.slices_raw:
            if ccbar:
                self.slices_raw[0].fill(m1, m2)
            else:
                self.slices_raw[1].fill(m1, m2)

        if self.slices_cor:
            if ccbar:
                self.slices_cor[0].fill(m1, m2, w)
            else:
                self.slices_cor[1].fill(m1, m2, w)

        return 1
Ejemplo n.º 7
0
class DD(Selector):

    """
    Create and fill the basic dataset for RooFit
    """

    def __init__(self,
                 cuts,
                 d1var,
                 d2var,
                 weight,
                 h1=None,
                 h2=None,
                 h3=None,
                 h4=None):

        Selector.__init__(self, None, self)  # initialize the base

        self._cuts = cuts
        self._weight = weight

        self.m_2c = ROOT.RooRealVar("m_2c", "mass(DD)", 3.0,  100)
        self.chi2dtf = ROOT.RooRealVar(
            "chi2dtf", "chi2(dtf)/ndf",  0,  1.e+100)

        self._d1 = d1var[0]
        self.m_D1 = ROOT.RooRealVar(
            "m_" + d1var[0], "mass(%s)" % d1var[0], d1var[1], d1var[2])
        self.pt_D1 = ROOT.RooRealVar(
            "pt_" + d1var[0], "pt(%s)" % d1var[0], 2.0, 12.0)
        self.y_D1 = ROOT.RooRealVar(
            "y_" + d1var[0], "y(%s)" % d1var[0], 2.0,  4.5)

        self._d2 = d2var[0]
        self.m_D2 = ROOT.RooRealVar(
            "m_" + d2var[0], "mass(%s)" % d2var[0], d2var[1], d2var[2])
        self.pt_D2 = ROOT.RooRealVar(
            "pt_" + d2var[0], "pt(%s)" % d2var[0], 2.0, 12.0)
        self.y_D2 = ROOT.RooRealVar(
            "y_" + d2var[0], "y(%s)" % d2var[0], 2.0,  4.5)

        self.weight = ROOT.RooRealVar(
            "weight", "efficiency-weight", 0.0,  1.e+20)
        self.dphi = ROOT.RooRealVar("dphi", "|delta(phi)|/pi", 0.0,  1.0)

        self.varset = ROOT.RooArgSet(
            #
            self.m_2c,
            self.m_D1,
            self.pt_D1,
            self.y_D1,
            #
            self.m_D2,
            self.pt_D2,
            self.y_D2,
            #
            # efficiency weight
            self.weight,
        )

        self.varset.add(self.dphi)
        self.varset.add(self.chi2dtf)

        self.nPV = ROOT.RooRealVar("nPV", 'n(PV)', 0,    20)
        self.nSpd = ROOT.RooRealVar("nSpd", 'n(Spd)', 0, 20000)
        self.nBest = ROOT.RooRealVar("nBest", 'n(Best)', 0,  5000)
        self.nLong = ROOT.RooRealVar("nLong", 'n(Long)', 0,  5000)
        self.nOT = ROOT.RooRealVar("nOT", 'n(OT)', 0, 50000)

        self.varset.add(self.nPV)
        self.varset.add(self.nSpd)
        self.varset.add(self.nBest)
        self.varset.add(self.nLong)
        self.varset.add(self.nOT)

        self.data1 = ROOT.RooDataSet(
            "DDbar",
            "D & anti-Charm",
            self.varset)

        self.data2 = ROOT.RooDataSet(
            "DD",
            "D & Charm",
            self.varset)

        #
        # prepare the structure for slice fits:
        #   fill histos only in case both histo templates are supplied
        self.slices_raw = None
        self.slices_cor = None
        if h1 and h2:
            self.slices_raw = (Slices(h1, h2), Slices(h1, h2))
        if h3 and h4:
            self.slices_cor = (Slices(h3, h4), Slices(h3, h4))

        self._events = 0
        self._counter = SE()
        self._progress = None

    #
    def dataset(self):
        return self.data1, self.data2

    # the only one important method
    def Process(self, entry):
        """
        Fills data set 
        """
        #
        # == getting the next entry from the tree
        #
        if self.GetEntry(entry) <= 0:
            return 0  # RETURN

        self._events += 1
        # if 0 == self._events % 1000 :
        #    print self._events

        if not self._progress:
            self._progress = ProgressBar(0,
                                         self.fChain.GetEntries(),
                                         77,
                                         mode='fixed')

        self._progress.increment_amount()
        print self._progress, '\r',

        #
        # == for more convenience
        #
        bamboo = self.fChain

        #
        # apply cuts
        if not self . _cuts(bamboo):
            return 0

        # calculate & store the efficiency weight
        w = self._weight(bamboo)
        self._counter += 0 != w
        if 0 == w:
            return 0  # skip invalid weights
        self.weight    . setVal(w)

        self.m_2c      . setVal(bamboo.m_2c)

        m1 = getattr(bamboo, 'm_' + self._d1)

        self.m_D1      . setVal(m1)
        self.pt_D1     . setVal(getattr(bamboo, 'pt_' + self._d1))
        self.y_D1      . setVal(getattr(bamboo, 'y_' + self._d1))

        m2 = getattr(bamboo, 'm_' + self._d2)

        self.m_D2      . setVal(m2)
        self.pt_D2     . setVal(getattr(bamboo, 'pt_' + self._d2))
        self.y_D2      . setVal(getattr(bamboo, 'y_' + self._d2))

        self.chi2dtf   . setVal(bamboo.dtf_2c)

        self.dphi      . setVal(dphi(bamboo, self._d1, self._d2))

        pid1 = getattr(bamboo, 'pid_' + self._d1)
        pid2 = getattr(bamboo, 'pid_' + self._d2)

        ccbar = pid1 * pid2 < 0

        data = self.data1 if ccbar else self.data2

        # GEC
        self.nPV       . setVal(bamboo.nPV_rec)
        self.nSpd      . setVal(bamboo.nSpd_gec)
        self.nBest     . setVal(bamboo.nBest_rec)
        self.nLong     . setVal(bamboo.nLong_rec)
        self.nOT       . setVal(bamboo.nOT_gec)

        data .add(self.varset)

        if self.slices_raw:
            if ccbar:
                self.slices_raw[0].fill(m1, m2)
            else:
                self.slices_raw[1].fill(m1, m2)

        if self.slices_cor:
            if ccbar:
                self.slices_cor[0].fill(m1, m2, w)
            else:
                self.slices_cor[1].fill(m1, m2, w)

        return 1
Ejemplo n.º 8
0
    def Process(self, entry):
        """
        Fills data set 
        """
        #
        # == getting the next entry from the tree
        #
        if self.GetEntry(entry) <= 0:
            return 0  # RETURN

        # if 0 == self._events % 100 :
        if not self._progress:
            self._progress = ProgressBar(0,
                                         self.fChain.GetEntries(),
                                         77,
                                         mode='fixed')

        self._progress.increment_amount()
        print self._progress, '\r',

        self._events += 1

        #
        # == for more convenience
        #
        bamboo = self.fChain

        #
        # J/psi  acceptance
        if not 12 > bamboo.pt_psi:
            return 0
        if not 2.0 < bamboo. y_psi <= 4.5:
            return 0
        #
        # "good" J/psi
        if not 1 == bamboo.good_psi:
            return 0  # Good J/psi

        #
        # apply cuts
        if not self . _cuts(bamboo):
            return 0

        # calculate & store the efficiency weight
        w = self._weight(bamboo)
        self._counter += 0 != w
        if 0 == w:
            return 0  # skip invalid weights

        self.weight    . setVal(w)

        self.m_2c      . setVal(bamboo.m_2c)

        m1 = getattr(bamboo, 'm_' + self._jvar)
        m2 = getattr(bamboo, 'm_' + self._dvar)

        self.m_psi     . setVal(m1)
        self.pt_psi    . setVal(getattr(bamboo, 'pt_' + self._jvar))
        self.y_psi     . setVal(getattr(bamboo, 'y_' + self._jvar))
        self.lv01_psi  . setVal(getattr(bamboo, 'lv01_' + self._jvar))

        self.chi2dtf   . setVal(bamboo.dtf_2c)

        self.m_D       . setVal(m2)
        self.pt_D      . setVal(getattr(bamboo, 'pt_' + self._dvar))
        self.y_D       . setVal(getattr(bamboo, 'y_' + self._dvar))

        self.dphi      . setVal(dphi(bamboo, self._jvar, self._dvar))

        # GEC
        self.nPV       . setVal(bamboo.nPV_rec)
        self.nSpd      . setVal(bamboo.nSpd_gec)
        self.nBest     . setVal(bamboo.nBest_rec)
        self.nLong     . setVal(bamboo.nLong_rec)
        self.nOT       . setVal(bamboo.nOT_gec)

        self.data .add(self.varset)

        if self.slices_raw:
            self.slices_raw.fill(m1, m2)
        if self.slices_cor:
            self.slices_cor.fill(m1, m2, w)

        return 1