From acf8ce757375e837ff2aeb7781f5f291daae41fe Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 28 Sep 2021 18:09:39 +0200 Subject: [PATCH 01/18] Configure the AllenSelReportsToTES` --- .../python/HltEfficiencyChecker/config.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py b/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py index 166e1eb..cada993 100644 --- a/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py +++ b/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py @@ -15,14 +15,13 @@ from PyConf.control_flow import CompositeNode, NodeLogic from PyConf.application import make_odin from Moore.config import (moore_control_flow, setup_ann_service, get_allen_hlt1_decision_ids) -from PyConf.Algorithms import MCDecayTreeTuple, EventTuple +from PyConf.Algorithms import MCDecayTreeTuple, EventTuple, AllenSelReportsToTES from Configurables import (TupleToolTrigger, TupleToolEventInfo, MCTupleToolKinematic, MCTupleToolReconstructed, MCTupleToolTOSHLT1, MCTupleToolTOSHLT2) from RecoConf.mc_checking import make_links_lhcbids_mcparticles_tracking_system from RecoConf.data_from_file import mc_unpackers, make_mc_track_info -from RecoConf.hlt1_allen import (make_allen_dec_reports, sequence as - allen_sequence) +from RecoConf.hlt1_allen import make_allen_dec_reports, make_allen_output def _mc_decay_tree_tuple_input_transform(MCParticles, MCVertices, MCTrackInfo): @@ -95,6 +94,7 @@ def add_efficiency_tuples_allen(allen_node, descriptor_template=None): decision_names = list(Hlt1SelectionIDs.keys()) # Get Allen DecReports location + # FIXME allen_node already has this as a child. Are they being made twice? dec_rep_loc = make_allen_dec_reports().location # Now set up the Tuple Tools to be added to the control flow to save trigger & kinematic info @@ -105,6 +105,12 @@ def add_efficiency_tuples_allen(allen_node, descriptor_template=None): mcttrec = MCTupleToolReconstructed(Associate=False, FillPID=False) # FIXME the Reconstructed flag from MCTupleToolReconstructed doesn't work yet + # SelReports... + allen_wrapper = make_allen_output() + allen_sel_rep_writer = AllenSelReportsToTES(AllenOutput=allen_wrapper) + # This then needs to feed into the HltSelReportsDecoder I think... + + # Want the following tools for both rates and line efficiencies tuple_flag = 'MCDecayTreeTuple' if efficiency_mode else 'EventTuple' ttt = TupleToolTrigger( -- GitLab From ce0e2503fd36249205e7979175d8f5e8fa107cd5 Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 28 Sep 2021 18:17:59 +0200 Subject: [PATCH 02/18] First try to string it all together. Not working yet --- .../python/HltEfficiencyChecker/config.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py b/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py index cada993..e3df2cb 100644 --- a/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py +++ b/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py @@ -15,7 +15,7 @@ from PyConf.control_flow import CompositeNode, NodeLogic from PyConf.application import make_odin from Moore.config import (moore_control_flow, setup_ann_service, get_allen_hlt1_decision_ids) -from PyConf.Algorithms import MCDecayTreeTuple, EventTuple, AllenSelReportsToTES +from PyConf.Algorithms import MCDecayTreeTuple, EventTuple, AllenSelReportsToTES, HltSelReportsDecoder from Configurables import (TupleToolTrigger, TupleToolEventInfo, MCTupleToolKinematic, MCTupleToolReconstructed, MCTupleToolTOSHLT1, MCTupleToolTOSHLT2) @@ -109,6 +109,17 @@ def add_efficiency_tuples_allen(allen_node, descriptor_template=None): allen_wrapper = make_allen_output() allen_sel_rep_writer = AllenSelReportsToTES(AllenOutput=allen_wrapper) # This then needs to feed into the HltSelReportsDecoder I think... + sel_rep_decoder = HltSelReportsDecoder( + RawEventLocations=allen_sel_rep_writer.OutputSelReports, + SourceID=1 + ) + sel_rep_loc = sel_rep_decoder.OutputHltSelReportsLocation.location + mctttos = MCTupleToolTOSHLT1( + 'MCDecayTreeTuple.MCTupleToolTOSHLT1', + TriggerList=decision_names, + MC2IDLink=make_links_lhcbids_mcparticles_tracking_system(). + location, + HltSelReports=sel_rep_loc) # Want the following tools for both rates and line efficiencies @@ -137,7 +148,7 @@ def add_efficiency_tuples_allen(allen_node, descriptor_template=None): Branches=branches, ToolList=tool_list + [mcttkin.getFullName(), - mcttrec.getFullName()]) + mcttrec.getFullName(), mctttos.getFullName()]) nodes = [mcdtt] else: et = EventTuple(ToolList=tool_list) -- GitLab From e54b17811d7c406c4cfb20f16cd3dfeec575ca74 Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 28 Sep 2021 18:32:18 +0200 Subject: [PATCH 03/18] get control flow to initialise now --- HltEfficiencyChecker/python/HltEfficiencyChecker/config.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py b/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py index e3df2cb..bcde637 100644 --- a/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py +++ b/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py @@ -149,7 +149,9 @@ def add_efficiency_tuples_allen(allen_node, descriptor_template=None): ToolList=tool_list + [mcttkin.getFullName(), mcttrec.getFullName(), mctttos.getFullName()]) - nodes = [mcdtt] + # mcttrec.getFullName()]) + nodes = [make_links_lhcbids_mcparticles_tracking_system(), + make_mc_track_info(), sel_rep_decoder, mcdtt] else: et = EventTuple(ToolList=tool_list) nodes = [et] -- GitLab From 9181e86f211559939515079676c4c28a7bfa288a Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Wed, 29 Sep 2021 18:01:56 +0200 Subject: [PATCH 04/18] Cleanup and fix formmatting --- .../python/HltEfficiencyChecker/config.py | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py b/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py index bcde637..96a016d 100644 --- a/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py +++ b/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py @@ -94,7 +94,6 @@ def add_efficiency_tuples_allen(allen_node, descriptor_template=None): decision_names = list(Hlt1SelectionIDs.keys()) # Get Allen DecReports location - # FIXME allen_node already has this as a child. Are they being made twice? dec_rep_loc = make_allen_dec_reports().location # Now set up the Tuple Tools to be added to the control flow to save trigger & kinematic info @@ -105,14 +104,11 @@ def add_efficiency_tuples_allen(allen_node, descriptor_template=None): mcttrec = MCTupleToolReconstructed(Associate=False, FillPID=False) # FIXME the Reconstructed flag from MCTupleToolReconstructed doesn't work yet - # SelReports... allen_wrapper = make_allen_output() allen_sel_rep_writer = AllenSelReportsToTES(AllenOutput=allen_wrapper) - # This then needs to feed into the HltSelReportsDecoder I think... sel_rep_decoder = HltSelReportsDecoder( RawEventLocations=allen_sel_rep_writer.OutputSelReports, - SourceID=1 - ) + SourceID=1) sel_rep_loc = sel_rep_decoder.OutputHltSelReportsLocation.location mctttos = MCTupleToolTOSHLT1( 'MCDecayTreeTuple.MCTupleToolTOSHLT1', @@ -121,7 +117,6 @@ def add_efficiency_tuples_allen(allen_node, descriptor_template=None): location, HltSelReports=sel_rep_loc) - # Want the following tools for both rates and line efficiencies tuple_flag = 'MCDecayTreeTuple' if efficiency_mode else 'EventTuple' ttt = TupleToolTrigger( @@ -146,12 +141,15 @@ def add_efficiency_tuples_allen(allen_node, descriptor_template=None): mcdtt = _mc_decay_tree_tuple( Decay=decay, Branches=branches, - ToolList=tool_list + - [mcttkin.getFullName(), - mcttrec.getFullName(), mctttos.getFullName()]) - # mcttrec.getFullName()]) - nodes = [make_links_lhcbids_mcparticles_tracking_system(), - make_mc_track_info(), sel_rep_decoder, mcdtt] + ToolList=tool_list + [ + mcttkin.getFullName(), + mcttrec.getFullName(), + mctttos.getFullName() + ]) + nodes = [ + make_links_lhcbids_mcparticles_tracking_system(), + make_mc_track_info(), sel_rep_decoder, mcdtt + ] else: et = EventTuple(ToolList=tool_list) nodes = [et] -- GitLab From b3314a00a835a0c86bc50a1a1f12dec635391e1f Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Mon, 4 Oct 2021 18:40:29 +0200 Subject: [PATCH 05/18] Add ability to specify which particles you want to TOS with --- .../scripts/hlt_line_efficiencies.py | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py index 257f999..5add26f 100755 --- a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py +++ b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py @@ -68,6 +68,12 @@ def get_parser(): '--reconstructible-children', required=True, help='Comma-separated list of child names.') + parser.add_argument( + '--TOS-match-to', + type=str, + default="", + help='Comma-separated list of particle names (specified in the annotated decay descriptor) that you\'d like to see TOS efficiences for.' + ) parser.add_argument('--make-plots', action='store_true') parser.add_argument( '--legend-header', @@ -226,7 +232,7 @@ def main(): lines = [] if args.lines: for key in args.lines.split(','): - if key in lines_in_tree or key in tos_lines_in_tree: + if key in lines_in_tree: lines.append(key) else: print( @@ -235,12 +241,31 @@ def main(): ) else: print("INFO:\t No lines specified. Defaulting to all...") - lines = lines_in_tree + tos_lines_in_tree + lines = lines_in_tree if lines == []: print( "WARNING:\t None of the lines specified are implemented. Defaulting to all lines that are present." ) - lines = lines_in_tree + tos_lines_in_tree + lines = lines_in_tree + + # Now add the TOS efficiencies that were requested + if not args.TOS_match_to: + print("INFO:\t Which particles to show TOS efficiencies for was unspecified. Defaulting to all...") + lines += tos_lines_in_tree + + tos_lines = [] + for particle_pfx in args.TOS_match_to.split(','): + for line in lines: + tos_name = f"{particle_pfx}_{line}TOS" + if tos_name in tos_lines_in_tree: + tos_lines.append(tos_name) + else: + # TODO should this be a failure? And the above too? + print( + "WARNING:\t Parsed TOS decision " + tos_name + + " does not have a branch in the tree. Skipping this line." + ) + lines += tos_lines length = max([len(line) for line in lines]) # for formatting # Split the lines into TOS and DEC lines for ease later -- GitLab From 5201d06fd88a7761fb803472f0f5d0852c9ec936 Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Mon, 4 Oct 2021 23:06:50 +0200 Subject: [PATCH 06/18] TOS eff extra plots --- .../scripts/hlt_line_efficiencies.py | 69 +++++++++++++++++-- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py index 5add26f..d2fa509 100755 --- a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py +++ b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py @@ -71,7 +71,7 @@ def get_parser(): parser.add_argument( '--TOS-match-to', type=str, - default="", + default=None, help='Comma-separated list of particle names (specified in the annotated decay descriptor) that you\'d like to see TOS efficiences for.' ) parser.add_argument('--make-plots', action='store_true') @@ -254,8 +254,8 @@ def main(): lines += tos_lines_in_tree tos_lines = [] - for particle_pfx in args.TOS_match_to.split(','): - for line in lines: + if args.TOS_match_to: + for particle_pfx, line in product(args.TOS_match_to.split(','), lines): tos_name = f"{particle_pfx}_{line}TOS" if tos_name in tos_lines_in_tree: tos_lines.append(tos_name) @@ -563,15 +563,15 @@ def main(): eff_histos[shape_hist_denom + "__distr"].Draw("HIST") events_with_this_denom = get_events_in_plot( shape_hist_denom) - for denom_key, line in product(denoms.keys(), lines): - # Loop over *lines*, not args.lines, as *lines* was cleaned of bad lines above + for denom_key, dec_line in product(denoms.keys(), dec_lines): + # Loop over *dec_lines*, not args.lines, as *dec_lines* was cleaned of bad lines above this_histo = eff_histos["{}__{}__eff".format( - denom_key, line)] + denom_key, dec_line)] this_histo.Draw("SAME PE0") if args.no_legend: print_colour_and_marker(this_histo) line_at_one, legend = plot_legend_and_line_at_one( - denoms.keys(), lines, events_with_this_denom, + denoms.keys(), dec_lines, events_with_this_denom, shape_hist_denom, logx) line_at_one.Draw("SAME") if not args.no_legend: legend.Draw() @@ -582,6 +582,61 @@ def main(): "log" if logx else "", var.replace( ":", "_"), args.plot_format)) + # Need a plot of all TOS effs for 1 line, with 1 denominator + # Either this ends up being every line or what is specified through args.lines + for dec_line, logx, denom_key in product(dec_lines, [True, False], denoms.keys()): + tos_lines_this_dec_line = [tos_line for tos_line in tos_lines if dec_line in tos_line] + c = TCanvas() + c.SetLogx(logx) + # Plot the shape hist + eff_histos[denom_key + "__distr"].Draw("HIST") + events_with_this_denom = get_events_in_plot( + denom_key) + eff_histos["{}__{}__eff".format( + denom_key, dec_line)].Draw("SAME PE0") + + for tos_line in tos_lines_this_dec_line: + eff_histos["{}__{}__eff".format( + denom_key, tos_line)].Draw("SAME PE0") + + line_at_one, legend = plot_legend_and_line_at_one( + [denom_key], [dec_line]+tos_lines_this_dec_line, events_with_this_denom, + denom_key, logx) + line_at_one.Draw("SAME") + if not args.no_legend: legend.Draw() + + c.Print('{}AllTOSEfficiencies__{}__{}__{}.{}'.format( + args.plot_prefix, dec_line, denom_key, + ("log" if logx else "") + var.replace( + ':', '_'), args.plot_format)) + + particles_that_have_tos_effs_in_tree = {tos_line.split("_")[0] for tos_line in tos_lines_in_tree} + if not args.TOS_match_to: + args.TOS_match_to = ",".join(particles_that_have_tos_effs_in_tree) + + for mcp, denom_key, logx in product(args.TOS_match_to.split(','), denoms, [True, False]): + # All TOS effs w.r.t. this particle + tos_lines_this_mcp = [tos_line for tos_line in tos_lines if tos_line.split("_")[0] == mcp] + # Plot the shape hist + eff_histos[denom_key + "__distr"].Draw("HIST") + events_with_this_denom = get_events_in_plot( + denom_key) + + for tos_line in tos_lines_this_mcp: + eff_histos["{}__{}__eff".format( + denom_key, tos_line)].Draw("SAME PE0") + + line_at_one, legend = plot_legend_and_line_at_one( + [denom_key], tos_lines_this_mcp, events_with_this_denom, + denom_key, logx) + line_at_one.Draw("SAME") + if not args.no_legend: legend.Draw() + + c.Print('{}TOSEfficiencies__{}__{}__{}.{}'.format( + args.plot_prefix, mcp, denom_key, + ("log" if logx else "") + var.replace( + ':', '_'), args.plot_format)) + # Now make a plot for each line with all the specified denominators for line in lines: for logx in [True, False]: -- GitLab From 13323793da81c6275c157bdd9f34cd25c469d095 Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 5 Oct 2021 10:05:21 +0200 Subject: [PATCH 07/18] Remove redundant plot --- .../scripts/hlt_line_efficiencies.py | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py index d2fa509..c653478 100755 --- a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py +++ b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py @@ -614,28 +614,30 @@ def main(): if not args.TOS_match_to: args.TOS_match_to = ",".join(particles_that_have_tos_effs_in_tree) - for mcp, denom_key, logx in product(args.TOS_match_to.split(','), denoms, [True, False]): - # All TOS effs w.r.t. this particle - tos_lines_this_mcp = [tos_line for tos_line in tos_lines if tos_line.split("_")[0] == mcp] - # Plot the shape hist - eff_histos[denom_key + "__distr"].Draw("HIST") - events_with_this_denom = get_events_in_plot( - denom_key) + if len(dec_lines) > 1: + # If not then this plot ends up the same as one produced below + for mcp, denom_key, logx in product(args.TOS_match_to.split(','), denoms, [True, False]): + # All TOS effs w.r.t. this particle + tos_lines_this_mcp = [tos_line for tos_line in tos_lines if tos_line.split("_")[0] == mcp] + # Plot the shape hist + eff_histos[denom_key + "__distr"].Draw("HIST") + events_with_this_denom = get_events_in_plot( + denom_key) - for tos_line in tos_lines_this_mcp: - eff_histos["{}__{}__eff".format( - denom_key, tos_line)].Draw("SAME PE0") + for tos_line in tos_lines_this_mcp: + eff_histos["{}__{}__eff".format( + denom_key, tos_line)].Draw("SAME PE0") - line_at_one, legend = plot_legend_and_line_at_one( - [denom_key], tos_lines_this_mcp, events_with_this_denom, - denom_key, logx) - line_at_one.Draw("SAME") - if not args.no_legend: legend.Draw() + line_at_one, legend = plot_legend_and_line_at_one( + [denom_key], tos_lines_this_mcp, events_with_this_denom, + denom_key, logx) + line_at_one.Draw("SAME") + if not args.no_legend: legend.Draw() - c.Print('{}TOSEfficiencies__{}__{}__{}.{}'.format( - args.plot_prefix, mcp, denom_key, - ("log" if logx else "") + var.replace( - ':', '_'), args.plot_format)) + c.Print('{}TOSEfficiencies__{}__{}__{}.{}'.format( + args.plot_prefix, mcp, denom_key, + ("log" if logx else "") + var.replace( + ':', '_'), args.plot_format)) # Now make a plot for each line with all the specified denominators for line in lines: -- GitLab From a40acf861f25a1556fb511f990fd1f90119b3fba Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 5 Oct 2021 11:20:36 +0200 Subject: [PATCH 08/18] Follow LHCb!3260 --- HltEfficiencyChecker/python/HltEfficiencyChecker/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py b/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py index 96a016d..68a0e86 100644 --- a/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py +++ b/HltEfficiencyChecker/python/HltEfficiencyChecker/config.py @@ -108,7 +108,7 @@ def add_efficiency_tuples_allen(allen_node, descriptor_template=None): allen_sel_rep_writer = AllenSelReportsToTES(AllenOutput=allen_wrapper) sel_rep_decoder = HltSelReportsDecoder( RawEventLocations=allen_sel_rep_writer.OutputSelReports, - SourceID=1) + SourceID='Hlt1') sel_rep_loc = sel_rep_decoder.OutputHltSelReportsLocation.location mctttos = MCTupleToolTOSHLT1( 'MCDecayTreeTuple.MCTupleToolTOSHLT1', -- GitLab From dd16d25658c22fcdc58365d873dce9692f4a38bf Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 5 Oct 2021 11:27:30 +0200 Subject: [PATCH 09/18] Fix ft_decoding_version --- HltEfficiencyChecker/options/hlt1_eff_default.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/HltEfficiencyChecker/options/hlt1_eff_default.yaml b/HltEfficiencyChecker/options/hlt1_eff_default.yaml index 01a8afa..b881ee2 100644 --- a/HltEfficiencyChecker/options/hlt1_eff_default.yaml +++ b/HltEfficiencyChecker/options/hlt1_eff_default.yaml @@ -6,6 +6,7 @@ job: trigger_level: 1 evt_max: 100 testfiledb_key: Upgrade_BsPhiPhi_MD_FTv4_DIGI + ft_decoding_version: 4 # # You can also define the input files and/or the processing conditions: # -- GitLab From f292b1a00bb5e13c9ad738229015789f77ca5254 Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 5 Oct 2021 12:33:09 +0200 Subject: [PATCH 10/18] Smarter working out of what efficiencies to print/plots to make --- HltEfficiencyChecker/scripts/hlt_line_efficiencies.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py index c653478..d3d307d 100755 --- a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py +++ b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py @@ -249,11 +249,12 @@ def main(): lines = lines_in_tree # Now add the TOS efficiencies that were requested + tos_lines = [] if not args.TOS_match_to: print("INFO:\t Which particles to show TOS efficiencies for was unspecified. Defaulting to all...") - lines += tos_lines_in_tree + for line in lines: + tos_lines += [tos_line for tos_line in tos_lines_in_tree if line in tos_line] - tos_lines = [] if args.TOS_match_to: for particle_pfx, line in product(args.TOS_match_to.split(','), lines): tos_name = f"{particle_pfx}_{line}TOS" @@ -610,7 +611,7 @@ def main(): ("log" if logx else "") + var.replace( ':', '_'), args.plot_format)) - particles_that_have_tos_effs_in_tree = {tos_line.split("_")[0] for tos_line in tos_lines_in_tree} + particles_that_have_tos_effs_in_tree = {tos_line.split("_Hlt")[0] for tos_line in tos_lines_in_tree} if not args.TOS_match_to: args.TOS_match_to = ",".join(particles_that_have_tos_effs_in_tree) @@ -618,7 +619,7 @@ def main(): # If not then this plot ends up the same as one produced below for mcp, denom_key, logx in product(args.TOS_match_to.split(','), denoms, [True, False]): # All TOS effs w.r.t. this particle - tos_lines_this_mcp = [tos_line for tos_line in tos_lines if tos_line.split("_")[0] == mcp] + tos_lines_this_mcp = [tos_line for tos_line in tos_lines if tos_line.split("_Hlt")[0] == mcp] # Plot the shape hist eff_histos[denom_key + "__distr"].Draw("HIST") events_with_this_denom = get_events_in_plot( -- GitLab From 36cb7cf4a94192f9ea6349a192bc8c050243ab3d Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 5 Oct 2021 15:50:12 +0200 Subject: [PATCH 11/18] Use default FT decoding version if not specified --- HltEfficiencyChecker/options/options_template.py.jinja | 2 -- 1 file changed, 2 deletions(-) diff --git a/HltEfficiencyChecker/options/options_template.py.jinja b/HltEfficiencyChecker/options/options_template.py.jinja index 595c80d..e060620 100644 --- a/HltEfficiencyChecker/options/options_template.py.jinja +++ b/HltEfficiencyChecker/options/options_template.py.jinja @@ -58,8 +58,6 @@ if {{ job. debug_mode }}: from RecoConf.hlt1_tracking import default_ft_decoding_version {% if job.ft_decoding_version is defined %} default_ft_decoding_version.global_bind(value={{ job.ft_decoding_version }}) -{% else %} -default_ft_decoding_version.global_bind(value=6) {% endif %} from RecoConf.global_tools import stateProvider_with_simplified_geom -- GitLab From 404a310fefcd87b0ec0caa212335792ac521d13f Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 5 Oct 2021 15:50:33 +0200 Subject: [PATCH 12/18] Add TOS_match_to to HLT2 example --- HltEfficiencyChecker/options/hlt2_eff_example.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/HltEfficiencyChecker/options/hlt2_eff_example.yaml b/HltEfficiencyChecker/options/hlt2_eff_example.yaml index f19c26e..399577c 100644 --- a/HltEfficiencyChecker/options/hlt2_eff_example.yaml +++ b/HltEfficiencyChecker/options/hlt2_eff_example.yaml @@ -40,4 +40,5 @@ analysis: # which is passed in a file such as eff_ntuple.root.json, but can also be given: # parent: B_s0 legend_header: "B^{0}_{s} #rightarrow J/#Psi#phi" + TOS_match_to: "Bs" make_plots: true -- GitLab From 814d4e3ab61c35eebbccbbd2fef05f3a809d02e1 Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 5 Oct 2021 15:51:55 +0200 Subject: [PATCH 13/18] Better plot naming and remove unnecessary plots --- .../scripts/hlt_line_efficiencies.py | 34 +++---------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py index d3d307d..b12e2cb 100755 --- a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py +++ b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py @@ -577,7 +577,7 @@ def main(): line_at_one.Draw("SAME") if not args.no_legend: legend.Draw() - c.Print('{}Efficiency__AllLines{}__{}{}.{}'.format( + c.Print('{}Efficiencies__AllLines{}__{}{}.{}'.format( args.plot_prefix, "__AllDenoms" if len(denoms) > 1 else "", "log" if logx else "", var.replace( @@ -606,7 +606,7 @@ def main(): line_at_one.Draw("SAME") if not args.no_legend: legend.Draw() - c.Print('{}AllTOSEfficiencies__{}__{}__{}.{}'.format( + c.Print('{}Efficiencies__{}__{}__{}.{}'.format( args.plot_prefix, dec_line, denom_key, ("log" if logx else "") + var.replace( ':', '_'), args.plot_format)) @@ -635,38 +635,12 @@ def main(): line_at_one.Draw("SAME") if not args.no_legend: legend.Draw() - c.Print('{}TOSEfficiencies__{}__{}__{}.{}'.format( + c.Print('{}{}__TOSEfficiencies__{}__{}.{}'.format( args.plot_prefix, mcp, denom_key, ("log" if logx else "") + var.replace( ':', '_'), args.plot_format)) - # Now make a plot for each line with all the specified denominators - for line in lines: - for logx in [True, False]: - c = TCanvas() - c.SetLogx(logx) - # Plot the shape hist - eff_histos[shape_hist_denom + "__distr"].Draw("HIST") - events_with_this_denom = get_events_in_plot( - shape_hist_denom) - for denom_key in denoms.keys(): - this_histo = eff_histos["{}__{}__eff".format( - denom_key, line)] - this_histo.Draw("SAME PE0") - if args.no_legend: print_colour_and_marker(this_histo) - - line_at_one, legend = plot_legend_and_line_at_one( - denoms.keys(), [line], events_with_this_denom, - shape_hist_denom, logx) - line_at_one.Draw("SAME") - if not args.no_legend: legend.Draw("SAME") - - c.Print('{}Efficiency__{}{}__{}{}.{}'.format( - args.plot_prefix, line, - "__AllDenoms" if len(denoms) > 1 else "", - "log" if logx else "", var.replace( - ":", "_"), args.plot_format)) - + # TODO Test this # Finally, if --denoms > 1, the user may wish to also see a plot for each combination of line and denominator # In this case, there will only ever be 1 denom on the plot, so take shape w.r.t. that denominator. # If len(denoms) = 1, these plots will be identical to the last block, so dont make them. -- GitLab From de46236bb87c087661cb3d478028fa7639e6c367 Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Tue, 5 Oct 2021 17:09:53 +0200 Subject: [PATCH 14/18] Add TOS match to to match the doc example --- HltEfficiencyChecker/options/hlt1_eff_default.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/HltEfficiencyChecker/options/hlt1_eff_default.yaml b/HltEfficiencyChecker/options/hlt1_eff_default.yaml index b881ee2..be110b9 100644 --- a/HltEfficiencyChecker/options/hlt1_eff_default.yaml +++ b/HltEfficiencyChecker/options/hlt1_eff_default.yaml @@ -37,3 +37,4 @@ analysis: make_plots: true vars: "PT,Kplus0:PT" lines: Hlt1TwoTrackMVADecision,Hlt1TrackMVADecision + TOS_match_to: "B_s0,Kplus0" -- GitLab From 4d2b7f9b7c6b21d114e24e4cd0b44e02f50e406f Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Wed, 6 Oct 2021 12:54:54 +0200 Subject: [PATCH 15/18] Add missing FT decoding version to moore HLT1 example and fill in TOS-related extra options --- HltEfficiencyChecker/options/hlt1_eff_example_moore.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/HltEfficiencyChecker/options/hlt1_eff_example_moore.yaml b/HltEfficiencyChecker/options/hlt1_eff_example_moore.yaml index a15ea03..5ea2bd7 100644 --- a/HltEfficiencyChecker/options/hlt1_eff_example_moore.yaml +++ b/HltEfficiencyChecker/options/hlt1_eff_example_moore.yaml @@ -1,12 +1,13 @@ # HltEfficiencyChecker "wizard" example annotated_decay_descriptor: - "[${B_s0}B_s0 => ( J/psi(1S) => ${muplus}mu+ ${muminus}mu- ) ( phi(1020) => ${Kplus}K+ ${Kminus}K- )]CC" + "[${B_s0}B_s0 => ${Jpsi}( J/psi(1S) => ${muplus}mu+ ${muminus}mu- ) ${phi}( phi(1020) => ${Kplus}K+ ${Kminus}K- )]CC" ntuple_path: &NTUPLE eff_ntuple.root job: trigger_level: 1 evt_max: 100 testfiledb_key: upgrade_DC19_01_Bs2JPsiPhi_MD use_moore_as_hlt1: True + ft_decoding_version: 6 # # You can also define the input files and/or the processing conditions: # @@ -34,4 +35,6 @@ analysis: # parent: B_s0 legend_header: "B^{0}_{s} #rightarrow J/#psi#phi" make_plots: true - vars: "PT,muplus:PT" \ No newline at end of file + vars: "PT,muplus:PT" + lines: "Hlt1TrackMVALineDecision,Hlt1TwoTrackMVALineDecision" + TOS_match_to: "B_s0,Jpsi,phi,muplus" \ No newline at end of file -- GitLab From 9ce403f9c7cdd0fdf75bf1f122322f72a0854616 Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Wed, 6 Oct 2021 14:37:24 +0200 Subject: [PATCH 16/18] Give correct FT decoding version --- HltEfficiencyChecker/options/hlt1_rate_example_moore.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/HltEfficiencyChecker/options/hlt1_rate_example_moore.yaml b/HltEfficiencyChecker/options/hlt1_rate_example_moore.yaml index ee56785..cc22a4e 100644 --- a/HltEfficiencyChecker/options/hlt1_rate_example_moore.yaml +++ b/HltEfficiencyChecker/options/hlt1_rate_example_moore.yaml @@ -5,6 +5,7 @@ job: evt_max: 100 testfiledb_key: upgrade_DC19_01_MinBiasMD use_moore_as_hlt1: True + ft_decoding_version: 6 # # Rates can only be calculated w.r.t min bias, but you can specify your own min bias files e.g. # -- GitLab From a2d7bdef39ebef1fc26b908cc3c83d78f195bcf2 Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Wed, 6 Oct 2021 14:38:48 +0200 Subject: [PATCH 17/18] Fix formatting --- .../scripts/hlt_line_efficiencies.py | 70 +++++++++++-------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py index b12e2cb..6e09f70 100755 --- a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py +++ b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py @@ -72,7 +72,8 @@ def get_parser(): '--TOS-match-to', type=str, default=None, - help='Comma-separated list of particle names (specified in the annotated decay descriptor) that you\'d like to see TOS efficiences for.' + help= + 'Comma-separated list of particle names (specified in the annotated decay descriptor) that you\'d like to see TOS efficiences for.' ) parser.add_argument('--make-plots', action='store_true') parser.add_argument( @@ -251,9 +252,13 @@ def main(): # Now add the TOS efficiencies that were requested tos_lines = [] if not args.TOS_match_to: - print("INFO:\t Which particles to show TOS efficiencies for was unspecified. Defaulting to all...") + print( + "INFO:\t Which particles to show TOS efficiencies for was unspecified. Defaulting to all..." + ) for line in lines: - tos_lines += [tos_line for tos_line in tos_lines_in_tree if line in tos_line] + tos_lines += [ + tos_line for tos_line in tos_lines_in_tree if line in tos_line + ] if args.TOS_match_to: for particle_pfx, line in product(args.TOS_match_to.split(','), lines): @@ -264,8 +269,7 @@ def main(): # TODO should this be a failure? And the above too? print( "WARNING:\t Parsed TOS decision " + tos_name + - " does not have a branch in the tree. Skipping this line." - ) + " does not have a branch in the tree. Skipping this line.") lines += tos_lines length = max([len(line) for line in lines]) # for formatting @@ -564,7 +568,8 @@ def main(): eff_histos[shape_hist_denom + "__distr"].Draw("HIST") events_with_this_denom = get_events_in_plot( shape_hist_denom) - for denom_key, dec_line in product(denoms.keys(), dec_lines): + for denom_key, dec_line in product(denoms.keys(), + dec_lines): # Loop over *dec_lines*, not args.lines, as *dec_lines* was cleaned of bad lines above this_histo = eff_histos["{}__{}__eff".format( denom_key, dec_line)] @@ -585,60 +590,69 @@ def main(): # Need a plot of all TOS effs for 1 line, with 1 denominator # Either this ends up being every line or what is specified through args.lines - for dec_line, logx, denom_key in product(dec_lines, [True, False], denoms.keys()): - tos_lines_this_dec_line = [tos_line for tos_line in tos_lines if dec_line in tos_line] + for dec_line, logx, denom_key in product(dec_lines, [True, False], + denoms.keys()): + tos_lines_this_dec_line = [ + tos_line for tos_line in tos_lines if dec_line in tos_line + ] c = TCanvas() c.SetLogx(logx) # Plot the shape hist eff_histos[denom_key + "__distr"].Draw("HIST") - events_with_this_denom = get_events_in_plot( - denom_key) - eff_histos["{}__{}__eff".format( - denom_key, dec_line)].Draw("SAME PE0") + events_with_this_denom = get_events_in_plot(denom_key) + eff_histos["{}__{}__eff".format(denom_key, + dec_line)].Draw("SAME PE0") for tos_line in tos_lines_this_dec_line: - eff_histos["{}__{}__eff".format( - denom_key, tos_line)].Draw("SAME PE0") + eff_histos["{}__{}__eff".format(denom_key, + tos_line)].Draw("SAME PE0") line_at_one, legend = plot_legend_and_line_at_one( - [denom_key], [dec_line]+tos_lines_this_dec_line, events_with_this_denom, - denom_key, logx) + [denom_key], [dec_line] + tos_lines_this_dec_line, + events_with_this_denom, denom_key, logx) line_at_one.Draw("SAME") if not args.no_legend: legend.Draw() c.Print('{}Efficiencies__{}__{}__{}.{}'.format( args.plot_prefix, dec_line, denom_key, - ("log" if logx else "") + var.replace( - ':', '_'), args.plot_format)) + ("log" if logx else "") + var.replace(':', '_'), + args.plot_format)) - particles_that_have_tos_effs_in_tree = {tos_line.split("_Hlt")[0] for tos_line in tos_lines_in_tree} + particles_that_have_tos_effs_in_tree = { + tos_line.split("_Hlt")[0] + for tos_line in tos_lines_in_tree + } if not args.TOS_match_to: - args.TOS_match_to = ",".join(particles_that_have_tos_effs_in_tree) + args.TOS_match_to = ",".join( + particles_that_have_tos_effs_in_tree) if len(dec_lines) > 1: # If not then this plot ends up the same as one produced below - for mcp, denom_key, logx in product(args.TOS_match_to.split(','), denoms, [True, False]): + for mcp, denom_key, logx in product( + args.TOS_match_to.split(','), denoms, [True, False]): # All TOS effs w.r.t. this particle - tos_lines_this_mcp = [tos_line for tos_line in tos_lines if tos_line.split("_Hlt")[0] == mcp] + tos_lines_this_mcp = [ + tos_line for tos_line in tos_lines + if tos_line.split("_Hlt")[0] == mcp + ] # Plot the shape hist eff_histos[denom_key + "__distr"].Draw("HIST") - events_with_this_denom = get_events_in_plot( - denom_key) + events_with_this_denom = get_events_in_plot(denom_key) for tos_line in tos_lines_this_mcp: eff_histos["{}__{}__eff".format( denom_key, tos_line)].Draw("SAME PE0") line_at_one, legend = plot_legend_and_line_at_one( - [denom_key], tos_lines_this_mcp, events_with_this_denom, - denom_key, logx) + [denom_key], tos_lines_this_mcp, + events_with_this_denom, denom_key, logx) line_at_one.Draw("SAME") if not args.no_legend: legend.Draw() c.Print('{}{}__TOSEfficiencies__{}__{}.{}'.format( args.plot_prefix, mcp, denom_key, - ("log" if logx else "") + var.replace( - ':', '_'), args.plot_format)) + ("log" if logx else "") + var.replace(':', '_'), + args.plot_format)) # TODO Test this # Finally, if --denoms > 1, the user may wish to also see a plot for each combination of line and denominator -- GitLab From 655df582ca75bc8b3aebd4dc73977449418ccfed Mon Sep 17 00:00:00 2001 From: Ross Hunter Date: Wed, 6 Oct 2021 15:25:23 +0200 Subject: [PATCH 18/18] Small scope bug --- HltEfficiencyChecker/scripts/hlt_line_efficiencies.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py index 6e09f70..13472ab 100755 --- a/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py +++ b/HltEfficiencyChecker/scripts/hlt_line_efficiencies.py @@ -518,6 +518,8 @@ def main(): else: legend_header = args.decay_name legend.SetHeader(legend_header) + shape_denom_acronym = '.'.join( + [letter for letter in shape_denom_key if letter.isupper()]) for denom_key in denoms_on_plot: for line in lines_on_plot: # Construct a short line name @@ -526,10 +528,6 @@ def main(): denom_acronym = '.'.join([ letter for letter in denom_key if letter.isupper() ]) - shape_denom_acronym = '.'.join([ - letter for letter in shape_denom_key - if letter.isupper() - ]) legend.AddEntry( eff_histos['__'.join([denom_key, line, 'eff'])], (denom_acronym + ', ' if len(denoms_on_plot) > 1 -- GitLab