コード例 #1
0
    def test_closure(self):
        www_card_orig = read_card('vh3l_120.txt')
        www_card_file = open('vh3l_cut_rewritten.txt', 'w')
        write_card(www_card_file, www_card_orig)
        www_card_file.close()
        www_card_reread = read_card('vh3l_cut_rewritten.txt')

        self.assertEqual(
            www_card_reread.exp['ch1'], www_card_orig.exp['bin1']
        )
        self.assertEqual(
            www_card_reread.isSignal, www_card_orig.isSignal
        )
        self.assertEqual(
            sorted(www_card_reread.processes), sorted(www_card_orig.processes)
        )
        orig_systs = sorted(www_card_orig.systs, key=lambda x: x[0])
        new_systs = sorted(www_card_reread.systs, key=lambda x: x[0])
        for orig_syst, new_syst in zip(orig_systs, new_systs):
            # Format
            # name, shape, type, ?, bin-process map
            self.assertEqual(
                orig_syst[:4], new_syst[:4]
            )
            self.assertEqual(
                orig_syst[4]['bin1'], new_syst[4]['ch1']
            )
コード例 #2
0
    def test_closure(self):
        os.system(
            'remove_systematics.py vh3l_120.txt "pdf_qqba*" > vh3l_nosys.txt')
        www_card_orig = read_card('vh3l_120.txt')
        www_card_nosys = read_card('vh3l_nosys.txt')

        self.assertTrue('pdf_qqbar' in [x[0] for x in www_card_orig.systs])
        self.assertTrue(
            'pdf_qqbar' not in [x[0] for x in www_card_nosys.systs])
コード例 #3
0
def interpolate_card(output_stream,
                     lowcardfile, lowmass,
                     highcardfile, highmass,
                     target, processes):
    ''' Interpolate between two data cards

    The output card (with mass=target) is written to output_stream.

    The [processes] are interpolated.  The processes can contain
    the format string {mass}
    '''

    log.info("Parsing %s m:%i", lowcardfile, lowmass)
    lowcard = read_card(lowcardfile)
    log.info("Parsing %s m:%i", highcardfile, highmass)
    highcard = read_card(highcardfile)

    assert(lowcard.bins == highcard.bins)

    newcard = copy.deepcopy(lowcard)

    for process in processes:
        targetlabel = process.format(mass=target)
        log.info("Interpolating %s process" % targetlabel)
        lowlabel = process.format(mass=lowmass)
        highlabel = process.format(mass=highmass)

        # Check the yield for this process in each bin
        for bin in lowcard.bins:
            try:
                low_yield = lowcard.exp[bin][lowlabel]
            except KeyError:
                log.error("Error reading bin: %s process: %s from file: %s",
                          bin, lowlabel, lowcardfile)
                raise

            try:
                high_yield = highcard.exp[bin][highlabel]
            except KeyError:
                log.error("Error reading bin: %s process: %s from file: %s",
                          bin, highlabel, highcardfile)
                raise

            target_yield = morph.interpolate(
                lowmass, low_yield,
                highmass, high_yield,
                target
            )
            #log.info("in bin", bin, "low yield is", low_yield,
                    #"high yield is", high_yield, "=> target is ", target_yield)
            # We use the same label as lowlabel, and replace it later
            newcard.exp[bin][lowlabel] = target_yield

    log.info("Writing new card to output")
    write_card(output_stream, newcard)
コード例 #4
0
    def test_closure(self):
        os.system('remove_systematics.py vh3l_120.txt "pdf_qqba*" > vh3l_nosys.txt')
        www_card_orig = read_card('vh3l_120.txt')
        www_card_nosys = read_card('vh3l_nosys.txt')

        self.assertTrue(
            'pdf_qqbar' in [x[0] for x in www_card_orig.systs]
        )
        self.assertTrue(
            'pdf_qqbar' not in [x[0] for x in www_card_nosys.systs]
        )
コード例 #5
0
def interpolate_card(output_stream, lowcardfile, lowmass, highcardfile,
                     highmass, target, processes):
    ''' Interpolate between two data cards

    The output card (with mass=target) is written to output_stream.

    The [processes] are interpolated.  The processes can contain
    the format string {mass}
    '''

    log.info("Parsing %s m:%i", lowcardfile, lowmass)
    lowcard = read_card(lowcardfile)
    log.info("Parsing %s m:%i", highcardfile, highmass)
    highcard = read_card(highcardfile)

    assert (lowcard.bins == highcard.bins)

    newcard = copy.deepcopy(lowcard)

    for process in processes:
        targetlabel = process.format(mass=target)
        log.info("Interpolating %s process" % targetlabel)
        lowlabel = process.format(mass=lowmass)
        highlabel = process.format(mass=highmass)

        # Check the yield for this process in each bin
        for bin in lowcard.bins:
            try:
                low_yield = lowcard.exp[bin][lowlabel]
            except KeyError:
                log.error("Error reading bin: %s process: %s from file: %s",
                          bin, lowlabel, lowcardfile)
                raise

            try:
                high_yield = highcard.exp[bin][highlabel]
            except KeyError:
                log.error("Error reading bin: %s process: %s from file: %s",
                          bin, highlabel, highcardfile)
                raise

            target_yield = morph.interpolate(lowmass, low_yield, highmass,
                                             high_yield, target)
            #log.info("in bin", bin, "low yield is", low_yield,
            #"high yield is", high_yield, "=> target is ", target_yield)
            # We use the same label as lowlabel, and replace it later
            newcard.exp[bin][lowlabel] = target_yield

    log.info("Writing new card to output")
    write_card(output_stream, newcard)
コード例 #6
0
 def test_closure(self):
     new_120_file = open('vh3l_120_interpolated.txt', 'w')
     new_120 = interpolate_card(new_120_file,
                                'vh3l_110.txt', 110,
                                'vh3l_130.txt', 130,
                                120, 'VHww', 'VHtt')
     new_120_file.close()
     new_120 = read_card('vh3l_120_interpolated.txt')
コード例 #7
0
    def test_closure(self):
        www_card_orig = read_card('vh3l_120.txt')
        www_card_file = open('vh3l_cut_rewritten.txt', 'w')
        write_card(www_card_file, www_card_orig)
        www_card_file.close()
        www_card_reread = read_card('vh3l_cut_rewritten.txt')

        self.assertEqual(www_card_reread.exp['ch1'], www_card_orig.exp['bin1'])
        self.assertEqual(www_card_reread.isSignal, www_card_orig.isSignal)
        self.assertEqual(sorted(www_card_reread.processes),
                         sorted(www_card_orig.processes))
        orig_systs = sorted(www_card_orig.systs, key=lambda x: x[0])
        new_systs = sorted(www_card_reread.systs, key=lambda x: x[0])
        for orig_syst, new_syst in zip(orig_systs, new_systs):
            # Format
            # name, shape, type, ?, bin-process map
            self.assertEqual(orig_syst[:4], new_syst[:4])
            self.assertEqual(orig_syst[4]['bin1'], new_syst[4]['ch1'])
コード例 #8
0
import pprint
import uncertainties
import FinalStateAnalysis.StatTools.cardreader as cardreader

card = cardreader.read_card("combo/comb_leptonic_120.txt")
systs = cardreader.create_uncertainties(card)

analyses = {
    'TT' : {
        'channels' : [
            'ch1_ch1_' + x for x in [
                'mmt_mumu_final_MuTauMass',
                'emt_emu_final_SubleadingMass',
            ]
        ],
        'names' : {
            'tt_signal' : 'VH120',
            'ww_signal' : 'VH120WW',
            'WZ' : 'WZ',
            'ZZ' : 'ZZ',
            'fakes' : 'fakes',
        },
    },
    'WW' : {
        'channels' : [
            'ch2'
        ],
        'names' : {
            'tt_signal' : 'VHtt',
            'ww_signal' : 'VHww',
            'WZ' : 'WZ',
コード例 #9
0
from FinalStateAnalysis.StatTools.cardreader import read_card
from FinalStateAnalysis.StatTools.cardwriter import write_card
import sys

parser = argparse.ArgumentParser()

parser.add_argument('card', help='Input card')
parser.add_argument('toremove', nargs='+', metavar='systematic', type=str,
                    help='Systematics to remove.  Can specify wildcards.')

log = logging.getLogger('remove_systematics')

if __name__ == "__main__":
    args = parser.parse_args()
    logging.basicConfig(stream=sys.stderr, level=logging.INFO)
    input = read_card(args.card)

    clean_systematics = []

    filters_applied = set([])

    for syst in input.systs:
        is_clean = True
        for filter in args.toremove:
            if fnmatch.fnmatchcase(syst[0], filter):
                is_clean = False
                filters_applied.add(filter)
                break
        if not is_clean:
            log.info("Removing systematic: %s", syst[0])
        else:
コード例 #10
0
    expected = card.exp[bin][process]
    total_relative_error = 1
    for syst in card.systs:
        error_object = my_systs[syst[0]]
        error = syst[4][bin][process]
        if error and error != 1:
            if isinstance(error, list):  # up/down format
                error = error[1]
            percent_error = error - 1
            multiplier = 1 + percent_error * error_object
            total_relative_error = total_relative_error * multiplier
    return expected, (total_relative_error)


for mass in range(110, 165, 10):
    card = read_card("combo/comb_leptonic_%i.txt" % mass)

    wh_yield = lumi * cross_section("WH", mass, 7)
    zh_yield = lumi * cross_section("ZH", mass, 7)

    wh_www_yield = wh_yield * branching_ratio("WW", mass)

    wh_wtt_yield = wh_yield * branching_ratio("tautau", mass)

    zh_ztt_yield = zh_yield * branching_ratio("tautau", mass)

    zh_zww_yield = zh_yield * branching_ratio("WW", mass)

    wh_www_yield_leptons = wh_www_yield * cube(w_to_any_lepton)
    wh_wtt_yield_leptons = wh_wtt_yield * w_to_any_lepton
    zh_zww_yield_leptons = zh_zww_yield * square(w_to_any_lepton) * z_to_any_lepton
コード例 #11
0
        www_card_orig = read_card('vh3l_120.txt')
        www_card_file = open('vh3l_cut_rewritten.txt', 'w')
        write_card(www_card_file, www_card_orig)
        www_card_file.close()
        www_card_reread = read_card('vh3l_cut_rewritten.txt')

        self.assertEqual(
            www_card_reread.exp['ch1'], www_card_orig.exp['bin1']
        )
        self.assertEqual(
            www_card_reread.isSignal, www_card_orig.isSignal
        )
        self.assertEqual(
            sorted(www_card_reread.processes), sorted(www_card_orig.processes)
        )
        orig_systs = sorted(www_card_orig.systs, key=lambda x: x[0])
        new_systs = sorted(www_card_reread.systs, key=lambda x: x[0])
        for orig_syst, new_syst in zip(orig_systs, new_systs):
            # Format
            # name, shape, type, ?, bin-process map
            self.assertEqual(
                orig_syst[:4], new_syst[:4]
            )
            self.assertEqual(
                orig_syst[4]['bin1'], new_syst[4]['ch1']
            )

if __name__ == '__main__':
    card = read_card('vh3l_120.txt')
    unittest.main()
コード例 #12
0
from FinalStateAnalysis.StatTools.cardreader import read_card
from FinalStateAnalysis.StatTools.cardwriter import write_card
import unittest


class TestCardParsring(unittest.TestCase):
    def test_closure(self):
        www_card_orig = read_card('vh3l_120.txt')
        www_card_file = open('vh3l_cut_rewritten.txt', 'w')
        write_card(www_card_file, www_card_orig)
        www_card_file.close()
        www_card_reread = read_card('vh3l_cut_rewritten.txt')

        self.assertEqual(www_card_reread.exp['ch1'], www_card_orig.exp['bin1'])
        self.assertEqual(www_card_reread.isSignal, www_card_orig.isSignal)
        self.assertEqual(sorted(www_card_reread.processes),
                         sorted(www_card_orig.processes))
        orig_systs = sorted(www_card_orig.systs, key=lambda x: x[0])
        new_systs = sorted(www_card_reread.systs, key=lambda x: x[0])
        for orig_syst, new_syst in zip(orig_systs, new_systs):
            # Format
            # name, shape, type, ?, bin-process map
            self.assertEqual(orig_syst[:4], new_syst[:4])
            self.assertEqual(orig_syst[4]['bin1'], new_syst[4]['ch1'])


if __name__ == '__main__':
    card = read_card('vh3l_120.txt')
    unittest.main()
コード例 #13
0
 def test_closure(self):
     new_120_file = open('vh3l_120_interpolated.txt', 'w')
     new_120 = interpolate_card(new_120_file, 'vh3l_110.txt', 110,
                                'vh3l_130.txt', 130, 120, 'VHww', 'VHtt')
     new_120_file.close()
     new_120 = read_card('vh3l_120_interpolated.txt')