Functions | Variables
spectra_to_pyobj Namespace Reference

Functions

def main (spectra_file, save_to)
 
def save_spectra (output_name, specs)
 
def bin_edges (hist)
 
def bin_contents (hist)
 

Variables

 parser = argparse.ArgumentParser('Convert ROOT spectra into numpy arrays and save to hdf5')
 
 help
 
 default
 
 args = parser.parse_args()
 

Function Documentation

def spectra_to_pyobj.bin_contents (   hist)

Definition at line 43 of file spectra_to_pyobj.py.

References PandAna.Demos.demo1.range.

Referenced by save_spectra().

43 def bin_contents(hist):
44  nbins = hist.GetNbinsX()
45  contents = np.zeros(nbins)
46  for i in range(nbins):
47  contents[i] = hist.GetBinContent(i+1)
48  return contents
49 
def bin_contents(hist)
def spectra_to_pyobj.bin_edges (   hist)

Definition at line 36 of file spectra_to_pyobj.py.

References PandAna.Demos.demo1.range.

Referenced by DrawCovMx(), and save_spectra().

36 def bin_edges(hist):
37  nbins = hist.GetNbinsX()
38  edges = np.zeros(nbins+1)
39  for i in range(nbins+1):
40  edges[i] = hist.GetBinLowEdge(i+1)
41  return edges
42 
def spectra_to_pyobj.main (   spectra_file,
  save_to 
)

Definition at line 7 of file spectra_to_pyobj.py.

References novadaq::HexUtils.format(), and save_spectra().

7 def main(spectra_file, save_to):
8  if save_to is None:
9  save_to = spectra_file.replace('.root', '.hdf5')
10 
11  input_file = TFile(spectra_file, 'read')
12  spectra = []
13  for key in input_file.GetListOfKeys():
14  spectra.append({})
15  spectra[-1]['name'] = key.GetName()
16  spectra[-1]['hist'] = input_file.Get('{}/hist'.format(key.GetName()))
17  spectra[-1]['pot'] = input_file.Get('{}/pot'.format(key.GetName())).GetBinContent(1)
18 
19  save_spectra(save_to, spectra)
20 
def main(spectra_file, save_to)
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
def save_spectra(output_name, specs)
def spectra_to_pyobj.save_spectra (   output_name,
  specs 
)

Definition at line 21 of file spectra_to_pyobj.py.

References bin_contents(), bin_edges(), and print.

Referenced by main().

21 def save_spectra(output_name, specs):
22  if not type(specs) is list: specs = [specs]
23  fobj = h5py.File(output_name, 'w')
24  for spec in specs:
25  edges = bin_edges(spec['hist'])
26  contents = bin_contents(spec['hist'])
27  pot = spec['pot']
28  group = spec['name']
29  fobj.create_group(group)
30  print('Saving ' + group)
31  fobj.create_dataset(group + '/edges', data=edges)
32  fobj.create_dataset(group + '/contents', data=contents)
33  fobj.create_dataset(group + '/pot', data=pot)
34  fobj.close()
35 
::xsd::cxx::tree::type type
Definition: Database.h:110
bool print
def bin_contents(hist)
def save_spectra(output_name, specs)

Variable Documentation

spectra_to_pyobj.args = parser.parse_args()

Definition at line 60 of file spectra_to_pyobj.py.

spectra_to_pyobj.default

Definition at line 57 of file spectra_to_pyobj.py.

spectra_to_pyobj.help

Definition at line 56 of file spectra_to_pyobj.py.

spectra_to_pyobj.parser = argparse.ArgumentParser('Convert ROOT spectra into numpy arrays and save to hdf5')

Definition at line 53 of file spectra_to_pyobj.py.