4 def DMR(config, validationDir):
16 if not dmrType
in config[
"validations"][
"DMR"]:
17 raise Exception(
"No 'single' key word in config for DMR")
19 for singleName
in config[
"validations"][
"DMR"][dmrType]:
20 aux_IOV = config[
"validations"][
"DMR"][dmrType][singleName][
"IOV"]
21 if not isinstance(aux_IOV, list)
and aux_IOV.endswith(
".txt"):
22 config[
"validations"][
"DMR"][dmrType][singleName][
"IOV"] = []
23 with open(aux_IOV,
'r') as IOVfile: for line
in IOVfile.readlines():
24 if len(line) != 0: config[
"validations"][
"DMR"][dmrType][singleName][
"IOV"].
append(
int(line))
25 for IOV
in config[
"validations"][
"DMR"][dmrType][singleName][
"IOV"]:
27 if singleName
not in IOVs.keys():
29 if IOV
not in IOVs[singleName]:
30 IOVs[singleName].
append(IOV)
32 for alignment
in config[
"validations"][
"DMR"][dmrType][singleName][
"alignments"]:
34 workDir =
"{}/DMR/{}/{}/{}/{}".
format(validationDir, dmrType, singleName, alignment, IOV)
38 local[
"output"] =
"{}/{}/DMR/{}/{}/{}/{}".
format(config[
"LFS"], config[
"name"], dmrType, alignment, singleName, IOV)
39 local[
"alignment"] = copy.deepcopy(config[
"alignments"][alignment])
40 local[
"validation"] = copy.deepcopy(config[
"validations"][
"DMR"][dmrType][singleName])
41 local[
"validation"].pop(
"alignments")
42 local[
"validation"][
"IOV"] = IOV
43 if "dataset" in local[
"validation"]:
44 local[
"validation"][
"dataset"] = local[
"validation"][
"dataset"].
format(IOV)
45 if "goodlumi" in local[
"validation"]:
46 local[
"validation"][
"goodlumi"] = local[
"validation"][
"goodlumi"].
format(IOV)
50 "name":
"DMR_{}_{}_{}_{}".
format(dmrType, alignment, singleName, IOV),
53 "cms-config":
"{}/src/Alignment/OfflineValidation/python/TkAlAllInOneTool/DMR_cfg.py".
format(os.environ[
"CMSSW_BASE"]),
62 if "merge" in config[
"validations"][
"DMR"]:
68 for mergeName
in config[
"validations"][
"DMR"][dmrType]:
71 for singleName
in config[
"validations"][
"DMR"][dmrType][mergeName][
'singles']:
72 if len(IOVs[singleName]) == 1
and int(IOVs[singleName][0]) == 1: singlesMC.append(singleName)
73 isMConly = (len(singlesMC) == len(config[
"validations"][
"DMR"][dmrType][mergeName][
'singles']))
75 isDataMerged[mergeName] = 0
76 elif len(singlesMC) == 0:
77 isDataMerged[mergeName] = 1
79 isDataMerged[mergeName] = -1
82 for iname,singleName
in enumerate(config[
"validations"][
"DMR"][dmrType][mergeName][
'singles']):
83 isMC = (singleName
in singlesMC)
84 if isMConly
and iname > 0:
continue 85 elif isMConly: singlesMC.pop(singlesMC.index(singleName))
87 for IOV
in IOVs[singleName]:
88 if isMC
and not isMConly:
continue 91 workDir =
"{}/DMR/{}/{}/{}".
format(validationDir, dmrType, mergeName, IOV)
97 "name":
"DMR_{}_{}_{}".
format(dmrType, mergeName, IOV),
100 "run-mode":
"Condor",
106 for alignment
in config[
"alignments"]:
108 local.setdefault(
"alignments", {})
109 if alignment
in config[
"validations"][
"DMR"][
"single"][singleName][
"alignments"]:
110 local[
"alignments"][alignment] = copy.deepcopy(config[
"alignments"][alignment])
111 local[
"alignments"][alignment][
'index'] = config[
"validations"][
"DMR"][
"single"][singleName][
"alignments"].
index(alignment)
112 for singleMCname
in singlesMC:
113 if alignment
in config[
"validations"][
"DMR"][
"single"][singleMCname][
"alignments"]:
114 local[
"alignments"][alignment] = copy.deepcopy(config[
"alignments"][alignment])
115 local[
"alignments"][alignment][
'index'] = len(config[
"validations"][
"DMR"][
"single"][singleName][
"alignments"])
116 local[
"alignments"][alignment][
'index'] += idxIncrement + config[
"validations"][
"DMR"][
"single"][singleMCname][
"alignments"].
index(alignment)
117 idxIncrement += len(config[
"validations"][
"DMR"][
"single"][singleMCname][
"alignments"])
118 local[
"validation"] = copy.deepcopy(config[
"validations"][
"DMR"][dmrType][mergeName])
119 local[
"validation"][
"IOV"] = IOV
120 if "customrighttitle" in local[
"validation"].
keys():
121 if "IOV" in local[
"validation"][
"customrighttitle"]:
122 local[
"validation"][
"customrighttitle"] = local[
"validation"][
"customrighttitle"].
replace(
"IOV",
str(IOV))
123 local[
"output"] =
"{}/{}/DMR/{}/{}/{}".
format(config[
"LFS"], config[
"name"], dmrType, mergeName, IOV)
126 if "style" in config.keys():
127 if "DMR" in config[
'style'].
keys():
128 if dmrType
in config[
'style'][
'DMR'].
keys():
129 local[
"style"] = copy.deepcopy(config[
"style"][
"DMR"][dmrType])
130 if "Rlabel" in local[
"style"]
and "customrighttitle" in local[
"validation"].
keys():
131 print(
"WARNING: custom right label is overwritten by global settings")
134 for singleJob
in jobs:
136 _alignment, _singleName, _singleIOV = singleJob[
"name"].
split(
"_")[2:]
137 if _singleName
in config[
"validations"][
"DMR"][dmrType][mergeName][
"singles"]:
138 if int(_singleIOV) == IOV
or (
int(_singleIOV) == 1
and _singleName
in singlesMC):
139 local[
"alignments"][_alignment][
"file"] = singleJob[
"config"][
"output"]
140 job[
"dependencies"].
append(singleJob[
"name"])
143 mergeJobs.append(job)
146 jobs.extend(mergeJobs)
148 if "trends" in config[
"validations"][
"DMR"]:
154 for trendName
in config[
"validations"][
"DMR"][dmrType]:
157 workDir =
"{}/DMR/{}/{}".
format(validationDir, dmrType, trendName)
162 "name":
"DMR_{}_{}".
format(dmrType, trendName),
165 "run-mode":
"Condor",
172 for mergeName
in config[
"validations"][
"DMR"][dmrType][trendName][
"merges"]:
174 if isDataMerged[mergeName] < 0:
175 raise Exception(
"Trend jobs cannot process merge jobs containing both DATA and MC objects.")
176 elif isDataMerged[mergeName] == 1:
177 mergesDATA.append(mergeName)
179 if "doUnitTest" in config[
"validations"][
"DMR"][dmrType][trendName].
keys()
and config[
"validations"][
"DMR"][dmrType][trendName][
"doUnitTest"]:
180 local.setdefault(
"alignments", {})
183 raise Exception(
"Trend jobs are not implemented for treating MC.")
188 for mergeName
in mergesDATA:
189 for iname,singleName
in enumerate(config[
"validations"][
"DMR"][
'merge'][mergeName][
'singles']):
190 trendIOVs += [IOV
for IOV
in IOVs[singleName]]
192 for alignment
in config[
"alignments"]:
193 local.setdefault(
"alignments", {})
194 if alignment
in config[
"validations"][
"DMR"][
"single"][singleName][
"alignments"]:
195 local[
"alignments"][alignment] = copy.deepcopy(config[
"alignments"][alignment])
196 local[
"alignments"][alignment][
'index'] = config[
"validations"][
"DMR"][
"single"][singleName][
"alignments"].
index(alignment)
197 _mergeFiles.append(
"{}/{}/DMR/{}/{}/{}".
format(config[
"LFS"], config[
"name"],
"merge", mergeName,
"{}"))
199 local[
"validation"] = copy.deepcopy(config[
"validations"][
"DMR"][dmrType][trendName])
200 if len(_mergeFiles) == 1:
201 local[
"validation"][
"mergeFile"] = _mergeFiles[0]
203 local[
"validation"][
"mergeFile"] = _mergeFiles
204 local[
"validation"][
"IOV"] = trendIOVs
205 local[
"output"] =
"{}/{}/DMR/{}/{}/".
format(config[
"LFS"], config[
"name"], dmrType, trendName)
206 if "style" in config.keys()
and "trends" in config[
"style"].
keys():
207 local[
"style"] = copy.deepcopy(config[
"style"])
208 if "DMR" in local[
"style"].
keys(): local[
"style"].pop(
"DMR")
209 if "CMSlabel" in config[
"style"][
"trends"].
keys(): local[
"style"][
"CMSlabel"] = config[
"style"][
"trends"][
"CMSlabel"]
210 if "Rlabel" in config[
"style"][
"trends"].
keys():
211 local[
"style"][
"trends"].pop(
"Rlabel")
212 local[
"style"][
"trends"][
"TitleCanvas"] = config[
"style"][
"trends"][
"Rlabel"]
214 raise Exception(
"You want to create 'trends' jobs, but there are no 'lines' section in the config for pixel updates!")
217 for mergeName
in mergesDATA:
218 for mergeJob
in mergeJobs:
219 alignment, mergeJobName, mergeIOV = mergeJob[
"name"].
split(
"_")[1:]
220 if mergeJobName == mergeName
and int(mergeIOV)
in trendIOVs:
221 job[
"dependencies"].
append(mergeJob[
"name"])
223 trendJobs.append(job)
225 jobs.extend(trendJobs)
227 if "averaged" in config[
"validations"][
"DMR"]:
232 for avpName
in config[
"validations"][
"DMR"][dmrType]:
234 workDir =
"{}/DMR/{}/{}".
format(validationDir, dmrType, avpName)
235 output =
"{}/{}/DMR/{}/{}".
format(config[
"LFS"], config[
"name"], dmrType, avpName)
240 for mergeName
in config[
"validations"][
"DMR"][dmrType][avpName][
"merges"]:
242 if isDataMerged[mergeName] < 0:
243 raise Exception(
"Average jobs cannot process merge jobs containing both DATA and MC objects.")
244 elif isDataMerged[mergeName] == 1:
245 mergesDATA.append(mergeName)
247 mergesMC.append(mergeName)
252 if len(mergesDATA) > 0:
253 if "lumiPerRun" in config[
"validations"][
"DMR"][dmrType][avpName].
keys():
254 for lumifile
in config[
"validations"][
"DMR"][dmrType][avpName][
'lumiPerRun']:
255 if lumifile.split(
".")[-1]
in [
"txt",
"csv"]:
256 lumiPerRun.append(lumifile)
257 if "lumiPerIoV" in config[
"validations"][
"DMR"][dmrType][avpName].
keys():
258 for lumifile
in config[
"validations"][
"DMR"][dmrType][avpName][
'lumiPerIoV']:
259 if lumifile.split(
".")[-1]
in [
"txt",
"csv"]:
260 lumiPerIoV.append(lumifile)
261 if len(lumiPerRun) == 0
and len(lumiPerIoV) == 0:
262 raise Exception(
"No lumi per run/IoV file found or not specified in .csv/.txt format.")
263 if len(mergesMC) > 0:
264 if 'lumiMC' in config[
"validations"][
"DMR"][dmrType][avpName].
keys():
265 lumiMC = config[
"validations"][
"DMR"][dmrType][avpName][
'lumiMC']
269 plotJob[
'workdir'] =
"{}/{}".
format(workDir,
"plots")
270 plotJob[
'output'] =
"{}/{}".
format(output,
"plots")
271 plotJob[
'inputData'] = []
272 plotJob[
'inputMC'] = []
273 plotJob[
'dependencies'] = []
276 for mergeName
in mergesDATA:
278 workDirMerge =
"{}/{}".
format(workDir, mergeName)
279 outputMerge =
"{}/{}".
format(output, mergeName)
283 local[
"type"] =
"DMR" 284 local[
"mode"] =
"merge" 285 local[
"isData"] =
True 286 local[
"isMC"] =
False 289 for alignment
in config[
"alignments"]:
290 local.setdefault(
"alignments", {})
291 for singleName
in config[
"validations"][
"DMR"][
"merge"][mergeName][
"singles"]:
292 if alignment
in config[
"validations"][
"DMR"][
"single"][singleName][
'alignments']:
293 local[
"alignments"][alignment] = copy.deepcopy(config[
"alignments"][alignment])
294 local[
"validation"] = copy.deepcopy(config[
"validations"][
"DMR"][dmrType][avpName])
295 local[
"validation"][
"mergeFile"] =
"{}/{}/DMR/{}/{}/{}".
format(config[
"LFS"], config[
"name"],
"merge", mergeName,
"{}")
296 local[
"validation"][
"lumiPerRun"] = lumiPerRun
297 local[
"validation"][
"lumiPerIoV"] = lumiPerIoV
298 local[
"validation"][
"lumiMC"] = lumiMC
299 local[
"validation"][
"firstFromNext"] = []
302 IOVsPerMergeStep = []
303 for singleName
in config[
"validations"][
"DMR"][
"merge"][mergeName][
"singles"]:
304 for IOV
in IOVs[singleName]:
305 if IOV
not in IOVsPerMergeStep:
306 IOVsPerMergeStep.append(IOV)
307 IOVsPerMergeStep.sort()
311 maxfiles =
int(config[
"validations"][
"DMR"][dmrType][avpName][
'maxfiles'])
312 if len(IOVsPerMergeStep)%maxfiles >= 2:
314 parts = extra_part+len(IOVsPerMergeStep)//maxfiles
316 subJob = {
'name' : [],
'output' : [],
'lumiPerFile' : []}
317 for ipart
in range(0,parts):
319 workDirSub = workDirMerge+
"_"+
str(ipart)
320 outputSub = outputMerge+
"_"+
str(ipart)
325 for iIOV,IOV
in enumerate(IOVsPerMergeStep):
326 if (iIOV//maxfiles == ipart)
or (ipart == parts-1
and iIOV//maxfiles > ipart):
330 if lastIndex != len(IOVsPerMergeStep)-1:
331 firstFromNext.append(IOVsPerMergeStep[lastIndex+1])
334 _local = copy.deepcopy(local)
335 _local[
"output"] = outputSub
336 _local[
"validation"][
"IOV"] = IOVGroup
337 _local[
"validation"][
"firstFromNext"] = firstFromNext
339 "name":
"DMR_{}_{}_{}".
format(dmrType, avpName, mergeName+
"_"+
str(ipart)),
341 "exe":
"mkLumiAveragedPlots.py",
342 "run-mode":
"Condor",
346 subJob[
'output'].
append(outputSub)
347 subJob[
'name'].
append(
"DMR_{}_{}_{}".
format(dmrType, avpName, mergeName+
"_"+
str(ipart)))
348 subJob[
'lumiPerFile'].
append(os.path.join(outputSub,
"lumiPerFile.csv"))
350 plotJob[
'inputData'].
append(outputSub)
351 plotJob[
'dependencies'].
append(job[
'name'])
354 for mergeJob
in mergeJobs:
355 alignment, mergeJobName, mergeIOV = mergeJob[
"name"].
split(
"_")[1:]
356 if mergeJobName == mergeName
and int(mergeIOV)
in IOVGroup:
357 job[
"dependencies"].
append(mergeJob[
"name"])
366 localFinalize = copy.deepcopy(local)
367 localFinalize[
'mode'] =
"finalize" 368 localFinalize[
'output'] = outputMerge
369 localFinalize[
"validation"][
"IOV"] = []
370 localFinalize[
"validation"][
"mergeFile"] = subJob[
'output']
371 localFinalize[
"validation"][
"lumiPerRun"] = []
372 localFinalize[
"validation"][
"lumiPerIoV"] = subJob[
'lumiPerFile']
374 "name":
"DMR_{}_{}_{}".
format(dmrType, avpName, mergeName+
"_finalize"),
376 "exe":
"mkLumiAveragedPlots.py",
377 "run-mode":
"Condor",
378 "dependencies": subJob[
'name'],
379 "config": localFinalize,
382 plotJob[
'inputData'].
append(outputMerge)
383 plotJob[
'dependencies'].
append(job[
'name'])
386 if len(mergesMC) != 0:
388 workDirMerge =
"{}/{}".
format(workDir,
"MC")
389 outputMerge =
"{}/{}".
format(output,
"MC")
393 local[
"type"] =
"DMR" 394 local[
"mode"] =
"merge" 395 local[
"isData"] =
False 397 local[
"output"] = outputMerge
400 local[
"validation"] = copy.deepcopy(config[
"validations"][
"DMR"][dmrType][avpName])
401 local[
"validation"][
"mergeFile"] = []
402 for mergeName
in mergesMC:
403 for alignment
in config[
"alignments"]:
404 local.setdefault(
"alignments", {})
405 for singleName
in config[
"validations"][
"DMR"][
"merge"][mergeName][
"singles"]:
406 if alignment
in config[
"validations"][
"DMR"][
"single"][singleName][
'alignments']:
407 local[
"alignments"][alignment] = copy.deepcopy(config[
"alignments"][alignment])
408 local[
"validation"][
"mergeFile"].
append(
"{}/{}/DMR/{}/{}/{}".
format(config[
"LFS"], config[
"name"],
"merge", mergeName,
"{}"))
409 local[
"validation"][
"lumiPerRun"] = lumiPerRun
410 local[
"validation"][
"lumiPerIoV"] = lumiPerIoV
411 local[
"validation"][
"lumiMC"] = lumiMC
412 local[
"validation"][
"IOV"] = [1]
416 "name":
"DMR_{}_{}_{}".
format(dmrType, avpName, mergeName+
"_MC"),
418 "exe":
"mkLumiAveragedPlots.py",
419 "run-mode":
"Condor",
423 plotJob[
'inputMC'].
append(outputMerge)
424 plotJob[
'dependencies'].
append(job[
'name'])
427 for mergeJob
in mergeJobs:
428 alignment, mergeJobName, mergeIOV = mergeJob[
"name"].
split(
"_")[1:]
429 if mergeJobName
in mergesMC:
430 job[
"dependencies"].
append(mergeJob[
"name"])
436 if len(plotJob[
'inputData'])+len(plotJob[
'inputMC']) > 0:
438 local[
"type"] =
"DMR" 439 local[
"mode"] =
"plot" 440 local[
"isData"] =
True if len(plotJob[
'inputData']) > 0
else False 441 local[
"isMC"] =
True if len(plotJob[
'inputMC']) > 0
else False 442 local[
"output"] = plotJob[
'output']
443 local[
"plot"] = {
"inputData" : plotJob[
'inputData'],
444 "inputMC" : plotJob[
'inputMC'],
451 "useFitError" :
False,
453 "showMeanError" :
False,
455 "showRMSError" :
False}
457 for mergeName
in mergesDATA+mergesMC:
458 for singleName
in config[
"validations"][
"DMR"][
"merge"][mergeName][
"singles"]:
459 for alignment
in config[
"validations"][
"DMR"][
"single"][singleName][
'alignments']:
460 if alignment
in config[
'alignments']
and alignment
not in local[
"plot"][
"alignments"]:
461 local[
"plot"][
"alignments"].
append(alignment)
462 objectName = config[
"alignments"][alignment][
"title"].
replace(
" ",
"_")
463 if objectName
not in local[
"plot"][
"objects"]:
464 local[
"plot"][
"objects"].
append(objectName)
465 local[
"plot"][
"labels"].
append(config[
"alignments"][alignment][
"title"])
466 local[
"plot"][
"colors"].
append(config[
"alignments"][alignment][
"color"])
467 local[
"plot"][
"styles"].
append(config[
"alignments"][alignment][
"style"])
469 for extraKey
in [
"objects",
"labels",
"colors",
"styles",
"useFit",
"useFitError",
"showMean",
"showMeamError",
"showRMS",
"showRMSError"]:
470 if extraKey
in config[
"validations"][
"DMR"][dmrType][avpName].
keys():
471 local[
"plot"][extraKey] = config[
"validations"][
"DMR"][dmrType][avpName][extraKey]
473 if "style" in config.keys():
474 if "DMR" in config[
'style'].
keys():
475 if dmrType
in config[
'style'][
'DMR'].
keys():
476 local[
"plotGlobal"] = copy.deepcopy(config[
"style"][
'DMR'][dmrType])
480 "name":
"DMR_{}_{}_{}".
format(dmrType, avpName,
"plot"),
481 "dir": plotJob[
'workdir'],
482 "exe":
"mkLumiAveragedPlots.py",
483 "run-mode":
"Condor",
484 "dependencies": plotJob[
'dependencies'],
493 def replace(string, replacements)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def DMR(config, validationDir)
def split(sequence, size)