Skip to content

Commit

Permalink
Add tests for the standalone mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvbrt committed Oct 26, 2023
1 parent d0d46ce commit 8a3daa2
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmake/FCCAnalysesFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions e4hsource/test/standalone.py
Original file line number Diff line number Diff line change
@@ -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()
50 changes: 50 additions & 0 deletions e4hsource/test/standalone_legacy.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 8a3daa2

Please sign in to comment.