From 1f5169c8b4f8d5313eb51f54e1e41753405a7560 Mon Sep 17 00:00:00 2001 From: Juraj Smiesko Date: Thu, 12 Oct 2023 17:46:41 +0200 Subject: [PATCH] Add tests for the standalone mode --- cmake/FCCAnalysesFunctions.cmake | 14 ++++++++ e4hsource/test/standalone.py | 44 +++++++++++++++++++++++++ e4hsource/test/standalone_legacy.py | 50 +++++++++++++++++++++++++++++ tests/CMakeLists.txt | 2 ++ 4 files changed, 110 insertions(+) create mode 100644 e4hsource/test/standalone.py create mode 100644 e4hsource/test/standalone_legacy.py diff --git a/cmake/FCCAnalysesFunctions.cmake b/cmake/FCCAnalysesFunctions.cmake index a34e3507cbd..d0ad136fcbc 100644 --- a/cmake/FCCAnalysesFunctions.cmake +++ b/cmake/FCCAnalysesFunctions.cmake @@ -58,6 +58,20 @@ function(add_generic_test _testname _testcmd) TEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR}) endfunction() +function(add_standalone_test _testname) + add_test(NAME fccanalysis_standalone_${_testname} + COMMAND python ${_testname} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ) + set_property(TEST fccanalysis_standalone_${_testname} APPEND PROPERTY ENVIRONMENT + LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/analyzers/dataframe:$ENV{LD_LIBRARY_PATH} + PYTHONPATH=${CMAKE_SOURCE_DIR}/python:$ENV{PYTHONPATH} + PATH=${CMAKE_SOURCE_DIR}/bin:${CMAKE_BINARY_DIR}:$ENV{PATH} + ROOT_INCLUDE_PATH=${CMAKE_SOURCE_DIR}/analyzers/dataframe:$ENV{ROOT_INCLUDE_PATH} + TEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR} + ) +endfunction() + macro(fccanalyses_addon_build _name) set(options) set(one_val) diff --git a/e4hsource/test/standalone.py b/e4hsource/test/standalone.py new file mode 100644 index 00000000000..f3225f2565c --- /dev/null +++ b/e4hsource/test/standalone.py @@ -0,0 +1,44 @@ +''' +Standalone test of EDM4hep RDataSource in Python. +''' + +import ROOT +ROOT.gROOT.SetBatch(True) + +def main(): + input_list = ['/eos/experiment/fcc/ee/generation/DelphesEvents/winter2023/' \ + 'IDEA/p8_ee_WW_ecm240/events_192112516.root'] + + print ("----> Info: Loading analyzers from libFCCAnalyses... ",) + ROOT.gSystem.Load("libFCCAnalyses") + _fcc = ROOT.dummyLoader + + print('----> Info: Loading events through EDM4hep RDataSource...') + ROOT.gSystem.Load("libe4hsource") + if ROOT.loadEDM4hepDataSource(): + print('----> Debug: EDM4hep RDataSource loaded') + try: + dframe = ROOT.FCCAnalyses.FromEDM4hep(input_list) + except TypeError as excp: + print('----> Error: Unable to build dataframe!') + print(excp) + + dframe2 = dframe.Define( + "electron_truth", + "FCCAnalyses::ReconstructedParticle::selPDG(11)(MCRecoAssociations)") + + dframe3 = dframe2.Define( + "electron_truth_pt", + "FCCAnalyses::ReconstructedParticle::getPt(electron_truth)") + + dframe4 = dframe3.Filter("electron_truth_pt.size() < 3") + + count = dframe4.Count() + dframe4.Snapshot("events", "output.root", {"electron_truth_pt"}) + # dframe4.Snapshot("events", "output.root", {"electron_truth", "electron_truth_pt"}) + + print("---------------------") + print("Nuber of events: ", count.GetValue()) + +if __name__ == "__main__": + main() diff --git a/e4hsource/test/standalone_legacy.py b/e4hsource/test/standalone_legacy.py new file mode 100644 index 00000000000..6313d30d112 --- /dev/null +++ b/e4hsource/test/standalone_legacy.py @@ -0,0 +1,50 @@ +''' +Standalone test of legacy EDM4hep RDataSource in Python. +''' + +import ROOT +ROOT.gROOT.SetBatch(True) + +def main(): + input_list = [ + '/eos/user/g/gasadows/Output/TrackingPerformance/' + 'LCIO/FCCee_o1_v04/REC/resVXD_3mic/' + 'RECTest_FCCee_o1_v04_resVXD_3mic_mu_89_deg_100_GeV_10000_evts_edm4hep' + '.root' + ] + + print ("----> Info: Loading analyzers from libFCCAnalyses... ",) + ROOT.gSystem.Load("libFCCAnalyses") + _fcc = ROOT.dummyLoader + + print('----> Info: Loading events through legacy EDM4hep RDataSource...') + ROOT.gSystem.Load("libe4hlegacysource") + if ROOT.loadEDM4hepLegacySource(): + print('----> Debug: Legacy EDM4hep RDataSource loaded') + try: + dframe = ROOT.FCCAnalyses.FromEDM4hepLegacy(input_list) + except TypeError as excp: + print('----> Error: Unable to build dataframe!') + print(excp) + + dframe2 = dframe.Define( + "electron_truth", + "FCCAnalyses::ReconstructedParticle::selPDG(11, false)(RecoMCTruthLink)" + ) + + dframe3 = dframe2.Define( + "electron_truth_pt", + "FCCAnalyses::ReconstructedParticle::getPt(electron_truth)") + + dframe4 = dframe3.Filter("electron_truth_pt.size() > 0") + + count = dframe4.Count() + dframe4.Snapshot("events", "output.root", {"electron_truth_pt"}) + # dframe4.Snapshot("events", "output.root", {"electron_truth", + # "electron_truth_pt"}) + + print("---------------------") + print("Nuber of events: ", count.GetValue()) + +if __name__ == "__main__": + main() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 42638fca82e..e0b5eb64c79 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,6 +8,8 @@ add_integration_test("examples/FCCee/test/jet_constituents.py") add_integration_test("examples/FCCee/vertex_lcfiplus/analysis_V0.py") add_integration_test("e4hsource/test/histmaker_source.py") add_integration_test("e4hsource/test/stages_source.py") +add_standalone_test("e4hsource/test/standalone.py") +add_standalone_test("e4hsource/test/standalone_legacy.py") # TODO: make this test run in the spack build environment #add_generic_test(build_new_case_study "tests/build_new_case_study.sh")