Esempio n. 1
0
def getWaveDescThresFromWaveList(waveListFileName, keyFiles):
	printInfo("reading amplitude names and thresholds from wave list file "
	          + "'" + waveListFileName + "'.")
	waveDescThres = []
	with open(waveListFileName, 'r') as waveListFile:
		lineNmb = 0
		for line in waveListFile:
			if line[0] == '#':  # comments start with #
				continue
			line = line.replace('\n', '')
			lineArray = line.split(" ")
			if len(lineArray) in [1, 2]:
				waveName = lineArray[0]
				if len(lineArray) == 1:
					threshold = 0
				else:
					threshold = lineArray[1]
				waveDesc = pyRootPwa.core.waveDescription.parseKeyFile(keyFiles[waveName][0])[keyFiles[waveName][1]]
				waveDescThres.append( (waveName, waveDesc, float(threshold)) )
			else:
				printWarn("cannot parse line '" + line + "' in wave list file "
				          + "'" + waveListFileName + "'.")
			lineNmb += 1
		printInfo("read " + str(lineNmb) + " lines from wave list file " + "'" + waveListFileName + "'")
	return waveDescThres
Esempio n. 2
0
def getWaveDescThresFromWaveList(waveListFileName, waveDescriptions):
    printInfo("reading amplitude names and thresholds from wave list file " +
              "'" + waveListFileName + "'.")
    waveDescThres = []
    with open(waveListFileName, 'r') as waveListFile:
        lineNmb = 0
        for line in waveListFile:
            line = line.strip()
            if line[0] == '#':  # comments start with #
                continue
            lineArray = line.split(" ")
            if len(lineArray) in [1, 2]:
                waveName = lineArray[0]
                if len(lineArray) == 1:
                    threshold = 0
                else:
                    threshold = lineArray[1]
                waveDesc = waveDescriptions[waveName]
                waveDescThres.append((waveName, waveDesc, float(threshold)))
            else:
                printWarn("cannot parse line '" + line +
                          "' in wave list file " + "'" + waveListFileName +
                          "'.")
            lineNmb += 1
        printInfo("read " + str(lineNmb) + " lines from wave list file " +
                  "'" + waveListFileName + "'")
    return waveDescThres
Esempio n. 3
0
def getBestFitResultsFromFile(fitResultFileName,
                              fitResultTreeName = "pwa",
                              fitResultBranchName = "fitResult_v2"
                             ):

	bestResultsInMultibin = pyRootPwa.core.getFitResultsFromFilesInMultibins([fitResultFileName], fitResultTreeName, fitResultBranchName, True, False, True)
	multiBins = set([ b.getSubMultiBin(exclude="mass") for b in bestResultsInMultibin.keys()])
	if len(multiBins) != 1:
		printWarn("Fit result file '{0}' contains more than one bin in a variable other than mass: {1}".format(fitResultFileName, list(multiBins)))
	return {b.getBinCenters()["mass"]: results[0] for b,results in bestResultsInMultibin.iteritems()}
Esempio n. 4
0
def getBestFitResultFromFile(fitResultFileName,
                             massBinCenter = None,
                             fitResultTreeName = "pwa",
                             fitResultBranchName = "fitResult_v2"
                            ):
	fitResultFile = ROOT.TFile.Open(fitResultFileName, "READ")
	if not fitResultFile:
		printErr("Could not open generated fit result file '" + fitResultFileName + "'.")
		return None

	fitResultTree = fitResultFile.Get(fitResultTreeName)
	if not fitResultTree:
		printErr("could not find fit result tree '" + fitResultTreeName +
		         "' in file '" + fitResultFileName + "'. Aborting...")
		return None

	result = pyRootPwa.core.fitResult()
	result.setBranchAddress(fitResultTree, fitResultBranchName)

	# only print the warning about multiple mass-bin centers in one file
	# once
	printedMassBinCenterWarning = False

	bestResult = None

	for i in xrange(fitResultTree.GetEntries()):
		fitResultTree.GetEntry(i)

		# skip fit results that did no converge
		if not result.converged():
			continue

		if bestResult is None:
			bestResult = pyRootPwa.core.fitResult(result)
		elif massBinCenter is None:
			if bestResult.massBinCenter() != result.massBinCenter() and not printedMassBinCenterWarning:
				printWarn("fit result file '" + fitResultFileName + "' " +
				          "contains more than one mass bin, return the " +
				          "fit result with the best likelihood.")
				printedMassBinCenterWarning = True
			if result.logLikelihood() < bestResult.logLikelihood():
				bestResult = pyRootPwa.core.fitResult(result)
		else:
			if abs(massBinCenter - result.massBinCenter()) < abs(massBinCenter - bestResult.massBinCenter()):
				bestResult = pyRootPwa.core.fitResult(result)
			elif abs(massBinCenter - result.massBinCenter()) == abs(massBinCenter - bestResult.massBinCenter()):
				if result.logLikelihood() < bestResult.logLikelihood():
					bestResult = pyRootPwa.core.fitResult(result)

	fitResultFile.Close()

	return bestResult