From 12036890087979a23b41a0f91446782c320150af Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 21 Feb 2024 14:23:34 +0100 Subject: [PATCH 01/23] Add a script to create an EDM4hep file --- scripts/createEDM4hepFile.py | 383 +++++++++++++++++++++++++++++++++++ 1 file changed, 383 insertions(+) create mode 100644 scripts/createEDM4hepFile.py diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py new file mode 100644 index 000000000..99feb05c6 --- /dev/null +++ b/scripts/createEDM4hepFile.py @@ -0,0 +1,383 @@ +import podio +import edm4hep +import cppyy.ll +from itertools import count +import argparse + +frames = 10 +vectorsize = 5 +counter = count() + +parser = argparse.ArgumentParser(description='Create a file with EDM4hep data') +parser.add_argument('--use-pre1', action='store_true', help='Use a pre 1.0 version of EDM4hep') +args = parser.parse_args() + +writer = podio.root_io.Writer("output.root") + +for i in range(frames): + print(f'Writing frame {i}') + frame = podio.Frame() + + header = edm4hep.EventHeaderCollection() + h = header.create() + h.setEventNumber(next(counter)) + h.setRunNumber(next(counter)) + h.setTimeStamp(next(counter)) + h.setWeight(1.0) + if not args.use_pre1: + for j in range(vectorsize): + h.addToWeights(next(counter)) + frame.put(header, "EventHeader") + + particles = edm4hep.MCParticleCollection() + parent_particle = particles.create() + parent_particle.setPDG(next(counter)) + parent_particle.setGeneratorStatus(next(counter)) + parent_particle.setSimulatorStatus(next(counter)) + parent_particle.setCharge(next(counter)) + parent_particle.setTime(next(counter)) + parent_particle.setMass(next(counter)) + parent_particle.setVertex(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + parent_particle.setEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + parent_particle.setMomentum(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + parent_particle.setMomentumAtEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + parent_particle.setSpin(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + parent_particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) + + daughter_particle = particles.create() + daughter_particle.setPDG(next(counter)) + daughter_particle.setGeneratorStatus(next(counter)) + daughter_particle.setSimulatorStatus(next(counter)) + daughter_particle.setCharge(next(counter)) + daughter_particle.setTime(next(counter)) + daughter_particle.setMass(next(counter)) + daughter_particle.setVertex(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + daughter_particle.setEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + daughter_particle.setMomentum(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + daughter_particle.setMomentumAtEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + daughter_particle.setSpin(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + daughter_particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) + + parent_particle.addToDaughters(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + daughter_particle.addToParents(cppyy.ll.static_cast['edm4hep::MCParticle'](parent_particle)) + frame.put(particles, "MCParticleCollection") + + hits = edm4hep.SimTrackerHitCollection() + hit = hits.create() + hit.setCellID(next(counter)) + hit.setEDep(next(counter)) + hit.setTime(next(counter)) + hit.setPathLength(next(counter)) + hit.setQuality(next(counter)) + hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + hit.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + hit.setParticle(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + simtracker_hit = hit + frame.put(hits, "SimTrackerHitCollection") + + hits = edm4hep.CaloHitContributionCollection() + hit = hits.create() + hit.setPDG(next(counter)) + hit.setEnergy(next(counter)) + hit.setTime(next(counter)) + hit.setStepPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + hit.setParticle(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + calohit = hit + frame.put(hits, "CaloHitContributionCollection") + + hits = edm4hep.SimCalorimeterHitCollection() + hit = hits.create() + hit.setCellID(next(counter)) + hit.setEnergy(next(counter)) + hit.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + hit.addToContributions(cppyy.ll.static_cast['edm4hep::CaloHitContribution'](calohit)) + simcalo_hit = hit + frame.put(hits, "SimCalorimeterHitCollection") + + hits = edm4hep.RawCalorimeterHitCollection() + hit = hits.create() + hit.setCellID(next(counter)) + hit.setAmplitude(next(counter)) + hit.setTimeStamp(next(counter)) + frame.put(hits, "RawCalorimeterHitCollection") + + hits = edm4hep.CalorimeterHitCollection() + hit = hits.create() + hit.setCellID(next(counter)) + hit.setEnergy(next(counter)) + hit.setEnergyError(next(counter)) + hit.setTime(next(counter)) + hit.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + hit.setType(next(counter)) + calo_hit = hit + frame.put(hits, "CalorimeterHitCollection") + + pids = edm4hep.ParticleIDCollection() + pid = pids.create() + pid.setType(next(counter)) + pid.setPDG(next(counter)) + pid.setAlgorithmType(next(counter)) + pid.setLikelihood(next(counter)) + for j in range(vectorsize): + pid.addToParameters(next(counter)) + frame.put(pids, "ParticleIDCollection") + + clusters = edm4hep.ClusterCollection() + cluster = clusters.create() + cluster.setType(next(counter)) + cluster.setEnergy(next(counter)) + cluster.setEnergyError(next(counter)) + cluster.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + for j in range(6): + cluster.setPositionError(j, next(counter)) + cluster.setITheta(next(counter)) + cluster.setPhi(next(counter)) + cluster.setDirectionError(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + for j in range(vectorsize): + cluster.addToShapeParameters(next(counter)) + for j in range(vectorsize): + cluster.addToSubdetectorEnergies(next(counter)) + cluster.addToClusters(cppyy.ll.static_cast['edm4hep::Cluster'](cluster)) + cluster.addToHits(cppyy.ll.static_cast['edm4hep::CalorimeterHit'](calo_hit)) + if args.use_pre1: + cluster.addToParticleIDs(cppyy.ll.static_cast['edm4hep::ParticleID'](pid)) + frame.put(clusters, "ClusterCollection") + + if args.use_pre1: + hits = edm4hep.TrackerHitCollection() + else: + hits = edm4hep.TrackerHit3DCollection() + hit = hits.create() + hit.setCellID(next(counter)) + hit.setType(next(counter)) + hit.setQuality(next(counter)) + hit.setTime(next(counter)) + hit.setEDep(next(counter)) + hit.setEDepError(next(counter)) + hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + hit.setCovMatrix(j, next(counter)) + if args.use_pre1: + for j in range(vectorsize): + oid = edm4hep.ObjectID() + oid.index = next(counter) + oid.collectionID = next(counter) + hit.addToRawHits(oid) + tracker_hit = hit + frame.put(hits, "TrackerHit3DCollection") + + hits = edm4hep.TrackerHitPlaneCollection() + hit = hits.create() + hit.setCellID(next(counter)) + hit.setType(next(counter)) + hit.setQuality(next(counter)) + hit.setTime(next(counter)) + hit.setEDep(next(counter)) + hit.setEDepError(next(counter)) + hit.setU(edm4hep.Vector2f(next(counter), next(counter))) + hit.setV(edm4hep.Vector2f(next(counter), next(counter))) + hit.setDu(next(counter)) + hit.setDv(next(counter)) + hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + for j in range(6): + hit.setCovMatrix(j, next(counter)) + if args.use_pre1: + for j in range(vectorsize): + oid = edm4hep.ObjectID() + oid.index = next(counter) + oid.collectionID = next(counter) + hit.addToRawHits(oid) + frame.put(hits, "TrackerHitPlaneCollection") + + series = edm4hep.RawTimeSeriesCollection() + serie = series.create() + serie.setCellID(next(counter)) + serie.setQuality(next(counter)) + serie.setTime(next(counter)) + serie.setCharge(next(counter)) + serie.setInterval(next(counter)) + for j in range(vectorsize): + serie.addToAdcCounts(next(counter)) + frame.put(series, "RawTimeSeriesCollection") + + tracks = edm4hep.TrackCollection() + track = tracks.create() + track.setType(next(counter)) + track.setChi2(next(counter)) + track.setNdf(next(counter)) + track.setDEdx(next(counter)) + track.setDEdxError(next(counter)) + track.setRadiusOfInnermostHit(next(counter)) + for j in range(vectorsize): + track.addToSubdetectorHitNumbers(next(counter)) + for j in range(vectorsize): + state = edm4hep.TrackState() + state.location = next(counter) + state.d0 = next(counter) + state.phi = next(counter) + state.omega = next(counter) + state.z0 = next(counter) + state.tanLambda = next(counter) + state.time = next(counter) + state.referencePoint = edm4hep.Vector3f(next(counter), next(counter), next(counter)) + # TODO + # for k in range(21): + # state.setCovMatrix(k, next(counter)) + track.addToTrackStates(state) + track.addToTrackerHits(cppyy.ll.static_cast['edm4hep::TrackerHit3D'](tracker_hit)) + track.addToTracks(cppyy.ll.static_cast['edm4hep::Track'](track)) + frame.put(tracks, "TrackCollection") + + vertex = edm4hep.VertexCollection() + v = vertex.create() + v.setPrimary(next(counter)) + v.setChi2(next(counter)) + v.setProbability(next(counter)) + v.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + for j in range(6): + v.setCovMatrix(j, next(counter)) + v.setAlgorithmType(next(counter)) + for j in range(vectorsize): + v.addToParameters(next(counter)) + + particles = edm4hep.ReconstructedParticleCollection() + particle = particles.create() + particle.setType(next(counter)) + particle.setEnergy(next(counter)) + particle.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + particle.setReferencePoint(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + particle.setCharge(next(counter)) + particle.setMass(next(counter)) + particle.setGoodnessOfPID(next(counter)) + for j in range(10): + particle.setCovMatrix(j, next(counter)) + particle.setStartVertex(cppyy.ll.static_cast['edm4hep::Vertex'](v)) + if args.use_pre1: + particle.setParticleIDUsed(cppyy.ll.static_cast['edm4hep::ParticleID'](pid)) + particle.addToClusters(cppyy.ll.static_cast['edm4hep::Cluster'](cluster)) + particle.addToTracks(cppyy.ll.static_cast['edm4hep::Track'](track)) + particle.addToParticles(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](particle)) + if args.use_pre1: + particle.addToParticleIDs(cppyy.ll.static_cast['edm4hep::ParticleID'](pid)) + reco_particle = particle + + # Vertex needs particles and particles needs vertex + v.setAssociatedParticle(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](reco_particle)) + frame.put(vertex, "VertexCollection") + frame.put(particles, "ReconstructedParticleCollection") + + if not args.use_pre1: + pid.setParticle(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](reco_particle)) + + assocs = edm4hep.MCRecoParticleAssociationCollection() + assoc = assocs.create() + assoc.setWeight(next(counter)) + assoc.setRec(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](reco_particle)) + assoc.setSim(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + frame.put(assocs, "MCRecoParticleAssociationCollection") + + assocs = edm4hep.MCRecoCaloAssociationCollection() + assoc = assocs.create() + assoc.setWeight(next(counter)) + assoc.setRec(cppyy.ll.static_cast['edm4hep::CalorimeterHit'](calo_hit)) + assoc.setSim(cppyy.ll.static_cast['edm4hep::SimCalorimeterHit'](simcalo_hit)) + frame.put(assocs, "MCRecoCaloAssociationCollection") + + assocs = edm4hep.MCRecoTrackerAssociationCollection() + assoc = assocs.create() + assoc.setWeight(next(counter)) + assoc.setRec(cppyy.ll.static_cast['edm4hep::TrackerHit3D'](tracker_hit)) + assoc.setSim(cppyy.ll.static_cast['edm4hep::SimTrackerHit'](simtracker_hit)) + frame.put(assocs, "MCRecoTrackerAssociationCollection") + + assocs = edm4hep.MCRecoCaloParticleAssociationCollection() + assoc = assocs.create() + assoc.setWeight(next(counter)) + assoc.setRec(cppyy.ll.static_cast['edm4hep::CalorimeterHit'](calo_hit)) + assoc.setSim(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + frame.put(assocs, "MCRecoCaloParticleAssociationCollection") + + assocs = edm4hep.MCRecoClusterParticleAssociationCollection() + assoc = assocs.create() + assoc.setWeight(next(counter)) + assoc.setRec(cppyy.ll.static_cast['edm4hep::Cluster'](cluster)) + assoc.setSim(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + frame.put(assocs, "MCRecoClusterParticleAssociationCollection") + + assocs = edm4hep.MCRecoTrackParticleAssociationCollection() + assoc = assocs.create() + assoc.setWeight(next(counter)) + assoc.setRec(cppyy.ll.static_cast['edm4hep::Track'](track)) + assoc.setSim(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + frame.put(assocs, "MCRecoTrackParticleAssociationCollection") + + assocs = edm4hep.RecoParticleVertexAssociationCollection() + assoc = assocs.create() + assoc.setWeight(next(counter)) + assoc.setRec(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](reco_particle)) + assoc.setVertex(cppyy.ll.static_cast['edm4hep::Vertex'](v)) + frame.put(assocs, "MCRecoParticleVertexAssociationCollection") + + simiocluster = edm4hep.SimPrimaryIonizationClusterCollection() + cluster = simiocluster.create() + cluster.setCellID(next(counter)) + cluster.setTime(next(counter)) + cluster.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + cluster.setType(next(counter)) + for j in range(vectorsize): + cluster.addToElectronCellID(next(counter)) + cluster.addToElectronTime(next(counter)) + cluster.addToElectronPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + cluster.addToPulseTime(next(counter)) + cluster.addToPulseAmplitude(next(counter)) + cluster.setParticle(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + frame.put(simiocluster, "SimPrimaryIonizationClusterCollection") + + timeseries = edm4hep.TimeSeriesCollection() + serie = timeseries.create() + serie.setCellID(next(counter)) + serie.setTime(next(counter)) + serie.setInterval(next(counter)) + for j in range(vectorsize): + serie.addToAmplitude(next(counter)) + frame.put(timeseries, "TimeSeriesCollection") + + trackerpulse = edm4hep.TrackerPulseCollection() + pulse = trackerpulse.create() + pulse.setCellID(next(counter)) + pulse.setTime(next(counter)) + pulse.setCharge(next(counter)) + pulse.setQuality(next(counter)) + for j in range(3): + pulse.setCovMatrix(j, next(counter)) + pulse.setTimeSeries(cppyy.ll.static_cast['edm4hep::TimeSeries'](serie)) + frame.put(trackerpulse, "TrackerPulseCollection") + + recioncluster = edm4hep.RecIonizationClusterCollection() + cluster = recioncluster.create() + cluster.setCellID(next(counter)) + cluster.setSignificance(next(counter)) + cluster.setType(next(counter)) + cluster.addToTrackerPulse(cppyy.ll.static_cast['edm4hep::TrackerPulse'](pulse)) + frame.put(recioncluster, "RecIonizationClusterCollection") + + recdqdx = edm4hep.RecDqdxCollection() + dqdx = recdqdx.create() + dqdx.setParticleType(next(counter)) + dqdx.setType(next(counter)) + for j in range(5): + h = edm4hep.Hypothesis() + h.chi2 = next(counter) + h.expected = next(counter) + h.sigma = next(counter) + dqdx.setHypotheses(j, h) + for j in range(vectorsize): + hd = edm4hep.HitLevelData() + hd.cellID = next(counter) + hd.N = next(counter) + hd.eDep = next(counter) + hd.pathLength = next(counter) + dqdx.addToHitData(hd) + dqdx.setTrack(cppyy.ll.static_cast['edm4hep::Track'](track)) + frame.put(recdqdx, "RecDqdxCollection") + + writer.write_frame(frame, "events") From 33fda00355768cd4dd1141cdb15f8d1849bc32bd Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 21 Feb 2024 14:33:18 +0100 Subject: [PATCH 02/23] Add a comment --- scripts/createEDM4hepFile.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 99feb05c6..2fd5bedbb 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -6,7 +6,7 @@ frames = 10 vectorsize = 5 -counter = count() +counter = count() # next(counter) will return 0, 1, 2, ... parser = argparse.ArgumentParser(description='Create a file with EDM4hep data') parser.add_argument('--use-pre1', action='store_true', help='Use a pre 1.0 version of EDM4hep') @@ -238,6 +238,7 @@ v.setAlgorithmType(next(counter)) for j in range(vectorsize): v.addToParameters(next(counter)) + frame.put(vertex, "VertexCollection") particles = edm4hep.ReconstructedParticleCollection() particle = particles.create() @@ -259,11 +260,9 @@ if args.use_pre1: particle.addToParticleIDs(cppyy.ll.static_cast['edm4hep::ParticleID'](pid)) reco_particle = particle + frame.put(particles, "ReconstructedParticleCollection") - # Vertex needs particles and particles needs vertex v.setAssociatedParticle(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](reco_particle)) - frame.put(vertex, "VertexCollection") - frame.put(particles, "ReconstructedParticleCollection") if not args.use_pre1: pid.setParticle(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](reco_particle)) From 22c020198ec0a541b12459ffc17008dbed4b8bc0 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 21 Feb 2024 14:58:02 +0100 Subject: [PATCH 03/23] Add a few comments and fix warnings related to Vector3d --- scripts/createEDM4hepFile.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 2fd5bedbb..039ce63fa 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -1,18 +1,23 @@ +# Description: Create a file with EDM4hep data using the EDM4hep python bindings +# The purpose of the script is to use all the classes of the EDM4hep library +# to create a file with dummy data. import podio import edm4hep import cppyy.ll from itertools import count import argparse -frames = 10 -vectorsize = 5 +frames = 10 # 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('--use-pre1', action='store_true', help='Use a pre 1.0 version of EDM4hep') args = parser.parse_args() -writer = podio.root_io.Writer("output.root") +writer = podio.root_io.Writer(output_file) for i in range(frames): print(f'Writing frame {i}') @@ -39,8 +44,12 @@ parent_particle.setMass(next(counter)) parent_particle.setVertex(edm4hep.Vector3d(next(counter), next(counter), next(counter))) parent_particle.setEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - parent_particle.setMomentum(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - parent_particle.setMomentumAtEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + if not args.use_pre1: + parent_particle.setMomentum(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + parent_particle.setMomentumAtEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + else: + parent_particle.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + parent_particle.setMomentumAtEndpoint(edm4hep.Vector3f(next(counter), next(counter), next(counter))) parent_particle.setSpin(edm4hep.Vector3f(next(counter), next(counter), next(counter))) parent_particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) @@ -53,8 +62,12 @@ daughter_particle.setMass(next(counter)) daughter_particle.setVertex(edm4hep.Vector3d(next(counter), next(counter), next(counter))) daughter_particle.setEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - daughter_particle.setMomentum(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - daughter_particle.setMomentumAtEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + if not args.use_pre1: + daughter_particle.setMomentum(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + daughter_particle.setMomentumAtEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + else: + daughter_particle.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + daughter_particle.setMomentumAtEndpoint(edm4hep.Vector3f(next(counter), next(counter), next(counter))) daughter_particle.setSpin(edm4hep.Vector3f(next(counter), next(counter), next(counter))) daughter_particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) @@ -320,12 +333,12 @@ cluster = simiocluster.create() cluster.setCellID(next(counter)) cluster.setTime(next(counter)) - cluster.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + cluster.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) cluster.setType(next(counter)) for j in range(vectorsize): cluster.addToElectronCellID(next(counter)) cluster.addToElectronTime(next(counter)) - cluster.addToElectronPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + cluster.addToElectronPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) cluster.addToPulseTime(next(counter)) cluster.addToPulseAmplitude(next(counter)) cluster.setParticle(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) From 32ad7f9720ae0f345f1a1fcc2f38009a63dd2101 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 21 Feb 2024 18:41:41 +0100 Subject: [PATCH 04/23] Add an rntuple option --- scripts/createEDM4hepFile.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 039ce63fa..2e41b8155 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -6,6 +6,7 @@ import cppyy.ll from itertools import count import argparse +import sys frames = 10 # How many frames or events will be written vectorsize = 5 # For vector members, each vector member will have this size @@ -15,8 +16,19 @@ parser = argparse.ArgumentParser(description='Create a file with EDM4hep data') parser.add_argument('--use-pre1', action='store_true', help='Use a pre 1.0 version of EDM4hep') +parser.add_argument('--rntuple', action='store_true', help='Use a ROOT ntuple instead of EDM4hep') args = parser.parse_args() +if args.rntuple: + try: + writer = podio.root_io.ROOTNTupleWriter(output_file) + except AttributeError: + writer = podio.root_io.ROOTRNTupleWriter(output_file) + except AttributeError: + print('The RNTuple writer from podio is not available but was requested') + sys.exit(1) + + writer = podio.root_io.Writer(output_file) for i in range(frames): From d86f7d031de57c8d1d63e77638998ca52bca7ded Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 21 Feb 2024 18:43:53 +0100 Subject: [PATCH 05/23] Fix the RNTuple names --- scripts/createEDM4hepFile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 2e41b8155..489dfa143 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -21,9 +21,7 @@ if args.rntuple: try: - writer = podio.root_io.ROOTNTupleWriter(output_file) - except AttributeError: - writer = podio.root_io.ROOTRNTupleWriter(output_file) + writer = podio.root_io.RNTupleWriter(output_file) except AttributeError: print('The RNTuple writer from podio is not available but was requested') sys.exit(1) From b2823d382892207b091d28cbd27f22450b70dd7f Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 21 Feb 2024 19:12:20 +0100 Subject: [PATCH 06/23] Format --- scripts/createEDM4hepFile.py | 184 ++++++++++++++++++++++------------- 1 file changed, 118 insertions(+), 66 deletions(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 489dfa143..dccd3f636 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -8,29 +8,33 @@ import argparse import sys -frames = 10 # 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 +frames = 10 # 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('--use-pre1', action='store_true', help='Use a pre 1.0 version of EDM4hep') -parser.add_argument('--rntuple', action='store_true', help='Use a ROOT ntuple instead of EDM4hep') +parser = argparse.ArgumentParser(description="Create a file with EDM4hep data") +parser.add_argument( + "--use-pre1", action="store_true", help="Use a pre 1.0 version of EDM4hep" +) +parser.add_argument( + "--rntuple", action="store_true", help="Use a ROOT ntuple instead of EDM4hep" +) args = parser.parse_args() if args.rntuple: try: writer = podio.root_io.RNTupleWriter(output_file) except AttributeError: - print('The RNTuple writer from podio is not available but was requested') + print("The RNTuple writer from podio is not available but was requested") sys.exit(1) writer = podio.root_io.Writer(output_file) for i in range(frames): - print(f'Writing frame {i}') + print(f"Writing frame {i}") frame = podio.Frame() header = edm4hep.EventHeaderCollection() @@ -52,15 +56,29 @@ parent_particle.setCharge(next(counter)) parent_particle.setTime(next(counter)) parent_particle.setMass(next(counter)) - parent_particle.setVertex(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - parent_particle.setEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + parent_particle.setVertex( + edm4hep.Vector3d(next(counter), next(counter), next(counter)) + ) + parent_particle.setEndpoint( + edm4hep.Vector3d(next(counter), next(counter), next(counter)) + ) if not args.use_pre1: - parent_particle.setMomentum(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - parent_particle.setMomentumAtEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + parent_particle.setMomentum( + edm4hep.Vector3d(next(counter), next(counter), next(counter)) + ) + parent_particle.setMomentumAtEndpoint( + edm4hep.Vector3d(next(counter), next(counter), next(counter)) + ) else: - parent_particle.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - parent_particle.setMomentumAtEndpoint(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - parent_particle.setSpin(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + parent_particle.setMomentum( + edm4hep.Vector3f(next(counter), next(counter), next(counter)) + ) + parent_particle.setMomentumAtEndpoint( + edm4hep.Vector3f(next(counter), next(counter), next(counter)) + ) + parent_particle.setSpin( + edm4hep.Vector3f(next(counter), next(counter), next(counter)) + ) parent_particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) daughter_particle = particles.create() @@ -70,19 +88,37 @@ daughter_particle.setCharge(next(counter)) daughter_particle.setTime(next(counter)) daughter_particle.setMass(next(counter)) - daughter_particle.setVertex(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - daughter_particle.setEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + daughter_particle.setVertex( + edm4hep.Vector3d(next(counter), next(counter), next(counter)) + ) + daughter_particle.setEndpoint( + edm4hep.Vector3d(next(counter), next(counter), next(counter)) + ) if not args.use_pre1: - daughter_particle.setMomentum(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - daughter_particle.setMomentumAtEndpoint(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + daughter_particle.setMomentum( + edm4hep.Vector3d(next(counter), next(counter), next(counter)) + ) + daughter_particle.setMomentumAtEndpoint( + edm4hep.Vector3d(next(counter), next(counter), next(counter)) + ) else: - daughter_particle.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - daughter_particle.setMomentumAtEndpoint(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - daughter_particle.setSpin(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + daughter_particle.setMomentum( + edm4hep.Vector3f(next(counter), next(counter), next(counter)) + ) + daughter_particle.setMomentumAtEndpoint( + edm4hep.Vector3f(next(counter), next(counter), next(counter)) + ) + daughter_particle.setSpin( + edm4hep.Vector3f(next(counter), next(counter), next(counter)) + ) daughter_particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) - - parent_particle.addToDaughters(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) - daughter_particle.addToParents(cppyy.ll.static_cast['edm4hep::MCParticle'](parent_particle)) + + parent_particle.addToDaughters( + cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle) + ) + daughter_particle.addToParents( + cppyy.ll.static_cast["edm4hep::MCParticle"](parent_particle) + ) frame.put(particles, "MCParticleCollection") hits = edm4hep.SimTrackerHitCollection() @@ -94,7 +130,7 @@ hit.setQuality(next(counter)) hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) hit.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - hit.setParticle(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + hit.setParticle(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) simtracker_hit = hit frame.put(hits, "SimTrackerHitCollection") @@ -104,7 +140,7 @@ hit.setEnergy(next(counter)) hit.setTime(next(counter)) hit.setStepPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - hit.setParticle(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + hit.setParticle(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) calohit = hit frame.put(hits, "CaloHitContributionCollection") @@ -113,7 +149,9 @@ hit.setCellID(next(counter)) hit.setEnergy(next(counter)) hit.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - hit.addToContributions(cppyy.ll.static_cast['edm4hep::CaloHitContribution'](calohit)) + hit.addToContributions( + cppyy.ll.static_cast["edm4hep::CaloHitContribution"](calohit) + ) simcalo_hit = hit frame.put(hits, "SimCalorimeterHitCollection") @@ -155,15 +193,17 @@ cluster.setPositionError(j, next(counter)) cluster.setITheta(next(counter)) cluster.setPhi(next(counter)) - cluster.setDirectionError(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + cluster.setDirectionError( + edm4hep.Vector3f(next(counter), next(counter), next(counter)) + ) for j in range(vectorsize): cluster.addToShapeParameters(next(counter)) for j in range(vectorsize): cluster.addToSubdetectorEnergies(next(counter)) - cluster.addToClusters(cppyy.ll.static_cast['edm4hep::Cluster'](cluster)) - cluster.addToHits(cppyy.ll.static_cast['edm4hep::CalorimeterHit'](calo_hit)) + cluster.addToClusters(cppyy.ll.static_cast["edm4hep::Cluster"](cluster)) + cluster.addToHits(cppyy.ll.static_cast["edm4hep::CalorimeterHit"](calo_hit)) if args.use_pre1: - cluster.addToParticleIDs(cppyy.ll.static_cast['edm4hep::ParticleID'](pid)) + cluster.addToParticleIDs(cppyy.ll.static_cast["edm4hep::ParticleID"](pid)) frame.put(clusters, "ClusterCollection") if args.use_pre1: @@ -241,13 +281,15 @@ state.z0 = next(counter) state.tanLambda = next(counter) state.time = next(counter) - state.referencePoint = edm4hep.Vector3f(next(counter), next(counter), next(counter)) + state.referencePoint = edm4hep.Vector3f( + next(counter), next(counter), next(counter) + ) # TODO # for k in range(21): # state.setCovMatrix(k, next(counter)) track.addToTrackStates(state) - track.addToTrackerHits(cppyy.ll.static_cast['edm4hep::TrackerHit3D'](tracker_hit)) - track.addToTracks(cppyy.ll.static_cast['edm4hep::Track'](track)) + track.addToTrackerHits(cppyy.ll.static_cast["edm4hep::TrackerHit3D"](tracker_hit)) + track.addToTracks(cppyy.ll.static_cast["edm4hep::Track"](track)) frame.put(tracks, "TrackCollection") vertex = edm4hep.VertexCollection() @@ -268,75 +310,83 @@ particle.setType(next(counter)) particle.setEnergy(next(counter)) particle.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - particle.setReferencePoint(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + particle.setReferencePoint( + edm4hep.Vector3f(next(counter), next(counter), next(counter)) + ) particle.setCharge(next(counter)) particle.setMass(next(counter)) particle.setGoodnessOfPID(next(counter)) for j in range(10): particle.setCovMatrix(j, next(counter)) - particle.setStartVertex(cppyy.ll.static_cast['edm4hep::Vertex'](v)) + particle.setStartVertex(cppyy.ll.static_cast["edm4hep::Vertex"](v)) if args.use_pre1: - particle.setParticleIDUsed(cppyy.ll.static_cast['edm4hep::ParticleID'](pid)) - particle.addToClusters(cppyy.ll.static_cast['edm4hep::Cluster'](cluster)) - particle.addToTracks(cppyy.ll.static_cast['edm4hep::Track'](track)) - particle.addToParticles(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](particle)) + particle.setParticleIDUsed(cppyy.ll.static_cast["edm4hep::ParticleID"](pid)) + particle.addToClusters(cppyy.ll.static_cast["edm4hep::Cluster"](cluster)) + particle.addToTracks(cppyy.ll.static_cast["edm4hep::Track"](track)) + particle.addToParticles( + cppyy.ll.static_cast["edm4hep::ReconstructedParticle"](particle) + ) if args.use_pre1: - particle.addToParticleIDs(cppyy.ll.static_cast['edm4hep::ParticleID'](pid)) + particle.addToParticleIDs(cppyy.ll.static_cast["edm4hep::ParticleID"](pid)) reco_particle = particle frame.put(particles, "ReconstructedParticleCollection") - v.setAssociatedParticle(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](reco_particle)) + v.setAssociatedParticle( + cppyy.ll.static_cast["edm4hep::ReconstructedParticle"](reco_particle) + ) if not args.use_pre1: - pid.setParticle(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](reco_particle)) + pid.setParticle( + cppyy.ll.static_cast["edm4hep::ReconstructedParticle"](reco_particle) + ) assocs = edm4hep.MCRecoParticleAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](reco_particle)) - assoc.setSim(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + assoc.setRec(cppyy.ll.static_cast["edm4hep::ReconstructedParticle"](reco_particle)) + assoc.setSim(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) frame.put(assocs, "MCRecoParticleAssociationCollection") assocs = edm4hep.MCRecoCaloAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast['edm4hep::CalorimeterHit'](calo_hit)) - assoc.setSim(cppyy.ll.static_cast['edm4hep::SimCalorimeterHit'](simcalo_hit)) + assoc.setRec(cppyy.ll.static_cast["edm4hep::CalorimeterHit"](calo_hit)) + assoc.setSim(cppyy.ll.static_cast["edm4hep::SimCalorimeterHit"](simcalo_hit)) frame.put(assocs, "MCRecoCaloAssociationCollection") assocs = edm4hep.MCRecoTrackerAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast['edm4hep::TrackerHit3D'](tracker_hit)) - assoc.setSim(cppyy.ll.static_cast['edm4hep::SimTrackerHit'](simtracker_hit)) + assoc.setRec(cppyy.ll.static_cast["edm4hep::TrackerHit3D"](tracker_hit)) + assoc.setSim(cppyy.ll.static_cast["edm4hep::SimTrackerHit"](simtracker_hit)) frame.put(assocs, "MCRecoTrackerAssociationCollection") - + assocs = edm4hep.MCRecoCaloParticleAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast['edm4hep::CalorimeterHit'](calo_hit)) - assoc.setSim(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + assoc.setRec(cppyy.ll.static_cast["edm4hep::CalorimeterHit"](calo_hit)) + assoc.setSim(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) frame.put(assocs, "MCRecoCaloParticleAssociationCollection") assocs = edm4hep.MCRecoClusterParticleAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast['edm4hep::Cluster'](cluster)) - assoc.setSim(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + assoc.setRec(cppyy.ll.static_cast["edm4hep::Cluster"](cluster)) + assoc.setSim(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) frame.put(assocs, "MCRecoClusterParticleAssociationCollection") - + assocs = edm4hep.MCRecoTrackParticleAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast['edm4hep::Track'](track)) - assoc.setSim(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + assoc.setRec(cppyy.ll.static_cast["edm4hep::Track"](track)) + assoc.setSim(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) frame.put(assocs, "MCRecoTrackParticleAssociationCollection") assocs = edm4hep.RecoParticleVertexAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast['edm4hep::ReconstructedParticle'](reco_particle)) - assoc.setVertex(cppyy.ll.static_cast['edm4hep::Vertex'](v)) + assoc.setRec(cppyy.ll.static_cast["edm4hep::ReconstructedParticle"](reco_particle)) + assoc.setVertex(cppyy.ll.static_cast["edm4hep::Vertex"](v)) frame.put(assocs, "MCRecoParticleVertexAssociationCollection") simiocluster = edm4hep.SimPrimaryIonizationClusterCollection() @@ -348,10 +398,12 @@ for j in range(vectorsize): cluster.addToElectronCellID(next(counter)) cluster.addToElectronTime(next(counter)) - cluster.addToElectronPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) + cluster.addToElectronPosition( + edm4hep.Vector3d(next(counter), next(counter), next(counter)) + ) cluster.addToPulseTime(next(counter)) cluster.addToPulseAmplitude(next(counter)) - cluster.setParticle(cppyy.ll.static_cast['edm4hep::MCParticle'](daughter_particle)) + cluster.setParticle(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) frame.put(simiocluster, "SimPrimaryIonizationClusterCollection") timeseries = edm4hep.TimeSeriesCollection() @@ -371,7 +423,7 @@ pulse.setQuality(next(counter)) for j in range(3): pulse.setCovMatrix(j, next(counter)) - pulse.setTimeSeries(cppyy.ll.static_cast['edm4hep::TimeSeries'](serie)) + pulse.setTimeSeries(cppyy.ll.static_cast["edm4hep::TimeSeries"](serie)) frame.put(trackerpulse, "TrackerPulseCollection") recioncluster = edm4hep.RecIonizationClusterCollection() @@ -379,7 +431,7 @@ cluster.setCellID(next(counter)) cluster.setSignificance(next(counter)) cluster.setType(next(counter)) - cluster.addToTrackerPulse(cppyy.ll.static_cast['edm4hep::TrackerPulse'](pulse)) + cluster.addToTrackerPulse(cppyy.ll.static_cast["edm4hep::TrackerPulse"](pulse)) frame.put(recioncluster, "RecIonizationClusterCollection") recdqdx = edm4hep.RecDqdxCollection() @@ -399,7 +451,7 @@ hd.eDep = next(counter) hd.pathLength = next(counter) dqdx.addToHitData(hd) - dqdx.setTrack(cppyy.ll.static_cast['edm4hep::Track'](track)) + dqdx.setTrack(cppyy.ll.static_cast["edm4hep::Track"](track)) frame.put(recdqdx, "RecDqdxCollection") writer.write_frame(frame, "events") From d5e3d4aca6466fe4070fb5bf35153b0664e97d96 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 22 Feb 2024 21:38:52 +0100 Subject: [PATCH 07/23] Update script with the Type -> PDG rename --- scripts/createEDM4hepFile.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index dccd3f636..e43cad436 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -307,7 +307,10 @@ particles = edm4hep.ReconstructedParticleCollection() particle = particles.create() - particle.setType(next(counter)) + if args.use_pre1: + particle.setType(next(counter)) + else: + particle.setPDG(next(counter)) particle.setEnergy(next(counter)) particle.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) particle.setReferencePoint( From 2d1b2f7f4f025bfbc7ec5a345e246df05aa1134d Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 25 Feb 2024 09:55:24 +0100 Subject: [PATCH 08/23] Remove casts --- scripts/createEDM4hepFile.py | 87 ++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 49 deletions(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index e43cad436..0ceb13b26 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -113,12 +113,8 @@ ) daughter_particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) - parent_particle.addToDaughters( - cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle) - ) - daughter_particle.addToParents( - cppyy.ll.static_cast["edm4hep::MCParticle"](parent_particle) - ) + parent_particle.addToDaughters(daughter_particle) + daughter_particle.addToParents(parent_particle) frame.put(particles, "MCParticleCollection") hits = edm4hep.SimTrackerHitCollection() @@ -130,7 +126,7 @@ hit.setQuality(next(counter)) hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) hit.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - hit.setParticle(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) + hit.setParticle(daughter_particle) simtracker_hit = hit frame.put(hits, "SimTrackerHitCollection") @@ -140,7 +136,7 @@ hit.setEnergy(next(counter)) hit.setTime(next(counter)) hit.setStepPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - hit.setParticle(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) + hit.setParticle(daughter_particle) calohit = hit frame.put(hits, "CaloHitContributionCollection") @@ -149,9 +145,7 @@ hit.setCellID(next(counter)) hit.setEnergy(next(counter)) hit.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - hit.addToContributions( - cppyy.ll.static_cast["edm4hep::CaloHitContribution"](calohit) - ) + hit.addToContributions(calohit) simcalo_hit = hit frame.put(hits, "SimCalorimeterHitCollection") @@ -200,10 +194,10 @@ cluster.addToShapeParameters(next(counter)) for j in range(vectorsize): cluster.addToSubdetectorEnergies(next(counter)) - cluster.addToClusters(cppyy.ll.static_cast["edm4hep::Cluster"](cluster)) - cluster.addToHits(cppyy.ll.static_cast["edm4hep::CalorimeterHit"](calo_hit)) + cluster.addToClusters(cluster) + cluster.addToHits(calo_hit) if args.use_pre1: - cluster.addToParticleIDs(cppyy.ll.static_cast["edm4hep::ParticleID"](pid)) + cluster.addToParticleIDs(pid) frame.put(clusters, "ClusterCollection") if args.use_pre1: @@ -288,8 +282,8 @@ # for k in range(21): # state.setCovMatrix(k, next(counter)) track.addToTrackStates(state) - track.addToTrackerHits(cppyy.ll.static_cast["edm4hep::TrackerHit3D"](tracker_hit)) - track.addToTracks(cppyy.ll.static_cast["edm4hep::Track"](track)) + track.addToTrackerHits(tracker_hit) + track.addToTracks(track) frame.put(tracks, "TrackCollection") vertex = edm4hep.VertexCollection() @@ -321,75 +315,70 @@ particle.setGoodnessOfPID(next(counter)) for j in range(10): particle.setCovMatrix(j, next(counter)) - particle.setStartVertex(cppyy.ll.static_cast["edm4hep::Vertex"](v)) + particle.setStartVertex(v) if args.use_pre1: - particle.setParticleIDUsed(cppyy.ll.static_cast["edm4hep::ParticleID"](pid)) - particle.addToClusters(cppyy.ll.static_cast["edm4hep::Cluster"](cluster)) - particle.addToTracks(cppyy.ll.static_cast["edm4hep::Track"](track)) - particle.addToParticles( - cppyy.ll.static_cast["edm4hep::ReconstructedParticle"](particle) - ) + particle.setParticleIDUsed(pid) + particle.addToClusters(cluster) + particle.addToTracks(track) + particle.addToParticles(particle) if args.use_pre1: - particle.addToParticleIDs(cppyy.ll.static_cast["edm4hep::ParticleID"](pid)) + particle.addToParticleIDs(pid) reco_particle = particle frame.put(particles, "ReconstructedParticleCollection") - v.setAssociatedParticle( - cppyy.ll.static_cast["edm4hep::ReconstructedParticle"](reco_particle) - ) + v.setAssociatedParticle(reco_particle) - if not args.use_pre1: - pid.setParticle( - cppyy.ll.static_cast["edm4hep::ReconstructedParticle"](reco_particle) - ) + # TODO: Add when the PID PR is merged + # if not args.use_pre1: + # pid.setParticle(reco_particle) assocs = edm4hep.MCRecoParticleAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast["edm4hep::ReconstructedParticle"](reco_particle)) - assoc.setSim(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) + assoc.setRec(reco_particle) + assoc.setSim(daughter_particle) frame.put(assocs, "MCRecoParticleAssociationCollection") assocs = edm4hep.MCRecoCaloAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast["edm4hep::CalorimeterHit"](calo_hit)) - assoc.setSim(cppyy.ll.static_cast["edm4hep::SimCalorimeterHit"](simcalo_hit)) + assoc.setRec(calo_hit) + assoc.setSim(simcalo_hit) frame.put(assocs, "MCRecoCaloAssociationCollection") assocs = edm4hep.MCRecoTrackerAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast["edm4hep::TrackerHit3D"](tracker_hit)) - assoc.setSim(cppyy.ll.static_cast["edm4hep::SimTrackerHit"](simtracker_hit)) + assoc.setRec(tracker_hit) + assoc.setSim(simtracker_hit) frame.put(assocs, "MCRecoTrackerAssociationCollection") assocs = edm4hep.MCRecoCaloParticleAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast["edm4hep::CalorimeterHit"](calo_hit)) - assoc.setSim(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) + assoc.setRec(calo_hit) + assoc.setSim(daughter_particle) frame.put(assocs, "MCRecoCaloParticleAssociationCollection") assocs = edm4hep.MCRecoClusterParticleAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast["edm4hep::Cluster"](cluster)) - assoc.setSim(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) + assoc.setRec(cluster) + assoc.setSim(daughter_particle) frame.put(assocs, "MCRecoClusterParticleAssociationCollection") assocs = edm4hep.MCRecoTrackParticleAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast["edm4hep::Track"](track)) - assoc.setSim(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) + assoc.setRec(track) + assoc.setSim(daughter_particle) frame.put(assocs, "MCRecoTrackParticleAssociationCollection") assocs = edm4hep.RecoParticleVertexAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) - assoc.setRec(cppyy.ll.static_cast["edm4hep::ReconstructedParticle"](reco_particle)) - assoc.setVertex(cppyy.ll.static_cast["edm4hep::Vertex"](v)) + assoc.setRec(reco_particle) + assoc.setVertex(v) frame.put(assocs, "MCRecoParticleVertexAssociationCollection") simiocluster = edm4hep.SimPrimaryIonizationClusterCollection() @@ -406,7 +395,7 @@ ) cluster.addToPulseTime(next(counter)) cluster.addToPulseAmplitude(next(counter)) - cluster.setParticle(cppyy.ll.static_cast["edm4hep::MCParticle"](daughter_particle)) + cluster.setParticle(daughter_particle) frame.put(simiocluster, "SimPrimaryIonizationClusterCollection") timeseries = edm4hep.TimeSeriesCollection() @@ -426,7 +415,7 @@ pulse.setQuality(next(counter)) for j in range(3): pulse.setCovMatrix(j, next(counter)) - pulse.setTimeSeries(cppyy.ll.static_cast["edm4hep::TimeSeries"](serie)) + pulse.setTimeSeries(serie) frame.put(trackerpulse, "TrackerPulseCollection") recioncluster = edm4hep.RecIonizationClusterCollection() @@ -434,7 +423,7 @@ cluster.setCellID(next(counter)) cluster.setSignificance(next(counter)) cluster.setType(next(counter)) - cluster.addToTrackerPulse(cppyy.ll.static_cast["edm4hep::TrackerPulse"](pulse)) + cluster.addToTrackerPulse(pulse) frame.put(recioncluster, "RecIonizationClusterCollection") recdqdx = edm4hep.RecDqdxCollection() @@ -454,7 +443,7 @@ hd.eDep = next(counter) hd.pathLength = next(counter) dqdx.addToHitData(hd) - dqdx.setTrack(cppyy.ll.static_cast["edm4hep::Track"](track)) + dqdx.setTrack(track) frame.put(recdqdx, "RecDqdxCollection") writer.write_frame(frame, "events") From d3da24b9fad1e82dc3c2b568f2c61a312ae76471 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 25 Mar 2024 07:07:10 +0100 Subject: [PATCH 09/23] Update the script --- scripts/createEDM4hepFile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 0ceb13b26..736e8315a 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -3,7 +3,6 @@ # to create a file with dummy data. import podio import edm4hep -import cppyy.ll from itertools import count import argparse import sys From f6df9ff3a65d734e3dc2ae05708a1615b5bfef5f Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 26 Jun 2024 11:14:57 +0200 Subject: [PATCH 10/23] Update the covariance matrixes --- scripts/createEDM4hepFile.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 736e8315a..5a7731080 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -183,7 +183,7 @@ cluster.setEnergyError(next(counter)) cluster.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) for j in range(6): - cluster.setPositionError(j, next(counter)) + cluster.setPositionError([next(counter) for _ in range(6)]) cluster.setITheta(next(counter)) cluster.setPhi(next(counter)) cluster.setDirectionError( @@ -211,7 +211,7 @@ hit.setEDep(next(counter)) hit.setEDepError(next(counter)) hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - hit.setCovMatrix(j, next(counter)) + hit.setCovMatrix([next(counter) for _ in range(6)]) if args.use_pre1: for j in range(vectorsize): oid = edm4hep.ObjectID() @@ -234,8 +234,7 @@ hit.setDu(next(counter)) hit.setDv(next(counter)) hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - for j in range(6): - hit.setCovMatrix(j, next(counter)) + hit.setCovMatrix([next(counter) for _ in range(6)]) if args.use_pre1: for j in range(vectorsize): oid = edm4hep.ObjectID() @@ -277,9 +276,7 @@ state.referencePoint = edm4hep.Vector3f( next(counter), next(counter), next(counter) ) - # TODO - # for k in range(21): - # state.setCovMatrix(k, next(counter)) + # state.setCovMatrix([next(counter) for _ in range(21)]) track.addToTrackStates(state) track.addToTrackerHits(tracker_hit) track.addToTracks(track) @@ -291,8 +288,7 @@ v.setChi2(next(counter)) v.setProbability(next(counter)) v.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - for j in range(6): - v.setCovMatrix(j, next(counter)) + v.setCovMatrix([next(counter) for _ in range(6)]) v.setAlgorithmType(next(counter)) for j in range(vectorsize): v.addToParameters(next(counter)) @@ -312,8 +308,7 @@ particle.setCharge(next(counter)) particle.setMass(next(counter)) particle.setGoodnessOfPID(next(counter)) - for j in range(10): - particle.setCovMatrix(j, next(counter)) + particle.setCovMatrix([next(counter) for _ in range(10)]) particle.setStartVertex(v) if args.use_pre1: particle.setParticleIDUsed(pid) @@ -412,8 +407,7 @@ pulse.setTime(next(counter)) pulse.setCharge(next(counter)) pulse.setQuality(next(counter)) - for j in range(3): - pulse.setCovMatrix(j, next(counter)) + pulse.setCovMatrix([next(counter) for _ in range(3)]) pulse.setTimeSeries(serie) frame.put(trackerpulse, "TrackerPulseCollection") From 0529b492870acf06ad83ada952b5c20ed1580d20 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 26 Jun 2024 12:10:05 +0200 Subject: [PATCH 11/23] Fix all covmatrix setters --- scripts/createEDM4hepFile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 5a7731080..c7f211f9e 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -276,7 +276,7 @@ state.referencePoint = edm4hep.Vector3f( next(counter), next(counter), next(counter) ) - # state.setCovMatrix([next(counter) for _ in range(21)]) + state.CovMatrix = [next(counter) for _ in range(21)] track.addToTrackStates(state) track.addToTrackerHits(tracker_hit) track.addToTracks(track) From d7b196f7c8cb9bb34760f893bde41a7463316899 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 26 Jun 2024 15:44:36 +0200 Subject: [PATCH 12/23] Add a workflow to generate a file --- .github/workflows/generate-edm4hep-file.yaml | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/generate-edm4hep-file.yaml diff --git a/.github/workflows/generate-edm4hep-file.yaml b/.github/workflows/generate-edm4hep-file.yaml new file mode 100644 index 000000000..3007d05fc --- /dev/null +++ b/.github/workflows/generate-edm4hep-file.yaml @@ -0,0 +1,41 @@ +name: Generate an EDM4Hep file + +on: + pull_request: + workflow_dispatch: + +jobs: + generate-file: + runs-on: ubuntu-latest + steps: + - shell: bash + run: echo "NOW=$(date +'%Y-%m-%d')" >> $GITHUB_ENV + + - uses: actions/cache@v4 + with: + path: ~/.cache/ccache + key: nightly-alma9-${{ env.NOW }} + restore-keys: | + nightly-alma9 + + - name: Start container + shell: bash + run: | + docker run --name container --privileged -v ${GITHUB_WORKSPACE}:/${name} -v ~/.cache/ccache:/root/.cache/ccache -d ghcr.io/key4hep/key4hep-images/alma9-cvmfs tail -f /dev/null + + - name: Run script + run: | + source /cvmfs/sw-nightlies.hsf.org/key4hep/setup.sh + cd /EDM4hep + k4_local_repo + mkdir build + cd build + cmake .. -DCMAKE_CXX_STANDARD=20 -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -G Ninja + time ninja install + ccache -s + + python3 /EDM4hep/scripts/createEDM4hepFile.py + + chmod +x ${GITHUB_WORKSPACE}/script_container.sh + + docker exec container /bin/bash -c "/mount.sh && /${name}/script_container.sh" \ No newline at end of file From ffbdc3135f47e0d796e77c7f99f4a44d39bfa96d Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 26 Jun 2024 15:49:43 +0200 Subject: [PATCH 13/23] Fix path --- .github/workflows/generate-edm4hep-file.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-edm4hep-file.yaml b/.github/workflows/generate-edm4hep-file.yaml index 3007d05fc..24d20be27 100644 --- a/.github/workflows/generate-edm4hep-file.yaml +++ b/.github/workflows/generate-edm4hep-file.yaml @@ -21,7 +21,7 @@ jobs: - name: Start container shell: bash run: | - docker run --name container --privileged -v ${GITHUB_WORKSPACE}:/${name} -v ~/.cache/ccache:/root/.cache/ccache -d ghcr.io/key4hep/key4hep-images/alma9-cvmfs tail -f /dev/null + docker run --name container --privileged -v ${GITHUB_WORKSPACE}:/EDM4hep -v ~/.cache/ccache:/root/.cache/ccache -d ghcr.io/key4hep/key4hep-images/alma9-cvmfs tail -f /dev/null - name: Run script run: | From 9d482a114db10e0b141d628617fe6c8c56b44210 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 26 Jun 2024 15:54:57 +0200 Subject: [PATCH 14/23] Fix workflow --- .github/workflows/generate-edm4hep-file.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/generate-edm4hep-file.yaml b/.github/workflows/generate-edm4hep-file.yaml index 24d20be27..bd72e0d34 100644 --- a/.github/workflows/generate-edm4hep-file.yaml +++ b/.github/workflows/generate-edm4hep-file.yaml @@ -25,6 +25,8 @@ jobs: - name: Run script run: | + cat <<'EOF' > ${GITHUB_WORKSPACE}/script_container.sh + source /cvmfs/sw-nightlies.hsf.org/key4hep/setup.sh cd /EDM4hep k4_local_repo @@ -36,6 +38,8 @@ jobs: python3 /EDM4hep/scripts/createEDM4hepFile.py + EOF + chmod +x ${GITHUB_WORKSPACE}/script_container.sh docker exec container /bin/bash -c "/mount.sh && /${name}/script_container.sh" \ No newline at end of file From 91e42ec2a72548671bf378f490d744c9614a29c2 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 26 Jun 2024 21:20:25 +0200 Subject: [PATCH 15/23] Fix the name --- .github/workflows/generate-edm4hep-file.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-edm4hep-file.yaml b/.github/workflows/generate-edm4hep-file.yaml index bd72e0d34..b11f1cf16 100644 --- a/.github/workflows/generate-edm4hep-file.yaml +++ b/.github/workflows/generate-edm4hep-file.yaml @@ -42,4 +42,4 @@ jobs: chmod +x ${GITHUB_WORKSPACE}/script_container.sh - docker exec container /bin/bash -c "/mount.sh && /${name}/script_container.sh" \ No newline at end of file + docker exec container /bin/bash -c "/mount.sh && /EDM4hep/script_container.sh" \ No newline at end of file From 6d817c3d88900866c56d505bf45aeb649cf191ad Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 30 Jun 2024 22:14:21 +0200 Subject: [PATCH 16/23] Add check --- .github/workflows/generate-edm4hep-file.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/generate-edm4hep-file.yaml b/.github/workflows/generate-edm4hep-file.yaml index b11f1cf16..b84d03a38 100644 --- a/.github/workflows/generate-edm4hep-file.yaml +++ b/.github/workflows/generate-edm4hep-file.yaml @@ -36,6 +36,7 @@ jobs: time ninja install ccache -s + ls /EDM4hep/scripts python3 /EDM4hep/scripts/createEDM4hepFile.py EOF From 62cac3a14e95ffb04b814fd601429308bd965563 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 30 Jun 2024 22:16:17 +0200 Subject: [PATCH 17/23] Add ls --- .github/workflows/generate-edm4hep-file.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/generate-edm4hep-file.yaml b/.github/workflows/generate-edm4hep-file.yaml index b84d03a38..f805896fd 100644 --- a/.github/workflows/generate-edm4hep-file.yaml +++ b/.github/workflows/generate-edm4hep-file.yaml @@ -36,6 +36,7 @@ jobs: time ninja install ccache -s + ls /EDM4hep ls /EDM4hep/scripts python3 /EDM4hep/scripts/createEDM4hepFile.py From 2d1ed57db12efc86a4c242b9fc3c28f69161af3f Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 30 Jun 2024 22:19:22 +0200 Subject: [PATCH 18/23] Run the script to create a file --- .github/workflows/generate-edm4hep-file.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/generate-edm4hep-file.yaml b/.github/workflows/generate-edm4hep-file.yaml index f805896fd..98a061376 100644 --- a/.github/workflows/generate-edm4hep-file.yaml +++ b/.github/workflows/generate-edm4hep-file.yaml @@ -36,9 +36,7 @@ jobs: time ninja install ccache -s - ls /EDM4hep - ls /EDM4hep/scripts - python3 /EDM4hep/scripts/createEDM4hepFile.py + python3 /scripts/createEDM4hepFile.py EOF From 54206b862a1bc914dccb39343a17875c04024f03 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 10:22:28 +0200 Subject: [PATCH 19/23] Update script --- scripts/createEDM4hepFile.py | 240 +++++++++++------------------------ 1 file changed, 73 insertions(+), 167 deletions(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index c7f211f9e..bc00e1d72 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -14,9 +14,6 @@ output_file = "output.root" parser = argparse.ArgumentParser(description="Create a file with EDM4hep data") -parser.add_argument( - "--use-pre1", action="store_true", help="Use a pre 1.0 version of EDM4hep" -) parser.add_argument( "--rntuple", action="store_true", help="Use a ROOT ntuple instead of EDM4hep" ) @@ -42,78 +39,39 @@ h.setRunNumber(next(counter)) h.setTimeStamp(next(counter)) h.setWeight(1.0) - if not args.use_pre1: - for j in range(vectorsize): - h.addToWeights(next(counter)) + for j in range(vectorsize): + h.addToWeights(next(counter)) frame.put(header, "EventHeader") particles = edm4hep.MCParticleCollection() - parent_particle = particles.create() - parent_particle.setPDG(next(counter)) - parent_particle.setGeneratorStatus(next(counter)) - parent_particle.setSimulatorStatus(next(counter)) - parent_particle.setCharge(next(counter)) - parent_particle.setTime(next(counter)) - parent_particle.setMass(next(counter)) - parent_particle.setVertex( - edm4hep.Vector3d(next(counter), next(counter), next(counter)) - ) - parent_particle.setEndpoint( - edm4hep.Vector3d(next(counter), next(counter), next(counter)) - ) - if not args.use_pre1: - parent_particle.setMomentum( + for i in range(3): + particle = particles.create() + particle.setPDG(next(counter)) + particle.setGeneratorStatus(next(counter)) + particle.setSimulatorStatus(next(counter)) + particle.setCharge(next(counter)) + particle.setTime(next(counter)) + particle.setMass(next(counter)) + particle.setVertex( edm4hep.Vector3d(next(counter), next(counter), next(counter)) ) - parent_particle.setMomentumAtEndpoint( + particle.setEndpoint( edm4hep.Vector3d(next(counter), next(counter), next(counter)) ) - else: - parent_particle.setMomentum( - edm4hep.Vector3f(next(counter), next(counter), next(counter)) - ) - parent_particle.setMomentumAtEndpoint( - edm4hep.Vector3f(next(counter), next(counter), next(counter)) - ) - parent_particle.setSpin( - edm4hep.Vector3f(next(counter), next(counter), next(counter)) - ) - parent_particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) - - daughter_particle = particles.create() - daughter_particle.setPDG(next(counter)) - daughter_particle.setGeneratorStatus(next(counter)) - daughter_particle.setSimulatorStatus(next(counter)) - daughter_particle.setCharge(next(counter)) - daughter_particle.setTime(next(counter)) - daughter_particle.setMass(next(counter)) - daughter_particle.setVertex( - edm4hep.Vector3d(next(counter), next(counter), next(counter)) - ) - daughter_particle.setEndpoint( - edm4hep.Vector3d(next(counter), next(counter), next(counter)) - ) - if not args.use_pre1: - daughter_particle.setMomentum( + particle.setMomentum( edm4hep.Vector3d(next(counter), next(counter), next(counter)) ) - daughter_particle.setMomentumAtEndpoint( + particle.setMomentumAtEndpoint( edm4hep.Vector3d(next(counter), next(counter), next(counter)) ) - else: - daughter_particle.setMomentum( - edm4hep.Vector3f(next(counter), next(counter), next(counter)) - ) - daughter_particle.setMomentumAtEndpoint( + particle.setSpin( edm4hep.Vector3f(next(counter), next(counter), next(counter)) ) - daughter_particle.setSpin( - edm4hep.Vector3f(next(counter), next(counter), next(counter)) - ) - daughter_particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) + particle.setColorFlow(edm4hep.Vector2i(next(counter), next(counter))) - parent_particle.addToDaughters(daughter_particle) - daughter_particle.addToParents(parent_particle) + particles[0].addToDaughters(particles[1]) + particles[0].addToParents(particles[2]) + particle = particles[0] frame.put(particles, "MCParticleCollection") hits = edm4hep.SimTrackerHitCollection() @@ -125,7 +83,7 @@ hit.setQuality(next(counter)) hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) hit.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - hit.setParticle(daughter_particle) + hit.setParticle(particle) simtracker_hit = hit frame.put(hits, "SimTrackerHitCollection") @@ -135,7 +93,7 @@ hit.setEnergy(next(counter)) hit.setTime(next(counter)) hit.setStepPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - hit.setParticle(daughter_particle) + hit.setParticle(particle) calohit = hit frame.put(hits, "CaloHitContributionCollection") @@ -191,18 +149,12 @@ ) for j in range(vectorsize): cluster.addToShapeParameters(next(counter)) - for j in range(vectorsize): cluster.addToSubdetectorEnergies(next(counter)) cluster.addToClusters(cluster) cluster.addToHits(calo_hit) - if args.use_pre1: - cluster.addToParticleIDs(pid) frame.put(clusters, "ClusterCollection") - if args.use_pre1: - hits = edm4hep.TrackerHitCollection() - else: - hits = edm4hep.TrackerHit3DCollection() + hits = edm4hep.TrackerHit3DCollection() hit = hits.create() hit.setCellID(next(counter)) hit.setType(next(counter)) @@ -212,12 +164,6 @@ hit.setEDepError(next(counter)) hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) hit.setCovMatrix([next(counter) for _ in range(6)]) - if args.use_pre1: - for j in range(vectorsize): - oid = edm4hep.ObjectID() - oid.index = next(counter) - oid.collectionID = next(counter) - hit.addToRawHits(oid) tracker_hit = hit frame.put(hits, "TrackerHit3DCollection") @@ -235,12 +181,6 @@ hit.setDv(next(counter)) hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) hit.setCovMatrix([next(counter) for _ in range(6)]) - if args.use_pre1: - for j in range(vectorsize): - oid = edm4hep.ObjectID() - oid.index = next(counter) - oid.collectionID = next(counter) - hit.addToRawHits(oid) frame.put(hits, "TrackerHitPlaneCollection") series = edm4hep.RawTimeSeriesCollection() @@ -259,12 +199,8 @@ track.setType(next(counter)) track.setChi2(next(counter)) track.setNdf(next(counter)) - track.setDEdx(next(counter)) - track.setDEdxError(next(counter)) - track.setRadiusOfInnermostHit(next(counter)) for j in range(vectorsize): track.addToSubdetectorHitNumbers(next(counter)) - for j in range(vectorsize): state = edm4hep.TrackState() state.location = next(counter) state.d0 = next(counter) @@ -284,9 +220,9 @@ vertex = edm4hep.VertexCollection() v = vertex.create() - v.setPrimary(next(counter)) + v.setType(next(counter)) v.setChi2(next(counter)) - v.setProbability(next(counter)) + v.setNdf(next(counter)) v.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) v.setCovMatrix([next(counter) for _ in range(6)]) v.setAlgorithmType(next(counter)) @@ -294,33 +230,27 @@ v.addToParameters(next(counter)) frame.put(vertex, "VertexCollection") - particles = edm4hep.ReconstructedParticleCollection() - particle = particles.create() - if args.use_pre1: - particle.setType(next(counter)) - else: - particle.setPDG(next(counter)) - particle.setEnergy(next(counter)) - particle.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - particle.setReferencePoint( + rparticles = edm4hep.ReconstructedParticleCollection() + rparticle = rparticles.create() + rparticle.setPDG(next(counter)) + rparticle.setEnergy(next(counter)) + rparticle.setMomentum(edm4hep.Vector3f(next(counter), next(counter), next(counter))) + rparticle.setReferencePoint( edm4hep.Vector3f(next(counter), next(counter), next(counter)) ) - particle.setCharge(next(counter)) - particle.setMass(next(counter)) - particle.setGoodnessOfPID(next(counter)) - particle.setCovMatrix([next(counter) for _ in range(10)]) - particle.setStartVertex(v) - if args.use_pre1: - particle.setParticleIDUsed(pid) - particle.addToClusters(cluster) - particle.addToTracks(track) - particle.addToParticles(particle) - if args.use_pre1: - particle.addToParticleIDs(pid) - reco_particle = particle - frame.put(particles, "ReconstructedParticleCollection") - - v.setAssociatedParticle(reco_particle) + rparticle.setCharge(next(counter)) + rparticle.setMass(next(counter)) + rparticle.setGoodnessOfPID(next(counter)) + rparticle.setCovMatrix([next(counter) for _ in range(10)]) + rparticle.setDecayVertex(v) + rparticle.addToClusters(cluster) + rparticle.addToTracks(track) + rparticle.addToParticles(rparticle) + reco_particle = rparticle + frame.put(rparticles, "ReconstructedParticleCollection") + + v.addToParticles(reco_particle) + pid.setParticle(reco_particle) # TODO: Add when the PID PR is merged # if not args.use_pre1: @@ -330,7 +260,7 @@ assoc = assocs.create() assoc.setWeight(next(counter)) assoc.setRec(reco_particle) - assoc.setSim(daughter_particle) + assoc.setSim(particle) frame.put(assocs, "MCRecoParticleAssociationCollection") assocs = edm4hep.MCRecoCaloAssociationCollection() @@ -351,21 +281,21 @@ assoc = assocs.create() assoc.setWeight(next(counter)) assoc.setRec(calo_hit) - assoc.setSim(daughter_particle) + assoc.setSim(particle) frame.put(assocs, "MCRecoCaloParticleAssociationCollection") assocs = edm4hep.MCRecoClusterParticleAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) assoc.setRec(cluster) - assoc.setSim(daughter_particle) + assoc.setSim(particle) frame.put(assocs, "MCRecoClusterParticleAssociationCollection") assocs = edm4hep.MCRecoTrackParticleAssociationCollection() assoc = assocs.create() assoc.setWeight(next(counter)) assoc.setRec(track) - assoc.setSim(daughter_particle) + assoc.setSim(particle) frame.put(assocs, "MCRecoTrackParticleAssociationCollection") assocs = edm4hep.RecoParticleVertexAssociationCollection() @@ -375,23 +305,6 @@ assoc.setVertex(v) frame.put(assocs, "MCRecoParticleVertexAssociationCollection") - simiocluster = edm4hep.SimPrimaryIonizationClusterCollection() - cluster = simiocluster.create() - cluster.setCellID(next(counter)) - cluster.setTime(next(counter)) - cluster.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - cluster.setType(next(counter)) - for j in range(vectorsize): - cluster.addToElectronCellID(next(counter)) - cluster.addToElectronTime(next(counter)) - cluster.addToElectronPosition( - edm4hep.Vector3d(next(counter), next(counter), next(counter)) - ) - cluster.addToPulseTime(next(counter)) - cluster.addToPulseAmplitude(next(counter)) - cluster.setParticle(daughter_particle) - frame.put(simiocluster, "SimPrimaryIonizationClusterCollection") - timeseries = edm4hep.TimeSeriesCollection() serie = timeseries.create() serie.setCellID(next(counter)) @@ -401,42 +314,35 @@ serie.addToAmplitude(next(counter)) frame.put(timeseries, "TimeSeriesCollection") - trackerpulse = edm4hep.TrackerPulseCollection() - pulse = trackerpulse.create() - pulse.setCellID(next(counter)) - pulse.setTime(next(counter)) - pulse.setCharge(next(counter)) - pulse.setQuality(next(counter)) - pulse.setCovMatrix([next(counter) for _ in range(3)]) - pulse.setTimeSeries(serie) - frame.put(trackerpulse, "TrackerPulseCollection") - - recioncluster = edm4hep.RecIonizationClusterCollection() - cluster = recioncluster.create() - cluster.setCellID(next(counter)) - cluster.setSignificance(next(counter)) - cluster.setType(next(counter)) - cluster.addToTrackerPulse(pulse) - frame.put(recioncluster, "RecIonizationClusterCollection") - recdqdx = edm4hep.RecDqdxCollection() dqdx = recdqdx.create() - dqdx.setParticleType(next(counter)) - dqdx.setType(next(counter)) - for j in range(5): - h = edm4hep.Hypothesis() - h.chi2 = next(counter) - h.expected = next(counter) - h.sigma = next(counter) - dqdx.setHypotheses(j, h) - for j in range(vectorsize): - hd = edm4hep.HitLevelData() - hd.cellID = next(counter) - hd.N = next(counter) - hd.eDep = next(counter) - hd.pathLength = next(counter) - dqdx.addToHitData(hd) + q = edm4hep.Quantity() + q.type = next(counter) + q.value = next(counter) + q.error = next(counter) + dqdx.setDQdx(q) dqdx.setTrack(track) frame.put(recdqdx, "RecDqdxCollection") + gep_coll = edm4hep.GeneratorEventParametersCollection() + gep = gep_coll.create() + gep.setEventScale(next(counter)) + gep.setAlphaQED(next(counter)) + gep.setAlphaQCD(next(counter)) + gep.setSignalProcessId(next(counter)) + gep.setSqrts(next(counter)) + + for i in range(vectorsize): + gep.addToCrossSections(next(counter)) + gep.addToCrossSectionErrors(next(counter)) + gep.addToSignalVertex(particle) + + gpi_coll = edm4hep.GeneratorPdfInfoCollection() + gpi = gpi_coll.create() + gpi.setPartonId([next(counter), next(counter)]) + gpi.setLhapdfId([next(counter), next(counter)]) + gpi.setX([next(counter), next(counter)]) + gpi.setXf([next(counter), next(counter)]) + gpi.setScale(next(counter)) + writer.write_frame(frame, "events") From 76c0baa90fb8c0cd6c5afe8435b984e9b47a5de8 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 10:51:03 +0200 Subject: [PATCH 20/23] Add a test in CMakeLists.txt --- .github/workflows/generate-edm4hep-file.yaml | 45 -------------------- scripts/createEDM4hepFile.py | 7 ++- test/CMakeLists.txt | 3 ++ 3 files changed, 6 insertions(+), 49 deletions(-) delete mode 100644 .github/workflows/generate-edm4hep-file.yaml diff --git a/.github/workflows/generate-edm4hep-file.yaml b/.github/workflows/generate-edm4hep-file.yaml deleted file mode 100644 index 98a061376..000000000 --- a/.github/workflows/generate-edm4hep-file.yaml +++ /dev/null @@ -1,45 +0,0 @@ -name: Generate an EDM4Hep file - -on: - pull_request: - workflow_dispatch: - -jobs: - generate-file: - runs-on: ubuntu-latest - steps: - - shell: bash - run: echo "NOW=$(date +'%Y-%m-%d')" >> $GITHUB_ENV - - - uses: actions/cache@v4 - with: - path: ~/.cache/ccache - key: nightly-alma9-${{ env.NOW }} - restore-keys: | - nightly-alma9 - - - name: Start container - shell: bash - run: | - docker run --name container --privileged -v ${GITHUB_WORKSPACE}:/EDM4hep -v ~/.cache/ccache:/root/.cache/ccache -d ghcr.io/key4hep/key4hep-images/alma9-cvmfs tail -f /dev/null - - - name: Run script - run: | - cat <<'EOF' > ${GITHUB_WORKSPACE}/script_container.sh - - source /cvmfs/sw-nightlies.hsf.org/key4hep/setup.sh - cd /EDM4hep - k4_local_repo - mkdir build - cd build - cmake .. -DCMAKE_CXX_STANDARD=20 -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -G Ninja - time ninja install - ccache -s - - python3 /scripts/createEDM4hepFile.py - - EOF - - chmod +x ${GITHUB_WORKSPACE}/script_container.sh - - docker exec container /bin/bash -c "/mount.sh && /EDM4hep/script_container.sh" \ No newline at end of file diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index bc00e1d72..851347980 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -7,7 +7,7 @@ import argparse import sys -frames = 10 # How many frames or events will be written +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 @@ -25,9 +25,8 @@ except AttributeError: print("The RNTuple writer from podio is not available but was requested") sys.exit(1) - - -writer = podio.root_io.Writer(output_file) +else: + writer = podio.root_io.Writer(output_file) for i in range(frames): print(f"Writing frame {i}") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3e238e52e..d02b9561b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,6 +12,9 @@ function(set_test_env _testname) ) endfunction() +add_test(NAME "Create an EDM4hep data file" COMMAND python ${PROJECT_SOURCE_DIR}/scripts/createEDM4hepFile.py) +set_test_env("Create an EDM4hep data file") + 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 a4e6da3a9ba6a8f28e2028438e929ab6cae30a4f Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 11:04:18 +0200 Subject: [PATCH 21/23] Add PYTHONPATH --- test/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d02b9561b..ee6306bdb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,6 +6,7 @@ function(set_test_env _testname) set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT LD_LIBRARY_PATH=$:$:$<$:$:>$:$ENV{LD_LIBRARY_PATH} ROOT_INCLUDE_PATH=${PROJECT_SOURCE_DIR}/edm4hep:${PROJECT_SOURCE_DIR}/utils/include:$ENV{ROOT_INCLUDE_PATH} + PYTHONPATH=${PROJECT_SOURCE_DIR}/python:$ENV{PYTHONPATH} ) set_tests_properties(${_testname} PROPERTIES FAIL_REGULAR_EXPRESSION "[^a-z]Error;ERROR;error;Failed" From fd7f7503f9fca9409ce56f35884a81c3f71e0efb Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 15:27:03 +0200 Subject: [PATCH 22/23] Fix the script for the current version of cppyy --- scripts/createEDM4hepFile.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index 851347980..c0bb289cb 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -32,6 +32,21 @@ print(f"Writing frame {i}") frame = podio.Frame() + # Make covariance matrices needed later + + # With the current version of cppyy (from ROOT 6.30.06) + # it's not possible to initialize an std::array from a list + # In future versions (works with 6.32.02) it will be possible + cov3f = edm4hep.CovMatrix3f() + for i in range(6): + cov3f[i] = next(counter) + cov4f = edm4hep.CovMatrix4f() + for i in range(10): + cov4f[i] = next(counter) + cov6f = edm4hep.CovMatrix6f() + for i in range(21): + cov6f[i] = next(counter) + header = edm4hep.EventHeaderCollection() h = header.create() h.setEventNumber(next(counter)) @@ -139,8 +154,7 @@ cluster.setEnergy(next(counter)) cluster.setEnergyError(next(counter)) cluster.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - for j in range(6): - cluster.setPositionError([next(counter) for _ in range(6)]) + cluster.setPositionError(cov3f) cluster.setITheta(next(counter)) cluster.setPhi(next(counter)) cluster.setDirectionError( @@ -162,7 +176,7 @@ hit.setEDep(next(counter)) hit.setEDepError(next(counter)) hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - hit.setCovMatrix([next(counter) for _ in range(6)]) + hit.setCovMatrix(cov3f) tracker_hit = hit frame.put(hits, "TrackerHit3DCollection") @@ -179,7 +193,7 @@ hit.setDu(next(counter)) hit.setDv(next(counter)) hit.setPosition(edm4hep.Vector3d(next(counter), next(counter), next(counter))) - hit.setCovMatrix([next(counter) for _ in range(6)]) + hit.setCovMatrix(cov3f) frame.put(hits, "TrackerHitPlaneCollection") series = edm4hep.RawTimeSeriesCollection() @@ -211,7 +225,7 @@ state.referencePoint = edm4hep.Vector3f( next(counter), next(counter), next(counter) ) - state.CovMatrix = [next(counter) for _ in range(21)] + state.CovMatrix = cov6f track.addToTrackStates(state) track.addToTrackerHits(tracker_hit) track.addToTracks(track) @@ -223,7 +237,7 @@ v.setChi2(next(counter)) v.setNdf(next(counter)) v.setPosition(edm4hep.Vector3f(next(counter), next(counter), next(counter))) - v.setCovMatrix([next(counter) for _ in range(6)]) + v.setCovMatrix(cov3f) v.setAlgorithmType(next(counter)) for j in range(vectorsize): v.addToParameters(next(counter)) @@ -240,7 +254,7 @@ rparticle.setCharge(next(counter)) rparticle.setMass(next(counter)) rparticle.setGoodnessOfPID(next(counter)) - rparticle.setCovMatrix([next(counter) for _ in range(10)]) + rparticle.setCovMatrix(cov4f) rparticle.setDecayVertex(v) rparticle.addToClusters(cluster) rparticle.addToTracks(track) From cec370ef344918516cc795a0012c1bccaa0000bd Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 19:07:03 +0200 Subject: [PATCH 23/23] Fix setting arrays --- scripts/createEDM4hepFile.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/createEDM4hepFile.py b/scripts/createEDM4hepFile.py index c0bb289cb..f838adeed 100644 --- a/scripts/createEDM4hepFile.py +++ b/scripts/createEDM4hepFile.py @@ -352,10 +352,22 @@ gpi_coll = edm4hep.GeneratorPdfInfoCollection() gpi = gpi_coll.create() - gpi.setPartonId([next(counter), next(counter)]) - gpi.setLhapdfId([next(counter), next(counter)]) - gpi.setX([next(counter), next(counter)]) - gpi.setXf([next(counter), next(counter)]) + # Doesn't work with ROOT 6.30.06 + # gpi.setPartonId([next(counter), next(counter)]) + gpi.setPartonId(0, next(counter)) + gpi.setPartonId(1, next(counter)) + # Doesn't work with ROOT 6.30.06 + # gpi.setLhapdfId([next(counter), next(counter)]) + gpi.setLhapdfId(0, next(counter)) + gpi.setLhapdfId(1, next(counter)) + # Doesn't work with ROOT 6.30.06 + # gpi.setX([next(counter), next(counter)]) + gpi.setX(0, next(counter)) + gpi.setX(1, next(counter)) + # Doesn't work with ROOT 6.30.06 + # gpi.setXf([next(counter), next(counter)]) + gpi.setXf(0, next(counter)) + gpi.setXf(1, next(counter)) gpi.setScale(next(counter)) writer.write_frame(frame, "events")