11 return [key.GetName()
for key
in gDirectory.GetListOfKeys()]
12 TFile.GetKeyNames = GetKeyNames
14 if len(sys.argv) != 3:
15 print "Incorrect number of arguments. Expected the following:"
16 print " 1. Output root file"
17 print " 2. Input root file"
20 outFileName = sys.argv[1]
21 inFileName = sys.argv[2]
24 if not outFileName.endswith(
".root"):
25 print "Output file doesn't appear to be a root file:",outFile
26 print "Blocking for safety"
28 if not inFileName.endswith(
".root"):
29 print "Input file doesn't appear to be a root file:",inFileName
30 print "Blocking for safety"
34 outFile = TFile.Open(outFileName,
"RECREATE")
35 inFile = TFile.Open(inFileName,
"READ")
37 for histName
in inFile.GetKeyNames():
38 hist = inFile.Get(histName)
41 if histName.startswith(
"Zjet")
or histName.startswith(
"MPF")
or histName.startswith(
"Gjet")
or histName.startswith(
"MJB")
or histName.startswith(
"Effective")
or histName.startswith(
"SingleParticle")
or histName.startswith(
"Insitu")
or histName.startswith(
"InSitu"):
44 for aBin
in range(1,hist.GetNbinsX()+2):
45 bins.append(hist.GetXaxis().GetBinLowEdge(aBin))
47 binArray = array.array(
'd',bins)
48 converted = TH1D(histName+
"_1D",hist.GetTitle(),len(bins)-1,binArray)
50 for aBin
in range(1,hist.GetNbinsX()+1):
51 if math.fabs(hist.GetXaxis().GetBinLowEdge(aBin) - converted.GetXaxis().GetBinLowEdge(aBin)) > 1.e-4:
52 print "ERROR: Bin edges differ, %f vs %f"%(hist.GetXaxis().GetBinLowEdge(aBin),converted.GetXaxis().GetBinLowEdge(aBin))
54 converted.SetBinContent(aBin,hist.GetBinContent(aBin,1))
56 histNameConverted =
None
57 if histName.endswith(
"AntiKt4Topo_LCJES"):
58 histNameConverted = re.sub(
"AntiKt4Topo_LCJES",
"AntiKt4LCTopo",histName)
59 elif histName.endswith(
"AntiKt4Topo_EMJES"):
60 histNameConverted = re.sub(
"AntiKt4Topo_EMJES",
"AntiKt4EMTopo",histName)
61 elif histName.endswith(
"AntiKt6Topo_LCJES"):
62 histNameConverted = re.sub(
"AntiKt6Topo_LCJES",
"AntiKt6LCTopo",histName)
63 elif histName.endswith(
"AntiKt6Topo_EMJES"):
64 histNameConverted = re.sub(
"AntiKt6Topo_EMJES",
"AntiKt6EMTopo",histName)
65 elif histName.endswith(
"AntiKt4EMTopo")
or histName.endswith(
"AntiKt4LCTopo")
or histName.endswith(
"AntiKt6EMTopo")
or histName.endswith(
"AntiKt6LCTopo"):
66 histNameConverted = histName
68 print "Unexpected hist name: ",histName
72 if "Pythia8" in histNameConverted
or "MC12a" in histNameConverted:
73 histNameConverted = re.sub(
"Pythia8",
"MC12",re.sub(
"MC12a",
"MC12",histNameConverted))
76 converted.Write(histNameConverted)