13 return [key.GetName()
for key
in gDirectory.GetListOfKeys()]
18 print "Creating reduced root file..."
19 print "Full file: " + fullFileName
20 print "Reduced file: " + reducedFileName
21 print "Output file: " + combinedFileName
22 AllNuisanceParametersFile = TFile.Open(fullFileName,
"READ")
23 ReducedNuisanceParametersFile = TFile.Open(reducedFileName,
"READ")
24 OutputFile = TFile.Open(combinedFileName,
"RECREATE")
26 for histName
in AllNuisanceParametersFile.GetKeyNames():
27 hist = AllNuisanceParametersFile.Get(histName)
31 reducedComponentNames = []
32 for histName
in ReducedNuisanceParametersFile.GetKeyNames():
33 if "EffectiveNP_" in histName:
34 hist = ReducedNuisanceParametersFile.Get(histName)
37 reducedComponentNames.append(histName)
39 ''' This method is no longer relevant due to Reduction changes, retained in case this changes
41 for histName in ReducedNuisanceParametersFile.GetKeyNames():
42 hist = ReducedNuisanceParametersFile.Get(histName)
45 reducedComponentNames.append(histName)
47 for histName in AllNuisanceParametersFile.GetKeyNames():
49 for aComponent in reducedComponentNames:
50 if histName in aComponent:
54 hist = AllNuisanceParametersFile.Get(histName)
59 AllNuisanceParametersFile.Close()
60 ReducedNuisanceParametersFile.Close()
63 return reducedComponentNames
67 line = file.readline()
68 sanitizedLine = re.sub(
'\r',
'',line)
74 sanitizedName = re.sub(
';1',
'',aName)
75 sanitizedName = re.sub(
'_AntiKt4Topo_EMJES',
'',sanitizedName)
76 sanitizedName = re.sub(
'_AntiKt6Topo_EMJES',
'',sanitizedName)
77 sanitizedName = re.sub(
'_AntiKt4Topo_LCJES',
'',sanitizedName)
78 sanitizedName = re.sub(
'_AntiKt6Topo_LCJES',
'',sanitizedName)
83 return "Effective JES Statistical and Method Component %c"%(aName[-1])
84 elif "Detector" in aName:
85 return "Effective JES Detector Component %c"%(aName[-1])
86 elif "Model" in aName:
87 return "Effective JES Modelling Component %c"%(aName[-1])
88 elif "Mixed" in aName:
89 return "Effective JES Mixed Modelling and Detector Component %c"%(aName[-1])
90 elif "Special" in aName:
91 print "WARNING: Including a special component directly - %s"%(aName)
92 return "Effective JES Special Component %c"%(aName[-1])
93 elif "UNKNOWN" in aName:
94 print "WARNING: Including an unknown component - %s"%(aName)
95 return "Effecitve JES Unknown Category Component %c"%(aName[-1])
96 elif "EffectiveNP_" in aName:
97 if "restTerm" in aName:
98 return "Effective JES Uncertainty Component %c"%(aName[-9])
100 return "Effective JES Uncertainty Component %c"%(aName[-1])
102 print "ERROR: Including an unrecognized component"
107 if "etaintercalibration_totalstat" in aName.lower():
109 elif "etaintercalibration_modelling" in aName.lower():
111 elif "stat" in aName.lower():
113 elif "detector" in aName.lower():
115 elif "model" in aName.lower():
117 elif "mixed" in aName.lower():
119 elif "special" in aName.lower():
121 elif "EffectiveNP_" in aName:
127 for aName
in listOfNames:
130 elif "Detector" in aName:
132 elif "Model" in aName:
134 elif "Mixed" in aName:
142 return re.sub(
"JESComponent.[0-9]*.",
"JESComponent.%d."%(newNumber),line)
145 print "Creating reduced config file..."
148 inputFile =
open(fullFileName,
"r")
149 outputFile =
open(combinedFileName,
"w")
153 if "GlobalReduction" in combinedFileName:
154 reductionString =
"Reduction was applied globally"
155 elif "CategoryReduction" in combinedFileName:
156 reductionString =
"Reduction was applied within each category"
158 reductionString =
"Unknown type of reduction"
161 now = datetime.datetime.now()
162 outputFile.write(
"\n#######################################\n#\n")
163 outputFile.write(
"# JESProvider Input Settings\n")
164 outputFile.write(
"# Reduced set of nuisance parameters from final 2011 iteration of the in-situ JES\n")
165 outputFile.write(
"# %s\n"%(reductionString))
167 outputFile.write(
"# %s %d, %d\n#\n"%(calendar.month_name[now.month],now.day,now.year))
169 outputFile.write(
"#\n#######################################\n\n")
172 outputFile.write(
"JESUncertaintyRootFile: %s\n"%(combinedRootFileName))
175 outputFile.write(
"\n#######################################\n#\n")
176 outputFile.write(
"# Settings for JES Components\n")
177 outputFile.write(
"#\n#######################################\n\n")
181 compNamesSanitized = []
182 for aName
in componentNames:
184 if sanitizedName
not in compNamesSanitized:
185 compNamesSanitized.append(sanitizedName)
188 for aName
in compNamesSanitized:
189 outputFile.write(
"JESComponent.%d.Desc: %s\n"%(i,
getDescFromName(aName)))
190 outputFile.write(
"JESComponent.%d.Name: %s\n"%(i,aName))
192 outputFile.write(
"\n")
197 outputFile.write(
"\n#######################################\n\n")
201 inputFile =
open(fullFileName,
"r")
205 while (nextLine !=
""):
206 if "Special" not in nextLine
and "EtaIntercal" not in currLine:
208 previousLine = currLine
218 previousLine = currLine
223 if (
"SubComponent" in nextLine):
225 previousLine = currLine
229 outputFile.write(
"\n")
233 outputFile.write(
"\n#\n#######################################\n")
238 print "Created config file: %s\n"%(combinedFileName)
241 if (len(sys.argv) < 7):
242 print "Too few arguments. Expected the following:"
243 print "\t1. Path to the JetUncertainties share directory"
244 print "\t2. Input (full) config file"
245 print "\t3. Input (full) root file"
246 print "\t4. Reduced root file (only effective nuisance parameters)"
247 print "\t5. Output config file"
248 print "\t6. Output root file"
251 sharePath = sys.argv[1]
252 fullConfigFile = sys.argv[2]
253 fullRootFile = sys.argv[3]
254 reducedRootFile = sys.argv[4]
255 outConfigFile = sys.argv[5]
256 outRootFile = sys.argv[6]
259 TFile.GetKeyNames = GetKeyNames
262 compNames =
CombineRootFiles(sharePath+
"/"+fullRootFile,reducedRootFile,sharePath+
"/"+outRootFile)
263 CombineConfigFiles(sharePath+
"/"+fullConfigFile,sharePath+
"/"+outConfigFile,outRootFile,compNames)