コード例 #1
0
 print "##"
 for chn in config.channels:
     for per in config.periods:
         for idx in range(len(config.bbbcat[chn][per])):
             if options.new_merging:
                 filename = 'htt_' + chn + '.inputs-mssm-' + per + '-0.root'
                 for cat in config.bbbcat[chn][per][idx].split(','):
                     ## loop all categories in question for index idx
                     if len(config.bbbproc[chn][idx].replace(
                             '>', ',').split(',')) > 1:
                         ## only get into action if there is more than one sample to do the merging for
                         os.system(
                             "merge_bin_errors.py --folder {DIR} --processes {PROC} --bbb_threshold={BBBTHR} --merge_threshold={THRESH} --verbose {SOURCE} {TARGET}"
                             .format(
                                 ## this list has only one entry by construction
                                 DIR=get_channel_dirs(
                                     chn, cat, per)[0],
                                 PROC=config.bbbproc[chn]
                                 [idx].replace('>', ','),
                                 BBBTHR=config.bbbthreshold[chn],
                                 THRESH=options.
                                 new_merging_threshold,
                                 SOURCE=dir + '/' + ana + '/' +
                                 chn + '/' + filename,
                                 TARGET=dir + '/' + ana + '/' +
                                 chn + '/' + filename,
                             ))
             normalize_bbb = ''
             if not options.drop_normalize_bbb:
                 normalize_bbb = ' --normalize '
             os.system(
                 "add_bbb_errors.py '{CHN}:{PER}:{CAT}:{PROC}' {NORMALIZE} -f --in {DIR}/{ANA} --out {DIR}/{ANA}-tmp --threshold {THR} --mssm"
コード例 #2
0
def create_systematics(ana, channel, category, process, period, shape_file, threshold, normalize):
    '''
    Create the bin-by-bin systematics in the shape file.
    Returns a list of tuples of kind [(channel name, list of added systs)]
    '''
    ## determine directories pointred to in the datacards (NB: can be more than one, e.g. in vhtt)
    channel_names = get_channel_dirs(ana, channel, category, period)
    # Parse process description in case we merge histograms
    process_to_merge_in = []
    ## default case -> process = target_process
    target_process = process
    if '>' in process:
        log.info("Detected multi-error merge: %s", process)
        target_process = process.split('>')[1].strip()
        for x in process.split('>')[0].split('+'):
            process_to_merge_in.append(x.strip())
    ## set up command line for bbb uncertainty creation in each root directory
    channel_name_and_systematics = []
    for channel_name in channel_names :
        root_path = os.path.join('/',channel_name, target_process)
        if root_path[0] == '/':
            root_path = root_path[1:]
        ## compose uncertainty name
        if channel == 'vhtt' :
            uncert_name = 'CMS_vhtt_%s_%s' % (channel_name, period)
        else :
            uncert_name = 'CMS_htt_%s_%s_%s' % (channel, channel_name, period)
        ## main command to add stat shapes
        command = [
            'add_stat_shapes.py',
            shape_file, # input
            shape_file, # output (modded in place)
            '--filter',
            root_path, # the histogram we are bbb-ing
            '--prefix',
            # Make the prefix as short as possible, to avoid RooFit
            # string-to-long bug
            # This prefix is needed so the systematics names don't overlap
            # between ET/MT, boost/VBF, etc.
            uncert_name,
            '--threshold',
            str(threshold),
            ]
        if normalize:
            command.append('--normalize')
        if process_to_merge_in:
            command.append('--merge-errors')
            command.extend(process_to_merge_in)
        ## and execute
        log.debug("Shape command:")
        log.debug(" ".join(command))
        ## run the command, get the list of new names (written to stdout)
        stdout = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=sys.stderr).communicate()[0]
        added_systematics = []
        for line in stdout.split('\n'):
            ## add proper regex match here
            match=re.compile("CMS_v?htt")
            if line and match.search(line):
                added_systematics.append(line.strip())
        channel_name_and_systematics.append((channel_name, added_systematics))
    return channel_name_and_systematics
コード例 #3
0
             for proc in hww_processes :
                 os.system(r"root -l -b -q {CMSSW_BASE}/src/HiggsAnalysis/HiggsToTauTau/macros/rescaleSignal.C+\(true,{SCALE},\"{INPUTFILE}\",\"{PROCESS}\",0\)".format(
                     CMSSW_BASE=os.environ.get("CMSSW_BASE"),
                     SCALE=hww_over_htt['125']*float(options.hww_scale),
                     INPUTFILE=file,
                     PROCESS=proc+'125'
                     ))
 ## if requested apply horizontal morphing for processes to get templates for intermediate masses
 if options.interpolate:
     for i in range(len(masspoints)-1):
         for chn in config.channels:
             for per in config.periods:
                 for cat in config.categories[chn][per]:
                     for file in glob.glob("{SETUP}/{CHN}/htt_{CHN}.inputs-sm-{PER}*.root".format(SETUP=setup,CHN=chn, PER=per, CAT=cat)):
                         for proc in ['ggH','qqH','VH']:
                             template_morphing = Morph(file, get_channel_dirs(chn,"0"+cat,per)[0], proc+'{MASS}', ','.join(get_shape_systematics(setup,per,chn,"0"+cat,proc)), masspoints[i]+','+masspoints[i+1], options.interpolate, True,'', '') 
                             template_morphing.run()
         ## add the new points to the masses array
         masses.append(masspoints[i]+'-'+masspoints[i+1]+':'+options.interpolate)
     ## set the masspoint list to the new points
     masspoints = [str(m) for m in range(int(masspoints[0]),int(masspoints[-1])+1,int(options.interpolate))]
 ## set up directory structure
 dir = "{CMSSW_BASE}/src/setups{LABEL}".format(CMSSW_BASE=cmssw_base, LABEL=options.label)
 if os.path.exists(dir) :
     if os.path.exists(dir.replace('src/', 'src/backup/')):
         os.system("rm -r "+dir.replace('src/', 'src/backup/'))
     os.system("mv {DIR} {CMSSW_BASE}/src/backup/".format(DIR=dir, CMSSW_BASE=cmssw_base))
 os.system("mkdir -p {DIR}".format(DIR=dir))
 for ana in analyses :
     if 'hww-sig' in ana :
         continue
コード例 #4
0
 if ana == 'bbb' :
     print "##"
     print "## update bbb    directory in setup:"
     print "##"    
     for chn in config.channels:
         for per in config.periods:
             for idx in range(len(config.bbbcat[chn][per])):
                 if options.new_merging :
                     filename='vhtt.inputs-sm-'+per+'.root' if chn == "vhtt" else 'htt_'+chn+'.inputs-bbA-'+per+'.root'
                     for cat in config.bbbcat[chn][per][idx].split(',') :
                         ## loop all categories in question for index idx
                         if len(config.bbbproc[chn][idx].replace('>',',').split(','))>1 :
                             ## only get into action if there is more than one sample to do the merging for
                             os.system("merge_bin_errors.py --folder {DIR} --processes {PROC} --bbb_threshold={BBBTHR} --merge_threshold={THRESH} --verbose {SOURCE} {TARGET}".format(
                                 ## this list has only one entry by construction
                                 DIR=get_channel_dirs(chn, cat,per)[0],
                                 PROC=config.bbbproc[chn][idx].replace('>',','),
                                 BBBTHR=config.bbbthreshold[chn],
                                 THRESH=options.new_merging_threshold,
                                 SOURCE=dir+'/'+ana+'/'+chn+'/'+filename,
                                 TARGET=dir+'/'+ana+'/'+chn+'/'+filename,
                                 ))
                 normalize_bbb = ''
                 if not options.drop_normalize_bbb :
                     normalize_bbb = ' --normalize '
                 os.system("add_bbb_errors.py '{CHN}:{PER}:{CAT}:{PROC}' {NORMALIZE} -f --in {DIR}/{ANA} --out {DIR}/{ANA}-tmp --threshold {THR} --bbA".format(
                     DIR=dir,
                     ANA=ana,
                     CHN=chn,
                     PER=per,
                     NORMALIZE=normalize_bbb,
コード例 #5
0
 if any('hww-sig' in ana for ana in analyses):
     for file in glob.glob("{SETUP}/em/htt_em.inputs-sm-7TeV*.root".format(SETUP=setup)) :
         template_morphing = Morph(file, 'emu_0jet_low,emu_1jet_low,emu_vbf_loose', 'ggH_hww{MASS}', 'QCDscale_ggH1in,CMS_scale_e_7TeV', '140,150', 5, True,'', '', False) 
         template_morphing.run()
         template_morphing = Morph(file, 'emu_0jet_high,emu_1jet_high', 'ggH_hww{MASS}', 'QCDscale_ggH1in,CMS_scale_e_highpt_7TeV', '140,150', 5, True,'', '', False) 
         template_morphing.run()
         template_morphing = Morph(file, 'emu_0jet_low,emu_1jet_low,emu_vbf_loose', 'qqH_hww{MASS}', 'CMS_scale_e_7TeV', '140,150', 5, True,'', '', False) 
         template_morphing.run()
         template_morphing = Morph(file, 'emu_0jet_high,emu_1jet_high', 'qqH_hww{MASS}', 'CMS_scale_e_highpt_7TeV', '140,150', 5, True,'', '', False) 
         template_morphing.run()
     for per in config.periods:
         for cat in config.categories['vhtt'][per]:
             for file in glob.glob("{SETUP}/{CHN}/vhtt.inputs-sm-{PER}*.root".format(SETUP=setup,CHN=chn, PER=per, CAT=cat)):
                 if cat in ['0','1']:
                     proc = 'WH_hww'
                     for dir in get_channel_dirs(chn,"0"+cat,per):
                         template_morphing = Morph(file, dir, proc+'{MASS}', ','.join(get_shape_systematics(setup,per,'vhtt',"0"+cat,proc,dir)), '135,140', 5, True,'145', '', False) 
                         template_morphing.run()
 ## scale to SM cross section (main processes and all channels but those listed in do_not_scales)
 for chn in config.channels :
     for file in glob.glob("{SETUP}/{CHN}/*-sm-*.root".format(SETUP=setup, CHN=chn)) :
         if not chn in do_not_scales :
             if chn == 'vhtt':
                 ## vhtt is part of do_no_scale in the current configuration. So nothing will
                 ## happen here for the moment.
                 process = RescaleSamples(file, ['VH' , 'WH' , 'ZH'], masspoints)
                 process.rescale()
             else:
                 process = RescaleSamples(file, ['ggH', 'qqH', 'VH', 'WH', 'ZH'], masspoints)
                 process.rescale()
 if 'em' in config.channels :
コード例 #6
0
 for per in config.periods:
     for idx in range(len(config.bbbcat[chn][per])):
         if options.new_merging:
             filename = 'htt_' + chn + '.inputs-Hhh-' + per + '.root'
             for cat in config.bbbcat[chn][per][idx].split(
                     ','):
                 print cat
                 ## loop all categories in question for index idx
                 if len(config.bbbproc[chn][idx].replace(
                         '>', '+').split('+')) > 1:
                     ## only get into action if there is more than one sample to do the merging for
                     os.system(
                         "merge_bin_errors.py --folder {DIR} --processes {PROC} --bbb_threshold={BBBTHR} --merge_threshold={THRESH} --verbose {SOURCE} {TARGET}"
                         .format(
                             ## this list has only one entry by construction
                             DIR=get_channel_dirs(
                                 "Hhh", chn, cat, per)[0],
                             PROC=config.bbbproc[chn]
                             [idx].split(',')[0].replace(
                                 '>', ','),
                             BBBTHR=config.
                             bbbthreshold[chn],
                             THRESH=options.
                             new_merging_threshold,
                             SOURCE=dir + '/' + ana + '/' +
                             chn + '/' + filename,
                             TARGET=dir + '/' + ana + '/' +
                             chn + '/' + filename,
                         ))
         normalize_bbb = ''
         if not options.drop_normalize_bbb:
             normalize_bbb = ' --normalize '
コード例 #7
0
def create_systematics(channel, category, process, period, shape_file,
                       threshold, normalize):
    '''
    Create the bin-by-bin systematics in the shape file.
    Returns a list of tuples of kind [(channel name, list of added systs)]
    '''
    ## determine directories pointred to in the datacards (NB: can be more than one, e.g. in vhtt)
    channel_names = get_channel_dirs(channel, category, period)
    # Parse process description in case we merge histograms
    process_to_merge_in = []
    ## default case -> process = target_process
    target_process = process
    if '>' in process:
        log.info("Detected multi-error merge: %s", process)
        target_process = process.split('>')[1].strip()
        for x in process.split('>')[0].split('+'):
            process_to_merge_in.append(x.strip())
    ## set up command line for bbb uncertainty creation in each root directory
    channel_name_and_systematics = []
    for channel_name in channel_names:
        root_path = os.path.join('/', channel_name, target_process)
        if root_path[0] == '/':
            root_path = root_path[1:]
        ## compose uncertainty name
        if channel == 'vhtt':
            uncert_name = 'CMS_vhtt_%s_%s' % (channel_name, period)
        else:
            uncert_name = 'CMS_htt_%s_%s_%s' % (channel, channel_name, period)
        ## main command to add stat shapes
        command = [
            'add_stat_shapes.py',
            shape_file,  # input
            shape_file,  # output (modded in place)
            '--filter',
            root_path,  # the histogram we are bbb-ing
            '--prefix',
            # Make the prefix as short as possible, to avoid RooFit
            # string-to-long bug
            # This prefix is needed so the systematics names don't overlap
            # between ET/MT, boost/VBF, etc.
            uncert_name,
            '--threshold',
            str(threshold),
        ]
        if normalize:
            command.append('--normalize')
        if process_to_merge_in:
            command.append('--merge-errors')
            command.extend(process_to_merge_in)
        ## and execute
        log.debug("Shape command:")
        log.debug(" ".join(command))
        ## run the command, get the list of new names (written to stdout)
        stdout = subprocess.Popen(command,
                                  stdout=subprocess.PIPE,
                                  stderr=sys.stderr).communicate()[0]
        added_systematics = []
        for line in stdout.split('\n'):
            ## add proper regex match here
            match = re.compile("CMS_v?htt")
            if line and match.search(line):
                added_systematics.append(line.strip())
        channel_name_and_systematics.append((channel_name, added_systematics))
    return channel_name_and_systematics
コード例 #8
0
 print "##"
 for chn in config.channels:
     if chn != "tt" :
         print chn
         for per in config.periods:
             for idx in range(len(config.bbbcat[chn][per])):
                 if options.new_merging :
                     filename='htt_'+chn+'.inputs-Hhh-'+per+'.root'
                     for cat in config.bbbcat[chn][per][idx].split(',') :
                         print cat
                         ## loop all categories in question for index idx
                         if len(config.bbbproc[chn][idx].replace('>','+').split('+'))>1 :
                             ## only get into action if there is more than one sample to do the merging for
                             os.system("merge_bin_errors.py --folder {DIR} --processes {PROC} --bbb_threshold={BBBTHR} --merge_threshold={THRESH} --verbose {SOURCE} {TARGET}".format(
                                 ## this list has only one entry by construction
                                 DIR=get_channel_dirs("Hhh",chn, cat,per)[0],
                                 PROC=config.bbbproc[chn][idx].split(',')[0].replace('>',','),
                                 BBBTHR=config.bbbthreshold[chn],
                                 THRESH=options.new_merging_threshold,
                                 SOURCE=dir+'/'+ana+'/'+chn+'/'+filename,
                                 TARGET=dir+'/'+ana+'/'+chn+'/'+filename,
                                 ))
                 normalize_bbb = ''
                 if not options.drop_normalize_bbb :
                     normalize_bbb = ' --normalize '
                 os.system("add_bbb_errors.py '{CHN}:{PER}:{CAT}:{PROC}' {NORMALIZE} -f --in {DIR}/{ANA} --out {DIR}/{ANA}-tmp --threshold {THR} --Hhh".format(
                     DIR=dir,
                     ANA=ana,
                     CHN=chn,
                     PER=per,
                     NORMALIZE=normalize_bbb,
コード例 #9
0
 if any('hww-sig' in ana for ana in analyses):
     for file in glob.glob("{SETUP}/em/htt_em.inputs-sm-7TeV*.root".format(SETUP=setup)) :
         template_morphing = Morph(file, 'emu_0jet_low,emu_1jet_low,emu_vbf_loose', 'ggH_hww{MASS}', 'QCDscale_ggH1in,CMS_scale_e_7TeV', '140,150', 5, True,'', '', False) 
         template_morphing.run()
         template_morphing = Morph(file, 'emu_0jet_high,emu_1jet_high', 'ggH_hww{MASS}', 'QCDscale_ggH1in,CMS_scale_e_highpt_7TeV', '140,150', 5, True,'', '', False) 
         template_morphing.run()
         template_morphing = Morph(file, 'emu_0jet_low,emu_1jet_low,emu_vbf_loose', 'qqH_hww{MASS}', 'CMS_scale_e_7TeV', '140,150', 5, True,'', '', False) 
         template_morphing.run()
         template_morphing = Morph(file, 'emu_0jet_high,emu_1jet_high', 'qqH_hww{MASS}', 'CMS_scale_e_highpt_7TeV', '140,150', 5, True,'', '', False) 
         template_morphing.run()
     for per in config.periods:
         for cat in config.categories['vhtt'][per]:
             for file in glob.glob("{SETUP}/{CHN}/vhtt.inputs-sm-{PER}*.root".format(SETUP=setup,CHN=chn, PER=per, CAT=cat)):
                 if cat in ['0','1']:
                     proc = 'WH_hww'
                     for dir in get_channel_dirs(chn,"0"+cat,per):
                         template_morphing = Morph(file, dir, proc+'{MASS}', ','.join(get_shape_systematics(setup,per,'vhtt',"0"+cat,proc,dir)), '135,140', 5, True,'145', '', False) 
                         template_morphing.run()
 ## scale to SM cross section (main processes and all channels but those listed in do_not_scales)
 for chn in config.channels :
     for file in glob.glob("{SETUP}/{CHN}/*-sm-*.root".format(SETUP=setup, CHN=chn)) :
         if not chn in do_not_scales :
             if chn == 'vhtt':
                 ## vhtt is part of do_no_scale in the current configuration. So nothing will
                 ## happen here for the moment.
                 process = RescaleSamples(file, ['VH' , 'WH' , 'ZH'], masspoints)
                 process.rescale()
             else:
                 process = RescaleSamples(file, ['ggH', 'qqH', 'VH', 'WH', 'ZH'], masspoints)
                 process.rescale()
 if 'em' in config.channels :