12This module contains classes for plotting validation results.
14from pxd.utils.plots import plot_in_module_efficiency, plot_efficiency_vs_run, \
15 plot_module_efficiencies_in_DHHs, plot_efficiency_map, plot_ip_resolutions
21def analyse_root_file(file_name, tree_name="tree"):
23 Function to analyse the ROOT file generated from validation algorithm
25 file_name (str): name of the ROOT file
26 tree_name (str): name of the TTree
29 tfile = ROOT.TFile.Open(file_name)
30 tree = tfile.Get(tree_name)
32 branches = [
'exp',
'run',
'pxdid',
'uBin',
'vBin',
'nTrackPoints',
'nSelTrackPoints',
'nSelTrackClusters',
'nTrackClusters']
33 df = uproot.open(file_name)[tree_name].arrays(branches, library=
'pd')
34 experiment_number = df.exp.min()
35 run_range = (df.run.min(), df.run.max())
36 prefix = f
"e{experiment_number:05}_r{run_range[0]:04}-{run_range[1]:04}_"
39 df.calculate_eff(num=
"nTrackClusters", den=
"nTrackPoints", output_var=
"eff")
40 df.calculate_eff(num=
"nSelTrackClusters", den=
"nSelTrackPoints", output_var=
"eff_sel")
42 plot_in_module_efficiency(
47 cut=
"eff_sel>0&eff_sel_err_low<0.01",
48 yerr_low=
"eff_sel_err_low",
49 yerr_up=
"eff_sel_err_up",
50 save_to=prefix +
"efficiency_in_selected_regions_H1052.png")
53 df_sum_all = df.groupby([
'exp',
'run'])[[
"nTrackPoints",
"nSelTrackPoints",
54 "nTrackClusters",
"nSelTrackClusters"]].sum().reset_index()
55 df_sum_all.calculate_eff(num=
"nTrackClusters", den=
"nTrackPoints", output_var=
"eff")
56 df_sum_all.calculate_eff(num=
"nSelTrackClusters", den=
"nSelTrackPoints", output_var=
"eff_sel")
58 plot_efficiency_vs_run(df=df_sum_all, max_err=0.01, save_to=prefix +
"pxd_efficiency_vs_run.png")
61 df_module_sum = df.groupby([
'exp',
'run',
'pxdid'])[[
"nTrackPoints",
"nSelTrackPoints",
62 "nTrackClusters",
"nSelTrackClusters"]].sum().reset_index()
63 df_module_sum[
"pxdid"] = df_module_sum[
"pxdid"].astype(np.int32)
64 df_module_sum.calculate_eff(num=
"nTrackClusters", den=
"nTrackPoints", output_var=
"eff")
65 df_module_sum.calculate_eff(num=
"nSelTrackClusters", den=
"nSelTrackPoints", output_var=
"eff_sel")
67 plot_module_efficiencies_in_DHHs(df=df_module_sum, save_to=prefix +
"efficiency_vs_run.png")
70 c1 = ROOT.TCanvas(
"c1",
"c1", 900, 600)
71 ROOT.gStyle.SetPalette(ROOT.kDarkRainBow)
77 num_name=
"hTrackClustersLayer1",
78 den_name=
"hTrackPointsLayer1",
79 save_to=prefix +
"efficiency_l1.png",
86 num_name=
"hTrackClustersLayer2",
87 den_name=
"hTrackPointsLayer2",
88 title=
"Efficiency of layer 2",
89 save_to=prefix +
"efficiency_l2.png",
92 plot_ip_resolutions(tree=tree, save_to=prefix +
"pxd_resolutions_vs_run.png")
95if __name__ ==
"__main__":
97 file_name = sys.argv[1]
98 ROOT.gROOT.SetBatch(
True)
99 analyse_root_file(file_name)