def _exists(analysis, topology, path=None): """ Check if the dictionary 'limit_topo' in <path>/sms.py exists. For topologies with intermediate masses, check if all dictionaries listed in the axes-information exist. If topology == None, check if <path>/sms.py exists. """ path2 = smsHelpers.getPath(analysis, path) if not topology: import os base = smsHelpers.base pydict = "%s/%s/%s/sms.py" % (base, path2, analysis) if os.path.exists(pydict): return True else: return False axes = getaxes(analysis, topology) if not axes: return False hasDict = smsHelpers.hasDictionary(analysis, path2) if not hasDict: return False return smsHelpers.hasDictionary(analysis, path2, topology)
def getUpperLimit(analysis, topology, mx=None, my=None, path=None, interpolate=False, expected=False): """ Get the upper limit for path/analysis/topology. :returns: None, if it does not exist; entire dictionary, if mx and my are None; upper limit at mx/my, if mx and my are floats; """ path = smsHelpers.getPath(analysis, path) if smsHelpers.hasDictionary(analysis, path): return getUpperLimitFromDictionary(analysis, topology, mx, my, path, interpolate=interpolate, expected=expected) logger.warning("No upper limits found for %s", analysis) return None
def getConditions(analysis, topology="all", fuzzy=True, path=None): """ Get conditions of an analysis. :returns: dictionary of conditions, if topology == "all"; single condition for the passed topology, if only one topology is passed; None if non-existent. """ key = analysis + topology + str(fuzzy) + str(path) if key in conditions: return conditions[key] path = smsHelpers.getPath(analysis, path) if fuzzy: ret = smsHelpers.getLines(analysis, path, "fuzzycondition") else: ret = smsHelpers.getLines(analysis, path, "condition") if topology == "all": conditions[key] = ret return ret if not topology in ret: conditions[key] = None return None conditions[key] = ret[topology] return ret[topology]
def getTopologies(analysis): """ Get all topologies of an analysis with constraints. """ path = smsHelpers.getPath(analysis) x = getConstraints(analysis, path=path) return x.keys()
def getExperiment(analysis, path=None): """ Check if path is to ATLAS directory, else return CMS. """ logger.warning("getExperiment is deprecated") path1 = getPath(analysis, path) if path1.find("ATLAS") > -1: return "ATLAS" return "CMS"
def upperLimit(analysis, topology, masses, path=None): """ Return upper limit for analysis-topology for given masses. :param masses: list of masses, with (mother, intermediate(s), LSP). For intermediate masses: if possible do interpolation over upper limits for different x-values. If interpolation is not possible: check if masses are comparable to the assumptions in the histogram. """ d = smsResults.getaxes(analysis, topology) if not path: path = smsHelpers.getPath(analysis) if not d: logger.error("%s/%s not found.", analysis, topology) return None for entry in masses: if not type(entry) == type(1 * GeV): logger.error("Please give input masses with unum units.") return None if len(masses) < 2: logger.error("No results for single mass entry") return None if len(masses) == 2 and not d[0]['mz']: return smsResults.getUpperLimit(analysis, topology, masses[_getAxis('x', d[0]['axes'])], masses[_getAxis('y', d[0]['axes'])], interpolate=True) if len(masses) == 2 and d[0]['mz']: logger.error("Need intermediate mass input for %s/%s.", analysis, topology) return None if len(masses) > 2 and not d[0]['mz']: logger.error("No intermediate mass in %s/%s.", analysis, topology) return None if len(masses) > 3 or len(d[0]['mz']) > 1: logger.error( "More than one intermediate mass in %s/%s. Cannot find " "upper limit for topologies with more than one " "intermediate mass.", analysis, topology) return None if len(masses) > 2 and len(d) == 1: if _compareMasses(masses, d[0]): return smsResults.getUpperLimit( analysis, _getHistName(topology, d[0]['mz'][0]), masses[_getAxis('x', d[0]['axes'])], masses[_getAxis('y', d[0]['axes'])], interpolate=True) logger.warning( "Only one histogram available for %s/%s, cannot " "interpolate for intermediate mass.", analysis, topology) return None return _doGridData(analysis, topology, masses, d, path)
def getBranchCondition(anaName, txName, path=None): """ Get the branch condition for an analysis. :returns: string containing the branch condition (e.g. equal branch masses) """ path = smsHelpers.getPath(anaName, path) ret = smsHelpers.getLines(anaName, path, "branchcondition") if not txName in ret: return None else: return ret[txName]
def upperLimit(analysis, topology, masses, path=None): """ Return upper limit for analysis-topology for given masses. :param masses: list of masses, with (mother, intermediate(s), LSP). For intermediate masses: if possible do interpolation over upper limits for different x-values. If interpolation is not possible: check if masses are comparable to the assumptions in the histogram. """ d = smsResults.getaxes(analysis, topology) if not path: path = smsHelpers.getPath(analysis) if not d: logger.error("%s/%s not found.", analysis, topology) return None for entry in masses: if not type(entry)==type(1*GeV): logger.error("Please give input masses with unum units.") return None if len(masses) < 2: logger.error("No results for single mass entry") return None if len(masses) == 2 and not d[0]['mz']: return smsResults.getUpperLimit(analysis, topology, masses[_getAxis('x', d[0]['axes'])], masses[_getAxis('y', d[0]['axes'])], interpolate=True) if len(masses) == 2 and d[0]['mz']: logger.error("Need intermediate mass input for %s/%s.", analysis, topology) return None if len(masses) > 2 and not d[0]['mz']: logger.error("No intermediate mass in %s/%s.", analysis, topology) return None if len(masses) > 3 or len(d[0]['mz']) > 1: logger.error("More than one intermediate mass in %s/%s. Cannot find " "upper limit for topologies with more than one " "intermediate mass.", analysis, topology) return None if len(masses) > 2 and len(d) == 1: if _compareMasses(masses, d[0]): return smsResults.getUpperLimit(analysis, _getHistName(topology, d[0]['mz'][0]), masses[_getAxis('x', d[0]['axes'])], masses[_getAxis('y', d[0]['axes'])], interpolate=True) logger.warning("Only one histogram available for %s/%s, cannot " "interpolate for intermediate mass.", analysis, topology) return None return _doGridData(analysis, topology, masses, d, path)
def getConstraints(analysis, topology="all", path=None): """ Get constraints of an analysis. :returns: dictionary of constraints, if topology == "all"; single constraint for the passed topology, if only one topology is passed; None if non-existent; """ key = analysis + topology + str(path) if key in constraints: return constraints[key] path = smsHelpers.getPath(analysis, path) ret = smsHelpers.getLines(analysis, path, "constraint") if topology == "all": constraints[key] = ret return ret if not topology in ret: constraints[key] = None return None constraints[key] = ret[topology] return ret[topology]
def load(analyses=None, topologies=None, sqrts=[7, 8], usePrivate=False, useSuperseded=False): """ Create an analysis objects from the info given in the SMS results database. :param analyses: If a list of analyses is passed, create only objects for these analyses (the database naming convention is used). :param topologies: If a list of topologies is passed, only these topologies are considered. :param sqrts: Array of center-of-mass energies of the analyses that are to be considered. :param usePrivate: Include analyses flagged as private. :returns: list of analyses """ #info message if superseded results are not used if not useSuperseded: logger.info("useSuperseded is not set, skipping superseded results") #to have readable input, we can give all instead of None if topologies == "all": topologies = None if analyses == "all": analyses = None # Enable supplying a single analysis/topology if isinstance(topologies, str): topologies = [topologies] if isinstance(analyses, str): analyses = [analyses] if isinstance(sqrts, int): sqrts = [sqrts] if isinstance(sqrts, float): sqrts = [int(sqrts)] listOfAnalyses = [] if analyses == None: analyses = smsResults.getAllResults().keys() for ana in analyses: if not smsHelpers.getPath(ana): logger.warning("Analysis %s not found" % ana) continue if smsResults.isPrivate(ana) and not usePrivate: logger.info("Skipping private analysis %s.", str(ana)) continue if smsResults.isSuperseded(ana) and not useSuperseded: continue logger.debug("Building analysis %s.", str(ana)) ss = smsResults.getSqrts(ana) / TeV if ss == None: logger.debug("SS: " + str(ss) + str(ana)) continue ss = int(ss) if not ss in sqrts: continue for tx in smsResults.getTopologies(ana): if topologies != None and tx not in topologies: continue logger.debug(str(tx)) newAnalysis = analysis.ULanalysis() newAnalysis.sqrts = smsResults.getSqrts(ana) newAnalysis.lum = smsResults.getLumi(ana) stopo = _getRealTopo(tx) newAnalysis.label = ana + ":" + tx # "2012" constraint = smsResults.getConstraints(ana, topology=stopo) cond = smsResults.getConditions(ana, topology=stopo) if not constraint or constraint == "Not yet assigned": logger.debug("Constraint for %s %s (%s) does not exist.", str(ana), str(tx), str(stopo)) continue if not cond: logger.warning( "Skipping %s %s (%s), Condition does not exist.", str(ana), str(tx), str(stopo)) continue cond = cond.replace("'", "").replace(" ", "").split(';') newAnalysis.constraint = constraint newAnalysis.conditions = cond newAnalysis.elementsEff = _getElementsEffs(constraint, cond) #Skip analyses with invalid elements if not newAnalysis.elementsEff: logger.warning( "Skipping analysis %s due to invalid elements." % (newAnalysis.label)) continue # Add analysis to list of analyses: listOfAnalyses.append(newAnalysis) if not listOfAnalyses: logger.warning("Zero analyses loaded.") return listOfAnalyses
def load(analyses=None, topologies=None, sqrts=[7, 8], usePrivate=False, useSuperseded=False ): """ Create an analysis objects from the info given in the SMS results database. :param analyses: If a list of analyses is passed, create only objects for these analyses (the database naming convention is used). :param topologies: If a list of topologies is passed, only these topologies are considered. :param sqrts: Array of center-of-mass energies of the analyses that are to be considered. :param usePrivate: Include analyses flagged as private. :returns: list of analyses """ #info message if superseded results are not used if not useSuperseded: logger.info("useSuperseded is not set, skipping superseded results") #to have readable input, we can give all instead of None if topologies == "all": topologies = None if analyses == "all": analyses = None # Enable supplying a single analysis/topology if isinstance(topologies, str): topologies = [topologies] if isinstance(analyses, str): analyses = [analyses] if isinstance(sqrts, int): sqrts = [sqrts] if isinstance(sqrts, float): sqrts = [int(sqrts)] listOfAnalyses = [] if analyses == None: analyses = smsResults.getAllResults().keys() for ana in analyses: if not smsHelpers.getPath(ana): logger.warning("Analysis %s not found" % ana) continue if smsResults.isPrivate(ana) and not usePrivate: logger.info("Skipping private analysis %s.",str(ana)) continue if smsResults.isSuperseded(ana) and not useSuperseded: continue logger.debug("Building analysis %s.", str(ana)) ss = smsResults.getSqrts(ana) / TeV if ss == None: logger.debug("SS: " + str(ss) + str(ana)) continue ss = int(ss) if not ss in sqrts: continue for tx in smsResults.getTopologies(ana): if topologies != None and tx not in topologies: continue logger.debug(str(tx)) newAnalysis = analysis.ULanalysis() newAnalysis.sqrts = smsResults.getSqrts(ana) newAnalysis.lum = smsResults.getLumi(ana) stopo = _getRealTopo(tx) newAnalysis.label = ana + ":" + tx # "2012" constraint = smsResults.getConstraints(ana, topology=stopo) cond = smsResults.getConditions(ana, topology=stopo) if not constraint or constraint == "Not yet assigned": logger.debug("Constraint for %s %s (%s) does not exist.", str(ana), str(tx), str(stopo)) continue if not cond: logger.warning("Skipping %s %s (%s), Condition does not exist.", str(ana), str(tx), str(stopo)) continue cond = cond.replace("'", "").replace(" ", "").split(';') newAnalysis.constraint = constraint newAnalysis.conditions = cond newAnalysis.elementsEff = _getElementsEffs(constraint,cond) #Skip analyses with invalid elements if not newAnalysis.elementsEff: logger.warning("Skipping analysis %s due to invalid elements." % (newAnalysis.label)) continue # Add analysis to list of analyses: listOfAnalyses.append(newAnalysis) if not listOfAnalyses: logger.warning("Zero analyses loaded.") return listOfAnalyses