4 from array
import array
11 from ParseCurrentFile
import ReadCurrentHistograms
15 from itertools
import groupby
17 return [
int(
''.
join(g))
if k
else ''.
join(g)
for k, g
in groupby(s[0], str.isdigit)]
20 jetreplacements = {
"AntiKt4EMTopo":
"AntiKt4Topo_EMJES"}
22 replacements[
"/cluster/warehouse/kpachal/JetCalibration/JetUncertainties/JetUncertainties/inputs/PunchThrough/"] = {
23 "PunchThrough_MC15" :
"PunchThrough_MC15",
31 print "USAGE: Expected the following arguments"
32 print " 1. Root file to use as template"
33 print " 2. Name of output root file to create"
36 inputFile = sys.argv[1]
37 outBaselineFile = sys.argv[2]
40 if not outBaselineFile.endswith(
".root"):
41 print "Output ROOT file doesn't appear to be a root file:",outBaselineFile
43 if not os.path.exists(inputFile):
44 print "Input file does not exist:",inputFile
46 for filename
in replacements.keys():
47 if not os.path.exists(filename) :
48 print "Replacement input file does not exist:",filename
52 print "Reading inputs..."
58 import ParseFlavourInput
59 import ParseNonClosureInput
60 import ParsePunchthroughInput
62 theReplacementHistos = {}
63 for filename
in replacements.keys() :
64 if "flavor" in filename
or "Flavor" in filename
or "flavour" in filename
or "Flavour" in filename :
66 elif "AFII_Uncertainty" in filename :
68 print "Just retrieved",thisset
69 elif "PunchThrough" in filename :
74 theReplacementHistos.update(thisset)
77 print "Merging inputs..."
78 jetDefs = [
"AntiKt4EMTopo"]
81 for aJetDef
in jetDefs :
82 systematics[aJetDef] = dict(
83 theCurrentHistos[aJetDef].
items()
87 print "Writing to output file",outBaselineFile,
"..."
88 baselineFile = TFile(outBaselineFile,
"RECREATE")
89 for aJetDef,aSyst
in sorted(systematics.iteritems(),key=natural_sort):
90 for aSystName,aSystHisto
in sorted(aSyst.iteritems(),key=natural_sort):
92 for filename
in replacements.keys() :
93 if aSystName
in replacements[filename].
keys() :
94 print "Writing new version of",aSystName
95 newName = replacements[filename][aSystName]
96 newHist = theReplacementHistos[jetreplacements[aJetDef]][newName]
97 newHist.SetDirectory(0)
98 newHist.SetTitle(aSystName+
"_"+aJetDef)
99 print "Giving it name",newHist.GetTitle()
100 newHist.Write(newHist.GetTitle())
101 elif aSystName
in deletions :
102 print "Deleting histogram",aSystName
105 print "Keeping original version of",aSystName
106 aSystHisto.SetTitle(aSystName+
"_"+aJetDef)
107 aSystHisto.Write(aSystHisto.GetTitle())