Exemple #1
0
 def runCombine(self, mass):
     result = commonLimitTools.Result(mass)
     if self.opts.limit:
         if self.opts.unblinded:
             self._runObservedAndExpected(result, mass)
         else:
             self._runBlinded(result, mass)
     else:
         print "Skipping limit for mass:", mass
     self._runMLFit(mass)
     self._runSignificance(mass)
     return result
def analyseTaskDir(taskDir, scenarioData, scenario, massWhiteList, massPoints):
    myScenario = None
    myTanbeta = None
    mySplit = taskDir.split("_")
    myScenario = mySplit[2]
    if myScenario != scenario:
        # Scenario not requested, do not consider it
        return
    myTanbeta = mySplit[4].replace("tanbetascan", "")
    myList = os.listdir(taskDir)
    for item in myList:
        if item.startswith("higgsCombineobs_") and item.endswith(".root"):
            mySplit = item.split(".")
            myMass = mySplit[len(mySplit) - 2].replace("mH", "")
            if len(massWhiteList) > 0:
                if not myMass in massWhiteList:
                    continue
            if not myMass in massPoints:
                massPoints.append(myMass)
            # Read result
            myResult = commonLimitTools.Result(myMass)
            myStatus = CombineTools.parseResultFromCombineOutput(
                taskDir, myResult, myMass)
            if myStatus != 6:  # 1 obs + 5 exp values
                # Combine failed
                myResult.failed = True
            # Store result
            myKey = tbtools.constructResultKey(myMass, myTanbeta)
            if myKey in scenarioData.keys():
                raise Exception(
                    "Duplicate results for scenario=%s mass=%s tanbeta=%s! Remove wrong ones and then rerun!"
                    % (myScenario, myMass, myTanbeta))
            scenarioData[myKey] = {}
            scenarioData[myKey]["combineResult"] = myResult
            print "Result found for scenario=%s mass=%s tanbeta=%s" % (
                myScenario, myMass, myTanbeta)
Exemple #3
0
def getCombineResultPassedStatus(opts, brContainer, mHp, tanbeta, resultKey, scen):
    reuseStatus = False
    if not brContainer.resultExists(mHp, tanbeta):
        # Produce cards
        myPostFix = "lhcasy_%s_mHp%s_tanbetascan%.1f"%(scen,mHp,tanbeta)
        myPostFixAllMasses = "lhcasy_%s_mHpAll_tanbetascan%.1f"%(scen,tanbeta)
        myList = os.listdir(".")
        myList.sort()
        myResultDir = None
        myResultFound = False
        for item in myList:
            if myPostFix in item or myPostFixAllMasses in item:
                myResultDir = item
        if myResultDir != None:
            myList = os.listdir("./%s"%myResultDir)
            for item in myList:
                if item.startswith("higgsCombineobs_m%s"%mHp):
                    f = ROOT.TFile.Open(os.path.join(myResultDir, item))
                    myTree = f.Get("limit")
                    myValue = array.array('d',[0])
                    myTree.SetBranchAddress("limit", myValue)
                    myResult = commonLimitTools.Result(mHp)
                    if myTree.GetEntries() != 6:
                        myResult.failed = True
                    else:
                        myResult.failed = False
                        i = 0
                        while i < myTree.GetEntries():
                            myTree.GetEvent(i)
                            if i == 0:
                                myResult.expectedMinus2Sigma = myValue[0]
                            elif i == 1:
                                myResult.expectedMinus1Sigma = myValue[0]
                            elif i == 2:
                                myResult.expected = myValue[0]
                            elif i == 3:
                                myResult.expectedPlus1Sigma = myValue[0]
                            elif i == 4:
                                myResult.expectedPlus2Sigma = myValue[0]
                            elif i == 5:
                                myResult.observed = myValue[0]
                            i += 1
                        myResultFound = True
                        brContainer._readFromDatabase(mHp, tanbeta)
                        brContainer.setCombineResult(mHp, tanbeta, myResult)
                    f.Close()
        if not myResultFound:
            massInput = [mHp]
            postFixInput = myPostFix
            if opts.gridRunAllMassesInOneJob:
                if mHp != opts.masspoints[0]:
                    return None
                massInput = opts.masspoints[:]
                postFixInput = myPostFixAllMasses
            # Result does not exist, let's calculate it
            if opts.gridRunAllMassesInOneJob:
                for m in opts.masspoints:
                    brContainer.produceScaledCards(m, tanbeta)
            else:
                brContainer.produceScaledCards(mHp, tanbeta)
            # Run Combine
            if "CMSSW_BASE" in os.environ or opts.creategridjobs:
                resultContainer = combine.produceLHCAsymptotic(opts, ".", massPoints=massInput,
                    datacardPatterns = brContainer.getDatacardPatterns(),
                    rootfilePatterns = brContainer.getRootfilePatterns(),
                    clsType = combine.LHCTypeAsymptotic(opts),
                    postfix = postFixInput,
                    quietStatus = True)
                if resultContainer != None and len(resultContainer.results) > 0:
                    result = resultContainer.results[0]
                    # Store result
                    brContainer.setCombineResult(mHp, tanbeta, result)
            else:
                print "... Skipping combine (assuming debug is intended; to run combine, do first cmsenv) ..."
    else:
        reuseStatus = True
    #if brContainer.resultExists(mHp, tanbeta):
        #myContainer = brContainer
    #else:
        #raise Exception("No datacards present")
    if opts.creategridjobs:
        return None
    
    # Print output
    s = "- mHp=%s, tanbeta=%.1f, sigmaTheory="%(mHp, tanbeta)
    if brContainer.getResult(mHp, tanbeta)["sigmaTheory"] == None:
        s += "None"
    else:
        s += "%.3f"%brContainer.getResult(mHp, tanbeta)["sigmaTheory"]
    if brContainer.getFailedStatus(mHp, tanbeta):
        s += " sigmaCombine (%s)=failed"%resultKey
    else:
        s += " sigmaCombine (%s)=%.3f, passed=%d"%(resultKey, brContainer.getCombineResultByKey(mHp, tanbeta, resultKey), brContainer.getPassedStatus(mHp, tanbeta, resultKey))
    if not reuseStatus:
        print s
    # return limit from combine
    if brContainer.getFailedStatus(mHp, tanbeta):
        return None
    return brContainer.getPassedStatus(mHp, tanbeta, resultKey)
def parseTextResultsFromFile(brContainer, massWhiteList, scen, resultKeys):
    # Read
    name = tbtools._resultsPattern % scen
    print "Opening file '%s' for input" % (name)
    f = open(name)
    if f == None:
        raise Exception("Error: Could not open result file '%s' for input!" %
                        name)
    lines = f.readlines()
    f.close()
    # Obtain mass points
    myMassPoints = []
    if len(massWhiteList) > 0:
        myMassPoints = massWhiteList[:]
    else:
        myLine = 0
        while myLine < len(lines):
            if lines[myLine].startswith("Tan beta limit scan ("):
                s = lines[myLine].replace("Tan beta limit scan (", "").replace(
                    ") for m=", ",").replace(" and key: ",
                                             ",").replace("\n", "")
                mySplit = s.split(",")
                m = mySplit[1]
                if not m in myMassPoints:
                    myMassPoints.append(m)
            myLine += 1
    myMassPoints.sort()
    # Analyse lines
    for m in myMassPoints:
        for myKey in resultKeys:
            myBlockStart = None
            myBlockEnd = None
            myLine = 0
            while myLine < len(lines) and myBlockEnd == None:
                if lines[myLine].startswith("Tan beta limit scan (") or lines[
                        myLine].startswith("Allowed tan beta"):
                    if myBlockStart == None:
                        s = lines[myLine].replace(
                            "Tan beta limit scan (",
                            "").replace(") for m=",
                                        ",").replace(" and key: ",
                                                     ",").replace("\n", "")
                        mySplit = s.split(",")
                        if scen == mySplit[0] and m == mySplit[
                                1] and myKey == mySplit[2]:
                            # Entry found, store beginning
                            myBlockStart = myLine
                    else:
                        myBlockEnd = myLine
                myLine += 1
            if myBlockStart == None or myLine - myBlockStart > 100:
                print "... could not find results"
            else:
                myBlockEnd = myLine
            if myBlockEnd != None:
                for i in range(myBlockStart + 1, myBlockEnd - 1):
                    s = lines[i].replace("  tan beta=", "").replace(
                        " xsecTheor=",
                        "").replace(" pb, limit(%s)=" % myKey,
                                    ",").replace(" pb, passed=", ",")
                    mySplit = s.split(",")
                    if len(mySplit) > 1 and s[0] != "#" and not mySplit[2] in [
                            "failed", "n.a.", ""
                    ] and mySplit[1] != "None":
                        myTanBeta = mySplit[0]
                        tanbetakey = tbtools.constructResultKey(m, myTanBeta)
                        if not brContainer.resultExists(m, myTanBeta):
                            brContainer._results[tanbetakey] = {}
                            if mySplit[1] == "None":
                                brContainer._results[tanbetakey][
                                    "sigmaTheory"] = None
                            else:
                                brContainer._results[tanbetakey][
                                    "sigmaTheory"] = float(mySplit[1])
                            result = commonLimitTools.Result(0)
                            setattr(result, myKey, float(mySplit[2]))
                            brContainer.setCombineResult(m, myTanBeta, result)
                        else:
                            # Add result key
                            setattr(
                                brContainer._results[tanbetakey]
                                ["combineResult"], myKey, float(mySplit[2]))
    return myMassPoints