10 return [key.GetName()
for key
in gDirectory.GetListOfKeys()]
11 TFile.GetKeyNames = GetKeyNames
15 tokens = histName.split(
"_")
19 print "Too few arguments. Expected the following:"
20 print " 1. Input file"
21 print " 2. Output file"
22 print " 3. Output name of histogram"
23 print " 4+ Input histogram name(s) to be combined in a special format"
24 print " Format: histName,minVal,maxVal"
25 print " Example: PunchThroughCentral,0,1.3 where values are for |eta|"
28 inputFile = TFile.Open(sys.argv[1],
"READ")
29 outputFile = TFile.Open(sys.argv[2],
"RECREATE")
31 inTuples = sys.argv[4:]
36 for inTuple
in inTuples:
37 tokens = inTuple.split(
",")
39 print "Unexpected input format: ",inTuple
41 inNames.append(tokens[0])
42 inMinVals.append(
float(tokens[1]))
43 inMaxVals.append(
float(tokens[2]))
49 for histName
in inputFile.GetKeyNames():
50 hist = inputFile.Get(histName)
53 for inName,inMin,inMax
in zip(inNames,inMinVals,inMaxVals):
54 if TString(histName).Contains(inName):
57 if not (jetDef
in inHists):
59 inHists[jetDef][
"hist"] = []
60 inHists[jetDef][
"min"] = []
61 inHists[jetDef][
"max"] = []
62 inHists[jetDef][
"hist"].
append(hist)
63 inHists[jetDef][
"min"].
append(inMin)
64 inHists[jetDef][
"max"].
append(inMax)
71 for aJetDef,aHist
in inHists.iteritems():
73 minVals = aHist[
"min"]
74 maxVals = aHist[
"max"]
77 for iX
in range(1,hists[0].GetXaxis().GetNbins()+2):
78 xBins.append(hists[0].GetXaxis().GetBinLowEdge(iX))
81 for iY
in range(1,hists[0].GetYaxis().GetNbins()+2):
82 yBins.append(hists[0].GetYaxis().GetBinLowEdge(iY))
87 for minVal,maxVal,hist
in zip(minVals,maxVals,hists):
88 zDict[minVal] = maxVal
89 for minVal,maxVal
in sorted(zDict.iteritems()):
94 elif fabs(zBins[-1]-minVal)<1.e-3:
97 print "Min value does not correspond to previous max"
98 print "Max value: ",zBins[-1]
99 print "Min value: ",minVal
103 outHists[aJetDef] = TH3D(outName+
"_"+aJetDef,outName+
"_"+aJetDef,len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins),len(zBins)-1,array.array(
'd',zBins))
104 outHist = outHists[aJetDef]
107 for minVal,maxVal
in sorted(zDict.iteritems()):
109 for minValGlobal,iVal
in zip(minVals,
range(0,len(minVals))):
110 if fabs(minValGlobal-minVal)<1.e-3:
114 for xBin
in range(1,hist.GetXaxis().GetNbins()+1):
115 for yBin
in range(1,hist.GetYaxis().GetNbins()+1):
116 outHist.SetBinContent(xBin,yBin,index+1,hist.GetBinContent(xBin,yBin))
121 outHist.Write(outName+
"_"+aJetDef)