def testInclusiveTxNameData(self):

        f = './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/c000/THSCPM2.txt'
        gInfo = infoObj.Info('./database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/globalInfo.txt')
        gInfo.addInfo('dataId','c000')
        tx = TxName(f,gInfo,gInfo,finalStates)
        res = tx.txnameData.getValueFor([[100.*GeV]]*2)
        self.assertAlmostEqual(res,0.058038)
        res = tx.txnameData.getValueFor([[500.*GeV,150.*GeV,10.*GeV],[100.*GeV]])
        self.assertAlmostEqual(res,0.058038)

        res = tx.txnameData.getValueFor([[125.*GeV]]*2)
        self.assertAlmostEqual(res,0.090999)
        res = tx.txnameData.getValueFor([[200.*GeV]]*2)
        self.assertEqual(res,None)

        f = './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/c000/THSCPM6.txt'
        gInfo = infoObj.Info('./database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/globalInfo.txt')
        gInfo.addInfo('dataId','c000')
        tx = TxName(f,gInfo,gInfo,finalStates)
        res = tx.txnameData.getValueFor([[279.*GeV,170.*GeV,100.*GeV]]*2)
        self.assertAlmostEqual(res,0.097172,6)
        res = tx.txnameData.getValueFor([[100.*GeV],[279.*GeV,170.*GeV,100.*GeV]])
        self.assertAlmostEqual(res,0.097172,6)
        res = tx.txnameData.getValueFor([[500*GeV,100.*GeV],[1.917E+03*GeV,1.7E+02*GeV,1E+02*GeV]])
        self.assertAlmostEqual(res,0.00025745,6)

        res = tx.txnameData.getValueFor([[500*GeV,100.*GeV,10.*GeV],[1.112E+03*GeV,188*GeV,1E+02*GeV]])
        self.assertAlmostEqual(res,0.015,3)
Example #2
0
    def testgetEffFor(self):

        f = './databaseBroken/13TeV/CMS/CMS-PAS-EXO-16-036-eff/c000/THSCPM2.txt'
        gInfo = infoObj.Info(
            './databaseBroken/13TeV/CMS/CMS-PAS-EXO-16-036-eff/globalInfo.txt')
        gInfo.addInfo('dataId', 'c000')
        tx = TxName(f, gInfo, gInfo, finalStates)

        self.assertFalse(hasattr(tx._topologyList.getElements()[0], 'mass'))

        el = Element(info="[[[e+]],[]]",
                     finalState=['HSCP', 'MET'],
                     model=finalStates)
        setattr(n1, 'mass', 200 * GeV)
        setattr(c1, 'mass', 150 * GeV)
        el.branches[0].oddParticles = [n1]
        el.branches[1].oddParticles = [c1]

        #test getting efficiency with mass only
        self.assertEqual(tx.getEfficiencyFor(el.mass), 0.12396)

        #test getting efficiency with element and reweighted efficiency
        setattr(n1, 'totalwidth', 0. * GeV)
        setattr(c1, 'totalwidth', 10**(-17) * GeV)
        self.assertAlmostEqual(tx.getEfficiencyFor(el), 0.08697, 3)
Example #3
0
    def __init__(self, path=None, info=None, createInfo=True,
                    discard_zeroes=True, databaseParticles = None):
        """
        :param discard_zeroes: discard txnames with zero-only results
        """

        self.path = path
        self.globalInfo = info
        self.txnameList = []

        if path and createInfo:
            logger.debug('Creating object based on data folder : %s' %self.path)

            #Get data folder info:
            if not os.path.isfile(os.path.join(path,"dataInfo.txt")):
                logger.error("dataInfo.txt file not found in " + path)
                raise TypeError
            self.dataInfo = infoObj.Info(os.path.join(path,"dataInfo.txt"))

            #Get list of TxName objects:
            for txtfile in glob.iglob(os.path.join(path,"*.txt")):
                try:
                    txname = txnameObj.TxName(txtfile,self.globalInfo,
                                            self.dataInfo, databaseParticles)
                    if discard_zeroes and txname.hasOnlyZeroes():
                        logger.debug ( "%s, %s has only zeroes. discard it." % \
                                         ( self.path, txname.txName ) )
                        continue
                    self.txnameList.append(txname)
                except TypeError: continue

            self.txnameList.sort()
            self.checkForRedundancy(databaseParticles)
    def __init__(self, path=None, info=None, createInfo=True):

        self.path = path
        self.globalInfo = info
        self.txnameList = []

        if path and createInfo:
            logger.debug('Creating object based on data folder : %s' %
                         self.path)

            #Get data folder info:
            if not os.path.isfile(os.path.join(path, "dataInfo.txt")):
                logger.error("dataInfo.txt file not found in " + path)
                raise TypeError
            self.dataInfo = infoObj.Info(os.path.join(path, "dataInfo.txt"))

            #Get list of TxName objects:
            for txtfile in glob.iglob(os.path.join(path, "*.txt")):
                try:
                    txname = txnameObj.TxName(txtfile, self.globalInfo,
                                              self.dataInfo)
                    self.txnameList.append(txname)
                except TypeError:
                    continue

        self.txnameList.sort()
Example #5
0
    def __init__(self, path=None):
        """
        :param path: Path to the experimental result folder
        """

        if path and os.path.isdir(path):
            self.path = path
            if not os.path.isfile(os.path.join(path, "globalInfo.txt")):
                logger.error("globalInfo.txt file not found in " + path)
                raise TypeError
            self.globalInfo = infoObj.Info(os.path.join(
                path, "globalInfo.txt"))
            self.datasets = []
            folders = []
            for root, _, files in os.walk(path):
                folders.append((root, files))
            folders.sort()
            for root, files in folders:
                if 'dataInfo.txt' in files:  # data folder found
                    # Build data set
                    try:
                        dataset = datasetObj.DataSet(root, self.globalInfo)
                        self.datasets.append(dataset)
                    except TypeError:
                        continue
Example #6
0
    def __init__(self, path=None, discard_zeroes=True, databaseParticles=None):
        """
        :param path: Path to the experimental result folder
        :param discard_zeroes: Discard maps with only zeroes
        :param databaseParticles: the model, i.e. the particle content
        """

        if not path:
            return
        if not os.path.isdir(path):
            raise SModelSExperimentError("%s is not a path" % path)

        self.discard_zeroes = discard_zeroes
        self.path = path
        if not os.path.isfile(os.path.join(path, "globalInfo.txt")):
            logger.error("globalInfo.txt file not found in " + path)
            raise TypeError
        self.globalInfo = infoObj.Info(os.path.join(path, "globalInfo.txt"))
        #Add type of experimental result (if not defined)
        if not hasattr(self.globalInfo, 'type'):
            self.globalInfo.type = 'prompt'

        datasets = {}
        folders = []
        for root, _, files in cleanWalk(path):
            folders.append((root, files))
        folders.sort()
        self.datasets = []
        hasOrder = hasattr(self.globalInfo, "datasetOrder")
        for root, files in folders:
            if 'dataInfo.txt' in files:  # data folder found
                # Build data set
                try:
                    dataset = datasetObj.DataSet(
                        root,
                        self.globalInfo,
                        discard_zeroes=discard_zeroes,
                        databaseParticles=databaseParticles)
                    if hasOrder:
                        datasets[dataset.dataInfo.dataId] = dataset
                    else:
                        self.datasets.append(dataset)
                except TypeError:
                    continue
        if not hasOrder:
            return
        dsOrder = self.globalInfo.datasetOrder
        if type(dsOrder) == str:
            ## for debugging only, we allow a single dataset
            dsOrder = [dsOrder]
        for dsname in dsOrder:
            self.datasets.append(datasets[dsname])
        if len(self.datasets) != len(dsOrder):
            raise SModelSExperimentError(
                "lengths of datasets and datasetOrder mismatch")
    def testInclusiveTxName(self):


        f = './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/c000/THSCPM2.txt'
        gInfo = infoObj.Info('./database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/globalInfo.txt')
        gInfo.addInfo('dataId','c000')
        tx = TxName(f,gInfo,gInfo,finalStates)
        el = element.Element(info="[[],[[e+]]]",finalState = ['HSCP','MET'], model=finalStates)
        newEl = tx.hasElementAs(el)  #newEl should be equal to el, but with opposite branch ordering
        self.assertFalse(newEl is None)
        bsmParticles = [[str(bsm) for bsm in br] for br in newEl.oddParticles]
        self.assertTrue(bsmParticles == [['anyOdd','MET'],['HSCP']])
Example #8
0
    def testTxnameElements(self):

        f = './databaseBroken/13TeV/CMS/CMS-PAS-EXO-16-036-eff/c000/THSCPM2.txt'
        gInfo = infoObj.Info(
            './databaseBroken/13TeV/CMS/CMS-PAS-EXO-16-036-eff/globalInfo.txt')
        gInfo.addInfo('dataId', 'c000')
        tx = TxName(f, gInfo, gInfo, finalStates)

        el = Element(info="[[*],[]]",
                     finalState=['MET', 'HSCP'],
                     model=finalStates)

        self.assertTrue(len(tx._topologyList.getElements()), 1)
        self.assertEqual(tx._topologyList.getElements()[0], el)
Example #9
0
    def testTxNameDataWildCard(self):

        f = './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/c000/THSCPM2.txt'
        gInfo = infoObj.Info(
            './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/globalInfo.txt')
        gInfo.addInfo('dataId', 'c000')
        tx = TxName(f, gInfo, gInfo)
        res = tx.getEfficiencyFor([[100. * GeV]] * 2)
        self.assertAlmostEqual(res, 0.058038)
        res = tx.getEfficiencyFor([[500. * GeV, 150. * GeV, 10. * GeV],
                                   [100. * GeV]])
        self.assertAlmostEqual(res, 0.058038)

        res = tx.getEfficiencyFor([[125. * GeV]] * 2)
        self.assertAlmostEqual(res, 0.090999)
        res = tx.getEfficiencyFor([[200. * GeV]] * 2)
        self.assertEqual(res, 0.)

        f = './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/c000/THSCPM6.txt'
        gInfo = infoObj.Info(
            './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/globalInfo.txt')
        gInfo.addInfo('dataId', 'c000')
        tx = TxName(f, gInfo, gInfo)
        res = tx.getEfficiencyFor([[279. * GeV, 170. * GeV, 100. * GeV]] * 2)
        self.assertAlmostEqual(res, 0.097172, 6)
        res = tx.getEfficiencyFor([[100. * GeV],
                                   [279. * GeV, 170. * GeV, 100. * GeV]])
        self.assertAlmostEqual(res, 0.097172, 6)
        res = tx.getEfficiencyFor(
            [[500 * GeV, 100. * GeV],
             [1.917E+03 * GeV, 1.7E+02 * GeV, 1E+02 * GeV]])
        self.assertAlmostEqual(res, 0.00025745, 6)

        res = tx.getEfficiencyFor([[500 * GeV, 100. * GeV, 10. * GeV],
                                   [1.112E+03 * GeV, 188 * GeV, 1E+02 * GeV]])
        self.assertAlmostEqual(res, 0.015, 3)
Example #10
0
    def testBrokenFinalState(self):

        f = './databaseBroken/13TeV/CMS/CMS-PAS-EXO-16-036-eff/c000/THSCPM2broken.txt'
        gInfo = infoObj.Info(
            './databaseBroken/13TeV/CMS/CMS-PAS-EXO-16-036-eff/globalInfo.txt')
        gInfo.addInfo('dataId', 'c000')
        try:
            #print (gInfo)
            TxName(f, gInfo, gInfo, finalStates)
            #print (tx)
            gotError = False
        except SModelSError as e:
            gotError = e

        errstr = "BSM particle ``non-MET'' has not been defined in databaseParticles.py"
        self.assertEqual(gotError.args[0], errstr)
Example #11
0
    def testTxNameWildCard(self):

        f = './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/c000/THSCPM2.txt'
        gInfo = infoObj.Info(
            './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/globalInfo.txt')
        gInfo.addInfo('dataId', 'c000')
        tx = TxName(f, gInfo, gInfo)

        el = element.Element(info="[[],[[e+]]]", finalState=['HSCP', 'MET'])
        el.setMasses([[1.25E+02 * GeV], [4.40E+02 * GeV, 1.00E+00 * GeV]])
        newEl = tx.hasElementAs(
            el
        )  #newEl should be equal to el, but with opposite branch ordering
        self.assertFalse(newEl is None)
        self.assertTrue(newEl.getMasses() == [[4.40E+02 * GeV, 1.00E+00 *
                                               GeV], [1.25E+02 * GeV]])
        res = tx.getEfficiencyFor(newEl.getMasses())
        self.assertAlmostEqual(res, 0.090999)
Example #12
0
    def testGetValueFor(self):

        f = './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/c000/THSCPM1.txt'
        gInfo = infoObj.Info(
            './database/13TeV/CMS/CMS-PAS-EXO-16-036-eff/globalInfo.txt')
        gInfo.addInfo('dataId', 'c000')
        tx = TxName(f, gInfo, gInfo, finalStates)

        el = Element(info="[[],[]]",
                     finalState=['HSCP', 'HSCP'],
                     model=finalStates)
        setattr(c1, 'mass', 150 * GeV)
        el.branches[0].oddParticles = [c1]
        el.branches[1].oddParticles = [c1]

        #test getting UL with mass only
        self.assertEqual(tx.txnameData.getValueFor(el.mass), 0.21496)

        #test getting UL with element and reweighted efficiency
        setattr(c1, 'totalwidth', 10**(-17) * GeV)
        self.assertAlmostEqual(tx.txnameData.getValueFor(el), 0.49 * 0.21496,
                               3)