Ejemplo n.º 1
0
    def prepare_for_events(self, reader):
        bins = np.arange(0, 200, 25)
        thresholds = [70, 90, 110]
        puBins = range(0, 50, 10) + [999]

        self.efficiencies = EfficiencyCollection(pileupBins=puBins)
        add_met_variable = partial(
            self.efficiencies.add_variable,
            bins=bins, thresholds=thresholds)
        map(add_met_variable, self.met_calcs)
        return True
    def test_add_variable(self):
        pileupBins = [0, 10, 15, 20, 30, 999]
        bins = np.concatenate(
            (np.arange(20, 80, 10), np.arange(80, 120,
                                              20), np.arange(120, 200, 40)))
        thresholds = [30, 50, 70, 100]
        hists = EfficiencyCollection(pileupBins=pileupBins)
        # this should create 1 entry for every pileup bin and every threshold

        hists.add_variable('jetEt', bins, thresholds)
        expected_len = (len(pileupBins) - 1) * len(thresholds)
        self.assertEqual(len(hists), expected_len)
    def prepare_for_events(self, reader):
        met_bins = list(np.arange(0, 40, 2))
        met_bins.extend(np.arange(40, 80, 5))
        met_bins.extend(np.arange(80, 120, 10))
        met_bins.extend(np.arange(120, 300, 20))

        mht_bins = list(np.arange(30, 50, 1))
        mht_bins.extend(np.arange(50, 80, 5))
        mht_bins.extend(np.arange(80, 140, 10))
        mht_bins.extend(np.arange(140, 200, 15))
        mht_bins.extend(np.arange(200, 300, 20))
        mht_bins.extend(np.arange(300, 400, 25))

        ett_bins = list(np.arange(0, 30, 30))
        ett_bins.extend(np.arange(30, 50, 10))
        ett_bins.extend(np.arange(50, 90, 5))
        ett_bins.extend(np.arange(90, 140, 2))

        htt_bins = list(np.arange(0, 100, 20))
        htt_bins.extend(np.arange(100, 200, 10))
        htt_bins.extend(np.arange(200, 400, 20))
        htt_bins.extend(np.arange(400, 500, 50))
        htt_bins.extend(np.arange(500, 800, 100))
        htt_bins.extend(np.arange(800, 1400, 200))
        htt_bins.extend(np.arange(1400, 2000, 600))

        thresholds = [0, 70, 90, 110]
        puBins = range(0, 50, 10) + [999]

        self.efficiencies = EfficiencyCollection(pileupBins=puBins)
        add_met_variable = partial(self.efficiencies.add_variable,
                                   bins=met_bins,
                                   thresholds=thresholds)
        map(add_met_variable,
            ['metBE', 'metBERecalc', 'metBEEmu', 'metBERecalcEmu'])
        self.efficiencies.add_variable('htt',
                                       bins=htt_bins,
                                       thresholds=thresholds)

        return True
Ejemplo n.º 4
0
    def prepare_for_events(self, reader):
        bins = list(np.arange(0, 100, 2))
        bins.extend(np.arange(100, 200, 5))
        bins.extend(np.arange(200, 300, 10))
        bins.extend(np.arange(300, 400, 20))
        bins.extend(np.arange(400, 500, 25))
        print(bins)

        thresholds = [36., 68., 128., 200.]
        puBins = range(0, 50, 10) + [999]

        self.efficiencies = EfficiencyCollection(pileupBins=puBins)
        self.efficiencies.add_variable('JetEt',
                                       bins=bins,
                                       thresholds=thresholds)
        add_jet_variable = partial(self.efficiencies.add_variable,
                                   bins=bins,
                                   thresholds=thresholds)
        map(add_jet_variable,
            ['JetEtBarrel', 'JetEtCentral', 'JetEtEndcap', 'JetEtHF'])

        return True
class Analyzer(BaseAnalyzer):

    def __init__(self, **kwargs):
        super(Analyzer, self).__init__(**kwargs)
        self.triggerName = self.params['triggerName']

        self.met_calcs = dict(
            RecalcL1EmuMETNot28=dict(
                title="Emulated MET, |ieta|<28",
                attr='l1MetNot28',),
            RecalcL1EmuMETNot28HF=dict(
                title="Emulated MET, |ieta|!=28",
                attr='l1MetNot28HF'),
        )

    def prepare_for_events(self, reader):
        bins = np.arange(0, 200, 25)
        thresholds = [70, 90, 110]
        puBins = range(0, 50, 10) + [999]

        self.efficiencies = EfficiencyCollection(pileupBins=puBins)
        add_met_variable = partial(
            self.efficiencies.add_variable,
            bins=bins, thresholds=thresholds)
        map(add_met_variable, self.met_calcs)

        return True

    def reload_histograms(self, input_file, do_comparison=False):
        # Something like this needs to be implemented still
        # self.efficiencies = EfficiencyCollection.from_root(input_file)
        return True

    def fill_histograms(self, entry, event):
        if self.triggerName == 'SingleMu':
            if not muonfilter(event):
                return True
        pileup = event.Vertex_nVtx
        if pileup < 5 or not pfMetFilter(event):
            return True

        self.efficiencies.set_pileup(pileup)

        offlineMetBE = event.Sums_caloMetBE
        for name, config in self.met_calcs.items():
            onlineMet = getattr(event, config['attr'])
            onlineMet = onlineMet.et
            self.efficiencies.fill(name, offlineMetBE, onlineMet)
        return True

    def write_histograms(self):
        self.efficiencies.to_root(self.get_histogram_filename())
        return True

    def make_plots(self):
        # Something like this needs to be implemented still
        # self.efficiencies.draw_plots(self.output_folder, "png")
        return True
Ejemplo n.º 6
0
class Analyzer(BaseAnalyzer):
    def __init__(self, config, **kwargs):
        super(Analyzer, self).__init__("study_tower28_met", config)
        self.triggerName = self.config.get('input', 'trigger')['name']

        self.met_calcs = dict(
            RecalcL1EmuMETNot28=dict(title="Emulated MET, |ieta|<28",
                                     calculate=recalc.l1MetNot28),
            RecalcL1EmuMETNot28HF=dict(title="Emulated MET, |ieta|!=28",
                                       calculate=recalc.l1MetNot28HF),
        )

    def prepare_for_events(self, reader):
        bins = np.arange(0, 200, 25)
        thresholds = [70, 90, 110]
        puBins = range(0, 50, 10) + [999]

        self.efficiencies = EfficiencyCollection(pileupBins=puBins)
        add_met_variable = partial(self.efficiencies.add_variable,
                                   bins=bins,
                                   thresholds=thresholds)
        map(add_met_variable, self.met_calcs)

        return True

    def reload_histograms(self, input_file):
        # Something like this needs to be implemented still
        # self.efficiencies = EfficiencyCollection.from_root(input_file)
        return True

    def fill_histograms(self, entry, event):
        if self.triggerName == 'SingleMu':
            if not muonfilter(event.muons):
                return True
        pileup = event.nVertex
        if pileup < 5 or not event.passesMETFilter():
            return True

        self.efficiencies.set_pileup(pileup)

        offlineMetBE = event.sums.caloMetBE
        for name, config in self.met_calcs.items():
            onlineMet = config['calculate'](event.caloTowers)
            onlineMet = onlineMet.mag
            self.efficiencies.fill(name, offlineMetBE, onlineMet)
        return True

    def write_histograms(self):
        self.efficiencies.to_root(self.get_histogram_filename())
        return True

    def make_plots(self):
        # Something like this needs to be implemented still
        # self.efficiencies.draw_plots(self.output_folder, "png")
        return True
Ejemplo n.º 7
0
class Analyzer(BaseAnalyzer):

    def __init__(self, config, **kwargs):
        super(Analyzer, self).__init__("demo_analyzer", config)

        self.met_calcs = dict(
            RecalcL1EmuMETNot28=dict(
                title="Emulated MET, |ieta|<28",
                attr='l1MetNot28'),
            RecalcL1EmuMETNot28HF=dict(
                title="Emulated MET, |ieta|!=28",
                attr='l1MetNot28HF'),
        )

    def prepare_for_events(self, reader):
        bins = np.arange(0, 200, 25)
        thresholds = [70, 90, 110]
        puBins = range(0, 50, 10) + [999]

        self.efficiencies = EfficiencyCollection(pileupBins=puBins)
        add_met_variable = partial(
            self.efficiencies.add_variable,
            bins=bins, thresholds=thresholds)
        map(add_met_variable, self.met_calcs)
        return True

    def reload_histograms(self, input_file):
        # Something like this needs to be implemented still
        # self.efficiencies = EfficiencyCollection.from_root(input_file)
        return True

    def fill_histograms(self, entry, event):
        pileup = event['Vertex_nVtx']
        if pileup < 5 or not event.MetFilters_hbheNoiseFilter:
            return True
        self.efficiencies.set_pileup(pileup)

        offlineMetBE = event.Sums_caloMetBE
        for name, config in self.met_calcs.items():
            onlineMet = event[config['attr']]
            onlineMet = onlineMet.mag
            self.efficiencies.fill(name, offlineMetBE, onlineMet)
        return True

    def write_histograms(self):
        self.efficiencies.to_root(self.get_histogram_filename())
        return True

    def make_plots(self):
        # Something like this needs to be implemented still
        # self.efficiencies.draw_plots(self.output_folder, "png")
        return True
class Analyzer(BaseAnalyzer):
    def __init__(self, config, **kwargs):
        super(Analyzer, self).__init__(__name__, config)
        self.triggerName = self.config.get('input', 'trigger')['name']

    def prepare_for_events(self, reader):
        met_bins = list(np.arange(0, 40, 2))
        met_bins.extend(np.arange(40, 80, 5))
        met_bins.extend(np.arange(80, 120, 10))
        met_bins.extend(np.arange(120, 300, 20))

        mht_bins = list(np.arange(30, 50, 1))
        mht_bins.extend(np.arange(50, 80, 5))
        mht_bins.extend(np.arange(80, 140, 10))
        mht_bins.extend(np.arange(140, 200, 15))
        mht_bins.extend(np.arange(200, 300, 20))
        mht_bins.extend(np.arange(300, 400, 25))

        ett_bins = list(np.arange(0, 30, 30))
        ett_bins.extend(np.arange(30, 50, 10))
        ett_bins.extend(np.arange(50, 90, 5))
        ett_bins.extend(np.arange(90, 140, 2))

        htt_bins = list(np.arange(0, 100, 20))
        htt_bins.extend(np.arange(100, 200, 10))
        htt_bins.extend(np.arange(200, 400, 20))
        htt_bins.extend(np.arange(400, 500, 50))
        htt_bins.extend(np.arange(500, 800, 100))
        htt_bins.extend(np.arange(800, 1400, 200))
        htt_bins.extend(np.arange(1400, 2000, 600))

        thresholds = [0, 70, 90, 110]
        puBins = range(0, 50, 10) + [999]

        self.efficiencies = EfficiencyCollection(pileupBins=puBins)
        add_met_variable = partial(self.efficiencies.add_variable,
                                   bins=met_bins,
                                   thresholds=thresholds)
        map(add_met_variable,
            ['metBE', 'metBERecalc', 'metBEEmu', 'metBERecalcEmu'])
        self.efficiencies.add_variable('htt',
                                       bins=htt_bins,
                                       thresholds=thresholds)

        return True

    def reload_histograms(self, input_file):
        # Something like this needs to be implemented still
        # self.efficiencies = EfficiencyCollection.from_root(input_file)
        return True

    def fill_histograms(self, entry, event):
        if self.triggerName == 'SingleMu':
            if not muonfilter(event.muons):
                return True
        if not event.passesMETFilter():
            return True

        pileup = event.nVertex
        self.efficiencies.set_pileup(pileup)

        l1MetBE = event.l1Sums['L1Met'].et
        l1MetBERecalc = recalcMET(event.caloTowers).mag

        l1MetBEEmu = event.l1Sums['L1EmuMet'].et
        l1MetBERecalcEmu = recalcMET(event.emuCaloTowers).mag

        l1Htt = event.l1Sums['L1Htt'].et

        offlineMetBE = event.sums.caloMetBE
        recoHtt = event.sums.Ht

        self.efficiencies.fill('metBE', offlineMetBE, l1MetBE)
        self.efficiencies.fill('metBERecalc', offlineMetBE, l1MetBERecalc)
        self.efficiencies.fill('metBEEmu', offlineMetBE, l1MetBEEmu)
        self.efficiencies.fill('metBERecalcEmu', offlineMetBE,
                               l1MetBERecalcEmu)

        self.efficiencies.fill('htt', recoHtt, l1Htt)

        return True

    def write_histograms(self):
        self.efficiencies.to_root(self.get_histogram_filename())
        return True

    def make_plots(self):
        from rootpy.io import root_open
        with root_open(self.get_histogram_filename()) as f:
            # our collections are flat, need only the objects
            for _, _, objects in f.walk():
                for name in objects:
                    if 'pickle' in name:
                        continue
                    obj = f.get(name)
                    plot(obj, name, self.output_folder)
        return True
Ejemplo n.º 9
0
class Analyzer(BaseAnalyzer):
    def __init__(self, config, **kwargs):
        super(Analyzer, self).__init__(__name__, config)
        self.triggerName = self.config.get('input', 'trigger')['name']

    def prepare_for_events(self, reader):
        bins = list(np.arange(0, 100, 2))
        bins.extend(np.arange(100, 200, 5))
        bins.extend(np.arange(200, 300, 10))
        bins.extend(np.arange(300, 400, 20))
        bins.extend(np.arange(400, 500, 25))
        print(bins)

        thresholds = [36., 68., 128., 200.]
        puBins = range(0, 50, 10) + [999]

        self.efficiencies = EfficiencyCollection(pileupBins=puBins)
        self.efficiencies.add_variable('JetEt',
                                       bins=bins,
                                       thresholds=thresholds)
        add_jet_variable = partial(self.efficiencies.add_variable,
                                   bins=bins,
                                   thresholds=thresholds)
        map(add_jet_variable,
            ['JetEtBarrel', 'JetEtCentral', 'JetEtEndcap', 'JetEtHF'])

        return True

    def reload_histograms(self, input_file):
        # Something like this needs to be implemented still
        # self.efficiencies = EfficiencyCollection.from_root(input_file)
        return True

    def fill_histograms(self, entry, event):
        if self.triggerName == 'SingleMu':
            if not muonfilter(event.muons):
                return True
        pileup = event.nVertex

        leadingRecoJet = event.getLeadingRecoJet()
        matchedL1Jet = event.getMatchedL1Jet(leadingRecoJet)

        if not leadingRecoJet or not matchedL1Jet:
            return True

        recoEt = leadingRecoJet.etCorr
        recoEta = leadingRecoJet.eta

        l1Et = matchedL1Jet.et

        self.efficiencies.set_pileup(pileup)
        if is_in_region('B', recoEta):
            self.efficiencies.fill('JetEtBarrel', recoEt, l1Et)
        elif is_in_region('BE', recoEta):
            self.efficiencies.fill('JetEtCentral', recoEt, l1Et)
        elif is_in_region('E', recoEta):
            self.efficiencies.fill('JetEtEndcap', recoEt, l1Et)
        else:
            self.efficiencies.fill('JetEtHF', recoEt, l1Et)

        return True

    def write_histograms(self):
        self.efficiencies.to_root(self.get_histogram_filename())
        return True

    def make_plots(self):
        from rootpy.io import root_open
        with root_open(self.get_histogram_filename()) as f:
            # our collections are flat, need only the objects
            for _, _, objects in f.walk():
                for name in objects:
                    if 'pickle' in name:
                        continue
                    obj = f.get(name)
                    plot(obj, name, self.output_folder)
        return True
Ejemplo n.º 10
0
def main(nEvents, output_folder):
    # range 0-100 in steps of 25
    bins = np.arange(0, 200, 25)
    thresholds = [70, 90, 110]
    # TODO: add control plots
    histograms = EfficiencyCollection(pileupBins=[0, 13, 20, 999])
    # all MET variables have the same bins & thresholds
    add_met_variable = partial(histograms.add_variable,
                               bins=bins,
                               thresholds=thresholds)

    map(
        add_met_variable,
        [
            'RecalcL1EmuMet',
            # 'RecalcL1EmuMetHF',
            # 'RecalcL1EmuMet28Only',
            # 'RecalcL1EmuMetNot28',
            # 'RecalcL1EmuMetPUS',
            # 'RecalcL1EmuMetPUSHF',
            # 'RecalcL1EmuMetPUS28',
            # 'RecalcL1EmuMetPUSThresh',
            # 'RecalcL1EmuMetPUSThreshHF',
            # 'RecalcL1Met',
            # 'RecalcL1Met28Only',
        ])

    reader = EventReader(FILES, events=nEvents)

    for entry, event in enumerate(reader):
        pileup = event.nVertex
        if pileup < 5 or not event.passesMETFilter():
            continue

        histograms.set_pileup(pileup)

        caloMetBE = event.sums.caloMetBE
        l1Sums = event.l1Sums
        if 'L1Met' not in l1Sums:
            print(l1Sums)
        # l1Met = l1Sums['L1Met'].et

        # l1Met28Only = rmet.l1Met28Only(event.caloTowers)
        # metNot28HF = rmet.l1MetNot28HF(event.caloTowers)
        # metNot28 = rmet.l1MetNot28(event.caloTowers)

        l1EmuMet = l1Sums['L1EmuMet'].et
        # l1EmuMetHF = l1Sums['L1EmuMetHF'].et
        # l1EmuMet28Only = rmet.l1Met28Only(event.emuCaloTowers)
        # l1EmuMetNot28 = rmet.l1MetNot28(event.emuCaloTowers)

        histograms.fill('RecalcL1EmuMet', caloMetBE, l1EmuMet)

        # l1EmuMetPUS =
        # l1EmuMetPUSHF =
        # l1EmuMetPUS28 =
        # l1EmuMetPUSThresh =
        # l1EmuMetPUSThreshHF =
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)

    output_file = os.path.join(output_folder, 'studyTower28MET.root')
    histograms.to_root(output_file)

    # plotting should be separate, this is just here as an example
    from rootpy.io import root_open
    with root_open(output_file) as f:
        # our collections are flat, need only the objects
        for _, _, objects in f.walk():
            for name in objects:
                if 'pickle' in name:
                    continue
                # obj = f.get(name)


#                 plot(obj, name, output_folder)
    print('Processed', entry + 1, 'events')