HiggsAnalysis-KITHiggsToTauTau
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
makePlots_datacardsQCDfactors Namespace Reference

Functions

def addArguments
 
def matching_process
 
def remove_procs_and_systs_with_zero_yield
 

Variables

tuple log = logging.getLogger(__name__)
 
tuple parser
 
tuple args = parser.parse_args()
 
tuple clear_output_dir = raw_input("Do you really want to clear the output directory? [yes]")
 
tuple sample_settings = samples.Samples()
 
tuple systematics_factory = systematics.SystematicsFactory()
 
list www_output_dirs_postfit = []
 
list www_output_dirs_weightbin = []
 
list www_output_dirs_parabola = []
 
string tmp_input_root_filename_template = "input/${ANALYSIS}_${CHANNEL}_${BIN}_${SYSTEMATIC}_${ERA}.root"
 
string input_root_filename_template = "input/${ANALYSIS}_${CHANNEL}_${BIN}_${ERA}.root"
 
string bkg_histogram_name_template = "${BIN}/${PROCESS}"
 
string sig_histogram_name_template = "${BIN}/${PROCESS}${MASS}"
 
string bkg_syst_histogram_name_template = "${BIN}/${PROCESS}_${SYSTEMATIC}"
 
string sig_syst_histogram_name_template = "${BIN}/${PROCESS}${MASS}_${SYSTEMATIC}"
 
list datacard_filename_templates = ["datacards/${BIN}/${ANALYSIS}_${CHANNEL}_${BIN}_${ERA}.txt"]
 
string output_root_filename_template = "datacards/common/${ANALYSIS}.input_${ERA}.root"
 
 quantity = args.quantity
 
list categories = [channel+"_"+category for channel in args.channels for category in args.categories[0]]
 
dictionary mapping_category2binid = {}
 
tuple datacards = qcdfactorsdatacards.QcdFactorsDatacards(quantity, args.era, mapping_category2binid)
 
tuple channel = category.split("_")
 
 useRelaxedIsolation = False
 
tuple output_file
 
list input_plot_configs = []
 
list hadd_commands = []
 
tuple datacards_per_channel_category = qcdfactorsdatacards.QcdFactorsDatacards(cb=datacards.cb.cp().channel([channel]).bin([category]), mapping_category2binid=mapping_category2binid)
 
list tmp_output_files = []
 
tuple nominal = (shape_systematic == "nominal")
 
list list_of_samples = [datacards.configs.process2sample(process) for process in list_of_samples]
 
string systematic = "nominal"
 
string samples = "\", \""
 
 category = category,
 
dictionary merged_config = {}
 
tuple config_rest
 
 histogram_name_template = bkg_histogram_name_templateifnominalelsebkg_syst_histogram_name_template
 
tuple PROCESS = datacards.configs.sample2process(sample)
 
 BIN = category,
 
 SYSTEMATIC = systematic
 
tuple systematics_settings = systematics_factory.get(shape_systematic)
 
tuple config_ztt
 
tuple MASS = str(shift)
 
tuple tmp_output_file
 
 DST = output_file,
 
string SRC = " "
 
tuple output_files = list(set([os.path.join(config["output_dir"], config["filename"]+".root") for config in input_plot_configs[:args.n_plots[0]]]))
 
 update_systematics = True
 
tuple processes = datacards.cb.cp()
 
float add_threshold = 0.1
 
dictionary datacards_cbs = {}
 
tuple datacards_workspaces = datacards.text2workspace(datacards_cbs, n_processes=args.n_processes)
 
 VERBOSITY = args.combine_verbosity,
 
 STABLE = datacards.stable_options
 
tuple BINNING = int((args.shift_ranges[1]-args.shift_ranges[0])/args.shift_binning)
 
tuple RANGE = str(args.shift_ranges[0])
 
tuple datacards_postfit_shapes = datacards.postfit_shapes_fromworkspace(datacards_cbs, datacards_workspaces, True, args.n_processes, "--sampling" + (" --print" if args.n_processes <= 1 else ""))
 
list postfit_plot_configs = []
 
list bkg_plotting_order = ["ZTT", "ZL", "ZJ", "TTT","TTJJ", "VVT", "VVJ", "W", "QCD"]
 
tuple postfit_shapes = datacards_postfit_shapes.get("fit_s", {})
 
tuple decayMode = category.split("_")
 
tuple weightBin = int(category.split("_")[-1].split(weight_type+"bin")[-1])
 
list bkg_process = datacards_cbs[datacard]
 
list sig_process = datacards_cbs[datacard]
 
dictionary config = {}
 
tuple processes_to_plot = list(processes)
 
list parabola_plot_configs = []
 
list weightbin_plot_configs = []
 
tuple filename_mlfit = os.path.join(os.path.dirname(datacard), "mlfit.root")
 
tuple file_mlfit = ROOT.TFile(filename_mlfit)
 
tuple tree_mlfit = file_mlfit.Get("tree_fit_sb")
 
tuple filename_multidimfit = os.path.join(os.path.dirname(datacard), "higgsCombineTest.MultiDimFit.mH0.root")
 
tuple file_multidimfit = ROOT.TFile(filename_multidimfit)
 
tuple tree_multidimfit = file_multidimfit.Get("limit")
 
list mes_list = []
 
list deltaNLL_list = []
 
list deltaNLLshifted_list = []
 
list min_nll = deltaNLL_list[0]
 
list min_shift = mes_list[0]
 
list mes_list_nll_belowX = []
 
list nll_belowX = []
 
int nllMax = 10
 
 found2sigmaLow = True
 
tuple err2sigmaLow = abs((mes_list[index-1]+mes_list[index])/2.0 - min_shift)
 
 found1sigmaLow = True
 
tuple err1sigmaLow = abs((mes_list[index-1]+mes_list[index])/2.0 - min_shift)
 
 found1sigmaHi = True
 
tuple err1sigmaHi = abs((mes_list[index]+mes_list[index+1])/2.0 - min_shift)
 
 found2sigmaHi = True
 
tuple err2sigmaHi = abs((mes_list[index]+mes_list[index+1])/2.0 - min_shift)
 
list xvaluesF = []
 
string xvalues = ""
 
string yvalues = ""
 
list xvaluesF_belowX = []
 
tuple RooFitGraph_Parabola
 
tuple fitf = ROOT.TF1("f1","pol2",min(xvaluesF_belowX),max(xvaluesF_belowX))
 
tuple minimumScanFit = fitf.GetMinimumX(min(xvaluesF_belowX),max(xvaluesF_belowX))
 
tuple minimumScanFitY = fitf.GetMinimum(min(xvaluesF_belowX),max(xvaluesF_belowX))
 
tuple sigmaScanFit = abs(fitf.GetX(minimumScanFitY+1)-minimumScanFit)
 
tuple graphfilename = os.path.join(os.path.dirname(datacard), "parabola_" + category + ("_tightenedMassWindow" if args.tighten_mass_window else "")+".root")
 
tuple graphfile = ROOT.TFile(graphfilename, "RECREATE")
 
list weight_bins_loop = weight_binsifargs.no_inclusiveelseweight_bins[1:]
 
list weight_ranges_loop = weight_rangesifargs.no_inclusiveelseweight_ranges[1:]
 
string xval = "0.7395 2.2185"
 
string xerrsval = "0.7395 0.7395"
 
list xbinsF = [0.7395, 2.2185]
 
list xerrsF = [0.7395, 0.7395]
 
tuple RooFitGraph_Linear
 
tuple fit_polZero = ROOT.TF1("f2","pol0",min(xbinsF),max(xbinsF))
 
tuple fit_polOne = ROOT.TF1("f3","pol1",min(xbinsF),max(xbinsF))
 
tuple polZero_filename = os.path.join(args.output_dir, "datacards/result_fit_" + ("eta" if args.eta_binning else "pt") + "_pol0_" + decayMode + "_" + quantity + ".root")
 
tuple polZero_file = ROOT.TFile(polZero_filename, "RECREATE")
 
tuple polOne_filename = os.path.join(args.output_dir, "datacards/result_fit_" + ("eta" if args.eta_binning else "pt") + "_pol1_" + decayMode + "_" + quantity + ".root")
 
tuple polOne_file = ROOT.TFile(polOne_filename, "RECREATE")
 
string row_format = "{:^22}"
 
string polZero_string1 = "%1.2f"
 
string polZero_string2 = "%1.2f"
 
string polOne_string1 = "%1.2f"
 
string polOne_string2 = "%1.2f"
 
tuple subpath = os.path.normpath(output_dir)
 
list output_filenames = []
 
tuple www = args.wwwif(subpath == "tauEsStudies_datacards")
 
 output_dir = output_dir,
 
 export_json = False,
 

Function Documentation

def makePlots_datacardsQCDfactors.addArguments (   parser)
def makePlots_datacardsQCDfactors.matching_process (   obj1,
  obj2 
)
def makePlots_datacardsQCDfactors.remove_procs_and_systs_with_zero_yield (   proc)

Variable Documentation

float makePlots_datacardsQCDfactors.add_threshold = 0.1
tuple makePlots_datacardsQCDfactors.args = parser.parse_args()
makePlots_datacardsQCDfactors.BIN = category,
tuple makePlots_datacardsQCDfactors.BINNING = int((args.shift_ranges[1]-args.shift_ranges[0])/args.shift_binning)
string makePlots_datacardsQCDfactors.bkg_histogram_name_template = "${BIN}/${PROCESS}"
list makePlots_datacardsQCDfactors.bkg_plotting_order = ["ZTT", "ZL", "ZJ", "TTT","TTJJ", "VVT", "VVJ", "W", "QCD"]
list makePlots_datacardsQCDfactors.bkg_process = datacards_cbs[datacard]
string makePlots_datacardsQCDfactors.bkg_syst_histogram_name_template = "${BIN}/${PROCESS}_${SYSTEMATIC}"
list makePlots_datacardsQCDfactors.categories = [channel+"_"+category for channel in args.channels for category in args.categories[0]]
tuple makePlots_datacardsQCDfactors.category = category,
tuple makePlots_datacardsQCDfactors.channel = category.split("_")
tuple makePlots_datacardsQCDfactors.clear_output_dir = raw_input("Do you really want to clear the output directory? [yes]")
dictionary makePlots_datacardsQCDfactors.config = {}
tuple makePlots_datacardsQCDfactors.config_rest
Initial value:
1 = sample_settings.get_config(
2  samples=[getattr(samples.Samples, sample) for sample in list_of_samples if sample not in ["qcd"]],
3  channel=channel,
4  category=category,
5  nick_suffix="_",
6  weight=args.weight,
7  lumi=args.lumi * 1000,
8  cut_type="smhtt2016" if args.era == "2016" else "tauescuts",
9  estimationMethod="classic",
10  useRelaxedIsolationForW = useRelaxedIsolation,
11  useRelaxedIsolationForQCD = useRelaxedIsolation
12  )
tuple makePlots_datacardsQCDfactors.config_ztt
Initial value:
1 = sample_settings.get_config(
2  samples=[getattr(samples.Samples, sample) for sample in list_of_samples if sample in ["ztt", "ttt", "vvt"]],
3  channel=channel,
4  category=catForConfig,
5  nick_suffix="_" + str(shift).replace(".", "_") + "_" + str(weight_index),
6  weight="(pt_2>20)*" + args.weight,
7  lumi=args.lumi * 1000,
8  cut_type="tauescuts2016" if args.era == "2016" else "tauescuts",
9  estimationMethod=args.background_method,
10  wj_sf_shift=wj_sf_shift,
11  ss_os_factor = ss_os_factors.get(channel,0.0),
12  useRelaxedIsolation = useRelaxedIsolation
13  )
list makePlots_datacardsQCDfactors.datacard_filename_templates = ["datacards/${BIN}/${ANALYSIS}_${CHANNEL}_${BIN}_${ERA}.txt"]
tuple makePlots_datacardsQCDfactors.datacards = qcdfactorsdatacards.QcdFactorsDatacards(quantity, args.era, mapping_category2binid)
dictionary makePlots_datacardsQCDfactors.datacards_cbs = {}
tuple makePlots_datacardsQCDfactors.datacards_per_channel_category = qcdfactorsdatacards.QcdFactorsDatacards(cb=datacards.cb.cp().channel([channel]).bin([category]), mapping_category2binid=mapping_category2binid)
tuple makePlots_datacardsQCDfactors.datacards_postfit_shapes = datacards.postfit_shapes_fromworkspace(datacards_cbs, datacards_workspaces, True, args.n_processes, "--sampling" + (" --print" if args.n_processes <= 1 else ""))
tuple makePlots_datacardsQCDfactors.datacards_workspaces = datacards.text2workspace(datacards_cbs, n_processes=args.n_processes)
tuple makePlots_datacardsQCDfactors.decayMode = category.split("_")
list makePlots_datacardsQCDfactors.deltaNLL_list = []
list makePlots_datacardsQCDfactors.deltaNLLshifted_list = []
makePlots_datacardsQCDfactors.DST = output_file,
tuple makePlots_datacardsQCDfactors.err1sigmaHi = abs((mes_list[index]+mes_list[index+1])/2.0 - min_shift)
tuple makePlots_datacardsQCDfactors.err1sigmaLow = abs((mes_list[index-1]+mes_list[index])/2.0 - min_shift)
tuple makePlots_datacardsQCDfactors.err2sigmaHi = abs((mes_list[index]+mes_list[index+1])/2.0 - min_shift)
tuple makePlots_datacardsQCDfactors.err2sigmaLow = abs((mes_list[index-1]+mes_list[index])/2.0 - min_shift)
makePlots_datacardsQCDfactors.export_json = False,
tuple makePlots_datacardsQCDfactors.file_mlfit = ROOT.TFile(filename_mlfit)
tuple makePlots_datacardsQCDfactors.file_multidimfit = ROOT.TFile(filename_multidimfit)
tuple makePlots_datacardsQCDfactors.filename_mlfit = os.path.join(os.path.dirname(datacard), "mlfit.root")
tuple makePlots_datacardsQCDfactors.filename_multidimfit = os.path.join(os.path.dirname(datacard), "higgsCombineTest.MultiDimFit.mH0.root")
tuple makePlots_datacardsQCDfactors.fit_polOne = ROOT.TF1("f3","pol1",min(xbinsF),max(xbinsF))
tuple makePlots_datacardsQCDfactors.fit_polZero = ROOT.TF1("f2","pol0",min(xbinsF),max(xbinsF))
tuple makePlots_datacardsQCDfactors.fitf = ROOT.TF1("f1","pol2",min(xvaluesF_belowX),max(xvaluesF_belowX))
makePlots_datacardsQCDfactors.found1sigmaHi = True
makePlots_datacardsQCDfactors.found1sigmaLow = True
makePlots_datacardsQCDfactors.found2sigmaHi = True
makePlots_datacardsQCDfactors.found2sigmaLow = True
tuple makePlots_datacardsQCDfactors.graphfile = ROOT.TFile(graphfilename, "RECREATE")
tuple makePlots_datacardsQCDfactors.graphfilename = os.path.join(os.path.dirname(datacard), "parabola_" + category + ("_tightenedMassWindow" if args.tighten_mass_window else "")+".root")
list makePlots_datacardsQCDfactors.hadd_commands = []
makePlots_datacardsQCDfactors.histogram_name_template = bkg_histogram_name_templateifnominalelsebkg_syst_histogram_name_template
list makePlots_datacardsQCDfactors.input_plot_configs = []
string makePlots_datacardsQCDfactors.input_root_filename_template = "input/${ANALYSIS}_${CHANNEL}_${BIN}_${ERA}.root"
list makePlots_datacardsQCDfactors.list_of_samples = [datacards.configs.process2sample(process) for process in list_of_samples]
tuple makePlots_datacardsQCDfactors.log = logging.getLogger(__name__)
dictionary makePlots_datacardsQCDfactors.mapping_category2binid = {}
tuple makePlots_datacardsQCDfactors.MASS = str(shift)
tuple makePlots_datacardsQCDfactors.merged_config = {}
list makePlots_datacardsQCDfactors.mes_list = []
list makePlots_datacardsQCDfactors.mes_list_nll_belowX = []
list makePlots_datacardsQCDfactors.min_nll = deltaNLL_list[0]
list makePlots_datacardsQCDfactors.min_shift = mes_list[0]
tuple makePlots_datacardsQCDfactors.minimumScanFit = fitf.GetMinimumX(min(xvaluesF_belowX),max(xvaluesF_belowX))
tuple makePlots_datacardsQCDfactors.minimumScanFitY = fitf.GetMinimum(min(xvaluesF_belowX),max(xvaluesF_belowX))
list makePlots_datacardsQCDfactors.nll_belowX = []
int makePlots_datacardsQCDfactors.nllMax = 10
tuple makePlots_datacardsQCDfactors.nominal = (shape_systematic == "nominal")
makePlots_datacardsQCDfactors.output_dir = output_dir,
tuple makePlots_datacardsQCDfactors.output_file
Initial value:
1 = os.path.join(args.output_dir, input_root_filename_template.replace("$", "").format(
2  ANALYSIS="ztt",
3  CHANNEL=channel,
4  BIN=category,
5  ERA="13TeV"
6  ))
list makePlots_datacardsQCDfactors.output_filenames = []
tuple makePlots_datacardsQCDfactors.output_files = list(set([os.path.join(config["output_dir"], config["filename"]+".root") for config in input_plot_configs[:args.n_plots[0]]]))
string makePlots_datacardsQCDfactors.output_root_filename_template = "datacards/common/${ANALYSIS}.input_${ERA}.root"
list makePlots_datacardsQCDfactors.parabola_plot_configs = []
tuple makePlots_datacardsQCDfactors.parser
Initial value:
1 = argparse.ArgumentParser(description="Create ROOT inputs and datacards for the measurement of the QCD 0S/SS factor from data in a sideband region.",
2  parents=[logger.loggingParser])
tuple makePlots_datacardsQCDfactors.polOne_file = ROOT.TFile(polOne_filename, "RECREATE")
tuple makePlots_datacardsQCDfactors.polOne_filename = os.path.join(args.output_dir, "datacards/result_fit_" + ("eta" if args.eta_binning else "pt") + "_pol1_" + decayMode + "_" + quantity + ".root")
string makePlots_datacardsQCDfactors.polOne_string1 = "%1.2f"
string makePlots_datacardsQCDfactors.polOne_string2 = "%1.2f"
tuple makePlots_datacardsQCDfactors.polZero_file = ROOT.TFile(polZero_filename, "RECREATE")
tuple makePlots_datacardsQCDfactors.polZero_filename = os.path.join(args.output_dir, "datacards/result_fit_" + ("eta" if args.eta_binning else "pt") + "_pol0_" + decayMode + "_" + quantity + ".root")
string makePlots_datacardsQCDfactors.polZero_string1 = "%1.2f"
string makePlots_datacardsQCDfactors.polZero_string2 = "%1.2f"
list makePlots_datacardsQCDfactors.postfit_plot_configs = []
tuple makePlots_datacardsQCDfactors.postfit_shapes = datacards_postfit_shapes.get("fit_s", {})
tuple makePlots_datacardsQCDfactors.PROCESS = datacards.configs.sample2process(sample)
list makePlots_datacardsQCDfactors.processes = datacards.cb.cp()
list makePlots_datacardsQCDfactors.processes_to_plot = list(processes)
makePlots_datacardsQCDfactors.quantity = args.quantity
tuple makePlots_datacardsQCDfactors.RANGE = str(args.shift_ranges[0])
tuple makePlots_datacardsQCDfactors.RooFitGraph_Linear
Initial value:
1 = ROOT.TGraphAsymmErrors(
2  len(xbinsF),
3  array.array("d", xbinsF),
4  array.array("d", ybinsF),
5  array.array("d", xerrsF),
6  array.array("d", xerrsF),
7  array.array("d", yerrsloF),
8  array.array("d", yerrshiF)
9  )
tuple makePlots_datacardsQCDfactors.RooFitGraph_Parabola
Initial value:
1 = ROOT.TGraphErrors(
2  len(xvaluesF),
3  array.array("d", xvaluesF),
4  array.array("d", deltaNLLshifted_list),
5  array.array("d", [0.1]*len(xvaluesF)),
6  array.array("d", [1.0*nllMax/10.0]*len(xvaluesF)) # this is an arbitrary value in order to be able to fit also not so smooth parabolas
7  )
string makePlots_datacardsQCDfactors.row_format = "{:^22}"
tuple makePlots_datacardsQCDfactors.sample_settings = samples.Samples()
string makePlots_datacardsQCDfactors.samples = "\", \""
string makePlots_datacardsQCDfactors.sig_histogram_name_template = "${BIN}/${PROCESS}${MASS}"
list makePlots_datacardsQCDfactors.sig_process = datacards_cbs[datacard]
string makePlots_datacardsQCDfactors.sig_syst_histogram_name_template = "${BIN}/${PROCESS}${MASS}_${SYSTEMATIC}"
tuple makePlots_datacardsQCDfactors.sigmaScanFit = abs(fitf.GetX(minimumScanFitY+1)-minimumScanFit)
string makePlots_datacardsQCDfactors.SRC = " "
makePlots_datacardsQCDfactors.STABLE = datacards.stable_options
tuple makePlots_datacardsQCDfactors.subpath = os.path.normpath(output_dir)
makePlots_datacardsQCDfactors.systematic = "nominal"
makePlots_datacardsQCDfactors.SYSTEMATIC = systematic
tuple makePlots_datacardsQCDfactors.systematics_factory = systematics.SystematicsFactory()
tuple makePlots_datacardsQCDfactors.systematics_settings = systematics_factory.get(shape_systematic)
string makePlots_datacardsQCDfactors.tmp_input_root_filename_template = "input/${ANALYSIS}_${CHANNEL}_${BIN}_${SYSTEMATIC}_${ERA}.root"
tuple makePlots_datacardsQCDfactors.tmp_output_file
Initial value:
1 = os.path.join(args.output_dir, tmp_input_root_filename_template.replace("$", "").format(
2  ANALYSIS="ztt",
3  CHANNEL=channel,
4  BIN=category,
5  SYSTEMATIC=systematic,
6  ERA="13TeV"
7  ))
list makePlots_datacardsQCDfactors.tmp_output_files = []
tuple makePlots_datacardsQCDfactors.tree_mlfit = file_mlfit.Get("tree_fit_sb")
tuple makePlots_datacardsQCDfactors.tree_multidimfit = file_multidimfit.Get("limit")
makePlots_datacardsQCDfactors.update_systematics = True
makePlots_datacardsQCDfactors.useRelaxedIsolation = False
makePlots_datacardsQCDfactors.VERBOSITY = args.combine_verbosity,
list makePlots_datacardsQCDfactors.weight_bins_loop = weight_binsifargs.no_inclusiveelseweight_bins[1:]
list makePlots_datacardsQCDfactors.weight_ranges_loop = weight_rangesifargs.no_inclusiveelseweight_ranges[1:]
tuple makePlots_datacardsQCDfactors.weightBin = int(category.split("_")[-1].split(weight_type+"bin")[-1])
list makePlots_datacardsQCDfactors.weightbin_plot_configs = []
tuple makePlots_datacardsQCDfactors.www = args.wwwif(subpath == "tauEsStudies_datacards")
list makePlots_datacardsQCDfactors.www_output_dirs_parabola = []
list makePlots_datacardsQCDfactors.www_output_dirs_postfit = []
list makePlots_datacardsQCDfactors.www_output_dirs_weightbin = []
list makePlots_datacardsQCDfactors.xbinsF = [0.7395, 2.2185]
list makePlots_datacardsQCDfactors.xerrsF = [0.7395, 0.7395]
string makePlots_datacardsQCDfactors.xerrsval = "0.7395 0.7395"
string makePlots_datacardsQCDfactors.xval = "0.7395 2.2185"
string makePlots_datacardsQCDfactors.xvalues = ""
list makePlots_datacardsQCDfactors.xvaluesF = []
list makePlots_datacardsQCDfactors.xvaluesF_belowX = []
string makePlots_datacardsQCDfactors.yvalues = ""