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']
25 if not dirName.endswith(
"/"):
26 dirName = dirName +
"/"
29 rootFileList =
sorted(glob.glob(dirName+
"*.root"))
30 if len(rootFileList) != 1:
31 print "Found a number of root files not equal to 1 in dir:",dirName
33 rootFile = TFile(rootFileList[0],
"READ")
36 for aJetDef,aJetDefProv
in jetDefDict.iteritems():
37 histos[aJetDefProv] = {}
39 for histName
in rootFile.GetKeyNames():
40 if aJetDef
not in histName:
continue
41 for aKey
in SystematicNameList:
42 histName = aKey+
"_"+aJetDef
43 histo = rootFile.Get(histName)
45 print "Failed to get histogram:",histName
47 histo.SetName(aKey+
"_"+aJetDefProv+
"badaxes")
57 nPTBins = histo.GetXaxis().GetNbins()
58 for bin
in range(1,nPTBins+2) :
59 binEdge = histo.GetXaxis().GetBinLowEdge(bin)
60 pTBinArray.append(binEdge)
61 pTBinArray =
array(
'd',pTBinArray)
64 nEtaBins = histo.GetYaxis().GetNbins()
65 for bin
in range(1,nEtaBins+2) :
66 binEdge = histo.GetYaxis().GetBinLowEdge(bin)
67 etaBinArray.append(binEdge)
68 etaBinArray =
array(
'd',etaBinArray)
70 nSegmentsBinArray = []
71 nNSegBins = histo.GetZaxis().GetNbins()
72 for bin
in range(1,nNSegBins+2) :
73 binEdge = histo.GetZaxis().GetBinLowEdge(bin)
74 nSegmentsBinArray.append(binEdge)
75 nSegmentsBinArray =
array(
'd',nSegmentsBinArray)
77 outhisto = TH3D(aKey+
"_"+aJetDefProv,aKey+
"_"+aJetDefProv,nPTBins,pTBinArray,nNSegBins,nSegmentsBinArray,nEtaBins,etaBinArray)
78 outhisto.SetDirectory(0)
82 for xbin
in range(histo.GetNbinsX()+2) :
83 for ybin
in range(histo.GetNbinsY()+2) :
84 for zbin
in range(histo.GetNbinsZ()+2) :
90 if histo.GetXaxis().GetBinCenter(xbin) < 50
or \
91 histo.GetYaxis().GetBinCenter(ybin) > 2.7
or \
92 histo.GetZaxis().GetBinCenter(zbin) < 20 :
93 histo.SetBinContent(xbin,ybin,zbin,0.0)
97 outhisto.SetBinContent(xbin,zbin,ybin,0.0)
99 outhisto.SetBinContent(xbin,zbin,ybin,histo.GetBinContent(xbin,ybin,zbin))
105 histos[aJetDefProv][aKey] = outhisto