Belle II Software  release-06-00-14
test_VariablesToHDF5.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import os
13 import basf2
14 import pandas
15 import b2test_utils
16 from b2pandas_utils import VariablesToHDF5
17 
18 inputFile = b2test_utils.require_file('mdst14.root', 'validation')
19 path = basf2.create_path()
20 path.add_module('RootInput', inputFileName=inputFile)
21 path.add_module('ParticleLoader', decayStrings=['e+'])
22 
23 # Write out electron id and momentum of all true electron candidates
24 v2hdf5_e = VariablesToHDF5(
25  "e+:all", ['electronID', 'p', 'isSignal'], "particleDF.hdf5")
26 path.add_module(v2hdf5_e)
27 
28 # event-wise mode is not supported at the moment. when it is add something like
29 # the following comment and test file creation
30 # Write out number of tracks and ecl-clusters in every event
31 # v2hdf5_evt = VariablesToHDF5(
32 # "", ['nTracks', 'nKLMClusters'], "eventDF.hdf5")
33 # path.add_module(v2hdf5_evt)
34 
35 
37  basf2.process(path, 10) # v2hdf5 is a python module, so don't run over everything... remove this if it gets implemented in C++
38 
39  # Testing
40  assert os.path.isfile('particleDF.hdf5'), "particleDF.hdf5 wasn't created"
41  df1 = pandas.read_hdf('particleDF.hdf5', 'e+:all')
42  assert len(df1) > 0, "electron dataframe contains zero entries"
43  assert 'electronID' in df1.columns, "electronID column is missing from electron dataframe"
44  assert 'p' in df1.columns, "p column is missing from electron dataframe"
45  assert 'evt' in df1.columns, "event number is missing from electron dataframe"
46  assert 'run' in df1.columns, "run number is missing from electron dataframe"
47  assert 'exp' in df1.columns, "experiment number is missing from electron dataframe"
48  assert 'icand' in df1.columns, "candidate number is missing from electron dataframe"
49  assert 'ncand' in df1.columns, "candidate count is missing from electron dataframe"
50 
51  assert df1.run[0] == 0, "run number not as expected"
52  assert df1.exp[0] == 1003, "experiment number not as expected"
53  assert df1.evt[0] == 1, "event number not as expected"
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:54
def clean_working_directory()
Definition: __init__.py:185