From efdc150fdf82a50170457094ec86e0c42977b644 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 27 Aug 2024 16:04:14 +0200 Subject: [PATCH 1/7] Run a test to create an RNTuple EDM4hep file and add explanations in the README. --- README.md | 8 ++++++++ scripts/createEDM4hepFile.py | 10 +++++----- test/CMakeLists.txt | 5 ++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6c70d33bb..6cb0bbc2a 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,14 @@ with tools that consume JSON. Use `edm4hep2json --help` to see the available options for selecting which parts of the input file should be part of the output. +## Example files + +Example EDM4hep files can be obtained from the Continuous Integration (CI) +workflows. From the EDM4hep github page, go to Actions -> Key4hep build, click +one of the runs (the latest scheduled is preferred) and they will appear at the +bottom, under Artifacts. + + ## Contributing Contributions and bug reports are welcome! See our [contributing guidelines](doc/contributing.md) if you want to contribute code to EDM4hep. diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 9ade63cf0..e9e902cc2 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -10,14 +10,16 @@ frames = 3 # How many frames or events will be written vectorsize = 5 # For vector members, each vector member will have this size counter = count() # next(counter) will return 0, 1, 2, ... -# used to generate the dummy data -output_file = "output.root" parser = argparse.ArgumentParser(description="Create a file with EDM4hep data") parser.add_argument( "--rntuple", action="store_true", help="Use a ROOT ntuple instead of EDM4hep" ) +parser.add_argument( + "--output-file", type=str, help="Output file name", default="edm4hep.root" +) args = parser.parse_args() +output_file = args.output_file if args.rntuple: try: @@ -78,9 +80,7 @@ particle.setMomentumAtEndpoint( edm4hep.Vector3d(next(counter), next(counter), next(counter)) ) - particle.setSpin( - edm4hep.Vector3f(next(counter), next(counter), next(counter)) - ) + particle.setSpin(edm4hep.Vector3f(next(counter), next(counter), next(counter))) particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) particles[0].addToDaughters(particles[1]) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ee6306bdb..83cf21ca1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,9 +13,12 @@ function(set_test_env _testname) ) endfunction() -add_test(NAME "Create an EDM4hep data file" COMMAND python ${PROJECT_SOURCE_DIR}/scripts/createEDM4hepFile.py) +add_test(NAME "Create an EDM4hep data file" COMMAND python ${PROJECT_SOURCE_DIR}/scripts/createEDM4hepFile.py --output-file edm4hep_example.root) set_test_env("Create an EDM4hep data file") +add_test(NAME "Create an EDM4hep data file (RNTuple)" COMMAND python ${PROJECT_SOURCE_DIR}/scripts/createEDM4hepFile.py --rntuple --output-file edm4hep_example_rntuple.root) +set_test_env("Create an EDM4hep data file (RNTuple)") + add_executable(write_events write_events.cc) target_include_directories(write_events PUBLIC ${PROJECT_SOURCE_DIR}/edm4hep ) target_link_libraries(write_events edm4hep podio::podioRootIO) From 496b3d7b4ced4309a185d5862c235872fa51e609 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 27 Aug 2024 16:34:38 +0200 Subject: [PATCH 2/7] Skip test if the RNTuple writer isn't found --- test/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 83cf21ca1..81370e3bf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,6 +18,9 @@ set_test_env("Create an EDM4hep data file") add_test(NAME "Create an EDM4hep data file (RNTuple)" COMMAND python ${PROJECT_SOURCE_DIR}/scripts/createEDM4hepFile.py --rntuple --output-file edm4hep_example_rntuple.root) set_test_env("Create an EDM4hep data file (RNTuple)") +set_test_properties("Create an EDM4hep data file (RNTuple)" PROPERTIES + SKIP_REGULAR_EXPRESSION "The RNTuple writer from podio is not available but was requested" +) add_executable(write_events write_events.cc) target_include_directories(write_events PUBLIC ${PROJECT_SOURCE_DIR}/edm4hep ) From 5969b930f083c950d3d725619a65f48d2da826a5 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 27 Aug 2024 16:38:28 +0200 Subject: [PATCH 3/7] Fix typo --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 81370e3bf..65c816322 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,7 +18,7 @@ set_test_env("Create an EDM4hep data file") add_test(NAME "Create an EDM4hep data file (RNTuple)" COMMAND python ${PROJECT_SOURCE_DIR}/scripts/createEDM4hepFile.py --rntuple --output-file edm4hep_example_rntuple.root) set_test_env("Create an EDM4hep data file (RNTuple)") -set_test_properties("Create an EDM4hep data file (RNTuple)" PROPERTIES +set_tests_properties("Create an EDM4hep data file (RNTuple)" PROPERTIES SKIP_REGULAR_EXPRESSION "The RNTuple writer from podio is not available but was requested" ) From 4ffdb369a816a64000c57f73affc27d2d09302c7 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 2 Sep 2024 08:27:38 +0200 Subject: [PATCH 4/7] Use setFrom and setTo to fix deprecation warnings --- scripts/createEDM4hepFile.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index e9e902cc2..9fae31fcc 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -272,50 +272,50 @@ links = edm4hep.RecoMCParticleLinkCollection() link = links.create() link.setWeight(next(counter)) - link.setRec(reco_particle) - link.setSim(particle) + link.setFrom(reco_particle) + link.setTo(particle) frame.put(links, "RecoMCParticleLinkCollection") links = edm4hep.CaloHitSimCaloHitLinkCollection() link = links.create() link.setWeight(next(counter)) - link.setRec(calo_hit) - link.setSim(simcalo_hit) + link.setFrom(calo_hit) + link.setTo(simcalo_hit) frame.put(links, "CaloHitSimCaloHitLinkCollection") links = edm4hep.TrackerHitSimTrackerHitLinkCollection() link = links.create() link.setWeight(next(counter)) - link.setRec(tracker_hit) - link.setSim(simtracker_hit) + link.setFrom(tracker_hit) + link.setTo(simtracker_hit) frame.put(links, "TrackerHitSimTrackerHitLinkCollection") links = edm4hep.CaloHitMCParticleLinkCollection() link = links.create() link.setWeight(next(counter)) - link.setRec(calo_hit) - link.setSim(particle) + link.setFrom(calo_hit) + link.setTo(particle) frame.put(links, "CaloHitMCParticleLinkCollection") links = edm4hep.ClusterMCParticleLinkCollection() link = links.create() link.setWeight(next(counter)) - link.setRec(cluster) - link.setSim(particle) + link.setFrom(cluster) + link.setTo(particle) frame.put(links, "ClusterMCParticleLinkCollection") links = edm4hep.TrackMCParticleLinkCollection() link = links.create() link.setWeight(next(counter)) - link.setRec(track) - link.setSim(particle) + link.setFrom(track) + link.setTo(particle) frame.put(links, "TrackMCParticleLinkCollection") links = edm4hep.VertexRecoParticleLinkCollection() link = links.create() link.setWeight(next(counter)) - link.setRec(reco_particle) - link.setVertex(v) + link.setTo(reco_particle) + link.setFrom(v) frame.put(links, "MCVertexRecoParticleLinkCollection") timeseries = edm4hep.TimeSeriesCollection() From 9d65a63726da9fbcd9d6b823fd75a94819c15590 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 2 Sep 2024 08:27:56 +0200 Subject: [PATCH 5/7] Add missing collections to the frames --- scripts/createEDM4hepFile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 9fae31fcc..d8e070fe2 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -344,6 +344,7 @@ gep.setAlphaQCD(next(counter)) gep.setSignalProcessId(next(counter)) gep.setSqrts(next(counter)) + frame.put(gep_coll, "GeneratorEventParametersCollection") for i in range(vectorsize): gep.addToCrossSections(next(counter)) @@ -369,5 +370,6 @@ gpi.setXf(0, next(counter)) gpi.setXf(1, next(counter)) gpi.setScale(next(counter)) + frame.put(gpi_coll, "GeneratorPdfInfoCollection") writer.write_frame(frame, "events") From 822edeade5b8852332ac85c7fdb618796d869861 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 2 Sep 2024 08:52:42 +0200 Subject: [PATCH 6/7] Add missing Nholes for tracks --- scripts/createEDM4hepFile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index d8e070fe2..bfe2a4e6d 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -229,6 +229,7 @@ track.addToTrackStates(state) track.addToTrackerHits(tracker_hit) track.addToTracks(track) + track.setNholes(next(counter)) frame.put(tracks, "TrackCollection") vertex = edm4hep.VertexCollection() From 41dbd45a9d7f2cf742e6313d2c416343c6ecfb9d Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 2 Sep 2024 09:37:24 +0200 Subject: [PATCH 7/7] Fix setting the covariance matrix --- scripts/createEDM4hepFile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index bfe2a4e6d..a7666346d 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -225,7 +225,7 @@ state.referencePoint = edm4hep.Vector3f( next(counter), next(counter), next(counter) ) - state.CovMatrix = cov6f + state.covMatrix = cov6f track.addToTrackStates(state) track.addToTrackerHits(tracker_hit) track.addToTracks(track)