Пример #1
0
    def make_signal_views(self, rebin, unblinded=True):
        ''' Make signal views with FR background estimation '''

        wz_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('WZ*'), rebin), 'os/All_Passed/')
        zz_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('ZZ*'), rebin), 'os/All_Passed/')
        all_data_view = self.rebin_view(self.get_view('data'), rebin)
        if unblinded and self.blind:
            all_data_view = self.rebin_view(
                self.get_view('data', 'unblinded_view'), rebin)

        data_view = views.SubdirectoryView(all_data_view, 'os/All_Passed/')
        #Categories (to match Abdollah's naming convention)
        probes = [p + 'IsoFailed' for p in products_map[self.channel][1]]
        cat0 = 'os/' + '_'.join(probes) + '/all_weights_applied/'
        cat1 = 'os/' + probes[0] + '/obj1_weight/'
        cat2 = 'os/' + probes[1] + '/obj2_weight/'

        # View of weighted obj1-fails data
        cat1_view = views.SubdirectoryView(all_data_view, cat1)
        # View of weighted obj2-fails data
        cat2_view = views.SubdirectoryView(all_data_view, cat2)
        # View of weighted obj1&2-fails data
        cat0_view = views.SubdirectoryView(all_data_view, cat0)

        subtract_cat0_view = views.ScaleView(cat0_view, -1)
        # Corrected fake view
        Zjets_view = views.SumView(cat1_view, cat2_view, subtract_cat0_view)
        Zjets_view = views.TitleView(
            views.StyleView(Zjets_view, **data_styles['Zjets*']), 'Non-prompt')

        charge_fakes = views.TitleView(
            views.StyleView(
                views.SubdirectoryView(all_data_view, 'os/p1p2p3/c1'),
                **data_styles['TT*']), 'Charge mis-id')

        output = {
            'wz': wz_view,
            'zz': zz_view,
            'data': data_view,
            'cat1': cat1_view,
            'cat2': cat2_view,
            'Zjets': Zjets_view,
            'charge_fakes': charge_fakes,
        }

        # Add signal
        for mass in [110, 120, 130, 140]:
            vh_view = views.SubdirectoryView(
                self.rebin_view(self.get_view('VH_H2Tau_M-%i' % mass), rebin),
                'os/All_Passed/')
            output['vh%i' % mass] = vh_view
            ww_view = views.SubdirectoryView(
                self.rebin_view(self.get_view('VH_%i_HWW' % mass), rebin),
                'os/All_Passed/')
            output['vh%i_hww' % mass] = ww_view
            output['signal%i' % mass] = views.SumView(ww_view, vh_view)

        return output
Пример #2
0
    def make_signal_views(self, rebin, unblinded=True):
        ''' Make signal views with FR background estimation '''

        wz_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('WZJetsTo3LNu*'), rebin),
            'ss/p1p2p3/')
        zz_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('ZZJetsTo4L*'), rebin), 'ss/p1p2p3/')
        all_data_view = self.rebin_view(self.get_view('data'), rebin)
        if unblinded:
            all_data_view = self.rebin_view(
                self.get_view('data', 'unblinded_view'), rebin)

        data_view = views.SubdirectoryView(all_data_view, 'ss/p1p2p3/')

        # View of weighted obj1-fails data
        obj1_view = views.SubdirectoryView(all_data_view, 'ss/f1p2p3/w1')
        # View of weighted obj2-fails data
        obj2_view = views.SubdirectoryView(all_data_view, 'ss/p1f2p3/w2')
        # View of weighted obj1&2-fails data
        obj12_view = views.SubdirectoryView(all_data_view, 'ss/f1f2p3/w12')

        subtract_obj12_view = views.ScaleView(obj12_view, -1)
        # Corrected fake view
        fakes_view = views.SumView(obj1_view, obj2_view, subtract_obj12_view)
        fakes_view = views.TitleView(
            views.StyleView(fakes_view, **data_styles['Zjets*']), 'Non-prompt')

        charge_fakes = views.TitleView(
            views.StyleView(
                views.SubdirectoryView(all_data_view, 'os/p1p2p3/c1'),
                **data_styles['TT*']), 'Charge mis-id')

        output = {
            'wz': wz_view,
            'zz': zz_view,
            'data': data_view,
            'obj1': obj1_view,
            'obj2': obj2_view,
            'fakes': fakes_view,
            'charge_fakes': charge_fakes,
        }

        # Add signal
        for mass in [110, 120, 130, 140]:
            vh_view = views.SubdirectoryView(
                self.rebin_view(self.get_view('VH_*%i' % mass), rebin),
                'ss/p1p2p3/')
            output['vh%i' % mass] = vh_view
            ww_view = views.SubdirectoryView(
                self.rebin_view(self.get_view('WH_%i*' % mass), rebin),
                'ss/p1p2p3/')
            output['vh%i_hww' % mass] = ww_view
            output['signal%i' % mass] = views.SumView(ww_view, vh_view)

        return output
Пример #3
0
    def make_wz_cr_views(self, rebin):
        ''' Make WZ control region views with FR background estimation '''

        wz_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('WZJetsTo3LNu*'), rebin),
            'ss/p1p2p3_enhance_wz/')
        zz_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('ZZJetsTo4L*'), rebin),
            'ss/p1p2p3_enhance_wz/')
        all_data_view = self.rebin_view(self.get_view('data'), rebin)
        data_view = views.SubdirectoryView(all_data_view,
                                           'ss/p1p2p3_enhance_wz/')

        # View of weighted obj2-fails data
        fakes_view = views.SubdirectoryView(all_data_view,
                                            'ss/p1f2p3_enhance_wz/w2')
        fakes_view = views.StyleView(fakes_view, **data_styles['Zjets*'])

        # Correct
        wz_in_fakes_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('WZJetsTo3LNu*'), rebin),
            'ss/p1f2p3_enhance_wz/w2')
        zz_in_fakes_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('ZZJetsTo4L*'), rebin),
            'ss/p1f2p3_enhance_wz/w2')

        diboson_view = views.SumView(wz_in_fakes_view, zz_in_fakes_view)
        inverted_diboson_view = views.ScaleView(diboson_view, -1)

        fakes_view = views.SumView(fakes_view, inverted_diboson_view)

        fakes_view = views.TitleView(fakes_view, 'Non-prompt')

        output = {
            'wz': wz_view,
            'zz': zz_view,
            'data': data_view,
            'fakes': fakes_view
        }

        # Add signal
        for mass in [110, 120, 130, 140]:
            vh_view = views.SubdirectoryView(
                self.rebin_view(self.get_view('VH_*%i' % mass), rebin),
                'ss/p1p2p3/')
            output['vh%i' % mass] = vh_view

        return output
Пример #4
0
    def get_view(self, sample_pattern, key_name='view'):
        ''' Get a view which matches a pattern like "Zjets*"
        Multiple matches are summed together (e.g. "Z?jets*")

        Generally key_name does not need to be modified, unless getting
        unblinded data via "unblinded_view"
        '''
        matching = []
        samples = []
        for sample, sample_info in self.views.iteritems():
            if fnmatch.fnmatch(sample, sample_pattern):
                try:
                    matching.append(sample_info[key_name])
                    samples.append(sample)
                except KeyError:
                    raise KeyError(
                        "you asked for %s in sample %s, but it was not found, I only have: %s"
                        % (key_name, sample, ','.join(sample_info.keys())))

        if matching:
            logging.debug("Merging %s into a single view. Asked: %s" %
                          (' '.join(samples), sample_pattern))
            return views.SumView(*matching)
        else:
            raise KeyError("I can't find a view that matches %s, I have: %s" %
                           (sample_pattern, " ".join(self.views.keys())))
Пример #5
0
    def make_views(self, rebin):
        ''' Make signal views with FR background estimation '''

        wz_view = InflateErrorView(
            views.SubdirectoryView(
                self.rebin_view(self.get_view('WZ*'), rebin), 'charge'), 0.16)

        zz_view = InflateErrorView(
            views.SubdirectoryView(
                self.rebin_view(self.get_view('ZZ*'), rebin), 'charge'), 0.16)

        zj_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('Zjets*'), rebin), 'charge')

        diboson_view = views.StyleView(views.SumView(wz_view, zz_view),
                                       fillcolor=(ROOT.EColor.kRed - 7),
                                       drawstyle='hist')
        all_data_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('data'), rebin), 'charge')

        output = {
            'wz': wz_view,
            'zz': zz_view,
            'zjets': zj_view,
            'data': all_data_view,
            'diboson': diboson_view,
        }

        return output
Пример #6
0
    def make_wz_cr_views(self, rebin=1, project=None, project_axis=None):
        ''' Make WZ control region views with FR background estimation '''

        def preprocess(view):
            ret = view
            if project and project_axis:
                ret = ProjectionView(ret, project_axis, project)
            return RebinView( ret, rebin )

        wz_view_tautau_all = preprocess( self.get_view('WZJetsTo3LNu*ZToTauTau*') )
        wz_view_tautau     = views.SubdirectoryView(wz_view_tautau_all, 'ss/tau_os/p1p2p3_enhance_wz/')

        tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia'
        wz_view_3l_all = preprocess( self.get_view(tomatch) )
        wz_view_3l     = views.SubdirectoryView(wz_view_3l_all, 'ss/tau_os/p1p2p3_enhance_wz/')
        wz_view_all    = views.SumView(wz_view_tautau_all, wz_view_3l_all)

        zz_view_all = preprocess( self.get_view('ZZJetsTo4L*') )
        zz_view     = views.SubdirectoryView(zz_view_all, 'ss/tau_os/p1p2p3_enhance_wz/')
            
        all_data_view = preprocess( self.get_view('data') )
        data_view = views.SubdirectoryView(
            all_data_view, 'ss/tau_os/p1p2p3_enhance_wz/')

        # View of weighted obj2-fails data
        fakes_view = views.SubdirectoryView(
            all_data_view, 'ss/tau_os/p1f2p3_enhance_wz/w2')
        fakes_view = views.StyleView(fakes_view, **remove_name_entry(data_styles['Zjets*']))

        # Correct
        wz_in_fakes_view = views.SubdirectoryView(wz_view_all, 'ss/tau_os/p1f2p3_enhance_wz/w2')
        zz_in_fakes_view = views.SubdirectoryView(zz_view_all, 'ss/tau_os/p1f2p3_enhance_wz/w2')

        diboson_view = views.SumView(wz_in_fakes_view, zz_in_fakes_view)
        inverted_diboson_view = views.ScaleView(diboson_view, -1)

        fakes_view = views.SumView(fakes_view, inverted_diboson_view)
        fakes_view = views.TitleView(fakes_view, 'Reducible bkg.')

        output = {
            'wz_ztt': wz_view_tautau,
            'wz_3l' : wz_view_3l,
            'zz'    : zz_view,
            'data'  : data_view,
            'fakes' : fakes_view
        }
        return output
Пример #7
0
def correct_for_contrib_in_fakes(x, fudge_factor=1.0):
    ''' Make a view of MC which corrects for the contribution in the fakes '''
    fakes_view = views.PathModifierView(x, get_fakes)
    invert_view = views.ScaleView(fakes_view, -1)
    output = views.SumView(x, invert_view)
    # Fudge factor from Zmumu (from H2TAu inclusive)
    fudge = views.ScaleView(output, fudge_factor)
    return fudge
Пример #8
0
        def make_fakes(qcd_fraction):
            def make_fakes_view(weight_type, scale):
                scaled_bare_data = views.ScaleView(all_data_view, scale)
                scaled_wz_data   = views.ScaleView(all_wz_view,   scale)
                scaled_data      = SubtractionView(scaled_bare_data, scaled_wz_data, restrict_positive=True) 
                # View of weighted obj1-fails data
                obj1_view = views.SubdirectoryView(
                    scaled_data, 'ss/%s/f1p2f3/%s1' % (tau_charge, weight_type))
                # View of weighted obj2-fails data
                obj2_view = views.SubdirectoryView(
                    scaled_data, 'ss/%s/p1f2f3/%s2' % (tau_charge, weight_type))
                # View of weighted obj1&2-fails data
                obj12_view = views.SubdirectoryView(
                    scaled_data, 'ss/%s/f1f2f3/%s12' % (tau_charge, weight_type))

                # Give the individual object views nice colors
                obj1_view = views.TitleView(
                    views.StyleView(obj1_view, **remove_name_entry(data_styles['TT*'])),
                    'Reducible bkg. 1')
                obj2_view = views.TitleView(
                    views.StyleView(obj2_view, **remove_name_entry(data_styles['QCD*'])),
                    'Reducible bkg. 2')
                obj12_view = views.TitleView(
                    views.StyleView(obj12_view, **remove_name_entry(data_styles['WW*'])),
                    'Reducible bkg. 12')

                subtract_obj12_view = views.ScaleView(obj12_view, -1)
                return obj1_view, obj2_view, obj12_view, subtract_obj12_view

            qcd1, qcd2, qcd12, negqcd12 = make_fakes_view('q', qcd_fraction)
            wjet1, wjet2, wjet12, negwjet12 = make_fakes_view(
                'w', 1 - qcd_fraction)

            obj1_view  = views.SumView(qcd1, wjet1)
            obj2_view  = views.SumView(qcd2, wjet2)
            obj12_view = views.SumView(qcd12, wjet12)
            subtract_obj12_view = views.SumView(negqcd12, negwjet12)

            # Corrected fake view
            fakes_view = views.SumView(obj1_view, obj2_view, subtract_obj12_view)
            fakes_view = views.TitleView(
                views.StyleView(fakes_view, **remove_name_entry(data_styles['Zjets*'])), 'Reducible bkg.')
            return obj1_view, obj2_view, obj12_view, fakes_view
Пример #9
0
    def write_f3_shapes(self, variable, rebin, outdir,
                     qcd_fraction=0, show_charge_fakes=False,
                     project=None, project_axis=None):
        ''' Write final shapes for [variable] into a TDirectory [outputdir] '''
        show_charge_fakes = show_charge_fakes if 'show_charge_fakes' not in self.defaults else self.defaults['show_charge_fakes']
        sig_view = self.make_obj3_fail_cr_views(False, qcd_weight_fraction=qcd_fraction)
        
        if project and project_axis:
            sig_view = self.apply_to_dict( sig_view, ProjectionView, project_axis, project )
        sig_view = self.apply_to_dict( sig_view, RebinView, rebin )

        outdir.cd()
        wz = views.SumView(sig_view['wz'], sig_view['wz_3l']).Get(variable)
        zz = sig_view['zz'].Get(variable)
        obs = sig_view['data'].Get(variable)
        fakes = sig_view['fakes'].Get(variable)

        wz.SetName('wz')
        zz.SetName('zz')
        obs.SetName('data_obs')
        fakes.SetName('fakes')
        
        wz.Write()
        zz.Write()
        obs.Write()
        fakes.Write()

        mass = 120
        vh = sig_view['vh%i' % mass].Get(variable)
        vh.SetName('WH%i' % mass)
        vh.Write()
        # Only have 10 GeV steps for WW
        if sig_view['vh%i_hww' % mass]:
            ww = sig_view['vh%i_hww' % mass].Get(variable)
            ww.SetName('WH_hww125')
            ww.Write()

        #charge_fakes_CMS_vhtt_emt_chargeFlip_8TeVUpx
        if show_charge_fakes:
            logging.info('adding charge fakes shape errors')
            charge_fakes          = sig_view['charge_fakes']['central'].Get(variable)
            charge_fakes_sys_up   = sig_view['charge_fakes']['sys_up' ].Get(variable) #shift='up') 
            charge_fakes_sys_down = charge_fakes+charge_fakes - charge_fakes_sys_up
            charge_fakes.SetName('charge_fakes')
            charge_fakes_sys_up.SetName('charge_fakes_CMS_vhtt_%s_chargeFlip_%sTeVUp' % (self.channel.lower(), self.sqrts))
            charge_fakes_sys_down.SetName('charge_fakes_CMS_vhtt_%s_chargeFlip_%sTeVDown' % (self.channel.lower(), self.sqrts))
            charge_fakes.Write()
            charge_fakes_sys_up.Write()
            charge_fakes_sys_down.Write()
Пример #10
0
    def make_additional_fakes_view(self, unblinded=False, rebin=1, 
                                   project=None, project_axis=None, tau_charge='tau_os' ):
        other_tau_sign = 'tau_os' if tau_charge == 'tau_ss' else 'tau_ss'
        def preprocess(view):
            ret = view
            if project and project_axis:
                ret = ProjectionView(ret, project_axis, project)
            return RebinView( ret, rebin )

        zjets_view    = preprocess( self.get_view('Zjets*') )
        all_data_view = preprocess( self.get_view('data') )
        zjets_fakes   = views.SumView(
            views.SubdirectoryView( zjets_view, 'ss/%s/f1p2p3/w1/' % tau_charge ),
            views.SubdirectoryView( zjets_view, 'ss/%s/p1f2p3/w2/' % tau_charge )
            #,views.SubdirectoryView( zjets_view, 'ss/%s/f1f2p3/w12/' % tau_charge ) #FIXME: check that effect is small
        )
        tau_fakes  = views.SubdirectoryView(all_data_view, 'ss/%s/p1p2f3/w3/' % tau_charge)
        full_fakes = views.SumView(tau_fakes, zjets_fakes)

        return {
            'fakes'      : full_fakes,
            'zjet_fakes' : zjets_fakes,
            'tau_fakes'  : tau_fakes,
        }
Пример #11
0
    def plot_final_f3(self,
                      variable,
                      rebin=1,
                      xaxis='',
                      maxy=None,
                      show_error=False):
        ''' Plot the final F3 control region - with bkg. estimation '''
        sig_view = self.make_obj3_fail_cr_views(rebin)

        stack = views.StackView(
            sig_view['charge_fakes'],
            sig_view['fakes'],
            sig_view['wz'],
            sig_view['zz'],
        )
        histo = stack.Get(variable)
        histo.Draw()
        histo.GetHistogram().GetXaxis().SetTitle(xaxis)

        # Add legend
        legend = self.add_legend(histo, leftside=False, entries=4)

        if show_error:
            bkg_error_view = BackgroundErrorView(
                views.SumView(sig_view['fakes'], sig_view['charge_fakes']),
                sig_view['wz'],
                sig_view['zz'],
            )
            bkg_error = bkg_error_view.Get(variable)
            self.keep.append(bkg_error)
            bkg_error.Draw('pe2,same')
            legend.AddEntry(bkg_error)

        data = sig_view['data'].Get(variable)
        data.Draw('same')
        if maxy:
            histo.SetMaximum(maxy)
        else:
            histo.SetMaximum(
                1.2 *
                max(histo.GetHistogram().GetMaximum(), data.GetMaximum()))
        self.keep.append(data)
        self.keep.append(histo)

        #legend.AddEntry(data)
        legend.Draw()
Пример #12
0
    def get_flip_data(self, rebin=1, xaxis='', data_type='data'):
        data_view = self.get_view(data_type)
        data_view = self.rebin_view(data_view,
                                    rebin) if rebin != 1 else data_view
        #Get ss/p1p2 views
        ss_p1p2_view = views.SubdirectoryView(data_view, 'ss/p1p2')
        ss_p1p2_view = views.TitleView(
            views.StyleView(ss_p1p2_view, **data_styles['data*']),
            'observed;%s' % xaxis)

        #def make_fakes_view(sign, weight_type):
        #    # View of weighted obj1-fails data
        #    obj1_view = views.SubdirectoryView(data_view, '%s/f1p2/%s' % (sign, weight_type))
        #    # View of weighted obj2-fails data
        #    obj2_view = views.SubdirectoryView(data_view, '%s/p1f2/%s' % (sign, weight_type))
        #    # View of weighted obj1&2-fails data
        #    obj12_view = views.SubdirectoryView(data_view, '%s/f1f2/%s' % (sign, weight_type))
        #    # Give the individual object views nice colors
        #    subtract_obj12_view = views.ScaleView(obj12_view, -1)
        #    return obj1_view, obj2_view, subtract_obj12_view

        #Get fakes according to WJets or QCD
        #ss_f1p2_qcd_view, ss_p1f2_qcd_view, ss_f1f2_qcd_view = self.make_fakes_view(data_view, 'ss','qcd_w')
        ss_f1p2_wje_view, ss_p1f2_wje_view, ss_f1f2_wje_view = self.make_fakes_view(
            data_view, 'ss', 'wjet_w')

        ss_fakes_1 = ss_f1p2_wje_view  #MedianView(lowv=ss_f1p2_qcd_view, highv=ss_f1p2_wje_view)
        ss_fakes_2 = ss_p1f2_wje_view  #MedianView(lowv=ss_p1f2_qcd_view, highv=ss_p1f2_wje_view)
        ss_fakes_12 = ss_f1f2_wje_view  #MedianView(lowv=ss_f1f2_qcd_view, highv=ss_f1f2_wje_view)
        ss_fakes_est = views.SumView(ss_fakes_1, ss_fakes_2, ss_fakes_12)
        ss_fakes_est = views.TitleView(
            views.StyleView(ss_fakes_est, **data_styles['Zjets*']),
            'Fakes;%s' % xaxis)

        os_flip_est_up = views.SubdirectoryView(data_view,
                                                'os/p1p2/charge_weightSysUp')
        os_flip_est = views.SubdirectoryView(data_view,
                                             'os/p1p2/charge_weight')
        #os_flip_est     = MedianView(highv=os_flip_est_up, centv=os_flip_est)
        os_flip_est_nofake = os_flip_est  #views.SumView(os_flip_est, neg_os_fakes)
        os_flip_est_nofake = views.TitleView(
            views.StyleView(os_flip_est_nofake, **data_styles['WZ*']),
            'charge-fakes;%s' % xaxis)
        return ss_p1p2_view, ss_fakes_est, os_flip_est_nofake
Пример #13
0
    def make_obj3_fail_cr_views(self, rebin):
        ''' Make views when obj3 fails, estimating the bkg in obj1 pass using
            f1p2f3 '''
        wz_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('WZJetsTo3LNu*'), rebin),
            'ss/p1p2f3/')
        zz_view = views.SubdirectoryView(
            self.rebin_view(self.get_view('ZZJetsTo4L*'), rebin), 'ss/p1p2f3/')
        all_data_view = self.rebin_view(self.get_view('data'), rebin)
        data_view = views.SubdirectoryView(all_data_view, 'ss/p1p2f3/')

        # View of weighted obj1-fails data
        obj1_view = views.SubdirectoryView(all_data_view, 'ss/f1p2f3/w1')
        # View of weighted obj2-fails data
        obj2_view = views.SubdirectoryView(all_data_view, 'ss/p1f2f3/w2')
        # View of weighted obj1&2-fails data
        obj12_view = views.SubdirectoryView(all_data_view, 'ss/f1f2f3/w12')

        subtract_obj12_view = views.ScaleView(obj12_view, -1)
        # Corrected fake view
        fakes_view = views.SumView(obj1_view, obj2_view, subtract_obj12_view)
        fakes_view = views.TitleView(
            views.StyleView(fakes_view, **data_styles['Zjets*']), 'Non-prompt')

        charge_fakes = views.TitleView(
            views.StyleView(
                views.SubdirectoryView(all_data_view, 'os/p1p2f3/c1'),
                **data_styles['TT*']), 'Charge mis-id')

        output = {
            'wz': wz_view,
            'zz': zz_view,
            'data': data_view,
            'obj1': obj1_view,
            'obj2': obj2_view,
            'fakes': fakes_view,
            'charge_fakes': charge_fakes,
        }

        return output
Пример #14
0
def data_views(files, lumifiles):
    ''' Builds views of files.

    [files] gives an iterator of .root files with histograms to build.

    [lumifiles] gives the correspond list of .lumisum files which contain
    the effective integrated luminosity of the samples.

    The lumi to normalize to is taken as the sum of the data file int. lumis.

    '''

    files = list(files)

    log.info("Creating views from %i files", len(files))

    # Map sample_name => root file
    histo_files = dict((extract_sample(x), io.open(x)) for x in files)

    # Map sample_name => lumi file
    lumi_files = dict((extract_sample(x), read_lumi(x)) for x in lumifiles)

    # Identify data files
    datafiles = set([name for name in histo_files.keys() if 'data' in name])

    log.info("Found the following data samples:")
    log.info(" ".join(datafiles))
    datalumi = 0
    for x in datafiles:
        if x not in lumi_files:
            raise KeyError(
                "Can't find a lumi file for %s - I have these ones: " % x
                + repr(lumi_files.keys()))
        datalumi += lumi_files[x]
    log.info("-> total int. lumi = %0.0fpb-1", datalumi)

    # Figure out the dataset for each file, and the int lumi.
    # Key = dataset name
    # Value = {intlumi, rootpy file, weight, weighted view}
    output = {}

    for sample in histo_files.keys():
        raw_file = histo_files[sample]
        intlumi = lumi_files[sample]
        log.info("Building sample: %s => int lumi: %0.f pb-1", sample, intlumi)
        weight = 1
        if intlumi:
            weight = datalumi/intlumi
        if 'data' in sample:
            weight = 1
        log.debug("Weight: %0.2f", weight)

        view = views.ScaleView(raw_file, weight)
        unweighted_view = raw_file

        # Find the longest (i.e. most specific) matching style pattern
        best_pattern = ''
        for pattern, style_dict in data_styles.iteritems():
            log.debug("Checking pattern: %s against %s", pattern, sample)
            if fnmatch.fnmatch(sample, pattern):
                log.debug("-> it matches!")
                if len(pattern) > len(best_pattern):
                    best_pattern = pattern
                    log.info("Found new best style for %s: %s",
                             sample, pattern)
        if best_pattern:
            style_dict = data_styles[best_pattern]
            log.info("Found style for %s - applying Style View", sample)

            # Set style and title
            # title = the name of the sample, rootpy Legend uses this.
            nicename = copy.copy(style_dict['name'])
            view = views.TitleView(
                views.StyleView(view, **style_dict), nicename
            )
            unweighted_view = views.TitleView(
                views.StyleView(unweighted_view, **style_dict), nicename
            )

        output[sample] = {
            'intlumi': intlumi,
            'file' : raw_file,
            'weight' : weight,
            'view' : view,
            'unweighted_view' : unweighted_view
        }

    # Merge the data into just 'data'
    log.info("Merging data together")
    output['data'] = {
        'intlumi' : datalumi,
        'weight' : 1,
        'view' : views.SumView(*[output[x]['view'] for x in datafiles]),
        'unweighted_view' : views.SumView(*[output[x]['unweighted_view']
                                            for x in datafiles]),
    }

    return output
Пример #15
0
    def plot_zee_control(self,
                         variable,
                         xaxis='',
                         rebin=1,
                         legend_on_the_left=False,
                         x_range=None,
                         show_ratio=False,
                         logscale=False):
        data_view = self.get_view('data')
        data_view = self.rebin_view(data_view,
                                    rebin) if rebin != 1 else data_view
        mc_views = [
            self.get_view(i)
            for i in ['ZZ*', 'WZ*', 'WW*', 'TT*', 'Zjets_M50']
        ]
        if rebin != 1:
            mc_views = [self.rebin_view(i, rebin) for i in mc_views]

        zee_data = views.SubdirectoryView(data_view, 'os/p1p2/')
        zee_mcs = [views.SubdirectoryView(i, 'os/p1p2/') for i in mc_views]

        #os_f1p2_qcd_view, os_p1f2_qcd_view, os_f1f2_qcd_view = self.make_fakes_view(data_view, 'os','qcd_w')
        os_f1p2_wje_view, os_p1f2_wje_view, os_f1f2_wje_view = self.make_fakes_view(
            data_view, 'os', 'wjet_w')
        os_fakes_1 = os_f1p2_wje_view  #MedianView(lowv=os_f1p2_qcd_view, highv=os_f1p2_wje_view)
        os_fakes_2 = os_p1f2_wje_view  #MedianView(lowv=os_p1f2_qcd_view, highv=os_p1f2_wje_view)
        os_fakes_12 = os_f1f2_wje_view  #MedianView(lowv=os_f1f2_qcd_view, highv=os_f1f2_wje_view)
        os_fakes_est = views.SumView(os_fakes_1, os_fakes_2, os_fakes_12)
        os_fakes_est = views.TitleView(
            views.StyleView(os_fakes_est, **data_styles['WplusJets*']),
            'Fakes;%s' % xaxis)

        zee_mcs = zee_mcs[:-1] + [os_fakes_est] + zee_mcs[-1:]
        events_estimate = views.StackView(*zee_mcs)
        estimate_hist = events_estimate.Get(variable)
        obs_hist = zee_data.Get(variable)
        hmax = max([estimate_hist.GetMaximum(), max(list(obs_hist))])
        if logscale:
            obs_hist.GetYaxis().SetRangeUser(10**-2, hmax * 10**4)
            self.pad.SetLogy(True)
        else:
            obs_hist.GetYaxis().SetRangeUser(0., hmax * 1.3)

        if x_range:
            obs_hist.GetXaxis().SetRangeUser(x_range[0], x_range[1])

        obs_hist.Draw()
        estimate_hist.Draw('same')
        obs_hist.Draw('same')
        self.canvas.Update()
        self.keep.extend([estimate_hist, obs_hist])

        legend = self.add_legend([obs_hist],
                                 leftside=legend_on_the_left,
                                 entries=len(zee_mcs) + 1)
        legend.AddEntry(estimate_hist, 'f')
        #legend.AddEntry(estimate_error,'f')
        legend.Draw()
        if show_ratio:
            self.add_ratio_plot(obs_hist,
                                estimate_hist,
                                x_range,
                                ratio_range=0.2)
        self.add_cms_blurb(self.sqrts)
Пример #16
0
signals = glob('results/%s/permProbComputer/[AH]toTT*.root' % jobid)
Hs, As, HIs, AIs = [], [], [], []
for i in signals:
    base = os.path.basename(i)
    if base.startswith('HtoTT'):
        if '_Interf' in i:
            HIs.append(i)
        else:
            Hs.append(i)
    else:
        if '_Interf' in i:
            AIs.append(i)
        else:
            As.append(i)

higgses = views.SumView(*[root_open(i) for i in Hs])
pscals = views.SumView(*[root_open(i) for i in As])
hinter = views.SumView(*[root_open(i) for i in HIs])
ainter = views.SumView(*[root_open(i) for i in AIs])

pys_samples = [
    (higgses, 'H', 'blue'),
    (pscals, 'A', 'cyan'),
    #	(hinter , 'HI', 'red'),
    #	(ainter , 'AI', '#00960a'),
]

pys_samples = [
    urviews.NormalizedView(
        views.TitleView(
            views.StyleView(views.SubdirectoryView(i, 'semilep_visible_right'),
Пример #17
0
    def plot_final(self, variable, rebin=1, xaxis='', maxy=24,
                   show_error=False, qcd_correction=False, stack_higgs=True, 
                   qcd_weight_fraction=0., x_range=None, show_charge_fakes=False,
                   leftside_legend=False, higgs_xsec_multiplier=1, project=None, 
                   project_axis=None, differential=False, yaxis='Events', tau_charge='tau_os', **kwargs):
        ''' Plot the final output - with bkg. estimation '''        
        show_charge_fakes = show_charge_fakes if 'show_charge_fakes' not in self.defaults else self.defaults['show_charge_fakes']
        sig_view = self.make_signal_views(unblinded=(not self.blind), 
                                          qcd_weight_fraction=qcd_weight_fraction,
                                          rebin=rebin, project=project, 
                                          project_axis=project_axis, tau_charge=tau_charge)

        if differential:
            sig_view = self.apply_to_dict(sig_view, DifferentialView)

        vh_10x = views.TitleView(
            views.StyleView(
                views.ScaleView(sig_view['vh125'], higgs_xsec_multiplier),
                **remove_name_entry(data_styles['VH*'])
            ),
            "(%i#times) m_{H} = 125" % higgs_xsec_multiplier
        )
        charge_fakes_view = MedianView(highv=sig_view['charge_fakes']['sys_up'], centv=sig_view['charge_fakes']['central'])

        # Fudge factor to go from 120->125 - change in xsec*BR
        #vh_10x = views.ScaleView(vh_10x), .783)
        tostack = [sig_view['wz_3l'], sig_view['zz'], sig_view['wz'], sig_view['fakes'], vh_10x] if stack_higgs else \
            [sig_view['wz_3l'], sig_view['zz'], sig_view['wz'], sig_view['fakes']]
        if show_charge_fakes:
            tostack = tostack[:2]+[charge_fakes_view]+tostack[2:]

        vh_hww = views.ScaleView(sig_view['vh120_hww'], .783) if 'vh120_hww' in sig_view else None
        if vh_hww:
            tostack = tostack[:-1] + [vh_hww] + tostack[-1:]

        stack = views.StackView( *tostack )
        histo = stack.Get(variable)
        
        histo.Draw()
        histo.GetHistogram().GetXaxis().SetTitle(xaxis)
        histo.GetHistogram().GetYaxis().SetTitle(yaxis)

        if x_range:
            histo.GetHistogram().GetXaxis().SetRangeUser(x_range[0], x_range[1])
        self.keep.append(histo)

        # Add legend
        entries = len(tostack)+1
        if show_error:
            entries += 1
        legend  = self.add_legend(histo, leftside=leftside_legend, entries=entries)

        if show_error:
            #correct_qcd_view = None
            #if qcd_weight_fraction == 0:
            #    fakes05 = sig_view['weighted_fakes'][1.]
            #    correct_qcd_view = MedianView(lowv=fakes05, centv=sig_view['fakes'])
            #
            #elif qcd_weight_fraction == 0.5:
            #    fakes1 = sig_view['weighted_fakes'][1.]
            #    correct_qcd_view = MedianView(highv=fakes1, centv=sig_view['fakes'])
            #
            #elif qcd_weight_fraction == 1:
            #    fakes05 = sig_view['weighted_fakes'][0.5]
            #    correct_qcd_view = MedianView(lowv=fakes05, centv=sig_view['fakes'])

            bkg_error_view = BackgroundErrorView(
                sig_view['fakes'], #correct_qcd_view, #sig_view['fakes'],
                views.SumView( sig_view['wz'], sig_view['wz_3l']),
                sig_view['zz'],
                charge_fakes_view,
                fake_error=0.3,
                **kwargs
            )
            bkg_error = bkg_error_view.Get(variable)
            self.keep.append(bkg_error)
            bkg_error.Draw('pe2,same')
            legend.AddEntry(bkg_error)

        # Use poisson error bars on the data
        sig_view['data'] = PoissonView(sig_view['data'], x_err=False, is_scaled=differential) #PoissonView(, x_err=False)

        data = sig_view['data'].Get(variable)
        ymax = histo.GetMaximum()
        if not self.blind or tau_charge != 'tau_os':
            #print "drawing", data.Integral()
            data.Draw('pe,same')
            legend.AddEntry(data)
            ymax = max(ymax, data.GetMaximum())
        self.keep.append(data)

        if isinstance(maxy, (int, long, float)):
            #print "setting maxy to %s" % maxy
            histo.SetMaximum(maxy)
            self.canvas.Update()
        else:
            histo.SetMaximum(ymax*1.2)

        if not stack_higgs:
            higgs_plot = vh_10x.Get(variable)
            higgs_plot.Draw('same')
            self.keep.append(higgs_plot)
            
        legend.Draw()
Пример #18
0
def merge_views(inview, subnames):
    subviews = [views.SubdirectoryView(inview, i) for i in subnames]
    return views.SumView(*subviews)
Пример #19
0
    return ret


postfix = '_TEST_'

ROOT.gStyle.SetPaintTextFormat('.2g')
jobid = os.environ['jobid']
channels = ['eet', 'emt', 'mmt']

public = os.environ['pub']
chan_hists = {}
for ch, color in zip(channels, ['darkgreen', 'blue', 'red']):
    view = views.TitleView(
        views.StyleView(
            views.SumView(
                #                io.open('results/%s/WHAnalyze%s/VH_120_HWW.root' % (jobid, ch.upper()) ),
                io.open('results/%s/WHAnalyze%s/VH_H2Tau_M-120.root' %
                        (jobid, ch.upper()))),
            drawstyle='hist TEXT00',
            linecolor=color,
            linewidth=2,
            fillstyle='hollow',
            legendstyle='l',
        ),
        ch)
    chan_hists[ch] = view.Get('ss/CUT_FLOW')
    chan_hists[ch].SetLabelSize(0.035)

canvas = plotting.Canvas(name='adsf', title='asdf')
canvas.SetGridx(True)
canvas.SetGridy(True)
canvas.SetLogy(True)
Пример #20
0
#    else:
#        files.extend(glob.glob('results/lpairs_data_Oct9/MuMuAnalyser/%s' % (x)))
#        lumifiles.extend(glob.glob('inputs/lpairs_data_Oct9/%s.lumicalc.sum' % (x)))

period = '13TeV'
sqrts = 13
outputdir = 'plots/%s/MuMuAnalyser/' % (jobid)
if not os.path.exists(outputdir):
    os.makedirs(outputdir)
#plotter = BasePlotter(files, lumifiles, outputdir, None, 1000.)
plotter = Plotter(files, lumifiles, outputdir)


WSMH = views.StyleView(
    views.SumView(
        *[ plotter.get_view(regex) for regex in \
          filter(lambda x : x.startswith('WminusHToTauTau_M125') or x.startswith('WplusHToTauTau_M125') , mc_samples )]
    ), **remove_name_entry(data_styles['WH*'])
)

EWKDiboson = views.StyleView(
    views.SumView(
        *[ plotter.get_view(regex) for regex in \
          filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )]
    ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*'
                                       ])
)

WJ = views.StyleView(
    views.SumView(
        *[ plotter.get_view(regex) for regex in \
          filter(lambda x : x.startswith('W1JetsToLNu') or x.startswith('W2JetsToLNu') or x.startswith('W3JetsToLNu') or x.startswith('W4JetsToLNu') or x.startswith('WJetsToLNu') , mc_samples )]
Пример #21
0
#!/usr/bin/env python
'''

Get fake systematic.

'''

from rootpy import io
import rootpy.plotting.views as views
import sys

the_filename = sys.argv[1]
base_dirs = sys.argv[2].split(',')
syst_name = sys.argv[3]

the_file = io.open(the_filename, 'READ')
nom_view = views.SumView(
    *[views.SubdirectoryView(the_file, dirname) for dirname in base_dirs])

qcd_view = views.SumView(*[
    views.SubdirectoryView(the_file, dirname + '_q') for dirname in base_dirs
])

nom = nom_view.Get('fakes').Integral()
qcd = qcd_view.Get('fakes').Integral()

print "%s fakes %s %0.2f" % (','.join(base_dirs), syst_name,
                             1 + abs(nom - qcd) / nom)
Пример #22
0
    if preliminary:
        label_text += " Preliminary"
    label_text += " %s TeV" % sqrts
    label_text += " L=%sfb^{-1}" % (intlumi)
    label_text += " " + blurb
    return latex.DrawLatex(0.18, 0.97, label_text)

vh_7TeV = io.open('VHTT/cmb/common/vhtt.input_7TeV.root')
vh_8TeV = io.open('VHTT/cmb/common/vhtt.input_8TeV.root')

vh_7TeV_pf = io.open('../HiggsAnalysis/HiggsToTauTau/test/root_postfit/vhtt.input_7TeV.root')
vh_8TeV_pf = io.open('../HiggsAnalysis/HiggsToTauTau/test/root_postfit/vhtt.input_8TeV.root')

# We only care about 7 + 8 TeV
for pf_suffix, (vh7file, vh8file) in [('', (vh_7TeV, vh_8TeV)), ('_postfit', (vh_7TeV_pf, vh_8TeV_pf))]:
    vh_7and8 = views.SumView(vh7file, vh8file)
    for period, vh_combined in [('7+8', vh_7and8), ('7', vh7file), ('8', vh8file)]:

        # Now combine sub-channels
        llt_combined = views.SumView(*[
            views.SubdirectoryView(vh_combined, x) for x in ['emt', 'mmt', ]])

        zh_combined = views.SumView(*[
            views.SubdirectoryView(vh_combined, x) for x in [
                'eeem_zh', 'eeet_zh', 'eemt_zh', 'eett_zh',
                'mmme_zh', 'mmet_zh', 'mmmt_zh', 'mmtt_zh',
            ]])


        # Make views of individual backgrounds
        channels = {
Пример #23
0
outputdir = 'plots/%s/ControlFakeTau/%s/' % (jobid, channel)
if not os.path.exists(outputdir):
        os.makedirs(outputdir)


        
def remove_name_entry(dictionary):
    return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] )


plotter = BasePlotter(channel,files, lumifiles, outputdir) 

EWKDiboson = views.StyleView(
    views.SumView( 
        *[ plotter.get_view(regex) for regex in \
          filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )]
    ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*'
])
)
Wplus = views.StyleView(views.SumView(  *[ plotter.get_view(regex) for regex in filter(lambda x :  x.startswith('Wplus'), mc_samples )]), **remove_name_entry(data_styles['Wplus*Jets*']))
DYLL = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x :  x.endswith('skimmedLL'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*LL']))
DYTT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x :  x.endswith('jets_M50_skimmedTT'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*TT']))
TT = views.StyleView(views.SumView(  *[ plotter.get_view(regex) for regex in  filter(lambda x : x.startswith('TT') , mc_samples)]), **remove_name_entry(data_styles['TTJets*']))
singleT = views.StyleView(views.SumView(  *[ plotter.get_view(regex) for regex in  filter(lambda x : x.startswith('T_') or x.startswith('Tbar_'), mc_samples)]), **remove_name_entry(data_styles['T*_t*']))
SMH = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'HToTauTau' in x , mc_samples)]), **remove_name_entry(data_styles['GluGluToHToTauTau*']))


plotter.views['EWKDiboson']={'view' : EWKDiboson }
plotter.views['Wplus']={'view' : Wplus }
plotter.views['DYLL']={'view' : DYLL }
plotter.views['DYTT']={'view' : DYTT }
Пример #24
0
    def write_shapes(self, variable, rebin, outdir,
                     qcd_fraction=0., #[1., 0., -1.], 
                     show_charge_fakes=False,
                     project=None, project_axis=None, different_fakes=False):
        ''' Write final shapes for [variable] into a TDirectory [outputdir] '''
        show_charge_fakes = show_charge_fakes if 'show_charge_fakes' not in self.defaults else self.defaults['show_charge_fakes']
        sig_view = self.make_signal_views(unblinded=(not self.blind),
                                          qcd_weight_fraction=qcd_fraction,
                                          rebin=rebin, project=project, project_axis=project_axis)

        different_fakes_views = self.make_additional_fakes_view( unblinded=(not self.blind), rebin=rebin, 
                                   project=project, project_axis=project_axis)
        
        
        outdir.cd()
        wz_weight = self.get_view('WZJetsTo3LNu*ZToTauTau*', 'weight')
        zz_weight = self.get_view('ZZJetsTo4L*', 'weight')
        print "wz_weight: %s" % wz_weight
        print "zz_weight: %s" % zz_weight

        wz = views.FunctorView( views.SumView(sig_view['wz'], sig_view['wz_3l']), make_empty_bin_remover(wz_weight)).Get(variable)
        zz = views.FunctorView( sig_view['zz'], make_empty_bin_remover(zz_weight)).Get(variable)
        obs = sig_view['data'].Get(variable)
        fakes = sig_view['fakes'].Get(variable) if not different_fakes else different_fakes_views['fakes'].Get(variable)

        fakes_down = different_fakes_views['fakes'].Get(variable)
        fakes_up   = PositiveView(
            views.SumView( views.ScaleView(sig_view['fakes'], 2.), 
                           views.ScaleView(different_fakes_views['fakes'], -1.) 
                       )
        ).Get(variable)

        wz.SetName('wz')
        zz.SetName('zz')
        obs.SetName('data_obs')
        fakes.SetName('fakes')
        fakes_down.SetName('fakes_CMS_vhtt_%s_fakeshape_%sTeVDown' % (outdir.GetName(), self.sqrts))
        fakes_up.SetName('fakes_CMS_vhtt_%s_fakeshape_%sTeVUp' % (outdir.GetName(), self.sqrts))
        #for mass in [110, 115, 120, 125, 130, 135, 140]:
        #set_trace()
        for mass in range(90, 165, 5):
            try:
                vh = None
                if mass == 90 and self.sqrts == 8:
                    vh = views.ScaleView(sig_view['vh100'], 1.3719).Get(variable)
                elif mass == 95 and self.sqrts == 8:
                    vh = views.ScaleView(sig_view['vh100'], 1.1717).Get(variable)
                else:
                    vh = sig_view['vh%i' % mass].Get(variable)
                vh.SetName('WH%i' % mass)
                vh.SetLineColor(0)
                vh.Write()
            except KeyError:
                #logging.warning('No sample found matching VH_*%i' % mass)
                continue

            if mass % 10 == 0 and mass < 150:
                # Only have 10 GeV steps for WW
                if 'vh%i_hww' % mass in sig_view:
                    ww = sig_view['vh%i_hww' % mass].Get(variable)
                    ww.SetName('WH_hww%i' % mass)
                    ww.Write()

        wz.Write()
        zz.Write()
        obs.Write()
        fakes.Write()
        fakes_down.Write()
        fakes_up.Write()
        #charge_fakes_CMS_vhtt_emt_chargeFlip_8TeVUpx
        if show_charge_fakes:
            logging.info('adding charge fakes shape errors')
            charge_fakes          = sig_view['charge_fakes']['central'].Get(variable)
            charge_fakes_sys_up   = sig_view['charge_fakes']['sys_up' ].Get(variable) #shift='up') 
            charge_fakes_sys_down = charge_fakes+charge_fakes - charge_fakes_sys_up
            charge_fakes.SetName('charge_fakes')
            charge_fakes_sys_up.SetName('charge_fakes_CMS_vhtt_%s_chargeFlip_%sTeVUp' % (self.channel.lower(), self.sqrts))
            charge_fakes_sys_down.SetName('charge_fakes_CMS_vhtt_%s_chargeFlip_%sTeVDown' % (self.channel.lower(), self.sqrts))
            charge_fakes.Write()
            charge_fakes_sys_up.Write()
            charge_fakes_sys_down.Write()
Пример #25
0
tauiso = ['tNoCuts', 'tSuperSuperLoose', 'tSuperLoose', 'tLoose', 'tTigh']
#sign = ['os']
#tauiso=['tTigh']
outputdir = 'plots/%s/TauFakeRateAnalyzerMVA/%s/' % (jobid, channel)
if not os.path.exists(outputdir):
    os.makedirs(outputdir)

plotter = Plotter(files, lumifiles, outputdir)




EWKDiboson = views.StyleView(
    views.SumView(
        *[ plotter.get_view(regex) for regex in \
          filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )]
        #          filter(lambda x : x.startswith('WZ') , mc_samples )]
    ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*'
                                       ])
)
Wplus = views.StyleView(
    views.SumView(*[
        plotter.get_view(regex)
        for regex in filter(lambda x: x.startswith('Wplus'), mc_samples)
    ]), **remove_name_entry(data_styles['Wplus*Jets*']))
DYLL = views.StyleView(
    views.SumView(*[
        plotter.get_view(regex)
        for regex in filter(lambda x: x.endswith('skimmedLL'), mc_samples)
    ]), **remove_name_entry(data_styles['Z*jets*LL']))
DYTT = views.StyleView(
Пример #26
0
 def get_wild_dir(self, view, path):
     '''equivalent of SubdirectoryView, 
     but with unix-style wildcards'''
     paths = self.expand_path(path)
     return views.SumView(*[views.SubdirectoryView(view, i) for i in paths])
Пример #27
0
                          help='Plot fit error band')

    args = parser.parse_args(args[1:])

    if args.verbose:
        logging.basicConfig(level=logging.DEBUG, stream=sys.stderr)
    else:
        logging.basicConfig(level=logging.INFO, stream=sys.stderr)

    from rootpy.plotting import views
    import rootpy.io as io
    from FinalStateAnalysis.Utilities.rootbindings import ROOT

    # Build view of input histograms
    log.info("Merging input files")
    input_view = views.SumView(*[io.open(x) for x in args.input])

    if args.rebin and args.rebin > 1:
        binning = None
        # if ',' in args.rebin:
        # print args.rebin.split(',')
        if args.rebin:
            binning = eval(args.rebin)
            if isinstance(binning, float) or isinstance(binning, int):
                newbinning = int(binning)
            elif isinstance(binning, list) and isinstance(
                    binning[0], float) or isinstance(binning[0], int):
                newbinning = tuple(float(x) for x in binning)
            elif isinstance(binning, list) and isinstance(binning[0], list):
                # print   args.rebin
                #print binning[0]
Пример #28
0
period = '13TeV'
sqrts = 13
outputdir = 'plots/%s/MuMuAnalyserGen/' % (jobid)
if not os.path.exists(outputdir):
    os.makedirs(outputdir)
#print "outputdir", outputdir
#print "files", files
#print lumifiles
#plotter = BasePlotter(files, lumifiles, outputdir, None, 1000.)
plotter = Plotter(files, lumifiles, outputdir)


WSMH = views.StyleView(
    views.SumView(
        *[ plotter.get_view(regex) for regex in \
          filter(lambda x : x.startswith('WminusHToTauTau_M125') or x.startswith('WplusHToTauTau_M125') , mc_samples )]
    ), **remove_name_entry(data_styles['WH*'])
)

#EWK = views.StyleView(
#    views.SumView(
#        *[ plotter.get_view(regex) for regex in \
#          filter(lambda x : x.startswith('EWKZ2Jets_ZToLL') or x.startswith('EWKZ2Jets_ZToNuNu') , mc_samples )]
#    ), **remove_name_entry(data_styles['EWK*'])
#)

EWKDiboson = views.StyleView(
    views.SumView(
        *[ plotter.get_view(regex) for regex in \
          filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )]
    ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*'
Пример #29
0
    categories = arguments

    tfile = io.open(tfile_name)
    logging.info("Opened file %s" % tfile_name)
    
    #get a directory and look into that
    keys = [i.GetName() for i in tfile.Get(categories[0]).GetListOfKeys() if not fnmatch(i.GetName(), options.nuisances)]
    if options.excluded:
        keys = [ i for i in keys if not fnmatch(i, options.excluded)]
    data = [i for i in keys if i.startswith('data')][0]
    keys = [i for i in keys if not i.startswith('data')]

    logging.debug("These shapes will be plotted: %s" % keys.__repr__())
    
    input_view = views.SumView(
        *[ views.SubdirectoryView( tfile, category ) 
           for category in categories]
        )
    
    if options.differential == 1:
        input_view = DifferentialView( input_view )

    histograms = [ apply_style(input_view.Get(i), i) for i in keys ]
    histograms = sorted(histograms, key=lambda x: x.Integral())
    observed   = apply_style(input_view.Get(data), data)

    logging.debug("debugging histos:")
    for histo in histograms:
        logging.debug("    %s: style: %s, integral: %.2f" % ( histo.GetTitle(), histo.drawstyle, histo.Integral() ) )

    stack = plotting.HistStack()
    for obj in histograms:
Пример #30
0
 def __init__(self, highv=None, lowv=None, centv=None):
     self.highv = highv
     self.lowv  = lowv
     self.centv = views.ScaleView( views.SumView(lowv, self.highv) , 0.5) if not centv else centv