def pack(): usage = 'usage: %prog -p path' parser = optparse.OptionParser(usage) parser.add_option('--prefix', '-p', dest='prefix', help='prefix', default=None) hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser) (opt, args) = parser.parse_args() if not opt.prefix: parser.error('Prefix not defined: check the usage') prefix = opt.prefix if opt.prefix[-1] != '/' else opt.prefix[:-1] tmppath = tempfile.mkdtemp('_pack_' + prefix) shutil.copytree(prefix + '/datacards', tmppath + '/datacards') if opt.variable == 'mll': os.system('rename _shape _mllShape ' + tmppath + '/datacards/*_shape.txt') elif opt.variable == 'bdts': os.system('rename _shape _bdtShape ' + tmppath + '/datacards/*_shape.txt') tarname = tmppath + '/' + prefix + '.tgz' here = os.getcwd() os.chdir(tmppath) tar = tarfile.open(tarname, mode='w:gz') tar.add('datacards') tar.close() shutil.move(tarname, here)
def pack(): usage = 'usage: %prog -p path' parser = optparse.OptionParser(usage) parser.add_option('--prefix','-p',dest='prefix',help='prefix',default=None) hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser) (opt, args) = parser.parse_args() if not opt.prefix: parser.error('Prefix not defined: check the usage') prefix = opt.prefix if opt.prefix[-1] != '/' else opt.prefix[:-1] tmppath = tempfile.mkdtemp('_pack_'+prefix) shutil.copytree(prefix+'/datacards',tmppath+'/datacards') if opt.variable == 'mll': os.system('rename _shape _mllShape '+tmppath+'/datacards/*_shape.txt') elif opt.variable == 'bdts': os.system('rename _shape _bdtShape '+tmppath+'/datacards/*_shape.txt') tarname = tmppath+'/'+prefix+'.tgz' here = os.getcwd() os.chdir(tmppath) tar = tarfile.open(tarname,mode='w:gz') tar.add('datacards') tar.close() shutil.move(tarname,here)
def addOptions(parser): parser.add_option('-o', '--output', dest='output', help='Output directory (%default)', default=None) parser.add_option('-x', '--xlabel', dest='xlabel', help='X-axis label', default='') parser.add_option('-r', '--ratio', dest='ratio', help='Plot the data/mc ration', default=True, action='store_false') parser.add_option('--errormode', dest='errmode', help='Algo to calculate the errors', default='errorband') parser.add_option('--nofit', dest='fit', help='Don\'t fit', default=True, action='store_false') parser.add_option('--clean', dest='clean', help='Clean the ws (regenerate)', default=False, action='store_true') parser.add_option('--dump', dest='dump', help='Dump the histograms to file', default=None) parser.add_option('--tmpdir', dest='tmpdir', help='Temporary directory', default=None) parser.add_option('--usefit', dest='usefit', help='Do not fit, use an external file', default=None) parser.add_option('--stretch', dest='stretch', help='Stretch', default=None, type='float') hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser)
def addOptions( parser ): parser.add_option('-o' , '--output' , dest='output' , help='Output directory (%default)' , default=None) parser.add_option('-x' , '--xlabel' , dest='xlabel' , help='X-axis label' , default='') parser.add_option('-r' , '--ratio' , dest='ratio' , help='Plot the data/mc ration' , default=True , action='store_false') parser.add_option('--errormode' , dest='errmode', help='Algo to calculate the errors' , default='errorband') parser.add_option('--nofit' , dest='fit' , help='Don\'t fit' , default=True , action='store_false') parser.add_option('--clean' , dest='clean' , help='Clean the ws (regenerate)' , default=False , action='store_true') parser.add_option('--dump' , dest='dump' , help='Dump the histograms to file' , default=None) parser.add_option('--tmpdir' , dest='tmpdir' , help='Temporary directory' , default=None) parser.add_option('--usefit' , dest='usefit' , help='Do not fit, use an external file', default=None) parser.add_option('--stretch' , dest='stretch', help='Stretch' , default=None, type='float') hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser)
def main(): ## option parser usage = 'usage: %prog [options]' parser = optparse.OptionParser(usage) hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser) addOptions(parser) (opt, args) = parseOptions(parser) inputdir = opt.inputdir outputdir = opt.outputdir mass = opt.mass # get MWLPlot.C shapepath = os.path.abspath(os.path.dirname(os.path.normpath(__file__))+'/..') print 'Shape main directory is',shapepath ROOT.gInterpreter.ExecuteMacro(shapepath+'/macros/LatinoStyle2.C') hwwtools.loadAndCompile(shapepath+'/macros/MWLPlot.C') filenames = getFiles(inputdir) # loop over all files for file in filenames: path = inputdir+'/'+file if not any([ (str(m) in file) for m in mass ]): continue # if str(mass) not in file and mass > 0: # continue print 'Making',path if not opt.variations: makeNominalPlots(path, outputdir, opt) else: makeShapeUpDown(path,outputdir, opt) print 'Used options' print ', '.join([ '{0} = {1}'.format(a,b) for a,b in opt.__dict__.iteritems()])
usage = 'usage: %prog [options]' parser = optparse.OptionParser(usage) parser.add_option('--tag' , dest='tag' , help='Tag used for the shape file name' , default=None) parser.add_option('--sigset' , dest='sigset' , help='Signal samples [SM]' , default='SM') parser.add_option('--inputDir' , dest='inputDir' , help='input directory' , default='./') parser.add_option('--outputDir' , dest='outputDir' , help='output directory' , default='./') parser.add_option('--outputFileName' , dest='outputFileName' , help='output file name' , default='01_PseudoDataSmeared') parser.add_option('--analysisName' , dest='analysisName' , help='analysis name' , default='Stop') parser.add_option('--structureFile' , dest='structureFile' , help='file with datacard configurations' , default=None ) parser.add_option('--nuisancesFile' , dest='nuisancesFile' , help='file with nuisances configurations' , default=None ) # read default parsing options as well hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser) (opt, args) = parser.parse_args() sys.argv.append( '-b' ) ROOT.gROOT.SetBatch() print " configuration file = ", opt.pycfg print " inputDir = ", opt.inputDir print " outputDir = ", opt.outputDir print " outputFileName = ", opt.outputFileName if not opt.debug: pass elif opt.debug == 2:
#!/usr/bin/env python import hwwinfo import hwwtools import optparse parser = optparse.OptionParser() hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser, quiet=True) (opt,args) = parser.parse_args([]) # print opt print '\n' print 'export masses="'+' '.join([str(mass) for mass in hwwinfo.masses])+'";' # print 'export jets="'+' '.join([str(njet) for njet in hwwinfo.jets])+'";' print 'export flavors="'+' '.join(hwwinfo.flavors)+'";' print 'export channels="'+' '.join(hwwinfo.channels)+'";' print 'export lumi="%.2f"' % opt.lumi+';'
#!/usr/bin/env python import hwwinfo import hwwtools import optparse parser = optparse.OptionParser() hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser, quiet=True) (opt, args) = parser.parse_args([]) # print opt print '\n' print 'export masses="' + ' '.join([str(mass) for mass in hwwinfo.masses]) + '";' # print 'export jets="'+' '.join([str(njet) for njet in hwwinfo.jets])+'";' print 'export flavors="' + ' '.join(hwwinfo.flavors) + '";' print 'export channels="' + ' '.join(hwwinfo.channels) + '";' print 'export lumi="%.2f"' % opt.lumi + ';'
def main(): usage = '''usage: %prog [opts] dctag''' parser = optparse.OptionParser(usage) parser.add_option('-s', '--stepping', dest='stepping', help='Switch stepping on ', action='store_true', default=False) parser.add_option('-1', dest='minuit1', help='Minuit ', action='store_true', default=False) parser.add_option('-n', dest='dryrun', help='Dry run ', action='store_true', default=False) parser.add_option('-o', dest='observed', help='Observed only', action='store_true', default=False) parser.add_option('--prefix', '-p', dest='prefix', help='prefix', default=None) hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser) (opt, args) = parser.parse_args() print 'Running with lumi', opt.lumi constraints = {'*': '--rMin=0.01'} if len(args) != 1: parser.error('One and only one datacard tag at the time') tag = args[0] if tag not in hwwlimits.dcnames['all']: parser.error('Wrong tag: ' + ', '.join(sorted(hwwlimits.dcnames['all']))) tmpl = 'hww-{lumi:.2f}fb.mH{mass}.{tag}_shape.txt' # masses = hwwinfo.masses[:] if opt.mass == 0 else [opt.mass] masses = opt.mass if opt.prefix: os.chdir(opt.prefix) print 'Running in ', os.getcwd() if not os.path.exists(indir): print 'Error: datacard directory', indir, 'not found' sys.exit(-1) allcards = [(mass, os.path.join(indir, tmpl.format(mass=mass, tag=tag, lumi=opt.lumi))) for mass in masses] for mass, card in allcards: if ((int(opt.lumi) < 10 or int(opt.lumi) > 22) and (int(mass) == 145 or int(mass) == 155)): continue if not os.path.exists(card): print 'Error: missing datacard: ' + card sys.exit(-1) os.system('mkdir -p ' + outdir) tagname = 'HWW_' + tag + '_shape' for mass, card in allcards: print opt.lumi, mass if ((int(opt.lumi) < 10 or int(opt.lumi) > 22) and (int(mass) == 145 or int(mass) == 155)): continue exe = 'combine -v 2 -M Asymptotic' flags = ' -n %s -m %s %s' % (tagname, mass, card) if opt.stepping: flags = ' --minosAlgo stepping' + flags if opt.minuit1: flags = ' --minimizerAlgo Minuit' + flags if opt.observed: flags = ' --run observed' + flags for c, flag in constraints.iteritems(): if fnmatch.fnmatch(str(mass), c): flags = ' ' + flag + flags command = exe + flags print '-' * 50 print command if opt.dryrun: continue code = os.system(command) move = 'mv higgsCombine%s.Asymptotic.mH%d.root %s' % (tagname, mass, outdir) print move os.system(move) if code: sys.exit(code)
def runTheShape(): usage = 'usage: %prog -t tag -p prefix channel' parser = optparse.OptionParser(usage) parser.add_option('--tag', '-t', dest='tag', help='tag to identify the plots', default=None) parser.add_option('--prefix', '-p', dest='prefix', help='prefix', default='.') hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser) (opt, args) = parser.parse_args() tag = opt.tag.replace(' ', '_') if not args: raise ValueError('Desired channels missing: check the usage') if args[0] in hwwlimits.dcnames: plots = hwwlimits.dcnames[args[0]] else: plots = args[:] if opt.prefix: os.chdir(opt.prefix) name = opt.prefix if opt.prefix[-1] != '/' else opt.prefix[:-1] macropath = os.path.join(os.path.dirname(mypath), 'macros') import ROOT hwwtools.loadAndCompile(macropath + '/tdrstyle.C') hwwtools.loadAndCompile(macropath + '/PlotLimit.C') data = '8' if int(opt.lumi) < 10: data = '7' pars = { 'tag': tag, 'option': '', 'mypath': mypath, 'name': name, 'lumi': opt.lumi, 'data': data } print pars os.system('mkdir -p plots') for plot in plots: print plot pars['option'] = plot command = plot_tmpl.format(tag=tag, option=plot, mypath=macropath, name=name, lumi=opt.lumi) print command p = os.system(command) ROOT.gROOT.SetBatch(True) ROOT.setTDRStyle() if int(opt.lumi) < 22: ROOT.PlotLimit("limits/{option}_shape.summary".format(**pars), "plots/{tag}_{name}_{option}".format(**pars), ("{lumi} fb^{{-1}} ({data} TeV)".format(**pars)), 110, 600, 1, 1, "H #rightarrow WW #rightarrow 2l2#nu", True, 0, 'pdf') ROOT.PlotLimit("limits/{option}_shape.summary".format(**pars), "plots/{tag}_{name}_{option}".format(**pars), ("{lumi} fb^{{-1}} ({data} TeV)".format(**pars)), 110, 600, 1, 1, "H #rightarrow WW #rightarrow 2l2#nu", True, 0, 'png') else: ROOT.PlotLimit("limits/{option}_shape.summary".format(**pars), "plots/{tag}_{name}_{option}".format(**pars), "default", 110, 600, 1, 1, "H #rightarrow WW #rightarrow 2l2#nu", True, 0, 'pdf') ROOT.PlotLimit("limits/{option}_shape.summary".format(**pars), "plots/{tag}_{name}_{option}".format(**pars), "default", 110, 600, 1, 1, "H #rightarrow WW #rightarrow 2l2#nu", True, 0, 'png')
def main(): usage = '''usage: %prog [opts] dctag''' parser = optparse.OptionParser(usage) parser.add_option('-s','--stepping',dest='stepping',help='Switch stepping on ', action='store_true', default=False) parser.add_option('-1',dest='minuit1',help='Minuit ', action='store_true', default=False) parser.add_option('-n',dest='dryrun',help='Dry run ', action='store_true', default=False) parser.add_option('-o',dest='observed',help='Observed only', action='store_true', default=False) parser.add_option('--prefix','-p',dest='prefix',help='prefix',default=None) hwwtools.addOptions(parser) hwwtools.loadOptDefaults(parser) (opt, args) = parser.parse_args() print 'Running with lumi',opt.lumi constraints = { '*':'--rMin=0.01' } if len(args) != 1: parser.error('One and only one datacard tag at the time') tag = args[0] if tag not in hwwlimits.dcnames['all']: parser.error('Wrong tag: '+', '.join(sorted(hwwlimits.dcnames['all']))) tmpl = 'hww-{lumi:.2f}fb.mH{mass}.{tag}_shape.txt' # masses = hwwinfo.masses[:] if opt.mass == 0 else [opt.mass] masses = opt.mass if opt.prefix: os.chdir(opt.prefix) print 'Running in ',os.getcwd() if not os.path.exists(indir): print 'Error: datacard directory',indir,'not found' sys.exit(-1) allcards = [(mass,os.path.join(indir,tmpl.format(mass=mass, tag=tag, lumi=opt.lumi))) for mass in masses] for mass,card in allcards: if ((int(opt.lumi)<10 or int(opt.lumi)>22) and (int(mass)==145 or int(mass)==155)): continue if not os.path.exists(card): print 'Error: missing datacard: '+card sys.exit(-1) os.system('mkdir -p '+outdir) tagname = 'HWW_'+tag+'_shape' for mass,card in allcards: print opt.lumi, mass if ((int(opt.lumi)<10 or int(opt.lumi)>22) and (int(mass)==145 or int(mass)==155)): continue exe = 'combine -v 2 -M Asymptotic' flags = ' -n %s -m %s %s'%(tagname,mass,card) if opt.stepping: flags = ' --minosAlgo stepping'+flags if opt.minuit1: flags = ' --minimizerAlgo Minuit'+flags if opt.observed: flags = ' --run observed'+flags for c,flag in constraints.iteritems(): if fnmatch.fnmatch(str(mass),c): flags = ' '+flag+flags command = exe+flags print '-'*50 print command if opt.dryrun: continue code = os.system(command) move = 'mv higgsCombine%s.Asymptotic.mH%d.root %s' % (tagname,mass,outdir) print move os.system(move) if code: sys.exit(code)