Skip to content

Commit

Permalink
Add artifacts with EDM4hep files (#353)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jmcarcell and jmcarcell authored Sep 2, 2024
1 parent bd1ccb8 commit c5a7462
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
43 changes: 23 additions & 20 deletions scripts/createEDM4hepFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand All @@ -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")
8 changes: 7 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c5a7462

Please sign in to comment.