UHepp

This notebook illustrates how FreeForestML integrates with uhepp.

[1]:
import pandas as pd
import seaborn as sns

from freeforestml import Variable, Process, Cut, hist, McStack, DataStack, Stack
from freeforestml import toydata, example_style
from freeforestml.plot import hist
example_style()

import uhepp
2023-08-02 16:41:31.455133: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-08-02 16:41:31.595309: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2023-08-02 16:41:31.595341: I tensorflow/compiler/xla/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2023-08-02 16:41:32.451346: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2023-08-02 16:41:32.451458: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2023-08-02 16:41:32.451470: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
[2]:
df = toydata.get()
[3]:
df.compute()
[3]:
jet_1_pt jet_1_eta jet_1_phi jet_2_pt jet_2_eta jet_2_phi met_phi met_pt tau_phi tau_eta ... higgs_pt higgs_eta higgs_phi higgs_m m_jj lep_centrality tau_centrality random fpid weight
0 88.594422 2.227779 5.447955 41.690209 2.551271 0.837869 3.421552 8.111048 4.885477 -1.005320 ... 176.643326 -1.067341 -1.511005 80.330013 92.365255 8.546637e-201 1.600036e-96 0.692583 0 1
1 112.332084 3.689913 5.009235 88.663452 2.571029 0.240387 5.901392 18.987162 6.185564 -1.392806 ... 170.961698 -1.164432 -0.135802 105.554097 180.611149 4.808119e-01 4.168943e-27 0.484160 0 1
2 75.818592 -0.688960 4.217875 26.745473 0.173188 1.702686 5.571233 10.456192 4.205480 -0.640830 ... 41.179120 -2.048499 -2.060285 88.839000 94.573758 2.911326e-02 8.633178e-01 0.561923 0 1
3 167.919679 -4.106876 2.664687 39.265503 0.872895 5.447550 0.222917 49.302641 4.527605 -0.201476 ... 18.004806 -2.177271 -1.638312 138.509621 985.571563 5.101841e-01 9.830257e-01 0.695018 1 1
4 211.198986 1.722085 5.363762 60.079350 3.617989 2.822620 2.986224 20.536071 4.570506 -0.073213 ... 113.577391 -0.082111 -1.477354 104.931391 327.616481 9.670123e-01 9.583673e-01 0.144974 1 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
9995 179.536895 -2.198896 5.824548 44.455686 0.217464 6.009975 3.558790 8.675338 2.185412 0.297409 ... 61.431004 0.614294 1.550631 90.480296 272.864556 8.434026e-01 9.422578e-01 0.727435 0 1
9996 126.324773 -0.266018 6.057800 109.739485 -0.275967 4.999130 4.737586 27.654352 5.569802 -0.307197 ... 185.914270 -0.404378 -1.054940 91.512900 118.914089 0.000000e+00 2.401191e-122 0.342996 0 1
9997 109.171854 -1.575872 0.212045 46.863079 0.288242 0.142182 3.250009 36.009504 4.196136 -0.312703 ... 215.453970 -0.160157 -2.606385 95.198448 153.577498 9.979729e-01 9.544165e-01 0.838124 0 1
9998 314.678913 0.803816 1.355712 38.399009 1.614987 2.319213 0.653931 31.069108 5.298284 1.312493 ... 65.500176 1.167349 -0.376793 83.755828 137.012721 5.652720e-05 2.228233e-07 0.094694 0 1
9999 99.152141 -1.644103 1.775950 45.133586 -1.181621 1.986518 2.716860 11.789360 4.567087 -0.430057 ... 37.335738 -0.916864 1.077127 88.458963 34.235184 2.973423e-04 1.003417e-03 0.595205 0 1

10000 rows × 24 columns

[4]:
p_ztt = Process(r"$Z\rightarrow\tau\tau$", range=(0, 0))
p_sig = Process(r"Signal", range=(1, 1))

p_asimov = Process(r"Asimov", selection=lambda d: d.fpid >= 0)
[5]:
colors = ["windows blue", "amber", "greyish", "faded green", "dusty purple"]
palette = sns.xkcd_palette(colors)

s_bkg = McStack(p_ztt, p_sig, palette=palette)
s_data = DataStack(p_asimov)
[6]:
v_higgs_m = Variable(r"$m^H$", "higgs_m", "GeV")

Pass the return_uhepp=True argument to hist().

[7]:
h = hist(df, v_higgs_m, 20, [s_bkg, s_data], range=(0, 200), selection=None,
     weight="weight",  ratio_label="Data / SM", return_uhepp=True)
h.render()
[7]:
(<Figure size 500x500 with 2 Axes>,
 (<AxesSubplot:ylabel='Events / 10 GeV'>,
  <AxesSubplot:xlabel='$m^H$ / GeV', ylabel='Data / SM'>))
_images/UHepp_9_1.png
[8]:
json_string = h.to_jsons()
print(json_string)
{"badge": {"brand": null, "subtext": "FreeForestML Example"}, "bins": {"edges": [0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 170.0, 180.0, 190.0, 200.0]}, "metadata": {"date": "2023-08-02T16:41:33.389677+00:00", "filename": "unnamed", "producer": "freeforestml", "tags": {}}, "ratio": [{"denominator": ["den"], "error": "stat", "keep_zero": false, "numerator": ["num_0"], "style": {"color": "#000000"}, "type": "points", "x_errorbar": true}], "ratio_axis": {"diff": false, "label": "Data / SM", "log": false}, "stacks": [{"content": [{"label": "$Z\\rightarrow\\tau\\tau$", "style": {"color": "#3778bf"}, "yield": ["Z_rightarrow_tau_tau__s0_p0"]}, {"label": "Signal", "style": {"color": "#feb308"}, "yield": ["Signal__s0_p1"]}], "error": "stat", "keep_zero": false, "type": "stepfilled", "x_errorbar": true}, {"content": [{"label": "Asimov", "style": {"color": "#000000"}, "yield": ["Asimov__s1_p0"]}], "error": "stat", "keep_zero": false, "type": "points", "x_errorbar": true}], "type": "histogram", "variable": {"symbol": "$m^H$", "unit": "GeV"}, "version": "0.4", "y_axis": {}, "yields": {"Asimov__s1_p0": {"base": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 7.0, 146.0, 1046.0, 2398.0, 2760.0, 1634.0, 654.0, 516.0, 436.0, 273.0, 99.0, 27.0, 4.0, 0.0, 0.0, 0.0], "stat": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.6457513110645907, 12.083045973594572, 32.341923257592455, 48.96937818678118, 52.53570214625479, 40.422765862815474, 25.573423705088842, 22.715633383201094, 20.8806130178211, 16.522711641858304, 9.9498743710662, 5.196152422706632, 2.0, 0.0, 0.0, 0.0]}, "Signal__s0_p1": {"base": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 8.0, 61.0, 222.0, 367.0, 502.0, 436.0, 273.0, 99.0, 27.0, 4.0, 0.0, 0.0, 0.0], "stat": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.8284271247461903, 7.810249675906654, 14.89966442575134, 19.157244060668017, 22.40535650240808, 20.8806130178211, 16.522711641858304, 9.9498743710662, 5.196152422706632, 2.0, 0.0, 0.0, 0.0]}, "Z_rightarrow_tau_tau__s0_p0": {"base": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 7.0, 146.0, 1045.0, 2390.0, 2699.0, 1412.0, 287.0, 14.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "stat": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.6457513110645907, 12.083045973594572, 32.32645975048923, 48.88762624632127, 51.95190083144215, 37.57658845611187, 16.941074346097416, 3.7416573867739413, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}, "den": {"base": [0, 0, 0, 0, 0, 0, 7, 146, 1046, 2398, 2760, 1634, 654, 516, 436, 273, 99, 27, 4, 0, 0, 0], "stat": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.6457513110645907, 12.083045973594572, 32.341923257592455, 48.96937818678118, 52.53570214625479, 40.422765862815474, 25.573423705088842, 22.715633383201094, 20.8806130178211, 16.522711641858304, 9.9498743710662, 5.196152422706632, 2.0, 0.0, 0.0, 0.0]}, "num_0": {"base": [0, 0, 0, 0, 0, 0, 7, 146, 1046, 2398, 2760, 1634, 654, 516, 436, 273, 99, 27, 4, 0, 0, 0], "stat": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.6457513110645907, 12.083045973594572, 32.341923257592455, 48.96937818678118, 52.53570214625479, 40.422765862815474, 25.573423705088842, 22.715633383201094, 20.8806130178211, 16.522711641858304, 9.9498743710662, 5.196152422706632, 2.0, 0.0, 0.0, 0.0]}}}

You could now save the json_string as a file or push it to uhepp.org via h.push(collection_id). Here will will simply restore the plot from the string.

[9]:
h = uhepp.from_jsons(json_string)
h.render()
[9]:
(<Figure size 500x500 with 2 Axes>,
 (<AxesSubplot:ylabel='Events / 10 GeV'>,
  <AxesSubplot:xlabel='$m^H$ / GeV', ylabel='Data / SM'>))
_images/UHepp_12_1.png
[10]:
h.rebin_edges = [0, 70, 80, 90, 100, 110, 120, 130, 140, 150, 200]
h.subtext = "Hello"
h.brand = None
h.render()
[10]:
(<Figure size 500x500 with 2 Axes>,
 (<AxesSubplot:ylabel='Events / Bin'>,
  <AxesSubplot:xlabel='$m^H$ / GeV', ylabel='Data / SM'>))
_images/UHepp_13_1.png