diff --git a/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.idx b/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.idx similarity index 98% rename from pr-preview/pr-70/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.idx rename to pr-preview/pr-70/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.idx index a115939c..f0ad81a0 100644 Binary files a/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.idx and b/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.idx differ diff --git a/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.pack b/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.pack similarity index 99% rename from pr-preview/pr-70/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.pack rename to pr-preview/pr-70/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.pack index 32e760c1..d3aa6714 100644 Binary files a/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.pack and b/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.pack differ diff --git a/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.rev b/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.rev similarity index 91% rename from pr-preview/pr-70/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.rev rename to pr-preview/pr-70/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.rev index e8974c33..e75cea26 100644 Binary files a/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-fd5e4e256db2022cde860fee7431094e5989400b.rev and b/pr-preview/pr-70/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.rev differ diff --git a/pr-preview/pr-70/test/filter.json b/pr-preview/pr-70/test/filter.json new file mode 100644 index 00000000..19340e02 --- /dev/null +++ b/pr-preview/pr-70/test/filter.json @@ -0,0 +1,94 @@ +{ + "Event 0": { + "Collection": { + "collID": 0, + "collType": "edm4hep::MCParticleCollection", + "collection": [ + { + "momentum": 0, + "charge": 0, + "mass": 0, + "simulatorStatus": 70, + "parents": [], + "daughters": [ + { + "collectionID": 0, + "index": 1 + } + ] + }, + { + "momentum": 100, + "charge": 1, + "mass": 10, + "simulatorStatus": 24, + "daughters": [ + { + "collectionID": 0, + "index": 3 + } + ], + "parents": [ + { + "collectionID": 0, + "index": 0 + } + ] + }, + { + "momentum": 200, + "charge": 2, + "mass": 20, + "simulatorStatus": 25, + "daughters": [ + { + "collectionID": 0, + "index": 4 + } + ], + "parents": [ + { + "collectionID": 0, + "index": 0 + } + ] + }, + { + "momentum": 300, + "charge": 3, + "mass": 30, + "simulatorStatus": 26, + "daughters": [ + { + "collectionID": 0, + "index": 4 + } + ], + "parents": [ + { + "collectionID": 0, + "index": 1 + } + ] + }, + { + "momentum": 400, + "charge": 4, + "mass": 40, + "simulatorStatus": 27, + "parents": [ + { + "collectionID": 0, + "index": 2 + }, + { + "collectionID": 0, + "index": 3 + } + ], + "daughters": [] + } + ] + } + } +} \ No newline at end of file diff --git a/pr-preview/pr-70/test/filterMCParticle.test.js b/pr-preview/pr-70/test/filterMCParticle.test.js index 51480cce..e9eac78b 100644 --- a/pr-preview/pr-70/test/filterMCParticle.test.js +++ b/pr-preview/pr-70/test/filterMCParticle.test.js @@ -1,245 +1,44 @@ -// import { reconnect } from "../js/menu/filter/reconnect.js"; -// import { loadObjects } from "../js/types/load.js"; -// import { -// Range, -// Checkbox, -// buildCriteriaFunction, -// } from "../js/menu/filter/parameters.js"; - -// let objects = {}; - -// const data = { -// "Event 0": { -// "Collection": { -// "collID": 0, -// "collType": "edm4hep::MCParticleCollection", -// "collection": [ -// { -// "momentum": 0, -// "charge": 0, -// "mass": 0, -// "simulatorStatus": 70, -// "parents": [], -// "daughters": [ -// { -// "collectionID": 0, -// "index": 1, -// }, -// ], -// }, -// { -// "momentum": 100, -// "charge": 1, -// "mass": 10, -// "simulatorStatus": 24, -// "daughters": [ -// { -// "collectionID": 0, -// "index": 3, -// }, -// ], -// "parents": [ -// { -// "collectionID": 0, -// "index": 0, -// }, -// ], -// }, -// { -// "momentum": 200, -// "charge": 2, -// "mass": 20, -// "simulatorStatus": 25, -// "daughters": [ -// { -// "collectionID": 0, -// "index": 4, -// }, -// ], -// "parents": [ -// { -// "collectionID": 0, -// "index": 0, -// }, -// ], -// }, -// { -// "momentum": 300, -// "charge": 3, -// "mass": 30, -// "simulatorStatus": 26, -// "daughters": [ -// { -// "collectionID": 0, -// "index": 4, -// }, -// ], -// "parents": [ -// { -// "collectionID": 0, -// "index": 1, -// }, -// ], -// }, -// { -// "momentum": 400, -// "charge": 4, -// "mass": 40, -// "simulatorStatus": 27, -// "parents": [ -// { -// "collectionID": 0, -// "index": 2, -// }, -// { -// "collectionID": 0, -// "index": 3, -// }, -// ], -// "daughters": [], -// }, -// ], -// }, -// }, -// }; - -// beforeAll(() => { -// objects = loadObjects(data, 0, ["edm4hep::MCParticle"]); -// }); - -// describe("filter by ranges", () => { -// it("filter by a single range parameter", () => { -// const momentum = new Range({ -// property: "momentum", -// unit: "GeV", -// }); -// momentum.min = 300; -// momentum.max = 1000; -// const rangeFilters = Range.buildFilter([momentum]); -// const criteriaFunction = buildCriteriaFunction(rangeFilters); - -// const filteredObjects = reconnect(criteriaFunction, objects); - -// expect( -// filteredObjects.datatypes["edm4hep::MCParticle"].collection.map( -// (mcParticle) => mcParticle.index -// ) -// ).toEqual([3, 4]); -// }); - -// it("filter by a combination of ranges", () => { -// const charge = new Range({ -// property: "charge", -// unit: "e", -// }); -// charge.min = 3; -// const mass = new Range({ -// property: "mass", -// unit: "GeV", -// }); -// mass.min = 20; -// mass.max = 40; -// const rangeFilters = Range.buildFilter([mass, charge]); -// const criteriaFunction = buildCriteriaFunction(rangeFilters); - -// const filteredObjects = reconnect(criteriaFunction, objects); - -// expect( -// filteredObjects.datatypes["edm4hep::MCParticle"].collection.map( -// (mcParticle) => mcParticle.index -// ) -// ).toEqual([3, 4]); -// }); -// }); - -// describe("filter by checkboxes", () => { -// it("filter by a single checkbox", () => { -// const simulatorStatus = new Checkbox("simulatorStatus", 23); -// simulatorStatus.checked = true; -// const checkboxFilters = Checkbox.buildFilter([simulatorStatus]); -// const criteriaFunction = buildCriteriaFunction(checkboxFilters); - -// const filteredObjects = reconnect(criteriaFunction, objects); - -// expect( -// filteredObjects.datatypes["edm4hep::MCParticle"].collection.map( -// (mcParticle) => mcParticle.index -// ) -// ).toEqual([]); -// }); - -// it("filter by a combination of checkboxes", () => { -// const simulatorStatus1 = new Checkbox("simulatorStatus", 23); -// simulatorStatus1.checked = true; -// const simulatorStatus2 = new Checkbox("simulatorStatus", 26); -// simulatorStatus2.checked = true; -// const simulatorStatus3 = new Checkbox("simulatorStatus", 27); -// simulatorStatus3.checked = true; -// const checkboxFilters = Checkbox.buildFilter([ -// simulatorStatus1, -// simulatorStatus2, -// simulatorStatus3, -// ]); -// const criteriaFunction = buildCriteriaFunction(checkboxFilters); - -// const filteredObjects = reconnect(criteriaFunction, objects); - -// expect( -// filteredObjects.datatypes["edm4hep::MCParticle"].collection.map( -// (mcParticle) => mcParticle.index -// ) -// ).toEqual([3, 4]); -// }); -// }); - -// describe("filter by ranges and checkboxes", () => { -// it("show all particles when no kind of filter is applied", () => { -// const charge = new Range({ -// property: "charge", -// unit: "e", -// }); -// const simulatorStatus = new Checkbox("simulatorStatus", 26); -// const rangeFilters = Range.buildFilter([charge]); -// const checkboxFilters = Checkbox.buildFilter([simulatorStatus]); -// const criteriaFunction = buildCriteriaFunction( -// rangeFilters, -// checkboxFilters -// ); +import { loadObjects } from "../js/types/load.js"; +import { filterOut } from "../js/filters/filter-out.js"; +import data from "./filter.json" assert { type: "json" }; + +let objects = {}; + +const range = { + "edm4hep::MCParticle": (object) => + object.momentum >= 300 && + object.momentum <= 1000 && + object.mass >= 20 && + object.mass <= 30, +}; + +const checkboxes = { + "edm4hep::MCParticle": (object) => + object.simulatorStatus === 24 || object.simulatorStatus === 26, +}; + +const all = { + "edm4hep::MCParticle": () => true, +}; + +beforeAll(() => { + objects = loadObjects(data, 0, ["edm4hep::MCParticle"]); +}); -// const filteredObjects = reconnect(criteriaFunction, objects); +test("filter by ranges", () => { + const ids = filterOut(objects, {}, range); -// expect( -// filteredObjects.datatypes["edm4hep::MCParticle"].collection.map( -// (mcParticle) => mcParticle.index -// ) -// ).toEqual([0, 1, 2, 3, 4]); -// }); + expect(ids).toEqual(new Set(["3-0"])); +}); -// it("filter by a combination of ranges and checkboxes", () => { -// const charge = new Range({ -// property: "charge", -// unit: "e", -// }); -// charge.max = 3; -// const simulatorStatus = new Checkbox("simulatorStatus", 23); -// simulatorStatus.checked = true; -// const rangeFilters = Range.buildFilter([charge]); -// const checkboxFilters = Checkbox.buildFilter([simulatorStatus]); -// const criteriaFunction = buildCriteriaFunction( -// rangeFilters, -// checkboxFilters -// ); +test("filter by property equality", () => { + const ids = filterOut(objects, {}, checkboxes); -// const filteredObjects = reconnect(criteriaFunction, objects); + expect(ids).toEqual(new Set(["1-0", "3-0"])); +}); -// expect( -// filteredObjects.datatypes["edm4hep::MCParticle"].collection.map( -// (mcParticle) => mcParticle.index -// ) -// ).toEqual([]); -// }); -// }); +test("filter by function that allows all objects", () => { + const ids = filterOut(objects, {}, all); -test("placeholder", () => { - expect(1).toBe(1); + expect(ids).toEqual(new Set(["0-0", "1-0", "2-0", "3-0", "4-0"])); });