TMVA BDT interface

To facilitate the comparison of a trained NN and a classical TMVA BDT, the package provides an interface to compute the output score of a TMVA BDT.

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

from freeforestml import Variable, Process, Cut, hist, McStack, DataStack, Stack, TmvaBdt
from freeforestml import toydata, example_style
example_style()
2023-08-02 16:40:17.383651: 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:40:17.518600: 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:40:17.518632: 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:40:18.341927: 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:40:18.342043: 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:40:18.342056: 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()
df = df.compute()

Evaluation of TMVA BDT

The file tmva_bdt.xml contains a sample BDT trained on the toy dataset. The input variables are - \(\eta^{j_1}\), - \(\eta^{j_2}\), - \(\tau\;\mathrm{centrality}\) and - \(\ell\;\mathrm{centrality}\).

The BDT was trained with regular TMVA in ROOT. The weights stored in the XML file can be read by freeforestml.TmvaBdt directly.

[3]:
bdt = TmvaBdt("tmva_bdt.xml")
df['bdt_prediction'] = bdt.predict(df)

Plotting

[4]:
p_ztt = Process(r"$Z\rightarrow\tau\tau$", range=(0, 0))
p_sig = Process(r"Signal", range=(1, 1))
[5]:
colors = ["windows blue", "amber", "greyish", "faded green", "dusty purple"]
colors = sns.xkcd_palette(colors)
s_ztt = McStack(p_ztt, color=colors[0], histtype='step')
s_sig = McStack(p_sig, color=colors[1], histtype='step')
[6]:
v_bdt = Variable("BDT Score", "bdt_prediction")
hist(df, v_bdt, 22, [s_ztt, s_sig], range=(-1.1, 1.1),
     weight="weight",  numerator=None)
None
_images/TmvaBdt_9_0.png