Differences between revisions 1 and 2
Revision 1 as of 2020-03-24 17:25:18
Size: 374
Comment:
Revision 2 as of 2020-06-28 21:50:26
Size: 1174
Comment:
Deletions are marked like this. Additions are marked like this.
Line 8: Line 8:


== gwpyのFrequencySeriesをROOTのTH1にする ==

{{{#!python
mean = FrequencySeries(...)
error = FrequencySeries(...)

nbin = mean.size
value = mean.value
freqs = mean.frequencies.value
df = mean.df.value
fmin = freqs[0] - df*0.5
fmax = freqs[-1]+ df*0.5

h = TH1F('h', ';Frequency [Hz]', nbin, fmin, fmax)
h.Sumw2()
h.SetContent(array('d', np.insert( value, 0,0).tolist() ) )
h.SetError( array('d', np.insert(error.value, 0,0).tolist() ) )
}}}

[[https://root.cern.ch/doc/master/classTH1.html#a828aa3b97264611a20c3849e1820b28b|SetContent()]]と[[https://root.cern.ch/doc/master/classTH1.html#a02b9ba99fdb9312861ac3a0f5d25946d|SetError()]]はゼロbin目(アンダーフロー)から詰めるため、ndarrayの先頭にゼロを追加しておく必要がある。

pyROOT

高エネルギー宇宙物理学のためのROOT入門 ‒第6回‒

KamonoWiki

QumaWiki

gwpyのFrequencySeriesをROOTのTH1にする

   1 mean  = FrequencySeries(...)
   2 error = FrequencySeries(...)
   3 
   4 nbin = mean.size
   5 value = mean.value
   6 freqs = mean.frequencies.value
   7 df = mean.df.value
   8 fmin = freqs[0] - df*0.5
   9 fmax = freqs[-1]+ df*0.5
  10 
  11 h = TH1F('h', ';Frequency [Hz]', nbin, fmin, fmax)
  12 h.Sumw2()
  13 h.SetContent(array('d', np.insert(      value, 0,0).tolist() ) )
  14 h.SetError(  array('d', np.insert(error.value, 0,0).tolist() ) )

SetContent()SetError()はゼロbin目(アンダーフロー)から詰めるため、ndarrayの先頭にゼロを追加しておく必要がある。

KAGRA/Subgroups/PEM/PythonMemoJP/pyROOT (last edited 2020-06-28 22:23:38 by tatsuki.washimi)