def __init__( self, year=2017, sigma='central' ):
     """Load data and MC pilup profiles."""
     
     assert( year in [2016,2017,2018] ), "You must choose a year from: 2016, 2017, or 2018."
     assert( sigma in ['central','up','down'] ), "You must choose a s.d. variation from: 'central', 'up', or 'down'."
     
     minbias = '69p2'
     if sigma=='down':
       minbias = '66p0168' # -4.6%
     elif sigma=='up':
       minbias = '72p3832' # +4.6%
     
     if year==2016:
       self.datafile = ensureTFile( path+'Data_PileUp_2016_%s.root'%(minbias), 'READ')
       self.mcfile   = ensureTFile( path+'MC_PileUp_2016.root', 'READ')
     elif year==2017:
       self.datafile = ensureTFile( path+'Data_PileUp_2017_%s.root'%(minbias), 'READ')
       self.mcfile   = ensureTFile( path+'MC_PileUp_2017.root', 'READ')
     else:
       self.datafile = ensureTFile( path+'Data_PileUp_2018_%s.root'%(minbias), 'READ')
       self.mcfile   = ensureTFile( path+'MC_PileUp_2018.root', 'READ')
     self.datahist = self.datafile.Get('pileup')
     self.mchist   = self.mcfile.Get('pileup')
     self.datahist.SetDirectory(0)
     self.mchist.SetDirectory(0)
     self.datahist.Scale(1./self.datahist.Integral())
     self.mchist.Scale(1./self.mchist.Integral())
     self.datafile.Close()
     self.mcfile.Close()
Exemplo n.º 2
0
    def __init__(self, year=2017, sigma='central'):
        """Load data and MC pilup profiles."""

        assert (year
                in [2016, 2017,
                    2018]), "You must choose a year from: 2016, 2017, or 2018."
        assert (
            sigma in ['central', 'up', 'down']
        ), "You must choose a s.d. variation from: 'central', 'up', or 'down'."

        if year == 2016:
            self.datafile = ensureTFile(path + 'Data_PileUp_2016_69p2.root',
                                        'READ')
            self.mcfile = ensureTFile(path + 'MC_PileUp_2016_Moriond17.root',
                                      'READ')
        if year == 2017:
            self.datafile = ensureTFile(path + 'Data_PileUp_2017_69p2.root',
                                        'READ')
            self.mcfile = ensureTFile(path + 'MC_PileUp_2017_Winter17_V2.root',
                                      'READ')
        else:
            self.datafile = ensureTFile(path + 'Data_PileUp_2018_69p2.root',
                                        'READ')
            self.mcfile = ensureTFile(path + 'MC_PileUp_2018_Autumn18.root',
                                      'READ')
        self.datahist = self.datafile.Get('pileup')
        self.mchist = self.mcfile.Get('pileup')
        self.datahist.SetDirectory(0)
        self.mchist.SetDirectory(0)
        self.datahist.Scale(1. / self.datahist.Integral())
        self.mchist.Scale(1. / self.mchist.Integral())
        self.datafile.Close()
        self.mcfile.Close()
Exemplo n.º 3
0
    def __init__(self, year=2017):
        """Load Z pT weights."""
        assert year in [
            2016, 2017, 2018
        ], "ZptCorrectionTool: You must choose a year from: 2016, 2017, or 2018."

        if year == 2016:
            filename = zptpath + "Zpt_weights_2016.root"
        elif year == 2017:
            filename = zptpath + "Zpt_weights_2017.root"
        else:
            filename = zptpath + "Zpt_weights_2018.root"

        file = ensureTFile(filename, 'READ')
        hist = file.Get('zptmass_weights')
        hist.SetDirectory(0)
        file.Close()

        self.hist = hist
        self.filename = filename
Exemplo n.º 4
0
    def __init__(self,
                 tagger,
                 wp='medium',
                 sigma='central',
                 channel='mutau',
                 year=2017):
        """Load b tag weights from CSV file."""
        print "Loading BTagWeightTool for %s (%s WP)..." % (tagger, wp)

        assert (year
                in [2016, 2017,
                    2018]), "You must choose a year from: 2016, 2017, or 2018."
        assert (tagger in [
            'CSVv2', 'DeepCSV'
        ]), "BTagWeightTool: You must choose a tagger from: CSVv2, DeepCSV!"
        assert (wp in [
            'loose', 'medium', 'tight'
        ]), "BTagWeightTool: You must choose a WP from: loose, medium, tight!"
        assert (sigma in [
            'central', 'up', 'down'
        ]), "BTagWeightTool: You must choose a WP from: central, up, down!"
        #assert(channel in ['mutau','eletau','tautau','mumu']), "BTagWeightTool: You must choose a channel from: mutau, eletau, tautau, mumu!"

        # FILE
        if year == 2016:
            if 'deep' in tagger.lower():
                csvname = path + 'DeepCSV_Moriond17_B_H.csv'
                effname = path + 'DeepCSV_2016_Moriond17_eff.root'
            else:
                csvname = path + 'CSVv2_Moriond17_B_H.csv'
                effname = path + 'CSVv2_2016_Moriond17_eff.root'
        elif year == 2017:
            if 'deep' in tagger.lower():
                csvname = path + 'DeepCSV_94XSF_V3_B_F.csv'
                effname = path + 'DeepCSV_2017_12Apr2017_eff.root'
            else:
                csvname = path + 'CSVv2_94XSF_V2_B_F.csv'
                effname = path + 'CSVv2_2017_12Apr2017_eff.root'
        elif year == 2018:
            if 'deep' in tagger.lower():
                csvname = path + 'DeepCSV_94XSF_V3_B_F.csv'
                effname = path + 'DeepCSV_2018_Autumn18_eff.root'
            else:
                csvname = path + 'CSVv2_94XSF_V2_B_F.csv'
                effname = path + 'CSVv2_2018_Autumn18_eff.root'

        # TAGGING WP
        self.wp = getattr(BTagWPs(tagger, year), wp)
        if 'deep' in tagger.lower():
            tagged = lambda e, i: e.Jet_btagDeepB[i] > self.wp
        else:
            tagged = lambda e, i: e.Jet_btagCSVV2[i] > self.wp

        # CSV READER
        op = OP_LOOSE if wp == 'loose' else OP_MEDIUM if wp == 'medium' else OP_TIGHT if wp == 'tight' else OP_RESHAPING
        type_udsg = 'incl'
        type_bc = 'comb'  # 'mujets' for QCD; 'comb' for QCD+TT
        calib = BTagCalibration(tagger, csvname)
        reader = BTagCalibrationReader(op, sigma)
        reader.load(calib, FLAV_B, type_bc)
        reader.load(calib, FLAV_C, type_bc)
        reader.load(calib, FLAV_UDSG, type_udsg)

        # EFFICIENCIES
        ptbins = array(
            'd', [10, 20, 30, 50, 70, 100, 140, 200, 300, 500, 1000, 1500])
        etabins = array('d', [-2.5, -1.5, 0.0, 1.5, 2.5])
        bins = (len(ptbins) - 1, ptbins, len(etabins) - 1, etabins)
        hists = {}
        effs = {}
        efffile = ensureTFile(effname)
        for flavor in [0, 4, 5]:
            flavor = flavorToString(flavor)
            histname = "%s_%s_%s" % (tagger, flavor, wp)
            effname = "%s/eff_%s_%s_%s" % (channel, tagger, flavor, wp)
            hists[flavor] = TH2F(histname, histname, *bins)
            hists[flavor + '_all'] = TH2F(histname + '_all', histname + '_all',
                                          *bins)
            effs[flavor] = efffile.Get(effname)
            hists[flavor].SetDirectory(0)
            hists[flavor + '_all'].SetDirectory(0)
            effs[flavor].SetDirectory(0)
        efffile.Close()

        self.tagged = tagged
        self.calib = calib
        self.reader = reader
        self.hists = hists
        self.effs = effs
Exemplo n.º 5
0
    def __init__(self, trigger, wp='medium', id='MVAv2', year=2016):
        """Load tau trigger histograms from files."""
        print "Loading TauTriggerSFs for %s (%s WP)..." % (trigger, wp)

        trigger = trigger.replace('tautau', 'ditau').replace('eletau', 'etau')
        assert (trigger
                in ['ditau', 'mutau',
                    'etau']), "Choose from: 'ditau', 'mutau', 'etau' triggers."
        assert (
            wp in ['vloose', 'loose', 'medium', 'tight', 'vtight', 'vvtight']
        ), "You must choose a WP from: vloose, loose, medium, tight, vtight, or vvtight"
        assert (
            id in ['MVAv2', 'dR0p3']
        ), "Choose from two provided ID types: 'MVAv2', 'dR0p3'. 'MVAv2' uses dR0p5, and 'dR0p3' is also an MVA-based ID."
        assert (
            id == 'MVAv2'
        ), "Tau POG is currently only providing efficiencies for MVAv2, sorry."
        assert (year
                in [2016, 2017,
                    2018]), "You must choose a year from: 2016, 2017, or 2018."
        print "Loading Efficiencies for trigger %s usingTau %s ID WP %s for year %i" % (
            trigger, id, wp, year)

        # Assume this is in CMSSW with the below path structure
        if year == 2018: year = 2017
        file = ensureTFile(
            path + '%d/tauTriggerEfficiencies%i.root' % (year, year), 'r')

        self.fit_data = {}
        self.fit_mc = {}
        self.fitUnc_data = {}
        self.fitUnc_mc = {}
        self.effEtaPhi_data = {}
        self.effEtaPhi_mc = {}
        self.effEtaPhiAvg_data = {}
        self.effEtaPhiAvg_mc = {}
        for dm in [0, 1, 10]:

            # Load the TF1s containing the analytic best-fit results.
            self.fit_data[dm] = extractTH1(
                file, '%s_%s%s_dm%d_DATA_fit' % (trigger, wp, id, dm))
            self.fit_mc[dm] = extractTH1(
                file, '%s_%s%s_dm%d_MC_fit' % (trigger, wp, id, dm))

            # Load the TH1s containing the analytic best-fit result in 1 GeV incriments and the associated uncertainty.
            self.fitUnc_data[dm] = extractTH1(
                file, '%s_%s%s_dm%d_DATA_errorBand' % (trigger, wp, id, dm))
            self.fitUnc_mc[dm] = extractTH1(
                file, '%s_%s%s_dm%d_MC_errorBand' % (trigger, wp, id, dm))

            # Load the TH2s containing the eta phi efficiency corrections
            self.effEtaPhi_data[dm] = extractTH1(
                file, '%s_%s%s_dm%d_DATA' % (trigger, wp, id, dm))
            self.effEtaPhi_mc[dm] = extractTH1(
                file, '%s_%s%s_dm%d_MC' % (trigger, wp, id, dm))

            # Eta Phi Averages
            self.effEtaPhiAvg_data[dm] = extractTH1(
                file, '%s_%s%s_dm%d_DATA_AVG' % (trigger, wp, id, dm))
            self.effEtaPhiAvg_mc[dm] = extractTH1(
                file, '%s_%s%s_dm%d_MC_AVG' % (trigger, wp, id, dm))

        file.Close()

        self.trigger = trigger
        self.year = year
        self.wp = wp
        self.id = id
    def __init__(self,
                 tagger,
                 jettype,
                 wp='loose',
                 sigma='central',
                 channel='ll',
                 year=2017):
        """Load b tag weights from CSV file."""
        #print "Loading BTagWeightTool for %s (%s WP)..."%(tagger,wp)

        assert (year
                in [2016, 2017,
                    2018]), "You must choose a year from: 2016, 2017, or 2018."
        assert (tagger in [
            'CSVv2', 'DeepCSV'
        ]), "BTagWeightTool: You must choose a tagger from: CSVv2, DeepCSV!"
        assert (wp in [
            'loose', 'medium', 'tight'
        ]), "BTagWeightTool: You must choose a WP from: loose, medium, tight!"
        assert (sigma in [
            'central', 'up', 'down'
        ]), "BTagWeightTool: You must choose a WP from: central, up, down!"
        self.jettype = jettype

        # FILE
        if year == 2016:
            csvname = path + 'DeepCSV_2016LegacySF_V1.csv'
            effname = path + 'DeepCSV_%s_2016_eff.root' % jettype
        elif year == 2017:
            csvname = path + 'DeepCSV_94XSF_V5_B_F.csv'
            effname = path + 'DeepCSV_%s_2017_eff.root' % jettype
        elif year == 2018:
            csvname = path + 'DeepCSV_102XSF_V1.csv'
            effname = path + 'DeepCSV_%s_2018_eff.root' % jettype
        # TAGGING WP
        self.wp = getattr(BTagWPs(tagger, year), wp)

        # CSV READER
        op = OP_LOOSE if wp == 'loose' else OP_MEDIUM if wp == 'medium' else OP_TIGHT if wp == 'tight' else OP_RESHAPING
        type_udsg = 'incl'
        type_bc = 'comb'  # 'mujets' for QCD; 'comb' for QCD+TT
        calib = BTagCalibration(tagger, csvname)
        reader = BTagCalibrationReader(op, sigma)
        reader.load(calib, FLAV_B, type_bc)
        reader.load(calib, FLAV_C, type_bc)
        reader.load(calib, FLAV_UDSG, type_udsg)
        self.sigma = sigma

        # EFFICIENCIES
        ptbins = array(
            'd', [10, 20, 30, 50, 70, 100, 140, 200, 300, 500, 1000, 1500])
        etabins = array('d', [-2.5, -1.5, 0.0, 1.5, 2.5])
        bins = (len(ptbins) - 1, ptbins, len(etabins) - 1, etabins)
        hists = {}
        effs = {}

        if tagger in ['CSVv2', 'DeepCSV']:
            efffile = ensureTFile(effname)
            for flavor in [0, 4, 5]:
                flavor = flavorToString(flavor)
                histname = "%s_%s_%s" % (tagger, flavor, wp)
                effname = "%s/eff_%s_%s_%s" % (channel, tagger, flavor, wp)
                hists[flavor] = TH2F(histname, histname, *bins)
                hists[flavor + '_all'] = TH2F(histname + '_all',
                                              histname + '_all', *bins)
                effs[flavor] = efffile.Get(effname)
                hists[flavor].SetDirectory(0)
                hists[flavor + '_all'].SetDirectory(0)
                effs[flavor].SetDirectory(0)
            efffile.Close()
        else:
            efffile = ensureTFile(effname)
            for flavor in [0, 4, 5]:
                flavor = flavorToString(flavor)
                histname = "%s_%s_%s" % (tagger, flavor, wp)
                effname = "%s/eff_%s_%s_%s" % (channel, tagger, flavor, wp)
                hists[flavor] = TH2F(histname, histname, *bins)
                hists[flavor + '_all'] = TH2F(histname + '_all',
                                              histname + '_all', *bins)
                #effs[flavor]         = efffile.Get(effname)
                hists[flavor].SetDirectory(0)
                hists[flavor + '_all'].SetDirectory(0)
                #effs[flavor].SetDirectory(0)
            efffile.Close()

        self.calib = calib
        self.reader = reader
        self.hists = hists
        self.effs = effs