diff --git a/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.idx b/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.idx similarity index 97% rename from pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.idx rename to pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.idx index 064be2d5..f0ad81a0 100644 Binary files a/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.idx and b/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.idx differ diff --git a/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.pack b/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.pack similarity index 99% rename from pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.pack rename to pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.pack index d6654af6..d3aa6714 100644 Binary files a/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.pack and b/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.pack differ diff --git a/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.rev b/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.rev similarity index 91% rename from pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.rev rename to pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.rev index f42a6f69..e75cea26 100644 Binary files a/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.rev and b/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.rev differ diff --git a/pr-preview/pr-25/js/types/dynamic.js b/pr-preview/pr-25/js/types/dynamic.js new file mode 100644 index 00000000..d06ebace --- /dev/null +++ b/pr-preview/pr-25/js/types/dynamic.js @@ -0,0 +1,15 @@ +export function dynamicLoad(object, data, ignore = null) { + let filteredData = {}; + + if (ignore !== null) { + for (const key in data) { + if (!ignore.has(key)) filteredData[key] = data[key]; + } + } else { + filteredData = data; + } + + for (const [key, value] of Object.entries(filteredData)) { + object[key] = value; + } +} diff --git a/pr-preview/pr-25/js/types/load.js b/pr-preview/pr-25/js/types/load.js index 289c7efe..2ac27473 100644 --- a/pr-preview/pr-25/js/types/load.js +++ b/pr-preview/pr-25/js/types/load.js @@ -1,21 +1,7 @@ import jsonData from "../../input/wzp6_ee_mumuH_ecm240_CLD_RECO.edm4hep.json" assert { type: "json" }; // node 20 -import { - Cluster, - ParticleID, - ReconstructedParticle, - Vertex, - Track, -} from "./reconstruction.js"; +import { types } from "./reconstruction.js"; import { compatible } from "./version.js"; -const types = { - "Cluster": Cluster, - "ParticleID": ParticleID, - "ReconstructedParticle": ReconstructedParticle, - "Vertex": Vertex, - "Track": Track, -}; - const loadersConfig = [ "ReconstructedParticle", "ParticleID", @@ -68,20 +54,4 @@ export function loadParticles(jsonData, event, loadersConfig) { return particles; } -export function dynamicLoad(object, data, ignore = null) { - let filteredData = {}; - - if (ignore !== null) { - for (const key in data) { - if (!ignore.has(key)) filteredData[key] = data[key]; - } - } else { - filteredData = data; - } - - for (const [key, value] of Object.entries(filteredData)) { - object[key] = value; - } -} - loadParticles(jsonData, 0, loadersConfig); diff --git a/pr-preview/pr-25/js/types/reconstruction.js b/pr-preview/pr-25/js/types/reconstruction.js index ae292903..efc3b5cc 100644 --- a/pr-preview/pr-25/js/types/reconstruction.js +++ b/pr-preview/pr-25/js/types/reconstruction.js @@ -1,4 +1,4 @@ -import { dynamicLoad } from "./load.js"; +import { dynamicLoad } from "./dynamic.js"; export class Cluster { static MIN_VERSION = "0.7.0"; // may vary per type of particle @@ -46,7 +46,7 @@ export class ParticleID { constructor() { // Physics properties this.type = 0; - this.pdg = 0; + this.PDG = 0; this.algorithmType = 0; this.likelihood = 0; this.parameters = []; @@ -78,7 +78,7 @@ export class ReconstructedParticle { constructor() { // Physics properties - this.pdg = 0; + this.PDG = 0; this.energy = 0; // GeV this.momentum = {}; // GeV this.referencePoint = {}; // mm @@ -213,7 +213,7 @@ export class GenericLink { } } -function createLinksManager(types) { +export function createLinksManager(types) { const links = {}; types.forEach((type) => (links[type] = [])); return links; @@ -225,7 +225,12 @@ export function createGenericLink(id, from, { collectionID, index }) { return genericLink; } -function extractOneToManyLinks(linksManager, keys, newParticle, particleData) { +export function extractOneToManyLinks( + linksManager, + keys, + newParticle, + particleData +) { for (const key of keys) { particleData[key].map((val) => { const link = createGenericLink( @@ -239,7 +244,12 @@ function extractOneToManyLinks(linksManager, keys, newParticle, particleData) { } } -function extractOneToOneLink(linksManager, key, newParticle, particleData) { +export function extractOneToOneLink( + linksManager, + key, + newParticle, + particleData +) { const link = createGenericLink( linksManager[key].length, newParticle.index, @@ -248,3 +258,11 @@ function extractOneToOneLink(linksManager, key, newParticle, particleData) { linksManager[key].push(link); newParticle[key] = link.id; } + +export const types = { + "Cluster": Cluster, + "ParticleID": ParticleID, + "ReconstructedParticle": ReconstructedParticle, + "Vertex": Vertex, + "Track": Track, +}; diff --git a/pr-preview/pr-25/js/types/version.js b/pr-preview/pr-25/js/types/version.js index dd710ca4..2d1efad8 100644 --- a/pr-preview/pr-25/js/types/version.js +++ b/pr-preview/pr-25/js/types/version.js @@ -12,18 +12,18 @@ export class Version { greaterOrEqualThan(version) { return ( - this.major >= version.major || + this.major > version.major || (this.major === version.major && - (this.minor >= version.minor || + (this.minor > version.minor || (this.minor === version.minor && this.patch >= version.patch))) ); } lessOrEqualThan(version) { return ( - this.major <= version.major || + this.major < version.major || (this.major === version.major && - (this.minor <= version.minor || + (this.minor < version.minor || (this.minor === version.minor && this.patch <= version.patch))) ); } diff --git a/pr-preview/pr-25/test/load.test.js b/pr-preview/pr-25/test/load.test.js index 1f35effe..38f42d24 100644 --- a/pr-preview/pr-25/test/load.test.js +++ b/pr-preview/pr-25/test/load.test.js @@ -1,85 +1,6 @@ import { buildLoader, loadParticles } from "../js/types/load"; - -const data = { - "Event 0": { - "EFlowPhoton": { - "collID": 7, - "collType": "edm4hep::ClusterCollection", - "collection": [ - { - "clusters": [], - "directionError": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - }, - "energy": 6.2020978927612305, - "energyError": 0.0, - "hits": [], - "iTheta": 0.0, - "particleIDs": [], - "phi": 0.0, - "position": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - }, - "positionError": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - "shapeParameters": [], - "subdetectorEnergies": [], - "type": 0, - }, - ], - }, - "ReconstructedParticles": { - "collID": 14, - "collType": "edm4hep::ReconstructedParticleCollection", - "collection": [ - { - "charge": 1.0, - "clusters": [], - "covMatrix": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - "energy": 0.358455091714859, - "goodnessOfPID": 0.0, - "mass": 0.13957038521766663, - "momentum": { - "x": 0.09558331221342087, - "y": -0.11288221180438995, - "z": -0.2951807975769043, - }, - "particleIDUsed": { - "collectionID": -2, - "index": -2, - }, - "particleIDs": [ - { - "collectionID": 4, - "index": 0, - }, - ], - "particles": [], - "referencePoint": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - }, - "startVertex": { - "collectionID": -2, - "index": -2, - }, - "tracks": [ - { - "collectionID": 3, - "index": 0, - }, - ], - "type": 0, - }, - ], - }, - "edm4hepVersion": "0.7.0", - }, -}; +import { dynamicLoad } from "../js/types/dynamic.js"; +import { ReconstructedParticle } from "../js/types/reconstruction"; describe("build loader", () => { it("should create a loader with a set of types", () => { @@ -93,6 +14,91 @@ describe("build loader", () => { }); describe("load different types of particles", () => { + let data = {}; + + beforeAll(() => { + data = { + "Event 0": { + "EFlowPhoton": { + "collID": 7, + "collType": "edm4hep::ClusterCollection", + "collection": [ + { + "clusters": [], + "directionError": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + }, + "energy": 6.2020978927612305, + "energyError": 0.0, + "hits": [], + "iTheta": 0.0, + "particleIDs": [], + "phi": 0.0, + "position": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + }, + "positionError": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + "shapeParameters": [], + "subdetectorEnergies": [], + "type": 0, + }, + ], + }, + "ReconstructedParticles": { + "collID": 14, + "collType": "edm4hep::ReconstructedParticleCollection", + "collection": [ + { + "charge": 1.0, + "clusters": [], + "covMatrix": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + "energy": 0.358455091714859, + "goodnessOfPID": 0.0, + "mass": 0.13957038521766663, + "momentum": { + "x": 0.09558331221342087, + "y": -0.11288221180438995, + "z": -0.2951807975769043, + }, + "particleIDUsed": { + "collectionID": -2, + "index": -2, + }, + "particleIDs": [ + { + "collectionID": 4, + "index": 0, + }, + ], + "particles": [], + "referencePoint": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + }, + "startVertex": { + "collectionID": -2, + "index": -2, + }, + "tracks": [ + { + "collectionID": 3, + "index": 0, + }, + ], + "type": 0, + }, + ], + }, + "edm4hepVersion": "0.7.0", + }, + }; + }); + it("should only load particles of one type", () => { const loadersConfig = "ReconstructedParticle"; @@ -111,3 +117,70 @@ describe("load different types of particles", () => { ); }); }); + +describe("dynamically load an object", () => { + let particleData = {}; + let reconstructedParticle; + + beforeAll(() => { + particleData = { + "PDG": 3, + "charge": 0.0, + "clusters": [], + "covMatrix": { + "values": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + }, + "energy": 9.644623756408691, + "goodnessOfPID": 0.0, + "mass": 0.45484575629234314, + "momentum": { + "x": -4.557793617248535, + "y": -6.684719085693359, + "z": 5.230002403259277, + }, + "particles": [ + { + "collectionID": 4196981182, + "index": 20, + }, + { + "collectionID": 4196981182, + "index": 19, + }, + ], + "referencePoint": { + "x": -1.2017582654953003, + "y": -2.118278741836548, + "z": 1.424477458000183, + }, + "startVertex": { + "collectionID": 4294967295, + "index": -1, + }, + "tracks": [], + }; + }); + + beforeEach(() => { + reconstructedParticle = new ReconstructedParticle(); + reconstructedParticle.index = 0; + }); + + it("should load all the properties of an object", () => { + dynamicLoad(reconstructedParticle, particleData); + + expect(reconstructedParticle).toMatchObject(particleData); + }); + + it("should ignore some properties of an object", () => { + const ignore = new Set(["PDG", "charge", "particles"]); + + dynamicLoad(reconstructedParticle, particleData, ignore); + expect(reconstructedParticle).toMatchObject({ + ...particleData, + PDG: 0, + charge: 0, + particles: [], + }); + }); +}); diff --git a/pr-preview/pr-25/test/reconstruction.test.js b/pr-preview/pr-25/test/reconstruction.test.js new file mode 100644 index 00000000..90278d6f --- /dev/null +++ b/pr-preview/pr-25/test/reconstruction.test.js @@ -0,0 +1,49 @@ +import { + extractOneToManyLinks, + extractOneToOneLink, + createLinksManager, + createGenericLink, + GenericLink, +} from "../js/types/reconstruction.js"; + +test("it should create a generic link", () => { + const link = createGenericLink(1, 2, { collectionID: 3, index: 4 }); + expect(link.id).toBe(1); + expect(link.from).toBe(2); + expect(link.to).toBe(4); + expect(link.collectionID).toBe(3); +}); + +test("it should create a links manager", () => { + const linksManager = createLinksManager(["a", "b"]); + expect(linksManager).toEqual({ a: [], b: [] }); +}); + +test("it should extract one-to-many links", () => { + const linksManager = { a: [], b: [] }; + const keys = ["a", "b"]; + const newParticle = { index: 0, a: [], b: [] }; + const particleData = { + a: [{ collectionID: 1, index: 2 }], + b: [{ collectionID: 3, index: 4 }], + }; + const firstLink = createGenericLink(0, 0, { collectionID: 1, index: 2 }); + const secondLink = createGenericLink(0, 0, { collectionID: 3, index: 4 }); + + extractOneToManyLinks(linksManager, keys, newParticle, particleData); + expect(linksManager).toEqual({ a: [firstLink], b: [secondLink] }); + expect(newParticle.a).toEqual([0]); + expect(newParticle.b).toEqual([0]); +}); + +test("it should extract one-to-one link", () => { + const linksManager = { a: [] }; + const key = "a"; + const newParticle = { index: 0, a: [] }; + const particleData = { a: { collectionID: 1, index: 2 } }; + const link = createGenericLink(0, 0, { collectionID: 1, index: 2 }); + + extractOneToOneLink(linksManager, key, newParticle, particleData); + expect(linksManager).toEqual({ a: [link] }); + expect(newParticle.a).toEqual(0); +}); diff --git a/pr-preview/pr-25/test/version.test.js b/pr-preview/pr-25/test/version.test.js new file mode 100644 index 00000000..dd4063bb --- /dev/null +++ b/pr-preview/pr-25/test/version.test.js @@ -0,0 +1,78 @@ +import { Version, compatible } from "../js/types/version.js"; + +describe("version class methods", () => { + let version; + + beforeAll(() => { + version = new Version("1.12.4"); + }); + + it("should return a string", () => { + expect(version.toString()).toBe("1.12.4"); + }); + + describe("greater version than current", () => { + let greaterVersion; + + beforeAll(() => { + greaterVersion = new Version("1.12.5"); + }); + + it("should return false", () => { + expect(version.greaterOrEqualThan(greaterVersion)).toBe(false); + }); + + it("should return true", () => { + expect(version.lessOrEqualThan(version)).toBe(true); + }); + }); + + describe("smaller version than current", () => { + let lessVersion; + + beforeAll(() => { + lessVersion = new Version("1.5.4"); + }); + + it("should return false", () => { + expect(version.lessOrEqualThan(lessVersion)).toBe(false); + }); + + it("should return true", () => { + expect(version.greaterOrEqualThan(version)).toBe(true); + }); + }); + + it("should return true if version is between", () => { + const version1 = new Version("1.0.0"); + const version2 = new Version("2.0.0"); + + expect(version.isBetween(version1, version2)).toBe(true); + }); + + it("should return false if version is not between", () => { + const version1 = new Version("0.7.0"); + const version2 = new Version("1.12.3"); + + expect(version.isBetween(version1, version2)).toBe(false); + }); +}); + +describe("compatible function", () => { + let type; + + beforeAll(() => { + type = { + MIN_VERSION: "0.7.0", + MAX_VERSION: "1.0.0", + }; + }); + + it("should be compatible", () => { + expect(compatible(type, "0.7.0")).toBe(true); + }); + + it("should not be compatible with a greater version", () => { + expect(compatible(type, "1.0.1")).toBe(false); + }); +});