From c5a7462adf3d585700fb4f3b028dda2503deead2 Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Mon, 2 Sep 2024 11:50:14 +0200 Subject: [PATCH] Add artifacts with EDM4hep files (#353) * Run a test to create an RNTuple EDM4hep file and add explanations in the README. * Skip test if the RNTuple writer isn't found * Fix typo * Use setFrom and setTo to fix deprecation warnings * Add missing collections to the frames * Add missing Nholes for tracks * Fix setting the covariance matrix --------- Co-authored-by: jmcarcell --- README.md | 8 +++++++ scripts/createEDM4hepFile.py | 43 +++++++++++++++++++----------------- test/CMakeLists.txt | 8 ++++++- 3 files changed, 38 insertions(+), 21 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..a7666346d 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]) @@ -225,10 +225,11 @@ 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) + track.setNholes(next(counter)) frame.put(tracks, "TrackCollection") vertex = edm4hep.VertexCollection() @@ -272,50 +273,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() @@ -344,6 +345,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 +371,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") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ee6306bdb..65c816322 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,9 +13,15 @@ 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)") +set_tests_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 ) target_link_libraries(write_events edm4hep podio::podioRootIO)