def runtime(args=None, additional_dictionary=None): """Make performance plots (processor runtime). To create the 'runTime'-ntuple in the excalibur output, add 'RunTimeConsumer' to the list of consumers in the config. """ only_producers = True # dont plot filters plots = [] for label, corr in zip( ['Data', 'MC'], ['Res', ''], ): filename = '{}_runtime.root'.format(label.lower()) folder = 'finalcuts_AK5PFJetsCHSL1L2L3{}/runTime'.format(corr) processors = [] # get list of processors with TFileContextManager(filename, "READ") as rootfile: ntuple = rootfile.Get(folder) try: for leaf in ntuple.GetListOfLeaves(): if ('Producer' in leaf.GetName()) or not only_producers: processors.append(leaf.GetName()) except AttributeError: print "Could not find {}! Did you let the RunTimeConsumer run?".format(folder) exit(1) d = { # input 'files': [filename], 'folders': [folder], 'x_expressions': processors, 'nicks': processors, 'x_bins': ['100,0,500'], 'no_weight': True, # analysis 'analysis_modules': ['NormalizeToUnity', 'HistogramFromMeanValues'], # formatting 'nicks_whitelist': ['mean'], 'markers': ['fill'], 'legend': None, 'x_label': ' ', 'y_label': 'runtime', 'energies': None, 'title': label, 'no_energy_label': True, # output 'filename': label.lower() + '_runtime', } plots.append(d) harryinterface.harry_interface(plots, args)
def zmass_ee_mm(args=None, additional_dictionary=None, run=2): """1D histograms for Zmass calculated from ee and mm """ plots = [] if run == 2: files = [ 'work/mc15_25ns_ee.root', 'work/mc15_25ns.root', 'work/mc15_25ns.root' ], algo = ['ak4PFJetsCHS'], elif run == 1: files = ['work/mc_ee.root', 'work/mc.root', 'work/mc.root'], algo = ['ak5PFJetsCHS'], d_1 = { #get data 'files': files, 'algorithms': algo, 'corrections': ['L1L2L3'], #binning 'x_expressions': ["zmass", "zmass", 'genzmass'], 'x_bins': '20,81,102', 'x_label': '$m_{{Z}}$ / GeV', #formatting 'nicks': ["ze", "zmu", 'genz'], 'labels': ["$Z_{e}$", r"$Z_{{\\mu}}$", "$Z_{gen}$"], 'colors': [color['e'], color['mu'], color['undef']], 'filename': 'zmass_ee_mm_comparison_run{}'.format(str(run)), 'analysis_modules': [ 'NormalizeToFirstHisto', ], 'y_label': 'Electron Events', 'markers': ['_', '4', '3'], 'marker_fill_styles': ['none', 'none', 'none'], 'line_styles': ['-'], 'step': ['True', 'True', 'True'], 'title': r'Zmass calculated \n from ee and $\\mu\\mu$', } plots.append(d_1) for d in plots: d.update({ # web gallery options 'www_title': 'Comparison of Zmass', 'www_text': 'Comparison of Zmass calculated from ee and mm', }) harryinterface.harry_interface(plots, args)
def muon_isolation(args=None, additional_dictionary=None): """Show criteria for muon isolation based selection""" arg_plots = {} input_files, args_nofiles = get_input_files(args) # variables == mu1pt, muinv2sumnhet, ... # ISO == sumchpt + sumnhet + sumpet - 0.5 * sumpupt for muid in (1, 2): for validity in ("inv", ""): muon_id = "mu%s%d" % (validity, muid) for obs in ("sumchpt", "sumnhet", "sumpet", "sumpupt"): # 1D plots d = { 'x_expressions': ['%s%s/%spt' % (muon_id, obs, muon_id)], 'analysis_modules': ['NormalizeToFirstHisto', 'Ratio'], "filename": "cuts_iso_%s_%s" % (muon_id, obs), 'x_bins': "25,0,1", 'weights': ['%spt>0' % muon_id], } if additional_dictionary is not None: d.update(additional_dictionary) arg_plots.setdefault(tuple(args), []).append(d) # 2D plots for in_file in input_files: d_args = args_nofiles[:] d_args.extend(("-i", in_file)) d = { 'x_expressions': ['%siso/%spt' % (muon_id, muon_id)], 'y_expressions': ['%s%s/%spt' % (muon_id, obs, muon_id)], 'x_bins': "25,0,1", 'y_bins': "25,0,1", 'z_log': True, "filename": "cuts_iso_%s_%s_%s" % (muon_id, obs, os.path.basename(in_file).split(".", 1)[0]), 'weights': ['%spt>0' % muon_id], } if additional_dictionary is not None: d.update(additional_dictionary) arg_plots.setdefault(tuple(d_args), []).append(d) for d_args in arg_plots: harryinterface.harry_interface(arg_plots[d_args], d_args)
def cut_n_muons(args=None, additional_dictionary=None): """Plot min/max N muon cut""" plots = [] d_base = { 'x_bins': ["6,-0.5,5.5"], 'plot_modules': ["PlotMplZJet", "PlotMplRectangle"], "rectangle_x": [-1, 1.5, 3.5, 6], "rectangle_alpha": [0.2], "rectangle_color": ["red", "red"], "y_log": True, 'y_subplot_lims': [0.15, 1.95], } d1 = { "x_expressions": ["nmuons", "nmuons"], "markers": ["o", "fill"] * 1 + ["o"] * 1, "nicks": ["data", "mc"], "labels": [r"$\\mu_\\mathrm{Data}$", r"$\\mu_\\mathrm{MC}$"], 'analysis_modules': ['Ratio'], "filename": "cuts_nmuons", "title": "Number of valid Muons", } d2 = { "x_expressions": ["nmuonsinv+nmuons", "nmuonsinv+nmuons"], "markers": ["o", "fill"] * 2 + ["o"] * 2, "nicks": ["data Mu Val", "mc Mu Val", "data Mu Tot", "mc Mu Tot"], "labels": [ r"$\\mu_\\mathrm{Data}$", r"$\\mu_\\mathrm{MC}$", r"$\\mu_\\mathrm{Data}^\\mathrm{tot}$", r"$\\mu_\\mathrm{MC}^\\mathrm{tot}$" ], "filename": "cuts_totmuons", "title": "Number of total Muons", } d1.update(d_base) d2.update(d_base) if additional_dictionary is not None: d1.update(additional_dictionary) d2.update(additional_dictionary) plots.append(d1) plots.append(d2) harryinterface.harry_interface(plots, args)
def jec_factors(args=None, additional_dictionary=None, rc=True, res=False): """ Plot JEC factors from artus output ntuples. Creates plots for L1 and L2L3, optionally also RC and Res Usage e.g.: merlin.py --py jec_factors -i work/data.root """ plots = [] #level: (title, basept) jec_dict = { 'l1': ('L1', 'raw'), 'l2': ('L2', 'l1'), 'rc': ('L1RC', 'raw'), 'res': ('Res', 'l1l2l3') } corr_levels = ['l1', 'l2'] if rc: corr_levels.append('rc') if res: corr_levels.append('res') for level, (title, basept) in zip(corr_levels, [jec_dict[level] for level in corr_levels]): d = { 'x_expressions': ['jet1eta'], 'y_expressions': ['jet1pt'+basept], 'x_bins': ['100,-5,5'], 'y_bins': ['100,0,100'], 'zjetfolders': ['nocuts'], 'z_expressions': ['jet1'+level], 'colormap': 'seismic', 'z_lims': [0, 2], 'tree_draw_options': 'prof', 'title': title, 'filename': title.lower(), 'x_label': 'jet1eta', 'y_label': 'jet1pt', 'z_label': 'JEC Correction Factor', } if additional_dictionary is not None: d.update(additional_dictionary) plots.append(d) harryinterface.harry_interface(plots, args)
def pt_distribution(args=None, additional_dictionary=None): """ pT Distribution, 1D histogram: number of events for jet1pt, eminuspt, muminuspt """ plots = [] d_1 = { #get data 'files': ['work/mc.root', 'work/mc_ee.root', 'work/mc.root'], 'corrections': ['L1L2L3'], #binning 'x_expressions': ["jet1pt", "eminuspt", 'muminuspt'], 'x_bins': '100,0,700', 'x_label': '$p_{{T}}$ / GeV', #formatting 'nicks': ["jet1", "e", 'mu'], 'labels': [r"$Jet1$", "$e^{-}$", r"$\\mu^{-}$"], 'colors': [color['jet'], color['e'], color['mu']], 'filename': 'pT_distribution', 'analysis_modules': [ 'NormalizeToFirstHisto', ], 'markers': ['.', '.', '.'], 'marker_fill_styles': ['full', 'full', 'full'], 'line_styles': ['-'], 'step': ['True', 'True', 'True'], 'title': 'Number of events\n depending on pT', } plots.append(d_1) for d in plots: d.update({ # web gallery options #'www_title': 'Comparison of Zmass', #'www_text': 'Comparison of Zmass calculated from ee and mm', }) harryinterface.harry_interface(plots, args)
def muoniso_aod(args=None, additional_dictionary=None): """Plot muons PF Iso/pT quantities directly out of AOD files. WORKS ONLY AT NAF! """ # set a pT threshold for the muons: pt_threshold = 0 weights = ['patMuons_slimmedMuons__{}.obj.m_state.p4Polar_.fCoordinates.fPt>{}'.format(item, pt_threshold) for item in ['RECO', 'PAT']] plots = [] for fraction in ['ChargedHadronPt', 'ChargedParticlePt', 'PUPt', 'PhotonEt', 'NeutralHadronEt']: for cone_size in ['3', '4']: d = { 'files':[ # MINIAOD data and mc '/pnfs/desy.de/cms/tier2/store/data/Run2015B/DoubleMuon/MINIAOD/PromptReco-v1/000/251/883/00000/44864117-232D-E511-8C15-02163E01463E.root', '/pnfs/desy.de/cms/tier2/store/mc/RunIISpring15DR74/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/MINIAODSIM/Asympt50ns_MCRUN2_74_V9A-v2/60000/2A5F281F-F007-E511-87F2-00074305CD93.root', ], 'folders': 'Events', 'x_expressions': [ "patMuons_slimmedMuons__RECO.obj.pfIsolationR0{}_.sum{}/patMuons_slimmedMuons__RECO.obj.m_state.p4Polar_.fCoordinates.fPt".format(cone_size, fraction), "patMuons_slimmedMuons__PAT.obj.pfIsolationR0{}_.sum{}/patMuons_slimmedMuons__PAT.obj.m_state.p4Polar_.fCoordinates.fPt".format(cone_size, fraction), # for AOD: 'recoMuons_muons__RECO.obj.pfIsolationR04_.sumChargedHadronPt/recoMuons_muons__RECO.obj.m_state.p4Polar_.fCoordinates.fPt' ], 'x_bins': '25,0,50', 'weights': [weights], #analysis 'analysis_modules': ['NormalizeToFirstHisto', 'Ratio'], #formatting 'labels': ['Data', 'MC'], 'energies': [13], 'y_subplot_lims': [0, 2.99], # not exactly three so the tick labels of upper and lower plot dont clash 'x_label': r'Muon {}R0{}'.format(fraction, cone_size) + r'$/\\mathit{p}_T^{\\mu}$', 'title': 'Shape comparison', 'y_log': True, # output 'filename': 'muons_{}_R0{}'.format(fraction, cone_size), } plots.append(d) harryinterface.harry_interface(plots, args)
def jec_pu_combination(args=None, additional_dictionary=None, algo='CHS'): """Create combination info on pileup""" mpl_plots = [] root_plots = [] try: file_label = additional_dictionary.pop("file_label") except (AttributeError, KeyError): file_label = "" now = time.localtime() create_file = True for x_expression, y_expression in [("npumean", "rho"), ("npv", "rho"), ("npumean", "npv")]: for correction in ['L1L2L3']: # no L1L2L3Res available atm labelsuffix = "_".join((x_expression, "vs", y_expression, algo, correction)) d_mpl = { 'x_expressions': [x_expression], 'y_expressions': [y_expression], 'tree_draw_options': 'prof', 'corrections': ['L1L2L3'], 'cutlabel': True, 'markers': ['o', 'd'], 'x_bins': "50,0.5,50.5", 'legend': 'lower right', 'analysis_modules': ['Ratio', 'ConvertToTGraphErrors'], 'labels': ['_'.join([item, labelsuffix]) for item in ['Data', 'MC', 'Ratio']], } if additional_dictionary is not None: d_mpl.update(additional_dictionary) d_root = d_mpl.copy() d_root.update({ 'plot_modules': ['ExportRoot'], 'filename': 'combination_ZJet_PU_' + file_label + time.strftime("%Y-%m-%d", now), 'file_mode': ('RECREATE' if create_file else 'UPDATE'), }) create_file = False mpl_plots.append(d_mpl) root_plots.append(d_root) harryinterface.harry_interface(mpl_plots, args) harryinterface.harry_interface(root_plots, args + ['--max-processes', '1'])
def cut_jet_kinematics(args=None, additional_dictionary=None): """Plot pt and eta jet1 cut""" arg_plots = {} input_files, args_nofiles = get_input_files(args) for in_file in input_files: args = args_nofiles[:] args.extend(("-i", in_file)) for muid in range(1, 2): d = { 'x_expressions': ['jet%dpt' % muid], 'y_expressions': ['jet%deta' % muid], 'x_bins': "25,0,100", 'y_bins': "25,0,2.5", 'y_lims': [0, 2.5], 'x_lims': [0, 100], #'z_log': True, 'plot_modules': ["PlotMplZJet", "PlotMplRectangle"], # cfg['CutLeadingJetPtMin'] = 12.0 # cfg['CutLeadingJetEtaMax'] = 1.3 "rectangle_x": [-1, 12], "rectangle_y": [0, 1.3, 1.3, 5], "rectangle_color": ["red", "red"], "rectangle_alpha": [0.2], "filename": "cuts_jet%d_%s" % (muid, os.path.basename(in_file).split(".", 1)[0]), "title": "Jet %d" % muid, } if additional_dictionary is not None: d.update(additional_dictionary) arg_plots.setdefault(tuple(args), []).append(d) for args in arg_plots: harryinterface.harry_interface(arg_plots[args], args)
def call_python_function(function_name, python_path, unknown_args=None): """call a python if it is present in any module in the path.""" module_list = [] for path in python_path.split(':'): module_list += get_module_list(path) for module in module_list: functions = inspect.getmembers(module, inspect.isfunction) for func in functions: if func[0] == function_name: log.info("Executing function {} in module {}".format( func[0], module.__name__)) plotting_jobs = func[1](unknown_args) if plotting_jobs is not None and isinstance( plotting_jobs, list): import Excalibur.Plotting.harryinterface as harryinterface # Aggregating plots with same arguments for parallel plotting all_plots = {} for plotting_job in plotting_jobs: all_plots.setdefault(tuple(plotting_job.args), []).extend(plotting_job.plots) for args in all_plots: harryinterface.harry_interface(all_plots[args], args) return log.warning("Could not execute function {}".format(function_name))
def rootfile_53742(args=None): """ Create a root file with zpt-jet1eta 2D histograms for 53 and 742. Matched events. Sent to Ia 18.06.2015 Input file created with eventmatching tool: eventmatching.py /storage/a/dhaitz/zjet/excalibur/data742RC_2015-07-09_11-49/out.root /storage/a/dhaitz/zjet/excalibur/dataRC_2015-07-09_10-45/out.root -t nocuts_AK5PFJetsCHSRC/ntuple finalcuts_AK5PFJetsCHSRC/ntuple -o -n 742 53 -f 53742_newRC_RConly_event_matched_finalcuts_nocuts.root eventmatching.py /storage/a/dhaitz/zjet/excalibur/data742RC_2015-07-09_11-49/out.root /storage/a/dhaitz/zjet/excalibur/dataRC_2015-07-09_10-45/out.root -t nocuts_AK5PFJetsCHSRC/ntuple noetacuts_AK5PFJetsCHSRC/ntuple -o -n 742 53 -f 53742_newRC_RConly_event_matched_noetacuts_nocuts.root """ d = { 'files': ['/storage/a/dhaitz/zjet/53742_newRC_RConly_fixedArea_event_matched_finalcuts_nocuts.root'], 'folders': ['common742', 'common53'], 'labels': ['742', '53'], 'plot_modules': ['ExportRoot'], } d1 = { 'x_expressions': ['zpt'], 'y_expressions': ['jet1eta'], 'x_bins': ["100,0,500"], 'y_bins': ["26,-1.3,1.3"], } d2 = { 'x_expressions': ['zpt'], 'y_expressions': ['jet1pt'], 'x_bins': ["100,0,500"], 'y_bins': ["40,0,400"], } d3 = { 'x_expressions': ['zpt'], 'y_expressions': ['ptbalance'], 'x_bins': ["100,0,500"], 'y_bins': ["210,0.,2.1"], } harryinterface.harry_interface([dict(d,**d1)], args) harryinterface.harry_interface([dict(d,**d2)], args) harryinterface.harry_interface([dict(d,**d3)], args) # outer eta region: 1.3<|jet1eta|<2.5 d = { 'files': ['/storage/a/dhaitz/zjet/53742_newRC_RConly_fixedArea_event_matched_noetacuts_nocuts.root'], 'folders': ['common742', 'common53'], 'labels': ['742', '53'], 'plot_modules': ['ExportRoot'], 'weights' : ["(abs(jet1eta)<2.5&&abs(jet1eta)>1.3)"], } d1 = { 'x_expressions': ['zpt'], 'y_expressions': ['jet1eta'], 'x_bins': ["100,0,500"], 'y_bins': ["50,-2.5,2.5"], 'filename': 'outereta_jet1eta_VS_zpt', } d2 = { 'x_expressions': ['zpt'], 'y_expressions': ['jet1pt'], 'x_bins': ["100,0,500"], 'y_bins': ["40,0,400"], 'filename': 'outereta_jet1pt_VS_zpt', } d3 = { 'x_expressions': ['zpt'], 'y_expressions': ['ptbalance'], 'x_bins': ["100,0,500"], 'y_bins': ["210,0.,2.1"], 'filename': 'outereta_ptbalance_VS_zpt', } harryinterface.harry_interface([dict(d,**d1)], args) harryinterface.harry_interface([dict(d,**d2)], args) harryinterface.harry_interface([dict(d,**d3)], args) # jet1pt_VS_zpt for 53 (only), where jet is corrected with Winter V8 JEC: d = { 'files': ['ntuples/Data_8TeV_53X_E2_50ns_2015-05-20.root'], 'algorithms': ['AK5PFJetsCHS'], 'corrections': ['L1L2L3Res'], 'labels': ['53'], 'plot_modules': ['ExportRoot'], 'x_expressions': ['zpt'], 'y_expressions': ['jet1pt'], 'x_bins': ["100,0,500"], 'y_bins': ["40,0,400"], 'filename': 'fully_corrected_jet1pt_VS_zpt', } harryinterface.harry_interface([d], args)
def reco_gen_comparison(args=None, additional_dictionary=None): """Plots 2D plots of reco and gen for Z, jet1, muminus, as well as 1D-plots of Z/genZ and jet1/genjet1 for various parameters """ #binning overall number, start, stop startstop = { 'pt': ['30', '0', '250'], 'phi': ['30', '-2', '2'], 'eta': ['30', '-3.14', '3.14'], 'y': ['30', '-2.5', '2.5'], 'mass': ['30', '85', '100'], } plots = [] parameterlist_z = ['pt', 'phi', 'y', 'mass'] parameterlist_jet1 = ['pt', 'phi', 'eta'] #2D-plots of Z vs genZ and jet1 vs genjet1 for various parameters for objct, parameterlist in zip([ 'z', 'jet1', 'muminus', ], [parameterlist_z, parameterlist_jet1, parameterlist_jet1]): #Plots for parameter in parameterlist: #2D-plots of Z vs genZ and jet1 vs genjet1 for various parameters d_2 = { #get data 'files': ['work/mc.root'], 'corrections': ['L1L2L3'], #binning 'x_expressions': [ "gen{}{}".format(objct, parameter), ], 'y_expressions': [ "{}{}".format(objct, parameter), ], 'x_bins': ','.join(startstop[parameter]), 'y_bins': ','.join(startstop[parameter]), #formatting 'y_lims': [ float(startstop[parameter][1]), float(startstop[parameter][2]) ], 'x_lims': [ float(startstop[parameter][1]), float(startstop[parameter][2]) ], 'filename': '{}{}_VS_gen{}{}'.format(objct, parameter, objct, parameter), 'title': '{}{} vs gen{}{}'.format(objct, parameter, objct, parameter), } plots.append(d_2) #1D-plots of Z/genZ and jet1/genjet1 for various parameters d_1 = { #get data 'files': ['work/mc.root'], 'corrections': ['L1L2L3'], #binning 'x_expressions': [ "{}{}/gen{}{}".format(objct, parameter, objct, parameter), ], 'x_bins': '50,0.5,1.5', #formatting 'x_lims': [0.5, 1.5], 'filename': '{}{}overgen{}{}'.format(objct, parameter, objct, parameter), 'title': '{}{}/gen{}{}'.format(objct, parameter, objct, parameter), } plots.append(d_1) for d in plots: d.update({ # web gallery options 'www_title': 'Reco-gen-comparisons', 'www_text': 'Comparison of reco- and gen-level pT,eta,y,phi of muons, jets and Z bosons.', }) harryinterface.harry_interface(plots, args)
def jec_combination(args=None, additional_dictionary=None, algo = 'CHS'): """function to create the root combination file for the jec group.""" mpl_plots = [] root_plots = [] label_dict = { 'ptbalance': 'PtBal', 'mpf': 'MPF', 'rawmpf': 'MPF-notypeI', 'zmass': 'ZMass', 'npumean': 'Mu', 'rho': 'Rho', 'npv': 'NPV', } # alpha_limits = [0.4] alpha_limits = [0.1, 0.15, 0.2, 0.3, 0.4] alpha_cuts = ['(alpha<{})'.format(limit) for limit in alpha_limits] alpha_strings = ['a'+str(int(100*limit)) for limit in alpha_limits] # wide eta bins: # eta_borders = [0, 0.783, 1.305, 1.93, 2.5, 2.964, 3.2, 5.191] # narrow eta bins: eta_borders = [0.000, 0.261, 0.522, 0.783, 1.044, 1.305, 1.479, 1.653, 1.930, 2.172, 2.322, 2.500, 2.650, 2.853, 2.964, 3.139, 3.489, 3.839, 5.191] eta_cuts = ["({0}<=abs(jet1eta)&&abs(jet1eta)<{1})".format(*b) for b in zip(eta_borders[:-1], eta_borders[1:])] eta_cuts = ["(0<=abs(jet1eta)&&abs(jet1eta)<1.3)"] + eta_cuts # also include standard barrel jet selection eta_strings = ["eta_{0:0>2d}_{1:0>2d}".format(int(round(10*up)), int(round(10*low))) for up, low in zip(eta_borders[:-1], eta_borders[1:])] eta_strings = ["eta_00_13"] + eta_strings try: npv_weights = additional_dictionary.pop("_npv_weights") warnings.warn("Usage of '_npv_weights' is deprecated. Use PUWeights in Excalibur instead.") except (AttributeError, KeyError): npv_weights = ["1"] try: file_label = additional_dictionary.pop("file_label") except (AttributeError, KeyError): file_label = "" now = time.localtime() def mpl_to_root(mpl_plot_dict): """Create root plot dict from mpl plot dict""" root_plot_dict = mpl_plot_dict.copy() root_plot_dict.update({ 'plot_modules': ['ExportRoot'], 'filename': 'combination_ZJet_' + file_label + time.strftime("%Y-%m-%d", now), 'file_mode': ('RECREATE' if mpl_to_root.first else 'UPDATE'), }) mpl_to_root.first = False return root_plot_dict mpl_to_root.first = False for alphacut, alphastring in zip(alpha_cuts, alpha_strings): for etacut, etastring in zip(eta_cuts, eta_strings): for correction in ['L1L2L3']: # no L1L2L3Res available atm eta_alpha_cut = '&&'.join((alphacut, etacut)) base_plot = { 'nicks': ['data', 'mc'], 'corrections': [correction], 'zjetfolders': ['noalphanoetacuts'], 'weights': ["(%s)*(%s)" % (eta_alpha_cut, npv_weight) for npv_weight in npv_weights], 'tree_draw_options' : ['prof'], # ratio 'analysis_modules': ['Ratio'], 'ratio_numerator_nicks':['data'], 'ratio_denominator_nicks':['mc'], 'ratio_denominator_no_errors': False, } # histograms - raw event counts labelsuffix = '_'.join(['RawNEvents', algo, alphastring, etastring, correction]) d_mpl = { 'x_expressions': ['zpt'], 'x_bins': 'zpt', 'labels': ['_'.join([item, labelsuffix]) for item in ['Data', 'MC', 'Ratio']], 'filename': labelsuffix + file_label, 'no_weight': True, #Remove reweights in MC } d_mpl.update(base_plot) if additional_dictionary is not None: d_mpl.update(additional_dictionary) del d_mpl['tree_draw_options'] d_root = mpl_to_root(d_mpl) # make plots comparable to jec_comparison d_mpl['x_log'] = True d_mpl['x_ticks'] = [30, 50, 70, 100, 200, 400, 1000] mpl_plots.append(d_mpl) root_plots.append(d_root) # profiles - responses for method in ['mpf', 'ptbalance', 'rawmpf', 'zmass']: labelsuffix = '_'.join([label_dict[method], algo, alphastring, etastring, correction]) d_mpl = { 'x_expressions': ['zpt'], 'y_expressions': [method], 'x_bins': 'zpt', 'y_label': method, 'labels': ['_'.join([item, labelsuffix]) for item in ['Data', 'MC', 'Ratio']], 'filename': labelsuffix + file_label, } d_mpl.update(base_plot) if additional_dictionary is not None: d_mpl.update(additional_dictionary) apply_double_profile(d_mpl, args) d_root = mpl_to_root(d_mpl) # make plots comparable to jec_comparison d_mpl['x_log'] = True d_mpl['x_ticks'] = [30, 50, 70, 100, 200, 400, 1000] mpl_plots.append(d_mpl) root_plots.append(d_root) # pileup info for x_expression, y_expression in [("npumean", "rho"), ("npumean", "npv")]: labelsuffix = "_".join((y_expression, "vs", x_expression, algo, alphastring, etastring, correction)) d_mpl = { 'x_expressions': [x_expression], 'y_expressions': [y_expression], 'y_label': y_expression, 'cutlabel': True, 'x_bins': "25,0.5,25.5", 'legend': 'upper left', 'labels': ['_'.join([item, labelsuffix]) for item in ['Data', 'MC', 'Ratio']], 'filename': labelsuffix + file_label, } d_mpl.update(base_plot) if additional_dictionary is not None: d_mpl.update(additional_dictionary) apply_double_profile(d_mpl, args) d_root = mpl_to_root(d_mpl) mpl_plots.append(d_mpl) root_plots.append(d_root) harryinterface.harry_interface(mpl_plots, args) harryinterface.harry_interface(root_plots, args + ['--max-processes', '1'])
def jet_muon_z_comparison_tree(args=None, additional_dictionary=None, run=2): """Comparison of jet, muon, z reconstruction quality depending on pT: Tree-plots of Z/genZ, muminus/genmuminus and jet1/genjet1 together in one diagram for pt, phi, eta each """ plots = [] parameterlist_jet1 = ['pt', 'phi', 'eta'] bins = { "pt": ['10 30 40 50 60 70 80 90 100 150 200 300 500 700'], "phi": ['10 30 40 50 60 70 80 90 100 150 200 250 300 400 500 600'], "eta": ['10 30 40 50 60 70 80 90 100 150 200 250 300 400 500 600'], } if run == 2: files = ['work/mc15_25ns.root'], algo = ['ak4PFJetsCHS'], elif run == 1: files = ['work/mc.root'], algo = ['ak5PFJetsCHS'], for parameter in parameterlist_jet1: #Tree-plots d_1 = { #get data 'files': files, 'algorithms': algo, 'corrections': ['L1L2L3'], #binning 'x_expressions': ["genjet1pt", "genmuminuspt", "genzpt"], 'y_expressions': [ jmzexpress["jet{}".format(parameter)], jmzexpress["mu{}".format(parameter)], jmzexpress["z{}".format(parameter)] ], 'y_label': jmzlabel['{}'.format(parameter)], 'tree_draw_options': 'profs', 'x_bins': bins[parameter], #nicknames, text 'nicks': ["jet1", "mu", "z"], 'labels': [latex["jet1"], latex["muminus"], latex["z"]], 'colors': [color['jet'], color['mu'], color['z']], 'texts': '{} - $error$ $bars$ $show$ $standard$ $deviation$'.format( latex[parameter]), 'x_label': "{}$/GeV$".format(latex["pt"]), 'y_label': (r"{}$_{{reco}}/${}$_{{gen}}$".format(latex[parameter], latex[parameter])), 'x_log': True, #formatting 'filename': 'comparison_rel_recogen_{}_tree'.format(parameter), 'markers': ['_', '4', '3'], 'marker_fill_styles': ['none', 'none', 'none'], 'line_styles': ['-'], 'step': 'True', } plots.append(d_1) # shows errors in bin contents d_2 = { #get data 'files': files, 'algorithms': algo, 'corrections': ['L1L2L3'], #binning 'x_expressions': ["genjet1pt", "genmuminuspt", "genzpt"], 'y_expressions': [ jmzexpress["jet{}".format(parameter)], jmzexpress["mu{}".format(parameter)], jmzexpress["z{}".format(parameter)] ], 'tree_draw_options': 'profs', 'x_bins': bins[parameter], 'analysis_modules': [ 'ConvertToHistogram', 'StatisticalErrors', ], 'stat_error_nicks': ["jet1", "mu", "z"], 'convert_nicks': ["jet1", "mu", "z"], #nicknames, text 'nicks': ["jet1", "mu", "z"], 'labels': [latex["jet1"], latex["muminus"], latex["z"]], 'colors': [color['jet'], color['mu'], color['z']], 'x_label': "{}$/GeV$".format(latex["pt"]), 'y_label': "{} $resolution$".format(latex[parameter]), 'texts': '{} - $statistical$ $errors$'.format(latex[parameter]), 'x_log': True, #formatting 'y_errors': 'none', 'filename': 'comparison_rel_recogen_{}_staterrors'.format(parameter), 'markers': ['_', '4', '3'], 'marker_fill_styles': ['none', 'none', 'none'], 'line_styles': ['-'], 'step': 'True', } plots.append(d_2) for d in plots: d.update({ # web gallery options 'www_title': 'Reco-gen-comparisons', 'www_text': 'Comparison of reco- and gen-level pT,eta,phi of muons, jets and Z bosons for different weightings of pt. High resolution-value indicates worse resolution than low res-value.', }) harryinterface.harry_interface(plots, args)
def jet_muon_z_comparison(args=None, additional_dictionary=None, run=2): """9 plots: 1D-plots of Z/genZ, muminus/genmuminus and jet1/genjet1 together in one diagram for pt, phi, eta each, with weights for pt>50, 50<pt<100, pt>100 """ plots = [] parameterlist_jet1 = ['pt', 'phi', 'eta'] weightinglist_pt = [ "0_pt_noweight", "1_pt_lower50", "2_pt_50to100", "3_pt_higher100" ] if run == 2: files = ['work/mc15_25ns.root'], algo = ['ak4PFJetsCHS'], elif run == 1: files = ['work/mc.root'], algo = ['ak5PFJetsCHS'], for parameter in parameterlist_jet1: for selection in weightinglist_pt: #1D-plots d_1 = { #get data 'files': files, 'corrections': ['L1L2L3'], 'algorithms': algo, #binning 'x_expressions': [ jmzexpress["jet{}".format(parameter)], jmzexpress["mu{}".format(parameter)], jmzexpress["z{}".format(parameter)] ], 'x_label': jmzlabel['{}'.format(parameter)], 'x_bins': jmzbin['{}'.format(parameter)], #weights and normalization 'weights': weighting_z[selection], 'analysis_modules': [ 'NormalizeToFirstHisto', ], #nicknames, text 'nicks': ["jet1", "mu", "z"], 'labels': [latex["jet1"], latex["muminus"], latex["z"]], 'colors': [color['jet'], color['mu'], color['z']], 'texts': '{}'.format(latex[selection]), 'title': 'Reconstruction of {}'.format(latex[parameter]), #formatting 'filename': 'comparison_rel_recogen_{}_{}'.format(parameter, selection), 'markers': ['_', '4', '3'], 'marker_fill_styles': ['none', 'none', 'none'], 'line_styles': ['-'], 'step': True, } plots.append(d_1) #print d_1 for d in plots: d.update({ # web gallery options 'www_title': 'Reco-gen-comparisons', 'www_text': 'Comparison of reco- and gen-level pT,eta,phi of muons, jets and Z bosons for different weightings of pt.', }) harryinterface.harry_interface(plots, args)
def ee_jet_muon_comp_npv_tree(args=None, additional_dictionary=None, run=2): """Comparison of jet, muon, e reconstruction depending on number of pileupevents (npv): Tree-plots of eminus/geneminus, muminus/genmuminus and jet1/genjet1 together in one diagram for pt, phi, eta each. Additionally, plots of statistical errors of said Tree-plots depending on npv. """ plots = [] parameterlist_jet1 = ['pt', 'phi', 'eta'] bins = { "pt": ['35,-0.5,34.5'], "phi": ['35,-0.5,34.5'], "eta": ['35,-0.5,34.5'], } weightlist = { "e": "(eminuspt/geneminuspt>0&&eminuspt/geneminuspt<5)", "jet": "(jet1pt/genjet1pt>0&&jet1pt/genjet1pt<5)", "mu": "(muminuspt/genmuminuspt>0&&muminuspt/genmuminuspt<5)", } if run == 2: files = [ 'work/mc15_25ns_ee.root', 'work/mc15_25ns.root', 'work/mc15_25ns.root' ], algo = ['ak4PFJetsCHS'], elif run == 1: files = ['work/mc_ee.root', 'work/mc.root', 'work/mc.root'], algo = ['ak5PFJetsCHS'], for parameter in parameterlist_jet1: #Tree-plots d_1 = { #get data 'files': files, 'algorithms': algo, 'corrections': ['L1L2L3'], 'zjetfolders': ['zcuts'], 'weights': [weightlist['e'], weightlist['jet'], weightlist['mu']], #binning 'x_expressions': ["npv", "npv", "npv"], 'y_expressions': [ ejmexpress["e{}".format(parameter)], ejmexpress["jet{}".format(parameter)], ejmexpress["mu{}".format(parameter)] ], 'tree_draw_options': 'profs', #'x_bins': bins[parameter], 'x_log': True, #formatting 'nicks': ["eminus", "jet1", "mu"], 'labels': [latex["eminus"], latex["jet1"], latex["muminus"]], 'colors': [color['e'], color['jet'], color['mu']], 'texts': '{} - $error$ $bars$ $show$ $standard$ $deviation$'.format( latex[parameter]), 'x_label': "$pileup$ $activity$ $n_{{PV}}$", 'y_label': ejmlabel['{}'.format(parameter)], 'title': 'Reconstruction of {} \n depending on npv'.format( latex[parameter], latex['pt']), 'markers': ['_', '4', '3'], 'marker_fill_styles': ['none', 'none', 'none'], 'line_styles': ['-'], 'step': 'True', 'filename': 'resolution_{}_pileup_tree'.format(parameter), } plots.append(d_1) # shows errors in bin contents d_2 = { #get data 'files': files, 'algorithms': algo, 'corrections': ['L1L2L3'], 'zjetfolders': ['zcuts'], 'weights': [weightlist['jet'], weightlist['mu'], weightlist['e']], #binning 'x_expressions': ["npv", "npv", "npv"], 'y_expressions': [ ejmexpress["e{}".format(parameter)], ejmexpress["jet{}".format(parameter)], ejmexpress["mu{}".format(parameter)] ], 'tree_draw_options': 'profs', 'x_bins': bins[parameter], 'x_log': True, 'analysis_modules': [ 'ConvertToHistogram', 'StatisticalErrors', ], 'stat_error_nicks': ["e", "jet1", "mu"], 'convert_nicks': ["e", "jet1", "mu"], #formatting 'nicks': ["e", "jet1", "mu"], 'labels': [latex["eminus"], latex["jet1"], latex["muminus"]], 'colors': [color['e'], color['jet'], color['mu']], 'x_label': "$pileup$ $activity$ $npv$".format(latex["pt"]), 'y_label': "{} $resolution$".format(latex[parameter]), 'texts': '{} - $statistical$ $errors$'.format(latex[parameter]), 'title': 'Resolution of {} \n depending on $n_{{PV}}$'.format( latex[parameter]), 'y_errors': 'none', 'markers': ['.', '.', '.'], 'marker_fill_styles': ['full', 'full', 'full'], 'line_styles': ['-'], 'step': 'True', 'filename': 'resolution_{}_pileup_staterrors'.format(parameter), 'y_lims': [0, 0.5], } plots.append(d_2) for d in plots: d.update({ # web gallery options 'www_title': 'Reco-gen-comparisons (tree): jet muon eminus', 'www_text': 'Comparison of pT,eta,phi resolution of muons, jets and electrons as a function on pileup activity. High resolution-value indicates worse resolution than low res-value.', }) harryinterface.harry_interface(plots, args)
def ee_jet_muon_comparison_tree(args=None, additional_dictionary=None, run=2): """Comparison of jet, muon, e reconstruction depending on pt: Tree-plots of eminus/geneminus, muminus/genmuminus and jet1/genjet1 together in one diagram for pt, phi, eta each. Additionally, plots of statistical errors of said Tree-plots depending on pt. """ plots = [] parameterlist_jet1 = ['pt', 'phi', 'eta'] bins = { "pt": ['20 30 40 50 60 70 95 150 280 400 700'], "phi": ['20 30 40 50 60 70 95 150 280 400 700'], "eta": ['20 30 40 50 60 70 95 150 280 400 700'], } if run == 2: files = [ 'work/mc15_25ns_ee.root', 'work/mc15_25ns.root', 'work/mc15_25ns.root' ], algo = ['ak4PFJetsCHS'], elif run == 1: files = ['work/mc_ee.root', 'work/mc.root', 'work/mc.root'], algo = ['ak5PFJetsCHS'], for parameter in parameterlist_jet1: #Tree-plots d_1 = { #get data 'files': files, 'corrections': ['L1L2L3'], 'algorithms': algo, #'zjetfolders':['zcuts'], #binning 'x_expressions': ["geneminuspt", "genjet1pt", "genmuminuspt"], 'y_expressions': [ ejmexpress["e{}".format(parameter)], ejmexpress["jet{}".format(parameter)], ejmexpress["mu{}".format(parameter)] ], 'tree_draw_options': 'profs', "x_ticks": [20, 30, 50, 70, 100, 200, 400, 700], 'x_bins': bins[parameter], 'x_log': True, #formatting 'nicks': ["eminus", "jet1", "mu"], 'labels': [latex["eminus"], latex["jet1"], latex["muminus"]], 'colors': [color['e'], color['jet'], color['mu']], 'texts': '{} - $error$ $bars$ $show$ $standard$ $deviation$'.format( latex[parameter]), 'x_label': "{}$/GeV$".format(latex["pt"]), 'y_label': ejmlabel['{}'.format(parameter)], #'title':'Reconstruction of {} \n depending on {}'.format(latex[parameter], latex['pt']), 'markers': ['_', '4', '3'], 'marker_fill_styles': ['none', 'none', 'none'], 'line_styles': ['-'], 'step': 'True', 'filename': 'comparison_rel_recogen_{}_tree'.format(parameter), } plots.append(d_1) # shows errors in bin contents d_2 = { #get data 'files': files, 'corrections': ['L1L2L3'], 'algorithms': algo, #'zjetfolders':['zcuts'], #binning 'x_expressions': ["geneminuspt", "genjet1pt", "genmuminuspt"], 'y_expressions': [ ejmexpress["e{}".format(parameter)], ejmexpress["jet{}".format(parameter)], ejmexpress["mu{}".format(parameter)] ], 'tree_draw_options': 'profs', "x_ticks": [20, 30, 50, 70, 100, 200, 400, 700], 'x_bins': bins[parameter], 'x_log': True, 'analysis_modules': [ 'ConvertToHistogram', 'StatisticalErrors', ], 'stat_error_nicks': ["e", "jet1", "mu"], 'convert_nicks': ["e", "jet1", "mu"], #formatting 'nicks': ["e", "jet1", "mu"], 'labels': [latex["eminus"], latex["jet1"], latex["muminus"]], 'colors': [color['e'], color['jet'], color['mu']], 'x_label': "{}$/GeV$".format(latex["pt"]), 'y_label': "{} $resolution$".format(latex[parameter]), 'texts': '{} - $statistical$ $errors$'.format(latex[parameter]), #'title':'Resolution of {} \n depending on {}'.format(latex[parameter], latex['pt']), 'y_errors': 'none', 'markers': ['.', '.', '.'], 'marker_fill_styles': ['full', 'full', 'full'], 'line_styles': ['-'], 'step': 'True', 'filename': 'comparison_rel_recogen_{}_staterrors'.format(parameter), } plots.append(d_2) for d in plots: d.update({ # web gallery options 'www_title': 'Reco-gen-comparisons (tree): jet muon eminus', 'www_text': 'Comparison of reco- and gen-level pT,eta,phi of muons, jets and electrons for different weightings of pt. High resolution-value indicates worse resolution than low res-value.', }) harryinterface.harry_interface(plots, args)