Commit 2d98d25b authored by Gitlab CI's avatar Gitlab CI Committed by Ross John Hunter
Browse files

Fixed formatting

patch generated by https://gitlab.cern.ch/lhcb/MooreAnalysis/-/jobs/7818574
parent 42f52cf4
Pipeline #1528458 passed with stage
in 40 seconds
......@@ -106,7 +106,7 @@ if efficiencyMode:
'MCDecayTreeTuple.MCTupleToolKinematic', StoreEtaInfo=True)
mcttrec = MCTupleToolReconstructed(Associate=False, FillPID=False)
# FIXME the Reconstructed flag from MCTupleToolReconstructed doesn't work yet
# Want the following tools for both rates and line efficiencies
tuple_flag = 'MCDecayTreeTuple' if efficiencyMode else 'EventTuple'
ttt = TupleToolTrigger(
......
......@@ -202,7 +202,9 @@ print('HltEfficiencyChecker.py')
print('-' * 84)
steps = []
if args.trigger.lower() != 'allen' and args.trigger.lower() != 'moore' and args.trigger.lower() != 'both': # use .lower() so that this argument is case-insensitive.
if args.trigger.lower() != 'allen' and args.trigger.lower(
) != 'moore' and args.trigger.lower(
) != 'both': # use .lower() so that this argument is case-insensitive.
print(
"FATAL\t You must specify whether you want to use Allen, Moore or both to do the reconstruction and trigger. Aborting..."
)
......@@ -234,8 +236,9 @@ options.set_input_from_testfiledb(testfile)
options.set_conds_from_testfiledb(testfile)
os.environ[\"RATES_OUT_NAME\"] = \"%s\"
os.environ[\"FT_DECODING_VERSION\"] = \"%s\"
""" % (min_bias_key, args.events, '_'.join([make_name(min_bias_key), "ForRates", args.trigger.lower()]),
"4" if "FTv4" in min_bias_key else "6")
""" % (min_bias_key, args.events, '_'.join(
[make_name(min_bias_key), "ForRates",
args.trigger.lower()]), "4" if "FTv4" in min_bias_key else "6")
if args.trigger == 'both':
rates_options_by_tr = {
trig: rates_options.replace('both', trig)
......@@ -243,8 +246,7 @@ os.environ[\"FT_DECODING_VERSION\"] = \"%s\"
}
if not args.dump:
print("INFO\t Extra options passed to gaudirun.py: " +
rates_options)
print("INFO\t Extra options passed to gaudirun.py: " + rates_options)
# Setup the subprocesses for Moore and the analysis script
if args.trigger.lower() == 'both':
......@@ -252,10 +254,9 @@ os.environ[\"FT_DECODING_VERSION\"] = \"%s\"
triggers,
['hlt1_allen_maketuple.py', 'hlt1_runtrigger_maketuple.py']):
steps.append([
'gaudirun.py', '--option',
rates_options_by_tr[trig],
'gaudirun.py', '--option', rates_options_by_tr[trig],
os.path.expandvars('$HLTEFFICIENCYCHECKERROOT/options/' +
trig_opt_file)
trig_opt_file)
])
else:
steps.append([
......@@ -278,7 +279,8 @@ os.environ[\"FT_DECODING_VERSION\"] = \"%s\"
analysis_opts += ['--trigger', args.trigger.lower()]
analysis_opts += [
'--input-file', 'Hlt1DecisionTuple_{0}.root'.format('_'.join(
[make_name(min_bias_key), "ForRates", args.trigger.lower()]))
[make_name(min_bias_key), "ForRates",
args.trigger.lower()]))
] #FIXME hardcoding twice in 1 file.
steps.append([
'python',
......@@ -386,17 +388,21 @@ if args.dump:
}
for trig in triggers:
with open(tmp_options_file_paths[trig], "w") as f:
f.write(rates_options_by_tr[trig] if args.rates else decay_specific_options_by_tr[trig])
f.write(rates_options_by_tr[trig] if args.
rates else decay_specific_options_by_tr[trig])
f.close()
print('INFO\t The individual steps are...')
for step in steps:
for trig in triggers:
if args.rates and rates_options_by_tr[trig] in step:
step[step.index(rates_options_by_tr[trig])] = tmp_options_file_paths[trig]
step[step.index(
rates_options_by_tr[trig])] = tmp_options_file_paths[trig]
step.remove('--option')
elif not args.rates and decay_specific_options_by_tr[trig] in step: # Need to use the temporary options file rather than the --option flag
step[step.index(decay_specific_options_by_tr[trig] )] = tmp_options_file_paths[trig]
elif not args.rates and decay_specific_options_by_tr[
trig] in step: # Need to use the temporary options file rather than the --option flag
step[step.index(decay_specific_options_by_tr[trig]
)] = tmp_options_file_paths[trig]
step.remove('--option')
for step in steps:
......
......@@ -15,20 +15,24 @@ import ROOT, sys, os, json
from itertools import cycle
gStyle.SetOptStat(False)
gROOT.ProcessLine(os.path.expandvars(".x $HLTEFFICIENCYCHECKERROOT/lhcbStyle.C"))
gROOT.ProcessLine(
os.path.expandvars(".x $HLTEFFICIENCYCHECKERROOT/lhcbStyle.C"))
gStyle.SetLegendTextSize(0.04)
def sanitise_line(line):
new_line_name = str(line)
for ugly in ['Hlt1', 'Line', 'Decision']:
new_line_name = new_line_name.replace(ugly, '')
return new_line_name
def dot_aligned(dicto):
snums = {k:str(n) for k,n in dicto.items()}
dots = {k:s.find('.') for k,s in snums.items()}
snums = {k: str(n) for k, n in dicto.items()}
dots = {k: s.find('.') for k, s in snums.items()}
m = max(dots.values())
return {k: ' '*(m - dots[k]) + snums[k] for k in dicto.keys()}
return {k: ' ' * (m - dots[k]) + snums[k] for k in dicto.keys()}
def main():
def make_cut_string(cut_list):
......@@ -39,18 +43,15 @@ def main():
"Parse in the configuration for the line integrated_efficiencies test")
parser.add_argument('--level', default='Hlt1')
parser.add_argument('--input-file', default=None)
parser.add_argument('--allen-lines', type=str, nargs='+', default=None, required=True)
parser.add_argument('--moore-lines', type=str, nargs='+', default=None, required=True)
parser.add_argument(
'--file-sfx', type=str, default='2018MinBias')
parser.add_argument(
'--plot-rates', action='store_true')
'--allen-lines', type=str, nargs='+', default=None, required=True)
parser.add_argument(
'--plot-total-rate', action='store_true')
parser.add_argument(
'--plot-group-rates', action='store_true')
parser.add_argument(
'--dump-results-to-json', action='store_true')
'--moore-lines', type=str, nargs='+', default=None, required=True)
parser.add_argument('--file-sfx', type=str, default='2018MinBias')
parser.add_argument('--plot-rates', action='store_true')
parser.add_argument('--plot-total-rate', action='store_true')
parser.add_argument('--plot-group-rates', action='store_true')
parser.add_argument('--dump-results-to-json', action='store_true')
parser.add_argument('--plot-format', dest='plot_format', default='pdf')
parser.add_argument(
'--trigger',
......@@ -99,10 +100,12 @@ def main():
and br.GetName().endswith("Decision"))
]
except AttributeError:
print("FATAL:\t Seems there are no branches in the tree. Was the tuple created correctly and without failure?")
print(
"FATAL:\t Seems there are no branches in the tree. Was the tuple created correctly and without failure?"
)
sys.exit()
lines = []
if parsed_lines: # FIXME you made these args required, so not sure if this check is needed anymore - not the ELSE statement either.
if parsed_lines: # FIXME you made these args required, so not sure if this check is needed anymore - not the ELSE statement either.
for key in parsed_lines:
if key in lines_in_tree:
lines.append(key)
......@@ -134,7 +137,7 @@ def main():
# Get the number of evts that trigger for each line
# Turn into rate by dividing by 30MHz (the LHCb collision rate)
# We would also like to know the exclusive rate: the rate where the events only fire that trigger.
# We would also like to know the exclusive rate: the rate where the events only fire that trigger.
# We can do this will nSelection == 1 and the line of interest.
denom_evts = float(tree.GetEntries())
if not denom_evts:
......@@ -145,56 +148,75 @@ def main():
print('-' * 100)
lhcb_coll_rate = 30000
for line in lines:
incl_eff = float(tree.GetEntries(line))/ denom_evts
incl_rate = incl_eff * lhcb_coll_rate # in kHz
excl_eff = float(tree.GetEntries(line + ' && Hlt1nSelections == 1')) / denom_evts
incl_eff = float(tree.GetEntries(line)) / denom_evts
incl_rate = incl_eff * lhcb_coll_rate # in kHz
excl_eff = float(
tree.GetEntries(line +
' && Hlt1nSelections == 1')) / denom_evts
excl_rate = excl_eff * lhcb_coll_rate
rates[line] = incl_rate
rates[line] = incl_rate
rates[line + 'Exclusive'] = excl_rate
incl_rate_err = TMath.Sqrt(incl_eff * (1.0 - incl_eff) / denom_evts) * lhcb_coll_rate
excl_rate_err = TMath.Sqrt(excl_eff * (1.0 - excl_eff) / denom_evts) * lhcb_coll_rate
incl_rate_err = TMath.Sqrt(
incl_eff * (1.0 - incl_eff) / denom_evts) * lhcb_coll_rate
excl_rate_err = TMath.Sqrt(
excl_eff * (1.0 - excl_eff) / denom_evts) * lhcb_coll_rate
rates_errors[line] = incl_rate_err
rates_errors[line + 'Exclusive'] = excl_rate_err
# THE BELOW NOT REQUIRED FOR THE PHYSICS PERFORMANCE COMPARISON
# Finally, want to print rates for events that fire on the OR of a group of lines,
# Finally, want to print rates for events that fire on the OR of a group of lines,
# e.g. any muon-related line.
#groups = {'TrackMVA': [], 'Muon':[], 'NotPhysics':[]}
#groups['TrackMVA'] = [line for line in lines if 'TrackMVA' in line]
#groups['Muon'] = [line for line in lines if 'Muon' in line]
#groups['NotPhysics'] = [line for line in lines if (line not in groups['Muon'] and line not in groups['TrackMVA'])]
groups = {'Inclusive':[]}
groups = {'Inclusive': []}
groups['Inclusive'] = [line for line in lines if 'GEC' not in line]
for name, group in groups.items():
incl_selection = ' || '.join([line for line in group])
incl_group_eff = float(tree.GetEntries(incl_selection))/ denom_evts
incl_group_rate = incl_group_eff * lhcb_coll_rate # in kHz
incl_group_eff = float(
tree.GetEntries(incl_selection)) / denom_evts
incl_group_rate = incl_group_eff * lhcb_coll_rate # in kHz
rates[name] = incl_group_rate
incl_group_rate_err = TMath.Sqrt(incl_group_eff * (1.0 - incl_group_eff) / denom_evts) * lhcb_coll_rate
incl_group_rate_err = TMath.Sqrt(
incl_group_eff *
(1.0 - incl_group_eff) / denom_evts) * lhcb_coll_rate
rates_errors[name] = incl_group_rate_err
excl_selection = '(' + incl_selection + ') && (' + ' && '.join(['!'+line for line in lines if line not in group]) + ')'
excl_group_eff = float(tree.GetEntries(excl_selection))/ denom_evts
excl_selection = '(' + incl_selection + ') && (' + ' && '.join(
['!' + line for line in lines if line not in group]) + ')'
excl_group_eff = float(
tree.GetEntries(excl_selection)) / denom_evts
excl_group_rate = excl_group_eff * lhcb_coll_rate
rates[name + 'Exclusive'] = excl_group_rate
excl_group_rate_err = TMath.Sqrt(excl_group_eff * (1.0 - excl_group_eff) / denom_evts) * lhcb_coll_rate
excl_group_rate_err = TMath.Sqrt(
excl_group_eff *
(1.0 - excl_group_eff) / denom_evts) * lhcb_coll_rate
rates_errors[name + 'Exclusive'] = excl_group_rate_err
# Sanitise the results so they align by decimal point
pretty_rates = dot_aligned( rates )
pretty_rates_errors = dot_aligned( rates_errors )
pretty_rates = dot_aligned(rates)
pretty_rates_errors = dot_aligned(rates_errors)
for line in lines:
print(
"Line:\t {0:<{1}}\t Incl: {2:4} +/- {3:4} kHz, Excl: {4:4} +/- {5:4} kHz".format(
line, length, pretty_rates[line], pretty_rates_errors[line][:4], pretty_rates[line+'Exclusive'], pretty_rates_errors[line+'Exclusive'][:4]))
"Line:\t {0:<{1}}\t Incl: {2:4} +/- {3:4} kHz, Excl: {4:4} +/- {5:4} kHz"
.format(line, length, pretty_rates[line],
pretty_rates_errors[line][:4],
pretty_rates[line + 'Exclusive'],
pretty_rates_errors[line + 'Exclusive'][:4]))
print('-' * 100)
print('Rates grouped by common physics: ')
for name, lines_in_group in groups.items(): print('INFO:\t %s group is formed of %s.' % (name, ', '.join(lines_in_group)) )
for name, lines_in_group in groups.items():
print('INFO:\t %s group is formed of %s.' %
(name, ', '.join(lines_in_group)))
print('-' * 100)
for name in groups.keys():
print(
"Group:\t {0:<{1}}\t Incl: {2:4} +/- {3:4} kHz, Excl: {4:4} +/- {5:4} kHz".format(
name + ' lines', length, pretty_rates[name], pretty_rates_errors[name][:4], pretty_rates[name+'Exclusive'], pretty_rates_errors[name+'Exclusive'][:4]))
"Group:\t {0:<{1}}\t Incl: {2:4} +/- {3:4} kHz, Excl: {4:4} +/- {5:4} kHz"
.format(name + ' lines', length, pretty_rates[name],
pretty_rates_errors[name][:4],
pretty_rates[name + 'Exclusive'],
pretty_rates_errors[name + 'Exclusive'][:4]))
print('-' * 100)
# We also want the total rate - this should be #events that fire any trigger/#events run over
......@@ -203,25 +225,26 @@ def main():
total_eff = float(tree.GetEntries("Hlt1nSelections >= 1")) / denom_evts
total_rate = total_eff * lhcb_coll_rate
rates['Hlt1Total'] = total_rate
total_rate_err = TMath.Sqrt(total_eff * (1.0 - total_eff) / denom_evts) * lhcb_coll_rate
total_rate_err = TMath.Sqrt(
total_eff * (1.0 - total_eff) / denom_evts) * lhcb_coll_rate
rates_errors['Hlt1Total'] = total_rate_err
print(
"Hlt1 Total: {0:<{1}} Rate:\t {2:.0f} +/- {3:.1f} kHz".format(
'', length, rates['Hlt1Total'], rates_errors['Hlt1Total']))
print("Hlt1 Total: {0:<{1}} Rate:\t {2:.0f} +/- {3:.1f} kHz".format(
'', length, rates['Hlt1Total'], rates_errors['Hlt1Total']))
if ['Problem' for line in lines_in_tree if 'GEC' in line]:
print("WARNING:\t There is a GEC pass-through line in the tree. Total rates are unlikely to make sense.")
print(
"WARNING:\t There is a GEC pass-through line in the tree. Total rates are unlikely to make sense."
)
if args.plot_total_rate:
lines.append('Hlt1Total')
if args.plot_group_rates:
for name in groups.keys(): lines.append(name)
for name in groups.keys():
lines.append(name)
both_triggers_rates[trig] = rates
both_triggers_rates_errs[trig] = rates_errors
print('-' * 100)
print(
'Finished printing {0} rates!'
.format(args.level))
print('Finished printing {0} rates!'.format(args.level))
if args.plot_rates:
# Make a bar chart of the rates.
......@@ -235,57 +258,76 @@ def main():
print('INFO:\t Making bar chart of the rates...')
print('-' * 100)
c = TCanvas()
c = TCanvas()
c.SetGridy()
#c.SetRightMargin(0.15) Unnecessary for 4 lines.
gStyle.SetHistMinimumZero()
gStyle.SetErrorX(0)
allen_rate_hist = TH1F("allen_rate_hist", "", len(args.allen_lines), 0, len(args.allen_lines))
allen_rate_hist = TH1F("allen_rate_hist", "", len(args.allen_lines), 0,
len(args.allen_lines))
moore_rate_hist = allen_rate_hist.Clone("moore_rate_hist")
for trig, rate_hist, lines in zip(['Allen', 'Moore'], [allen_rate_hist, moore_rate_hist], [args.allen_lines, args.moore_lines]):
for trig, rate_hist, lines in zip(
['Allen', 'Moore'], [allen_rate_hist, moore_rate_hist],
[args.allen_lines, args.moore_lines]):
for i, line in enumerate(lines):
rate_hist.SetBinContent(i+1, both_triggers_rates[trig][line])
rate_hist.SetBinError(i+1, both_triggers_rates_errs[trig][line])
if trig == 'Allen': rate_hist.GetXaxis().SetBinLabel(i+1, sanitise_line(line))
rate_hist.SetFillColor((ROOT.kBlue if trig == 'Allen' else ROOT.kRed)- 10)
rate_hist.SetLineColor((ROOT.kBlue if trig == 'Allen' else ROOT.kRed)- 10)
rate_hist.SetBarWidth(0.45);
rate_hist.SetBarOffset(0.025 + (0.50 if trig == 'Moore' else 0.0));
rate_hist.SetBinContent(i + 1, both_triggers_rates[trig][line])
rate_hist.SetBinError(i + 1,
both_triggers_rates_errs[trig][line])
if trig == 'Allen':
rate_hist.GetXaxis().SetBinLabel(i + 1,
sanitise_line(line))
rate_hist.SetFillColor(
(ROOT.kBlue if trig == 'Allen' else ROOT.kRed) - 10)
rate_hist.SetLineColor(
(ROOT.kBlue if trig == 'Allen' else ROOT.kRed) - 10)
rate_hist.SetBarWidth(0.45)
rate_hist.SetBarOffset(0.025 + (0.50 if trig == 'Moore' else 0.0))
rate_hist.GetXaxis().SetTitle("")
rate_hist.GetYaxis().SetTitle("Rate / kHz")
rate_hist.SetMaximum(max([both_triggers_rates[trig][line] + both_triggers_rates_errs[trig][line] for line in lines])*1.1)
rate_hist.SetMaximum(
max([
both_triggers_rates[trig][line] +
both_triggers_rates_errs[trig][line] for line in lines
]) * 1.1)
rate_hist.Draw('HIST BAR ' + ('SAME' if trig == 'Moore' else ''))
# artificially shift the markers by making new hists with twice finer binning, and only filling alternate bins
# with the correct rate, giving the illusion of offset markers
allen_marker_hist = TH1F('allen_marker_hist', '', 2*len(args.allen_lines), 0, len(args.allen_lines))
# artificially shift the markers by making new hists with twice finer binning, and only filling alternate bins
# with the correct rate, giving the illusion of offset markers
allen_marker_hist = TH1F('allen_marker_hist', '',
2 * len(args.allen_lines), 0,
len(args.allen_lines))
moore_marker_hist = allen_marker_hist.Clone('moore_marker_hists')
for i, (allen_line, moore_line) in enumerate(zip(args.allen_lines, args.moore_lines)):
allen_marker_hist.SetBinContent((2*i) + 1, both_triggers_rates['Allen'][allen_line])
allen_marker_hist.SetBinError((2*i)+1, both_triggers_rates_errs['Allen'][allen_line])
moore_marker_hist.SetBinContent((2*i) + 2, both_triggers_rates['Moore'][moore_line])
moore_marker_hist.SetBinError((2*i)+2, both_triggers_rates_errs['Moore'][moore_line])
for i, (allen_line, moore_line) in enumerate(
zip(args.allen_lines, args.moore_lines)):
allen_marker_hist.SetBinContent(
(2 * i) + 1, both_triggers_rates['Allen'][allen_line])
allen_marker_hist.SetBinError(
(2 * i) + 1, both_triggers_rates_errs['Allen'][allen_line])
moore_marker_hist.SetBinContent(
(2 * i) + 2, both_triggers_rates['Moore'][moore_line])
moore_marker_hist.SetBinError(
(2 * i) + 2, both_triggers_rates_errs['Moore'][moore_line])
allen_marker_hist.Draw('HIST SAME PE')
moore_marker_hist.Draw('HIST SAME PE')
allen_rate_hist.Draw('AXIS SAME') # Draw the axes again to stop the bars being drawn over them.
allen_rate_hist.Draw(
'AXIS SAME'
) # Draw the axes again to stop the bars being drawn over them.
# make a legend
legend = TLegend(0.6, 0.73, 0.9, 0.92)
events_in_plot = tree.GetEntries()
legend.SetHeader(
'Min. Bias, {0:.0f} events'.format(
events_in_plot))
legend.SetHeader('Min. Bias, {0:.0f} events'.format(events_in_plot))
for trig in ['Allen', 'Moore']:
legend.AddEntry('_'.join([trig.lower(), "rate_hist"]),
trig if trig == 'Allen' else 'Baseline','F')
trig if trig == 'Allen' else 'Baseline', 'F')
legend.SetFillColorAlpha(ROOT.kWhite, 0.70)
legend.SetLineWidth(0)
legend.Draw()
c.Print('_'.join([args.trigger, 'Rates', args.file_sfx]) +
"." + args.plot_format)
c.Print('_'.join([args.trigger, 'Rates', args.file_sfx]) + "." +
args.plot_format)
print('-' * 100)
print('INFO\t Finished making plots. Goodbye.')
......@@ -298,5 +340,6 @@ def main():
json.dump(rates_errors, f, indent=4)
f.close()
if __name__ == "__main__":
main()
......@@ -24,13 +24,18 @@ gStyle.SetLegendTextSize(0.04)
# Define the units that you know for plotting - make sure that none of the keys are substrings of any other keys, or the logic below will break.
units = {"PT": "MeV", "TAU": "ns"}
var_latex_var_map = {"PT": r"p_{T}", "TAU": r"#tau", "2ndHighestPT": "2ndHighestPT", "HighestPT": "HighestPT"}
var_latex_var_map = {
"PT": r"p_{T}",
"TAU": r"#tau",
"2ndHighestPT": "2ndHighestPT",
"HighestPT": "HighestPT"
}
input_file_latex_decay_map = {
"JPsiMuMuMD": r"J/#psi #rightarrow #mu#mu",
"ZMuMuMD": r"Z #rightarrow #mu#mu",
"KstMuMuMD": r"B^{0} #rightarrow K^{*}_{0} #mu#mu",
"KstEEMD": r"B^{0} #rightarrow K^{*}_{0} ee",
"Ds2KKPiMD": r"D_{s} #rightarrow KK#pi",
"ZMuMuMD": r"Z #rightarrow #mu#mu",
"KstMuMuMD": r"B^{0} #rightarrow K^{*}_{0} #mu#mu",
"KstEEMD": r"B^{0} #rightarrow K^{*}_{0} ee",
"Ds2KKPiMD": r"D_{s} #rightarrow KK#pi",
"BsPhiPhiMD": r"B^{0}_{s} #rightarrow #phi#phi"
}
......@@ -48,9 +53,11 @@ def main():
return ' && '.join([('(' + cut + ')') for cut in cut_list])
def make_max_min_child_draw_var(children, max_min, var):
kidvars = [kid+'_TRUE'+var for kid in children]
kidvars = [kid + '_TRUE' + var for kid in children]
if max_min != 'max' and max_min != 'min':
print("FATAL:\t Couldn\'t interpret the max_min you asked for - use \"max\" or \"min\".")
print(
"FATAL:\t Couldn\'t interpret the max_min you asked for - use \"max\" or \"min\"."
)
sys.exit()
length = len(kidvars)
......@@ -62,39 +69,53 @@ def main():
elif length == 2:
draw_str = max_min + '(' + kidvars[0] + ',' + kidvars[1] + ')'
else:
draw_str = (max_min + "(")*(length-1) + kidvars[0] + ', ' + ', '.join([kid + ')' for kid in kidvars[1:]])
draw_str = (max_min + "(") * (
length - 1) + kidvars[0] + ', ' + ', '.join(
[kid + ')' for kid in kidvars[1:]])
return draw_str
def fill_histo_with_nth_highest_var(hist, tree, denom, children, var, n, passhist):
def fill_histo_with_nth_highest_var(hist, tree, denom, children, var, n,
passhist):
child_vars = [kid + '_TRUE' + var for kid in children]
cutvars = denom.split(' && ')
new_file = TFile.Open("tmp.root", "recreate")
new_file.cd()
filtered_tree = tree.CopyTree(denom)
if passhist:
if passhist:
print("THIS IS A PASSHIST")
print(denom)
print([cut for cut in denom.split(' ') if 'Hlt1' in cut][0])
print("Unfiltered entries: %.0f. Unfiltered passes: %.0f" % (tree.GetEntries(), tree.GetEntries([cut for cut in denom.split(' ') if 'Hlt1' in cut][0])))
print("Filtered entries: %.0f. Filtered passes: %.0f" % (filtered_tree.GetEntries(), filtered_tree.GetEntries([cut for cut in denom.split(' ') if 'Hlt1' in cut][0])))
print("Unfiltered entries: %.0f. Unfiltered passes: %.0f" %
(tree.GetEntries(),
tree.GetEntries(
[cut for cut in denom.split(' ') if 'Hlt1' in cut][0])))
print("Filtered entries: %.0f. Filtered passes: %.0f" %
(filtered_tree.GetEntries(),
filtered_tree.GetEntries(
[cut for cut in denom.split(' ') if 'Hlt1' in cut][0])))
count = 0
for evt in filtered_tree:
vals_by_kid = {var:getattr(evt, var) for var in child_vars}
vals_by_kid = {var: getattr(evt, var) for var in child_vars}
# sorted() with this lambda returns list of key-value pairs sorted by value in ascending order
# if n = 1, you want highest, 2 = 2nd highest etc
key, val = sorted(vals_by_kid.items(), key=lambda kvpair: kvpair[1])[-n]
key, val = sorted(
vals_by_kid.items(), key=lambda kvpair: kvpair[1])[-n]
if passhist:
if val < 800:
# Threshold for the 2TrkMVA line
print("Did trigger fire? %.0f" % getattr(evt, [cut for cut in denom.split(' ') if 'Hlt1' in cut][0])) #assume it finds only one
print(sorted(vals_by_kid.items(), key=lambda kvpair: kvpair[1]))
print("Did trigger fire? %.0f" % getattr(
evt, [
cut for cut in denom.split(' ') if 'Hlt1' in cut
][0])) #assume it finds only one
print(sorted(
vals_by_kid.items(), key=lambda kvpair: kvpair[1]))
print("Chose %s with value %.2f" % (key, val))
count += 1
......@@ -133,7 +154,11 @@ def main():
type=str,
default=None,
)
parser.add_argument('--force-binning', type=str, default=None, help='Colon-separated nbins:max:min')
parser.add_argument(
'--force-binning',
type=str,
default=None,
help='Colon-separated nbins:max:min')
args = parser.parse_args()
print('-' * 84)
......@@ -234,11 +259,13 @@ def main():
and br.GetName().endswith("Decision"))
]
except AttributeError:
print("FATAL:\t Seems there are no branches in the tree. Was the tuple created correctly and without failure?")
print(
"FATAL:\t Seems there are no branches in the tree. Was the tuple created correctly and without failure?"
)
sys.exit()
lines = []
if parsed_lines: # FIXME you made these args required, so not sure if this check is needed anymore - not the ELSE statement either.
if parsed_lines: # FIXME you made these args required, so not sure if this check is needed anymore - not the ELSE statement either.
for key in parsed_lines:
if key in lines_in_tree:
lines.append(key)
......@@ -261,8 +288,7 @@ def main():
)
sys.exit()
length = max([len(line) for line in lines]) # for formatting
both_triggers_lines[
trig] = lines
both_triggers_lines[trig] = lines
for denom, cut in denoms.items():
# Get the number of evts that pass each line for each denominator
......@@ -320,24 +346,27 @@ def main():
xmin = tree.GetMinimum(draw_var)
nbins = 20
limit_hist = TH1F('_'.join([trig, draw_var, "limhist"]),
', '.join([args.decay_name]), nbins,
xmin,
tree.GetMaximum(draw_var))
', '.join([args.decay_name]), nbins,
xmin, tree.GetMaximum(draw_var))
if var == '2ndHighestPT':
fill_histo_with_nth_highest_var(limit_hist, tree, '', child_names, 'PT', 2, False)
fill_histo_with_nth_highest_var(
limit_hist, tree, '', child_names, 'PT', 2, False)
elif var == 'HighestPT':
tree.Draw(
"{0}>>{1}".format(make_max_min_child_draw_var(child_names, 'max', 'PT'), '_'.join(
[trig, draw_var, "limhist"])), '')