ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonValidation
MuonDQA
MuonTrackMonitoring
python
MuonTrackMonitorPostProcessing.py
Go to the documentation of this file.
1
"""
2
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
2021 Peter Kraemer - Uni Mainz
4
"""
5
6
7
"""Implement functions for postprocessing used by histgrinder."""
8
9
10
def
project_mean_ROOT
(inputs):
11
"""Fit peak for every row in 2D histogram."""
12
mean = inputs[0][1][0].ProjectionY().Clone()
13
mean.Clear()
14
sigma = inputs[0][1][0].ProjectionY().Clone()
15
sigma.Clear()
16
name = inputs[0][1][0].GetName()
17
n_bins_y = inputs[0][1][0].GetNbinsY()
18
for
i
in
range(n_bins_y):
19
tmp = inputs[0][1][0].ProjectionX(name, i,i).Clone()
20
if
tmp.GetEntries() == 0:
21
print
(
"zero entries in Projection"
)
22
continue
23
mean.SetBinContent(i, tmp.GetMean(1))
24
mean.SetBinError(i, tmp.GetMeanError(1))
25
sigma.SetBinContent(i, tmp.GetRMS(1))
26
sigma.SetBinError(i, tmp.GetRMSError(1))
27
mean.SetTitle(inputs[0][1][0].GetTitle()+
"projection mean"
)
28
mean.GetXaxis().SetTitle(
"#eta regions"
)
29
mean.GetYaxis().SetTitle(
"entries"
)
30
sigma.SetTitle(inputs[0][1][0].GetTitle()+
"projection sigma"
)
31
sigma.GetXaxis().SetTitle(
"#eta regions"
)
32
sigma.GetYaxis().SetTitle(
"entries"
)
33
return
[mean, sigma]
34
35
def
efficiencies_2d
(inputs):
36
"""Returns 2D efficiencies from two 2D input histograms, the first the selective and the second the inclusive histogram."""
37
selective = inputs[0][1][0].Clone()
38
inclusive = inputs[0][1][1].Clone()
39
efficiency = selective.Clone()
40
efficiency.Reset()
41
42
n_bins_x = selective.GetNbinsX()
43
n_bins_y = selective.GetNbinsY()
44
for
i
in
range(n_bins_x):
45
for
j
in
range(n_bins_y):
46
bin1 = selective.GetBinContent(i, j)
47
bin2 = inclusive.GetBinContent(i, j)
48
eff = float(bin1)/float(bin2)
if
bin2!=0
else
0
49
efficiency.SetBinContent(i, j, eff)
50
51
efficiency.SetTitle(selective.GetTitle())
52
efficiency.GetXaxis().SetTitle(
"eta"
)
53
efficiency.GetYaxis().SetTitle(
"phi"
)
54
return
[efficiency]
55
56
57
def
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
# Clone histogram for output
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
# Project this row (fixed Y-bin) onto X
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
# Normalize this row
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]
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
MuonTrackMonitorPostProcessing.project_mean_ROOT
project_mean_ROOT(inputs)
Definition
MuonTrackMonitorPostProcessing.py:10
MuonTrackMonitorPostProcessing.efficiencies_2d
efficiencies_2d(inputs)
Definition
MuonTrackMonitorPostProcessing.py:35
MuonTrackMonitorPostProcessing.normalize_rows_ROOT
normalize_rows_ROOT(inputs)
Definition
MuonTrackMonitorPostProcessing.py:57
Generated on
for ATLAS Offline Software by
1.17.0