33
44def 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
0 commit comments