diff --git a/limits/LimitsLauncher.py b/limits/LimitsLauncher.py index bcfb95c..5dd9622 100644 --- a/limits/LimitsLauncher.py +++ b/limits/LimitsLauncher.py @@ -22,18 +22,18 @@ #"----------------User's decision board-----------------" # choose which scripts to run -do_combineDatacards = False -do_produceLimits = False -do_producePlots = True #note that this flag can be turned to true only when the limit results have been produced +do_combineDatacards = True +do_produceLimits = True +do_producePlots = False #note that this flag can be turned to true only when the limit results have been produced -version_label = 'test3' +version_label = 'test00' # path to datacards # Note that it will get // appended -path_to_datacards = './datacards' +path_to_datacards = '/work/manzoni/hnl_limits/CMSSW_10_2_13/src/HiggsAnalysis/CombinedLimit/WHNL_code/limits/datacards_july_talk/' # which years to process -years = ['2016', '2017', '2018'] +years = ['2018'] # which channels channels = ['mmm', 'mem_os', 'mem_ss'] @@ -50,7 +50,7 @@ signal_type = 'majorana' # you may want to select the mass values you would like to run on -mass_whiteList = ['10.0', '6.0'] #['10.0'] +mass_whiteList = [] #['10.0'] # you may want to select the mass values you would like to ignore mass_blackList = [] @@ -100,6 +100,7 @@ def getStringParser(input): print 'Will run the limits production tool' os.system('mkdir -p results/limits/{}'.format(version_label)) + os.system('mkdir -p logs/{}'.format(version_label)) if run_blind: flag_blind = 1 else: flag_blind = 0 @@ -140,7 +141,7 @@ def getStringParser(input): print 'will run the limit plotter' - command_plotter = 'python limit_plotter.py --version {ver} --signal {sig} --channels {ch} --mass_whitelist {mwl} --mass_blacklist {mbl} --coupling_whitelist {cwl} --coupling_blacklist {cbl}'.format(ver=version_label, sig=signal_type, ch=getStringParser(channels), mwl=getStringParser(mass_whiteList), mbl=getStringParser(mass_blackList), cwl=getStringParser(coupling_whiteList), cbl=getStringParser(coupling_blackList)) + command_plotter = 'python limit_plotter.py --version {ver} --signal {sig} --years {ys} --channels {ch} --mass_whitelist {mwl} --mass_blacklist {mbl} --coupling_whitelist {cwl} --coupling_blacklist {cbl}'.format(ver=version_label, sig=signal_type, ys=getStringParser(years), ch=getStringParser(channels), mwl=getStringParser(mass_whiteList), mbl=getStringParser(mass_blackList), cwl=getStringParser(coupling_whiteList), cbl=getStringParser(coupling_blackList)) if run_blind: command_plotter += ' --run_blind' diff --git a/limits/README.md b/limits/README.md index 7a17cf5..9a915b8 100644 --- a/limits/README.md +++ b/limits/README.md @@ -1,6 +1,9 @@ # Limits Analysis Tool ## Installation + +Note: it is preferable to use a bash environment. + ``` cmsrel CMSSW_10_2_13 cd CMSSW_10_2_13/src @@ -15,7 +18,7 @@ make -j 8; make ``` git clone git@github.com:rmanzoni/plotter.git WHNL_code -cd plotter/limits +cd WHNLcode/limits ``` ## Running the limits diff --git a/limits/combine_datacards.py b/limits/combine_datacards.py index ca7122e..aceb83c 100644 --- a/limits/combine_datacards.py +++ b/limits/combine_datacards.py @@ -73,8 +73,8 @@ def getOptions(): for channel in channels: for year in years: - all_datacards[channel][year] = glob('/'.join([path_year[year], path_channel['mmm'], datacard_wildcard])) - all_datacards[channel][year] = [dd for dd in all_datacards[channel][year] if 'coarse' not in dd and signal_type in dd] + all_datacards[channel][year] = glob('/'.join([path_year[year], path_channel[channels[0]], datacard_wildcard])) + all_datacards[channel][year] = [dd for dd in all_datacards[channel][year] if signal_type in dd] all_datacards[channel][year].sort() print '... datacards {a}_{b} loaded'.format(a=channel, b=year) diff --git a/limits/limit_plotter.py b/limits/limit_plotter.py index a059ae5..762daf7 100644 --- a/limits/limit_plotter.py +++ b/limits/limit_plotter.py @@ -210,7 +210,6 @@ def sortList(input): limits2D[mass]['exp_plus_two' ] = x_plus_two if not opt.run_blind: limits2D[mass]['obs'] = x_obs - print '\nwill plot 2D limits' with open('{}/results.pck'.format(plotDir), 'w') as ff: @@ -237,20 +236,18 @@ def sortList(input): obs.append( min(limits2D[mass]['obs']) ) masses_obs.append(mass) - if len(limits2D[mass]['exp_minus_one'])==len(limits2D[mass]['exp_plus_one']) and len(limits2D[mass]['exp_minus_two'])==len(limits2D[mass]['exp_plus_two']): - if len(limits2D[mass]['exp_central'])>0: + if len(limits2D[mass]['exp_central'])>0 and len(limits2D[mass]['exp_minus_one'])>0 and len(limits2D[mass]['exp_plus_one' ])>0 and len(limits2D[mass]['exp_minus_two'])>0 and len(limits2D[mass]['exp_plus_two' ])>0: central.append( min(limits2D[mass]['exp_central']) ) masses_central.append(float(mass)) - if len(limits2D[mass]['exp_minus_one'])>0 and len(limits2D[mass]['exp_plus_one' ])>0: minus_one.append( min(limits2D[mass]['exp_minus_one']) ) - plus_one .append( min(limits2D[mass]['exp_plus_one' ]) ) + plus_one.append( min(limits2D[mass]['exp_plus_one' ]) ) masses_one_sigma.append(float(mass)) - if len(limits2D[mass]['exp_minus_two'])>0 and len(limits2D[mass]['exp_plus_two' ])>0: minus_two.append( min(limits2D[mass]['exp_minus_two']) ) - plus_two .append( min(limits2D[mass]['exp_plus_two' ]) ) + plus_two.append( min(limits2D[mass]['exp_plus_two' ]) ) masses_two_sigma.append(float(mass)) + for mass in sorted(limits2D.keys(), key=sortList, reverse=True): diff --git a/nn/cfg/train_all_years.cfg.py b/nn/cfg/train_all_years.cfg.py index 617189b..2dd51cc 100644 --- a/nn/cfg/train_all_years.cfg.py +++ b/nn/cfg/train_all_years.cfg.py @@ -107,7 +107,7 @@ # 'l2_ptcone' , 'log_hnl_2d_disp', # 'isdata' , - 'log_hnl_2d_disp_sig_log', +# 'log_hnl_2d_disp_sig_log', # 'l0_pt' , # 'abs_l0_eta' , diff --git a/plotter/cfg/2017/plot_mem_ttbar.cfg.py b/plotter/cfg/2017/plot_mem_ttbar.cfg.py index f670b4d..a263869 100644 --- a/plotter/cfg/2017/plot_mem_ttbar.cfg.py +++ b/plotter/cfg/2017/plot_mem_ttbar.cfg.py @@ -21,8 +21,10 @@ selection_mc = selection # + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] + +training = 'run2/all_channels__200623_17h_51m' #training = '2018/all_channels__200528_23h_35m' -training = 'all_channels_200213_14h_55m' +#training = 'all_channels_200213_14h_55m' # training = 'all_channels_200526_12h_46m' # training = 'all_channels_200525_19h_38m' # training = 'all_channels_200525_18h_55m' @@ -54,11 +56,13 @@ plot_signals = False, blinded = False, - datacards = ['hnl_m_12_lxy_lt_0p5', 'hnl_m_12_lxy_0p5_to_1p5', 'hnl_m_12_lxy_1p5_to_4p0', 'hnl_m_12_lxy_mt_4p0'], # FIXME! improve this to accept wildcards / regex + #datacards = ['hnl_m_12_lxy_lt_0p5', 'hnl_m_12_lxy_0p5_to_1p5', 'hnl_m_12_lxy_1p5_to_4p0', 'hnl_m_12_lxy_mt_4p0'], # FIXME! improve this to accept wildcards / regex + datacards = ['hnl_m_12_lxy_lt_0p5', 'hnl_m_12_lxy_0p5_to_1p5', 'hnl_m_12_lxy_1p5_to_4p0', 'hnl_m_12_lxy_mt_4p0'], mc_subtraction = True, - data_driven = False, + #data_driven = False, + data_driven = True, ) if __name__ == '__main__': diff --git a/plotter/cfg/2017/plot_mmm.cfg.py b/plotter/cfg/2017/plot_mmm.cfg.py index 9ca9342..8870a08 100644 --- a/plotter/cfg/2017/plot_mmm.cfg.py +++ b/plotter/cfg/2017/plot_mmm.cfg.py @@ -26,9 +26,10 @@ selection_mc = selection + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] +training = 'run2/all_channels__200623_17h_51m' #training = '2018/all_channels__200528_23h_35m' #training = 'all_2017_channels_200116_15h_15m' -training = 'all_channels_200213_14h_55m' +#training = 'all_channels_200213_14h_55m' # training = 'all_channels_200526_12h_46m' # training = 'all_channels_200525_19h_38m' # training = 'all_channels_200525_18h_55m' @@ -61,12 +62,14 @@ plot_signals = False, blinded = False, - datacards = ['log_hnl_2d_disp' , - 'hnl_m_12' , - 'hnl_m_12_lxy_lt_0p5' , - 'hnl_m_12_lxy_0p5_to_1p5', - 'hnl_m_12_lxy_1p5_to_4p0', - 'hnl_m_12_lxy_mt_4p0'], # FIXME! improve this to accept wildcards / regex + #datacards = ['log_hnl_2d_disp' , + # 'hnl_m_12' , + # 'hnl_m_12_lxy_lt_0p5' , + # 'hnl_m_12_lxy_0p5_to_1p5', + # 'hnl_m_12_lxy_1p5_to_4p0', + # 'hnl_m_12_lxy_mt_4p0'], # FIXME! improve this to accept wildcards / regex + + datacards = ['hnl_m_12_lxy_lt_0p5', 'hnl_m_12_lxy_0p5_to_1p5', 'hnl_m_12_lxy_1p5_to_4p0', 'hnl_m_12_lxy_mt_4p0'], mc_subtraction = True, diff --git a/plotter/cfg/2017/plot_mmm_zmm.cfg.py b/plotter/cfg/2017/plot_mmm_zmm.cfg.py index 536893b..8fd8b2a 100644 --- a/plotter/cfg/2017/plot_mmm_zmm.cfg.py +++ b/plotter/cfg/2017/plot_mmm_zmm.cfg.py @@ -26,8 +26,9 @@ selection_mc = selection # + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] +training = 'run2/all_channels__200623_17h_51m' #training = '2018/all_channels__200528_23h_35m' -training = 'all_channels_200213_14h_55m' +#training = 'all_channels_200213_14h_55m' # training = 'all_channels_200526_12h_46m' # training = 'all_channels_200525_19h_38m' # training = 'all_channels_200525_18h_55m' @@ -60,11 +61,14 @@ plot_signals = False, blinded = False, - datacards = ['hnl_m_12_lxy_lt_0p5', 'hnl_m_12_lxy_0p5_to_1p5', 'hnl_m_12_lxy_1p5_to_4p0', 'hnl_m_12_lxy_mt_4p0'], # FIXME! improve this to accept wildcards / regex + #datacards = ['hnl_m_12_lxy_lt_0p5', 'hnl_m_12_lxy_0p5_to_1p5', 'hnl_m_12_lxy_1p5_to_4p0', 'hnl_m_12_lxy_mt_4p0'], # FIXME! improve this to accept wildcards / regex + datacards = ['hnl_m_12_lxy_lt_0p5', 'hnl_m_12_lxy_0p5_to_1p5', 'hnl_m_12_lxy_1p5_to_4p0', 'hnl_m_12_lxy_mt_4p0'], - mc_subtraction = False, + #mc_subtraction = False, + mc_subtraction = True, - data_driven = False, + #data_driven = False, + data_driven = True, ) if __name__ == '__main__': diff --git a/plotter/cfg/2018/plot_mem_os.cfg.py b/plotter/cfg/2018/plot_mem_os.cfg.py index da93954..5cf89aa 100644 --- a/plotter/cfg/2018/plot_mem_os.cfg.py +++ b/plotter/cfg/2018/plot_mem_os.cfg.py @@ -25,7 +25,8 @@ selection_mc = selection + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] -training = '2018/all_channels__200528_23h_35m' +training = 'run2/all_channels__200623_17h_51m' +# training = '2018/all_channels__200528_23h_35m' # training = 'all_channels_200526_12h_46m' # training = 'all_channels_200525_19h_38m' # training = 'all_channels_200525_18h_55m' diff --git a/plotter/cfg/2018/plot_mem_os_loose.cfg.py b/plotter/cfg/2018/plot_mem_os_loose.cfg.py index be9c2d2..b1877a5 100644 --- a/plotter/cfg/2018/plot_mem_os_loose.cfg.py +++ b/plotter/cfg/2018/plot_mem_os_loose.cfg.py @@ -38,7 +38,8 @@ selection_mc = selection + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] -training = 'run2/all_channels__200604_15h_13m' +training = 'run2/all_channels__200623_17h_51m' +#training = 'run2/all_channels__200604_15h_13m' # training = 'run2/all_channels__200602_17h_26m' # training = 'run2/all_channels__200601_18h_20m' # training = '2018/all_channels__200528_23h_35m' @@ -76,13 +77,15 @@ plot_signals = False, blinded = False, - datacards = ['log_hnl_2d_disp' , - 'hnl_m_12' , - 'hnl_m_12_lxy_lt_0p5' , - 'hnl_m_12_lxy_0p5_to_1p5', - 'hnl_m_12_lxy_1p5_to_4p0', - 'hnl_m_12_lxy_mt_4p0'], # FIXME! improve this to accept wildcards / regex + #datacards = ['log_hnl_2d_disp' , + # 'hnl_m_12' , + # 'hnl_m_12_lxy_lt_0p5' , + # 'hnl_m_12_lxy_0p5_to_1p5', + # 'hnl_m_12_lxy_1p5_to_4p0', + # 'hnl_m_12_lxy_mt_4p0'], # FIXME! improve this to accept wildcards / regex + datacards = ['hnl_m_12_lxy_lt_0p5', 'hnl_m_12_lxy_0p5_to_1p5', 'hnl_m_12_lxy_1p5_to_4p0', 'hnl_m_12_lxy_mt_4p0'], + mc_subtraction = False, data_driven = True, diff --git a/plotter/cfg/2018/plot_mem_ss.cfg.py b/plotter/cfg/2018/plot_mem_ss.cfg.py index aa9edb6..c4127f5 100644 --- a/plotter/cfg/2018/plot_mem_ss.cfg.py +++ b/plotter/cfg/2018/plot_mem_ss.cfg.py @@ -24,8 +24,9 @@ selection_mc = selection + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] +training = 'run2/all_channels__200623_17h_51m' #training = '2018/all_channels__200528_23h_35m' -training = 'all_channels_200213_14h_55m' +#training = 'all_channels_200213_14h_55m' # training = 'all_channels_200526_12h_46m' # training = 'all_channels_200525_19h_38m' # training = 'all_channels_200525_18h_55m' diff --git a/plotter/cfg/2018/plot_mem_ss_loose.cfg.py b/plotter/cfg/2018/plot_mem_ss_loose.cfg.py index 7c83a17..67994cc 100644 --- a/plotter/cfg/2018/plot_mem_ss_loose.cfg.py +++ b/plotter/cfg/2018/plot_mem_ss_loose.cfg.py @@ -36,7 +36,8 @@ selection_mc = selection + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] -training = 'run2/all_channels__200604_15h_13m' +training = 'run2/all_channels__200623_17h_51m' +#training = 'run2/all_channels__200604_15h_13m' # training = 'run2/all_channels__200602_17h_26m' # training = 'run2/all_channels__200601_18h_20m' # training = '2018/all_channels__200528_23h_35m' diff --git a/plotter/cfg/2018/plot_mmm.cfg.py b/plotter/cfg/2018/plot_mmm.cfg.py index 608449f..183a09c 100644 --- a/plotter/cfg/2018/plot_mmm.cfg.py +++ b/plotter/cfg/2018/plot_mmm.cfg.py @@ -13,8 +13,8 @@ cuts.selections['vetoes_12_OS'], cuts.selections['vetoes_01_OS'], cuts.selections['vetoes_02_OS'], -# cuts.selections['signal_region'], - cuts.selections['sideband'], + cuts.selections['signal_region'], +# cuts.selections['sideband'], 'hlt_IsoMu24', ] @@ -26,8 +26,11 @@ selection_mc = selection + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] -#training = 'run2/all_channels__200601_18h_20m' -training = 'all_channels_200213_14h_55m' +# training = 'run2/all_channels__200623_19h_2m' +training = 'run2/all_channels__200623_16h_37m' +# training = 'run2/all_channels__200604_15h_13m' +# training = 'run2/all_channels__200602_17h_26m' +# training = 'run2/all_channels__200601_18h_20m' # training = '2018/all_channels__200528_23h_35m' # training = 'all_channels_200526_12h_46m' # training = 'all_channels_200525_19h_38m' @@ -43,8 +46,8 @@ plot_dir = '/'.join([env['BASE_DIR'], 'plotter', 'plots', '2018']), base_dir = '/'.join([env['BASE_DIR'], 'ntuples', 'may20', '2018']), post_fix = 'HNLTreeProducer_%s/tree.root' %ch, -# dir_suffix = 'signal_dd_datacards', #'signal', - dir_suffix = 'sideband', + dir_suffix = 'signal_dd_datacards_blinded', #'signal', +# dir_suffix = 'sideband', selection_data = selection, selection_mc = selection_mc, @@ -58,9 +61,9 @@ features = '/'.join([env['BASE_DIR'], 'nn', 'trainings', training, 'input_features.pck' ]), process_signals = True, # switch off for control regions - mini_signals = True, # process only the signals that you'll plot + mini_signals = False, # process only the signals that you'll plot plot_signals = True, - blinded = False, + blinded = True, datacards = ['log_hnl_2d_disp' , 'hnl_m_12' , @@ -77,6 +80,7 @@ if __name__ == '__main__': plotter.plot() # save the plotter and all + #save_plotter_and_selections(plotter, selection, selection_mc, selection_tight, training) save_plotter_and_selections(plotter, selection, selection_mc, selection_tight) pass diff --git a/plotter/cfg/2018/plot_mmm_loose.cfg.py b/plotter/cfg/2018/plot_mmm_loose.cfg.py index 1da97e5..3150f23 100644 --- a/plotter/cfg/2018/plot_mmm_loose.cfg.py +++ b/plotter/cfg/2018/plot_mmm_loose.cfg.py @@ -38,7 +38,8 @@ selection_mc = selection + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] -training = 'run2/all_channels__200604_15h_13m' +training = 'run2/all_channels__200623_17h_51m' +#training = 'run2/all_channels__200604_15h_13m' # training = 'run2/all_channels__200602_17h_26m' # training = 'run2/all_channels__200601_18h_20m' # training = '2018/all_channels__200528_23h_35m' @@ -76,12 +77,14 @@ plot_signals = False, blinded = False, - datacards = ['log_hnl_2d_disp' , - 'hnl_m_12' , - 'hnl_m_12_lxy_lt_0p5' , - 'hnl_m_12_lxy_0p5_to_1p5', - 'hnl_m_12_lxy_1p5_to_4p0', - 'hnl_m_12_lxy_mt_4p0'], # FIXME! improve this to accept wildcards / regex + #datacards = ['log_hnl_2d_disp' , + # 'hnl_m_12' , + # 'hnl_m_12_lxy_lt_0p5' , + # 'hnl_m_12_lxy_0p5_to_1p5', + # 'hnl_m_12_lxy_1p5_to_4p0', + # 'hnl_m_12_lxy_mt_4p0'], # FIXME! improve this to accept wildcards / regex + + datacards = ['hnl_m_12_lxy_lt_0p5', 'hnl_m_12_lxy_0p5_to_1p5', 'hnl_m_12_lxy_1p5_to_4p0', 'hnl_m_12_lxy_mt_4p0'], mc_subtraction = False, diff --git a/plotter/cfg/2018/plot_mmm_signal.cfg.py b/plotter/cfg/2018/plot_mmm_signal.cfg.py index f65303c..160214a 100644 --- a/plotter/cfg/2018/plot_mmm_signal.cfg.py +++ b/plotter/cfg/2018/plot_mmm_signal.cfg.py @@ -26,8 +26,9 @@ selection_mc = selection + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] +training = 'run2/all_channels__200623_17h_51m' #training = 'all_channels_200526_12h_14m' -training = 'all_channels_200213_14h_55m' +#training = 'all_channels_200213_14h_55m' # training = 'all_channels_200525_18h_55m' # training = 'all_channels_200523_22h_39m' #<==== GOOD # training = 'all_channels_200523_15h_53m' diff --git a/plotter/cfg/2018/plot_mmm_zmm.cfg.py b/plotter/cfg/2018/plot_mmm_zmm.cfg.py index 0326de6..6a31c9a 100644 --- a/plotter/cfg/2018/plot_mmm_zmm.cfg.py +++ b/plotter/cfg/2018/plot_mmm_zmm.cfg.py @@ -25,8 +25,9 @@ selection_mc = selection # + [cuts.selections['is_prompt_lepton']] selection_tight = cuts.selections_pd['tight'] +training = 'run2/all_channels__200623_17h_51m' #training = '2018/all_channels__200528_18h_42m' -training = 'all_channels_200213_14h_55m' +#training = 'all_channels_200213_14h_55m' # training = 'all_channels_200525_19h_38m' # training = 'all_channels_200525_18h_55m' # training = 'all_channels_200523_22h_39m' #<==== GOOD diff --git a/plotter/objects/plotter.py b/plotter/objects/plotter.py index 51f8123..f81a558 100644 --- a/plotter/objects/plotter.py +++ b/plotter/objects/plotter.py @@ -664,7 +664,9 @@ def plot(self): # data in tight all_obs_prompt_norm = copy(all_obs_prompt) - all_obs_prompt_norm.Scale(np.nan_to_num(np.divide(1., all_obs_prompt_norm.integral()))) + if all_obs_prompt_norm.integral() != 0: + all_obs_prompt_norm.Scale(np.nan_to_num(np.divide(1., all_obs_prompt_norm.integral()))) + #import pdb; pdb.set_trace() all_obs_prompt_norm.drawstyle = 'hist e' all_obs_prompt_norm.linecolor = 'black' all_obs_prompt_norm.markersize = 0