From 18fdf019913c03bf6e4bdc2af045878535e86cda Mon Sep 17 00:00:00 2001 From: Pere Mato Date: Mon, 5 Feb 2024 23:00:48 +0100 Subject: [PATCH 1/4] Generate accessors --- docs/src/index.md | 2 +- podio/genComponents.jl | 16 +-- podio/genDatatypes.jl | 217 ++++++++++++++++++++++++++++++++++++++++- podio/generate.jl | 42 +++++++- src/Components.jl | 19 +++- src/Datatypes.jl | 10 -- src/EDStore.jl | 1 + test/runtests.jl | 1 + test/testCluster.jl | 75 ++++++++++++++ test/testParticleID.jl | 2 +- 10 files changed, 356 insertions(+), 29 deletions(-) create mode 100644 test/testCluster.jl diff --git a/docs/src/index.md b/docs/src/index.md index 0a6c431..ce3b50f 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -35,7 +35,7 @@ There are a number of issues and problems still to be resolved. We keep track of - Better handle collectionID in one-to-many relations - *DONE* - Be able to read RNTuple files in addition to TTree files - *DONE* - Generate doc string with member information - *DONE* -- Generate accessors for one-to-many relations, vector members +- Generate accessors for one-to-many relations, vector members - *DONE* - Support latest version (RC2) of RNTuple format (waiting for a file being generated) diff --git a/podio/genComponents.jl b/podio/genComponents.jl index 7d32899..54b71fb 100644 --- a/podio/genComponents.jl +++ b/podio/genComponents.jl @@ -1,5 +1,5 @@ """ -struct HitLevelData +HitLevelData # Fields - `cellID::UInt64`: cell id - `N::UInt32`: number of reconstructed ionization cluster. @@ -15,7 +15,7 @@ struct HitLevelData <: POD end """ -struct Vector3d +Vector3d # Fields - `x::Float64`: - `y::Float64`: @@ -29,7 +29,7 @@ struct Vector3d <: POD end """ -struct Quantity +Quantity # Fields - `type::Int16`: flag identifying how to interpret the quantity - `value::Float32`: value of the quantity @@ -43,7 +43,7 @@ struct Quantity <: POD end """ -struct Vector3f +Vector3f # Fields - `x::Float32`: - `y::Float32`: @@ -57,7 +57,7 @@ struct Vector3f <: POD end """ -struct TrackState +TrackState # Fields - `location::Int32`: for use with At{Other|IP|FirstHit|LastHit|Calorimeter|Vertex}|LastLocation - `D0::Float32`: transverse impact parameter @@ -83,7 +83,7 @@ struct TrackState <: POD end """ -struct Hypothesis +Hypothesis # Fields - `chi2::Float32`: chi2 - `expected::Float32`: expected value @@ -97,7 +97,7 @@ struct Hypothesis <: POD end """ -struct Vector2i +Vector2i # Fields - `a::Int32`: - `b::Int32`: @@ -125,7 +125,7 @@ struct Vector4f <: POD end """ -struct Vector2f +Vector2f # Fields - `a::Float32`: - `b::Float32`: diff --git a/podio/genDatatypes.jl b/podio/genDatatypes.jl index 9e68e55..62e7458 100644 --- a/podio/genDatatypes.jl +++ b/podio/genDatatypes.jl @@ -23,6 +23,11 @@ function ParticleID(;type=0, PDG=0, algorithmType=0, likelihood=0, parameters=PV ParticleID(-1, type, PDG, algorithmType, likelihood, parameters) end +function setParameters(o::ParticleID, v::AbstractVector{Float32}) + iszero(o.index) && (o = register(o)) + o = @set o.parameters = v + update(o) +end """ Calibrated Detector Data - Author: Wenxing Fang, IHEP @@ -46,6 +51,11 @@ function TimeSeries(;cellID=0, time=0, interval=0, amplitude=PVector{TimeSeries, TimeSeries(-1, cellID, time, interval, amplitude) end +function setAmplitude(o::TimeSeries, v::AbstractVector{Float32}) + iszero(o.index) && (o = register(o)) + o = @set o.amplitude = v + update(o) +end """ Calorimeter hit - Author: F.Gaede, DESY @@ -115,6 +125,46 @@ function Cluster(;type=0, energy=0, energyError=0, position=Vector3f(), position Cluster(-1, type, energy, energyError, position, positionError, iTheta, phi, directionError, shapeParameters, subdetectorEnergies, clusters, hits, particleIDs) end +function pushToClusters(c::Cluster, o::Cluster) + iszero(c.index) && (c = register(c)) + c = @set c.clusters = push(c.clusters, o) + update(c) +end +function popFromClusters(c::Cluster) + iszero(c.index) && (c = register(c)) + c = @set c.clusters = pop(c.clusters) + update(c) +end +function pushToHits(c::Cluster, o::CalorimeterHit) + iszero(c.index) && (c = register(c)) + c = @set c.hits = push(c.hits, o) + update(c) +end +function popFromHits(c::Cluster) + iszero(c.index) && (c = register(c)) + c = @set c.hits = pop(c.hits) + update(c) +end +function pushToParticleIDs(c::Cluster, o::ParticleID) + iszero(c.index) && (c = register(c)) + c = @set c.particleIDs = push(c.particleIDs, o) + update(c) +end +function popFromParticleIDs(c::Cluster) + iszero(c.index) && (c = register(c)) + c = @set c.particleIDs = pop(c.particleIDs) + update(c) +end +function setShapeParameters(o::Cluster, v::AbstractVector{Float32}) + iszero(o.index) && (o = register(o)) + o = @set o.shapeParameters = v + update(o) +end +function setSubdetectorEnergies(o::Cluster, v::AbstractVector{Float32}) + iszero(o.index) && (o = register(o)) + o = @set o.subdetectorEnergies = v + update(o) +end """ The Monte Carlo particle - based on the lcio::MCParticle. - Author: F.Gaede, DESY @@ -159,6 +209,26 @@ function MCParticle(;PDG=0, generatorStatus=0, simulatorStatus=0, charge=0, time MCParticle(-1, PDG, generatorStatus, simulatorStatus, charge, time, mass, vertex, endpoint, momentum, momentumAtEndpoint, spin, colorFlow, parents, daughters) end +function pushToParents(c::MCParticle, o::MCParticle) + iszero(c.index) && (c = register(c)) + c = @set c.parents = push(c.parents, o) + update(c) +end +function popFromParents(c::MCParticle) + iszero(c.index) && (c = register(c)) + c = @set c.parents = pop(c.parents) + update(c) +end +function pushToDaughters(c::MCParticle, o::MCParticle) + iszero(c.index) && (c = register(c)) + c = @set c.daughters = push(c.daughters, o) + update(c) +end +function popFromDaughters(c::MCParticle) + iszero(c.index) && (c = register(c)) + c = @set c.daughters = pop(c.daughters) + update(c) +end """ Simulated Primary Ionization - Author: Wenxing Fang, IHEP @@ -204,6 +274,31 @@ function Base.getproperty(obj::SimPrimaryIonizationCluster, sym::Symbol) return getfield(obj, sym) end end +function setElectronCellID(o::SimPrimaryIonizationCluster, v::AbstractVector{UInt64}) + iszero(o.index) && (o = register(o)) + o = @set o.electronCellID = v + update(o) +end +function setElectronTime(o::SimPrimaryIonizationCluster, v::AbstractVector{Float32}) + iszero(o.index) && (o = register(o)) + o = @set o.electronTime = v + update(o) +end +function setElectronPosition(o::SimPrimaryIonizationCluster, v::AbstractVector{Vector3d}) + iszero(o.index) && (o = register(o)) + o = @set o.electronPosition = v + update(o) +end +function setPulseTime(o::SimPrimaryIonizationCluster, v::AbstractVector{Float32}) + iszero(o.index) && (o = register(o)) + o = @set o.pulseTime = v + update(o) +end +function setPulseAmplitude(o::SimPrimaryIonizationCluster, v::AbstractVector{Float32}) + iszero(o.index) && (o = register(o)) + o = @set o.pulseAmplitude = v + update(o) +end """ Association between a Cluster and a MCParticle - Author: Placido Fernandez Declara @@ -328,6 +423,16 @@ function SimCalorimeterHit(;cellID=0, energy=0, position=Vector3f(), contributio SimCalorimeterHit(-1, cellID, energy, position, contributions) end +function pushToContributions(c::SimCalorimeterHit, o::CaloHitContribution) + iszero(c.index) && (c = register(c)) + c = @set c.contributions = push(c.contributions, o) + update(c) +end +function popFromContributions(c::SimCalorimeterHit) + iszero(c.index) && (c = register(c)) + c = @set c.contributions = pop(c.contributions) + update(c) +end """ Raw data of a detector readout - Author: F.Gaede, DESY @@ -355,6 +460,11 @@ function RawTimeSeries(;cellID=0, quality=0, time=0, charge=0, interval=0, adcCo RawTimeSeries(-1, cellID, quality, time, charge, interval, adcCounts) end +function setAdcCounts(o::RawTimeSeries, v::AbstractVector{Int32}) + iszero(o.index) && (o = register(o)) + o = @set o.adcCounts = v + update(o) +end """ Association between a CaloHit and the corresponding simulated CaloHit - Author: C. Bernet, B. Hegner @@ -479,6 +589,11 @@ function TrackerHit(;cellID=0, type=0, quality=0, time=0, eDep=0, eDepError=0, p TrackerHit(-1, cellID, type, quality, time, eDep, eDepError, position, covMatrix, rawHits) end +function setRawHits(o::TrackerHit, v::AbstractVector{ObjectID}) + iszero(o.index) && (o = register(o)) + o = @set o.rawHits = v + update(o) +end """ Raw calorimeter hit - Author: F.Gaede, DESY @@ -523,6 +638,16 @@ function RecIonizationCluster(;cellID=0, significance=0, type=0, trackerPulse=Re RecIonizationCluster(-1, cellID, significance, type, trackerPulse) end +function pushToTrackerPulse(c::RecIonizationCluster, o::TrackerPulse) + iszero(c.index) && (c = register(c)) + c = @set c.trackerPulse = push(c.trackerPulse, o) + update(c) +end +function popFromTrackerPulse(c::RecIonizationCluster) + iszero(c.index) && (c = register(c)) + c = @set c.trackerPulse = pop(c.trackerPulse) + update(c) +end """ Vertex - Author: F.Gaede, DESY @@ -564,6 +689,11 @@ function Base.getproperty(obj::Vertex, sym::Symbol) return getfield(obj, sym) end end +function setParameters(o::Vertex, v::AbstractVector{Float32}) + iszero(o.index) && (o = register(o)) + o = @set o.parameters = v + update(o) +end """ Reconstructed track - Author: F.Gaede, DESY @@ -603,6 +733,41 @@ function Track(;type=0, chi2=0, ndf=0, dEdx=0, dEdxError=0, radiusOfInnermostHit Track(-1, type, chi2, ndf, dEdx, dEdxError, radiusOfInnermostHit, subdetectorHitNumbers, trackStates, dxQuantities, trackerHits, tracks) end +function pushToTrackerHits(c::Track, o::TrackerHit) + iszero(c.index) && (c = register(c)) + c = @set c.trackerHits = push(c.trackerHits, o) + update(c) +end +function popFromTrackerHits(c::Track) + iszero(c.index) && (c = register(c)) + c = @set c.trackerHits = pop(c.trackerHits) + update(c) +end +function pushToTracks(c::Track, o::Track) + iszero(c.index) && (c = register(c)) + c = @set c.tracks = push(c.tracks, o) + update(c) +end +function popFromTracks(c::Track) + iszero(c.index) && (c = register(c)) + c = @set c.tracks = pop(c.tracks) + update(c) +end +function setSubdetectorHitNumbers(o::Track, v::AbstractVector{Int32}) + iszero(o.index) && (o = register(o)) + o = @set o.subdetectorHitNumbers = v + update(o) +end +function setTrackStates(o::Track, v::AbstractVector{TrackState}) + iszero(o.index) && (o = register(o)) + o = @set o.trackStates = v + update(o) +end +function setDxQuantities(o::Track, v::AbstractVector{Quantity}) + iszero(o.index) && (o = register(o)) + o = @set o.dxQuantities = v + update(o) +end """ Association between a Track and a MCParticle - Author: Placido Fernandez Declara @@ -692,6 +857,46 @@ function Base.getproperty(obj::ReconstructedParticle, sym::Symbol) return getfield(obj, sym) end end +function pushToClusters(c::ReconstructedParticle, o::Cluster) + iszero(c.index) && (c = register(c)) + c = @set c.clusters = push(c.clusters, o) + update(c) +end +function popFromClusters(c::ReconstructedParticle) + iszero(c.index) && (c = register(c)) + c = @set c.clusters = pop(c.clusters) + update(c) +end +function pushToTracks(c::ReconstructedParticle, o::Track) + iszero(c.index) && (c = register(c)) + c = @set c.tracks = push(c.tracks, o) + update(c) +end +function popFromTracks(c::ReconstructedParticle) + iszero(c.index) && (c = register(c)) + c = @set c.tracks = pop(c.tracks) + update(c) +end +function pushToParticles(c::ReconstructedParticle, o::ReconstructedParticle) + iszero(c.index) && (c = register(c)) + c = @set c.particles = push(c.particles, o) + update(c) +end +function popFromParticles(c::ReconstructedParticle) + iszero(c.index) && (c = register(c)) + c = @set c.particles = pop(c.particles) + update(c) +end +function pushToParticleIDs(c::ReconstructedParticle, o::ParticleID) + iszero(c.index) && (c = register(c)) + c = @set c.particleIDs = push(c.particleIDs, o) + update(c) +end +function popFromParticleIDs(c::ReconstructedParticle) + iszero(c.index) && (c = register(c)) + c = @set c.particleIDs = pop(c.particleIDs) + update(c) +end """ Used to keep track of the correspondence between MC and reconstructed particles - Author: C. Bernet, B. Hegner @@ -795,6 +1000,11 @@ function Base.getproperty(obj::RecDqdx, sym::Symbol) return getfield(obj, sym) end end +function setHitData(o::RecDqdx, v::AbstractVector{HitLevelData}) + iszero(o.index) && (o = register(o)) + o = @set o.hitData = v + update(o) +end """ Tracker hit plane - Author: Placido Fernandez Declara, CERN @@ -836,6 +1046,11 @@ function TrackerHitPlane(;cellID=0, type=0, quality=0, time=0, eDep=0, eDepError TrackerHitPlane(-1, cellID, type, quality, time, eDep, eDepError, u, v, du, dv, position, covMatrix, rawHits) end +function setRawHits(o::TrackerHitPlane, v::AbstractVector{ObjectID}) + iszero(o.index) && (o = register(o)) + o = @set o.rawHits = v + update(o) +end """ Simulated tracker hit - Author: F.Gaede, DESY @@ -942,4 +1157,4 @@ function Base.getproperty(obj::MCRecoTrackerAssociation, sym::Symbol) return getfield(obj, sym) end end -export ParticleID, TimeSeries, CalorimeterHit, Cluster, MCParticle, SimPrimaryIonizationCluster, MCRecoClusterParticleAssociation, MCRecoCaloParticleAssociation, CaloHitContribution, SimCalorimeterHit, RawTimeSeries, MCRecoCaloAssociation, TrackerPulse, EventHeader, TrackerHit, RawCalorimeterHit, RecIonizationCluster, Vertex, Track, MCRecoTrackParticleAssociation, ReconstructedParticle, MCRecoParticleAssociation, RecoParticleVertexAssociation, RecDqdx, TrackerHitPlane, SimTrackerHit, MCRecoTrackerHitPlaneAssociation, MCRecoTrackerAssociation +export setParameters, ParticleID, setAmplitude, TimeSeries, CalorimeterHit, pushToClusters, popFromClusters, pushToHits, popFromHits, pushToParticleIDs, popFromParticleIDs, setShapeParameters, setSubdetectorEnergies, Cluster, pushToParents, popFromParents, pushToDaughters, popFromDaughters, MCParticle, setElectronCellID, setElectronTime, setElectronPosition, setPulseTime, setPulseAmplitude, SimPrimaryIonizationCluster, MCRecoClusterParticleAssociation, MCRecoCaloParticleAssociation, CaloHitContribution, pushToContributions, popFromContributions, SimCalorimeterHit, setAdcCounts, RawTimeSeries, MCRecoCaloAssociation, TrackerPulse, EventHeader, setRawHits, TrackerHit, RawCalorimeterHit, pushToTrackerPulse, popFromTrackerPulse, RecIonizationCluster, Vertex, pushToTrackerHits, popFromTrackerHits, pushToTracks, popFromTracks, setSubdetectorHitNumbers, setTrackStates, setDxQuantities, Track, MCRecoTrackParticleAssociation, pushToParticles, popFromParticles, ReconstructedParticle, MCRecoParticleAssociation, RecoParticleVertexAssociation, setHitData, RecDqdx, TrackerHitPlane, SimTrackerHit, MCRecoTrackerHitPlaneAssociation, MCRecoTrackerAssociation diff --git a/podio/generate.jl b/podio/generate.jl index da4b51c..64cd6fa 100644 --- a/podio/generate.jl +++ b/podio/generate.jl @@ -83,6 +83,7 @@ function gen_datatype(io, key, dtype) push!(members,v) push!(defvalues, t in fundamental_types ? "0" : contains(t,"SVector") ? "zero($t)" : t*"()") end + vectormembers = @NamedTuple{varname::String, totype::String}[] if haskey(dtype, "VectorMembers") println(io, " #---VectorMembers") for (i,r) in enumerate(dtype["VectorMembers"]) @@ -92,6 +93,7 @@ function gen_datatype(io, key, dtype) println(io, " $(vt) $(c)") push!(members, v) push!(defvalues, "PVector{$(jtype),$(t),$(i)}()") + push!(vectormembers, (varname=v,totype=t)) end end relations1to1 = @NamedTuple{varname::String, totype::String}[] @@ -107,6 +109,7 @@ function gen_datatype(io, key, dtype) push!(relations1to1, (varname=v, totype=t)) end end + relations1toN = @NamedTuple{varname::String, totype::String}[] if haskey(dtype, "OneToManyRelations") println(io, " #---OneToManyRelations") for (i,r) in enumerate(dtype["OneToManyRelations"]) @@ -116,10 +119,11 @@ function gen_datatype(io, key, dtype) println(io, " $(vt) $(c)") push!(members, v) push!(defvalues, "Relation{$(jtype),$(t),$(i)}()") + push!(relations1toN, (varname=v, totype=t)) end end - println(io, "end\n") + # add an extra constructor with keyword parameters args = join(members, ", ") defs = join(["$m=$dv" for (m,dv) in zip(members,defvalues)], ", ") @@ -128,7 +132,7 @@ function gen_datatype(io, key, dtype) $jtype(-1, $args) end """) - # add an Base.getproperty() for the one-to-one relations (for the time being) + # add an Base.getproperty() for the one-to-one relations if !isempty(relations1to1) println(io, "function Base.getproperty(obj::$jtype, sym::Symbol)") for (i, r) in enumerate(relations1to1) @@ -146,6 +150,38 @@ function gen_datatype(io, key, dtype) end end""") end + # add pushToXxxx() and popFromXxxx for al one-to-many relations + if !isempty(relations1toN) + global exports + for r in relations1toN + (;varname, totype) = r + upvarname = uppercasefirst(varname) + println(io, "function pushTo$(upvarname)(c::$jtype, o::$totype)") + println(io, " iszero(c.index) && (c = register(c))") + println(io, " c = @set c.$(varname) = push(c.$varname, o)") + println(io, " update(c)") + println(io,"end") + println(io, "function popFrom$(upvarname)(c::$jtype)") + println(io, " iszero(c.index) && (c = register(c))") + println(io, " c = @set c.$(varname) = pop(c.$varname)") + println(io, " update(c)") + println(io,"end") + push!(exports, "pushTo$(upvarname)", "popFrom$(upvarname)") + end + end + if !isempty(vectormembers) + global exports + for v in vectormembers + (;varname, totype) = v + upvarname = uppercasefirst(varname) + println(io, "function set$(upvarname)(o::$jtype, v::AbstractVector{$totype})") + println(io, " iszero(o.index) && (o = register(o))") + println(io, " o = @set o.$(varname) = v") + println(io, " update(o)") + println(io,"end") + push!(exports, "set$(upvarname)") + end + end end function gen_docstring(io, key, dtype) @@ -209,6 +245,6 @@ for i in topological_sort(graph) gen_datatype(io, dtypes[i], datatypes[dtypes[i]]) push!(exports, to_julia(dtypes[i])) end -println(io, "export $(join(exports,", "))") +println(io, "export $(join(unique(exports),", "))") close(io) diff --git a/src/Components.jl b/src/Components.jl index 2641971..7cf5764 100644 --- a/src/Components.jl +++ b/src/Components.jl @@ -87,6 +87,7 @@ function register(p::ED) where ED return p end function update(p::ED) where ED + iszero(p.index) && (p = register(p)) # need to register if not done EDStore_objects(ED)[p.index.index+1] = p end function collectionID(::Type{ED}) where ED @@ -141,17 +142,25 @@ function vmembers(::Type{ED}) where ED end function push(r::Relation{ED,TD,N}, p::TD) where {ED,TD,N} - relations = EDStore_relations(ED,N,r.collid) - (;first, last) = r + (;first, last, collid) = r + relations = EDStore_relations(ED, N, collid) length = last-first tail = lastindex(relations) - append!(relations, zeros(ObjectID{TD}, length+1)) # add extended indices at the end + append!(relations, zeros(ObjectID{TD}, length+1)) # add extended indices at the end relations[tail + 1:tail + length] = relations[first+1:last] # copy indices - relations[first + 1:last] .= zeros(ObjectID{TD},length) # reset unused indices + relations[first + 1:last] .= zeros(ObjectID{TD},length) # reset unused indices first = tail last = first + length + 1 relations[last] = p - Relation{ED,TD,N}(first, last, r.collid) + Relation{ED,TD,N}(first, last, collid) +end + +function pop(r::Relation{ED,TD,N}) where {ED,TD,N} + (;first, last, collid) = r + (last - first <= 0) && throw(ArgumentError("relation must be non-empty")) + relations = EDStore_relations(ED, N, collid) + relations[last] = zero(ObjectID{TD}) + return Relation{ED,TD,N}(first, last-1, collid) end #-------------------------------------------------------------------------------------------------- diff --git a/src/Datatypes.jl b/src/Datatypes.jl index 46dedc0..25c0256 100644 --- a/src/Datatypes.jl +++ b/src/Datatypes.jl @@ -41,13 +41,3 @@ function Base.getproperty(obj::MCParticle, sym::Symbol) return getfield(obj, sym) end end - -#-------------------------------------------------------------------------------------------------- -#----Utility functions for ParticleID-------------------------------------------------------------- -#-------------------------------------------------------------------------------------------------- - -function set_parameters(o::ParticleID, v::AbstractVector{Float32}) - iszero(o.index) && (o = register(o)) - o = @set o.parameters = v - update(o) -end diff --git a/src/EDStore.jl b/src/EDStore.jl index 07acfec..918b88a 100644 --- a/src/EDStore.jl +++ b/src/EDStore.jl @@ -77,6 +77,7 @@ function EDStore_relations(::Type{ED}, N::Int, collid::UInt32=0x00000000) where end store.relations[N] end + function EDStore_pvectors(::Type{ED}, N::Int, collid::UInt32=0x00000000) where ED store = getEDStore(ED, collid) if !isdefined(store, :vmembers) diff --git a/test/runtests.jl b/test/runtests.jl index ab0a5f9..2f2a67d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,6 +6,7 @@ using EDM4hep include("testMCParticle.jl") # one-to-many relation include("testSimTrackerHit.jl") # one-to-one relation include("testParticleID.jl") # vector members + include("testCluster.jl") # several one-to-many and Vector members #---ROOT I/O---------------------- include("testRootReader.jl") # TTree and RNTuple reader end diff --git a/test/testCluster.jl b/test/testCluster.jl new file mode 100644 index 0000000..229bdc2 --- /dev/null +++ b/test/testCluster.jl @@ -0,0 +1,75 @@ +# struct Cluster <: POD +# index::ObjectID{Cluster} # ObjectID of himself +# #---Data Members +# type::Int32 # flagword that defines the type of cluster. Bits 16-31 are used internally. +# energy::Float32 # energy of the cluster [GeV] +# energyError::Float32 # error on the energy +# position::Vector3f # position of the cluster [mm] +# positionError::SVector{6,Float32} # covariance matrix of the position (6 Parameters) +# iTheta::Float32 # intrinsic direction of cluster at position Theta. Not to be confused with direction cluster is seen from IP. +# phi::Float32 # intrinsic direction of cluster at position - Phi. Not to be confused with direction cluster is seen from IP. +# directionError::Vector3f # covariance matrix of the direction (3 Parameters) [mm^2] +# #---VectorMembers +# shapeParameters::PVector{Cluster,Float32,1} # shape parameters - check/set collection parameter ClusterShapeParameters for size and names of parameters. +# subdetectorEnergies::PVector{Cluster,Float32,2} # energy observed in a particular subdetector. Check/set collection parameter ClusterSubdetectorNames for decoding the indices of the array. +# #---OneToManyRelations +# clusters::Relation{Cluster,Cluster,1} # clusters that have been combined to this cluster. +# hits::Relation{Cluster,CalorimeterHit,2} # hits that have been combined to this cluster. +# particleIDs::Relation{Cluster,ParticleID,3} # particle IDs (sorted by their likelihood) +# end + +@testset "Cluster" begin + emptyEDStore() + + h1 = CalorimeterHit(cellID=0x1) |> register + h2 = CalorimeterHit(cellID=0x2) |> register + pid1 = ParticleID(type=1) |> register + pid2 = ParticleID(type=2) |> register + c1 = Cluster(type=1, positionError=(1,2,3,4,5,6), directionError=(1,2,3)) |> register + + @test c1.type == 1 + @test c1.positionError[1] == 1.0 + @test c1.positionError[6] == 6.0 + + @test_throws ArgumentError popFromHits(c1) + + c1 = pushToHits(c1, h1) + c1 = pushToHits(c1, h2) + + @test length(c1.hits) == 2 + c1 = popFromHits(c1) + @test length(c1.hits) == 1 + c1 = popFromHits(c1) + @test length(c1.hits) == 0 + + c1 = pushToHits(c1, h1) + c1 = pushToHits(c1, h2) + + c1 = pushToParticleIDs(c1, pid1) + c1 = pushToParticleIDs(c1, pid2) + @test length(c1.particleIDs) == 2 + @test c1.particleIDs[1].type == 1 + @test c1.particleIDs[2].type == 2 + + c1 = pushToClusters(c1, Cluster(type=2)) + c1 = pushToClusters(c1, Cluster(type=3)) + @test length(c1.clusters) == 2 + @test c1.clusters[1].type == 2 + @test c1.clusters[2].type == 3 + + @test c1.hits[1].cellID == 0x1 + @test c1.hits[2].cellID == 0x2 + + + c1 = setShapeParameters(c1, [1.0f0,2.0f0,3.0f0]) + c1 = setSubdetectorEnergies(c1, [10.0f0,20.0f0,30.0f0]) + @test length(c1.shapeParameters) == 3 + @test length(c1.subdetectorEnergies) == 3 + @test c1.shapeParameters == [1.0f0,2.0f0,3.0f0] + @test c1.subdetectorEnergies == [10.0f0,20.0f0,30.0f0] + + @test length(getEDStore(Cluster).objects) == 3 + @test length(getEDStore(CalorimeterHit).objects) == 2 + @test length(getEDStore(ParticleID).objects) == 2 + +end diff --git a/test/testParticleID.jl b/test/testParticleID.jl index 2265230..3d21951 100644 --- a/test/testParticleID.jl +++ b/test/testParticleID.jl @@ -9,7 +9,7 @@ @test length(pid1.parameters) == 0 @test length(pid2.parameters) == 3 - pid1 = set_parameters(pid1, pid2.parameters) # can we make this more generically? + pid1 = setParameters(pid1, pid2.parameters) # can we make this more generically? @test length(pid1.parameters) == 3 @test pid2.parameters[1] == 1.0f0 From 002d1dde1a8965068f174cf624568c4cb0296885 Mon Sep 17 00:00:00 2001 From: Pere Mato Date: Tue, 6 Feb 2024 01:21:13 +0100 Subject: [PATCH 2/4] removed push for vector members --- src/Components.jl | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Components.jl b/src/Components.jl index 7cf5764..4c8a959 100644 --- a/src/Components.jl +++ b/src/Components.jl @@ -188,19 +188,6 @@ Base.getindex(v::PVector{ED,T, N}, i) where {ED,T, N} = 0 < i <= (v.last - v.fir Base.size(v::PVector{ED,T,N}) where {ED,T,N} = (v.last-v.first,) Base.length(v::PVector{ED,T,N}) where {ED,T,N} = v.last-v.first Base.eltype(::Type{PVector{ED,T,N}}) where {ED,T,N} = T -function push(v::PVector{ED,T,N}, p::T) where {ED,T,N} - pvectors = EDStore_pvectors(ED,N,v.collid) - (;first, last) = v - length = last-first - tail = lastindex(pvectors) - append!(pvectors, zeros(ObjectID{ED}, length+1)) # add extended indices at the end - pvectors[tail + 1:tail + length] = pvectors[first+1:last] # copy indices - pvectors[first + 1:last] .= zeros(ED,length) # reset unused indices - first = tail - last = first + length + 1 - pvectors[last] = p - PVector{ED,T,N}(first, last, v.collid) -end function Base.convert(::Type{PVector{ED,T,N}}, v::AbstractVector{T}) where {ED,T,N} pvectors = EDStore_pvectors(ED,N) tail = lastindex(pvectors) From f65b87cdc4e99b4680166676ab0a22239cd08b16 Mon Sep 17 00:00:00 2001 From: Pere Mato Date: Tue, 6 Feb 2024 02:21:44 +0100 Subject: [PATCH 3/4] See if coverage is display --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1beb457..af10ee0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,8 @@ jobs: uses: codecov/codecov-action@v3 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + file: lcov.info docs: name: Documentation runs-on: ubuntu-latest From fa7e2321120be6416d9c118877bb969adef62643 Mon Sep 17 00:00:00 2001 From: Pere Mato Date: Tue, 6 Feb 2024 02:22:30 +0100 Subject: [PATCH 4/4] change file --- examples/read_reco_rntuple.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/read_reco_rntuple.jl b/examples/read_reco_rntuple.jl index 2f1795d..17420ec 100644 --- a/examples/read_reco_rntuple.jl +++ b/examples/read_reco_rntuple.jl @@ -5,16 +5,17 @@ using EDM4hep.RootIO cd(@__DIR__) #f = "Output_REC_rntuple.root" -f = "Output_REC.root" +#f = "Output_REC.root" +f = "/Users/mato/cernbox/Data/Dirac-Dst-E250-e2e2h_inv.eL.pR_bg-00001.root" reader = RootIO.Reader(f) events = RootIO.get(reader, "events"); evt = events[1]; -tracks = RootIO.get(reader, evt, "SiTracks_Refitted"); -for t in tracks - println("Track $(t.index) with sum(subdet hit numbers) $(sum(t.subdetectorHitNumbers))") +particles = RootIO.get(reader, evt, "PandoraPFOs"); +for p in particles + println("Particle $(p.index) with energy $(p.energy)") end