10 return [key.GetName()
for key
in gDirectory.GetListOfKeys()]
11 TFile.GetKeyNames = GetKeyNames
16 for aBin
in range(1,self.GetNbinsX()+2):
17 xBins.append(self.GetXaxis().GetBinLowEdge(aBin))
20 if self.GetDimension() > 1:
21 for aBin
in range(1,self.GetNbinsY()+2):
22 yBins.append(self.GetYaxis().GetBinLowEdge(aBin))
25 if self.GetDimension() > 2:
26 for aBin
in range(1,self.GetNbinsZ()+2):
27 zBins.append(self.GetZaxis().GetBinLowEdge(aBin))
30 xBins = [aVal*factor
for aVal
in xBins]
32 yBins = [aVal*factor
for aVal
in yBins]
34 zBins = [aVal*factor
for aVal
in zBins]
37 if self.GetDimension() == 1:
38 if isinstance(self,TH1C):
39 histo = TH1C(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins))
40 elif isinstance(self,TH1S):
41 histo = TH1S(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins))
42 elif isinstance(self,TH1I):
43 histo = TH1I(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins))
44 elif isinstance(self,TH1F):
45 histo =
TH1F(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins))
46 elif isinstance(self,TH1D):
47 histo = TH1D(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins))
48 for xBin
in range(1,self.GetNbinsX()+1):
49 histo.SetBinContent(xBin,self.GetBinContent(xBin))
50 elif self.GetDimension() == 2:
51 if isinstance(self,TH2C):
52 histo = TH2C(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins))
53 elif isinstance(self,TH2S):
54 histo = TH2S(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins))
55 elif isinstance(self,TH2I):
56 histo = TH2I(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins))
57 elif isinstance(self,TH2F):
58 histo =
TH2F(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins))
59 elif isinstance(self,TH2D):
60 histo = TH2D(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins))
61 for xBin
in range(1,self.GetNbinsX()+1):
62 for yBin
in range(1,self.GetNbinsY()+1):
63 histo.SetBinContent(xBin,yBin,self.GetBinContent(xBin,yBin))
64 elif self.GetDimension() == 3:
65 if isinstance(self,TH3C):
66 histo = TH3C(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins),len(zBins)-1,array.array(
'd',zBins))
67 elif isinstance(self,TH3S):
68 histo = TH3S(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins),len(zBins)-1,array.array(
'd',zBins))
69 elif isinstance(self,TH3I):
70 histo = TH3I(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins),len(zBins)-1,array.array(
'd',zBins))
71 elif isinstance(self,TH3F):
72 histo = TH3F(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins),len(zBins)-1,array.array(
'd',zBins))
73 elif isinstance(self,TH3D):
74 histo = TH3D(self.GetName()+
"_scaled",self.GetTitle(),len(xBins)-1,array.array(
'd',xBins),len(yBins)-1,array.array(
'd',yBins),len(zBins)-1,array.array(
'd',zBins))
75 for xBin
in range(1,self.GetNbinsX()+1):
76 for yBin
in range(1,self.GetNbinsY()+1):
77 for zBin
in range(1,self.GetNbinsZ()+1):
78 histo.SetBinContent(xBin,yBin,zBin,self.GetBinContent(xBin,yBin,zBin))
81 TH1.ScaleBins = ScaleBins
85 if len(sys.argv) != 3:
86 print "Incorrect number of arguments. Expected the following:"
87 print " 1. Output root file"
88 print " 2. Input root file"
91 outFileName = sys.argv[1]
92 inFileName = sys.argv[2]
95 if not outFileName.endswith(
".root"):
96 print "Output file doesn't appear to be a root file:",outFile
97 print "Blocking for safety"
99 if not inFileName.endswith(
".root"):
100 print "Input file doesn't appear to be a root file:",inFileName
101 print "Blocking for safety"
105 outFile = TFile.Open(outFileName,
"RECREATE")
106 inFile = TFile.Open(inFileName,
"READ")
110 validHist = inFile.Get(
"Valid_area")
116 validHist.Write(
"Valid_area")
117 for histName
in inFile.GetKeyNames():
118 hist = inFile.Get(histName)
120 histNameConverted =
None
121 jetType=
"AntiKt10LCTopoTrimmedPtFrac5SmallR30"
122 if histName.startswith(
"valid")
or histName.startswith(
"Valid"):
124 elif histName.endswith(jetType+
"_pT"):
125 histNameConverted = re.sub(jetType+
"_pT",
"pT_"+jetType,histName)
126 elif histName.endswith(jetType+
"_Pileup_NPV"):
127 histNameConverted = re.sub(jetType+
"_Pileup_NPV",
"Pileup_NPV_"+jetType,histName)
128 elif histName.endswith(jetType+
"_Pileup_Mu"):
129 histNameConverted = re.sub(jetType+
"_Pileup_Mu",
"Pileup_Mu_"+jetType,histName)
130 elif histName.endswith(jetType):
131 histNameConverted = histName
133 print "Unexpected hist name: ",histName
138 if "Pileup" in histName:
141 for aBin
in range(1,hist.GetNbinsX()+2):
142 bins.append(hist.GetXaxis().GetBinLowEdge(aBin))
143 binArray = array.array(
'd',bins)
146 etaBinArray = array.array(
'd',etaBins)
148 converted = TH2D(histName+
"_2D",hist.GetTitle(),len(bins)-1,binArray,len(etaBins)-1,etaBinArray)
150 for aBin
in range(1,hist.GetNbinsX()+1):
151 if fabs(hist.GetXaxis().GetBinLowEdge(aBin) - converted.GetXaxis().GetBinLowEdge(aBin)) > 1.e-4:
152 print "ERROR: Bin edges differ, %f vs %f"%(hist.GetXaxis().GetBinLowEdge(aBin),converted.GetXaxis().GetBinLowEdge(aBin))
154 converted.SetBinContent(aBin,1,hist.GetBinContent(aBin))
164 converted.Write(histNameConverted)
165 if not "Pileup" in histNameConverted:
166 validHist.Write(
"valid_"+histNameConverted)