2 from array
import array
9 from ParseCurrentFile
import ReadCurrentHistograms
13 from itertools
import groupby
15 return [
int(
''.
join(g))
if k
else ''.
join(g)
for k, g
in groupby(s[0], str.isdigit)]
18 jetreplacements = {
"AntiKt4EMTopo":
"AntiKt4Topo_EMJES"}
20 replacements[
"/cluster/warehouse/kpachal/JetCalibration/JetUncertainties/JetUncertainties/inputs/PunchThrough/"] = {
21 "PunchThrough_MC15" :
"PunchThrough_MC15",
29 print "USAGE: Expected the following arguments"
30 print " 1. Root file to use as template"
31 print " 2. Name of output root file to create"
34 inputFile = sys.argv[1]
35 outBaselineFile = sys.argv[2]
38 if not outBaselineFile.endswith(
".root"):
39 print "Output ROOT file doesn't appear to be a root file:",outBaselineFile
41 if not os.path.exists(inputFile):
42 print "Input file does not exist:",inputFile
44 for filename
in replacements.keys():
45 if not os.path.exists(filename) :
46 print "Replacement input file does not exist:",filename
50 print "Reading inputs..."
56 import ParseFlavourInput
57 import ParseNonClosureInput
58 import ParsePunchthroughInput
60 theReplacementHistos = {}
61 for filename
in replacements.keys() :
62 if "flavor" in filename
or "Flavor" in filename
or "flavour" in filename
or "Flavour" in filename :
64 elif "AFII_Uncertainty" in filename :
66 print "Just retrieved",thisset
67 elif "PunchThrough" in filename :
72 theReplacementHistos.update(thisset)
75 print "Merging inputs..."
76 jetDefs = [
"AntiKt4EMTopo"]
79 for aJetDef
in jetDefs :
80 systematics[aJetDef] = dict(
81 theCurrentHistos[aJetDef].
items()
85 print "Writing to output file",outBaselineFile,
"..."
86 baselineFile = TFile(outBaselineFile,
"RECREATE")
87 for aJetDef,aSyst
in sorted(systematics.iteritems(),key=natural_sort):
88 for aSystName,aSystHisto
in sorted(aSyst.iteritems(),key=natural_sort):
90 for filename
in replacements.keys() :
91 if aSystName
in replacements[filename].
keys() :
92 print "Writing new version of",aSystName
93 newName = replacements[filename][aSystName]
94 newHist = theReplacementHistos[jetreplacements[aJetDef]][newName]
95 newHist.SetDirectory(0)
96 newHist.SetTitle(aSystName+
"_"+aJetDef)
97 print "Giving it name",newHist.GetTitle()
98 newHist.Write(newHist.GetTitle())
99 elif aSystName
in deletions :
100 print "Deleting histogram",aSystName
103 print "Keeping original version of",aSystName
104 aSystHisto.SetTitle(aSystName+
"_"+aJetDef)
105 aSystHisto.Write(aSystHisto.GetTitle())