コード例 #1
0
def getsampleset(channel, era, **kwargs):
    verbosity = LOG.getverbosity(kwargs)
    year = getyear(era)  # get integer year
    tag = kwargs.get('tag', "")
    table = kwargs.get('table', True)  # print sample set table
    setera(era)  # set era for plot style and lumi normalization

    negative_fractions = {
        "DYJetsToLL_M-50": 0.0004,
        "WJetsToLNu": 0.0004,
        "WW_TuneCP5_13TeV-pythia8":
        0.0,  # <-- no adaption of effective events needed
        "WZ_TuneCP5_13TeV-pythia8":
        0.0,  # <-- no adaption of effective events needed
        "ZZ_TuneCP5_13TeV-pythia8":
        0.0,  # <-- no adaption of effective events needed
        "ST_t-channel_top": 0.033,
        "ST_t-channel_antitop": 0.031,
        "ST_tW_top": 0.002,
        "ST_tW_antitop": 0.002,
        "TTTo2L2Nu": 0.004,
        "TTToHadronic": 0.004,
        "TTToSemiLeptonic": 0.004,
    }

    # SM BACKGROUND MC SAMPLES
    expsamples = [  # table of MC samples to be converted to Sample objects
        # GROUP NAME                     TITLE                 XSEC [pb]      effective NEVENTS = simulated NEVENTS * ( 1  - 2 * negative fraction)

        # Cross-secitons: https://twiki.cern.ch/twiki/bin/viewauth/CMS/StandardModelCrossSectionsat13TeV, Z/a* (50)
        ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 6077.22, {
            "nevts":
            100194597 * (1.0 - 2 * negative_fractions["DYJetsToLL_M-50"])
        }),

        # Cross-sections: https://twiki.cern.ch/twiki/bin/viewauth/CMS/StandardModelCrossSectionsat13TeV, Total W
        ('WJ', "WJetsToLNu", "W + jets", 3 * 20508.9, {
            "nevts": 71072199 * (1.0 - 2 * negative_fractions["WJetsToLNu"])
        }),

        # Cross-sections: https://twiki.cern.ch/twiki/bin/viewauth/CMS/StandardModelCrossSectionsat13TeV, W+ W-
        ('VV', "WW", "WW", 118.7, {
            "nevts": 7850000
        }),

        # Cross-sections: from generator (https://cms-gen-dev.cern.ch/xsdb with 'process_name=WZ_TuneCP5_13TeV-pythia8')
        ('VV', "WZ", "WZ", 27.6, {
            "nevts": 3885000
        }),

        # Cross-sections: from generator (https://cms-gen-dev.cern.ch/xsdb with 'process_name=ZZ_TuneCP5_13TeV-pythia8')
        ('VV', "ZZ", "ZZ", 12.14, {
            "nevts": 1979000
        }),

        # Cross-sections: # https://twiki.cern.ch/twiki/bin/viewauth/CMS/SingleTopSigma
        ('ST', "ST_t-channel_top", "ST t-channel t", 136.02, {
            "nevts":
            154307600 * (1.0 - 2 * negative_fractions["ST_t-channel_top"])
        }),
        ('ST', "ST_t-channel_antitop", "ST t-channel at", 80.95, {
            "nevts":
            79090800 * (1.0 - 2 * negative_fractions["ST_t-channel_antitop"])
        }),
        ('ST', "ST_tW_top", "ST tW", 35.85, {
            "nevts": 9598000 * (1.0 - 2 * negative_fractions["ST_tW_top"])
        }),
        ('ST', "ST_tW_antitop", "ST atW", 35.85, {
            "nevts": 7623000 * (1.0 - 2 * negative_fractions["ST_tW_antitop"])
        }),

        # Cross-sections: https://twiki.cern.ch/twiki/bin/view/LHCPhysics/TtbarNNLO#Top_quark_pair_cross_sections_at, m_top = 172.5 GeV + PDG for W boson decays
        ('TT', "TTTo2L2Nu", "ttbar 2l2#nu", 831.76 * (3 * 0.1086)**2, {
            "nevts": 64310000 * (1.0 - 2 * negative_fractions["TTTo2L2Nu"])
        }),
        ('TT', "TTToHadronic", "ttbar hadronic",
         831.76 * 2 * (3 * 0.1086) * (0.6741), {
             "nevts":
             199524000 * (1.0 - 2 * negative_fractions["TTToHadronic"])
         }),
        ('TT', "TTToSemiLeptonic", "ttbar semileptonic", 831.76 * (0.6741)**2,
         {
             "nevts":
             199925998 * (1.0 - 2 * negative_fractions["TTToSemiLeptonic"])
         }),
    ]

    # OBSERVED DATA SAMPLES
    if 'mutau' in channel: dataset = "SingleMuon_Run%d?" % year
    elif 'etau' in channel: dataset = "SingleElectron_Run%d?" % year
    else:
        LOG.throw(IOError, "Did not recognize channel %r!" % (channel))
    datasample = ('Data', dataset)  # Data for chosen channel

    # SAMPLE SET
    # TODO section 5: This weight needs to be extended with correction weights common to all simulated samples (MC)
    weight = "genweight/abs(genweight)"  # normalize weight, since sometimes the generator cross-section is contained in it.
    kwargs.setdefault('weight', weight)  # common weight for MC
    sampleset = _getsampleset(datasample,
                              expsamples,
                              channel=channel,
                              era=era,
                              **kwargs)

    # JOIN
    # Note: titles are set via STYLE.sample_titles
    sampleset.join('WW', 'WZ', 'ZZ', name='VV')  # Diboson
    sampleset.join('VV', 'WJ', name='EWK')  # Electroweak

    sampleset.join('TT', name='TT')  # ttbar
    sampleset.join('ST', name='ST')  # single top
    sampleset.join('ST', 'TT', name='Top')  #ttbar & single top

    # SPLIT
    # TODO section 5: Check the generator matching for various samples in the flat n-tuples.
    # Is it justified to require only the tauh candidate to match to generator level hadronic tau to declare the full process with Z->tautau in mutau final state?
    # What is the major contribution from Drell-Yan to genmatch_2!=5? How does this look like for other processes?
    GMR = "genmatch_2==5"
    GMO = "genmatch_2!=5"
    sampleset.split('DY', [('ZTT', GMR), ('ZL', GMO)])
    sampleset.split('Top', [('TopT', GMR), ('TopJ', GMO)])
    sampleset.split('EWK', [('EWKT', GMR), ('EWKJ', GMO)])

    if table:
        sampleset.printtable(merged=True, split=True)
    return sampleset
コード例 #2
0
ファイル: samples.py プロジェクト: cms-tau-pog/TauFW
def getsampleset(channel, era, **kwargs):
    verbosity = LOG.getverbosity(kwargs)
    year = getyear(era)  # get integer year
    dysample = kwargs.get('dy', "jet")
    dyweight = kwargs.get('dyweight', "")
    split = kwargs.get('split',
                       [])  # split samples (e.g. DY) into genmatch components
    join = kwargs.get('join', ['VV', 'Top'])  # join samples (e.g. VV, top)
    tag = kwargs.get('tag', "")
    table = kwargs.get('table', True)  # print sample set table
    setera(era)  # set global era for plot style and lumi-xsec normalization

    if 'UL2016' in era and 'VFP' not in era:  # join pre-/post-VFP into full UL2016
        kwargs['table'] = False
        kwargs1 = kwargs.copy()  # prevent overwriting
        kwargs2 = kwargs.copy()  # prevent overwriting
        sampleset1 = getsampleset(channel, era + "_preVFP", **kwargs1)
        sampleset2 = getsampleset(channel, era + "_postVFP", **kwargs2)
        setera(era)  # reset era for plot style and lumi-xsec normalization
        sampleset = sampleset1 + sampleset2  # merge samples
        if table:
            sampleset.printtable(merged=True, split=True)
        return sampleset

    # SM BACKGROUND MC SAMPLES
    xsec_dy_lo = 4963.0  # MadGraph (LO)
    xsec_dy_nlo = 6529.0  # aMC@NLO
    xsec_dy_nnlo = 3 * 2025.74  # FEWZ (NNLO)
    k_lo = xsec_dy_nnlo / xsec_dy_lo
    k_nlo = 1.  #xsec_dy_nnlo/xsec_dy_nlo
    if 'UL' in era:
        expsamples = [  # table of MC samples to be converted to Sample objects
            # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
            #( 'DY', "DYJetsToLL_M-10to50",   "Drell-Yan 10-50",    18610.0  ),
            ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 5343.0, {
                'extraweight': dyweight
            }),
            ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 877.8, {
                'extraweight': dyweight
            }),
            ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 304.4, {
                'extraweight': dyweight
            }),
            ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 111.5, {
                'extraweight': dyweight
            }),
            ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 44.05, {
                'extraweight': dyweight
            }),
            ###( 'DY', "DYJetsToMuTauh_M-50",   "DYJetsToMuTauh_M-50", 5343.0, {'extraweight': dyweight} ),
            ('WJ', "WJetsToLNu", "W + jets", 52940.0),
            ('WJ', "W1JetsToLNu", "W + 1J", 8104.0),
            ('WJ', "W2JetsToLNu", "W + 2J", 2793.0),
            ('WJ', "W3JetsToLNu", "W + 3J", 992.5),
            ('WJ', "W4JetsToLNu", "W + 4J", 544.3),
            ('VV', "WW", "WW", 75.88),
            ('VV', "WZ", "WZ", 27.6),
            ('VV', "ZZ", "ZZ", 12.14),
            ('ST', "ST_t-channel_top", "ST t-channel t", 136.02),
            ('ST', "ST_t-channel_antitop", "ST t-channel at", 80.95),
            ('ST', "ST_tW_top", "ST tW", 35.85),
            ('ST', "ST_tW_antitop", "ST atW", 35.85),
            ('TT', "TTTo2L2Nu", "ttbar 2l2#nu", 88.29, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToHadronic", "ttbar hadronic", 377.96, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToSemiLeptonic", "ttbar semileptonic", 365.35, {
                'extraweight': 'ttptweight'
            }),
        ]
    else:
        if era == '2016':
            expsamples = [
            ]  # table of MC samples to be converted to Sample objects
            if 'mass' in dysample:
                expsamples += [
                    # GROUP NAME                       TITLE                   XSEC             EXTRA OPTIONS
                    ('DY', "DYJetsToLL_M-100to200", "Drell-Yan 100to200",
                     k_nlo * 226.6, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-200to400", "Drell-Yan 200to400",
                     k_nlo * 7.77, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-400to500", "Drell-Yan 400to500",
                     k_nlo * 0.4065, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-500to700", "Drell-Yan 500to700",
                     k_nlo * 0.2334, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-700to800", "Drell-Yan 700to800",
                     k_nlo * 0.03614, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-800to1000", "Drell-Yan 800to1000",
                     k_nlo * 0.03047, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-1000to1500", "Drell-Yan 1000to1500",
                     k_nlo * 0.01636, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-1500to2000", "Drell-Yan 1500to2000",
                     k_nlo * 0.00218, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-2000to3000", "Drell-Yan 2000to3000",
                     k_nlo * 0.0005156, {
                         'extraweight': dyweight
                     }),
                ]
            else:
                expsamples += [
                    # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
                    ('DY', "DYJetsToLL_M-10to50", "Drell-Yan 10-50", 18610.0, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 4963.0, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 1012.0, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 334.7, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 102.3, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 54.52, {
                        'extraweight': dyweight
                    }),
                ]
            expsamples += [
                # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
                ('WJ', "WJetsToLNu", "W + jets", 50260.0),
                ('WJ', "W1JetsToLNu", "W + 1J", 9625.0),
                ('WJ', "W2JetsToLNu", "W + 2J", 3161.0),
                ('WJ', "W3JetsToLNu", "W + 3J", 954.8),
                ('WJ', "W4JetsToLNu", "W + 4J", 494.6),
                ('VV', "WW", "WW", 75.88),
                ('VV', "WZ", "WZ", 27.6),
                ('VV', "ZZ", "ZZ", 12.14),
                ('ST', "ST_t-channel_top", "ST t-channel t", 136.02),
                ('ST', "ST_t-channel_antitop", "ST t-channel at", 80.95),
                ('ST', "ST_tW_top", "ST tW", 35.85),
                ('ST', "ST_tW_antitop", "ST atW", 35.85),
                ('TT', "TT", "ttbar", 831.76, {
                    'extraweight': 'ttptweight'
                }),
            ]
        elif era == '2017':
            expsamples = [
            ]  # table of MC samples to be converted to Sample objects
            if 'mass' in dysample:
                expsamples += [
                    # GROUP NAME                       TITLE                   XSEC             EXTRA OPTIONS
                    ('DY', "DYJetsToLL_M-100to200", "Drell-Yan 100to200",
                     k_nlo * 247.8, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-200to400", "Drell-Yan 200to400",
                     k_nlo * 8.502, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-400to500", "Drell-Yan 400to500",
                     k_nlo * 0.4514, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-500to700", "Drell-Yan 500to700",
                     k_nlo * 0.2558, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-700to800", "Drell-Yan 700to800",
                     k_nlo * 0.04023, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-800to1000", "Drell-Yan 800to1000",
                     k_nlo * 0.03406, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-1000to1500", "Drell-Yan 1000to1500",
                     k_nlo * 0.01828, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-1500to2000", "Drell-Yan 1500to2000",
                     k_nlo * 0.002367, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-2000to3000", "Drell-Yan 2000to3000",
                     k_nlo * 0.0005409, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-3000toInf", "Drell-Yan 3000toInf",
                     k_nlo * 3.048e-05, {
                         'extraweight': dyweight
                     }),
                ]
            else:
                expsamples += [
                    # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
                    ('DY', "DYJetsToLL_M-10to50", "Drell-Yan 10-50", 18610.0, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 5343.0, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 877.8, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 304.4, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 111.5, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 44.05, {
                        'extraweight': dyweight
                    }),
                ]
            expsamples += [
                # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
                ('WJ', "WJetsToLNu", "W + jets", 52940.0),
                ('WJ', "W1JetsToLNu", "W + 1J", 8104.0),
                ('WJ', "W2JetsToLNu", "W + 2J", 2793.0),
                #( 'WJ', "W3JetsToLNu",           "W + 3J",               992.5  ),
                ('WJ', "W4JetsToLNu", "W + 4J", 544.3),
                ('VV', "WW", "WW", 75.88),
                ('VV', "WZ", "WZ", 27.6),
                ('VV', "ZZ", "ZZ", 12.14),
                ('ST', "ST_t-channel_top", "ST t-channel t", 136.02),
                ('ST', "ST_t-channel_antitop", "ST t-channel at", 80.95),
                ('ST', "ST_tW_top", "ST tW", 35.85),
                ('ST', "ST_tW_antitop", "ST atW", 35.85),
                ('TT', "TTTo2L2Nu", "ttbar 2l2#nu", 88.29, {
                    'extraweight': 'ttptweight'
                }),
                ('TT', "TTToHadronic", "ttbar hadronic", 377.96, {
                    'extraweight': 'ttptweight'
                }),
                ('TT', "TTToSemiLeptonic", "ttbar semileptonic", 365.35, {
                    'extraweight': 'ttptweight'
                }),
            ]
        elif era == '2018':
            expsamples = [
            ]  # table of MC samples to be converted to Sample objects
            if 'mass' in dysample:
                expsamples += [
                    # GROUP NAME                       TITLE                   XSEC             EXTRA OPTIONS
                    ('DY', "DYJetsToLL_M-100to200", "Drell-Yan 100to200",
                     k_nlo * 247.8, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-200to400", "Drell-Yan 200to400",
                     k_nlo * 8.502, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-400to500", "Drell-Yan 400to500",
                     k_nlo * 0.4514, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-500to700", "Drell-Yan 500to700",
                     k_nlo * 0.2558, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-700to800", "Drell-Yan 700to800",
                     k_nlo * 0.04023, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-800to1000", "Drell-Yan 800to1000",
                     k_nlo * 0.03406, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-1000to1500", "Drell-Yan 1000to1500",
                     k_nlo * 0.01828, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-1500to2000", "Drell-Yan 1500to2000",
                     k_nlo * 0.002367, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-2000to3000", "Drell-Yan 2000to3000",
                     k_nlo * 0.0005409, {
                         'extraweight': dyweight
                     }),
                    ('DY', "DYJetsToLL_M-3000toInf", "Drell-Yan 3000toInf",
                     k_nlo * 3.048e-05, {
                         'extraweight': dyweight
                     }),
                ]
            else:
                expsamples += [
                    # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
                    ('DY', "DYJetsToLL_M-10to50", "Drell-Yan 10-50", 18610.0, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 5343.0, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 877.8, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 304.4, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 111.5, {
                        'extraweight': dyweight
                    }),
                    ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 44.05, {
                        'extraweight': dyweight
                    }),
                ]
            expsamples += [
                # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
                ('WJ', "WJetsToLNu", "W + jets", 52940.0),
                ('WJ', "W1JetsToLNu", "W + 1J", 8104.0),
                ('WJ', "W2JetsToLNu", "W + 2J", 2793.0),
                ('WJ', "W3JetsToLNu", "W + 3J", 992.5),
                ('WJ', "W4JetsToLNu", "W + 4J", 544.3),
                ('VV', "WW", "WW", 75.88),
                ('VV', "WZ", "WZ", 27.6),
                ('VV', "ZZ", "ZZ", 12.14),
                ('ST', "ST_t-channel_top", "ST t-channel t", 136.02),
                ('ST', "ST_t-channel_antitop", "ST t-channel at", 80.95),
                ('ST', "ST_tW_top", "ST tW", 35.85),
                ('ST', "ST_tW_antitop", "ST atW", 35.85),
                ('TT', "TTTo2L2Nu", "ttbar 2l2#nu", 88.29, {
                    'extraweight': 'ttptweight'
                }),
                ('TT', "TTToHadronic", "ttbar hadronic", 377.96, {
                    'extraweight': 'ttptweight'
                }),
                ('TT', "TTToSemiLeptonic", "ttbar semileptonic", 365.35, {
                    'extraweight': 'ttptweight'
                }),
            ]
        else:
            LOG.throw(IOError, "Did not recognize era %r!" % (era))

    # OBSERVED DATA SAMPLES
    dataset = "SingleMuon_Run%d?" % year
    datasample = ('Data', dataset)  # GROUP, NAME

    # SAMPLE SET
    weight = "genweight*trigweight*puweight*idisoweight_1*idisoweight_2"
    fname = "$PICODIR/$SAMPLE_$CHANNEL$TAG.root"
    kwargs.setdefault('weight', weight)  # common weight for MC
    kwargs.setdefault('fname', fname)  # default filename pattern
    sampleset = _getsampleset(datasample,
                              expsamples,
                              channel=channel,
                              era=era,
                              **kwargs)

    # JOIN
    ZMM = STYLE.sample_titles.get('ZMM', "Z -> mumu")  # title
    # Note: titles are set via STYLE.sample_titles
    sampleset.stitch("W*Jets", incl='WJ', name='WJ')  # W + jets
    if 'mass' not in dysample:
        sampleset.stitch("DY*J*M-10to50", incl='DYJ', name="DY_M10to50")
        sampleset.stitch("DY*J*M-50", incl='DYJ',
                         name='DY')  # Drell-Yan, M > 50 GeV
    sampleset.join('DY', name='DY')  # Drell-Yan, M < 50 GeV + M > 50 GeV
    if 'VV' in join:
        sampleset.join('VV', 'WZ', 'WW', 'ZZ', name='VV')  # Diboson
    if 'TT' in join and era != 'year':
        sampleset.join('TT', name='TT')  # ttbar
    if 'ST' in join:
        sampleset.join('ST', name='ST')  # single top
    if 'Top' in join:
        sampleset.join('TT', 'ST', name='Top')  # ttbar + single top

    # SPLIT
    GMR = "genmatch_1>0 && genmatch_2>0"
    GMF = "(genmatch_1<=0 || genmatch_2<=0)"
    if 'DY' in split:
        sampleset.split('DY', [
            ('ZMM', ZMM, GMR),
            ('ZJ', GMF),
        ])
    if 'TT' in split:
        sampleset.split('TT', [
            ('TMM', GMR),
            ('TTJ', GMF),
        ])

    if table:
        sampleset.printtable(merged=True, split=True)
    return sampleset
コード例 #3
0
ファイル: plot_compare.py プロジェクト: cms-tau-pog/TauFW
def getsampleset_simple(channel, era, **kwargs):
    """Simplified version of Plotter/config/samples.py:getsampleset"""
    fname = "$PICODIR/$SAMPLE_$CHANNEL$TAG.root"
    if 'mutau' in channel:
        weight = "genweight*trigweight*puweight*idisoweight_1*idweight_2*ltfweight_2"
    else:
        weight = "genweight*trigweight*puweight*idweight_1*idweight_2*ltfweight_1*ltfweight_2"
    fname = kwargs.get('fname',
                       fname) or fname  # file name pattern of pico files
    weight = kwargs.get('weight', weight)
    tag = kwargs.get('tag', "")
    table = kwargs.get('table', True)  # print sample set table
    setera(era)  # set era for plot style and lumi-xsec normalization
    year = getyear(era)  # get integer year
    if 'UL' in era:  # UltraLegacy
        expsamples = [  # table of MC samples to be converted to Sample objects
            # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
            ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 5343.0, {
                'extraweight': 'zptweight'
            }),  # apply k-factor in stitching
            ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 877.8, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 304.4, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 111.5, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 44.05, {
                'extraweight': 'zptweight'
            }),
            ('WJ', "WJetsToLNu", "W + jets", 52940.0),
            ('WJ', "W1JetsToLNu", "W + 1J", 8104.0),
            ('WJ', "W2JetsToLNu", "W + 2J", 2793.0),
            ('WJ', "W3JetsToLNu", "W + 3J", 992.5),
            ('WJ', "W4JetsToLNu", "W + 4J", 544.3),
            ('VV', "WW", "WW", 75.88),
            ('VV', "WZ", "WZ", 27.6),
            ('VV', "ZZ", "ZZ", 12.14),
            ('ST', "ST_t-channel_top", "ST t-channel t", 136.02),
            ('ST', "ST_t-channel_antitop", "ST t-channel at", 80.95),
            ('ST', "ST_tW_top", "ST tW", 35.85),
            ('ST', "ST_tW_antitop", "ST atW", 35.85),
            ('TT', "TTTo2L2Nu", "ttbar 2l2#nu", 88.29, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToHadronic", "ttbar hadronic", 377.96, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToSemiLeptonic", "ttbar semileptonic", 365.35, {
                'extraweight': 'ttptweight'
            }),
        ]
        #if 'mutau' in channel:
        #  expsamples.append(('DY',"DYJetsToMuTauh_M-50","DYJetsToMuTauh_M-50",5343.0,{'extraweight': dyweight})) # apply correct normalization in stitching
    elif era == '2016':  # pre-UL
        expsamples = [  # table of MC samples to be converted to Sample objects
            ('DY', "DYJetsToLL_M-10to50", "Drell-Yan 10-50", 18610.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 4963.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 1012.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 334.7, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 102.3, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 54.52, {
                'extraweight': 'zptweight'
            }),
            (
                'WJ',
                "WJetsToLNu",
                "W + jets",
                50260.0,
            ),
            ('WJ', "W1JetsToLNu", "W + 1 jet", 9625.0),
            ('WJ', "W2JetsToLNu", "W + 2 jets", 3161.0),
            ('WJ', "W3JetsToLNu", "W + 3 jets", 954.8),
            ('WJ', "W4JetsToLNu", "W + 4 jets", 494.6),
            ('TT', "TT", "ttbar", 831.76, {
                'extraweight': 'ttptweight'
            }),
        ]
    elif era == '2017':  # pre-UL
        expsamples = [  # table of MC samples to be converted to Sample objects
            ('DY', "DYJetsToLL_M-10to50", "Drell-Yan 10-50", 18610.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 4963.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 1012.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 334.7, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 102.3, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 54.52, {
                'extraweight': 'zptweight'
            }),
            (
                'WJ',
                "WJetsToLNu",
                "W + jets",
                50260.0,
            ),
            ('WJ', "W1JetsToLNu", "W + 1 jet", 9625.0),
            ('WJ', "W2JetsToLNu", "W + 2 jets", 3161.0),
            ('WJ', "W3JetsToLNu", "W + 3 jets", 954.8),
            ('WJ', "W4JetsToLNu", "W + 4 jets", 494.6),
            ('TT', "TTTo2L2Nu", "ttbar 2l2#nu", 88.29, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToHadronic", "ttbar hadronic", 377.96, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToSemiLeptonic", "ttbar semileptonic", 365.35, {
                'extraweight': 'ttptweight'
            }),
        ]
    elif era == '2018':  # pre-UL
        expsamples = [  # table of MC samples to be converted to Sample objects
            ('DY', "DYJetsToLL_M-10to50", "Drell-Yan 10-50", 18610.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 4963.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 1012.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 334.7, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 102.3, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 54.52, {
                'extraweight': 'zptweight'
            }),
            (
                'WJ',
                "WJetsToLNu",
                "W + jets",
                50260.0,
            ),
            ('WJ', "W1JetsToLNu", "W + 1 jet", 9625.0),
            ('WJ', "W2JetsToLNu", "W + 2 jets", 3161.0),
            ('WJ', "W3JetsToLNu", "W + 3 jets", 954.8),
            ('WJ', "W4JetsToLNu", "W + 4 jets", 494.6),
            ('TT', "TTTo2L2Nu", "ttbar 2l2#nu", 88.29, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToHadronic", "ttbar hadronic", 377.96, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToSemiLeptonic", "ttbar semileptonic", 365.35, {
                'extraweight': 'ttptweight'
            }),
        ]
    else:
        LOG.throw(IOError, "Did not recognize era %r!" % (era))
    datasamples = { # table of data samples (per channel) to be converted to Sample objects
      'mutau':  ('Data', "SingleMuon_Run%s?"%year),
      'etau':   ('Data', "SingleElectron_Run%s?"%year),
      'tautau': ('Data', "Tau_Run%s?"%year),
    }

    # SAMPLE SET
    sampleset = _getsampleset(datasamples,
                              expsamples,
                              channel=channel,
                              era=era,
                              weight=weight,
                              file=fname)
    sampleset.stitch("DY*J*M-50", incl='DYJ', name="DY_M50", npart='NUP')
    sampleset.stitch("W*Jets", incl='WJ', name='WJ', npart='NUP')
    if era != '2016':
        sampleset.join('TT')
    sampleset.join('DY', name='DY')
    sampleset.printtable()
    return sampleset
コード例 #4
0
def getsampleset(channel, era, **kwargs):
    verbosity = LOG.getverbosity(kwargs)
    year = getyear(era)  # get integer year
    split = kwargs.get(
        'split', ['DY'])  # split samples (e.g. DY) into genmatch components
    join = kwargs.get('join', ['VV', 'Top'])  # join samples (e.g. VV, top)
    tag = kwargs.get('tag', "")
    table = kwargs.get('table', True)  # print sample set table
    setera(era)  # set era for plot style and lumi-xsec normalization

    # SM BACKGROUND MC SAMPLES
    if era == '2016':
        expsamples = [  # table of MC samples to be converted to Sample objects
            # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
            ('DY', "DYJetsToLL_M-10to50", "Drell-Yan 10-50", 18610.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 4963.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 1012.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 334.7, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 102.3, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 54.52, {
                'extraweight': 'zptweight'
            }),
            ('WJ', "WJetsToLNu", "W + jets", 50260.0),
            ('WJ', "W1JetsToLNu", "W + 1J", 9625.0),
            ('WJ', "W2JetsToLNu", "W + 2J", 3161.0),
            ('WJ', "W3JetsToLNu", "W + 3J", 954.8),
            ('WJ', "W4JetsToLNu", "W + 4J", 494.6),
            ('VV', "WW", "WW", 75.88),
            ('VV', "WZ", "WZ", 27.6),
            ('VV', "ZZ", "ZZ", 12.14),
            ('ST', "ST_t-channel_top", "ST t-channel t", 136.02),
            ('ST', "ST_t-channel_antitop", "ST t-channel at", 80.95),
            ('ST', "ST_tW_top", "ST tW", 35.85),
            ('ST', "ST_tW_antitop", "ST atW", 35.85),
            ('TT', "TT", "ttbar", 831.76, {
                'extraweight': 'ttptweight'
            }),
        ]
    elif era == '2017':
        expsamples = [  # table of MC samples to be converted to Sample objects
            # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
            ('DY', "DYJetsToLL_M-10to50", "Drell-Yan 10-50", 18610.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 5343.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 877.8, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 304.4, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 111.5, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 44.05, {
                'extraweight': 'zptweight'
            }),
            ('WJ', "WJetsToLNu", "W + jets", 52940.0),
            ('WJ', "W1JetsToLNu", "W + 1J", 8104.0),
            ('WJ', "W2JetsToLNu", "W + 2J", 2793.0),
            ('WJ', "W3JetsToLNu", "W + 3J", 992.5),
            ('WJ', "W4JetsToLNu", "W + 4J", 544.3),
            ('VV', "WW", "WW", 75.88),
            ('VV', "WZ", "WZ", 27.6),
            ('VV', "ZZ", "ZZ", 12.14),
            ('ST', "ST_t-channel_top", "ST t-channel t", 136.02),
            ('ST', "ST_t-channel_antitop", "ST t-channel at", 80.95),
            ('ST', "ST_tW_top", "ST tW", 35.85),
            ('ST', "ST_tW_antitop", "ST atW", 35.85),
            ('TT', "TTTo2L2Nu", "ttbar 2l2#nu", 88.29, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToHadronic", "ttbar hadronic", 377.96, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToSemiLeptonic", "ttbar semileptonic", 365.35, {
                'extraweight': 'ttptweight'
            }),
        ]
    elif era == 'UL2017':
        expsamples = [  # table of MC samples to be converted to Sample objects
            # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
            #( 'DY', "DYJetsToLL_M-10to50",   "Drell-Yan 10-50",    18610.0, {'extraweight': 'zptweight'} ),
            ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 5343.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 877.8, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 304.4, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 111.5, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 44.05, {
                'extraweight': 'zptweight'
            }),
            ('WJ', "WJetsToLNu", "W + jets", 52940.0),
            ('WJ', "W1JetsToLNu", "W + 1J", 8104.0),
            ('WJ', "W2JetsToLNu", "W + 2J", 2793.0),
            ('WJ', "W3JetsToLNu", "W + 3J", 992.5),
            ('WJ', "W4JetsToLNu", "W + 4J", 544.3),
            ('VV', "WW", "WW", 75.88),
            ('VV', "WZ", "WZ", 27.6),
            ('VV', "ZZ", "ZZ", 12.14),
            ('ST', "ST_t-channel_top", "ST t-channel t", 136.02),
            ('ST', "ST_t-channel_antitop", "ST t-channel at", 80.95),
            ('ST', "ST_tW_top", "ST tW", 35.85),
            ('ST', "ST_tW_antitop", "ST atW", 35.85),
            ('TT', "TTTo2L2Nu", "ttbar 2l2#nu", 88.29, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToHadronic", "ttbar hadronic", 377.96, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToSemiLeptonic", "ttbar semileptonic", 365.35, {
                'extraweight': 'ttptweight'
            }),
        ]
    elif era == '2018':
        expsamples = [  # table of MC samples to be converted to Sample objects
            # GROUP NAME                     TITLE                 XSEC      EXTRA OPTIONS
            ('DY', "DYJetsToLL_M-10to50", "Drell-Yan 10-50", 18610.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DYJetsToLL_M-50", "Drell-Yan 50", 4963.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY1JetsToLL_M-50", "Drell-Yan 1J 50", 1012.0, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY2JetsToLL_M-50", "Drell-Yan 2J 50", 334.7, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY3JetsToLL_M-50", "Drell-Yan 3J 50", 102.3, {
                'extraweight': 'zptweight'
            }),
            ('DY', "DY4JetsToLL_M-50", "Drell-Yan 4J 50", 54.52, {
                'extraweight': 'zptweight'
            }),
            ('WJ', "WJetsToLNu", "W + jets", 52940.0),
            ('WJ', "W1JetsToLNu", "W + 1J", 8104.0),
            ('WJ', "W2JetsToLNu", "W + 2J", 2793.0),
            ('WJ', "W3JetsToLNu", "W + 3J", 992.5),
            ('WJ', "W4JetsToLNu", "W + 4J", 544.3),
            ('VV', "WW", "WW", 75.88),
            ('VV', "WZ", "WZ", 27.6),
            ('VV', "ZZ", "ZZ", 12.14),
            ('ST', "ST_t-channel_top", "ST t-channel t", 136.02),
            ('ST', "ST_t-channel_antitop", "ST t-channel at", 80.95),
            ('ST', "ST_tW_top", "ST tW", 35.85),
            ('ST', "ST_tW_antitop", "ST atW", 35.85),
            ('TT', "TTTo2L2Nu", "ttbar 2l2#nu", 88.29, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToHadronic", "ttbar hadronic", 377.96, {
                'extraweight': 'ttptweight'
            }),
            ('TT', "TTToSemiLeptonic", "ttbar semileptonic", 365.35, {
                'extraweight': 'ttptweight'
            }),
        ]
    else:
        LOG.throw(IOError, "Did not recognize era %r!" % (era))

    # OBSERVED DATA SAMPLES
    if 'tautau' in channel: dataset = "Tau_Run%d?" % year
    elif 'mutau' in channel: dataset = "SingleMuon_Run%d?" % year
    elif 'etau' in channel:
        dataset = "EGamma_Run%d?" % year if year == 2018 else "SingleElectron_Run%d?" % year
    elif 'mumu' in channel:
        dataset = "SingleMuon_Run%d?" % year
    elif 'emu' in channel:
        dataset = "SingleMuon_Run%d?" % year
    elif 'ee' in channel:
        dataset = "EGamma_Run%d?" % year if year == 2018 else "SingleElectron_Run%d?" % year
    else:
        LOG.throw(IOError, "Did not recognize channel %r!" % (channel))
    datasample = ('Data', dataset)  # GROUP, NAME

    # SAMPLE SET
    weight = "genweight*trigweight*puweight*idisoweight_1*idweight_2"
    if era == 'UL2017':
        weight = weight.replace("*idweight_2", "")
    fname = "$PICODIR/$SAMPLE_$CHANNEL$TAG.root"
    kwargs.setdefault('weight', weight)  # common weight for MC
    kwargs.setdefault('fname', fname)  # default filename pattern
    sampleset = _getsampleset(datasample,
                              expsamples,
                              channel=channel,
                              era=era,
                              **kwargs)

    # JOIN
    # Note: titles are set via STYLE.sample_titles
    sampleset.stitch("W*Jets", incl='WJ', name='WJ')  # W + jets
    sampleset.stitch("DY*J*M-50", incl='DYJ',
                     name="DY_M50")  # Drell-Yan, M > 50 GeV
    #sampleset.stitch("DY*J*M-10to50", incl='DYJ', name="DY_M10to50" )
    sampleset.join('DY', name='DY')  # Drell-Yan, M < 50 GeV + M > 50 GeV
    if 'VV' in join:
        sampleset.join('VV', 'WZ', 'WW', 'ZZ', name='VV')  # Diboson
    if 'TT' in join and era != 'year':
        sampleset.join('TT', name='TT')  # ttbar
    if 'ST' in join:
        sampleset.join('ST', name='ST')  # single top
    if 'Top' in join:
        sampleset.join('TT', 'ST', name='Top')  # ttbar + single top

    # SPLIT
    # Note: titles are set via STYLE.sample_titles
    if split and channel.count('tau') == 1:
        ZTT = STYLE.sample_titles.get('ZTT', "Z -> %s" % channel)  # title
        if channel.count('tau') == 1:
            ZTT = ZTT.replace("{l}", "{mu}" if "mu" in channel else "{e}")
            GMR = "genmatch_2==5"
            GML = "genmatch_2>0 && genmatch_2<5"
            GMJ = "genmatch_2==0"
            GMF = "genmatch_2<5"
        elif channel.count('tau') == 2:
            ZTT = ZTT.replace("{l}", "{h}")
            GMR = "genmatch_1==5 && genmatch_2==5"
            GML = "(genmatch_1<5 || genmatch_2<5) && genmatch_1>0 && genmatch_2>0"
            GMJ = "(genmatch_1==0 || genmatch_2==0)"
            GMF = "(genmatch_1<5 || genmatch_2<5)"
        else:
            LOG.throw(IOError, "Did not recognize channel %r!" % (channel))
        if 'DY' in split:
            sampleset.split('DY', [
                ('ZTT', ZTT, GMR),
                ('ZL', GML),
                ('ZJ', GMJ),
            ])
        if 'DM' in split:  # split DY by decay modes
            samples.split('DY', [
                ('ZTT_DM0', ZTT + ", h^{#pm}", GMR + " && decayMode_2==0"),
                ('ZTT_DM1', ZTT + ", h^{#pm}h^{0}",
                 GMR + " && decayMode_2==1"),
                ('ZTT_DM10', ZTT + ", h^{#pm}h^{#mp}h^{#pm}",
                 GMR + " && decayMode_2==10"),
                ('ZTT_DM11', ZTT + ", h^{#pm}h^{#mp}h^{#pm}h^{0}",
                 GMR + " && decayMode_2==11"),
                ('ZL', GML),
                ('ZJ', GMJ),
            ])
        if 'TT' in split:
            sampleset.split('TT', [
                ('TTT', GMR),
                ('TTJ', GMF),
            ])

    if table:
        sampleset.printtable(merged=True, split=True)
    return sampleset