#!/usr/bin/env python
# coding: utf-8
#
Table of Contents
#
# # Investigating Issues with Track Reconstruction and Simulation in Run 14
#
# More information is available in my slides at
# https://plexoos.github.io/pub-docs/star-run14-jetcorr-issue
#
# To investigate the reason for the drop in the number of global tracks in Run 14 data
# we create the following branches:
#
# `baseline` = `ds-fix-cmake-build`: This is our baseline for a "recent" code
# - https://github.com/plexoos/star-cvs/commits/ds-fix-cmake-build
#
# `ds-jc-fix`: Revert changes causing the drop as found by Dmitri. This is essentiall the same
# patch as on `ds-jc-fix-SL16f`
# - https://github.com/plexoos/star-cvs/commits/ds-jc-fix
#
# `ds-jc-fix-3`: Same patch as `ds-jc-fix` rebased on a later commit following some `approx()`
# bug related changes introduced by Victor
# - https://github.com/plexoos/star-cvs/commits/ds-jc-fix-3
#
# `ds-jc-fix-cutele`: In addition to `ds-jc-fix` revert the change in `mCutEle` value
# - https://github.com/plexoos/star-cvs/commits/ds-jc-fix-cutele
#
# `ds-jc-fix-victor-2`: Changes proposed by Victor. These changes were pointed to me by email
# and I applied them as found in a Victor's directory
# - https://github.com/plexoos/star-cvs/commits/ds-jc-fix-victor-2
#
# `ds-jc-fix-victor-3`: This is similar to `ds-jc-fix-victor-2` except it is based on
# a later commit and committed to CVS. Most importantly, this patch set has the same scale
# factor applied to the track error matrix as in SL16f
# - https://github.com/plexoos/star-cvs/commits/ds-jc-fix-victor-3
#
# `ds-jc-fix-victor-4`: This branch is based on `ds-jc-fix-victor-3`. It includes a change to
# the argument of the `approx()` function in order to exactly match the result of `ds-jc-fix`
# and `ds-jc-fix-3`
# - https://github.com/plexoos/star-cvs/commits/ds-jc-fix-victor-4
#
# `ds-jc-fix-SL16f-last-good` and `ds-jc-fix-SL16f-first-bad`: The bug causing the drop in
# the number of global track has been narrowed down to be between these two references
# - https://github.com/plexoos/star-cvs/commits/ds-jc-fix-SL16f-last-good
# - https://github.com/plexoos/star-cvs/commits/ds-jc-fix-SL16f-fist-bad
#
# `ds-jc-fix-SL16f`: Contains a (minimal) patch fixing the problem by reverting changes between
# `ds-jc-fix-SL16f-last-good` and `ds-jc-fix-SL16f-first-bad`
# - https://github.com/plexoos/star-cvs/commits/ds-jc-fix-SL16f
#
# Each of the proposed changes we test with real data from Run 14 and Run 18, and simulation
# from Run 14
#
# For quick navigation use the links to various test results at the top of this page.
# In[1]:
import plotly.io as pio
pio.templates.default = "none"
import uproot
import numpy as np
import plotly.offline as ofl
import mypytk.plotlytools as ptls
ofl.init_notebook_mode(connected=True)
config = dict(displayModeBar=False, staticPlot=False, showLink=False)
#config = dict(displayModeBar=True, staticPlot=True, showLink=False)
layout = {
'xaxis': {'showgrid': True, 'gridcolor': '#ccc', 'gridwidth': 1, 'automargin': True},
'yaxis1': {'showgrid': True, 'gridcolor': '#ccc', 'gridwidth': 1, 'title': 'Events', 'automargin': True},
'yaxis2': {'showgrid': True, 'gridcolor': '#ccc', 'gridwidth': 1, 'title': 'Ratio', 'automargin': True},
'barmode': 'overlay',
'legend': {'orientation': 'h', 'y': 1.06},
#'showlegend': False,
'margin': {'l': 50, 'r': 15, 'b': 40, 't': 5, 'pad': 5},
'width': 800,
'height': 900,
#'font': dict(size=20)
}
observables = {
'nhits': {'branch': 'GlobalTracks.mNHitsFit', 'bins': np.linspace(0, 48, 49), 'yaxis_range': [0.7, 1.3], 'xaxis_title': 'Number of Hits'},
'pt': {'branch': 'GlobalTracks.mPt', 'bins': np.linspace(0, 2, 51), 'yaxis_range': [0.7, 1.2], 'xaxis_title': 'Transverse Momentum'},
'eta': {'branch': 'GlobalTracks.mEta', 'bins': np.linspace(-1.5, 1.5, 51), 'yaxis_range': [0.7, 1.3], 'xaxis_title': 'Pseudorapidity'},
'chi2': {'branch': 'GlobalTracks.mChiSqXY', 'bins': np.linspace(0, 6, 61) , 'yaxis_range': [0.6, 1.4], 'xaxis_title': 'Chi-squared'}
}
#selection = 'pt < 2 and pt > 0.5'
#selection = 'nhits > 12 and pt < 2'
selection = 'nhits >= 15'
# In[2]:
ptls.output_figure_dir='./graphics/'
ptls.include_plotlyjs='/pub-docs/assets/plotly.min.js'
all_hists = {}
trace_names = ['With bug', 'Patched', 'Ratio']
# # Run 14 Data
# ## baseline vs ds-jc-fix (public)
# In[3]:
mudst0 = uproot.open('data/ds-fix-cmake-build/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config, 'run_14_data_baseline_vs_ds-jc-fix', trace_names)
all_hists.update(ah)
# ## baseline vs ds-jc-fix-victor-2 (public)
# In[4]:
mudst0 = uproot.open('data/ds-fix-cmake-build/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-2/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config, 'run_14_data_baseline_vs_ds-jc-fix-victor-2', trace_names)
all_hists.update(ah)
# ## baseline vs ds-jc-fix-victor-3 (used in ratio comparison)
# In[5]:
mudst0 = uproot.open('data/ds-fix-cmake-build/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-3/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config, 'run_14_data_baseline_vs_ds-jc-fix-victor-3', trace_names)
all_hists.update(ah)
# ## ds-jc-fix vs ds-jc-fix-victor-2
# In[6]:
mudst0 = uproot.open('data/ds-jc-fix/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-2/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# ## ds-jc-fix vs ds-jc-fix-victor-3
# In[7]:
mudst0 = uproot.open('data/ds-jc-fix/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-3/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# ## ds-jc-fix vs ds-jc-fix-3
# In[8]:
mudst0 = uproot.open('data/ds-jc-fix/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-3/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# ## ds-jc-fix-3 vs ds-jc-fix-victor-4
# In[9]:
mudst0 = uproot.open('data/ds-jc-fix-3/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-4/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# ## ds-jc-fix-SL16f vs ds-jc-fix-SL16f-last-good
# In[10]:
mudst0 = uproot.open('data/ds-jc-fix-SL16f/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-SL16f-last-good/st_physics_15086051_raw_2500017.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# # Run 18 Data
# ## baseline vs ds-jc-fix (public)
# In[11]:
mudst0 = uproot.open('data/ds-fix-cmake-build/st_physics_19114030_raw_4500023.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix/st_physics_19114030_raw_4500023.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config, 'run_18_data_baseline_vs_ds-jc-fix', trace_names)
# ## baseline vs ds-jc-fix-victor-2
# In[12]:
mudst0 = uproot.open('data/ds-fix-cmake-build/st_physics_19114030_raw_4500023.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-2/st_physics_19114030_raw_4500023.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# ## baseline vs ds-jc-fix-victor-3
# In[13]:
mudst0 = uproot.open('data/ds-fix-cmake-build/st_physics_19114030_raw_4500023.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-3/st_physics_19114030_raw_4500023.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# ## ds-jc-fix vs ds-jc-fix-victor-3
# In[14]:
mudst0 = uproot.open('data/ds-jc-fix/st_physics_19114030_raw_4500023.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-3/st_physics_19114030_raw_4500023.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# # Run 14 Simulation
# ## baseline vs ds-jc-fix (public)
# In[15]:
mudst0 = uproot.open('data/ds-fix-cmake-build/rcf15000_1_100evts.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix/rcf15000_1_100evts.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config, 'run_14_simu_baseline_vs_ds-jc-fix', trace_names)
all_hists.update(ah)
# ## baseline vs ds-jc-fix-cutele
# In[16]:
mudst0 = uproot.open('data/ds-fix-cmake-build/rcf15000_1_100evts.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-cutele/rcf15000_1_100evts.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# ## baseline vs ds-jc-fix-victor-2 (public)
# In[17]:
mudst0 = uproot.open('data/ds-fix-cmake-build/rcf15000_1_100evts.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-2/rcf15000_1_100evts.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config, 'run_14_simu_baseline_vs_ds-jc-fix-victor-2', trace_names)
all_hists.update(ah)
# ## baseline vs ds-jc-fix-victor-3 (public)
# In[18]:
mudst0 = uproot.open('data/ds-fix-cmake-build/rcf15000_1_100evts.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-3/rcf15000_1_100evts.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config, 'run_14_simu_baseline_vs_ds-jc-fix-victor-3', trace_names)
all_hists.update(ah)
# ## ds-jc-fix vs ds-jc-fix-victor-2
# In[19]:
mudst0 = uproot.open('data/ds-jc-fix/rcf15000_1_100evts.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-2/rcf15000_1_100evts.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# ## ds-jc-fix vs ds-jc-fix-victor-3
# In[20]:
mudst0 = uproot.open('data/ds-jc-fix/rcf15000_1_100evts.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-3/rcf15000_1_100evts.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# ## ds-jc-fix vs ds-jc-fix-3
# In[21]:
mudst0 = uproot.open('data/ds-jc-fix/rcf15000_1_100evts.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-3/rcf15000_1_100evts.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# ## ds-jc-fix-3 vs ds-jc-fix-victor-3
# In[22]:
mudst0 = uproot.open('data/ds-jc-fix-3/rcf15000_1_100evts.MuDst.root')['MuDst']
mudst1 = uproot.open('data/ds-jc-fix-victor-3/rcf15000_1_100evts.MuDst.root')['MuDst']
ah = ptls.make_plots(mudst0, mudst1, observables, selection, layout, config)
# # Run 14 Data vs Simulation
# ## baseline vs ds-jc-fix
# In[23]:
for var_name, var_props in observables.items():
t0 = all_hists[f'run_14_data_baseline_vs_ds-jc-fix_{var_name}_hR']
t1 = all_hists[f'run_14_simu_baseline_vs_ds-jc-fix_{var_name}_hR']
layout = dict(
yaxis=dict(range=[0.7, 1.3]),
xaxis=dict(title=var_props['xaxis_title']),
width=1000, height=400
)
fig = dict(data=[t0, t1], layout=layout)
ofl.iplot(fig, config=config)
# ## baseline vs ds-jc-fix-victor-2
# In[24]:
for var_name, var_props in observables.items():
t0 = all_hists[f'run_14_data_baseline_vs_ds-jc-fix-victor-2_{var_name}_hR']
t1 = all_hists[f'run_14_simu_baseline_vs_ds-jc-fix-victor-2_{var_name}_hR']
layout = dict(
yaxis=dict(range=[0.7, 1.3]),
xaxis=dict(title=var_props['xaxis_title']),
width=1000, height=400
)
fig = dict(data=[t0, t1], layout=layout)
ofl.iplot(fig, config=config)
# ## baseline vs ds-jc-fix-victor-3
# In[25]:
for var_name, var_props in observables.items():
t0 = all_hists[f'run_14_data_baseline_vs_ds-jc-fix-victor-3_{var_name}_hR']
t1 = all_hists[f'run_14_simu_baseline_vs_ds-jc-fix-victor-3_{var_name}_hR']
layout = dict(
yaxis=dict(range=[0.7, 1.3]),
xaxis=dict(title=var_props['xaxis_title']),
width=1000, height=400
)
fig = dict(data=[t0, t1], layout=layout)
ofl.iplot(fig, config=config)
# ## Normalized distributions for baseline case
# In[26]:
for var_name, var_props in observables.items():
t0 = all_hists[f'run_14_data_baseline_vs_ds-jc-fix_{var_name}_h0']
t0.name = 'Data'
t1 = all_hists[f'run_14_simu_baseline_vs_ds-jc-fix_{var_name}_h0']
t1.name = 'Simu'
t0.y = t0.y / t0.y.sum()
t1.y = t1.y / t1.y.sum()
#layout = dict(
# xaxis=dict(title=var_props['xaxis_title'])
#)
layout = {
'xaxis': {'showgrid': True, 'gridcolor': '#ccc', 'gridwidth': 1, 'automargin': True, 'title': f'{var_props["xaxis_title"]}'},
'yaxis1': {'showgrid': True, 'gridcolor': '#ccc', 'gridwidth': 1, 'title': 'Events Normalized', 'automargin': True},
'barmode': 'overlay',
'legend': {'orientation': 'h', 'y': 1.06},
'margin': {'l': 50, 'r': 15, 'b': 40, 't': 5, 'pad': 5},
'width': 900,
'height': 500,
}
fig = dict(data=[t0, t1], layout=layout)
ofl.iplot(fig, config=config)
ptls.write_html(fig, 'graphics/run_14_data_vs_simu_baseline/', var_name, config=config, include_plotlyjs=ptls.include_plotlyjs)