7 __doc__ =
"""Test read and write histograms and trees via ITHistSvc"""
8 __author__ =
"Sebastien Binet <binet@cern.ch>"
10 from AthenaPython
import PyAthena
11 StatusCode = PyAthena.StatusCode
14 """Simple algorithm to read data from Root hist. svc
19 super(PyHistReader,self).
__init__(**kw)
27 _info(
"==> initialize...")
28 self.
hsvc = PyAthena.py_svc(
'THistSvc/THistSvc')
30 self.
msg.
error(
'Could not retrieve THistSvc')
31 return StatusCode.Failure
33 def print_properties(h):
34 _info(
' -%-20s: %i <mean>=%8.3f rms=%8.3f',
35 h.GetName(), h.GetEntries(), h.GetMean(), h.GetRMS())
38 o = self.
hsvc.
load(
'/read1/xxx/gauss1d', oid_type=
'hist')
41 o = self.
hsvc.
load(
'/read2/gauss2d', oid_type=
'hist')
44 o = self.
hsvc.
load(
'/read2/gauss3d', oid_type=
'hist')
47 o = self.
hsvc.
load(
'/read2/profile', oid_type=
'hist')
50 o = self.
hsvc.
load(
'/read2/trees/stuff/tree1', oid_type=
'tree')
51 _info(
' -%-20s: %i', o.GetName(), o.GetEntries())
53 return StatusCode.Success
57 _info(
'==> execute...')
58 return StatusCode.Success
61 self.
msg.
info(
'==> finalize...')
62 return StatusCode.Success
66 from math
import sin
as math_sin
67 from random
import gauss
68 from array
import array
70 """A simple python algorithm to write stuff into a ROOT file via the
71 @c ITHistSvc (translated example from GaudiExamples/src/THist)
76 super(PyHistWriter,self).
__init__(**kw)
84 _info(
'==> initialize...')
85 self.
hsvc = PyAthena.py_svc(
'THistSvc/THistSvc')
87 self.
msg.
error(
'could not retrieve THistSvc/THistSvc')
88 return StatusCode.Failure
90 from ROOT
import TH1F, TH2F, TH3F, TProfile, TTree
92 def th1(n,t):
return TH1F(n,t,100,0.,100.)
93 def th2(n,t):
return TH2F(n,t,100,-50.,50.,100,-50.,50.)
94 def th3(n,t):
return TH3F(n,t,100,-50.,50.,100,-50.,50.,100,-50.,50.)
95 def tp (n,t):
return TProfile(n,t,100,-50.,50.)
98 self.
hsvc[
'/temp/h1'] = th1(
'h1',
'Temporary hist 1')
99 self.
hsvc[
'/temp/other/h1a'] = th1(
'h1a',
'Temporary hist 1a')
102 self.
hsvc[
'/upd/xxx/gauss1d'] =
TH1F(
'gauss1d',
'1D gaussian',
106 self.
hsvc[
'/rec/gauss2d'] = th2(
'gauss2d',
'2D gaussian')
107 self.
hsvc[
'/rec/gauss3d'] = th3(
'gauss3d',
'3D gaussian')
108 self.
hsvc[
'/rec/prof'] = tp (
'profile',
'profile')
111 self.
hsvc[
'/rec/trees/stuff/tree1'] = TTree(
'tree1',
'tree title')
114 return StatusCode.Success
117 _info = self.
msg.info
118 _info(
'==> execute...')
121 x = math_sin(
float(n)) * 52. + 50.
123 hsvc[
'/temp/h1'].Fill(x)
124 for _
in range(2): hsvc[
'/temp/other/h1a'].Fill(x)
125 _fill = hsvc[
'/upd/xxx/gauss1d'].Fill
126 for _
in range(1000): _fill(
gauss(mu=0.,sigma=15.),1.)
127 _fill = hsvc[
'/rec/gauss2d'].Fill
128 for _
in range(1000): _fill(
gauss(mu=0.,sigma=15.),
129 gauss(mu=0.,sigma=15.), 1.)
130 _fill = hsvc[
'/rec/gauss3d'].Fill
131 for _
in range(1000): _fill(
gauss(mu=0.,sigma=15.),
132 gauss(mu=0.,sigma=15.),
133 gauss(mu=0.,sigma=15.), 1.)
135 tr = hsvc[
'/rec/trees/stuff/tree1']
140 tr.Branch(
'branch1', p1,
'point1/I')
141 tr.Branch(
'branch2', p2,
'point2/I')
142 tr.Branch(
'branch3', p3,
'point3/I')
144 for i
in range(1000):
149 return StatusCode.Success
152 _info = self.
msg.info
153 _info(
'==> finalize...')
154 for n
in (
'/temp/h1',
'/temp/other/h1a'):
156 _info(
' - histo [%r]', n)
158 _info(
' entries = %i', h.GetEntries())
159 _info(
' mean = %8.3f', h.GetMean())
160 _info(
' rms = %8.3f', h.GetRMS())
162 return StatusCode.Success