def routes(self):
     lines = [line.strip() for line in open('Logs/Routes')]
     l = len(lines)
     for line in lines:
         if line == 'Routing table = system Destinations = 5 Routes = 13':
             s = lines.index(line)
             s = s + 4
         if line == 'Routing table = XUA':
             e = lines.index(line)
             e = e - 1
     system = lines[s:e]
     xua = lines[e + 5:l]
     sys_routes = {}
     for sys in system:
         route = sys.split()
         rl = len(route)
         if rl == 6:
             route_dic = {}
             pc = route[0].split('/')
             pc = pc[0]
             l = 1
             route_dic[l] = route[2:rl]
             l = l + 1
             sys_routes[pc] = route_dic
         else:
             route_dic[l] = route
             l = l + 1
     xua_routes = {}
     for xu in xua:
         route = xu.split()
         rl = len(route)
         pc = route[0].split('/')
         pc = pc[0]
         xua_routes[pc] = route[rl - 1]
     return {'system': sys_routes, 'XUA': xua_routes}
Beispiel #2
0
def build_hierarchy_tree():
    # builds the tree sturcture of the PODM data to get the location hierarchy
    lst_chassis = get_chassis_list()
    podmtree = tree.Tree()
    podmtree.add_node("0")  # Add root node
    for d in lst_chassis:
        podmtree.add_node(d["ChassisID"], d)

    for d in lst_chassis:
        containedby = d["ContainedBy"] if d["ContainedBy"] else "0"
        podmtree.add_node(d["ChassisID"], d, containedby)
        systems = d["ComputerSystems"]
        for sys in systems:
            sysname = sys.split("/")[-2] + ":" + sys.split("/")[-1]
            podmtree.add_node(sys, {"name": sysname}, d["ChassisID"])
    return podmtree
Beispiel #3
0
def build_hierarchy_tree():
    # builds the tree sturcture of the PODM data to get the location hierarchy
    lst_chassis = get_chassis_list()
    podmtree = tree.Tree()
    podmtree.add_node("0")  # Add root node
    for d in lst_chassis:
        podmtree.add_node(d["ChassisID"], d)

    for d in lst_chassis:
        containedby = d["ContainedBy"] if d["ContainedBy"] else "0"
        podmtree.add_node(d["ChassisID"], d, containedby)
        systems = d["ComputerSystems"]
        for sys in systems:
            sysname = sys.split("/")[-2] + ":" + sys.split("/")[-1]
            podmtree.add_node(sys, {"name": sysname}, d["ChassisID"])
    return podmtree
Beispiel #4
0
# Script to find to most Diverse files for an ensemble
#
# python manhattan.py file_with_scores #configurations
# python manhattan.py scores.csv 10

import sys,os


chosen = []
scores = open(sys.argv[1],'r')
count = int(sys.argv[2])

for sys in scores:
	
	u = sys.split()
	
	a = u[0].split('-')[1:-1]
	
	x = 0
	
	for i in a:
		
		try:
			x+=int(i)/(a.index(i)+1.0)
			print x,a
		except ValueError: pass


	# Calculates a factor to be multiplied with the average score
	try:
		mean = (float(u[2])+float(u[3])+float(u[4])/3)
Beispiel #5
0
def draw_instack(variable, label='VBF', select=''):
    histos = []
    varname = variable
    formula = variables[varname].get('formula',varname)
    if ':=' in variable:
        varname  = variable.split(':=')[0]
        formula  = variable.split(':=')[1]
        
    histfilename = ('histogram_stack_' +
                    varname + '_' + label+ '_'
                    + selection['name'])
    
    legend  = None
    if settings.two_colomn_legend:
        legend  = ROOT.TLegend(0.45, 0.72,
                               (1 - ROOT.gStyle.GetPadRightMargin()),
                               (0.96 - ROOT.gStyle.GetPadTopMargin()))
        legend.SetNColumns(2)
        legend.SetColumnSeparation(0)
    else:
        legend  = ROOT.TLegend(0.6, 0.62,
                               (1 - ROOT.gStyle.GetPadRightMargin()),
                               (0.96 - ROOT.gStyle.GetPadTopMargin()))

    cutflow = variable_cutflow(variable,'')
    if len(cutflow)!=0:
        cutflow = variable_cutflow(variable,select)

    hstack = ROOT.THStack('hs_' + varname,'')
    
    hstack.SetName('hs_'+ varname)
    hstack.SetTitle(";" + variables[varname]['title']+";entries")

    histUpSys = {}
    histDwSys = {}

    for sys in treesUpSys:
        sysname   = sys.split('*')[1]
        histUpSys.update({sysname : None })
    for sys in treesDwSys:
        sysname   = sys.split('*')[1]
        histDwSys.update({sysname : None })
    
    if len(cutflow)!=0 and options.nocuts==False:
        cutflow = 'weight*(' + cutflow + ')'
    else:
        cutflow = 'weight*(1)'
    if  options.nocuts:
        histfilename = histfilename + '_nocuts'
    # loop over the samples
    bar    = ProgressBar(widgets=[colored('-- variables:: %20s   ' % variable, 'green'),
                                  Percentage(),'  ' ,Bar('>'), ' ', ETA()], term_width=100)
    ordsam = OrderedDict(sorted(samples.items(), key=lambda x: x[1]['order']))
    for proc in bar(ordsam):
        logger.debug(' -- %17s  %12s ' % (proc,  samples[proc].get('name')))
        
        tree       = samples[proc].get('_root_tree_')
        sample_cut = samples[proc].get('cut','')
        _cutflow_  = cutflow

        if samples[proc].get('cut','') != '':
            _cutflow_ = cutflow[:-1] + '&&' +  samples[proc].get('cut','') + ')'
        if variables[variable]['blind'] != '' and proc == 'Data':
            _cutflow_ = cutflow[:-1] + '&&' +  variables[variable]['blind']+ ')'
            
        if proc != 'Data':        
            tree.Project(
                'h_' + varname + variables[variable]['hist'],
                formula,
                _cutflow_.replace('weight','weight*%f*%f*%f' % ( treeinfo.get('kfactor',1.0),
                                                                 treeinfo.get('lumi'   ,1.0),
                                                                 samples[proc].get('kfactor',1.0)))
                )
        else:
            tree.Project(
                'h_' + varname + variables[variable]['hist'],
                formula,
                _cutflow_
            )
        #=== systematics 
        for sys in treesUpSys:
            if proc != 'Data' and 'signal' != samples[proc].get('label',''):        
                sysname = sys.split('*')[1]
                treeUp  = [x for x in samples[proc].get('_root_tree_sysUp_') if sysname in x.GetName()][0]
                treeUp.Project(
                    'h_UpSys_' + sysname +'_'+ varname + variables[variable]['hist'],
                    formula,
                    _cutflow_.replace('weight','weight*%f*%f*%f' % ( treeinfo.get('kfactor',1.0),
                                                                     treeinfo.get('lumi'   ,1.0),
                                                                     samples[proc].get('kfactor',1.0)))
                )
                histUp = ROOT.gDirectory.Get('h_UpSys_' + sysname +'_'+ varname )
                histUp.SetDirectory(0)
                if histUpSys[sysname] == None:
                    histUpSys[sysname] = histUp
                else:
                    histUpSys[sysname].Add(histUp)
        for sys in treesDwSys:
            if proc != 'Data' and 'signal' != samples[proc].get('label',''):        
                #treeDw    = samples[proc].get('_root_tree_sysDw_')[0]
                sysname   = sys.split('*')[1]
                treeDw  = [x for x in samples[proc].get('_root_tree_sysDw_') if sysname in x.GetName()][0]
                treeDw.Project(
                    'h_DwSys_' + sysname +'_'+ varname + variables[variable]['hist'],
                    formula,
                    _cutflow_.replace('weight','weight*%f*%f*%f' % ( treeinfo.get('kfactor',1.0),
                                                                     treeinfo.get('lumi'   ,1.0),
                                                                     samples[proc].get('kfactor',1.0)))
                )
                histDw = ROOT.gDirectory.Get('h_DwSys_' + sysname +'_'+ varname )
                histDw.SetDirectory(0)
                if histDwSys[sysname] == None:
                    histDwSys[sysname] = histDw
                else:
                    histDwSys[sysname].Add(histDw)
                    
        # ----------------------------------------------    
        hist = ROOT.gDirectory.Get('h_' + varname )
        hist.SetDirectory(0)

        hist.SetTitle(";" + variables[variable]['title']+";entries")
        hcolor = 1

        hcolor = samples[proc]['color']
        if ('signal'==samples[proc]['label']) or ('spectator'==samples[proc]['label']):
            hist.SetLineColor(hcolor)
            hist.SetLineStyle(1)
            hist.SetLineWidth(2)
            hist.SetFillStyle(0)
            histos.append(hist)
            if samples[proc].get('kfactor',1) !=1:
                legend.AddEntry(hist,
                                samples[proc]["title"] + ("#times%i"%samples[proc].get('kfactor',1)),
                                "l" );
            else:
                legend.AddEntry( hist, samples[proc]["title"], "l" );
        if 'data' in samples[proc]['label']:
            hist.SetMarkerColor(ROOT.kBlack)
            hist.SetLineColor  (ROOT.kBlack)
            hist.SetMarkerStyle(20)
            hist.SetMarkerSize (0.8) # fixme
            hist.SetFillColorAlpha(0,0)
            hist.SetLineWidth(2)
            hist.SetBinErrorOption(ROOT.TH1.kPoisson)
            hist.SetName(hist.GetName() + 'data')
            legend.AddEntry( hist, samples[proc]["title"], "lep" );
            histos.append(hist)
        if 'background' in samples[proc]['label']:
            hist.SetLineColor(ROOT.kBlack)
            hist.SetFillColor(hcolor)
            hist.SetLineWidth(2)
            hstack.Add(hist)
            legend.AddEntry( hist, samples[proc]["title"], "f" );
    # drawing
    c = makeRatioPlotCanvas(name = varname)
    c.cd(1)
    htmp   = histos[0].Clone('__htmp__')
    bounds = [float(s) for s in re.findall('[-+]?\d*\.\d+|\d+',variables[variable]['hist'])]
    htmp.SetTitle(';' + variables[variable]['title']
                  + (';events %s %s '% ( fformat((bounds[2]-bounds[1])/bounds[0]),
                                            variables[variable].get('unit',''))    ))
    htmp.Reset()
    if  options.allloghist or variables[variable]['log']:
        ymin = 0.01 - 0.003
        ymax = hstack.GetMaximum()*1000
        htmp.GetYaxis().SetRangeUser(ymin,ymax)
        histfilename = histfilename + '_log'
        ROOT.gPad.SetLogy()
    else:
        ymin = 0
        ymax = hstack.GetMaximum() + hstack.GetMaximum()*0.5
        htmp.GetYaxis().SetRangeUser(ymin,ymax)
    customizeHisto(htmp)
    htmp.Draw('')
    hstack.Draw('hist,same')
    herrstat = drawStatErrorBand(hstack.GetStack().Last(), histDwSys, histUpSys)
    herrstat.Draw('E2,same')
    hdata = None
    for h in histos:
        if 'data' not in h.GetName():
            h.Draw('hist,same')
        else:
            h.Draw('E,same')
            hdata = h

    if len(histUpSys)>0 and len(histDwSys)>0:
        legend.AddEntry(herrstat, "Stat #oplus Syst", "f" )
    else:
        legend.AddEntry(herrstat, "Stat Uncert", "f" )
        # cosmetics
    draw_cut_line(htmp,variable)
    draw_categories(variables[varname].get('boudaries',[]),
                    miny=htmp.GetMinimum(),
                    maxy=htmp.GetMaximum())
    ROOT.gPad.RedrawAxis();
    # this is for the legend
    legend.SetTextAlign( 12 )
    legend.SetTextFont ( 43 )
    legend.SetTextSize ( 18 )
    legend.SetLineColor( 0 )
    legend.SetFillColor( 0 )
    legend.SetFillStyle( 0 )
    legend.SetLineColorAlpha(0,0)
    legend.SetShadowColor(0)
    legend.Draw()
    # draw labels
    if  options.nocuts:
        draw_labels('w/o cuts')
    else:
        draw_labels(plotlabels['name'])
    draw_cms_headlabel(label_right='#sqrt{s} = 13 TeV, L = %1.2f fb^{-1}' % treeinfo.get('lumi',2.63))
    
    c.cd()
    c.cd(2)
    errorHist = MakeStatProgression(hstack.GetStack().Last(),histDwSys, histUpSys)
    ROOT.SetOwnership(errorHist,0)
    errorHist.GetXaxis().SetTitle(htmp.GetXaxis().GetTitle())
    errorHist.GetYaxis().SetTitle('Data/MC')
    errorHist.GetYaxis().CenterTitle(True)
    customizeHisto(errorHist)
    errorHist.Draw('E2')
    ratioHist = None
    sig_and_bkg_ratio = []
    if hdata==None:
        ratioHist = hstack.GetStack().Last().Clone('_temp_')
        ratioHist.Clear()
        ratioHist.SetLineColorAlpha(0,0)
        ratioHist.SetMarkerColorAlpha(0,0)
        ROOT.SetOwnership(ratioHist,0)
        ratioHist.GetXaxis().SetTitle(htmp.GetXaxis().GetTitle())
        ratioHist.GetYaxis().SetTitle(htmp.GetYaxis().GetTitle())
        if settings.ratio_draw_signal:
            for sig in histos:
                sig_and_bkg = hstack.GetStack().Last().Clone('_temp_bkg_' + sig.GetName())
                sig_and_bkg.Add(sig)
                sig_and_bkg_ratio_ = makeRatio(sig_and_bkg,hstack.GetStack().Last())
                ROOT.SetOwnership(sig_and_bkg_ratio_,0)
                sig_and_bkg_ratio_.GetXaxis().SetTitle(htmp.GetXaxis().GetTitle())
                sig_and_bkg_ratio_.GetYaxis().SetTitle(htmp.GetYaxis().GetTitle())
                sig_and_bkg_ratio_.SetFillColorAlpha(0,0)
                sig_and_bkg_ratio_.SetLineColor(sig.GetLineColor())
                sig_and_bkg_ratio.append(sig_and_bkg_ratio_)
    else:
        ratioHist = makeRatio(hist1 = hdata, hist2 = hstack.GetStack().Last(), isdata = True)
        ROOT.SetOwnership(ratioHist,0)
        ratioHist.GetXaxis().SetTitle(htmp.GetXaxis().GetTitle())
        ratioHist.GetYaxis().SetTitle(htmp.GetYaxis().GetTitle())
        if settings.ratio_draw_signal:
            for sig in histos:
                sig_and_bkg = hstack.GetStack().Last().Clone('_temp_bkg_' + sig.GetName())
                sig_and_bkg.Add(sig)
                sig_and_bkg_ratio_ = makeRatio(sig_and_bkg,hstack.GetStack().Last())
                ROOT.SetOwnership(sig_and_bkg_ratio_,0)
                sig_and_bkg_ratio_.GetXaxis().SetTitle(htmp.GetXaxis().GetTitle())
                sig_and_bkg_ratio_.GetYaxis().SetTitle(htmp.GetYaxis().GetTitle())
                sig_and_bkg_ratio_.SetFillColorAlpha(0,0)
                sig_and_bkg_ratio_.SetLineColor(sig.GetLineColor())
                sig_and_bkg_ratio.append(sig_and_bkg_ratio_)
                
    for o in sig_and_bkg_ratio:
        o.Draw('same,hist')
    draw_cut_line(errorHist,variable)
    line = ROOT.TLine(ratioHist.GetXaxis().GetXmin(),1,ratioHist.GetXaxis().GetXmax(),1)
    line.SetLineColor(4)
    line.SetLineStyle(7)
    line.Draw()
    draw_categories(variables[varname].get('boudaries',[]),
                    miny=htmp.GetMinimum(),
                    maxy=htmp.GetMaximum())
    ROOT.SetOwnership(line,0)
    ratioHist.Draw('same')

    c.cd()
    
    if variables[variable]['norm']==True or allnormhist==True:
        histfilename = histfilename + '_norm'
    c.SaveAs( 'plots/' + histfilename + '.png')
    c.SaveAs( 'plots/' + histfilename + '.pdf')
Beispiel #6
0
    def ascii_copy(self, db, switch_cons):
        """
        This method is to 
        """
        sys = ""
        founds = 0

        switch_cons.sendline('switchback')
        switch_cons.expect(defn.SWITCH_PROMPT)

        #For storing the kickstart and the system images
        switch_cons.sendline('show version | grep "image file is"')
        switch_cons.expect(defn.SWITCH_PROMPT)
        string = switch_cons.before
        if "///" in string:
            sys = string.split('///')[1]
            sys = sys.split()[0]
        if sys != "":
            switch_cons.sendline('dir')
            switch_cons.expect(defn.SWITCH_PROMPT)
            dir = switch_cons.before
            imgs = dir.split()
            if sys in imgs:
                founds = 1

        logging.info("Found sys %d", founds)
        if founds == 1:
            db.update_images(self.switch_name, "", sys)
        else:
            db.update_images(self.switch_name, "", "")

        #Now write erase and copy the running config to file
        switch_cons.sendline('delete run_power_config n')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        switch_cons.sendline('delete start_power_config n')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)

        #no boot kick and sys
        switch_cons.sendline('config t')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        switch_cons.sendline('no boot nxos')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        #write erase
        switch_cons.sendline('write erase')
        switch_cons.expect('Do you wish to proceed anyway')
        switch_cons.sendline('y')
        switch_cons.expect(defn.SWITCH_PROMPT, 120)
        #write erase boot
        switch_cons.sendline('write erase boot')
        switch_cons.expect('Do you wish to proceed anyway')
        switch_cons.sendline('y')
        switch_cons.expect(defn.SWITCH_PROMPT, 120)

        "Now copy the running config to run_power_config file"
        switch_cons.sendline('show running-config vdc-all > run_power_config')
        i = switch_cons.expect(
            [defn.SWITCH_PROMPT, r'yes/no', pexpect.TIMEOUT, pexpect.EOF])
        if i == 0:
            pass
        if i == 1:
            switch_cons.sendline('yes')
            switch_cons.expect(defn.SWITCH_PROMPT, 180)
        if i == 2 or i == 3:
            print "Something wrong with switch %s so go ahead and poweroff" % self.switch_name
            return False

        "Now copy the startup config to run_power_config file"
        switch_cons.sendline(
            'show startup-config vdc-all > start_power_config')
        i = switch_cons.expect(
            [defn.SWITCH_PROMPT, r'yes/no', pexpect.TIMEOUT, pexpect.EOF])
        if i == 0:
            pass
        if i == 1:
            switch_cons.sendline('yes')
            switch_cons.expect(defn.SWITCH_PROMPT, 180)
        if i == 2 or i == 3:
            print "Something wrong with switch %s so go ahead and poweroff" % self.switch_name
            return False

        Switch.setip(switch_cons, self.mgmt_ip)

        #Copy the kickstart and system image to server only if present
        if founds == 1:
            d_file = "%s/%s.system.gbin" % (self.switch_name, self.switch_name)
            Switch.copy_files_to_server(switch_cons=switch_cons,
                                        s_file=sys,
                                        d_file=d_file)
        d_file = "%s/%s.run_power_config" % (self.switch_name,
                                             self.switch_name)
        Switch.copy_files_to_server(switch_cons=switch_cons,
                                    s_file='run_power_config',
                                    d_file=d_file)
        d_file = "%s/%s.start_power_config" % (self.switch_name,
                                               self.switch_name)
        Switch.copy_files_to_server(switch_cons=switch_cons,
                                    s_file='start_power_config',
                                    d_file=d_file)

        return True
Beispiel #7
0
    def ascii_copy(self, switch_cons):
        """
        This method is to copy the running confing to run_power_config and
        startup config to start_power_config. Then save both the files to
        remote server.
        This will even store the kickstart/system image loaded to the same
        remote server which will be loaded while reloading the setup.
        """
        kick = sys = ""
        foundk = founds = 0
        
        switch_cons.sendline('switchback')
        switch_cons.expect(SWITCH_PROMPT)

        #For storing the kickstart and the system images
        switch_cons.sendline('show version | grep "kickstart image file is"')
        switch_cons.expect(SWITCH_PROMPT)
        string = switch_cons.before
        if "///" in string:
            kick = string.split('///')[1]
            kick = kick.split()[0]
        switch_cons.sendline('show version | grep "system image file is"')
        switch_cons.expect(SWITCH_PROMPT)
        string = switch_cons.before
        if "///" in string:
            sys = string.split('///')[1]
            sys = sys.split()[0]
        if kick != "" and sys != "":
            check_kick = 'dir | grep "%s"' % kick
            check_sys = 'dir | grep "%s"' % sys
            switch_cons.sendline(check_kick)
            switch_cons.expect(SWITCH_PROMPT)
            dirk = switch_cons.before
            imgsk = dirk.split()
            if kick in imgsk: 
                foundk = 1
            switch_cons.sendline(check_sys)
            switch_cons.expect(SWITCH_PROMPT)
            dirsy = switch_cons.before
            imgss = dirsy.split()
            if sys in imgss:
                founds = 1

        logging.info("Found kick %d and found sys %d", foundk, founds)
        if foundk==founds==1:
            Utils.update_images(self.switch_name, kick, sys)
        else:
            Utils.update_images(self.switch_name,"","")

        #Now write erase and copy the running config to file
        switch_cons.sendline('delete run_power_config n')
        switch_cons.expect(SWITCH_PROMPT, 60)
        switch_cons.sendline('delete start_power_config n')
        switch_cons.expect(SWITCH_PROMPT, 60)

        #no boot kick and sys
        switch_cons.sendline('config t')
        switch_cons.expect(SWITCH_PROMPT)
        switch_cons.sendline('no boot kick')
        switch_cons.expect(SWITCH_PROMPT, 120)
        switch_cons.sendline('config t')
        switch_cons.expect(SWITCH_PROMPT)
        switch_cons.sendline('no boot sys')
        switch_cons.expect(SWITCH_PROMPT, 120)
        #write erase
        switch_cons.sendline('write erase')
        switch_cons.expect('Do you wish to proceed anyway')
        switch_cons.sendline('y')
        switch_cons.expect(SWITCH_PROMPT, 120)
        #write erase boot
        switch_cons.sendline('write erase boot')
        switch_cons.expect('Do you wish to proceed anyway')
        switch_cons.sendline('y')
        switch_cons.expect(SWITCH_PROMPT, 120)
        
        Switch.setip(switch_cons, self.mgmt_ip)
        #Copy the kickstart and system image to server only if present
        if foundk==founds==1:
            d_file = "%s/%s.kickstart.gbin"%(self.switch_name,self.switch_name)	
            Switch.copy_files_to_server(switch_cons=switch_cons,s_file=kick,d_file=d_file)
            d_file = "%s/%s.system.gbin"%(self.switch_name,self.switch_name)
            Switch.copy_files_to_server(switch_cons=switch_cons,s_file=sys,d_file=d_file)

        "Now copy the running config to run_power_config file"
        switch_cons.sendline('show running-config vdc-all > run_power_config')
        i = switch_cons.expect([SWITCH_PROMPT,r'yes/no',pexpect.TIMEOUT, pexpect.EOF], 600)
        if i==0:
            pass
        if i==1:
            switch_cons.sendline('yes')
            switch_cons.expect(SWITCH_PROMPT,600)
        if i==2 or i==3:
            logging.info("Something wrong with switch %s",self.switch_name)
            return False
        
        d_file = "%s/%s.run_power_config"%(self.switch_name,self.switch_name)
        Switch.copy_files_to_server(switch_cons=switch_cons,s_file='run_power_config',d_file=d_file)
        
        "Now copy the startup config to run_power_config file"
        switch_cons.sendline('show startup-config vdc-all > start_power_config')
        i = switch_cons.expect([SWITCH_PROMPT,r'yes/no',pexpect.TIMEOUT, pexpect.EOF])
        if i==0:
            pass
        if i==1:
            switch_cons.sendline('yes')
            switch_cons.expect(SWITCH_PROMPT,180)
        if i==2 or i==3:
            logging.info("Something wrong with switch %s",self.switch_name)
            return False
        
        d_file = "%s/%s.start_power_config"%(self.switch_name,self.switch_name)
        Switch.copy_files_to_server(switch_cons=switch_cons,s_file='start_power_config',d_file=d_file)
        
        return True
Beispiel #8
0
def draw_instack(variable, label='VBF', select=''):
    histos = []
    varname = variable
    formula = variables[varname].get('formula',varname)
    if ':=' in variable:
        varname  = variable.split(':=')[0]
        formula  = variable.split(':=')[1]
        
    histfilename = ('histogram_stack_' +
                    varname + '_' + label+ '_'
                    + selection['name'])
    
    legend  = None
    if settings.two_colomn_legend:
        legend  = ROOT.TLegend(0.45, 0.72,
                               (1 - ROOT.gStyle.GetPadRightMargin()),
                               (0.96 - ROOT.gStyle.GetPadTopMargin()))
        legend.SetNColumns(2)
        legend.SetColumnSeparation(0)
    else:
        legend  = ROOT.TLegend(0.6, 0.62,
                               (1 - ROOT.gStyle.GetPadRightMargin()),
                               (0.96 - ROOT.gStyle.GetPadTopMargin()))

    cutflow = variable_cutflow(variable,select)

    hstack = ROOT.THStack('hs_' + varname,'')
    
    hstack.SetName('hs_'+ varname)
    hstack.SetTitle(";" + variables[varname]['title']+";entries")

    histUpSys = {}
    histDwSys = {}

    for sys in treesUpSys:
        sysname   = sys.split('*')[1]
        histUpSys.update({sysname : None })
    for sys in treesDwSys:
        sysname   = sys.split('*')[1]
        histDwSys.update({sysname : None })
    for sys in branchUpSys:
        histUpSys.update({sys : None })
    for sys in branchDwSys:
        histDwSys.update({sys : None })
        

        
    if len(cutflow)!=0 and options.nocuts==False:
        cutflow = 'weight*(' + cutflow + ')'
    else:
        cutflow = 'weight*(1)'
    if  options.nocuts:
        histfilename = histfilename + '_nocuts'
    # loop over the samples
    bar    = ProgressBar(widgets=[colored('-- variables:: {0:20!s}   '.format(variable), 'green'),
                                  Percentage(),'  ' ,Bar('>'), ' ', ETA()], term_width=100)
    ordsam = OrderedDict(sorted(samples.items(), key=lambda x: x[1]['order']))
    for proc in bar(ordsam):
        logger.debug(' -- {0:17!s}  {1:12!s} '.format(proc, samples[proc].get('name')))
        
        tree       = samples[proc].get('_root_tree_')
        sample_cut = samples[proc].get('cut','')
        _cutflow_  = cutflow
        _sample_weight_ = samples[proc].get('weight','1')

        if samples[proc].get('cut','') != '':
            _cutflow_ = cutflow[:-1] + '&&' +  samples[proc].get('cut','') + ')'
        if variables[variable]['blind'] != '' and proc == 'Data':
            _cutflow_ = cutflow[:-1] + '&&' +  variables[variable]['blind']+ ')'
            
        if proc != 'Data':        
            tree.Project(
                'h_' + varname + variables[variable]['hist'],
                formula,
                _cutflow_.replace('weight','weight*{0:f}*{1:f}*{2:f}*{3!s}'.format(treeinfo.get('kfactor',1.0),
                                                                 treeinfo.get('lumi'   ,1.0),
                                                                 samples[proc].get('kfactor',1.0),
                                                                 _sample_weight_))
                )
        else:
            tree.Project(
                'h_' + varname + variables[variable]['hist'],
                formula,
                _cutflow_
            )
        #=== systematics 
        for sys in treesUpSys:
            if proc != 'Data' and samples[proc].get('dosysts',True):
                sysname = sys.split('*')[1]
                treeUp  = [x for x in samples[proc].get('_root_tree_sysUp_') if sysname in x.GetName()][0]
                print 'sys ::', sys, ' :: treeUp ::', treeUp, ' :: ', treeUp.GetEntries()
                treeUp.Project(
                    'h_UpSys_' + sysname +'_'+ varname + variables[variable]['hist'],
                    formula,
                    _cutflow_.replace('weight','weight*{0:f}*{1:f}*{2:f}*{3!s}'.format(treeinfo.get('kfactor',1.0),
                                                                     treeinfo.get('lumi'   ,1.0),
                                                                     samples[proc].get('kfactor',1.0),
                                                                     _sample_weight_))
                )
                histUp = ROOT.gDirectory.Get('h_UpSys_' + sysname +'_'+ varname )
                histUp.SetDirectory(0)
                if histUpSys[sysname] is None:
                    histUpSys[sysname] = histUp
                else:
                    histUpSys[sysname].Add(histUp)
        for sys in treesDwSys:
            if proc != 'Data' and samples[proc].get('dosysts',True):
                sysname   = sys.split('*')[1]
                treeDw  = [x for x in samples[proc].get('_root_tree_sysDw_') if sysname in x.GetName()][0]
                print 'sys ::', sys, ' :: treeUp ::', treeDw, ' :: ', treeDw.GetEntries()
                treeDw.Project(
                    'h_DwSys_' + sysname +'_'+ varname + variables[variable]['hist'],
                    formula,
                    _cutflow_.replace('weight','weight*{0:f}*{1:f}*{2:f}*{3!s}'.format(treeinfo.get('kfactor',1.0),
                                                                     treeinfo.get('lumi'   ,1.0),
                                                                     samples[proc].get('kfactor',1.0),
                                                                     _sample_weight_))
                )
                histDw = ROOT.gDirectory.Get('h_DwSys_' + sysname +'_'+ varname )
                histDw.SetDirectory(0)
                if histDwSys[sysname] is None:
                    histDwSys[sysname] = histDw
                else:
                    histDwSys[sysname].Add(histDw)
        # ======= weight systematics
        for sys in branchUpSys:
            if proc != 'Data' and samples[proc].get('dosysts',True):
                print 'sys ::', sys, ' :: treeUp ::', tree, ' :: ', tree.GetEntries(), ' :: ', 'weight*{0:f}*{1:f}*{2!s}*{3:f}*{4!s}'.format(treeinfo.get('kfactor',1.0),
                                                                                                                        treeinfo.get('lumi'   ,1.0),
                                                                                                                        sys,
                                                                                                                        samples[proc].get('kfactor',1.0),
                                                                                                                        _sample_weight_)
                tree.Project(
                    'h_weight_UpSys_' + sysname +'_'+ varname + variables[variable]['hist'],
                    formula,
                    _cutflow_.replace('weight','weight*{0:f}*{1:f}*{2!s}*{3:f}*{4!s}'.format(treeinfo.get('kfactor',1.0),
                                                                        treeinfo.get('lumi'   ,1.0),
                                                                        sys,
                                                                        samples[proc].get('kfactor',1.0),
                                                                        _sample_weight_))
                )
                histUp = ROOT.gDirectory.Get('h_weight_UpSys_' + sysname +'_'+ varname)
                histUp.SetDirectory(0)
                if histUpSys[sys]    is None:
                    histUpSys[sys] = histUp
                else:
                    histUpSys[sys].Add(histUp)

        for sys in branchDwSys:
            if proc != 'Data' and samples[proc].get('dosysts',True):
                print 'sys ::', sys, ' :: treeUp ::', tree, ' :: ', tree.GetEntries(), ' :: ', 'weight*{0:f}*{1:f}*{2!s}*{3:f}*{4!s}'.format(treeinfo.get('kfactor',1.0),
                                                                                                                        treeinfo.get('lumi'   ,1.0),
                                                                                                                        sys,
                                                                                                                        samples[proc].get('kfactor',1.0),
                                                                                                                        _sample_weight_)
                tree.Project(
                    'h_weight_DwSys_' + sysname +'_'+ varname + variables[variable]['hist'],
                    formula,
                    _cutflow_.replace('weight','weight*{0:f}*{1:f}*{2!s}*{3:f}*{4!s}'.format(treeinfo.get('kfactor',1.0),
                                                                        treeinfo.get('lumi'   ,1.0),
                                                                        sys,
                                                                        samples[proc].get('kfactor',1.0),
                                                                        _sample_weight_))
                )
                histDw = ROOT.gDirectory.Get('h_weight_DwSys_' + sysname +'_'+ varname)
                histDw.SetDirectory(0)
                if histDwSys[sys]    is None:
                    histDwSys[sys] = histDw
                else:
                    histDwSys[sys].Add(histDw)
        # ----------------------------------------------    
        hist = ROOT.gDirectory.Get('h_' + varname )
        hist.SetDirectory(0)

        hist.SetTitle(";" + variables[variable]['title']+";entries")
        hcolor = 1

        hcolor = samples[proc]['color']
        if ('signal'==samples[proc]['label']) or ('spectator'==samples[proc]['label']):
            hist.SetLineColor(hcolor)
            hist.SetLineStyle(1)
            hist.SetLineWidth(2)
            hist.SetFillStyle(0)
            histos.append(hist)
            if samples[proc].get('kfactor',1) !=1:
                legend.AddEntry(hist,
                                samples[proc]["title"] + ("#times{0:d}".format(samples[proc].get('kfactor',1))),
                                "l" );
            else:
                legend.AddEntry( hist, samples[proc]["title"], "l" );
        if 'data' in samples[proc]['label']:
            hist.SetMarkerColor(ROOT.kBlack)
            hist.SetLineColor  (ROOT.kBlack)
            hist.SetMarkerStyle(20)
            hist.SetMarkerSize (0.8) # fixme
            hist.SetFillColorAlpha(0,0)
            hist.SetLineWidth(2)
            hist.SetBinErrorOption(ROOT.TH1.kPoisson)
            hist.SetName(hist.GetName() + 'data')
            legend.AddEntry( hist, samples[proc]["title"], "lep" );
            histos.append(hist)
        if 'background' in samples[proc]['label']:
            hist.SetLineColor(ROOT.kBlack)
            hist.SetFillColor(hcolor)
            hist.SetLineWidth(2)
            hstack.Add(hist)
            legend.AddEntry( hist, samples[proc]["title"], "f" );
    # drawing
    c = makeRatioPlotCanvas(name = varname)
    c.cd(1)
    htmp   = histos[0].Clone('__htmp__')
    bounds = [float(s) for s in re.findall('[-+]?\d*\.\d+|\d+',variables[variable]['hist'])]
    htmp.SetTitle(';' + variables[variable]['title']
                  + (';events {0!s} {1!s} '.format(fformat((bounds[2]-bounds[1])/bounds[0]),
                                            variables[variable].get('unit',''))    ))
    htmp.Reset()
    if  options.allloghist or variables[variable]['log']:
        ymin = 0.01 - 0.003
        ymax = hstack.GetMaximum()*1000
        htmp.GetYaxis().SetRangeUser(ymin,ymax)
        histfilename = histfilename + '_log'
        ROOT.gPad.SetLogy()
    else:
        ymin = 0
        ymax = hstack.GetMaximum() + hstack.GetMaximum()*0.5
        htmp.GetYaxis().SetRangeUser(ymin,ymax)
    customizeHisto(htmp)
    htmp.Draw('')
    hstack.Draw('hist,same')
    herrstat = drawStatErrorBand(hstack.GetStack().Last(), histDwSys, histUpSys)
    herrstat.Draw('E2,same')
    hdata = None
    for h in histos:
        if 'data' not in h.GetName():
            h.Draw('hist,same')
        else:
            h.Draw('E,same')
            hdata = h

    if len(histUpSys)>0 and len(histDwSys)>0:
        legend.AddEntry(herrstat, "Stat #oplus Syst", "f" )
    else:
        legend.AddEntry(herrstat, "Stat Uncert", "f" )
        # cosmetics
    draw_cut_line(htmp,variable)
    draw_categories(variables[varname].get('boudaries',[]),
                    miny=htmp.GetMinimum(),
                    maxy=htmp.GetMaximum())
    ROOT.gPad.RedrawAxis();
    # this is for the legend
    legend.SetTextAlign( 12 )
    legend.SetTextFont ( 43 )
    legend.SetTextSize ( 18 )
    legend.SetLineColor( 0 )
    legend.SetFillColor( 0 )
    legend.SetFillStyle( 0 )
    legend.SetLineColorAlpha(0,0)
    legend.SetShadowColor(0)
    legend.Draw()
    # draw labels
    if  options.nocuts:
        draw_labels('w/o cuts')
    else:
        draw_labels(plotlabels['name'])
    draw_cms_headlabel(label_right='#sqrt{{s}} = 13 TeV, L = {0:1.2f} fb^{{-1}}'.format(treeinfo.get('lumi',2.63)))
    
    c.cd()
    c.cd(2)
    errorHist = MakeStatProgression(hstack.GetStack().Last(),histDwSys, histUpSys)
    ROOT.SetOwnership(errorHist,0)
    errorHist.GetXaxis().SetTitle(htmp.GetXaxis().GetTitle())
    errorHist.GetYaxis().SetTitle('Data/MC')
    errorHist.GetYaxis().CenterTitle(True)
    customizeHisto(errorHist)
    errorHist.Draw('E2')
    ratioHist = None
    sig_and_bkg_ratio = []
    if hdata isNone:
        ratioHist = hstack.GetStack().Last().Clone('_temp_')
        ratioHist.Clear()
        ratioHist.SetLineColorAlpha(0,0)
        ratioHist.SetMarkerColorAlpha(0,0)
        ROOT.SetOwnership(ratioHist,0)
        ratioHist.GetXaxis().SetTitle(htmp.GetXaxis().GetTitle())
        ratioHist.GetYaxis().SetTitle(htmp.GetYaxis().GetTitle())
        if settings.ratio_draw_signal:
            for sig in histos:
                sig_and_bkg = hstack.GetStack().Last().Clone('_temp_bkg_' + sig.GetName())
                sig_and_bkg.Add(sig)
                sig_and_bkg_ratio_ = makeRatio(sig_and_bkg,hstack.GetStack().Last())
                ROOT.SetOwnership(sig_and_bkg_ratio_,0)
                sig_and_bkg_ratio_.GetXaxis().SetTitle(htmp.GetXaxis().GetTitle())
                sig_and_bkg_ratio_.GetYaxis().SetTitle(htmp.GetYaxis().GetTitle())
                sig_and_bkg_ratio_.SetFillColorAlpha(0,0)
                sig_and_bkg_ratio_.SetLineColor(sig.GetLineColor())
                sig_and_bkg_ratio.append(sig_and_bkg_ratio_)
    else:
        ratioHist = makeRatio(hist1 = hdata, hist2 = hstack.GetStack().Last(), isdata = True)
        ROOT.SetOwnership(ratioHist,0)
        ratioHist.GetXaxis().SetTitle(htmp.GetXaxis().GetTitle())
        ratioHist.GetYaxis().SetTitle(htmp.GetYaxis().GetTitle())
        if settings.ratio_draw_signal:
            for sig in histos:
                sig_and_bkg = hstack.GetStack().Last().Clone('_temp_bkg_' + sig.GetName())
                sig_and_bkg.Add(sig)
                sig_and_bkg_ratio_ = makeRatio(sig_and_bkg,hstack.GetStack().Last())
                ROOT.SetOwnership(sig_and_bkg_ratio_,0)
                sig_and_bkg_ratio_.GetXaxis().SetTitle(htmp.GetXaxis().GetTitle())
                sig_and_bkg_ratio_.GetYaxis().SetTitle(htmp.GetYaxis().GetTitle())
                sig_and_bkg_ratio_.SetFillColorAlpha(0,0)
                sig_and_bkg_ratio_.SetLineColor(sig.GetLineColor())
                sig_and_bkg_ratio.append(sig_and_bkg_ratio_)
                
    for o in sig_and_bkg_ratio:
        o.Draw('same,hist')
    draw_cut_line(errorHist,variable)
    line = ROOT.TLine(ratioHist.GetXaxis().GetXmin(),1,ratioHist.GetXaxis().GetXmax(),1)
    line.SetLineColor(4)
    line.SetLineStyle(7)
    line.Draw()
    draw_categories(variables[varname].get('boudaries',[]),
                    miny=htmp.GetMinimum(),
                    maxy=htmp.GetMaximum())
    ROOT.SetOwnership(line,0)
    ratioHist.Draw('same')

    c.cd()
    
    if variables[variable]['norm']==True or allnormhist==True:
        histfilename = histfilename + '_norm'
    c.SaveAs( 'plots/' + histfilename + '.png')
    c.SaveAs( 'plots/' + histfilename + '.pdf')
Beispiel #9
0
    def ascii_copy(self, db, switch_cons):
        """
        This method is to 
        """
        sys = ""
        founds = 0
        
        switch_cons.sendline('switchback')
        switch_cons.expect(defn.SWITCH_PROMPT)

        #For storing the kickstart and the system images
        switch_cons.sendline('show version | grep "image file is"')
        switch_cons.expect(defn.SWITCH_PROMPT)
        string = switch_cons.before
        if "///" in string:
            sys = string.split('///')[1]
            sys = sys.split()[0]
        if sys != "":
            switch_cons.sendline('dir')
            switch_cons.expect(defn.SWITCH_PROMPT)
            dir = switch_cons.before
            imgs = dir.split()
            if sys in imgs:
                founds = 1

        logging.info("Found sys %d", founds)
        if founds==1:
            db.update_images(self.switch_name,"",sys)
        else:
            db.update_images(self.switch_name,"","")

        #Now write erase and copy the running config to file
        switch_cons.sendline('delete run_power_config n')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        switch_cons.sendline('delete start_power_config n')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)

        #no boot kick and sys
        switch_cons.sendline('config t')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        switch_cons.sendline('no boot nxos')
        switch_cons.expect(defn.SWITCH_PROMPT, 60)
        #write erase
        switch_cons.sendline('write erase')
        switch_cons.expect('Do you wish to proceed anyway')
        switch_cons.sendline('y')
        switch_cons.expect(defn.SWITCH_PROMPT, 120)
        #write erase boot
        switch_cons.sendline('write erase boot')
        switch_cons.expect('Do you wish to proceed anyway')
        switch_cons.sendline('y')
        switch_cons.expect(defn.SWITCH_PROMPT, 120)
        
        "Now copy the running config to run_power_config file"
        switch_cons.sendline('show running-config vdc-all > run_power_config')
        i = switch_cons.expect([defn.SWITCH_PROMPT,r'yes/no',pexpect.TIMEOUT, pexpect.EOF])
        if i==0:
            pass
        if i==1:
            switch_cons.sendline('yes')
            switch_cons.expect(defn.SWITCH_PROMPT,180)
        if i==2 or i==3:
            print "Something wrong with switch %s so go ahead and poweroff" % self.switch_name
            return False
        
        "Now copy the startup config to run_power_config file"
        switch_cons.sendline('show startup-config vdc-all > start_power_config')
        i = switch_cons.expect([defn.SWITCH_PROMPT,r'yes/no',pexpect.TIMEOUT, pexpect.EOF])
        if i==0:
            pass
        if i==1:
            switch_cons.sendline('yes')
            switch_cons.expect(defn.SWITCH_PROMPT,180)
        if i==2 or i==3:
            print "Something wrong with switch %s so go ahead and poweroff" % self.switch_name
            return False
        
        Switch.setip(switch_cons,self.mgmt_ip)

        #Copy the kickstart and system image to server only if present
        if founds==1:
            d_file = "%s/%s.system.gbin"%(self.switch_name,self.switch_name)
            Switch.copy_files_to_server(switch_cons=switch_cons,s_file=sys,d_file=d_file)
        d_file = "%s/%s.run_power_config"%(self.switch_name,self.switch_name)
        Switch.copy_files_to_server(switch_cons=switch_cons,s_file='run_power_config',d_file=d_file)
        d_file = "%s/%s.start_power_config"%(self.switch_name,self.switch_name)
        Switch.copy_files_to_server(switch_cons=switch_cons,s_file='start_power_config',d_file=d_file)
        
        return True
Beispiel #10
0
#        order_params.append(mat_ops.get_local_op(A, rc))   # Goyal thesis, calling Fortran
        n1, n2 = mat_ops.get_local_op2(A, rc)               # Goyal thesis, alternative call
#        n1, n2 = n1/fA, n2/(1-fA)                           # rescale to make sense
        op = float(np.dot(n1-n2, n1-n2))/np.dot(n1+n2, n1+n2)
        order_params.append(op)
    return np.average(order_params)


if __name__ == "__main__":
    args = docopt(__doc__)
#    print args
    rc = float(args["<rc>"])
    systems = glob.glob(args["<systems>"])
    dumpfiles = args["<dumpfiles>"]

    fAs = list(set([float(sys.split("/")[0].split("_")[1]) for sys in systems]))
    ABs = list(set([float(sys.split("/")[0].split("_")[3]) for sys in systems]))
    fAs.sort()
    ABs.sort()
    print fAs, "\n", ABs
 
    op_mat = np.zeros((len(ABs), len(fAs)))
    for i in range(len(ABs)):
        for j in range(len(fAs)):
            system = "fA_" + str(fAs[j]) + "_AB_" + str(ABs[i])
            path = os.path.join(os.getcwd(), system, "Dump", dumpfiles)
            op_mat[i, j] = get_average_op(glob.glob(path), rc, fAs[j])
            if args["--gnuplot"]:
                print ABs[i], fAs[j], op_mat[i, j]
    save_matrix(op_mat, fAs, ABs, args["--save"])
                processRoadMap(cols, row)

readArchiSysSoftware()
readArchiProperties()
readNameMapping()

#For each system software in archi match to a roadmap entry
for sys in sysSoftware:
    #Check not in mapping file
    sysNew = nameMapping.get(sys, sys)
    #Check not direct match (this will be found in mapping entry)
    tech = roadMapDates.get(sysNew, None)
    matched = False
    if tech == None:
        #Find the version in the system software
        words = sys.split()
        sysVersion = ""
        for word in words:
            if isNumber(word):
                sysVersion = word
            else:
                ws = word.split('v')
                for w in ws:
                    if isNumber(w): sysVersion = w

        #print sys, sysVersion
        for tech in roadMapDates:
            #Check how many words match
            #Note: first word must match, as should the version (if present)
            words = tech.split()
            matchCount = 0
Beispiel #12
0
        #        order_params.append(mat_ops.get_local_op(A, rc))   # Goyal thesis, calling Fortran
        n1, n2 = mat_ops.get_local_op2(A, rc)  # Goyal thesis, alternative call
        #        n1, n2 = n1/fA, n2/(1-fA)                           # rescale to make sense
        op = float(np.dot(n1 - n2, n1 - n2)) / np.dot(n1 + n2, n1 + n2)
        order_params.append(op)
    return np.average(order_params)


if __name__ == "__main__":
    args = docopt(__doc__)
    #    print args
    rc = float(args["<rc>"])
    systems = glob.glob(args["<systems>"])
    dumpfiles = args["<dumpfiles>"]

    fAs = list(set([float(sys.split("/")[0].split("_")[1])
                    for sys in systems]))
    ABs = list(set([float(sys.split("/")[0].split("_")[3])
                    for sys in systems]))
    fAs.sort()
    ABs.sort()
    print fAs, "\n", ABs

    op_mat = np.zeros((len(ABs), len(fAs)))
    for i in range(len(ABs)):
        for j in range(len(fAs)):
            system = "fA_" + str(fAs[j]) + "_AB_" + str(ABs[i])
            path = os.path.join(os.getcwd(), system, "Dump", dumpfiles)
            op_mat[i, j] = get_average_op(glob.glob(path), rc, fAs[j])
            if args["--gnuplot"]:
                print ABs[i], fAs[j], op_mat[i, j]
Beispiel #13
0
card_.write("kmax * # number of nuisance parameters \n")
card_.write("--------------- \n")
card_.write("bin incl \n")
card_.write("observation %i \n"%(f_.Get("h_data_obs")).Integral())
card_.write("--------------- \n")
card_.write("shapes * * %s h_$PROCESS h_$PROCESS_$SYSTEMATIC \n"%args.infile)
card_.write("--------------- \n")
card_.write("bin " + "incl "*len(process_order)+"\n")
card_.write("process "+' '.join(process_order)+" \n")
card_.write("process "+' '.join([process_number_dict[i] for i in process_order])+" \n")
card_.write("rate  "+' '.join([str(round(i,2)) for i in rates])+" \n")
card_.write("--------------- \n")
for sys in all_systematics:
    if "MCStat" in sys:
        continue
        tag = sys.split("MCStat")[0]
        binary_string = " ".join([str(int(i == tag)).replace("0","-") for i in process_order])
        card_.write(sys + " " + "shape" + " " + binary_string + "\n")
    
    elif "cTagCalib" in sys:
        card_.write(sys + " " + "shape" + " " + "1 "*len(processes) + "\n") 
    # elif "muR" in sys:
#         binary_string = " ".join([(str(int("tt" in i)*1.11)).replace("0.0","-") for i in process_order])#.replace("0","-")
#         card_.write("muR " + "lnN" + " " + binary_string + "\n")
#     elif "muF" in sys:
#         binary_string = " ".join([(str(int("tt" in i)*1.04)).replace("0.0","-") for i in process_order])#.replace("0","-")
#         card_.write("muF " + "lnN" + " " + binary_string + "\n")    
    elif "hdamp" in sys or "JES" in sys or "JER" in sys or "Tune" in sys or "muR" in sys or "muF" in sys:# These are only on the ttbar samples
		binary_string = " ".join([str(int("tt" in i)).replace("0","-") for i in process_order])
		card_.write(sys + " " + "shape" + " " + binary_string + "\n")
    else:
Beispiel #14
0
        print sys
        ttHUp = f.Get("ttH_" + discr + "_" + c + "_" + sys + "Up")
        ttHDown = f.Get("ttH_" + discr + "_" + c + "_" + sys + "Down")
        #print ttHUp, ttHUp
        if ttHUp == None:
            print "no sys for ttH"
            ttHUp = f.Get("ttH_" + discr + "_" + c)
            ttHDown = f.Get("ttH_" + discr + "_" + c)

        bkgsUp = []
        bkgsDown = []

        for p in bkgProcs:
            if "Q2scale" in sys or "PSscale" in sys:
                print sys, p
                if p != sys.split("_")[-1]:
                    print "add nom"
                    bkgsUp.append(f.Get(p + "_" + discr + "_" + c))
                    bkgsDown.append(f.Get(p + "_" + discr + "_" + c))
                else:
                    print "add sys"
                    bkgsUp.append(
                        f.Get(p + "_" + discr + "_" + c + "_" + sys + "Up"))
                    bkgsDown.append(
                        f.Get(p + "_" + discr + "_" + c + "_" + sys + "Down"))
            else:
                bkgsUp.append(
                    f.Get(p + "_" + discr + "_" + c + "_" + sys + "Up"))
                bkgsDown.append(
                    f.Get(p + "_" + discr + "_" + c + "_" + sys + "Down"))
            #print bkgsUp
Beispiel #15
0
#mini yml file
time_of_runs = str(sys.argv[1])

with open(time_of_runs, 'r') as infile:
    data = infile.readlines()

    x = 0
    for i in xrange(len(data)):  #because we will need the next line
        if 'user' in data[i]:
            z = i
            #usr_time = data[z].rstrip('\n')
            usr_time = data[z].split('\t')
            usr = usr_time[1]
            usr = usr.rstrip('\n')
            usr = usr.rstrip('s')
            usr_l = usr.split('m')
            usr = usr_l[1].replace('.', '')
            #sys_time = data[z+1].rstrip('\n')
            sys_time = data[z + 1].split('\t')
            sys = sys_time[1]
            sys = sys.rstrip('\n')
            sys = sys.rstrip('s')
            sys_l = sys.split('m')
            sys = sys_l[1].replace('.', '')
            time_ = int(usr) + int(sys)
            run_time.append(str(time_) + '\n')
#Output
with open('time_total', 'w') as outfile:
    outfile.writelines(run_time)
Beispiel #16
0
    def MeasurementData(self, dev, xmldata):
        global devAddr
        print
        print "MeasurementData dev %s" % dev
        if interpret_data:
            Measurement(DataList(xmldata)).describe()
        else:
            print "=== Data: ", xmldata

            # H&C data parsing and upload to virtualizer
            deviceData = parseDeviceXmlData(xmldata)

            if devAddr == NONIN_PULSEOXYMETER_BT_ADDR:
                for i in range(len(deviceData)):
                    if i == 0:
                        satO2 = deviceData[i]
                        satO2 = satO2.split(".")[0]
                        print "SatO2: " + satO2 + " %"
                    elif i == 1:
                        pulseOx = deviceData[i]
                        pulseOx = pulseOx.split(".")[0]
                        print "Pulse: " + pulseOx + " BPM"

                xmlDataToPost = createPulseoxymeterXmlToPost(pulseOx, satO2)

            elif devAddr == OMRON_SCALE_BT_ADDR:
                for i in range(len(deviceData)):
                    if i == 0:
                        weight = deviceData[i]
                        print "Weight: " + weight + " kg"
                    elif i == 2:
                        bmi = deviceData[i]
                        print "Body Mass Index (BMI): " + bmi
                    elif i == 3:
                        bodyFat = deviceData[i]
                        print "Body Fat: " + bodyFat
                    elif i == 4:
                        restingMetabolism = deviceData[i]
                        print "Resting Metabolism: " + restingMetabolism + " cal"
                    elif i == 5:
                        visceralFat = deviceData[i]
                        print "Visceral Fat: " + visceralFat
                    elif i == 6:
                        bodyAge = deviceData[i]
                        print "Body Age: " + bodyAge
                    elif i == 7:
                        skeletalMuscle = deviceData[i]
                        print "Skeletal Muscle: " + skeletalMuscle + " %"

                xmlDataToPost = createScaleXmlToPost(weight, bodyFat, skeletalMuscle)

            elif devAddr == OMRON_SPHYGMOMANOMETER_BT_ADDR:
                for i in range(len(deviceData)):
                    if i == 0:
                        pulse = deviceData[i]
                        pulse = pulse.split(".")[0]
                        print "Pulse: " + pulse + " BPM"
                    elif i == 2:
                        sys = deviceData[i]
                        sys = sys.split(".")[0]
                        print "Systolic Pressure: " + sys + " mmHg"
                    elif i == 3:
                        dia = deviceData[i]
                        dia = dia.split(".")[0]
                        print "Diastolic Pressure: " + dia + " mmHg"

                xmlDataToPost = createSphygmomanometerXmlToPost(sys, dia, pulse)

            print xmlDataToPost

            if VIRTUALIZER_UPDATE:
                updateVirtualizer(xmlDataToPost)