Commit cc332a14 authored by Rosen Matev's avatar Rosen Matev
Browse files

Merge branch 'TOS-for-Allen-HltEfficiencyChecker' into 'master'

Calculate TOS efficiencies for Allen in HltEfficiencyChecker

See merge request !51
parents 32c11c04 4870f016
Pipeline #3114413 passed with stage
in 20 seconds
......@@ -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:
#
......@@ -36,3 +37,4 @@ analysis:
make_plots: true
vars: "PT,Kplus0:PT"
lines: Hlt1TwoTrackMVADecision,Hlt1TrackMVADecision
TOS_match_to: "B_s0,Kplus0"
# 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
......@@ -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.
#
......
......@@ -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
......@@ -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
......
......@@ -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, HltSelReportsDecoder
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):
......@@ -105,6 +104,19 @@ 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
allen_wrapper = make_allen_output()
allen_sel_rep_writer = AllenSelReportsToTES(AllenOutput=allen_wrapper)
sel_rep_decoder = HltSelReportsDecoder(
RawEventLocations=allen_sel_rep_writer.OutputSelReports,
SourceID='Hlt1')
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
tuple_flag = 'MCDecayTreeTuple' if efficiency_mode else 'EventTuple'
ttt = TupleToolTrigger(
......@@ -129,10 +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()])
nodes = [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]
......
......@@ -68,6 +68,13 @@ def get_parser():
'--reconstructible-children',
required=True,
help='Comma-separated list of child names.')
parser.add_argument(
'--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.'
)
parser.add_argument('--make-plots', action='store_true')
parser.add_argument(
'--legend-header',
......@@ -226,7 +233,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 +242,35 @@ 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
tos_lines = []
if not args.TOS_match_to:
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
]
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)
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
......@@ -488,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
......@@ -496,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
......@@ -538,52 +566,93 @@ 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()
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(
":", "_"), 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)
# 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('{}Efficiencies__{}__{}__{}.{}'.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("_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)
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("_Hlt")[0] == mcp
]
# 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)
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(
denoms.keys(), [line], events_with_this_denom,
shape_hist_denom, 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("SAME")
if not args.no_legend: legend.Draw()
c.Print('{}Efficiency__{}{}__{}{}.{}'.format(
args.plot_prefix, line,
"__AllDenoms" if len(denoms) > 1 else "",
"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))
# 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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment