ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
Jet
JetUncertainties
testingMacros
InputScripts
January2018_specialStatTerms
ParseEtaIntercalInput_detailed.py
Go to the documentation of this file.
1
from
ROOT
import
*
2
from
array
import
array
3
import
glob
4
import
re
5
import
math
6
import
ProviderHistoHelpers
7
8
def
GetKeyNames
(self,dir=""):
9
self.cd(dir)
10
return
[key.GetName()
for
key
in
gDirectory.GetListOfKeys()]
11
TFile.GetKeyNames = GetKeyNames
12
13
SystematicNames_timeinvariant = {
14
'EtaIntercalibration_TotalSyst'
:
'EtaIntercalibration_TotalSyst'
,\
15
}
16
17
SystematicNames_timedependent = {
18
'E_4TeV'
:
'EtaIntercalibration_NonClosure_highE'
,\
19
'Eta_2p4_to_2p6'
:
'EtaIntercalibration_NonClosure_posEta'
,\
20
'Eta_m2p6_to_m2p4'
:
'EtaIntercalibration_NonClosure_negEta'
21
}
22
23
jetDefDict = {
24
'AntiKt4EMTopo'
:
'AntiKt4Topo_EMJES'
,
25
'AntiKt4EMPFlow'
:
'AntiKt4PFlow_EMJES'
,
26
}
27
28
def
ReadEtaIntercalibrationDetailedStats
(filename, dictionary) :
29
# Inside detailed stats files, individual components are inside of a directory.
30
# Make a special name for each and add it to the output dictionary
31
32
openFile = TFile.Open(filename,
"READ"
)
33
dirName =
"StatNuisanceParams"
34
stat_keys = openFile.GetKeyNames(dirName)
35
36
jet_def =
""
37
for
thing
in
jetDefDict.keys() :
38
if
thing
in
filename :
39
jet_def = thing
40
41
for
key
in
stat_keys :
42
hist = openFile.Get(dirName+
"/"
+key)
43
hist.SetDirectory(0)
44
45
save_name =
"EtaIntercalibration_"
+key
46
hist.SetName(save_name+
"_"
+jet_def)
47
hist.SetTitle(save_name+
"_"
+jet_def)
48
49
dictionary[jetDefDict[jet_def]][save_name] = hist
50
51
return
dictionary
52
53
def
ReadEtaIntercalibrationHistograms
(dirName,year=""):
54
if
not
dirName.endswith(
"/"
):
55
dirName = dirName +
"/"
56
57
# Run over each file (one per jet definition)
58
# Collect files and figure out what they are, matching year token specified in run
59
histos = {}
60
files = sorted(glob.glob(dirName+
"*{0}*.root"
.format(year)))
61
for
aFileName
in
files:
62
# Determine the jet definition
63
jetDef =
""
64
for
aFileDef,aJetDef
in
jetDefDict.iteritems():
65
if
aFileDef
in
aFileName:
66
jetDef = aJetDef
67
break
68
if
jetDef ==
""
:
69
print
"Failed to determine jet definition for file:"
,aFileName
70
return
None
71
if
jetDef
not
in
histos.keys() :
72
histos[jetDef] = {}
73
74
# Read in the histograms of interest from the file
75
inFile = TFile(aFileName,
"READ"
)
76
contents = inFile.GetKeyNames()
77
78
if
year :
79
SystematicNames = SystematicNames_timedependent
80
else
:
81
SystematicNames = SystematicNames_timeinvariant
82
83
for
aName
in
SystematicNames.keys():
84
if
not
"NonClosure"
in
SystematicNames[aName] :
85
if
"Topo"
in
jetDef :
86
getsystematicName = aName +
"_"
+ jetDef.replace(
"Topo"
,
""
)
87
else
:
88
getsystematicName = aName +
"_"
+ jetDef.replace(
"4PFlow"
,
"4EMPFlow"
).
replace
(
"_EMJES"
,
"_PFlowJES"
)
89
else
:
90
getsystematicName = aName
91
92
if
not
getsystematicName
in
contents :
93
continue
94
95
histo = inFile.Get(getsystematicName)
96
97
systematicName = SystematicNames[aName] +
"_"
+ jetDef
98
histo.SetName(systematicName+
"_old"
)
99
100
# Histo has different range, extend it
101
histoNew =
ProviderHistoHelpers.ExtendPtRangeOfHisto
(histo,systematicName)
102
histoNew.SetDirectory(0)
103
histos[jetDef][SystematicNames[aName]] = histoNew
104
105
# Done reading, close the file
106
inFile.Close()
107
108
# Since histos came from a whole mix of files, make sure we got them all in the end.
109
for
aName,storeName
in
SystematicNames.iteritems():
110
for
aJetDef
in
histos.keys():
111
if
not
storeName
in
histos[aJetDef].keys() :
112
print
"Failed to find histogram:"
, storeName,
"for jet definition"
,aJetDef
113
114
# Now, if this is year dependent, add stat histograms
115
if
year :
116
for
thisDef
in
jetDefDict.keys() :
117
files = sorted(glob.glob(dirName+
"*{0}*_statErr_*{1}*.root"
.format(year,thisDef)))
118
if
len(files) != 1 :
119
print
"Did not find right number of stat term files!"
120
print
files
121
exit(1)
122
filename = files[0]
123
print
histos
124
histos =
ReadEtaIntercalibrationDetailedStats
(filename, histos)
125
print
histos
126
127
print
"Histos out here"
128
print
histos
129
print
"\n"
130
return
histos
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition
hcg.cxx:312
ParseEtaIntercalInput_detailed.ReadEtaIntercalibrationDetailedStats
ReadEtaIntercalibrationDetailedStats(filename, dictionary)
Definition
ParseEtaIntercalInput_detailed.py:28
ParseEtaIntercalInput_detailed.ReadEtaIntercalibrationHistograms
ReadEtaIntercalibrationHistograms(dirName, year="")
Definition
ParseEtaIntercalInput_detailed.py:53
ParseEtaIntercalInput_detailed.GetKeyNames
GetKeyNames
Definition
ParseEtaIntercalInput_detailed.py:11
ProviderHistoHelpers.ExtendPtRangeOfHisto
ExtendPtRangeOfHisto(histo, histoName)
Definition
Final2012/ProviderHistoHelpers.py:97
Generated on
for ATLAS Offline Software by
1.17.0