4 from array
import array
8 import ProviderHistoHelpers
12 return [key.GetName()
for key
in gDirectory.GetListOfKeys()]
13 TFile.GetKeyNames = GetKeyNames
16 'AntiKt4EMTopo' :
'AntiKt4Topo_EMJES',
18 'AntiKt4LCTopo' :
'AntiKt4Topo_LCJES',
22 SystematicNameList = [
'PunchThrough_MC15',
'PunchThrough_AFII']
25 if not dirName.endswith(
"/"):
26 dirName = dirName +
"/"
29 rootFileList =
sorted(glob.glob(dirName+
"*.root"))
31 if len(rootFileList) != 1:
32 print "Found a number of root files not equal to 1 in dir:",dirName
33 print "Assume separate files for EM, LC"
34 for aJetDef
in jetDefDict.keys() :
35 for file
in rootFileList :
37 if aJetDef
not in fileDict.keys() :
38 fileDict[aJetDef] = file
40 print "Oh no! More than one file corresponding to this jet definition:",aJetDef
43 print "Found only one root file: assume contents can be used for all jet collections."
44 for aJetDef
in jetDefDict.keys() :
45 fileDict[aJetDef] = rootFileList[0]
48 for aJetDef,aJetDefProv
in jetDefDict.iteritems():
49 rootFile = TFile(fileDict[aJetDef],
"READ")
50 histos[aJetDefProv] = {}
52 for histName
in rootFile.GetKeyNames():
53 if aJetDef
not in histName:
continue
54 for aKey
in SystematicNameList:
56 histName = aKey+
"_"+aJetDef
57 histo = rootFile.Get(histName)
59 print "Failed to get histogram:",histName
61 histo.SetName(aKey+
"_"+aJetDefProv+
"badaxes")
74 nPTBins = histo.GetXaxis().GetNbins()
75 for bin
in range(1,nPTBins+2) :
76 binEdge = histo.GetXaxis().GetBinLowEdge(bin)
77 pTBinArray.append(binEdge)
78 pTBinArray =
array(
'd',pTBinArray)
82 nEtaBins = histo.GetYaxis().GetNbins()
83 for bin
in range(1,nEtaBins+2) :
84 binEdge = histo.GetYaxis().GetBinLowEdge(bin)
85 etaBinArray.append(binEdge)
87 nEtaBins = histo.GetZaxis().GetNbins()
88 for bin
in range(1,nEtaBins+2) :
89 binEdge = histo.GetZaxis().GetBinLowEdge(bin)
90 etaBinArray.append(binEdge)
91 etaBinArray =
array(
'd',etaBinArray)
93 nSegmentsBinArray = []
95 nNSegBins = histo.GetZaxis().GetNbins()
96 for bin
in range(1,nNSegBins+2) :
97 binEdge = histo.GetZaxis().GetBinLowEdge(bin)
98 nSegmentsBinArray.append(binEdge)
100 nNSegBins = histo.GetYaxis().GetNbins()
101 for bin
in range(1,nNSegBins+2) :
102 binEdge = histo.GetYaxis().GetBinLowEdge(bin)
103 nSegmentsBinArray.append(binEdge)
105 nSegmentsBinArray =
array(
'd',nSegmentsBinArray)
107 outhisto = TH3D(aKey+
"_"+aJetDefProv,aKey+
"_"+aJetDefProv,nPTBins,pTBinArray,nNSegBins,nSegmentsBinArray,nEtaBins,etaBinArray)
108 outhisto.SetDirectory(0)
112 for xbin
in range(histo.GetNbinsX()+2) :
113 for ybin
in range(histo.GetNbinsY()+2) :
114 for zbin
in range(histo.GetNbinsZ()+2) :
121 if histo.GetXaxis().GetBinCenter(xbin) < 50
or \
122 histo.GetYaxis().GetBinCenter(ybin) > 2.7
or \
123 histo.GetZaxis().GetBinCenter(zbin) < 20 :
124 histo.SetBinContent(xbin,ybin,zbin,0.0)
125 outhisto.SetBinContent(xbin,zbin,ybin,0.0)
127 outhisto.SetBinContent(xbin,zbin,ybin,histo.GetBinContent(xbin,ybin,zbin))
129 elif "LC" in aJetDef :
130 if histo.GetXaxis().GetBinCenter(xbin) < 50
or \
131 histo.GetZaxis().GetBinCenter(zbin) > 2.7
or \
132 histo.GetYaxis().GetBinCenter(ybin) < 20 :
133 histo.SetBinContent(xbin,ybin,zbin,0.0)
134 outhisto.SetBinContent(xbin,ybin,zbin,0.0)
136 outhisto.SetBinContent(xbin,ybin,zbin,histo.GetBinContent(xbin,ybin,zbin))
139 histos[aJetDefProv][aKey] = outhisto
143 outhisto = TH3D(aKey+
"_"+aJetDefProv,aKey+
"_"+aJetDefProv,2,15.0,4500.0,2,0.0,1000.0,2,-4.5,4.5)
144 outhisto.SetDirectory(0)
145 histos[aJetDefProv][aKey] = outhisto