def evaluateEra(self): """ "Era selection" """ self._logger.info(self.__class__.__name__ + '::' + sys._getframe().f_code.co_name) if "2018" in self._era_name: from shape_producer.era import Run2018 as Run2018 self.era = Run2018(self._datasets) elif "2017" in self._era_name: from shape_producer.era import Run2017ReReco31Mar as Run2017 self.era = Run2017(self._datasets) else: self.logger.critical("Era {} is not implemented.".format(self.era)) raise Exception
def main(args): # Container for all distributions to be drawn logger.info("Set up shape variations.") systematics = Systematics( "fake-factor-application/{}_ff_yields.root".format(args.tag), num_threads=args.num_threads) # Era selection if "2018" in args.era: from shape_producer.estimation_methods_2018 import DataEstimation, ZTTEstimation, ZTTEmbeddedEstimation, ZLEstimation, ZJEstimation, TTLEstimation, TTJEstimation, TTTEstimation, VVLEstimation, VVTEstimation, VVJEstimation, WEstimation from shape_producer.era import Run2018 era = Run2018(args.datasets) else: logger.critical("Era {} is not implemented.".format(args.era)) raise Exception # Channels and processes # yapf: disable directory = args.directory et_friend_directory = args.et_friend_directory mt_friend_directory = args.mt_friend_directory tt_friend_directory = args.tt_friend_directory mt = MTSM2018() mt.cuts.remove("tau_iso") mt.cuts.add(Cut("(byTightIsolationMVArun2017v2DBoldDMwLT2017_2<0.5&&byVLooseIsolationMVArun2017v2DBoldDMwLT2017_2>0.5)", "tau_anti_iso")) mt_processes = { "data" : Process("data_obs", DataEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "EMB" : Process("EMB", ZTTEmbeddedEstimation(era, directory, mt, friend_directory=mt_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "ZJ" : Process("ZJ", ZJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "TTJ" : Process("TTJ", TTJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "VVJ" : Process("VVJ", VVJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "W" : Process("W", WEstimation (era, directory, mt, friend_directory=mt_friend_directory)) } et = ETSM2018() et.cuts.remove("tau_iso") et.cuts.add(Cut("(byTightIsolationMVArun2017v2DBoldDMwLT2017_2<0.5&&byVLooseIsolationMVArun2017v2DBoldDMwLT2017_2>0.5)", "tau_anti_iso")) et_processes = { "data" : Process("data_obs", DataEstimation (era, directory, et, friend_directory=et_friend_directory)), "EMB" : Process("EMB", ZTTEmbeddedEstimation(era, directory, et, friend_directory=et_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, et, friend_directory=et_friend_directory)), "ZJ" : Process("ZJ", ZJEstimation (era, directory, et, friend_directory=et_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, et, friend_directory=et_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, et, friend_directory=et_friend_directory)), "TTJ" : Process("TTJ", TTJEstimation (era, directory, et, friend_directory=et_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, et, friend_directory=et_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, et, friend_directory=et_friend_directory)), "VVJ" : Process("VVJ", VVJEstimation (era, directory, et, friend_directory=et_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, et, friend_directory=et_friend_directory)), "W" : Process("W", WEstimation (era, directory, et, friend_directory=et_friend_directory)) } #in tt two 'channels' are needed: antiisolated region for each tau respectively tt1 = TTSM2018() tt1.cuts.remove("tau_1_iso") tt1.cuts.add(Cut("(byTightIsolationMVArun2017v2DBoldDMwLT2017_1<0.5&&byVLooseIsolationMVArun2017v2DBoldDMwLT2017_1>0.5)", "tau_1_anti_iso")) tt1_processes = { "data" : Process("data_obs", DataEstimation (era, directory, tt1, friend_directory=tt_friend_directory)), "EMB" : Process("EMB", ZTTEmbeddedEstimation(era, directory, tt1, friend_directory=tt_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, tt1, friend_directory=tt_friend_directory)), "ZJ" : Process("ZJ", ZJEstimation (era, directory, tt1, friend_directory=tt_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, tt1, friend_directory=tt_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, tt1, friend_directory=tt_friend_directory)), "TTJ" : Process("TTJ", TTJEstimation (era, directory, tt1, friend_directory=tt_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, tt1, friend_directory=tt_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, tt1, friend_directory=tt_friend_directory)), "VVJ" : Process("VVJ", VVJEstimation (era, directory, tt1, friend_directory=tt_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, tt1, friend_directory=tt_friend_directory)), "W" : Process("W", WEstimation (era, directory, tt1, friend_directory=tt_friend_directory)) } tt2 = TTSM2018() tt2.cuts.remove("tau_2_iso") tt2.cuts.add(Cut("(byTightIsolationMVArun2017v2DBoldDMwLT2017_2<0.5&&byVLooseIsolationMVArun2017v2DBoldDMwLT2017_2>0.5)", "tau_2_anti_iso")) tt2_processes = { "data" : Process("data_obs", DataEstimation (era, directory, tt2, friend_directory=tt_friend_directory)), "EMB" : Process("EMB", ZTTEmbeddedEstimation(era, directory, tt2, friend_directory=tt_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, tt2, friend_directory=tt_friend_directory)), "ZJ" : Process("ZJ", ZJEstimation (era, directory, tt2, friend_directory=tt_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, tt2, friend_directory=tt_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, tt2, friend_directory=tt_friend_directory)), "TTJ" : Process("TTJ", TTJEstimation (era, directory, tt2, friend_directory=tt_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, tt2, friend_directory=tt_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, tt2, friend_directory=tt_friend_directory)), "VVJ" : Process("VVJ", VVJEstimation (era, directory, tt2, friend_directory=tt_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, tt2, friend_directory=tt_friend_directory)), "W" : Process("W", WEstimation (era, directory, tt2, friend_directory=tt_friend_directory)) } # Variables and categories config = yaml.load(open("fake-factor-application/config.yaml")) if not args.config in config.keys(): logger.critical("Requested config key %s not available in fake-factor-application/config.yaml!" % args.config) raise Exception config = config[args.config] et_categories = [] # et et_categories.append( Category( "inclusive", et, Cuts(), variable=Variable(args.config, VariableBinning(config["et"]["binning"]), config["et"]["expression"]))) if not args.only_inclusive: for i, label in enumerate(["ggh", "qqh", "ztt", "zll", "w", "tt", "ss", "misc"]): et_categories.append( Category( label, et, Cuts( Cut("et_max_index=={index}".format(index=i), "exclusive_score")), variable=Variable(args.config, VariableBinning(config["et"]["binning"]), config["et"]["expression"]))) mt_categories = [] # mt mt_categories.append( Category( "inclusive", mt, Cuts(), variable=Variable(args.config, VariableBinning(config["mt"]["binning"]), config["mt"]["expression"]))) if not args.only_inclusive: for i, label in enumerate(["ggh", "qqh", "ztt", "zll", "w", "tt", "ss", "misc"]): mt_categories.append( Category( label, mt, Cuts( Cut("mt_max_index=={index}".format(index=i), "exclusive_score")), variable=Variable(args.config, VariableBinning(config["mt"]["binning"]), config["mt"]["expression"]))) tt1_categories = [] tt2_categories = [] # tt tt1_categories.append( Category( "tt1_inclusive", tt1, Cuts(), variable=Variable(args.config, VariableBinning(config["tt"]["binning"]), config["tt"]["expression"]))) tt2_categories.append( Category( "tt2_inclusive", tt2, Cuts(), variable=Variable(args.config, VariableBinning(config["tt"]["binning"]), config["tt"]["expression"]))) if not args.only_inclusive: for i, label in enumerate(["ggh", "qqh", "ztt", "noniso", "misc"]): tt1_categories.append( Category( "tt1_"+label, tt1, Cuts( Cut("tt_max_index=={index}".format(index=i), "exclusive_score")), variable=Variable(args.config, VariableBinning(config["tt"]["binning"]), config["tt"]["expression"]))) tt2_categories.append( Category( "tt2_"+label, tt2, Cuts( Cut("tt_max_index=={index}".format(index=i), "exclusive_score")), variable=Variable(args.config, VariableBinning(config["tt"]["binning"]), config["tt"]["expression"]))) # Nominal histograms # yapf: enable for process, category in product(et_processes.values(), et_categories): systematics.add( Systematic(category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) for process, category in product(mt_processes.values(), mt_categories): systematics.add( Systematic(category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) for process, category in product(tt1_processes.values(), tt1_categories): systematics.add( Systematic(category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) for process, category in product(tt2_processes.values(), tt2_categories): systematics.add( Systematic(category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) # Produce histograms logger.info("Start producing shapes.") systematics.produce() logger.info("Done producing shapes.")
def main(args): # Container for all distributions to be drawn systematics_mm = Systematics("shapes_mm_recoilunc_2018.root", num_threads=args.num_threads, find_unique_objects=True) # Era era = Run2018(args.datasets) # Channels and processes # yapf: disable directory = args.directory mm = MM() mm_processes = { "ZL" : Process("ZL", ZLEstimation (era, directory, mm, friend_directory=[])), } # Variables and categories binning = yaml.load(open(args.binning)) mm_categories = [] variable_bins = { "njets" : [0, 1, 2], "genbosonpt" : [0, 10, 20, 30, 50], } variable_names = [ "recoilParToZ", "puppirecoilParToZ", ] for njets_bin in range(len(variable_bins["njets"])): for pt_bin in range(len(variable_bins["genbosonpt"])): name = "njets_bin_%s_vs_ptvis_bin_%s"%(str(njets_bin),str(pt_bin)) category_njets = "" category_pt = "" if njets_bin == (len(variable_bins["njets"]) - 1): category_njets = "njets >= %s"%str(variable_bins["njets"][njets_bin]) else: category_njets = "njets == %s"%str(variable_bins["njets"][njets_bin]) if pt_bin == (len(variable_bins["genbosonpt"]) - 1): category_pt = "genbosonpt > %s"%str(variable_bins["genbosonpt"][pt_bin]) else: category_pt= "genbosonpt > %s && genbosonpt <= %s"%(str(variable_bins["genbosonpt"][pt_bin]),str(variable_bins["genbosonpt"][pt_bin+1])) print category_njets, category_pt cuts = Cuts( Cut(category_njets,"njets_category"), Cut(category_pt,"ptvis_category"), Cut("m_vis > 70 && m_vis < 110","z_peak") ) for v in variable_names: mm_categories.append( Category( name, mm, cuts, variable=Variable("relative_%s"%v,ConstantBinning(400,-20.0,20.0), expression="-%s/genbosonpt"%v))) # Nominal histograms for process, category in product(mm_processes.values(), mm_categories): systematics_mm.add( Systematic( category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) # Produce histograms systematics_mm.produce()
def main(args): # Container for all distributions to be drawn systematics_mm = Systematics("counts_zptm_2018.root", num_threads=args.num_threads, find_unique_objects=True) # Era era = Run2018(args.datasets) # Channels and processes # yapf: disable directory = args.directory mm = MM() mm_processes = { "data" : Process("data_obs", DataEstimation (era, directory, mm, friend_directory=[])), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, mm, friend_directory=[])), "ZL" : Process("ZL", ZLEstimation (era, directory, mm, friend_directory=[])), "TTT" : Process("TTT", TTTEstimation (era, directory, mm, friend_directory=[])), "TTL" : Process("TTL", TTLEstimation (era, directory, mm, friend_directory=[])), "VVT" : Process("VVT", VVTEstimation (era, directory, mm, friend_directory=[])), "VVL" : Process("VVL", VVLEstimation (era, directory, mm, friend_directory=[])), "W" : Process("W", WEstimation (era, directory, mm, friend_directory=[])), } mm_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, mm, [mm_processes[process] for process in ["ZTT", "ZL", "W", "TTT", "TTL", "VVT", "VVL"]], mm_processes["data"], friend_directory=[], extrapolation_factor=2.0)) # Variables and categories mm_categories = [] variable_bins = { "m_vis" : [50, 100, 200, 500, 1000], "ptvis" : [0, 10, 20, 30, 40, 50, 100, 150, 200, 300, 400, 1000], } for mass_bin in range(len(variable_bins["m_vis"]) - 1): for pt_bin in range(len(variable_bins["ptvis"]) - 1): name = "%s_bin_%s_vs_%s_bin_%s"%("m_vis",str(mass_bin),"ptvis",str(pt_bin)) cuts = Cuts(Cut("(m_vis > %s && m_vis < %s) && (ptvis > %s && ptvis < %s)"%(str(variable_bins["m_vis"][mass_bin]),str(variable_bins["m_vis"][mass_bin+1]),str(variable_bins["ptvis"][pt_bin]),str(variable_bins["ptvis"][pt_bin+1])),"zptm_category")) mm_categories.append( Category( name, mm, cuts, variable=None)) # Nominal histograms for process, category in product(mm_processes.values(), mm_categories): #if process.name in ["ZTT","ZLL"]: # process.estimation_method.get_weights().remove("zPtReweightWeight") systematics_mm.add( Systematic( category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) # Produce histograms systematics_mm.produce()
def main(args): # Write arparse arguments to YAML config logger.debug("Write argparse arguments to YAML config.") output_config = {} output_config["base_path"] = args.base_path output_config["friend_paths"] = args.friend_paths output_config["output_path"] = args.output_path output_config["output_filename"] = args.output_filename output_config["tree_path"] = args.tree_path output_config["event_branch"] = args.event_branch output_config["training_weight_branch"] = args.training_weight_branch logger.debug("Channel" + args.channel + " Era " + args.era) # Define era if "2016" in args.era: from shape_producer.estimation_methods_2016 import DataEstimation, ggHEstimation, qqHEstimation, \ ZTTEstimation, ZLEstimation, ZJEstimation, TTTEstimation, TTJEstimation, \ ZTTEmbeddedEstimation, TTLEstimation, \ EWKZEstimation, VVLEstimation, VVTEstimation, VVJEstimation, WEstimation from shape_producer.era import Run2016 era = Run2016(args.database) elif "2017" in args.era: from shape_producer.estimation_methods_2017 import DataEstimation, ZTTEstimation, ZJEstimation, ZLEstimation, \ TTLEstimation, TTJEstimation, TTTEstimation, VVTEstimation, VVJEstimation, VVLEstimation, WEstimation, \ ggHEstimation, qqHEstimation, EWKZEstimation, ZTTEmbeddedEstimation from shape_producer.era import Run2017 era = Run2017(args.database) elif "2018" in args.era: from shape_producer.estimation_methods_2018 import DataEstimation, ZTTEstimation, ZJEstimation, ZLEstimation, \ TTLEstimation, TTJEstimation, TTTEstimation, VVTEstimation, VVJEstimation, VVLEstimation, WEstimation, \ ggHEstimation, qqHEstimation, EWKZEstimation, ZTTEmbeddedEstimation from shape_producer.era import Run2018 era = Run2018(args.database) else: logger.fatal("Era {} is not implemented.".format(args.era)) raise Exception def estimationMethodAndClassMapGenerator(): ###### common processes if args.training_stxs1p1: classes_map = { # class1 "ggH_GG2H_PTH_GT200125": "ggh_PTHGT200", # class2 "ggH_GG2H_0J_PTH_0_10125": "ggh_0J", "ggH_GG2H_0J_PTH_GT10125": "ggh_0J", # class3 "ggH_GG2H_1J_PTH_0_60125": "ggh_1J_PTH0to120", "ggH_GG2H_1J_PTH_60_120125": "ggh_1J_PTH0to120", # class4 "ggH_GG2H_1J_PTH_120_200125": "ggh_1J_PTH120to200", # class5 "ggH_GG2H_GE2J_MJJ_0_350_PTH_0_60125": "ggh_2J", "ggH_GG2H_GE2J_MJJ_0_350_PTH_60_120125": "ggh_2J", "ggH_GG2H_GE2J_MJJ_0_350_PTH_120_200125": "ggh_2J", # class6 "ggH_GG2H_GE2J_MJJ_350_700_PTH_0_200_PTHJJ_0_25125": "vbftopo_lowmjj", "ggH_GG2H_GE2J_MJJ_350_700_PTH_0_200_PTHJJ_GT25125": "vbftopo_lowmjj", "qqH_QQ2HQQ_GE2J_MJJ_350_700_PTH_0_200_PTHJJ_0_25125": "vbftopo_lowmjj", "qqH_QQ2HQQ_GE2J_MJJ_350_700_PTH_0_200_PTHJJ_GT25125": "vbftopo_lowmjj", # class7 "ggH_GG2H_GE2J_MJJ_GT700_PTH_0_200_PTHJJ_0_25125": "vbftopo_highmjj", "ggH_GG2H_GE2J_MJJ_GT700_PTH_0_200_PTHJJ_GT25125": "vbftopo_highmjj", "qqH_QQ2HQQ_GE2J_MJJ_GT700_PTH_0_200_PTHJJ_0_25125": "vbftopo_highmjj", "qqH_QQ2HQQ_GE2J_MJJ_GT700_PTH_0_200_PTHJJ_GT25125": "vbftopo_highmjj", # class8 "qqH_QQ2HQQ_GE2J_MJJ_0_60125": "qqh_2J", "qqH_QQ2HQQ_GE2J_MJJ_60_120125": "qqh_2J", "qqH_QQ2HQQ_GE2J_MJJ_120_350125": "qqh_2J", # class9 "qqH_QQ2HQQ_GE2J_MJJ_GT350_PTH_GT200125": "qqh_PTHGT200", } estimationMethodList = [ ggHEstimation("ggH_GG2H_PTH_GT200125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_0J_PTH_0_10125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_0J_PTH_GT10125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_1J_PTH_0_60125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_1J_PTH_60_120125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_1J_PTH_120_200125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_GE2J_MJJ_0_350_PTH_0_60125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_GE2J_MJJ_0_350_PTH_60_120125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_GE2J_MJJ_0_350_PTH_120_200125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_GE2J_MJJ_350_700_PTH_0_200_PTHJJ_0_25125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_GE2J_MJJ_350_700_PTH_0_200_PTHJJ_GT25125", era, args.base_path, channel), qqHEstimation("qqH_QQ2HQQ_GE2J_MJJ_350_700_PTH_0_200_PTHJJ_0_25125", era, args.base_path, channel), qqHEstimation("qqH_QQ2HQQ_GE2J_MJJ_350_700_PTH_0_200_PTHJJ_GT25125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_GE2J_MJJ_GT700_PTH_0_200_PTHJJ_0_25125", era, args.base_path, channel), ggHEstimation("ggH_GG2H_GE2J_MJJ_GT700_PTH_0_200_PTHJJ_GT25125", era, args.base_path, channel), qqHEstimation("qqH_QQ2HQQ_GE2J_MJJ_GT700_PTH_0_200_PTHJJ_0_25125", era, args.base_path, channel), qqHEstimation("qqH_QQ2HQQ_GE2J_MJJ_GT700_PTH_0_200_PTHJJ_GT25125", era, args.base_path, channel), qqHEstimation("qqH_QQ2HQQ_GE2J_MJJ_0_60125", era, args.base_path, channel), qqHEstimation("qqH_QQ2HQQ_GE2J_MJJ_60_120125", era, args.base_path, channel), qqHEstimation("qqH_QQ2HQQ_GE2J_MJJ_120_350125", era, args.base_path, channel), qqHEstimation("qqH_QQ2HQQ_GE2J_MJJ_GT350_PTH_GT200125", era, args.base_path, channel), ] elif args.training_inclusive: classes_map = { "ggH125": "xxh", "qqH125": "xxh", } estimationMethodList = [ ggHEstimation("ggH125", era, args.base_path, channel), qqHEstimation("qqH125", era, args.base_path, channel), ] else: classes_map = { "ggH125": "ggh", "qqH125": "qqh", } estimationMethodList = [ ggHEstimation("ggH125", era, args.base_path, channel), qqHEstimation("qqH125", era, args.base_path, channel), ] estimationMethodList.extend([ EWKZEstimation(era, args.base_path, channel), VVLEstimation(era, args.base_path, channel) ]) classes_map["EWKZ"]="misc" ##### TT* zl,zj processes estimationMethodList.extend([ TTLEstimation(era, args.base_path, channel), ZLEstimation(era, args.base_path, channel) ]) if args.channel == "tt": classes_map.update({ "TTL": "misc", "ZL": "misc", "VVL": "misc" }) ## not TTJ,ZJ for em elif args.channel == "em": classes_map.update({ "TTL": "tt", "ZL": "misc", "VVL": "db" }) else: classes_map.update({ "TTL": "tt", "ZL": "zll", "VVL": "misc" }) ######## Check for emb vs MC if args.training_z_estimation_method == "emb": classes_map["EMB"] = "emb" estimationMethodList.extend([ ZTTEmbeddedEstimation(era, args.base_path, channel)]) elif args.training_z_estimation_method == "mc": classes_map["ZTT"] = "ztt" estimationMethodList.extend([ ZTTEstimation(era, args.base_path, channel), TTTEstimation(era, args.base_path, channel), VVTEstimation(era, args.base_path, channel) ]) if args.channel == "tt": classes_map.update({ "TTT": "misc", "VVT": "misc" }) ## not TTJ,ZJ for em elif args.channel == "em": classes_map.update({ "TTT": "tt", "VVT": "db" }) else: classes_map.update({ "TTT": "tt", "VVT": "misc" }) else: logger.fatal("No valid training-z-estimation-method! Options are emb, mc. Argument was {}".format( args.training_z_estimation_method)) raise Exception if args.training_jetfakes_estimation_method == "ff" and args.channel != "em": classes_map.update({ "ff": "ff" }) elif args.training_jetfakes_estimation_method == "mc" or args.channel == "em": # less data-> less categories for tt if args.channel == "tt": classes_map.update({ "TTJ": "misc", "ZJ": "misc" }) ## not TTJ,ZJ for em elif args.channel != "em": classes_map.update({ "TTJ": "tt", "ZJ": "zll" }) if args.channel != "em": classes_map.update({ "VVJ": "misc" }) estimationMethodList.extend([ VVJEstimation(era, args.base_path, channel), ZJEstimation(era, args.base_path, channel), TTJEstimation(era, args.base_path, channel) ]) ###w: estimationMethodList.extend([WEstimation(era, args.base_path, channel)]) if args.channel in ["et", "mt"]: classes_map["W"] = "w" else: classes_map["W"] = "misc" ### QCD class if args.channel == "tt": classes_map["QCD"] = "noniso" else: classes_map["QCD"] = "ss" else: logger.fatal("No valid training-jetfakes-estimation-method! Options are ff, mc. Argument was {}".format( args.training_jetfakes_estimation_method)) raise Exception return ([classes_map, estimationMethodList]) channelDict = {} channelDict["2016"] = {"mt": MTSM2016(), "et": ETSM2016(), "tt": TTSM2016(), "em": EMSM2016()} channelDict["2017"] = {"mt": MTSM2017(), "et": ETSM2017(), "tt": TTSM2017(), "em": EMSM2017()} channelDict["2018"] = {"mt": MTSM2018(), "et": ETSM2018(), "tt": TTSM2018(), "em": EMSM2018()} channel = channelDict[args.era][args.channel] # Set up `processes` part of config output_config["processes"] = {} # Additional cuts additional_cuts = Cuts() logger.warning("Use additional cuts for mt: %s", additional_cuts.expand()) classes_map, estimationMethodList = estimationMethodAndClassMapGenerator() ### disables all other estimation methods # classes_map={"ff":"ff"} # estimationMethodList=[] for estimation in estimationMethodList: output_config["processes"][estimation.name] = { "files": [ str(f).replace(args.base_path.rstrip("/") + "/", "") for f in estimation.get_files() ], "cut_string": (estimation.get_cuts() + channel.cuts + additional_cuts).expand(), "weight_string": estimation.get_weights().extract(), "class": classes_map[estimation.name] } if args.training_jetfakes_estimation_method == "mc" or args.channel == "em": if args.training_jetfakes_estimation_method == "ff": logger.warn("ff+em: using mc for em channel") # Same sign selection for data-driven QCD estimation = DataEstimation(era, args.base_path, channel) estimation.name = "QCD" channel_qcd = copy.deepcopy(channel) if args.channel != "tt": ## os= opposite sign channel_qcd.cuts.get("os").invert() # Same sign selection for data-driven QCD else: channel_qcd.cuts.remove("tau_2_iso") channel_qcd.cuts.add( Cut("byTightDeepTau2017v2p1VSjet_2<0.5", "tau_2_iso")) channel_qcd.cuts.add( Cut("byMediumDeepTau2017v2p1VSjet_2>0.5", "tau_2_iso_loose")) output_config["processes"][estimation.name] = { "files": [ str(f).replace(args.base_path.rstrip("/") + "/", "") for f in estimation.get_files() ], "cut_string": (estimation.get_cuts() + channel_qcd.cuts + additional_cuts).expand(), "weight_string": estimation.get_weights().extract(), "class": classes_map[estimation.name] } else: ## ff and not em estimation = DataEstimation(era, args.base_path, channel) estimation.name = "ff" aiso = copy.deepcopy(channel) if args.channel in ["et", "mt"]: aisoCut = Cut( "byTightDeepTau2017v2p1VSjet_2<0.5&&byVLooseDeepTau2017v2p1VSjet_2>0.5", "tau_aiso") fakeWeightstring = "ff2_nom" aiso.cuts.remove("tau_iso") elif args.channel == "tt": aisoCut = Cut( "(byTightDeepTau2017v2p1VSjet_2>0.5&&byTightDeepTau2017v2p1VSjet_1<0.5&&byVLooseDeepTau2017v2p1VSjet_1>0.5)||(byTightDeepTau2017v2p1VSjet_1>0.5&&byTightDeepTau2017v2p1VSjet_2<0.5&&byVLooseDeepTau2017v2p1VSjet_2>0.5)", "tau_aiso") fakeWeightstring = "(0.5*ff1_nom*(byTightDeepTau2017v2p1VSjet_1<0.5)+0.5*ff2_nom*(byTightDeepTau2017v2p1VSjet_2<0.5))" aiso.cuts.remove("tau_1_iso") aiso.cuts.remove("tau_2_iso") # self._nofake_processes = [copy.deepcopy(p) for p in nofake_processes] aiso.cuts.add(aisoCut) additionalWeights = Weights(Weight(fakeWeightstring, "fake_factor")) output_config["processes"][estimation.name] = { "files": [ str(f).replace(args.base_path.rstrip("/") + "/", "") for f in estimation.get_files() ], "cut_string": (estimation.get_cuts() + aiso.cuts).expand(), "weight_string": (estimation.get_weights() + additionalWeights).extract(), "class": classes_map[estimation.name] } output_config["datasets"] = [args.output_path + "/fold" + fold + "_training_dataset.root" for fold in ["0", "1"]] ##################################### # Write output config logger.info("Write config to file: {}".format(args.output_config)) yaml.dump(output_config, open(args.output_config, 'w'), default_flow_style=False)
def main(args): # Write arparse arguments to YAML config filelist = {} # Define era if "2016" in args.era: from shape_producer.estimation_methods_2016 import DataEstimation, ggHEstimation, qqHEstimation, ZTTEstimation, ZLEstimation, ZJEstimation, WEstimation, TTTEstimation, TTJEstimation, ZTTEmbeddedEstimation, TTLEstimation, EWKZEstimation, VVLEstimation, VVJEstimation, VVEstimation, VVTEstimation, VHEstimation, EWKWpEstimation, EWKWmEstimation, ttHEstimation, ggHWWEstimation, qqHWWEstimation #QCDEstimation_SStoOS_MTETEM, QCDEstimationTT, HTTEstimation, from shape_producer.era import Run2016 era = Run2016(args.database) elif "2017" in args.era: from shape_producer.estimation_methods_2017 import DataEstimation, ZTTEstimation, ZLEstimation, ZJEstimation, TTLEstimation, TTJEstimation, TTTEstimation, VVTEstimation, VVJEstimation, VVLEstimation, WEstimation, ggHEstimation, qqHEstimation, VHEstimation, EWKZEstimation, ZTTEmbeddedEstimation, ttHEstimation from shape_producer.era import Run2017 era = Run2017(args.database) elif "2018" in args.era: from shape_producer.estimation_methods_2018 import DataEstimation, ZTTEstimation, ZLEstimation, ZJEstimation, TTLEstimation, TTJEstimation, TTTEstimation, VVTEstimation, VVJEstimation, VVLEstimation, WEstimation, ggHEstimation, qqHEstimation, VHEstimation, EWKZEstimation, ZTTEmbeddedEstimation, ttHEstimation from shape_producer.era import Run2018 era = Run2018(args.database) else: logger.fatal("Era {} is not implemented.".format(args.era)) raise Exception logger.debug("Write filelist for channel %s in era %s.", args.channel, args.era) ############################################################################ # Era: 2016, Channel: mt if "2016" in args.era and args.channel == "mt": channel = MTSM2016() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), #ZTTEmbeddedEstimation(era, args.directory, channel), #TODO include EMB again once samples are there ZLEstimation(era, args.directory, channel), ZJEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), TTJEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), EWKWpEstimation(era, args.directory, channel), EWKWmEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel), ggHWWEstimation(era, args.directory, channel), qqHWWEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era: 2017, Channel: mt if "2017" in args.era and args.channel == "mt": channel = MTSM2017() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), ZTTEmbeddedEstimation(era, args.directory, channel), ZLEstimation(era, args.directory, channel), ZJEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTJEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVJEstimation(era, args.directory, channel), VVTEstimation(era, args.directory, channel), VVLEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era: 2018, Channel: mt if "2018" in args.era and args.channel == "mt": channel = MTSM2018() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), ZTTEmbeddedEstimation(era, args.directory, channel), ZLEstimation(era, args.directory, channel), ZJEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTJEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVJEstimation(era, args.directory, channel), VVTEstimation(era, args.directory, channel), VVLEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era: 2016, Channel: et if "2016" in args.era and args.channel == "et": channel = ETSM2016() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), #ZTTEmbeddedEstimation(era, args.directory, channel), #TODO include EMB again once samples are there ZLEstimation(era, args.directory, channel), ZJEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), TTJEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), EWKWpEstimation(era, args.directory, channel), EWKWmEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel), ggHWWEstimation(era, args.directory, channel), qqHWWEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era: 2017, Channel: et if "2017" in args.era and args.channel == "et": channel = ETSM2017() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), ZTTEmbeddedEstimation(era, args.directory, channel), ZLEstimation(era, args.directory, channel), ZJEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTJEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVJEstimation(era, args.directory, channel), VVTEstimation(era, args.directory, channel), VVLEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era: 2018, Channel: et if "2018" in args.era and args.channel == "et": channel = ETSM2018() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), ZTTEmbeddedEstimation(era, args.directory, channel), ZLEstimation(era, args.directory, channel), ZJEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTJEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVJEstimation(era, args.directory, channel), VVTEstimation(era, args.directory, channel), VVLEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era: 2016, Channel: tt if "2016" in args.era and args.channel == "tt": channel = TTSM2016() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), #ZTTEmbeddedEstimation(era, args.directory, channel), #TODO include EMB again once samples are there ZLEstimation(era, args.directory, channel), ZJEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), TTJEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), EWKWpEstimation(era, args.directory, channel), EWKWmEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel), ggHWWEstimation(era, args.directory, channel), qqHWWEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era 2017, Channel: tt if "2017" in args.era and args.channel == "tt": channel = TTSM2017() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), ZTTEmbeddedEstimation(era, args.directory, channel), ZLEstimation(era, args.directory, channel), ZJEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTJEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVJEstimation(era, args.directory, channel), VVTEstimation(era, args.directory, channel), VVLEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era 2018, Channel: tt if "2018" in args.era and args.channel == "tt": channel = TTSM2018() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), ZTTEmbeddedEstimation(era, args.directory, channel), ZLEstimation(era, args.directory, channel), ZJEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTJEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVJEstimation(era, args.directory, channel), VVTEstimation(era, args.directory, channel), VVLEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era: 2016, Channel: em if "2016" in args.era and args.channel == "em": channel = EMSM2016() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), #ZTTEmbeddedEstimation(era, args.directory, channel), #TODO include EMB again once samples are there ZLEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), EWKWpEstimation(era, args.directory, channel), EWKWmEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel), ggHWWEstimation(era, args.directory, channel), qqHWWEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era: 2017, Channel: em if "2017" in args.era and args.channel == "em": channel = EMSM2017() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), ZTTEmbeddedEstimation(era, args.directory, channel), ZLEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVTEstimation(era, args.directory, channel), VVLEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Era: 2018, Channel: em if "2018" in args.era and args.channel == "em": channel = EMSM2018() for estimation in [ ggHEstimation("ggH", era, args.directory, channel), qqHEstimation("qqH", era, args.directory, channel), ttHEstimation(era, args.directory, channel), VHEstimation(era, args.directory, channel), ZTTEstimation(era, args.directory, channel), ZTTEmbeddedEstimation(era, args.directory, channel), ZLEstimation(era, args.directory, channel), TTTEstimation(era, args.directory, channel), TTLEstimation(era, args.directory, channel), WEstimation(era, args.directory, channel), VVTEstimation(era, args.directory, channel), VVLEstimation(era, args.directory, channel), EWKZEstimation(era, args.directory, channel), DataEstimation(era, args.directory, channel) ]: # Get files for estimation method logger.debug("Get files for estimation method %s.", estimation.name) files = [str(f) for f in estimation.get_files()] # Go through files and get folders for channel for f in files: if not os.path.exists(f): logger.fatal("File does not exist: %s", f) raise Exception folders = [] f_ = ROOT.TFile(f) for k in f_.GetListOfKeys(): if "{}_".format(args.channel) in k.GetName(): folders.append(k.GetName()) f_.Close() filelist[f] = folders ############################################################################ # Write output filelist logger.info("Write filelist to file: {}".format(args.output)) yaml.dump(filelist, open(args.output, 'w'), default_flow_style=False)
def main(args): # Container for all distributions to be drawn systematics_mt = Systematics("shapes_mt_2018.root", num_threads=args.num_threads, find_unique_objects=True) systematics_et = Systematics("shapes_et_2018.root", num_threads=args.num_threads, find_unique_objects=True) systematics_tt = Systematics("shapes_tt_2018.root", num_threads=args.num_threads, find_unique_objects=True) systematics_em = Systematics("shapes_em_2018.root", num_threads=args.num_threads, find_unique_objects=True) systematics_mm = Systematics("shapes_mm_2018.root", num_threads=args.num_threads, find_unique_objects=True) # Era era = Run2018(args.datasets) # Channels and processes # yapf: disable directory = args.directory et_friend_directory = args.et_friend_directory mt_friend_directory = args.mt_friend_directory tt_friend_directory = args.tt_friend_directory em_friend_directory = args.em_friend_directory mm_friend_directory = args.mm_friend_directory ff_friend_directory = args.fake_factor_friend_directory #mt = MT() #mt_processes = { # "data" : Process("data_obs", DataEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "ZTT" : Process("ZTT", ZTTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "EMB" : Process("EMB", ZTTEmbeddedEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "ZJ" : Process("ZJ", ZJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "ZL" : Process("ZL", ZLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "TTT" : Process("TTT", TTTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "TTJ" : Process("TTJ", TTJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "TTL" : Process("TTL", TTLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "VVT" : Process("VVT", VVTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "VVJ" : Process("VVJ", VVJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "VVL" : Process("VVL", VVLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "W" : Process("W", WEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "ggH" : Process("ggH125", ggHEstimation ("ggH125", era, directory, mt, friend_directory=mt_friend_directory)), # "qqH" : Process("qqH125", qqHEstimation ("qqH125", era, directory, mt, friend_directory=mt_friend_directory)), # "VH" : Process("VH125", VHEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "WH" : Process("WH125", WHEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "ZH" : Process("ZH125", ZHEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "ttH" : Process("ttH125", ttHEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # } #mt_processes["FAKES"] = Process("jetFakes", NewFakeEstimationLT(era, directory, mt, [mt_processes[process] for process in ["ZTT", "ZL", "TTT", "TTL", "VVT", "VVL"]], mt_processes["data"], friend_directory=mt_friend_directory+[ff_friend_directory])) #mt_processes["FAKESEMB"] = Process("jetFakesEMB", NewFakeEstimationLT(era, directory, mt, [mt_processes[process] for process in ["EMB", "ZL", "TTL", "VVL"]], mt_processes["data"], friend_directory=mt_friend_directory+[ff_friend_directory])) #mt_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, mt, # [mt_processes[process] for process in ["ZTT", "ZL", "ZJ", "W", "TTT", "TTJ", "TTL", "VVT", "VVJ", "VVL"]], # mt_processes["data"], friend_directory=mt_friend_directory, extrapolation_factor=1.00)) #mt_processes["QCDEMB"] = Process("QCDEMB", QCDEstimation_SStoOS_MTETEM(era, directory, mt, # [mt_processes[process] for process in ["EMB", "ZL", "ZJ", "W", "TTJ", "TTL", "VVJ", "VVL"]], # mt_processes["data"], friend_directory=mt_friend_directory, extrapolation_factor=1.00)) #et = ET() #et_processes = { # "data" : Process("data_obs", DataEstimation (era, directory, et, friend_directory=et_friend_directory)), # "ZTT" : Process("ZTT", ZTTEstimation (era, directory, et, friend_directory=et_friend_directory)), # "EMB" : Process("EMB", ZTTEmbeddedEstimation (era, directory, et, friend_directory=et_friend_directory)), # "ZJ" : Process("ZJ", ZJEstimation (era, directory, et, friend_directory=et_friend_directory)), # "ZL" : Process("ZL", ZLEstimation (era, directory, et, friend_directory=et_friend_directory)), # "TTT" : Process("TTT", TTTEstimation (era, directory, et, friend_directory=et_friend_directory)), # "TTJ" : Process("TTJ", TTJEstimation (era, directory, et, friend_directory=et_friend_directory)), # "TTL" : Process("TTL", TTLEstimation (era, directory, et, friend_directory=et_friend_directory)), # "VVT" : Process("VVT", VVTEstimation (era, directory, et, friend_directory=et_friend_directory)), # "VVJ" : Process("VVJ", VVJEstimation (era, directory, et, friend_directory=et_friend_directory)), # "VVL" : Process("VVL", VVLEstimation (era, directory, et, friend_directory=et_friend_directory)), # "W" : Process("W", WEstimation (era, directory, et, friend_directory=et_friend_directory)), # "ggH" : Process("ggH125", ggHEstimation ("ggH125", era, directory, et, friend_directory=et_friend_directory)), # "qqH" : Process("qqH125", qqHEstimation ("qqH125", era, directory, et, friend_directory=et_friend_directory)), # "VH" : Process("VH125", VHEstimation (era, directory, et, friend_directory=et_friend_directory)), # "WH" : Process("WH125", WHEstimation (era, directory, et, friend_directory=et_friend_directory)), # "ZH" : Process("ZH125", ZHEstimation (era, directory, et, friend_directory=et_friend_directory)), # "ttH" : Process("ttH125", ttHEstimation (era, directory, et, friend_directory=et_friend_directory)), # } #et_processes["FAKES"] = Process("jetFakes", NewFakeEstimationLT(era, directory, et, [et_processes[process] for process in ["ZTT", "ZL", "TTT", "TTL", "VVT", "VVL"]], et_processes["data"], friend_directory=et_friend_directory+[ff_friend_directory])) #et_processes["FAKESEMB"] = Process("jetFakesEMB", NewFakeEstimationLT(era, directory, et, [et_processes[process] for process in ["EMB", "ZL", "TTL", "VVL"]], et_processes["data"], friend_directory=et_friend_directory+[ff_friend_directory])) #et_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, et, # [et_processes[process] for process in ["ZTT", "ZL", "ZJ", "W", "TTT", "TTJ", "TTL", "VVT", "VVJ", "VVL"]], # et_processes["data"], friend_directory=et_friend_directory, extrapolation_factor=1.00)) #et_processes["QCDEMB"] = Process("QCDEMB", QCDEstimation_SStoOS_MTETEM(era, directory, et, # [et_processes[process] for process in ["EMB", "ZL", "ZJ", "W", "TTJ", "TTL", "VVJ", "VVL"]], # et_processes["data"], friend_directory=et_friend_directory, extrapolation_factor=1.00)) #tt = TT() #tt_processes = { # "data" : Process("data_obs", DataEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "ZTT" : Process("ZTT", ZTTEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "EMB" : Process("EMB", ZTTEmbeddedEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "ZJ" : Process("ZJ", ZJEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "ZL" : Process("ZL", ZLEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "TTT" : Process("TTT", TTTEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "TTJ" : Process("TTJ", TTJEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "TTL" : Process("TTL", TTLEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "VVT" : Process("VVT", VVTEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "VVJ" : Process("VVJ", VVJEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "VVL" : Process("VVL", VVLEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "W" : Process("W", WEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "ggH" : Process("ggH125", ggHEstimation ("ggH125", era, directory, tt, friend_directory=tt_friend_directory)), # "qqH" : Process("qqH125", qqHEstimation ("qqH125", era, directory, tt, friend_directory=tt_friend_directory)), # "VH" : Process("VH125", VHEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "WH" : Process("WH125", WHEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "ZH" : Process("ZH125", ZHEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "ttH" : Process("ttH125", ttHEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # } #tt_processes["FAKESEMB"] = Process("jetFakesEMB", NewFakeEstimationTT(era, directory, tt, [tt_processes[process] for process in ["EMB", "ZL", "TTL", "VVL"]], tt_processes["data"], friend_directory=tt_friend_directory+[ff_friend_directory])) #tt_processes["FAKES"] = Process("jetFakes", NewFakeEstimationTT(era, directory, tt, [tt_processes[process] for process in ["ZTT", "ZL", "TTT", "TTL", "VVT", "VVL"]], tt_processes["data"], friend_directory=tt_friend_directory+[ff_friend_directory])) #tt_processes["QCD"] = Process("QCD", QCDEstimation_ABCD_TT_ISO2(era, directory, tt, # [tt_processes[process] for process in ["ZTT", "ZL", "ZJ", "W", "TTT", "TTJ", "TTL", "VVT", "VVJ", "VVL"]], # tt_processes["data"], friend_directory=tt_friend_directory)) #tt_processes["QCDEMB"] = Process("QCDEMB", QCDEstimation_ABCD_TT_ISO2(era, directory, tt, # [tt_processes[process] for process in ["EMB", "ZL", "ZJ", "W", "TTJ", "TTL", "VVJ", "VVL"]], # tt_processes["data"], friend_directory=tt_friend_directory)) #em = EM() #em_processes = { # "data" : Process("data_obs", DataEstimation (era, directory, em, friend_directory=em_friend_directory)), # "ZTT" : Process("ZTT", ZTTEstimation (era, directory, em, friend_directory=em_friend_directory)), # "EMB" : Process("EMB", ZTTEmbeddedEstimation (era, directory, em, friend_directory=em_friend_directory)), # "ZL" : Process("ZL", ZLEstimation (era, directory, em, friend_directory=em_friend_directory)), # "TTT" : Process("TTT", TTTEstimation (era, directory, em, friend_directory=em_friend_directory)), # "TTL" : Process("TTL", TTLEstimation (era, directory, em, friend_directory=em_friend_directory)), # "VVT" : Process("VVT", VVTEstimation (era, directory, em, friend_directory=em_friend_directory)), # "VVL" : Process("VVL", VVLEstimation (era, directory, em, friend_directory=em_friend_directory)), # "W" : Process("W", WEstimation (era, directory, em, friend_directory=em_friend_directory)), # "ggH" : Process("ggH125", ggHEstimation ("ggH125", era, directory, em, friend_directory=em_friend_directory)), # "qqH" : Process("qqH125", qqHEstimation ("qqH125", era, directory, em, friend_directory=em_friend_directory)), # "VH" : Process("VH125", VHEstimation (era, directory, em, friend_directory=em_friend_directory)), # "WH" : Process("WH125", WHEstimation (era, directory, em, friend_directory=em_friend_directory)), # "ZH" : Process("ZH125", ZHEstimation (era, directory, em, friend_directory=em_friend_directory)), # "ttH" : Process("ttH125", ttHEstimation (era, directory, em, friend_directory=em_friend_directory)), # } #em_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, em, [em_processes[process] for process in ["ZTT", "ZL", "W", "TTT", "VVT", "VVL"]], em_processes["data"], extrapolation_factor=1.0, qcd_weight = Weight("em_qcd_extrap_up_Weight","qcd_weight"))) #em_processes["QCDEMB"] = Process("QCDEMB", QCDEstimation_SStoOS_MTETEM(era, directory, em, [em_processes[process] for process in ["EMB", "ZL", "W", "VVL"]], em_processes["data"], extrapolation_factor=1.0, qcd_weight = Weight("em_qcd_extrap_up_Weight","qcd_weight"))) mm = MM() mm_processes = { "data" : Process("data_obs", DataEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "W" : Process("W", WEstimation (era, directory, mm, friend_directory=mm_friend_directory)), } mm_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, mm, [mm_processes[process] for process in ["ZTT", "ZL", "W", "TTT", "TTL", "VVT", "VVL"]], mm_processes["data"], friend_directory=mm_friend_directory, extrapolation_factor=2.0)) # Variables and categories binning = yaml.load(open(args.binning)) mt_categories = [] et_categories = [] tt_categories = [] em_categories = [] mm_categories = [] variable_names = [ "m_vis", "ptvis", # "DiTauDeltaR", # "m_sv", "pt_sv", "eta_sv", # "m_sv_puppi", "pt_sv_puppi", "eta_sv_puppi", # "m_fastmtt", "pt_fastmtt", "eta_fastmtt", # "m_fastmtt_puppi", "pt_fastmtt_puppi", "eta_fastmtt_puppi", # "ME_D", "ME_vbf", "ME_z2j_1", "ME_z2j_2", "ME_q2v1", "ME_q2v2", "ME_costheta1", "ME_costheta2", "ME_costhetastar", "ME_phi", "ME_phi1", "pt_1", "pt_2", "eta_1", "eta_2", # "mjj", "jdeta", "dijetpt", "njets", "jpt_1", "jpt_2", "jeta_1", "jeta_2", # "nbtag", "bpt_1", "bpt_2", "beta_1", "beta_2", "met", #"mt_1", "mt_2", "pt_tt", "pZetaMissVis", "pt_ttjj", "mt_tot", "mTdileptonMET", "puppimet", #"mt_1_puppi", "mt_2_puppi", "pt_tt_puppi", "pZetaPuppiMissVis", "pt_ttjj_puppi", "mt_tot_puppi", "mTdileptonMET_puppi", # "NNrecoil_pt", "nnmet", "mt_1_nn", "mt_2_nn", "pt_tt_nn", "pZetaNNMissVis", "pt_ttjj_nn", "mt_tot_nn", "mTdileptonMET_nn", "metParToZ", "metPerpToZ", "puppimetParToZ", "puppimetPerpToZ", ] #if "mt" in args.channels: # variables = [Variable(v,VariableBinning(binning["control"]["mt"][v]["bins"]), expression=binning["control"]["mt"][v]["expression"]) for v in variable_names] # cuts = Cuts() # for name, var in zip(variable_names, variables): # mt_categories.append( # Category( # name, # mt, # cuts, # variable=var)) #if "et" in args.channels: # variables = [Variable(v,VariableBinning(binning["control"]["et"][v]["bins"]), expression=binning["control"]["et"][v]["expression"]) for v in variable_names] # cuts = Cuts() # for name, var in zip(variable_names, variables): # et_categories.append( # Category( # name, # et, # cuts, # variable=var)) #if "tt" in args.channels: # variables = [Variable(v,VariableBinning(binning["control"]["tt"][v]["bins"]), expression=binning["control"]["tt"][v]["expression"]) for v in variable_names] # cuts = Cuts() # for name, var in zip(variable_names, variables): # tt_categories.append( # Category( # name, # tt, # cuts, # variable=var)) #if "em" in args.channels: # variables = [Variable(v,VariableBinning(binning["control"]["em"][v]["bins"]), expression=binning["control"]["em"][v]["expression"]) for v in variable_names] # cuts = Cuts() # for name, var in zip(variable_names, variables): # em_categories.append( # Category( # name, # em, # cuts, # variable=var)) if "mm" in args.channels: variables = [Variable(v,VariableBinning(binning["control"]["mm"][v]["bins"]), expression=binning["control"]["mm"][v]["expression"]) for v in variable_names] variables.append(Variable("m_vis_high",ConstantBinning(19,50.0,1000.0),expression="m_vis")) variable_names.append("m_vis_high") cuts = Cuts() for name, var in zip(variable_names, variables): mm_categories.append( Category( name, mm, cuts, variable=var)) mm_categories.append( Category( name+"_peak", mm, Cuts(Cut("m_vis > 70 && m_vis < 110","m_vis_peak")), variable=var)) # Nominal histograms #if "mt" in args.channels: # for process, category in product(mt_processes.values(), mt_categories): # systematics_mt.add( # Systematic( # category=category, # process=process, # analysis="smhtt", # era=era, # variation=Nominal(), # mass="125")) #if "et" in args.channels: # for process, category in product(et_processes.values(), et_categories): # systematics_et.add( # Systematic( # category=category, # process=process, # analysis="smhtt", # era=era, # variation=Nominal(), # mass="125")) #if "tt" in args.channels: # for process, category in product(tt_processes.values(), tt_categories): # systematics_tt.add( # Systematic( # category=category, # process=process, # analysis="smhtt", # era=era, # variation=Nominal(), # mass="125")) #if "em" in args.channels: # for process, category in product(em_processes.values(), em_categories): # systematics_em.add( # Systematic( # category=category, # process=process, # analysis="smhtt", # era=era, # variation=Nominal(), # mass="125")) if "mm" in args.channels: for process, category in product(mm_processes.values(), mm_categories): systematics_mm.add( Systematic( category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) # Produce histograms #if "mt" in args.channels: systematics_mt.produce() #if "et" in args.channels: systematics_et.produce() #if "tt" in args.channels: systematics_tt.produce() #if "em" in args.channels: systematics_em.produce() if "mm" in args.channels: systematics_mm.produce()
def main(args): # Container for all distributions to be drawn systematics_mm = Systematics("shapes_mm_recoil_2018.root", num_threads=args.num_threads, find_unique_objects=True) # Era era = Run2018(args.datasets) # Channels and processes # yapf: disable directory = args.directory zptm_path = "/portal/ekpbms1/home/akhmet/workdir/FriendTreeProductionMain/CMSSW_10_2_14/src/ZPtMReweighting_workdir/ZPtMReweighting_collected/" mm = MM() mm_processes = { "data" : Process("data_obs", DataEstimation (era, directory, mm, friend_directory=[])), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, mm, friend_directory=[zptm_path])), "ZL" : Process("ZL", ZLEstimation (era, directory, mm, friend_directory=[zptm_path])), "TTT" : Process("TTT", TTTEstimation (era, directory, mm, friend_directory=[])), "TTL" : Process("TTL", TTLEstimation (era, directory, mm, friend_directory=[])), "VVT" : Process("VVT", VVTEstimation (era, directory, mm, friend_directory=[])), "VVL" : Process("VVL", VVLEstimation (era, directory, mm, friend_directory=[])), "W" : Process("W", WEstimation (era, directory, mm, friend_directory=[])), } mm_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, mm, [mm_processes[process] for process in ["ZTT", "ZL", "W", "TTT", "TTL", "VVT", "VVL"]], mm_processes["data"], friend_directory=[], extrapolation_factor=2.0)) # Variables and categories binning = yaml.load(open(args.binning)) mm_categories = [] variable_bins = { "njets" : [0, 1, 2], "ptvis" : [0, 10, 20, 30, 50], } variable_names = [ "metParToZ", "metPerpToZ", "puppimetParToZ", "puppimetPerpToZ", # "recoilParToZ", "recoilPerpToZ", # "puppirecoilParToZ", "puppirecoilPerpToZ", ] for njets_bin in range(len(variable_bins["njets"])): for pt_bin in range(len(variable_bins["ptvis"])): name = "njets_bin_%s_vs_ptvis_bin_%s"%(str(njets_bin),str(pt_bin)) category_njets = "" category_pt = "" if njets_bin == (len(variable_bins["njets"]) - 1): category_njets = "njets >= %s"%str(variable_bins["njets"][njets_bin]) else: category_njets = "njets == %s"%str(variable_bins["njets"][njets_bin]) if pt_bin == (len(variable_bins["ptvis"]) - 1): category_pt = "ptvis > %s"%str(variable_bins["ptvis"][pt_bin]) else: category_pt= "ptvis > %s && ptvis <= %s"%(str(variable_bins["ptvis"][pt_bin]),str(variable_bins["ptvis"][pt_bin+1])) print category_njets, category_pt cuts = Cuts( Cut(category_njets,"njets_category"), Cut(category_pt,"ptvis_category"), Cut("m_vis > 70 && m_vis < 110","z_peak") ) for v in variable_names: mm_categories.append( Category( name, mm, cuts, variable=Variable(v,VariableBinning(binning["control"]["mm"][v]["bins"]), expression=binning["control"]["mm"][v]["expression"]))) # Nominal histograms for process, category in product(mm_processes.values(), mm_categories): systematics_mm.add( Systematic( category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) # Produce histograms systematics_mm.produce()
def main(args): # Container for all distributions to be drawn logger.info("Set up shape variations.") systematics = Systematics( "{}_cutbased_shapes_{}.root".format(args.tag, args.discriminator_variable), num_threads=args.num_threads, skip_systematic_variations=args.skip_systematic_variations) # Era selection if "2018" in args.era: from shape_producer.estimation_methods_2018 import DataEstimation, ZTTEstimation, ZTTEmbeddedEstimation, ZLEstimation, ZJEstimation, TTLEstimation, TTJEstimation, TTTEstimation, VVLEstimation, VVTEstimation, VVJEstimation, WEstimation, ggHEstimation, qqHEstimation, VHEstimation, WHEstimation, ZHEstimation, ttHEstimation, HWWEstimation, ggHWWEstimation, qqHWWEstimation, SUSYggHEstimation, SUSYbbHEstimation, QCDEstimation_ABCD_TT_ISO2, QCDEstimation_SStoOS_MTETEM, NewFakeEstimationLT, NewFakeEstimationTT from shape_producer.era import Run2018 era = Run2018(args.datasets) else: logger.critical("Era {} is not implemented.".format(args.era)) raise Exception # Channels and processes # yapf: disable directory = args.directory friend_directories = { "et" : args.et_friend_directory, "mt" : args.mt_friend_directory, "tt" : args.tt_friend_directory, "em" : args.em_friend_directory, } ff_friend_directory = args.fake_factor_friend_directory channel_dict = { "mt" : MTMSSM2018(), "et" : ETMSSM2018(), "tt" : TTMSSM2018(), "em" : EMMSSM2018(), } susyggH_masses = [80, 90, 100, 110, 120, 130, 140, 160, 180, 200, 250, 300, 350, 400, 450, 600, 700, 800, 900, 1200, 1400, 1500, 1600, 1800, 2000, 2300, 2600, 2900, 3200] susybbH_lo_masses = [80, 90, 100, 110, 120, 130, 140, 160, 180, 200, 250, 300, 350, 400, 450, 600, 700, 800, 900, 1200, 1400, 1500, 1600, 1800, 2000, 2300, 2600, 2900, 3200] susybbH_masses = [80, 90, 100, 110, 120, 125, 130, 140, 160, 180, 200, 250, 300, 350, 400, 450, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2300, 2600, 2900, 3200, 3500] processes = { "mt" : {}, "et" : {}, "tt" : {}, "em" : {}, } for ch in args.channels: # common processes if args.shape_group == "backgrounds": processes[ch]["data"] = Process("data_obs", DataEstimation (era, directory, channel_dict[args.era][ch], friend_directory=friend_directories[ch])) processes[ch]["EMB"] = Process("EMB", ZTTEmbeddedEstimation (era, directory, channel_dict[args.era][ch], friend_directory=friend_directories[ch])) processes[ch]["ZL"] = Process("ZL", ZLEstimation (era, directory, channel_dict[args.era][ch], friend_directory=friend_directories[ch])) processes[ch]["TTL"] = Process("TTL", TTLEstimation (era, directory, channel_dict[args.era][ch], friend_directory=friend_directories[ch])) processes[ch]["VVL"] = Process("VVL", VVLEstimation (era, directory, channel_dict[args.era][ch], friend_directory=friend_directories[ch])) processes[ch]["VH125"] = Process("VH125", VHEstimation (era, directory, channel_dict[args.era][ch], friend_directory=friend_directories[ch])) processes[ch]["WH125"] = Process("WH125", WHEstimation (era, directory, channel_dict[args.era][ch], friend_directory=friend_directories[ch])) processes[ch]["ZH125"] = Process("ZH125", ZHEstimation (era, directory, channel_dict[args.era][ch], friend_directory=friend_directories[ch])) processes[ch]["ttH125"] = Process("ttH125", ttHEstimation (era, directory, channel_dict[args.era][ch], friend_directory=friend_directories[ch])) processes[ch]["ggHWW125"] = Process("ggHWW125", ggHWWEstimation (era, directory, channel_dict[ch], friend_directory=friend_directories[ch])) processes[ch]["qqHWW125"] = Process("qqHWW125", qqHWWEstimation (era, directory, channel_dict[ch], friend_directory=friend_directories[ch])) # mssm ggH and bbH signals if "gg" in args.shape_group: for m in susyggH_masses: name = args.shape_group + "_" + str(m) processes[ch][name] = Process(name, SUSYggHEstimation(era, directory, channel_dict[ch], str(m), args.shape_group.replace("gg",""), friend_directory=friend_directories[ch])) if args.shape_group == "bbH": for m in susybbH_masses: name = "bbH_" + str(m) processes[ch][name] = Process(name, SUSYbbHEstimation(era, directory, channel_dict[ch], str(m), friend_directory=friend_directories[ch])) if args.shape_group == "sm_signals": # stage 0 and stage 1.1 ggh and qqh for ggH_htxs in ggHEstimation.htxs_dict: processes[ch][ggH_htxs] = Process(ggH_htxs, ggHEstimation(ggH_htxs, era, directory, channel_dict[ch], friend_directory=[])) # friend_directories[ch])) for qqH_htxs in qqHEstimation.htxs_dict: processes[ch][qqH_htxs] = Process(qqH_htxs, qqHEstimation(qqH_htxs, era, directory, channel_dict[ch], friend_directory=[])) # friend_directories[ch])) # channel-specific processes if args.shape_group == "backgrounds": if ch in ["mt", "et"]: processes[ch]["FAKES"] = Process("jetFakes", NewFakeEstimationLT(era, directory, channel_dict[ch], [processes[ch][process] for process in ["EMB", "ZL", "TTL", "VVL"]], processes[ch]["data"], friend_directory=friend_directories[ch]+[ff_friend_directory])) elif ch == "tt": processes[ch]["FAKES"] = Process("jetFakes", NewFakeEstimationTT(era, directory, channel_dict[ch], [processes[ch][process] for process in ["EMB", "ZL", "TTL", "VVL"]], processes[ch]["data"], friend_directory=friend_directories[ch]+[ff_friend_directory])) elif ch == "em": processes[ch]["W"] = Process("W", WEstimation(era, directory, channel_dict[ch], friend_directory=friend_directories[ch])) processes[ch]["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, channel_dict[ch], [processes[ch][process] for process in ["EMB", "ZL", "W", "VVL", "TTL"]], processes[ch]["data"], extrapolation_factor=1.0, qcd_weight = Weight("em_qcd_extrap_up_Weight","qcd_weight"))) # Variables and categories if sys.version_info.major <= 2 and sys.version_info.minor <= 7 and sys.version_info.micro <= 15: binning = yaml.load(open(args.binning)) else: binning = yaml.load(open(args.binning), Loader=yaml.FullLoader) # Cut-based analysis shapes categories = { "mt" : [], "et" : [], "tt" : [], "em" : [], } for ch in args.channels: discriminator = construct_variable(binning, args.discriminator_variable) # Get dictionary mapping category name to cut objects. cut_dict = create_cut_map(binning, ch) # Create full set of cuts from dict and create category using these cuts. cuts = Cuts(*cut_dict[args.category]) categories[ch].append(Category(args.category, channel_dict[ch], cuts, variable=discriminator)) # Choice of activated signal processes signal_nicks = [] sm_htt_backgrounds_nicks = ["WH125", "ZH125", "VH125", "ttH125"] sm_hww_nicks = ["ggHWW125", "qqHWW125"] sm_htt_signals_nicks = [ggH_htxs for ggH_htxs in ggHEstimation.htxs_dict] + [qqH_htxs for qqH_htxs in qqHEstimation.htxs_dict] susy_nicks = [] if "gg" in args.shape_group: for m in susyggH_masses: susy_nicks.append(args.shape_group + "_" + str(m)) if args.shape_group == "bbH": for m in susybbH_masses: susy_nicks.append("bbH_" + str(m)) if args.shape_group == "backgrounds": signal_nicks = sm_htt_backgrounds_nicks + sm_hww_nicks elif args.shape_group == "sm_signals": signal_nicks = sm_htt_signals_nicks else: signal_nicks = susy_nicks # Nominal histograms for ch in args.channels: for process, category in product(processes[ch].values(), categories[ch]): systematics.add(Systematic(category=category, process=process, analysis="mssmvssm", era=era, variation=Nominal(), mass="125")) # Setup shapes variations # EMB: 10% removed events in ttbar simulation (ttbar -> real tau tau events) will be added/subtracted to ZTT shape to use as systematic if args.shape_group == "backgrounds": tttautau_process = {} for ch in args.channels: tttautau_process[ch] = Process("TTT", TTTEstimation(era, directory, channel_dict[ch], friend_directory=friend_directories[ch])) processes[ch]['ZTTpTTTauTauDown'] = Process("ZTTpTTTauTauDown", AddHistogramEstimationMethod("AddHistogram", "nominal", era, directory, channel_dict[ch], [processes[ch]["EMB"], tttautau_process[ch]], [1.0, -0.1])) processes[ch]['ZTTpTTTauTauUp'] = Process("ZTTpTTTauTauUp", AddHistogramEstimationMethod("AddHistogram", "nominal", era, directory, channel_dict[ch], [processes[ch]["EMB"], tttautau_process[ch]], [1.0, 0.1])) for category in categories[ch]: for updownvar in ["Down", "Up"]: systematics.add(Systematic(category=category, process=processes[ch]['ZTTpTTTauTau%s'%updownvar], analysis="smhtt", era=era, variation=Relabel("CMS_htt_emb_ttbar_Run2018", updownvar), mass="125")) # Split JES shapes jet_es_variations = create_systematic_variations("CMS_scale_j_Absolute", "jecUncAbsolute", DifferentPipeline) jet_es_variations += create_systematic_variations("CMS_scale_j_Absolute_Run2018", "jecUncAbsoluteYear", DifferentPipeline) jet_es_variations += create_systematic_variations("CMS_scale_j_BBEC1", "jecUncBBEC1", DifferentPipeline) jet_es_variations += create_systematic_variations("CMS_scale_j_BBEC1_Run2018", "jecUncBBEC1Year", DifferentPipeline) jet_es_variations += create_systematic_variations("CMS_scale_j_EC2", "jecUncEC2", DifferentPipeline) jet_es_variations += create_systematic_variations("CMS_scale_j_EC2_Run2018", "jecUncEC2Year", DifferentPipeline) jet_es_variations += create_systematic_variations("CMS_scale_j_FlavorQCD", "jecUncFlavorQCD", DifferentPipeline) jet_es_variations += create_systematic_variations("CMS_scale_j_HF", "jecUncHF", DifferentPipeline) jet_es_variations += create_systematic_variations("CMS_scale_j_HF_Run2018", "jecUncHFYear", DifferentPipeline) jet_es_variations += create_systematic_variations("CMS_scale_j_RelativeBal", "jecUncRelativeBal", DifferentPipeline) jet_es_variations += create_systematic_variations("CMS_scale_j_RelativeSample_Run2018", "jecUncRelativeSampleYear", DifferentPipeline) # B-tagging btag_eff_variations = create_systematic_variations("CMS_htt_eff_b_Run2018", "btagEff", DifferentPipeline) mistag_eff_variations = create_systematic_variations("CMS_htt_mistag_b_Run2018", "btagMistag", DifferentPipeline) ## Variations common for all groups (most of the mc-related systematics) common_mc_variations = btag_eff_variations + mistag_eff_variations + jet_es_variations # MET energy scale. Note: only those variations for non-resonant processes are used in the stat. inference met_unclustered_variations = create_systematic_variations("CMS_scale_met_unclustered", "metUnclusteredEn", DifferentPipeline) # Recoil correction unc, for resonant processes recoil_variations = create_systematic_variations( "CMS_htt_boson_reso_met_Run2018", "metRecoilResolution", DifferentPipeline) recoil_variations += create_systematic_variations( "CMS_htt_boson_scale_met_Run2018", "metRecoilResponse", DifferentPipeline) # Tau energy scale (general, MC-specific & EMB-specific), it is mt, et & tt specific tau_es_variations = {} for unctype in ["", "_mc", "_emb"]: tau_es_variations[unctype] = create_systematic_variations("CMS_scale%s_t_3prong_Run%s"% (unctype, args.era), "tauEsThreeProng", DifferentPipeline) tau_es_variations[unctype] += create_systematic_variations("CMS_scale%s_t_3prong1pizero_Run%s"% (unctype, args.era), "tauEsThreeProngOnePiZero", DifferentPipeline) tau_es_variations[unctype] += create_systematic_variations("CMS_scale%s_t_1prong_Run%s"% (unctype, args.era), "tauEsOneProng", DifferentPipeline) tau_es_variations[unctype] += create_systematic_variations("CMS_scale%s_t_1prong1pizero_Run%s"% (unctype, args.era), "tauEsOneProngOnePiZero", DifferentPipeline) # Tau ID variations (general, MC-specific & EMB specific), it is mt, et & tt specific # in et and mt one nuisance per pT bin, in tt per dm tau_id_variations = {} for ch in ["et" , "mt", "tt"]: tau_id_variations[ch] = {} for unctype in ["", "_emb"]: tau_id_variations[ch][unctype] = [] if ch in ["et", "mt"]: pt = [30, 35, 40, 500, 1000, "inf"] for i, ptbin in enumerate(pt[:-1]): bindown = ptbin binup = pt[i+1] if binup == "inf": tau_id_variations[ch][unctype].append( ReplaceWeight("CMS_eff{unctype}_t_{bindown}-{binup}_Run{era}".format(unctype=unctype,bindown=bindown, binup=binup, era=args.era), "taubyIsoIdWeight", Weight("(((pt_2 >= {bindown})*tauIDScaleFactorWeightUp_tight_DeepTau2017v2p1VSjet_2)+((pt_2 < {bindown})*tauIDScaleFactorWeight_tight_DeepTau2017v2p1VSjet_2))".format(bindown=bindown), "taubyIsoIdWeight"), "Up")) tau_id_variations[ch][unctype].append( ReplaceWeight("CMS_eff{unctype}_t_{bindown}-{binup}_Run{era}".format(unctype=unctype, bindown=bindown, binup=binup, era=args.era), "taubyIsoIdWeight", Weight("(((pt_2 >= {bindown})*tauIDScaleFactorWeightDown_tight_DeepTau2017v2p1VSjet_2)+((pt_2 < {bindown})*tauIDScaleFactorWeight_tight_DeepTau2017v2p1VSjet_2))".format(bindown=bindown),"taubyIsoIdWeight"), "Down")) else: tau_id_variations[ch][unctype].append( ReplaceWeight("CMS_eff{unctype}_t_{bindown}-{binup}_Run{era}".format(unctype=unctype, bindown=bindown, binup=binup, era=args.era), "taubyIsoIdWeight", Weight("(((pt_2 >= {bindown} && pt_2 <= {binup})*tauIDScaleFactorWeightUp_tight_DeepTau2017v2p1VSjet_2)+((pt_2 < {bindown} || pt_2 > {binup})*tauIDScaleFactorWeight_tight_DeepTau2017v2p1VSjet_2))".format(bindown=bindown, binup=binup),"taubyIsoIdWeight"), "Up")) tau_id_variations[ch][unctype].append( ReplaceWeight("CMS_eff{unctype}_t_{bindown}-{binup}_Run{era}".format(unctype=unctype, bindown=bindown, binup=binup, era=args.era), "taubyIsoIdWeight", Weight("(((pt_2 >= {bindown} && pt_2 <= {binup})*tauIDScaleFactorWeightDown_tight_DeepTau2017v2p1VSjet_2)+((pt_2 < {bindown} || pt_2 > {binup})*tauIDScaleFactorWeight_tight_DeepTau2017v2p1VSjet_2))".format(bindown=bindown, binup=binup),"taubyIsoIdWeight"), "Down")) if ch in ["tt"]: for decaymode in [0, 1, 10, 11]: tau_id_variations[ch][unctype].append( ReplaceWeight("CMS_eff{unctype}_t_dm{dm}_Run{era}".format(unctype=unctype, dm=decaymode, era=args.era), "taubyIsoIdWeight", Weight("(((decayMode_1=={dm})*tauIDScaleFactorWeightUp_tight_DeepTau2017v2p1VSjet_1)+((decayMode_1!={dm})*tauIDScaleFactorWeight_tight_DeepTau2017v2p1VSjet_1)*((decayMode_2=={dm})*tauIDScaleFactorWeightUp_tight_DeepTau2017v2p1VSjet_2)+((decayMode_2!={dm})*tauIDScaleFactorWeight_tight_DeepTau2017v2p1VSjet_2))".format(dm=decaymode), "taubyIsoIdWeight"), "Up")) tau_id_variations[ch][unctype].append( ReplaceWeight("CMS_eff{unctype}_t_dm{dm}_Run{era}".format(unctype=unctype, dm=decaymode, era=args.era), "taubyIsoIdWeight", Weight("(((decayMode_1=={dm})*tauIDScaleFactorWeightDown_tight_DeepTau2017v2p1VSjet_1)+((decayMode_1!={dm})*tauIDScaleFactorWeight_tight_DeepTau2017v2p1VSjet_1)*((decayMode_2=={dm})*tauIDScaleFactorWeightDown_tight_DeepTau2017v2p1VSjet_2)+((decayMode_2!={dm})*tauIDScaleFactorWeight_tight_DeepTau2017v2p1VSjet_2))".format(dm=decaymode), "taubyIsoIdWeight"), "Down")) # Ele energy scale & smear uncertainties (MC-specific), it is et & em specific ele_es_variations = create_systematic_variations("CMS_scale_mc_e", "eleScale", DifferentPipeline) ele_es_variations += create_systematic_variations("CMS_reso_mc_e", "eleSmear", DifferentPipeline) # Ele energy scale (EMB-specific), it is et & em specific ele_es_emb_variations = create_systematic_variations("CMS_scale_emb_e", "eleEs", DifferentPipeline) # Z pt reweighting zpt_variations = create_systematic_variations("CMS_htt_dyShape_Run2018", "zPtReweightWeight", SquareAndRemoveWeight) # top pt reweighting top_pt_variations = create_systematic_variations("CMS_htt_ttbarShape", "topPtReweightWeight", SquareAndRemoveWeight) # jet to tau fake efficiency # Needs to be introduced if one wants to create shapes for QCD # Applied to lt,tt channels for processes ZJ, TTJ, VVJ, W # value of weight: Up max(1-pt_2*0.002, 0.6) # Down min(1+pt_2*0.002, 1.4) # EMB charged track correction uncertainty (DM-dependent) decayMode_variations = [] decayMode_variations.append(ReplaceWeight("CMS_3ProngEff_Run2018".format(args.era), "decayMode_SF", Weight("embeddedDecayModeWeight_effUp_pi0Nom", "decayMode_SF"), "Up")) decayMode_variations.append(ReplaceWeight("CMS_3ProngEff_Run2018".format(args.era), "decayMode_SF", Weight("embeddedDecayModeWeight_effDown_pi0Nom", "decayMode_SF"), "Down")) decayMode_variations.append(ReplaceWeight("CMS_1ProngPi0Eff_Run2018".format(args.era), "decayMode_SF", Weight("embeddedDecayModeWeight_effNom_pi0Up", "decayMode_SF"), "Up")) decayMode_variations.append(ReplaceWeight("CMS_1ProngPi0Eff_Run2018".format(args.era), "decayMode_SF", Weight("embeddedDecayModeWeight_effNom_pi0Down", "decayMode_SF"), "Down")) # QCD for em qcd_variations = [] qcd_variations.append(ReplaceWeight("CMS_htt_qcd_0jet_rate_Run2018", "qcd_weight", Weight("em_qcd_osss_0jet_rateup_Weight", "qcd_weight"), "Up")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_0jet_rate_Run2018", "qcd_weight", Weight("em_qcd_osss_0jet_ratedown_Weight", "qcd_weight"), "Down")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_0jet_shape_Run2018", "qcd_weight", Weight("em_qcd_osss_0jet_shapeup_Weight", "qcd_weight"), "Up")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_0jet_shape_Run2018", "qcd_weight", Weight("em_qcd_osss_0jet_shapedown_Weight", "qcd_weight"), "Down")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_1jet_rate_Run2018", "qcd_weight", Weight("em_qcd_osss_1jet_rateup_Weight", "qcd_weight"), "Up")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_1jet_rate_Run2018", "qcd_weight", Weight("em_qcd_osss_1jet_ratedown_Weight", "qcd_weight"), "Down")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_1jet_shape_Run2018", "qcd_weight", Weight("em_qcd_osss_1jet_shapeup_Weight", "qcd_weight"), "Up")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_1jet_shape_Run2018", "qcd_weight", Weight("em_qcd_osss_1jet_shapedown_Weight", "qcd_weight"), "Down")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_iso_Run2018", "qcd_weight", Weight("em_qcd_extrap_up_Weight", "qcd_weight"), "Up")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_iso_Run2018", "qcd_weight", Weight("em_qcd_extrap_down_Weight", "qcd_weight"), "Down")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_iso", "qcd_weight", Weight("em_qcd_extrap_up_Weight", "qcd_weight"), "Up")) qcd_variations.append(ReplaceWeight("CMS_htt_qcd_iso", "qcd_weight", Weight("em_qcd_extrap_down_Weight", "qcd_weight"), "Down")) # Gluon-fusion WG1 uncertainty scheme ggh_variations = [] for unc in [ "THU_ggH_Mig01", "THU_ggH_Mig12", "THU_ggH_Mu", "THU_ggH_PT120", "THU_ggH_PT60", "THU_ggH_Res", "THU_ggH_VBF2j", "THU_ggH_VBF3j", "THU_ggH_qmtop" ]: ggh_variations.append(AddWeight(unc, "{}_weight".format(unc), Weight("({})".format(unc), "{}_weight".format(unc)), "Up")) ggh_variations.append(AddWeight(unc, "{}_weight".format(unc), Weight("(2.0-{})".format(unc), "{}_weight".format(unc)), "Down")) # ZL fakes energy scale fakelep_dict = {"et" : "Ele", "mt" : "Mu"} lep_fake_es_variations = {} for ch in ["mt", "et"]: lep_fake_es_variations[ch] = create_systematic_variations("CMS_ZLShape_%s_1prong_Run2018"%ch, "tau%sFakeEsOneProng"%fakelep_dict[ch], DifferentPipeline) lep_fake_es_variations[ch] += create_systematic_variations("CMS_ZLShape_%s_1prong1pizero_Run2018"%ch, "tau%sFakeEsOneProngPiZeros"%fakelep_dict[ch], DifferentPipeline) # Lepton trigger efficiency; the same values for (MC & EMB) and (mt & et) lep_trigger_eff_variations = {} for ch in ["mt", "et"]: lep_trigger_eff_variations[ch] = {} thresh_dict = {"mt": 25., "et": 28.} for unctype in ["", "_emb"]: lep_trigger_eff_variations[ch][unctype] = [] lep_trigger_eff_variations[ch][unctype].append(AddWeight("CMS_eff_trigger%s_%s_Run2018"%(unctype, ch), "trg_%s_eff_weight"%ch, Weight("(1.0*(pt_1<={0})+1.02*(pt_1>{0}))".format(thresh_dict[ch]), "trg_%s_eff_weight"%ch), "Up")) lep_trigger_eff_variations[ch][unctype].append(AddWeight("CMS_eff_trigger%s_%s_Run2018"%(unctype, ch), "trg_%s_eff_weight"%ch, Weight("(1.0*(pt_1<={0})+0.98*(pt_1>{0}))".format(thresh_dict[ch]), "trg_%s_eff_weight"%ch), "Down")) lep_trigger_eff_variations[ch][unctype].append(AddWeight("CMS_eff_xtrigger%s_%s_Run2018"%(unctype, ch), "xtrg_%s_eff_weight"%ch, Weight("(1.054*(pt_1<={0})+1.0*(pt_1>{0}))".format(thresh_dict[ch]), "xtrg_%s_eff_weight"%ch), "Up")) lep_trigger_eff_variations[ch][unctype].append(AddWeight("CMS_eff_xtrigger%s_%s_Run2018"%(unctype, ch), "xtrg_%s_eff_weight"%ch, Weight("(0.946*(pt_1<={0})+1.0*(pt_1>{0}))".format(thresh_dict[ch]), "xtrg_%s_eff_weight"%ch), "Down")) # Fake factor uncertainties fake_factor_variations = {} for ch in ["mt", "et", "tt"]: fake_factor_variations[ch] = [] if ch in ["mt", "et"]: for systematic_shift in [ "ff_qcd{ch}_syst_Run2018{shift}", "ff_qcd_dm0_njet0{ch}_stat_Run2018{shift}", "ff_qcd_dm0_njet1{ch}_stat_Run2018{shift}", "ff_w_syst_Run2018{shift}", "ff_w_dm0_njet0{ch}_stat_Run2018{shift}", "ff_w_dm0_njet1{ch}_stat_Run2018{shift}", "ff_tt_syst_Run2018{shift}", "ff_tt_dm0_njet0_stat_Run2018{shift}", "ff_tt_dm0_njet1_stat_Run2018{shift}", ]: for shift_direction in ["Up", "Down"]: fake_factor_variations[ch].append(ReplaceWeight("CMS_%s"%(systematic_shift.format(ch="_"+ch, shift="").replace("_dm0", "")), "fake_factor", Weight("ff2_{syst}".format(syst=systematic_shift.format(ch="", shift="_%s" %shift_direction.lower()).replace("_Run2018", "")), "fake_factor"), shift_direction)) elif ch == "tt": for systematic_shift in [ "ff_qcd{ch}_syst_Run2018{shift}", "ff_qcd_dm0_njet0{ch}_stat_Run2018{shift}", "ff_qcd_dm0_njet1{ch}_stat_Run2018{shift}", "ff_w{ch}_syst_Run2018{shift}", "ff_tt{ch}_syst_Run2018{shift}", "ff_w_frac{ch}_syst_Run2018{shift}", "ff_tt_frac{ch}_syst_Run2018{shift}" ]: for shift_direction in ["Up", "Down"]: fake_factor_variations[ch].append(ReplaceWeight("CMS_%s" % (systematic_shift.format(ch="_"+ch, shift="").replace("_dm0", "")), "fake_factor", Weight("(0.5*ff1_{syst}*(byTightDeepTau2017v2p1VSjet_1<0.5)+0.5*ff2_{syst}*(byTightDeepTau2017v2p1VSjet_2<0.5))".format(syst=systematic_shift.format(ch="", shift="_%s" % shift_direction.lower()).replace("_Run2018", "")), "fake_factor"), shift_direction)) ## Group nicks mc_nicks = ["ZL", "TTL", "VVL"] + signal_nicks # to be extended with 'W' in em boson_mc_nicks = ["ZL"] + signal_nicks # to be extended with 'W' in em ## Add variations to systematics for ch in args.channels: channel_mc_nicks = mc_nicks + ["W"] if ch == "em" else mc_nicks channel_boson_mc_nicks = boson_mc_nicks + ["W"] if ch == "em" else boson_mc_nicks if args.shape_group != "backgrounds": channel_mc_nicks = signal_nicks channel_boson_mc_nicks = signal_nicks channel_mc_common_variations = common_mc_variations if ch in ["et", "em"]: channel_mc_common_variations += ele_es_variations if ch in ["et", "mt", "tt"]: channel_mc_common_variations += tau_es_variations[""] + tau_es_variations["_mc"] + tau_id_variations[ch][""] if ch in ["et", "mt"]: channel_mc_common_variations += lep_trigger_eff_variations[ch][""] # variations common accross all shape groups for variation in channel_mc_common_variations: for process_nick in channel_mc_nicks: systematics.add_systematic_variation(variation=variation, process=processes[ch][process_nick], channel=channel_dict[ch], era=era) for variation in recoil_variations: for process_nick in channel_boson_mc_nicks: systematics.add_systematic_variation(variation=variation, process=processes[ch][process_nick], channel=channel_dict[ch], era=era) # variations relevant for ggH signals in 'sm_signals' shape group if args.shape_group == "sm_signals": for variation in ggh_variations: for process_nick in [nick for nick in signal_nicks if "ggH" in nick and "HWW" not in nick and "ggH_" not in nick]: systematics.add_systematic_variation(variation=variation, process=processes[ch][process_nick], channel=channel_dict[ch], era=era) # variations only relevant for the 'background' shape group if args.shape_group == "backgrounds": for variation in top_pt_variations: # TODO: Needs to be adapted if one wants to use DY MC or QCD estimation(lt,tt: TTT, TTL, TTJ, em: TTT, TTL) systematics.add_systematic_variation(variation=variation, process=processes[ch]["TTL"], channel=channel_dict[ch], era=era) for variation in met_unclustered_variations: for process_nick in ["TTL", "VVL"]: systematics.add_systematic_variation(variation=variation, process=processes[ch][process_nick], channel=channel_dict[ch], era=era) zl_variations = zpt_variations if ch in ["et", "mt"]: zl_variations += lep_fake_es_variations[ch] # TODO: maybe prepare variations for shape production with DY MC and QCD estimation, then applied to ZTT, ZL and ZJ for lt channels and ZTT and ZL for em channel for variation in zl_variations: systematics.add_systematic_variation(variation=variation, process=processes[ch]["ZL"], channel=channel_dict[ch], era=era) if ch == "em": for variation in qcd_variations: systematics.add_systematic_variation(variation=variation ,process=processes[ch]["QCD"], channel=channel_dict[ch], era=era) if ch in ["mt","et", "tt"]: ff_variations = fake_factor_variations[ch] + tau_es_variations[""] + tau_es_variations["_mc"] + tau_es_variations["_emb"] for variation in ff_variations: systematics.add_systematic_variation(variation=variation, process=processes[ch]["FAKES"], channel=channel_dict[ch], era=era) emb_variations = [] if ch in ["mt","et", "tt"]: emb_variations += tau_es_variations[""] + tau_es_variations["_emb"] + tau_id_variations[ch]["_emb"] + decayMode_variations if ch in ["mt", "et"]: emb_variations += lep_trigger_eff_variations[ch]["_emb"] if ch in ["et", "em"]: emb_variations += ele_es_emb_variations for variation in emb_variations: systematics.add_systematic_variation(variation=variation, process=processes[ch]["EMB"], channel=channel_dict[ch], era=era) # Produce histograms logger.info("Start producing shapes.") systematics.produce() logger.info("Done producing shapes.")
def main(args): # Write arparse arguments to YAML config logger.debug("Write argparse arguments to YAML config.") output_config = {} output_config["base_path"] = args.base_path output_config["friend_paths"] = args.friend_paths output_config["output_path"] = args.output_path output_config["output_filename"] = args.output_filename output_config["tree_path"] = args.tree_path output_config["event_branch"] = args.event_branch output_config["training_weight_branch"] = args.training_weight_branch # Define era if "2016" in args.era: from shape_producer.estimation_methods_2016 import DataEstimation, ggHEstimation, qqHEstimation, ZTTEstimation, ZLEstimation, ZJEstimation, WEstimation, TTTEstimation, TTJEstimation, ZTTEmbeddedEstimation, TTLEstimation, EWKZEstimation, VVLEstimation, VVJEstimation, VVEstimation, VVTEstimation #QCDEstimation_SStoOS_MTETEM, QCDEstimationTT, EWKWpEstimation, EWKWmEstimation, , VHEstimation, HTTEstimation, from shape_producer.era import Run2016 era = Run2016(args.database) elif "2017" in args.era: from shape_producer.estimation_methods_2017 import DataEstimation, ZTTEstimation, ZJEstimation, ZLEstimation, TTLEstimation, TTJEstimation, TTTEstimation, VVTEstimation, VVJEstimation, VVLEstimation, WEstimation, ggHEstimation, qqHEstimation, EWKZEstimation, ZTTEmbeddedEstimation from shape_producer.era import Run2017 era = Run2017(args.database) elif "2018" in args.era: from shape_producer.estimation_methods_2018 import DataEstimation, ZTTEstimation, ZJEstimation, ZLEstimation, TTLEstimation, TTJEstimation, TTTEstimation, VVTEstimation, VVJEstimation, VVLEstimation, WEstimation, ggHEstimation, qqHEstimation, EWKZEstimation, ZTTEmbeddedEstimation from shape_producer.era import Run2018 era = Run2018(args.database) else: logger.fatal("Era {} is not implemented.".format(args.era)) raise Exception def estimationMethodAndClassMapGenerator(): ###### common processes classes_map = {"ggH": "ggh", "qqH": "qqh", "EWKZ": "misc"} estimationMethodList = [ ggHEstimation("ggH", era, args.base_path, channel), qqHEstimation("qqH", era, args.base_path, channel), EWKZEstimation(era, args.base_path, channel), VVLEstimation(era, args.base_path, channel), WEstimation(era, args.base_path, channel) ] ######## Check for emb vs MC if args.training_z_estimation_method == "emb": classes_map["EMB"] = "ztt" estimationMethodList.extend( [ZTTEmbeddedEstimation(era, args.base_path, channel)]) elif args.training_z_estimation_method == "mc": classes_map["ZTT"] = "ztt" estimationMethodList.extend([ ZTTEstimation(era, args.base_path, channel), TTTEstimation(era, args.base_path, channel), VVTEstimation(era, args.base_path, channel) ]) else: logger.fatal( "No valid training-z-estimation-method! Options are emb, mc. Argument was {}" .format(args.training_z_estimation_method)) raise Exception ##### TT* zl,zj processes estimationMethodList.extend([ TTLEstimation(era, args.base_path, channel), ZLEstimation(era, args.base_path, channel) ]) # less data-> less categories for tt if args.channel == "tt": classes_map.update({ "TTT": "misc", "TTL": "misc", "TTJ": "misc", "ZL": "misc", "ZJ": "misc" }) estimationMethodList.extend([ ZJEstimation(era, args.base_path, channel), TTJEstimation(era, args.base_path, channel) ]) ## not TTJ,ZJ for em elif args.channel == "em": classes_map.update({"TTT": "tt", "TTL": "tt", "ZL": "misc"}) else: classes_map.update({ "TTT": "tt", "TTL": "tt", "TTJ": "tt", "ZL": "zll", "ZJ": "zll" }) estimationMethodList.extend([ ZJEstimation(era, args.base_path, channel), TTJEstimation(era, args.base_path, channel) ]) ###w: # estimation metho already included, just different mapping fror et and mt if args.channel in ["et", "mt"]: classes_map["W"] = "w" else: classes_map["W"] = "misc" ##### VV/[VVT,VVL,VVJ] split # VVL in common, VVT in "EMBvsMC" if args.channel == "em": classes_map.update({"VVT": "db", "VVL": "db"}) else: classes_map.update({"VVT": "misc", "VVL": "misc", "VVJ": "misc"}) estimationMethodList.extend([ VVJEstimation(era, args.base_path, channel), ]) ### QCD class if args.channel == "tt": classes_map["QCD"] = "noniso" else: classes_map["QCD"] = "ss" return ([classes_map, estimationMethodList]) channelDict = {} channelDict["2016"] = { "mt": MTSM2016(), "et": ETSM2016(), "tt": TTSM2016(), "em": EMSM2016() } channelDict["2017"] = { "mt": MTSM2017(), "et": ETSM2017(), "tt": TTSM2017(), "em": EMSM2017() } channelDict["2018"] = { "mt": MTSM2018(), "et": ETSM2018(), "tt": TTSM2018(), "em": EMSM2018() } channel = channelDict[args.era][args.channel] # Set up `processes` part of config output_config["processes"] = {} # Additional cuts additional_cuts = Cuts() logger.warning("Use additional cuts for mt: %s", additional_cuts.expand()) classes_map, estimationMethodList = estimationMethodAndClassMapGenerator() ##MC+/Embedding Processes for estimation in estimationMethodList: output_config["processes"][estimation.name] = { "files": [ str(f).replace(args.base_path.rstrip("/") + "/", "") for f in estimation.get_files() ], "cut_string": (estimation.get_cuts() + channel.cuts + additional_cuts).expand(), "weight_string": estimation.get_weights().extract(), "class": classes_map[estimation.name] } ### # Same sign selection for data-driven QCD estimation = DataEstimation(era, args.base_path, channel) estimation.name = "QCD" channel_qcd = copy.deepcopy(channel) if args.channel != "tt": ## os= opposite sign channel_qcd.cuts.get("os").invert() # Same sign selection for data-driven QCD else: channel_qcd.cuts.remove("tau_2_iso") channel_qcd.cuts.add( Cut("byTightIsolationMVArun2017v2DBoldDMwLT2017_2<0.5", "tau_2_iso")) channel_qcd.cuts.add( Cut("byLooseIsolationMVArun2017v2DBoldDMwLT2017_2>0.5", "tau_2_iso_loose")) output_config["processes"][estimation.name] = { "files": [ str(f).replace(args.base_path.rstrip("/") + "/", "") for f in estimation.get_files() ], "cut_string": (estimation.get_cuts() + channel_qcd.cuts + additional_cuts).expand(), "weight_string": estimation.get_weights().extract(), "class": classes_map[estimation.name] } ##################################### # Write output config logger.info("Write config to file: {}".format(args.output_config)) yaml.dump(output_config, open(args.output_config, 'w'), default_flow_style=False)
def main(args): # Container for all distributions to be drawn logger.info("Set up shape variations.") systematics = Systematics( "{}_shapes.root".format(args.tag), num_threads=args.num_threads, skip_systematic_variations=args.skip_systematic_variations) # Era selection if "2018" in args.era: from shape_producer.estimation_methods_2018 import DataEstimation, ZTTEstimation, ZTTEmbeddedEstimation, ZLEstimation, ZJEstimation, TTLEstimation, TTJEstimation, TTTEstimation, VVLEstimation, VVTEstimation, VVJEstimation, WEstimation, ggHEstimation, ggHEstimation_0J, ggHEstimation_1J_PTH_0_60, ggHEstimation_1J_PTH_60_120, ggHEstimation_1J_PTH_120_200, ggHEstimation_1J_PTH_GT200, ggHEstimation_GE2J_PTH_0_60, ggHEstimation_GE2J_PTH_60_120, ggHEstimation_GE2J_PTH_120_200, ggHEstimation_GE2J_PTH_GT200, ggHEstimation_VBFTOPO_JET3, ggHEstimation_VBFTOPO_JET3VETO, qqHEstimation, qqHEstimation_VBFTOPO_JET3VETO, qqHEstimation_VBFTOPO_JET3, qqHEstimation_REST, qqHEstimation_VH2JET, qqHEstimation_PTJET1_GT200, VHEstimation, WHEstimation, ZHEstimation, ttHEstimation, QCDEstimation_ABCD_TT_ISO2, QCDEstimation_SStoOS_MTETEM, FakeEstimationLT, NewFakeEstimationLT, FakeEstimationTT, NewFakeEstimationTT from shape_producer.era import Run2018 era = Run2018(args.datasets) else: logger.critical("Era {} is not implemented.".format(args.era)) raise Exception # Channels and processes # yapf: disable directory = args.directory et_friend_directory = []#args.et_friend_directory em_friend_directory = []#args.em_friend_directory mt_friend_directory = []#args.mt_friend_directory tt_friend_directory = []#args.tt_friend_directory ff_friend_directory = []#args.fake_factor_friend_directory mt = MTSM2018() mt_processes = { "data" : Process("data_obs", DataEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "EMB" : Process("EMB", ZTTEmbeddedEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "ZJ" : Process("ZJ", ZJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "TTJ" : Process("TTJ", TTJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "VVJ" : Process("VVJ", VVJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "W" : Process("W", WEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "ggH" : Process("ggH125", ggHEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "qqH" : Process("qqH125", qqHEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_0J" : Process("ggH_0J125", ggHEstimation_0J (era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_1J_PTH_0_60" : Process("ggH_1J_PTH_0_60125", ggHEstimation_1J_PTH_0_60 (era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_1J_PTH_60_120" : Process("ggH_1J_PTH_60_120125", ggHEstimation_1J_PTH_60_120 (era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_1J_PTH_120_200" : Process("ggH_1J_PTH_120_200125", ggHEstimation_1J_PTH_120_200 (era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_1J_PTH_GT200" : Process("ggH_1J_PTH_GT200125", ggHEstimation_1J_PTH_GT200 (era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_GE2J_PTH_0_60" : Process("ggH_GE2J_PTH_0_60125", ggHEstimation_GE2J_PTH_0_60 (era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_GE2J_PTH_60_120" : Process("ggH_GE2J_PTH_60_120125", ggHEstimation_GE2J_PTH_60_120 (era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_GE2J_PTH_120_200" : Process("ggH_GE2J_PTH_120_200125", ggHEstimation_GE2J_PTH_120_200(era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_GE2J_PTH_GT200" : Process("ggH_GE2J_PTH_GT200125", ggHEstimation_GE2J_PTH_GT200 (era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_VBFTOPO_JET3VETO" : Process("ggH_VBFTOPO_JET3VETO125", ggHEstimation_VBFTOPO_JET3VETO(era, directory, mt, friend_directory=mt_friend_directory)), # "ggH_VBFTOPO_JET3" : Process("ggH_VBFTOPO_JET3125", ggHEstimation_VBFTOPO_JET3 (era, directory, mt, friend_directory=mt_friend_directory)), # "qqH_VBFTOPO_JET3VETO" : Process("qqH_VBFTOPO_JET3VETO125", qqHEstimation_VBFTOPO_JET3VETO(era, directory, mt, friend_directory=mt_friend_directory)), # "qqH_VBFTOPO_JET3" : Process("qqH_VBFTOPO_JET3125", qqHEstimation_VBFTOPO_JET3 (era, directory, mt, friend_directory=mt_friend_directory)), # "qqH_REST" : Process("qqH_REST125", qqHEstimation_REST (era, directory, mt, friend_directory=mt_friend_directory)), # "qqH_VH2JET" : Process("qqH_VH2JET125", qqHEstimation_VH2JET (era, directory, mt, friend_directory=mt_friend_directory)), # "qqH_PTJET1_GT200" : Process("qqH_PTJET1_GT200125", qqHEstimation_PTJET1_GT200 (era, directory, mt, friend_directory=mt_friend_directory)), # "VH" : Process("VH125", VHEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "WH" : Process("WH125", WHEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "ZH" : Process("ZH125", ZHEstimation (era, directory, mt, friend_directory=mt_friend_directory)), # "ttH" : Process("ttH125", ttHEstimation (era, directory, mt, friend_directory=mt_friend_directory)), } # mt_processes["FAKES"] = Process("jetFakes", NewFakeEstimationLT(era, directory, mt, [mt_processes[process] for process in ["EMB", "ZL", "TTL", "VVL"]], mt_processes["data"], friend_directory=[mt_friend_directory, ff_friend_directory])) #mt_fakes_for_uncs=Process("jetFakes", FakeEstimationLT(era, directory, mt, friend_directory=[mt_friend_directory, ff_friend_directory])) mt_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, mt, [mt_processes[process] for process in ["ZTT", "ZL", "ZJ", "TTL","TTT","TTJ", "VVT", "VVJ", "VVL","W"]], mt_processes["data"], friend_directory=mt_friend_directory, extrapolation_factor=1.1)) mt_processes["QCDEMB"] = Process("QCDEMB", QCDEstimation_SStoOS_MTETEM(era, directory, mt, [mt_processes[process] for process in ["EMB", "ZL", "ZJ", "TTL", "TTJ", "VVJ", "VVL","W"]], mt_processes["data"], friend_directory=mt_friend_directory, extrapolation_factor=1.1)) et = ETSM2018() et_processes = { "data" : Process("data_obs", DataEstimation (era, directory, et, friend_directory=et_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, et, friend_directory=et_friend_directory)), "EMB" : Process("EMB", ZTTEmbeddedEstimation (era, directory, et, friend_directory=et_friend_directory)), "ZJ" : Process("ZJ", ZJEstimation (era, directory, et, friend_directory=et_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, et, friend_directory=et_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, et, friend_directory=et_friend_directory)), "TTJ" : Process("TTJ", TTJEstimation (era, directory, et, friend_directory=et_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, et, friend_directory=et_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, et, friend_directory=et_friend_directory)), "VVJ" : Process("VVJ", VVJEstimation (era, directory, et, friend_directory=et_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, et, friend_directory=et_friend_directory)), "W" : Process("W", WEstimation (era, directory, et, friend_directory=et_friend_directory)), "ggH" : Process("ggH125", ggHEstimation (era, directory, et, friend_directory=et_friend_directory)), "qqH" : Process("qqH125", qqHEstimation (era, directory, et, friend_directory=et_friend_directory)), # "ggH_0J" : Process("ggH_0J125", ggHEstimation_0J (era, directory, et, friend_directory=et_friend_directory)), # "ggH_1J_PTH_0_60" : Process("ggH_1J_PTH_0_60125", ggHEstimation_1J_PTH_0_60 (era, directory, et, friend_directory=et_friend_directory)), # "ggH_1J_PTH_60_120" : Process("ggH_1J_PTH_60_120125", ggHEstimation_1J_PTH_60_120 (era, directory, et, friend_directory=et_friend_directory)), # "ggH_1J_PTH_120_200" : Process("ggH_1J_PTH_120_200125", ggHEstimation_1J_PTH_120_200 (era, directory, et, friend_directory=et_friend_directory)), # "ggH_1J_PTH_GT200" : Process("ggH_1J_PTH_GT200125", ggHEstimation_1J_PTH_GT200 (era, directory, et, friend_directory=et_friend_directory)), # "ggH_GE2J_PTH_0_60" : Process("ggH_GE2J_PTH_0_60125", ggHEstimation_GE2J_PTH_0_60 (era, directory, et, friend_directory=et_friend_directory)), # "ggH_GE2J_PTH_60_120" : Process("ggH_GE2J_PTH_60_120125", ggHEstimation_GE2J_PTH_60_120 (era, directory, et, friend_directory=et_friend_directory)), # "ggH_GE2J_PTH_120_200" : Process("ggH_GE2J_PTH_120_200125", ggHEstimation_GE2J_PTH_120_200(era, directory, et, friend_directory=et_friend_directory)), # "ggH_GE2J_PTH_GT200" : Process("ggH_GE2J_PTH_GT200125", ggHEstimation_GE2J_PTH_GT200 (era, directory, et, friend_directory=et_friend_directory)), # "ggH_VBFTOPO_JET3VETO" : Process("ggH_VBFTOPO_JET3VETO125", ggHEstimation_VBFTOPO_JET3VETO(era, directory, et, friend_directory=et_friend_directory)), # "ggH_VBFTOPO_JET3" : Process("ggH_VBFTOPO_JET3125", ggHEstimation_VBFTOPO_JET3 (era, directory, et, friend_directory=et_friend_directory)), # "qqH_VBFTOPO_JET3VETO" : Process("qqH_VBFTOPO_JET3VETO125", qqHEstimation_VBFTOPO_JET3VETO(era, directory, et, friend_directory=et_friend_directory)), # "qqH_VBFTOPO_JET3" : Process("qqH_VBFTOPO_JET3125", qqHEstimation_VBFTOPO_JET3 (era, directory, et, friend_directory=et_friend_directory)), # "qqH_REST" : Process("qqH_REST125", qqHEstimation_REST (era, directory, et, friend_directory=et_friend_directory)), # "qqH_VH2JET" : Process("qqH_VH2JET125", qqHEstimation_VH2JET (era, directory, et, friend_directory=et_friend_directory)), # "qqH_PTJET1_GT200" : Process("qqH_PTJET1_GT200125", qqHEstimation_PTJET1_GT200 (era, directory, et, friend_directory=et_friend_directory)), # "VH" : Process("VH125", VHEstimation (era, directory, et, friend_directory=et_friend_directory)), # "WH" : Process("WH125", WHEstimation (era, directory, et, friend_directory=et_friend_directory)), # "ZH" : Process("ZH125", ZHEstimation (era, directory, et, friend_directory=et_friend_directory)), # "ttH" : Process("ttH125", ttHEstimation (era, directory, et, friend_directory=et_friend_directory)), } # et_processes["FAKES"] = Process("jetFakes", NewFakeEstimationLT(era, directory, et, [et_processes[process] for process in ["EMB", "ZL", "TTL", "VVL"]], et_processes["data"], friend_directory=[et_friend_directory, ff_friend_directory])) et_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, et, [et_processes[process] for process in ["ZTT", "ZL", "ZJ", "W", "TTT", "TTJ", "TTL", "VVT", "VVJ", "VVL"]], et_processes["data"], friend_directory=et_friend_directory, extrapolation_factor=1.1)) et_processes["QCDEMB"] = Process("QCDEMB", QCDEstimation_SStoOS_MTETEM(era, directory, et, [et_processes[process] for process in ["EMB", "ZL", "ZJ", "W", "TTJ", "TTL", "VVJ", "VVL"]], et_processes["data"], friend_directory=et_friend_directory, extrapolation_factor=1.1)) tt = TTSM2018() tt_processes = { "data" : Process("data_obs", DataEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "EMB" : Process("EMB", ZTTEmbeddedEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "ZJ" : Process("ZJ", ZJEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "TTJ" : Process("TTJ", TTJEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "VVJ" : Process("VVJ", VVJEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "W" : Process("W", WEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "ggH" : Process("ggH125", ggHEstimation (era, directory, tt, friend_directory=tt_friend_directory)), "qqH" : Process("qqH125", qqHEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_0J" : Process("ggH_0J125", ggHEstimation_0J (era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_1J_PTH_0_60" : Process("ggH_1J_PTH_0_60125", ggHEstimation_1J_PTH_0_60 (era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_1J_PTH_60_120" : Process("ggH_1J_PTH_60_120125", ggHEstimation_1J_PTH_60_120 (era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_1J_PTH_120_200" : Process("ggH_1J_PTH_120_200125", ggHEstimation_1J_PTH_120_200 (era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_1J_PTH_GT200" : Process("ggH_1J_PTH_GT200125", ggHEstimation_1J_PTH_GT200 (era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_GE2J_PTH_0_60" : Process("ggH_GE2J_PTH_0_60125", ggHEstimation_GE2J_PTH_0_60 (era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_GE2J_PTH_60_120" : Process("ggH_GE2J_PTH_60_120125", ggHEstimation_GE2J_PTH_60_120 (era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_GE2J_PTH_120_200" : Process("ggH_GE2J_PTH_120_200125", ggHEstimation_GE2J_PTH_120_200(era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_GE2J_PTH_GT200" : Process("ggH_GE2J_PTH_GT200125", ggHEstimation_GE2J_PTH_GT200 (era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_VBFTOPO_JET3VETO" : Process("ggH_VBFTOPO_JET3VETO125", ggHEstimation_VBFTOPO_JET3VETO(era, directory, tt, friend_directory=tt_friend_directory)), # "ggH_VBFTOPO_JET3" : Process("ggH_VBFTOPO_JET3125", ggHEstimation_VBFTOPO_JET3 (era, directory, tt, friend_directory=tt_friend_directory)), # "qqH_VBFTOPO_JET3VETO" : Process("qqH_VBFTOPO_JET3VETO125", qqHEstimation_VBFTOPO_JET3VETO(era, directory, tt, friend_directory=tt_friend_directory)), # "qqH_VBFTOPO_JET3" : Process("qqH_VBFTOPO_JET3125", qqHEstimation_VBFTOPO_JET3 (era, directory, tt, friend_directory=tt_friend_directory)), # "qqH_REST" : Process("qqH_REST125", qqHEstimation_REST (era, directory, tt, friend_directory=tt_friend_directory)), # "qqH_VH2JET" : Process("qqH_VH2JET125", qqHEstimation_VH2JET (era, directory, tt, friend_directory=tt_friend_directory)), # "qqH_PTJET1_GT200" : Process("qqH_PTJET1_GT200125", qqHEstimation_PTJET1_GT200 (era, directory, tt, friend_directory=tt_friend_directory)), # "VH" : Process("VH125", VHEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "WH" : Process("WH125", WHEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "ZH" : Process("ZH125", ZHEstimation (era, directory, tt, friend_directory=tt_friend_directory)), # "ttH" : Process("ttH125", ttHEstimation (era, directory, tt, friend_directory=tt_friend_directory)), } # tt_processes["FAKES"] = Process("jetFakes", NewFakeEstimationTT(era, directory, tt, [tt_processes[process] for process in ["EMB", "ZL", "TTL", "VVL"]], tt_processes["data"], friend_directory=[tt_friend_directory, ff_friend_directory])) tt_processes["QCD"] = Process("QCD", QCDEstimation_ABCD_TT_ISO2(era, directory, tt, [tt_processes[process] for process in ["ZTT", "ZL", "ZJ", "W", "TTT", "TTJ", "TTL", "VVT", "VVJ", "VVL"]], tt_processes["data"], friend_directory=tt_friend_directory)) tt_processes["QCDEMB"] = Process("QCDEMB", QCDEstimation_ABCD_TT_ISO2(era, directory, tt, [tt_processes[process] for process in ["EMB", "ZL", "ZJ", "W", "TTJ", "TTL", "VVJ", "VVL"]], tt_processes["data"], friend_directory=tt_friend_directory)) em = EMSM2018() em_processes = { "data" : Process("data_obs", DataEstimation (era, directory, em, friend_directory=em_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, em, friend_directory=em_friend_directory)), "EMB" : Process("EMB", ZTTEmbeddedEstimation (era, directory, em, friend_directory=em_friend_directory)), "ZJ" : Process("ZJ", ZJEstimation (era, directory, em, friend_directory=em_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, em, friend_directory=em_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, em, friend_directory=em_friend_directory)), "TTJ" : Process("TTJ", TTJEstimation (era, directory, em, friend_directory=em_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, em, friend_directory=em_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, em, friend_directory=em_friend_directory)), "VVJ" : Process("VVJ", VVJEstimation (era, directory, em, friend_directory=em_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, em, friend_directory=em_friend_directory)), "W" : Process("W", WEstimation (era, directory, em, friend_directory=em_friend_directory)), "ggH" : Process("ggH125", ggHEstimation (era, directory, em, friend_directory=em_friend_directory)), "qqH" : Process("qqH125", qqHEstimation (era, directory, em, friend_directory=em_friend_directory)) } em_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, em, [em_processes[process] for process in ["ZTT", "ZL", "ZJ", "W", "TTT", "TTJ", "TTL", "VVT", "VVJ", "VVL"]], em_processes["data"], friend_directory=em_friend_directory, extrapolation_factor=1.0, qcd_weight = Weight("em_qcd_extrap_up_Weight","qcd_weight"))) em_processes["QCDEMB"] = Process("QCDEMB", QCDEstimation_SStoOS_MTETEM(era, directory, em, [em_processes[process] for process in ["EMB", "ZL", "ZJ", "W", "TTJ", "TTL", "VVJ", "VVL"]], em_processes["data"], friend_directory=em_friend_directory, extrapolation_factor=1.0, qcd_weight = Weight("em_qcd_extrap_up_Weight","qcd_weight"))) # Variables and categories binning = yaml.load(open(args.binning)) et_categories = [] # Analysis shapes if "et" in args.channels: classes_et = ["ggh", "qqh", "ztt", "zll", "w", "tt", "ss", "misc"] for i, label in enumerate(classes_et): score = Variable( "et_max_score", VariableBinning(binning["analysis"]["et"][label])) et_categories.append( Category( label, et, Cuts( Cut("et_max_index=={index}".format(index=i), "exclusive_score")), variable=score)) if label in ["ggh", "qqh"]: expression = "" for i_e, e in enumerate(binning["stxs_stage1"]["lt"][label]): offset = (binning["analysis"]["et"][label][-1]-binning["analysis"]["et"][label][0])*i_e expression += "{STXSBIN}*(et_max_score+{OFFSET})".format(STXSBIN=e, OFFSET=offset) if not e is binning["stxs_stage1"]["lt"][label][-1]: expression += " + " score_unrolled = Variable( "et_max_score_unrolled", VariableBinning(binning["analysis"]["et"][label+"_unrolled"]), expression=expression) et_categories.append( Category( "{}_unrolled".format(label), et, Cuts(Cut("et_max_index=={index}".format(index=i), "exclusive_score"), Cut("et_max_score>{}".format(1.0/len(classes_et)), "protect_unrolling")), variable=score_unrolled)) # Goodness of fit shapes elif args.gof_channel == "et": score = Variable( args.gof_variable, VariableBinning(binning["gof"]["et"][args.gof_variable]["bins"]), expression=binning["gof"]["et"][args.gof_variable]["expression"]) if "cut" in binning["gof"]["et"][args.gof_variable].keys(): cuts=Cuts(Cut(binning["gof"]["et"][args.gof_variable]["cut"], "binning")) else: cuts=Cuts() et_categories.append( Category( args.gof_variable, et, cuts, variable=score)) mt_categories = [] # Analysis shapes if "mt" in args.channels: classes_mt = ["ggh", "qqh", "ztt", "zll", "w", "tt", "ss", "misc"] for i, label in enumerate(classes_mt): score = Variable( "mt_max_score", VariableBinning(binning["analysis"]["mt"][label])) mt_categories.append( Category( label, mt, Cuts( Cut("mt_max_index=={index}".format(index=i), "exclusive_score")), variable=score)) if label in ["ggh", "qqh"]: expression = "" for i_e, e in enumerate(binning["stxs_stage1"]["lt"][label]): offset = (binning["analysis"]["mt"][label][-1]-binning["analysis"]["mt"][label][0])*i_e expression += "{STXSBIN}*(mt_max_score+{OFFSET})".format(STXSBIN=e, OFFSET=offset) if not e is binning["stxs_stage1"]["lt"][label][-1]: expression += " + " score_unrolled = Variable( "mt_max_score_unrolled", VariableBinning(binning["analysis"]["mt"][label+"_unrolled"]), expression=expression) mt_categories.append( Category( "{}_unrolled".format(label), mt, Cuts(Cut("mt_max_index=={index}".format(index=i), "exclusive_score"), Cut("mt_max_score>{}".format(1.0/len(classes_mt)), "protect_unrolling")), variable=score_unrolled)) # Goodness of fit shapes elif args.gof_channel == "mt": score = Variable( args.gof_variable, VariableBinning(binning["gof"]["mt"][args.gof_variable]["bins"]), expression=binning["gof"]["mt"][args.gof_variable]["expression"]) if "cut" in binning["gof"]["mt"][args.gof_variable].keys(): cuts=Cuts(Cut(binning["gof"]["mt"][args.gof_variable]["cut"], "binning")) else: cuts=Cuts() mt_categories.append( Category( args.gof_variable, mt, cuts, variable=score)) tt_categories = [] # Analysis shapes if "tt" in args.channels: classes_tt = ["ggh", "qqh", "ztt", "noniso", "misc"] for i, label in enumerate(classes_tt): score = Variable( "tt_max_score", VariableBinning(binning["analysis"]["tt"][label])) tt_categories.append( Category( label, tt, Cuts( Cut("tt_max_index=={index}".format(index=i), "exclusive_score")), variable=score)) if label in ["ggh", "qqh"]: expression = "" for i_e, e in enumerate(binning["stxs_stage1"]["tt"][label]): offset = (binning["analysis"]["tt"][label][-1]-binning["analysis"]["tt"][label][0])*i_e expression += "{STXSBIN}*(tt_max_score+{OFFSET})".format(STXSBIN=e, OFFSET=offset) if not e is binning["stxs_stage1"]["tt"][label][-1]: expression += " + " score_unrolled = Variable( "tt_max_score_unrolled", VariableBinning(binning["analysis"]["tt"][label+"_unrolled"]), expression=expression) tt_categories.append( Category( "{}_unrolled".format(label), tt, Cuts(Cut("tt_max_index=={index}".format(index=i), "exclusive_score"), Cut("tt_max_score>{}".format(1.0/len(classes_tt)), "protect_unrolling")), variable=score_unrolled)) # Goodness of fit shapes elif args.gof_channel == "tt": score = Variable( args.gof_variable, VariableBinning(binning["gof"]["tt"][args.gof_variable]["bins"]), expression=binning["gof"]["tt"][args.gof_variable]["expression"]) if "cut" in binning["gof"]["tt"][args.gof_variable].keys(): cuts=Cuts(Cut(binning["gof"]["tt"][args.gof_variable]["cut"], "binning")) else: cuts=Cuts() tt_categories.append( Category( args.gof_variable, tt, cuts, variable=score)) em_categories = [] # Analysis shapes if "em" in args.channels: classes_em = ["ggh", "qqh", "ztt", "zll", "w", "tt", "ss", "misc"] for i, label in enumerate(classes_em): score = Variable( "em_max_score", VariableBinning(binning["analysis"]["em"][label])) em_categories.append( Category( label, em, Cuts( Cut("em_max_index=={index}".format(index=i), "exclusive_score")), variable=score)) if label in ["ggh", "qqh"]: expression = "" for i_e, e in enumerate(binning["stxs_stage1"]["lt"][label]): offsem = (binning["analysis"]["em"][label][-1]-binning["analysis"]["em"][label][0])*i_e expression += "{STXSBIN}*(em_max_score+{OFFSem})".format(STXSBIN=e, OFFSem=offsem) if not e is binning["stxs_stage1"]["lt"][label][-1]: expression += " + " score_unrolled = Variable( "em_max_score_unrolled", VariableBinning(binning["analysis"]["em"][label+"_unrolled"]), expression=expression) em_categories.append( Category( "{}_unrolled".format(label), em, Cuts(Cut("em_max_index=={index}".format(index=i), "exclusive_score"), Cut("em_max_score>{}".format(1.0/len(classes_em)), "protect_unrolling")), variable=score_unrolled)) # Goodness of fit shapes elif args.gof_channel == "em": score = Variable( args.gof_variable, VariableBinning(binning["gof"]["em"][args.gof_variable]["bins"]), expression=binning["gof"]["em"][args.gof_variable]["expression"]) if "cut" in binning["gof"]["em"][args.gof_variable].keys(): cuts=Cuts(Cut(binning["gof"]["em"][args.gof_variable]["cut"], "binning")) else: cuts=Cuts() em_categories.append( Category( args.gof_variable, em, cuts, variable=score)) # Nominal histograms if args.gof_channel == None: signal_nicks = [ "ggH", "qqH", "qqH_VBFTOPO_JET3VETO", "qqH_VBFTOPO_JET3", "qqH_REST", "qqH_PTJET1_GT200", "qqH_VH2JET", "ggH_0J", "ggH_1J_PTH_0_60", "ggH_1J_PTH_60_120", "ggH_1J_PTH_120_200", "ggH_1J_PTH_GT200", "ggH_GE2J_PTH_0_60", "ggH_GE2J_PTH_60_120", "ggH_GE2J_PTH_120_200", "ggH_GE2J_PTH_GT200", "ggH_VBFTOPO_JET3VETO", "ggH_VBFTOPO_JET3", "VH", "WH", "ZH", "ttH" ] else: signal_nicks = ["ggH", "qqH", "WH", "ZH", "ttH"] # yapf: enable if "et" in [args.gof_channel] + args.channels: for process, category in product(et_processes.values(), et_categories): systematics.add( Systematic(category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) if "mt" in [args.gof_channel] + args.channels: for process, category in product(mt_processes.values(), mt_categories): systematics.add( Systematic(category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) if "tt" in [args.gof_channel] + args.channels: for process, category in product(tt_processes.values(), tt_categories): systematics.add( Systematic(category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) if "em" in [args.gof_channel] + args.channels: for process, category in product(em_processes.values(), em_categories): systematics.add( Systematic(category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) # Produce histograms logger.info("Start producing shapes.") systematics.produce() logger.info("Done producing shapes.")
def main(args): # Container for all distributions to be drawn logger.info("Set up shape variations.") systematics = Systematics( "{}_shapes.root".format(args.tag), num_threads=args.num_threads, skip_systematic_variations=args.skip_systematic_variations) # Era selection if "2018" in args.era: from shape_producer.estimation_methods_2018 import DataEstimation, ZTTEstimation, ZTTEmbeddedEstimation, ZLEstimation, ZJEstimation, TTLEstimation, TTJEstimation, TTTEstimation, VVLEstimation, VVTEstimation, VVJEstimation, WEstimation, ggHEstimation, ggHEstimation_0J, ggHEstimation_1J_PTH_0_60, ggHEstimation_1J_PTH_60_120, ggHEstimation_1J_PTH_120_200, ggHEstimation_1J_PTH_GT200, ggHEstimation_GE2J_PTH_0_60, ggHEstimation_GE2J_PTH_60_120, ggHEstimation_GE2J_PTH_120_200, ggHEstimation_GE2J_PTH_GT200, ggHEstimation_VBFTOPO_JET3, ggHEstimation_VBFTOPO_JET3VETO, qqHEstimation, qqHEstimation_VBFTOPO_JET3VETO, qqHEstimation_VBFTOPO_JET3, qqHEstimation_REST, qqHEstimation_VH2JET, qqHEstimation_PTJET1_GT200, VHEstimation, WHEstimation, ZHEstimation, ttHEstimation, QCDEstimation_ABCD_TT_ISO2, QCDEstimation_SStoOS_MTETEM, FakeEstimationLT, NewFakeEstimationLT, FakeEstimationTT, NewFakeEstimationTT, DYJetsToLLEstimation, TTEstimation, VVEstimation from shape_producer.era import Run2018 era = Run2018(args.datasets) else: logger.critical("Era {} is not implemented.".format(args.era)) raise Exception wp_dict_mva = { "vvloose": "byVVLooseIsolationMVArun2017v2DBoldDMwLT2017_2", "vloose": "byVLooseIsolationMVArun2017v2DBoldDMwLT2017_2", "loose": "byLooseIsolationMVArun2017v2DBoldDMwLT2017_2", "medium": "byMediumIsolationMVArun2017v2DBoldDMwLT2017_2", "tight": "byTightIsolationMVArun2017v2DBoldDMwLT2017_2", "vtight": "byVTightIsolationMVArun2017v2DBoldDMwLT2017_2", "vvtight": "byVVTightIsolationMVArun2017v2DBoldDMwLT2017_2", "mm": "0<1", } wp_dict_deeptau = { "vvvloose": "byVVVLooseDeepTau2017v2p1VSjet_2", "vvloose": "byVVLooseDeepTau2017v2p1VSjet_2", "vloose": "byVLooseDeepTau2017v2p1VSjet_2", "loose": "byLooseDeepTau2017v2p1VSjet_2", "medium": "byMediumDeepTau2017v2p1VSjet_2", "tight": "byTightDeepTau2017v2p1VSjet_2", "vtight": "byVTightDeepTau2017v2p1VSjet_2", "vvtight": "byVVTightDeepTau2017v2p1VSjet_2", "mm": "0<1", } wp_dict = wp_dict_deeptau logger.info("Produce shapes for the %s working point of the MVA Tau ID", args.working_point) # Channels and processes # yapf: disable directory = args.directory et_friend_directory = []#args.et_friend_directory em_friend_directory = []#args.em_friend_directory mt_friend_directory = []#args.mt_friend_directory tt_friend_directory = []#args.tt_friend_directory ff_friend_directory = []#args.fake_factor_friend_directory mt = MTTauID2018() mt.cuts.add(Cut(wp_dict[args.working_point]+">0.5", "tau_iso")) # if args.gof_channel == "mt": # mt.cuts.remove("m_t") # mt.cuts.remove("dZeta") # mt.cuts.remove("absEta") mt_processes = { "data" : Process("data_obs", DataEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "EMB" : Process("EMB", ZTTEmbeddedEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "ZJ" : Process("ZJ", ZJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "TTJ" : Process("TTJ", TTJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "VVJ" : Process("VVJ", VVJEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, mt, friend_directory=mt_friend_directory)), "W" : Process("W", WEstimation (era, directory, mt, friend_directory=mt_friend_directory)), } # mt_processes["FAKES"] = Process("jetFakes", NewFakeEstimationLT(era, directory, mt, [mt_processes[process] for process in ["EMB", "ZL", "TTL", "VVL"]], mt_processes["data"], friend_directory=[mt_friend_directory, ff_friend_directory])) #mt_fakes_for_uncs=Process("jetFakes", FakeEstimationLT(era, directory, mt, friend_directory=[mt_friend_directory, ff_friend_directory])) mt_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, mt, [mt_processes[process] for process in ["ZTT", "ZL", "ZJ", "TTL","TTT","TTJ", "VVT", "VVJ", "VVL","W"]], mt_processes["data"], friend_directory=mt_friend_directory, extrapolation_factor=1.1)) mt_processes["QCDEMB"] = Process("QCDEMB", QCDEstimation_SStoOS_MTETEM(era, directory, mt, [mt_processes[process] for process in ["EMB", "ZL", "ZJ", "TTL", "TTJ", "VVJ", "VVL","W"]], mt_processes["data"], friend_directory=mt_friend_directory, extrapolation_factor=1.1)) # TODO: Include Z-> mumu control region. mm = MMTauID2018() mm_processes = { "data" : Process("data_obs", DataEstimation (era, directory, mm, friend_directory=[])), "ZLL" : Process("ZLL", DYJetsToLLEstimation (era, directory, mm, friend_directory=[])), "MMEMB" : Process("MMEMB", ZTTEmbeddedEstimation(era, directory, mm, friend_directory=[])), "TT" : Process("TT", TTEstimation (era, directory, mm, friend_directory=[])), "VV" : Process("VV", VVEstimation (era, directory, mm, friend_directory=[])), "W" : Process("W", WEstimation (era, directory, mm, friend_directory=[])), } # mm_processes["FAKES"] = None TODO: Add fake factors or alternative fake rate estimation here mm_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, mm, [mm_processes[process] for process in ["ZLL", "W", "TT", "VV"]], mm_processes["data"], friend_directory=[], extrapolation_factor=1.17)) mm_processes["QCDEMB"] = Process("QCDEMB", QCDEstimation_SStoOS_MTETEM(era, directory, mm, [mm_processes[process] for process in ["MMEMB", "W"]], mm_processes["data"], friend_directory=[], extrapolation_factor=1.17)) # Variables and categories binning = yaml.load(open(args.binning)) mt_categories = [] # Goodness of fit shapes if args.gof_channel == "mt": score = Variable( args.gof_variable, VariableBinning(binning["control"]["mt"][args.gof_variable]["bins"]), expression=binning["control"]["mt"][args.gof_variable]["expression"]) if "cut" in binning["control"]["mt"][args.gof_variable].keys(): cuts=Cuts(Cut(binning["control"]["mt"][args.gof_variable]["cut"], "binning")) else: cuts=Cuts() mt_categories.append( Category( args.gof_variable, mt, cuts, variable=score)) elif "mt" in args.channels: for cat in binning["categories"]["mt"]: category = Category( cat, mt, Cuts(Cut(binning["categories"]["mt"][cat]["cut"], "category")), variable=Variable(binning["categories"]["mt"][cat]["var"], VariableBinning(binning["categories"]["mt"][cat]["bins"]), expression=binning["categories"]["mt"][cat]["expression"])) mt_categories.append(category) # yapf: enable if "mt" in [args.gof_channel] + args.channels: for process, category in product(mt_processes.values(), mt_categories): systematics.add( Systematic(category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) mm_categories = [] if "mm" in args.channels: category = Category("control", mm, Cuts(), variable=Variable("m_vis", ConstantBinning(1, 50, 150), "m_vis")) mm_categories.append(category) if "mm" in args.channels: for process, category in product(mm_processes.values(), mm_categories): systematics.add( Systematic(category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) # Shapes variations # MC tau energy scale tau_es_3prong_variations = create_systematic_variations( "CMS_scale_mc_t_3prong_Run2018", "tauEsThreeProng", DifferentPipeline) tau_es_1prong_variations = create_systematic_variations( "CMS_scale_mc_t_1prong_Run2018", "tauEsOneProng", DifferentPipeline) tau_es_1prong1pizero_variations = create_systematic_variations( "CMS_scale_mc_t_1prong1pizero_Run2018", "tauEsOneProngOnePiZero", DifferentPipeline) for variation in tau_es_3prong_variations + tau_es_1prong_variations + tau_es_1prong1pizero_variations: for process_nick in [ "ZTT", "TTT", "TTL", "VVL", "VVT", # "FAKES" ]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) # Tau energy scale tau_es_3prong_variations = create_systematic_variations( "CMS_scale_t_3prong_Run2018", "tauEsThreeProng", DifferentPipeline) tau_es_1prong_variations = create_systematic_variations( "CMS_scale_t_1prong_Run2018", "tauEsOneProng", DifferentPipeline) tau_es_1prong1pizero_variations = create_systematic_variations( "CMS_scale_t_1prong1pizero_Run2018", "tauEsOneProngOnePiZero", DifferentPipeline) for variation in tau_es_3prong_variations + tau_es_1prong_variations + tau_es_1prong1pizero_variations: for process_nick in [ "ZTT", "TTT", "TTL", "VVT", "VVL", "EMB", # "FAKES" ]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) # Jet energy scale # Inclusive JES shapes TODO: Check this jet_es_variations = [] '''jet_es_variations += create_systematic_variations( "CMS_scale_j_Run2017", "jecUnc", DifferentPipeline)''' # Splitted JES shapes jet_es_variations += create_systematic_variations( "CMS_scale_j_eta0to3_Run2018", "jecUncEta0to3", DifferentPipeline) jet_es_variations += create_systematic_variations( "CMS_scale_j_eta0to5_Run2018", "jecUncEta0to5", DifferentPipeline) jet_es_variations += create_systematic_variations( "CMS_scale_j_eta3to5_Run2018", "jecUncEta3to5", DifferentPipeline) jet_es_variations += create_systematic_variations( "CMS_scale_j_RelativeBal_Run2018", "jecUncRelativeBal", DifferentPipeline) jet_es_variations += create_systematic_variations( "CMS_scale_j_RelativeSample_Run2018", "jecUncRelativeSample", DifferentPipeline) for variation in jet_es_variations: for process_nick in [ "ZTT", "ZL", "ZJ", "W", "TTT", "TTL", "TTJ", "VVT", "VVJ", "VVL", ]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) # MET energy scale. Note: only those variations for non-resonant processes are used in the stat. inference met_unclustered_variations = create_systematic_variations( "CMS_scale_met_unclustered", "metUnclusteredEn", DifferentPipeline) for variation in met_unclustered_variations: # + met_clustered_variations: for process_nick in [ "ZTT", "ZL", "ZJ", "W", "TTT", "TTL", "TTJ", "VVT", "VVJ", "VVL", ]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) # Recoil correction unc recoil_resolution_variations = create_systematic_variations( "CMS_htt_boson_reso_met_Run2018", "metRecoilResolution", DifferentPipeline) recoil_response_variations = create_systematic_variations( "CMS_htt_boson_scale_met_Run2018", "metRecoilResponse", DifferentPipeline) for variation in recoil_resolution_variations + recoil_response_variations: for process_nick in ["ZTT", "ZL", "ZJ", "W"]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) # Z pt reweighting zpt_variations = create_systematic_variations("CMS_htt_dyShape_Run2018", "zPtReweightWeight", SquareAndRemoveWeight) for variation in zpt_variations: for process_nick in ["ZTT", "ZL", "ZJ"]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) # top pt reweighting top_pt_variations = create_systematic_variations("CMS_htt_ttbarShape", "topPtReweightWeight", SquareAndRemoveWeight) for variation in top_pt_variations: for process_nick in ["TTT", "TTL", "TTJ"]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) # TODO: likely not necessary, to be checked # jet to tau fake efficiency jet_to_tau_fake_variations = [] jet_to_tau_fake_variations.append( AddWeight("CMS_htt_jetToTauFake_Run2018", "jetToTauFake_weight", Weight("max(1.0-pt_2*0.002, 0.6)", "jetToTauFake_weight"), "Up")) jet_to_tau_fake_variations.append( AddWeight("CMS_htt_jetToTauFake_Run2018", "jetToTauFake_weight", Weight("min(1.0+pt_2*0.002, 1.4)", "jetToTauFake_weight"), "Down")) for variation in jet_to_tau_fake_variations: for process_nick in ["ZJ", "TTJ", "W", "VVJ"]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) # ZL fakes energy scale mu_fake_es_1prong_variations = create_systematic_variations( "CMS_ZLShape_mt_1prong_Run2018", "tauMuFakeEsOneProng", DifferentPipeline) mu_fake_es_1prong1pizero_variations = create_systematic_variations( "CMS_ZLShape_mt_1prong1pizero_Run2018", "tauMuFakeEsOneProngPiZeros", DifferentPipeline) if "mt" in [args.gof_channel] + args.channels: for process_nick in ["ZL"]: for variation in mu_fake_es_1prong_variations + mu_fake_es_1prong1pizero_variations: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) # lepton trigger efficiency lep_trigger_eff_variations = [] lep_trigger_eff_variations.append( AddWeight( "CMS_eff_trigger_mt_Run2018", "trg_mt_eff_weight", Weight("(1.0*(pt_1<=25)+1.02*(pt_1>25))", "trg_mt_eff_weight"), "Up")) lep_trigger_eff_variations.append( AddWeight( "CMS_eff_trigger_mt_Run2018", "trg_mt_eff_weight", Weight("(1.0*(pt_1<=25)+0.98*(pt_1>25))", "trg_mt_eff_weight"), "Down")) for variation in lep_trigger_eff_variations: for process_nick in [ "ZTT", "ZL", "ZJ", "W", "TTT", "TTL", "TTJ", "VVL", "VVT", "VVJ", ]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) for process_nick in ["ZLL", "TT", "VV", "W"]: if "mm" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mm_processes[process_nick], channel=mm, era=era) lep_trigger_eff_variations = [] lep_trigger_eff_variations.append( AddWeight( "CMS_eff_trigger_emb_mt_Run2018", "trg_mt_eff_weight", Weight("(1.0*(pt_1<=25)+1.02*(pt_1>25))", "trg_mt_eff_weight"), "Up")) lep_trigger_eff_variations.append( AddWeight( "CMS_eff_trigger_emb_mt_Run2018", "trg_mt_eff_weight", Weight("(1.0*(pt_1<=25)+0.98*(pt_1>25))", "trg_mt_eff_weight"), "Down")) for variation in lep_trigger_eff_variations: for process_nick in ["EMB"]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) for process_nick in ["MMEMB"]: if "mm" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mm_processes[process_nick], channel=mm, era=era) # b tagging # btag_eff_variations = create_systematic_variations( # "CMS_htt_eff_b_Run2017", "btagEff", DifferentPipeline) # mistag_eff_variations = create_systematic_variations( # "CMS_htt_mistag_b_Run2017", "btagMistag", DifferentPipeline) # for variation in btag_eff_variations + mistag_eff_variations: # for process_nick in [ # "ZTT", "ZL", "ZJ", "W", "TTT", "TTL", "TTJ", "VVT", "VVJ", # "VVL" # ]: # if "et" in [args.gof_channel] + args.channels: # systematics.add_systematic_variation( # variation=variation, # process=et_processes[process_nick], # channel=et, # era=era) # if "mt" in [args.gof_channel] + args.channels: # systematics.add_systematic_variation( # variation=variation, # process=mt_processes[process_nick], # channel=mt, # era=era) # if "tt" in [args.gof_channel] + args.channels: # systematics.add_systematic_variation( # variation=variation, # process=tt_processes[process_nick], # channel=tt, # era=era) # for process_nick in ["ZTT", "ZL", "W", "TTT", "TTL", "VVL", "VVT" # ]: # if "em" in [args.gof_channel] + args.channels: # systematics.add_systematic_variation( # variation=variation, # process=em_processes[process_nick], # channel=em, # era=era) # Embedded event specifics # Tau energy scale tau_es_3prong_variations = create_systematic_variations( "CMS_scale_emb_t_3prong_Run2018", "tauEsThreeProng", DifferentPipeline) tau_es_1prong_variations = create_systematic_variations( "CMS_scale_emb_t_1prong_Run2018", "tauEsOneProng", DifferentPipeline) tau_es_1prong1pizero_variations = create_systematic_variations( "CMS_scale_emb_t_1prong1pizero_Run2018", "tauEsOneProngOnePiZero", DifferentPipeline) for variation in tau_es_3prong_variations + tau_es_1prong_variations + tau_es_1prong1pizero_variations: for process_nick in ["EMB"]: #, "FAKES"]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) mt_decayMode_variations = [] mt_decayMode_variations.append( ReplaceWeight( "CMS_3ProngEff_Run2018", "decayMode_SF", Weight("embeddedDecayModeWeight_effUp_pi0Nom", "decayMode_SF"), "Up")) mt_decayMode_variations.append( ReplaceWeight( "CMS_3ProngEff_Run2018", "decayMode_SF", Weight("embeddedDecayModeWeight_effDown_pi0Nom", "decayMode_SF"), "Down")) mt_decayMode_variations.append( ReplaceWeight( "CMS_1ProngPi0Eff_Run2018", "decayMode_SF", Weight("embeddedDecayModeWeight_effNom_pi0Up", "decayMode_SF"), "Up")) mt_decayMode_variations.append( ReplaceWeight( "CMS_1ProngPi0Eff_Run2018", "decayMode_SF", Weight("embeddedDecayModeWeight_effNom_pi0Down", "decayMode_SF"), "Down")) for variation in mt_decayMode_variations: for process_nick in ["EMB"]: if "mt" in [args.gof_channel] + args.channels: systematics.add_systematic_variation( variation=variation, process=mt_processes[process_nick], channel=mt, era=era) # 10% removed events in ttbar simulation (ttbar -> real tau tau events) will be added/subtracted to ZTT shape to use as systematic tttautau_process_mt = Process( "TTT", TTTEstimation(era, directory, mt, friend_directory=[])) if "mt" in [args.gof_channel] + args.channels: for category in mt_categories: mt_processes['ZTTpTTTauTauDown'] = Process( "ZTTpTTTauTauDown", AddHistogramEstimationMethod( "AddHistogram", "nominal", era, directory, mt, [mt_processes["EMB"], tttautau_process_mt], [1.0, -0.1])) systematics.add( Systematic(category=category, process=mt_processes['ZTTpTTTauTauDown'], analysis="smhtt", era=era, variation=Relabel("CMS_htt_emb_ttbar_Run2018", "Down"), mass="125")) mt_processes['ZTTpTTTauTauUp'] = Process( "ZTTpTTTauTauUp", AddHistogramEstimationMethod( "AddHistogram", "nominal", era, directory, mt, [mt_processes["EMB"], tttautau_process_mt], [1.0, 0.1])) systematics.add( Systematic(category=category, process=mt_processes['ZTTpTTTauTauUp'], analysis="smhtt", era=era, variation=Relabel("CMS_htt_emb_ttbar_Run2018", "Up"), mass="125")) # jetfakes # fake_factor_variations_mt = [] # for systematic_shift in [ # "ff_qcd{ch}_syst_Run2017{shift}", # "ff_qcd_dm0_njet0{ch}_stat_Run2017{shift}", # "ff_qcd_dm0_njet1{ch}_stat_Run2017{shift}", # #"ff_qcd_dm1_njet0{ch}_stat_Run2017{shift}", # #"ff_qcd_dm1_njet1{ch}_stat_Run2017{shift}", # "ff_w_syst_Run2017{shift}", # "ff_w_dm0_njet0{ch}_stat_Run2017{shift}", # "ff_w_dm0_njet1{ch}_stat_Run2017{shift}", # #"ff_w_dm1_njet0{ch}_stat_Run2017{shift}", # #"ff_w_dm1_njet1{ch}_stat_Run2017{shift}", # "ff_tt_syst_Run2017{shift}", # "ff_tt_dm0_njet0_stat_Run2017{shift}", # "ff_tt_dm0_njet1_stat_Run2017{shift}", # #"ff_tt_dm1_njet0_stat_Run2017{shift}", # #"ff_tt_dm1_njet1_stat_Run2017{shift}" # ]: # for shift_direction in ["Up", "Down"]: # fake_factor_variations_mt.append( # ReplaceWeight( # "CMS_%s" % (systematic_shift.format(ch='_mt', shift="").replace("_dm0", "")), # "fake_factor", # Weight( # "ff2_{syst}".format( # syst=systematic_shift.format( # ch="", shift="_%s" % shift_direction.lower()) # .replace("_Run2017", "")), # "fake_factor"), shift_direction)) # if "mt" in [args.gof_channel] + args.channels: # for variation in fake_factor_variations_mt: # systematics.add_systematic_variation( # variation=variation, # process=mt_processes["FAKES"], # channel=mt, # era=era) # Produce histograms logger.info("Start producing shapes.") systematics.produce() logger.info("Done producing shapes.")
def main(args): # Container for all distributions to be drawn systematics_mm = Systematics("fitrecoil_mm_2018.root", num_threads=args.num_threads, find_unique_objects=True) # Era era = Run2018(args.datasets) # Channels and processes # yapf: disable directory = args.directory mm_friend_directory = args.mm_friend_directory mm = MM() mm_processes = { "data" : Process("data_obs", DataEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "ZTT" : Process("ZTT", ZTTEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "ZL" : Process("ZL", ZLEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "TTT" : Process("TTT", TTTEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "TTL" : Process("TTL", TTLEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "VVT" : Process("VVT", VVTEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "VVL" : Process("VVL", VVLEstimation (era, directory, mm, friend_directory=mm_friend_directory)), "W" : Process("W", WEstimation (era, directory, mm, friend_directory=mm_friend_directory)), } mm_processes["QCD"] = Process("QCD", QCDEstimation_SStoOS_MTETEM(era, directory, mm, [mm_processes[process] for process in ["ZTT", "ZL", "W", "TTT", "TTL", "VVT", "VVL"]], mm_processes["data"], friend_directory=mm_friend_directory, extrapolation_factor=2.0)) # Variables and categories mm_categories = [] variable_names = [ # "met", "metphi", # "puppimet", "puppimetphi", "metParToZ", "metPerpToZ", "puppimetParToZ", "puppimetPerpToZ", # "recoilParToZ", "recoilPerpToZ", # "puppirecoilParToZ", "puppirecoilPerpToZ", ] variables = [Variable(v,ConstantBinning(25,-100.0,100.0)) for v in variable_names] cuts = [ Cut("njets == 0", "0jet"), Cut("njets == 1", "1jet"), Cut("njets >= 2", "ge2jet"), ] for cut in cuts: for var in variables: mm_categories.append( Category( cut.name, mm, Cuts(Cut("m_vis > 70 && m_vis < 110","m_vis_peak"), cut), variable=var)) for process, category in product(mm_processes.values(), mm_categories): systematics_mm.add( Systematic( category=category, process=process, analysis="smhtt", era=era, variation=Nominal(), mass="125")) # Recoil correction unc recoil_resolution_variations = create_systematic_variations( "CMS_htt_boson_reso_met_Run2018", "metRecoilResolution", DifferentPipeline) recoil_response_variations = create_systematic_variations( "CMS_htt_boson_scale_met_Run2018", "metRecoilResponse", DifferentPipeline) for variation in recoil_resolution_variations + recoil_response_variations: systematics_mm.add_systematic_variation( variation=variation, process=mm_processes["ZL"], channel=mm, era=era) # Produce histograms systematics_mm.produce()
def main(args): # Define era if "2016" in args.era: from shape_producer.era import Run2016 era = Run2016(args.datasets) elif "2017" in args.era: from shape_producer.era import Run2017 era = Run2017(args.datasets) elif "2018" in args.era: from shape_producer.era import Run2018 era = Run2018(args.datasets) else: logger.fatal("Era {} is not implemented.".format(args.era)) raise Exception # Load variables variables = yaml.load(open(args.variables))["selected_variables"] # Define bins and range of binning for variables in enabled channels channel_dict = { "et": { "2016": ETSM2016(), "2017": ETSM2017(), "2018": ETSM2018() }, "mt": { "2016": MTSM2016(), "2017": MTSM2017(), "2018": MTSM2018() }, "tt": { "2016": TTSM2016(), "2017": TTSM2017(), "2018": TTSM2018() }, "em": { "2016": EMSM2016(), "2017": EMSM2017(), "2018": EMSM2018() }, } friend_directories_dict = { "em": args.em_friend_directories, "et": args.et_friend_directories, "mt": args.mt_friend_directories, "tt": args.tt_friend_directories, } percentiles = [ 0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0 ] config = {"gof": {}} for ch in channel_dict.keys(): if ch != args.channel: continue # Get properties if "2016" in args.era: eraname = "2016" elif "2017" in args.era: eraname = "2017" elif "2018" in args.era: eraname = "2018" channel = channel_dict[ch][eraname] logger.info("Channel: %s" % ch) dict_ = {} additional_cuts = Cuts() logger.warning("Use additional cuts for %s: %s" % (ch, additional_cuts.expand())) dict_ = get_properties(dict_, era, channel, args.directory, additional_cuts) # Build chain dict_["tree_path"] = "%s_nominal/ntuple" % ch chain = build_chain(dict_, friend_directories_dict[ch]) # Get percentiles and calculate 1d binning binning = get_1d_binning(ch, chain, variables[int(eraname)][ch], percentiles) # Add binning for unrolled 2d distributions binning = add_2d_unrolled_binning(variables[int(eraname)][ch], binning) # Append binning to config config["gof"][ch] = binning # Write config logger.info("Write binning config to %s.", args.output) yaml.dump(config, open(args.output, 'w'))
"mt": MTSM2017(), "et": ETSM2017(), "tt": TTSM2017(), "em": EMSM2017() }, "2018": { "mt": MTSM2018(), "et": ETSM2018(), "tt": TTSM2018(), "em": EMSM2018() } } eraD = { "2016": Run2016(database), "2017": Run2017(database), "2018":Run2018(database) } from shape_producer.estimation_methods_2017 import DataEstimation, ZTTEstimation, ZJEstimation, ZLEstimation, TTLEstimation, TTJEstimation, TTTEstimation, VVTEstimation, VVJEstimation, VVLEstimation, WEstimation, ggHEstimation, qqHEstimation, EWKZEstimation, ZTTEmbeddedEstimation, NewFakeEstimationTT, NewFakeEstimationLT from fake_factor_derivation.cuts import cutDB class ParSpaceRegion(object): def __init__(self, eraName, channelName, bkgName): self.meta = {"era": eraName, "channel": channelName, "bkg": bkgName} self.era = eraD[eraName] self.channel = copy.deepcopy(channelDict[eraName][channelName]) if self.meta["era"] not in ["2016", "2017"]: raise Exception ### remove old isolation cuts and add the very Loose isolation, that is needed to to exclude other backgrounds from all regions # for cut_ in self.channel.cuts.names: