source: trunk/examples/advanced/Tiara/source/py_modules/dpsManip.py @ 807

Last change on this file since 807 was 807, checked in by garnier, 16 years ago

update

File size: 2.6 KB
Line 
1# $Id: dpsManip.py,v 1.2 2003/06/16 17:06:44 dressel Exp $
2# -------------------------------------------------------------------
3# GEANT4 tag $Name:  $
4# -------------------------------------------------------------------
5#
6import math
7
8# functions to manipulate a DPS (data point set)
9
10def getScaledDPS(hSrc, scale, df, name):
11    "Create a scaled DPS from a histogramm."
12    hSrc.scale(scale)
13    dp = df.create(name, hSrc)
14    setDPSErrorsToZero(dp, 0)
15    hSrc.scale(1./scale)
16
17    return dp
18
19
20def setDPSErrorsToZero(dps, coNum):
21    "Set errors of a DPS to zero."
22    for i in range(dps.size()):
23        p = dps.point(i)
24        co = p.coordinate(coNum)
25        co.setErrorMinus(coNum)
26        co.setErrorPlus(coNum)
27
28def copyDPS(dSrc, df, name):
29    "Make a copy of a DPS using the data point set factory df."
30    dp = df.create(name, dSrc.dimension ())
31    for i in range( dSrc.size() ):
32        dp.addPoint()
33        pNew = dp.point(i)
34        pOld = dSrc.point(i)
35        for d in range(dSrc.dimension ()):
36            cOld = pOld.coordinate(d)
37            cNew = pNew.coordinate(d)
38            cNew.setValue(cOld.value())
39            em = cOld.errorMinus()
40            ep = cOld.errorPlus()
41            cNew.setErrorMinus(em)
42            cNew.setErrorPlus(ep)
43    return dp
44
45def dLogWeightDPS(dSrc, df, name, binEdges):
46    """Create a dps with the coordinate 1 scaled by 1/dlog(coordinate 0).
47    """
48    dp = copyDPS(dSrc, df, name)
49    for i in range(len(binEdges) - 1):
50        s = math.log(binEdges[i+1]) - math.log(binEdges[i])
51        c = dp.point(i).coordinate (1)
52        value = dSrc.point(i).coordinate(1).value()
53        errorMinus = dSrc.point(i).coordinate(1).errorMinus()
54        errorPlus = dSrc.point(i).coordinate(1).errorPlus()
55        c.setValue(value / s)
56        c.setErrorMinus(errorMinus / s)
57        c.setErrorPlus(errorPlus / s)
58    return dp
59
60
61def createScaledDPS(coNum, pDataO, df, name, scale):
62    """Create a scaled DPS from a DPS.
63
64    The coordinate \'coNum\' of the source DPS \'pDataO\' is scaled by
65    \'scale\'. The result is returned in the DPS created by  the given
66    data point set factory \'df\' named \'name\'.
67    """
68    dp = copyDPS(pDataO, df, name)
69    for i in range( dp.size() ):
70        p = dp.point(i)
71        co = p.coordinate(coNum)
72        co.setValue(co.value()*scale)
73        co.setErrorMinus(co.errorMinus()*scale)
74        co.setErrorPlus(co.errorPlus()*scale)
75    return dp
76
77
78
79def getBinEdges(h):
80    "Get bin edges of a histogramm."
81    binEdges = []
82    a = h.axis ()
83    for i in range(a.bins ()):
84        binEdges.append(a.binLowerEdge(i))
85    binEdges.append(a.binUpperEdge(a.bins () - 1))
86    return binEdges
87
88
89
90
Note: See TracBrowser for help on using the repository browser.