Skip to content

Commit 7655768

Browse files
committed
Multi-IOV Zmumu mode, fixes on DMR averaged, PV trends
1 parent 47a226a commit 7655768

File tree

4 files changed

+135
-52
lines changed

4 files changed

+135
-52
lines changed

Alignment/OfflineValidation/bin/Zmumumerge.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,18 @@ int Zmumumerge(int argc, char* argv[]) {
374374
pt::ptree alignments = main_tree.get_child("alignments");
375375
pt::ptree validation = main_tree.get_child("validation");
376376

377+
//Load defined order
378+
std::vector<std::pair<std::string, pt::ptree>> alignmentsOrdered;
377379
for (const auto& childTree : alignments) {
380+
alignmentsOrdered.push_back(childTree);
381+
}
382+
std::sort(alignmentsOrdered.begin(),
383+
alignmentsOrdered.end(),
384+
[](const std::pair<std::string, pt::ptree>& left, const std::pair<std::string, pt::ptree>& right) {
385+
return left.second.get<int>("index") < right.second.get<int>("index");
386+
});
387+
388+
for (const auto& childTree : alignmentsOrdered) {
378389
// do not consider the nodes with a "file" to merge
379390
if (childTree.second.find("file") == childTree.second.not_found()) {
380391
std::cerr << "Ignoring alignment: " << childTree.second.get<std::string>("title") << ".\nNo file to merged found!"

Alignment/OfflineValidation/python/TkAlAllInOneTool/DMRplotter.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def __log__(self,log_type="",text=""):
5151
else:
5252
print(text)
5353

54+
def _middleString(self, fullString):
55+
##############################################################
56+
#Auxiliary function to retrieve object name from full string
57+
##############################################################
58+
59+
middleString = "_".join(fullString.split("_")[1:])
60+
if middleString.endswith("_y"): middleString = "_".join(middleString.split("_")[:-1])
61+
middleString = "_".join(middleString.split("_")[:-1])
62+
return middleString
63+
64+
5465
def _replaceMulti(self, mainString, toBeReplaced, newString):
5566
#################################
5667
#Auxiliary function to remove
@@ -339,7 +350,7 @@ def __defineObjects__(self):
339350
if objName in objAreIgnored: continue
340351
objDict[objName] = []
341352
for obj in objList:
342-
if objName in obj.GetName():
353+
if objName == self._middleString(obj.GetName()):
343354
segment = ""
344355
var = ""
345356
if obj.GetName()[-1] == "y":
@@ -834,7 +845,7 @@ def addMC(self,filename):
834845

835846
def plotSingle(self):
836847
##############################################
837-
#Auxiliary plotter for unweighted Data and MC
848+
#Auxiliary plotter for unweighted Data and MC
838849
##############################################
839850

840851
#check for input file and create output dir
@@ -993,7 +1004,7 @@ def plot(self):
9931004
#order plots & prepare y-axis scale factors
9941005
isEmpty = True
9951006
maxY = 0.0
996-
objGroup = []
1007+
objGroup = []
9971008
for objName in self.objNameList: #follow plotting order
9981009
for obj in objects[objName]:
9991010
if obj['var'] == var and obj['segment'] == segment:
@@ -1010,14 +1021,13 @@ def plot(self):
10101021
legStyle = "l"
10111022
if obj['type'] == "DATA":
10121023
drawStyle += "P HIST SAME"
1013-
legStyle = "p"
1024+
legStyle = "p"
10141025
objGroup.append({'hist' : obj['hist'],
10151026
'label' : legendLabel,
10161027
'stat' : self.__getStat__(obj['hist'],var),
10171028
'drawStyle' : drawStyle,
10181029
'legStyle' : legStyle
10191030
})
1020-
10211031
#draw & save
10221032
if not isEmpty:
10231033
legMinY = (1./self.legendOffset)+(1.-1./self.legendOffset)*(self.maxEntriesPerColumn-len(objGroup))/(self.maxEntriesPerColumn*3)

Alignment/OfflineValidation/python/TkAlAllInOneTool/Zmumu.py

Lines changed: 105 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,53 @@
33

44
def Zmumu(config, validationDir):
55
##List with all jobs
6-
jobs = []
6+
jobs, singleJobs = [], []
77
zmumuType = "single"
88

9-
##List with all wished IOVs
10-
IOVs = []
9+
##Dictionary of lists of all IOVs (can be different per each single job)
10+
IOVs = {}
11+
12+
##Auxilliary dictionary of isData flags per each merged job
13+
isDataMerged = {}
1114

1215
##Start with single Zmumu jobs
1316
if not zmumuType in config["validations"]["Zmumu"]:
1417
raise Exception("No 'single' key word in config for Zmumu")
1518

16-
for datasetName in config["validations"]["Zmumu"][zmumuType]:
17-
for IOV in config["validations"]["Zmumu"][zmumuType][datasetName]["IOV"]:
19+
for singleName in config["validations"]["Zmumu"][zmumuType]:
20+
aux_IOV = config["validations"]["Zmumu"][zmumuType][singleName]["IOV"]
21+
if not isinstance(aux_IOV, list) and aux_IOV.endswith(".txt"):
22+
config["validations"]["Zmumu"][zmumuType][singleName]["IOV"] = []
23+
with open(aux_IOV, 'r') as IOVfile:
24+
for line in IOVfile.readlines():
25+
if len(line) != 0: config["validations"]["Zmumu"][zmumuType][singleName]["IOV"].append(int(line))
26+
for IOV in config["validations"]["Zmumu"][zmumuType][singleName]["IOV"]:
1827
##Save IOV to loop later for merge jobs
19-
if not IOV in IOVs:
20-
IOVs.append(IOV)
28+
if singleName not in IOVs.keys():
29+
IOVs[singleName] = []
30+
if IOV not in IOVs[singleName]:
31+
IOVs[singleName].append(IOV)
2132

22-
for alignment in config["validations"]["Zmumu"][zmumuType][datasetName]["alignments"]:
33+
for alignment in config["validations"]["Zmumu"][zmumuType][singleName]["alignments"]:
2334
##Work directory for each IOV
24-
workDir = "{}/Zmumu/{}/{}/{}/{}".format(validationDir, zmumuType, datasetName, alignment, IOV)
35+
workDir = "{}/Zmumu/{}/{}/{}/{}".format(validationDir, zmumuType, singleName, alignment, IOV)
2536

2637
##Write local config
2738
local = {}
28-
local["output"] = "{}/{}/{}/{}/{}/{}".format(config["LFS"], config["name"], zmumuType, alignment, datasetName, IOV)
39+
local["output"] = "{}/{}/Zmumu/{}/{}/{}/{}".format(config["LFS"], config["name"], zmumuType, alignment, singleName, IOV)
2940
local["alignment"] = copy.deepcopy(config["alignments"][alignment])
30-
local["validation"] = copy.deepcopy(config["validations"]["Zmumu"][zmumuType][datasetName])
41+
local["alignment"]["name"] = alignment
42+
local["validation"] = copy.deepcopy(config["validations"]["Zmumu"][zmumuType][singleName])
3143
local["validation"].pop("alignments")
3244
local["validation"]["IOV"] = IOV
45+
if "dataset" in local["validation"]:
46+
local["validation"]["dataset"] = local["validation"]["dataset"].format(IOV)
3347
if "goodlumi" in local["validation"]:
3448
local["validation"]["goodlumi"] = local["validation"]["goodlumi"].format(IOV)
3549

3650
##Write job info
3751
job = {
38-
"name": "Zmumu_{}_{}_{}_{}".format(zmumuType, alignment, datasetName, IOV),
52+
"name": "Zmumu_{}_{}_{}_{}".format(zmumuType, alignment, singleName, IOV),
3953
"dir": workDir,
4054
"exe": "cmsRun",
4155
"cms-config": "{}/src/Alignment/OfflineValidation/python/TkAlAllInOneTool/Zmumu_cfg.py".format(os.environ["CMSSW_BASE"]),
@@ -44,7 +58,9 @@ def Zmumu(config, validationDir):
4458
"config": local,
4559
}
4660

47-
jobs.append(job)
61+
singleJobs.append(job)
62+
63+
jobs.extend(singleJobs)
4864

4965
##Do merge Zmumu if wished
5066
if "merge" in config["validations"]["Zmumu"]:
@@ -54,40 +70,84 @@ def Zmumu(config, validationDir):
5470

5571
##Loop over all merge jobs/IOVs which are wished
5672
for mergeName in config["validations"]["Zmumu"][zmumuType]:
57-
for IOV in IOVs:
58-
##Work directory for each IOV
59-
workDir = "{}/Zmumu/{}/{}/{}".format(validationDir, zmumuType, mergeName, IOV)
60-
61-
##Write job info
62-
local = {}
63-
64-
job = {
65-
"name": "Zmumu_{}_{}_{}".format(zmumuType, mergeName, IOV),
66-
"dir": workDir,
67-
"exe": "Zmumumerge",
68-
"run-mode": "Condor",
69-
"dependencies": [],
70-
"config": local,
71-
}
72-
73-
for alignment in config["alignments"]:
74-
##Deep copy necessary things from global config
75-
local.setdefault("alignments", {})
76-
local["alignments"][alignment] = copy.deepcopy(config["alignments"][alignment])
73+
##Search for MC single(s)
74+
singlesMC = []
75+
for singleName in config["validations"]["Zmumu"][zmumuType][mergeName]['singles']:
76+
if len(IOVs[singleName]) == 1 and int(IOVs[singleName][0]) == 1: singlesMC.append(singleName)
77+
isMConly = (len(singlesMC) == len(config["validations"]["Zmumu"][zmumuType][mergeName]['singles']))
78+
if isMConly:
79+
isDataMerged[mergeName] = 0
80+
elif len(singlesMC) == 0:
81+
isDataMerged[mergeName] = 1
82+
else:
83+
isDataMerged[mergeName] = -1
84+
85+
##Loop over singles
86+
for iname,singleName in enumerate(config["validations"]["Zmumu"][zmumuType][mergeName]['singles']):
87+
isMC = (singleName in singlesMC)
88+
if isMConly and iname > 0: continue #special case for MC only comparison
89+
elif isMConly: singlesMC.pop(singlesMC.index(singleName))
90+
91+
for IOV in IOVs[singleName]:
92+
##Work directory for each IOV
93+
workDir = "{}/Zmumu/{}/{}/{}".format(validationDir, zmumuType, mergeName, IOV)
94+
95+
##Write job info
96+
local = {}
97+
98+
job = {
99+
"name": "Zmumu_{}_{}_{}".format(zmumuType, mergeName, IOV),
100+
"dir": workDir,
101+
"exe": "Zmumumerge",
102+
"run-mode": "Condor",
103+
"dependencies": [],
104+
"config": local,
105+
}
106+
107+
##Deep copy necessary things from global config + assure plot order
108+
for alignment in config["alignments"]:
109+
idxIncrement = 0
110+
local.setdefault("alignments", {})
111+
if alignment in config["validations"]["Zmumu"]["single"][singleName]["alignments"]: #Cover all DATA validations
112+
local["alignments"][alignment] = copy.deepcopy(config["alignments"][alignment])
113+
local["alignments"][alignment]['index'] = config["validations"]["Zmumu"]["single"][singleName]["alignments"].index(alignment)
114+
local["alignments"][alignment]['isMC'] = False
115+
for singleMCname in singlesMC:
116+
if alignment in config["validations"]["Zmumu"]["single"][singleMCname]["alignments"]: #Add MC objects
117+
local["alignments"][alignment] = copy.deepcopy(config["alignments"][alignment])
118+
local["alignments"][alignment]['index'] = len(config["validations"]["Zmumu"]["single"][singleName]["alignments"])
119+
local["alignments"][alignment]['index'] += idxIncrement + config["validations"]["Zmumu"]["single"][singleMCname]["alignments"].index(alignment)
120+
local["alignments"][alignment]['isMC'] = True
121+
idxIncrement += len(config["validations"]["Zmumu"]["single"][singleMCname]["alignments"])
77122
local["validation"] = copy.deepcopy(config["validations"]["Zmumu"][zmumuType][mergeName])
78-
local["output"] = "{}/{}/{}/{}/{}".format(config["LFS"], config["name"], zmumuType, mergeName, IOV)
79-
80-
##Loop over all single jobs
81-
for singleJob in jobs:
82-
##Get single job info and append to merge job if requirements fullfilled
83-
alignment, datasetName, singleIOV = singleJob["name"].split("_")[2:]
84-
85-
if int(singleIOV) == IOV and datasetName in config["validations"]["Zmumu"][zmumuType][mergeName]["singles"]:
86-
local["alignments"][alignment]["file"] = singleJob["config"]["output"]
87-
job["dependencies"].append(singleJob["name"])
88-
89-
mergeJobs.append(job)
123+
local["validation"]["IOV"] = IOV
124+
if "customrighttitle" in local["validation"].keys():
125+
if "IOV" in local["validation"]["customrighttitle"]:
126+
local["validation"]["customrighttitle"] = local["validation"]["customrighttitle"].replace("IOV",str(IOV))
127+
local["output"] = "{}/{}/Zmumu/{}/{}/{}".format(config["LFS"], config["name"], zmumuType, mergeName, IOV)
128+
129+
##Add global plotting options
130+
if "style" in config.keys():
131+
if "Zmumu" in config['style'].keys():
132+
if zmumuType in config['style']['Zmumu'].keys():
133+
local["style"] = copy.deepcopy(config["style"]["Zmumu"][zmumuType])
134+
if "Rlabel" in local["style"] and "customrighttitle" in local["validation"].keys():
135+
print("WARNING: custom right label is overwritten by global settings")
136+
137+
##Loop over all single jobs
138+
for singleJob in jobs:
139+
##Get single job info and append to merge job if requirements fullfilled
140+
_alignment, _singleName, _singleIOV = singleJob["name"].split("_")[2:]
141+
if _singleName in config["validations"]["Zmumu"][zmumuType][mergeName]["singles"]:
142+
if int(_singleIOV) == IOV or (int(_singleIOV) == 1 and _singleName in singlesMC): #matching DATA job or any MC single job
143+
local["alignments"][_alignment]["file"] = singleJob["config"]["output"]
144+
job["dependencies"].append(singleJob["name"])
145+
146+
mergeJobs.append(job)
90147

91148
jobs.extend(mergeJobs)
92149

150+
if "trends" in config["validations"]["Zmumu"]:
151+
print("[WARNING] Zmumu trends are not implemented yet. Nothing to do here...")
152+
93153
return jobs

Alignment/OfflineValidation/src/PreparePVTrends.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,12 @@ void PreparePVTrends::outputGraphs(const pv::wrappedTrends &allInputs,
558558
g_asym->SetTitle(label);
559559

560560
// scatter or RMS TH1
561-
h_RMS[index] = new TH1F(Form("h_RMS_dz_eta_%s", label.Data()), label, ticks.size() - 1, &(ticks[0]));
561+
std::vector<double> newTicks = ticks;
562+
newTicks.insert(newTicks.end(), ticks.back() + 1.);
563+
h_RMS[index] = new TH1F(Form("h_RMS_dz_eta_%s", label.Data()), label, newTicks.size() - 1, &(newTicks[0]));
562564
h_RMS[index]->SetStats(kFALSE);
563565

564-
for (size_t bincounter = 1; bincounter < ticks.size(); bincounter++) {
566+
for (size_t bincounter = 1; bincounter < ticks.size() + 1; bincounter++) {
565567
h_RMS[index]->SetBinContent(
566568
bincounter, std::abs(allInputs.getHigh()[label][bincounter - 1] - allInputs.getLow()[label][bincounter - 1]));
567569
h_RMS[index]->SetBinError(bincounter, 0.01);

0 commit comments

Comments
 (0)