ATLAS Offline Software
rootconvert.py
Go to the documentation of this file.
1 from array import array
2 import ROOT as rt
3 import yoda
4 
5 fName = 'MyOutput.yoda.gz'
6 yodaAOs = yoda.read(fName)
7 rtFile = rt.TFile(fName[:fName.find('.yoda')] + '.root', 'recreate')
8 
9 for name_slashes in yodaAOs:
10  name = name_slashes.replace("/", "_")
11  yodaAO = yodaAOs[name_slashes]
12  rtAO = None
13 
14  if 'Histo1D' in str(yodaAO):
15  rtAO = rt.TH1D(name, '', yodaAO.numBins(), array('d', yodaAO.xEdges()))
16 
17 
18  rtAO.Sumw2()
19  rtErrs = rtAO.GetSumw2()
20 
21  for i in range(rtAO.GetNbinsX()):
22 
23  rtAO.SetBinContent(i + 1, yodaAO.bin(i).sumW())
24  rtErrs.AddAt(yodaAO.bin(i).sumW2(), i+1)
25 
26  elif 'Scatter2D' in str(yodaAO):
27  rtAO = rt.TGraphAsymmErrors(yodaAO.numPoints())
28  rtAO.SetName(name)
29 
30  for i in range(yodaAO.numPoints()):
31  x = yodaAO.point(i).x(); y = yodaAO.point(i).y()
32  xLo, xHi = yodaAO.point(i).xErrs()
33  yLo, yHi = yodaAO.point(i).yErrs()
34  rtAO.SetPoint(i, x, y)
35  rtAO.SetPointError(i, xLo, xHi, yLo, yHi)
36  else:
37  continue
38 
39  rtAO.Write(name)
40 
41 rtFile.Close()
rootconvert.x
x
Definition: rootconvert.py:31
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
array
str
Definition: BTagTrackIpAccessor.cxx:11