57def normalize_rows_ROOT(inputs):
58 """
59 Normalize each row (Y-bin) of a TH2F to a maximum of 1.
60 Rows with zero entries are skipped.
61 """
62 hist2d = inputs[0][1][0]
63 name = hist2d.GetName()
64
65 print(
"normalize rows for this hist:", hist2d)
66
67
68 norm_hist = hist2d.Clone(name + "_row_normalized")
69 norm_hist.Reset()
70
71 n_bins_x = hist2d.GetNbinsX()
72 n_bins_y = hist2d.GetNbinsY()
73
74 for iy in range(1, n_bins_y + 1):
75
76 proj = hist2d.ProjectionX(f"{name}_proj_{iy}", iy, iy)
77
78 if proj.GetEntries() == 0:
79 print(f
"Row {iy}: zero entries, skipping")
80 continue
81
82 max_val = proj.GetMaximum()
83
84 if max_val == 0:
85 print(f
"Row {iy}: max is zero, skipping")
86 continue
87
88
89 for ix in range(1, n_bins_x + 1):
90 val = hist2d.GetBinContent(ix, iy)
91 err = hist2d.GetBinError(ix, iy)
92
93 norm_hist.SetBinContent(ix, iy, val / max_val)
94 norm_hist.SetBinError(ix, iy, err / max_val)
95
96 norm_hist.SetTitle(hist2d.GetTitle() + " (row-normalized)")
97 norm_hist.GetXaxis().SetTitle(hist2d.GetXaxis().GetTitle())
98 norm_hist.GetYaxis().SetTitle(hist2d.GetYaxis().GetTitle())
99
100 return [norm_hist]
void print(char *figname, TCanvas *c1)