ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
Jet
JetUncertainties
testingMacros
InputScripts
January2018_specialStatTerms
January2018_specialStatTerms/ParseFlavourInput.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
9
def
GetKeyNames(self,dir=""):
10
self.cd(dir)
11
return
[key.GetName()
for
key
in
gDirectory.GetListOfKeys()]
12
TFile.GetKeyNames = GetKeyNames
13
14
15
SystematicNames = {
'lqResponsePythia'
:
'flavorCompLight'
,
16
'gluonResponsePythia'
:
'flavorCompGlu'
,
17
'gluonResponseDiff'
:
'FlavorResponse'
}
18
jetDefDict = {
19
'AntiKt4EMTopo'
:
'AntiKt4Topo_EMJES'
,
20
'AntiKt4EMPflow'
:
'AntiKt4PFlow_EMJES'
,
21
}
22
23
def
ReadFlavourHistograms(dirName,freezepT=False):
24
print
"Beginning flavour"
25
if
not
dirName.endswith(
"/"
)
and
not
dirName.endswith(
".root"
):
26
dirName = dirName +
"/"
27
if
dirName.endswith(
"/"
) :
28
files = sorted(glob.glob(dirName+
"*.root"
))
29
else
:
30
files = [dirName]
31
32
# Run over each file (one per jet definition for LQ/Gluon and one per jet definition for HvP)
33
histos = {}
34
for
aFileName
in
files:
35
# Determine the jet definition
36
jetDef =
""
37
for
jetDef
in
jetDefDict.keys() :
38
print
"Beginning jetDef"
,jetDef
39
if
jetDefDict[jetDef]
not
in
histos:
40
histos[jetDefDict[jetDef]] = {}
41
42
# Read in the histograms from the file
43
# Note that we want all the histograms, but with this scheme not everything in the dict is in each file
44
# So instead loop over all histos in the file
45
inFile = TFile(aFileName,
"READ"
)
46
for
histName
in
inFile.GetKeyNames():
47
systName = histName.split(
"_"
)[0]
48
if
not
jetDef
in
histName :
49
continue
50
if
not
systName
in
SystematicNames.keys() :
51
if
"bResponse"
in
systName :
52
continue
53
print
"Error!!!"
,systName,
"not in"
,SystematicNames.keys()
54
continue
55
systematicName = systName +
"_"
+ jetDefDict[jetDef]
56
histo = inFile.Get(histName)
57
if
histo
is
None
:
58
print
"Failed to get histogram:"
,systematicName
59
return
None
60
61
if
freezepT :
62
# Loop over eta bins.
63
for
ybin
in
range(histo.GetNbinsY()+2) :
64
# Loop out in pT.
65
freezeval = 0
66
for
xbin
in
range(histo.GetNbinsX()+2) :
67
inbin = histo.GetBinContent(xbin,ybin)
68
#print "Bin at pT ",histo.GetXaxis().GetBinCenter(xbin)," and [ylow,y,yhigh] = ", binYLow, histo.GetYaxis().GetBinCenter(ybin), binYHigh
69
# Store bin contents as we go out: last one is one we want as frozen value.
70
if
inbin > 0 :
71
freezeval = inbin
72
else
:
73
histo.SetBinContent(xbin,ybin,freezeval)
74
75
# Already eta symmetric.
76
#histoSym = ProviderHistoHelpers.SymmetrizeHistoInEta(histo,systematicName)
77
histo.SetDirectory(0)
78
histos[jetDefDict[jetDef]][SystematicNames[systName]] = histo
79
80
# Done reading, close the file
81
inFile.Close()
82
83
print
"Done flavour.\n"
84
return
histos
Generated on
for ATLAS Offline Software by
1.17.0