Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-24 04:07:57

0001 import copy
0002 import os
0003 
0004 def Zmumu(config, validationDir):
0005     ##List with all jobs
0006     jobs, singleJobs = [], []
0007     zmumuType = "single"
0008 
0009     ##Dictionary of lists of all IOVs (can be different per each single job)
0010     IOVs = {}
0011 
0012     ##Auxilliary dictionary of isData flags per each merged job
0013     isDataMerged = {}
0014 
0015     ##Start with single Zmumu jobs
0016     if not zmumuType in config["validations"]["Zmumu"]: 
0017         raise Exception("No 'single' key word in config for Zmumu") 
0018 
0019     for singleName in config["validations"]["Zmumu"][zmumuType]:
0020         aux_IOV = config["validations"]["Zmumu"][zmumuType][singleName]["IOV"]
0021         if not isinstance(aux_IOV, list) and aux_IOV.endswith(".txt"):
0022             config["validations"]["Zmumu"][zmumuType][singleName]["IOV"] = []
0023             with open(aux_IOV, 'r') as IOVfile:
0024                 for line in IOVfile.readlines():
0025                     if len(line) != 0: config["validations"]["Zmumu"][zmumuType][singleName]["IOV"].append(int(line))
0026         for IOV in config["validations"]["Zmumu"][zmumuType][singleName]["IOV"]:
0027             ##Save IOV to loop later for merge jobs
0028             if singleName not in IOVs.keys():
0029                 IOVs[singleName] = []
0030             if IOV not in IOVs[singleName]:
0031                 IOVs[singleName].append(IOV)
0032 
0033             for alignment in config["validations"]["Zmumu"][zmumuType][singleName]["alignments"]:
0034                 ##Work directory for each IOV
0035                 workDir = "{}/Zmumu/{}/{}/{}/{}".format(validationDir, zmumuType, singleName, alignment, IOV)
0036 
0037                 ##Write local config
0038                 local = {}
0039                 local["output"] = "{}/{}/Zmumu/{}/{}/{}/{}".format(config["LFS"], config["name"], zmumuType, alignment, singleName, IOV)
0040                 local["alignment"] = copy.deepcopy(config["alignments"][alignment])
0041                 local["alignment"]["name"] = alignment
0042                 local["validation"] = copy.deepcopy(config["validations"]["Zmumu"][zmumuType][singleName])
0043                 local["validation"].pop("alignments")
0044                 local["validation"]["IOV"] = IOV
0045                 if "dataset" in local["validation"]:
0046                     local["validation"]["dataset"] = local["validation"]["dataset"].format(IOV)
0047                 if "goodlumi" in local["validation"]:
0048                     local["validation"]["goodlumi"] = local["validation"]["goodlumi"].format(IOV)
0049 
0050                 ##Write job info
0051                 job = {
0052                     "name": "Zmumu_{}_{}_{}_{}".format(zmumuType, alignment, singleName, IOV),
0053                     "dir": workDir,
0054                     "exe": "cmsRun",
0055                     "cms-config": "{}/src/Alignment/OfflineValidation/python/TkAlAllInOneTool/Zmumu_cfg.py".format(os.environ["CMSSW_BASE"]),
0056                     "run-mode": "Condor",
0057                     "dependencies": [],
0058                     "config": local, 
0059                 }
0060 
0061                 singleJobs.append(job)
0062 
0063     jobs.extend(singleJobs)            
0064 
0065     ##Do merge Zmumu if wished
0066     if "merge" in config["validations"]["Zmumu"]:
0067         ##List with merge jobs, will be expanded to jobs after looping
0068         mergeJobs = []
0069         zmumuType = "merge"
0070 
0071         ##Loop over all merge jobs/IOVs which are wished
0072         for mergeName in config["validations"]["Zmumu"][zmumuType]:
0073             ##Search for MC single(s)
0074             singlesMC = []
0075             for singleName in config["validations"]["Zmumu"][zmumuType][mergeName]['singles']:
0076                 if len(IOVs[singleName]) == 1 and int(IOVs[singleName][0]) == 1: singlesMC.append(singleName)
0077             isMConly = (len(singlesMC) == len(config["validations"]["Zmumu"][zmumuType][mergeName]['singles']))
0078             if isMConly:
0079                 isDataMerged[mergeName] = 0
0080             elif len(singlesMC) == 0:
0081                 isDataMerged[mergeName] = 1
0082             else:
0083                 isDataMerged[mergeName] = -1
0084 
0085             ##Loop over singles
0086             for iname,singleName in enumerate(config["validations"]["Zmumu"][zmumuType][mergeName]['singles']):
0087                 isMC = (singleName in singlesMC)
0088                 if isMConly and iname > 0: continue #special case for MC only comparison
0089                 elif isMConly: singlesMC.pop(singlesMC.index(singleName))
0090 
0091                 for IOV in IOVs[singleName]:
0092                     ##Work directory for each IOV
0093                     workDir = "{}/Zmumu/{}/{}/{}".format(validationDir, zmumuType, mergeName, IOV)
0094 
0095                     ##Write job info
0096                     local = {}
0097 
0098                     job = {
0099                         "name": "Zmumu_{}_{}_{}".format(zmumuType, mergeName, IOV),
0100                         "dir": workDir,
0101                         "exe": "Zmumumerge",
0102                         "run-mode": "Condor",
0103                         "dependencies": [],
0104                         "config": local,
0105                     }
0106 
0107                     ##Deep copy necessary things from global config + assure plot order
0108                     for alignment in config["alignments"]:
0109                         idxIncrement = 0
0110                         local.setdefault("alignments", {})
0111                         if alignment in config["validations"]["Zmumu"]["single"][singleName]["alignments"]: #Cover all DATA validations
0112                             local["alignments"][alignment] = copy.deepcopy(config["alignments"][alignment])
0113                             local["alignments"][alignment]['index'] = config["validations"]["Zmumu"]["single"][singleName]["alignments"].index(alignment)
0114                             local["alignments"][alignment]['isMC'] = False
0115                         for singleMCname in singlesMC:
0116                             if alignment in config["validations"]["Zmumu"]["single"][singleMCname]["alignments"]: #Add MC objects
0117                                 local["alignments"][alignment] = copy.deepcopy(config["alignments"][alignment])
0118                                 local["alignments"][alignment]['index']  = len(config["validations"]["Zmumu"]["single"][singleName]["alignments"])
0119                                 local["alignments"][alignment]['index'] += idxIncrement + config["validations"]["Zmumu"]["single"][singleMCname]["alignments"].index(alignment)
0120                                 local["alignments"][alignment]['isMC'] = True
0121                             idxIncrement += len(config["validations"]["Zmumu"]["single"][singleMCname]["alignments"])    
0122                     local["validation"] = copy.deepcopy(config["validations"]["Zmumu"][zmumuType][mergeName])
0123                     local["validation"]["IOV"] = IOV
0124                     if "customrighttitle" in local["validation"].keys():
0125                         if "IOV" in local["validation"]["customrighttitle"]:
0126                             local["validation"]["customrighttitle"] = local["validation"]["customrighttitle"].replace("IOV",str(IOV))
0127                     local["output"] = "{}/{}/Zmumu/{}/{}/{}".format(config["LFS"], config["name"], zmumuType, mergeName, IOV) 
0128 
0129                     ##Add global plotting options
0130                     if "style" in config.keys():
0131                         if "Zmumu" in config['style'].keys():
0132                             if zmumuType in config['style']['Zmumu'].keys():
0133                                 local["style"] = copy.deepcopy(config["style"]["Zmumu"][zmumuType])
0134                                 if "Rlabel" in local["style"] and "customrighttitle" in local["validation"].keys():
0135                                     print("WARNING: custom right label is overwritten by global settings")
0136 
0137                     ##Loop over all single jobs
0138                     for singleJob in jobs:
0139                         ##Get single job info and append to merge job if requirements fullfilled
0140                         _alignment, _singleName, _singleIOV = singleJob["name"].split("_")[2:]
0141                         if _singleName in config["validations"]["Zmumu"][zmumuType][mergeName]["singles"]:
0142                             if int(_singleIOV) == IOV or (int(_singleIOV) == 1 and _singleName in singlesMC): #matching DATA job or any MC single job 
0143                                 local["alignments"][_alignment]["file"] = singleJob["config"]["output"]
0144                                 job["dependencies"].append(singleJob["name"])
0145 
0146                     mergeJobs.append(job)  
0147 
0148         jobs.extend(mergeJobs)
0149 
0150     if "trends" in config["validations"]["Zmumu"]:
0151         print("[WARNING] Zmumu trends are not implemented yet. Nothing to do here...")
0152 
0153     return jobs