ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonValidation
MuonDQA
MuonPhysValMonitoring
macros
MuonValidation_CreatePullProfiles.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2
3
import
sys
4
import
os
5
from
array
import
array
6
import
itertools
7
import
ROOT
8
from
MuonValidation_CreateResolutionProfiles
import
*
9
10
#---------------------------------------------------------------------------
11
12
#create profile plots for pull parameters vs pt from 2D histograms
13
def
CreateProfile
( infile, HistDir, HistName, Var, doAverage = False ):
14
hist = infile.Get(HistDir).
Get
(HistName)
15
if
not
hist:
16
return
17
prof_ave, prof_std, projHists =
GetProfilesFromTH2
( hist, doAverage = doAverage )
18
19
prof_ave.SetName( hist.GetName().
replace
(
'_vs_'
,
'_ProfMean_vs_'
) )
20
prof_ave.SetTitle( Var +
' Pull vs pt (Mean)'
)
21
prof_ave.SetXTitle(
'Transverse Momentum [GeV]'
)
22
prof_ave.SetYTitle( Var +
' Pull Mean'
)
23
24
prof_std.SetName( hist.GetName().
replace
(
'_vs_'
,
'_ProfStDev_vs_'
) )
25
prof_std.SetTitle( Var +
' Pull vs pt (StDev)'
)
26
prof_std.SetXTitle(
'Transverse Momentum [GeV]'
)
27
prof_std.SetYTitle( Var +
' Pull StdDev'
)
28
29
if
not
infile.Get( HistDir ).WriteTObject( prof_ave, prof_ave.GetName(),
"Overwrite"
):
30
print
(
'WARNING Failed to write histogram to file: '
+ HistDir +
'/'
+ prof_ave.GetName() )
31
if
not
infile.Get( HistDir ).WriteTObject( prof_std, prof_std.GetName(),
"Overwrite"
):
32
print
(
'WARNING Failed to write histogram to file: '
+ HistDir +
'/'
+ prof_std.GetName() )
33
del prof_ave, prof_std
34
35
#---------------------------------------------------------------------------
36
37
def
main
( args ):
38
doAverage =
False
39
if
len( args ) > 1:
40
filename = args[1]
41
if
len(args) > 2
and
args[2] ==
'doAverage'
:
42
doAverage =
True
43
else
:
44
print
(
'Usage: python {0} filename [doAverage]'
.format( args[0] ) )
45
return
46
47
if
not
os.path.exists( filename ):
48
print
(
'File not found: '
+ filename )
49
return
50
51
infile = ROOT.TFile.Open( filename,
'update'
)
52
53
MuonTypes = [
'All'
,
'Prompt'
]
#, 'InFlight', 'NonIsolated' ]
54
Variables = [
'phi'
,
'theta'
,
'qOverP'
,
'd0'
,
'z0'
]
55
56
for
MuonType
in
MuonTypes:
57
if
not
infile.Get(
'Muons/'
+ MuonType ):
58
print
(
'INFO TDirectory not found: Muons/'
+ MuonType )
59
continue
60
AuthDir = infile.Get(
'Muons/{0}/matched'
.format( MuonType ) )
61
Authors = [ i.GetName()
for
i
in
AuthDir.GetListOfKeys()
if
AuthDir.Get( i.GetName() ).InheritsFrom(
'TDirectory'
) ]
62
for
Author
in
Authors:
63
DirName =
'Muons/{0}/matched/{1}/Pulls'
.format( MuonType, Author )
64
Dir = infile.Get( DirName )
65
if
not
Dir:
66
print
(
'INFO TDirectory not found: '
+ DirName )
67
continue
68
for
var
in
Variables:
69
HistName =
'_'
.join( DirName.split(
'/'
) ) +
'_Pull_{0}_vs_pt'
.format(var)
70
if
not
Dir.Get( HistName ):
71
print
(
'INFO Histogram not found: '
+ HistName )
72
continue
73
CreateProfile
( infile, DirName, HistName, var, doAverage = doAverage )
74
infile.Close()
75
76
#---------------------------------------------------------------------------
77
78
if
__name__ ==
"__main__"
:
79
ROOT.gROOT.SetBatch()
80
main
( sys.argv )
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
Get
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...
Definition
comparitor.cxx:181
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition
hcg.cxx:312
main
int main()
Definition
hello.cxx:18
MuonValidation_CreatePullProfiles.CreateProfile
CreateProfile(infile, HistDir, HistName, Var, doAverage=False)
Definition
MuonValidation_CreatePullProfiles.py:13
MuonValidation_CreateResolutionProfiles.GetProfilesFromTH2
GetProfilesFromTH2(hist, doAverage)
Definition
MuonValidation_CreateResolutionProfiles.py:31
Generated on
for ATLAS Offline Software by
1.17.0