Belle II Software development
test_VariablesToParquet.py
1#!/usr/bin/env python3
2
3
10
11import os
12import basf2
13import pandas
14import b2test_utils
15from b2pandas_utils import VariablesToTable
16
17inputFile = b2test_utils.require_file('mdst16.root', 'validation')
18path = basf2.create_path()
19path.add_module('RootInput', inputFileName=inputFile)
20path.add_module('ParticleLoader', decayStrings=['e+'])
21
22# Write out electron id and momentum of all true electron candidates
23v2parquet_e = VariablesToTable(
24 "e+:all", ['electronID', 'p', 'isSignal'], "particleDF.pq", "parquet")
25path.add_module(v2parquet_e)
26
27# event-wise mode is not supported at the moment. when it is add something like
28# the following comment and test file creation
29# Write out number of tracks and ecl-clusters in every event
30# v2parquet_e = VariablesToNotRoot(
31# "", ['nTracks', 'nKLMClusters'], "eventDF.pq", "parquet")
32# path.add_module(v2parquet_e)
33
34
36 basf2.process(path, 10) # v2hdf5 is a python module, so don't run over everything... remove this if it gets implemented in C++
37
38 # Testing
39 assert os.path.isfile('particleDF.pq'), "particleDF.pq wasn't created"
40 df1 = pandas.read_parquet('particleDF.pq')
41 assert len(df1) > 0, "electron dataframe contains zero entries"
42 assert 'electronID' in df1.columns, "electronID column is missing from electron dataframe"
43 assert 'p' in df1.columns, "p column is missing from electron dataframe"
44 assert '__event__' in df1.columns, "event number is missing from electron dataframe"
45 assert '__run__' in df1.columns, "run number is missing from electron dataframe"
46 assert '__experiment__' in df1.columns, "experiment number is missing from electron dataframe"
47 assert '__candidate__' in df1.columns, "candidate number is missing from electron dataframe"
48 assert '__ncandidates__' in df1.columns, "candidate count is missing from electron dataframe"
49
50 assert df1.__run__[0] == 0, "run number not as expected"
51 assert df1.__experiment__[0] == 1003, "experiment number not as expected"
52 assert df1.__event__[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:189