Пример #1
0
	def __init__( self, title, numerator, denominator, sysHisto=None ):
		self.title = title
		self.numerator = numerator
		self.denominator = denominator
		self.sysHisto = sysHisto
		self.ratio = numerator.Clone( randomName() )
		self.ratioSys = denominator.Clone( randomName() )
Пример #2
0
 def __init__(self, title, numerator, denominator, sysHisto=None):
     self.title = title
     self.numerator = numerator
     self.denominator = denominator
     self.sysHisto = sysHisto
     self.ratio = numerator.Clone(randomName())
     self.ratioSys = denominator.Clone(randomName())
Пример #3
0
def setPointAtBeginning(cont, x, y):
    newCont = cont.Clone(randomName())
    newCont.SetPoint(0, x, y)
    x = ROOT.Double(0)
    y = ROOT.Double(0)
    for i in range(cont.GetN()):
        cont.GetPoint(i, x, y)
        newCont.SetPoint(i + 1, x, y)

    return newCont
Пример #4
0
def setPointAtBeginning( cont, x, y ):
	newCont = cont.Clone( randomName() )
	newCont.SetPoint( 0, x, y )
	x = ROOT.Double(0)
	y = ROOT.Double(0)
	for i in range( cont.GetN() ):
		cont.GetPoint( i, x, y )
		newCont.SetPoint( i+1, x, y )

	return newCont
Пример #5
0
def getHistoFromScan(pointList):
    xList = sorted(set(zip(*pointList)[0]))
    yList = sorted(set(zip(*pointList)[1]))
    stepSizeX = xList[1] - xList[0]
    stepSizeY = yList[1] - yList[0]

    if xList != range(xList[0], xList[-1] + 1, stepSizeX):
        print "Error: no equidistant x-binning"
        print xList
        print "Assume T5wg sample and set bins manually"
        xList = range(xList[0], xList[-1] + 1, 50)
    if yList != range(yList[0], yList[-1] + 1, stepSizeY):
        print "Error: no equidistant y-binning"
        print yList

    return ROOT.TH2F( randomName(), "", len(xList), xList[0]-0.5*stepSizeX, xList[-1]+0.5*stepSizeX, \
     len(yList), yList[0]-0.5*stepSizeY, yList[-1]+0.5*stepSizeY )
Пример #6
0
def getHistoFromScan( pointList ):
	xList = sorted(set(zip(*pointList)[0]))
	yList = sorted(set(zip(*pointList)[1]))
	stepSizeX = xList[1] - xList[0]
	stepSizeY = yList[1] - yList[0]

	if xList != range( xList[0], xList[-1]+1, stepSizeX ):
		print "Error: no equidistant x-binning"
		print xList
		print "Assume T5wg sample and set bins manually"
		xList = range( xList[0], xList[-1]+1, 50 )
	if yList != range( yList[0], yList[-1]+1, stepSizeY ):
		print "Error: no equidistant y-binning"
		print yList

	return ROOT.TH2F( randomName(), "", len(xList), xList[0]-0.5*stepSizeX, xList[-1]+0.5*stepSizeX, \
		len(yList), yList[0]-0.5*stepSizeY, yList[-1]+0.5*stepSizeY )
Пример #7
0
def smoothGraph(graph, n=3, sigmaCorrection=1):
    """The points of TGraph 'graph' are shifted slightly, to smooth the curve.
	The next 'n' points are used from both directions, and are considered with
	a gaussian. The width of the gaussian can be set by 'sigmaCorrection'.
	Points close to the boarder are treated seperatly.
	"""

    newGraph = graph.Clone(randomName())
    nGraph = newGraph.GetN()

    if n > nGraph: n = nGraph

    sigma = n * sigmaCorrection
    lim = 3 * n
    fb = ROOT.TF1("fb", "gaus(0)", -lim, lim)
    fb.SetParameter(0, 1)
    fb.SetParameter(1, 0)
    fb.SetParameter(2, sigma)

    gaus = [fb.Eval(i) for i in range(-n, n + 1)]
    gaus = [i / sum(gaus) for i in gaus]

    for iPoint in range(nGraph):
        # point iPoint will be changed
        x = ROOT.Double(0)
        y = ROOT.Double(0)
        newGraph.GetPoint(iPoint, x, y)
        x0, y0 = float(x), float(y)

        newX = 0
        newY = 0
        weightSum = 0

        if iPoint - n >= 0 and iPoint + n <= nGraph - 1:
            # normal mode, use +- n points
            for i, iTestPoint in enumerate(range(iPoint - n, iPoint + n + 1)):
                graph.GetPoint(iTestPoint, x, y)
                newX += x * gaus[i]
                newY += y * gaus[i]
                weightSum += gaus[i]
            newX /= weightSum
            newY /= weightSum
        else:
            pointPosition = getPositionOfPoint(x, y)
            if pointPosition == "center":
                # use up to n points, but the same number up and down
                modN = min(n, iPoint, nGraph - iPoint) - 1
                for i, iTestPoint in enumerate(
                        range(iPoint - modN, iPoint + modN + 1)):
                    graph.GetPoint(iTestPoint, x, y)
                    newX += x * gaus[i]
                    newY += y * gaus[i]
                    weightSum += gaus[i]
                newX /= weightSum
                newY /= weightSum
            else:
                for i, iTestPoint in enumerate(
                        range(iPoint - n, iPoint + n + 1)):
                    graph.GetPoint(iTestPoint, x, y)
                    newX += x * gaus[i]
                    newY += y * gaus[i]
                    weightSum += gaus[i]
                newX /= weightSum
                newY /= weightSum

                if pointPosition in ["left", "right"]:
                    newX = x0
                else:
                    newY = y0

        newGraph.SetPoint(iPoint, newX, newY)
    return newGraph
Пример #8
0
def smoothGraph( graph, n=3, sigmaCorrection=1 ):
	"""The points of TGraph 'graph' are shifted slightly, to smooth the curve.
	The next 'n' points are used from both directions, and are considered with
	a gaussian. The width of the gaussian can be set by 'sigmaCorrection'.
	Points close to the boarder are treated seperatly.
	"""

	newGraph = graph.Clone( randomName() )
	nGraph = newGraph.GetN()

	if n > nGraph: n = nGraph

	sigma = n*sigmaCorrection
	lim = 3*n
	fb = ROOT.TF1("fb", "gaus(0)", -lim, lim)
	fb.SetParameter( 0, 1 )
	fb.SetParameter( 1, 0 )
	fb.SetParameter( 2, sigma )

	gaus = [ fb.Eval(i) for i in range(-n, n+1) ]
	gaus = [ i/sum(gaus) for i in gaus ]

	for iPoint in range( nGraph ):
		# point iPoint will be changed
		x  = ROOT.Double(0)
		y  = ROOT.Double(0)
		newGraph.GetPoint( iPoint, x, y )
		x0, y0 = float(x), float(y)

		newX = 0
		newY = 0
		weightSum = 0

		if iPoint-n >= 0 and iPoint+n <= nGraph-1:
			# normal mode, use +- n points
			for i, iTestPoint in enumerate(range( iPoint-n, iPoint+n+1 )):
				graph.GetPoint( iTestPoint, x, y )
				newX += x * gaus[i]
				newY += y * gaus[i]
				weightSum += gaus[i]
			newX /= weightSum
			newY /= weightSum
		else:
			pointPosition = getPositionOfPoint( x, y )
			if pointPosition == "center":
				# use up to n points, but the same number up and down
				modN = min( n, iPoint, nGraph-iPoint ) - 1
				for i, iTestPoint in enumerate(range( iPoint-modN, iPoint+modN+1 )):
					graph.GetPoint( iTestPoint, x, y )
					newX += x * gaus[i]
					newY += y * gaus[i]
					weightSum += gaus[i]
				newX /= weightSum
				newY /= weightSum
			else:
				for i, iTestPoint in enumerate(range( iPoint-n, iPoint+n+1 )):
					graph.GetPoint( iTestPoint, x, y )
					newX += x * gaus[i]
					newY += y * gaus[i]
					weightSum += gaus[i]
				newX /= weightSum
				newY /= weightSum

				if pointPosition in [ "left", "right" ]:
					newX = x0
				else:
					newY = y0

		newGraph.SetPoint( iPoint, newX, newY )
	return newGraph