Skip to content

Commit

Permalink
add filter for particle id
Browse files Browse the repository at this point in the history
  • Loading branch information
brauliorivas committed Aug 9, 2024
1 parent f5380e2 commit 3e4e4d2
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
110 changes: 110 additions & 0 deletions js/filters/collections/particleid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import {
CheckboxComponent,
checkboxLogic,
objectSatisfiesCheckbox,
} from "../components/checkbox.js";
import {
addCollectionTitle,
collectionFilterContainer,
createCheckboxContainer,
createCollectionSubtitle,
createSubContainer,
} from "../components/lib.js";

function renderParticleIdFilters(viewObjects) {
const container = collectionFilterContainer();
const title = addCollectionTitle("Particle ID");
container.appendChild(title);

const checkboxes = {
type: [],
pdg: [],
algorithmType: [],
};

const typeContainer = createSubContainer();
const typeTitle = createCollectionSubtitle("Type");
typeContainer.appendChild(typeTitle);
const typeCheckboxesContainer = createCheckboxContainer();
const typeSet = new Set();
viewObjects.datatypes["edm4hep::ParticleID"].collection.forEach(
(particleId) => typeSet.add(particleId.type)
);
typeSet.forEach((type) => {
const checkbox = new CheckboxComponent("type", type, type, true);
checkboxes.type.push(checkbox);
typeCheckboxesContainer.appendChild(checkbox.render());
});
typeContainer.appendChild(typeCheckboxesContainer);

const pdgContainer = createSubContainer();
const pdgTitle = createCollectionSubtitle("PDG");
pdgContainer.appendChild(pdgTitle);
const pdgCheckboxesContainer = createCheckboxContainer();
const pdgSet = new Set();
viewObjects.datatypes["edm4hep::ParticleID"].collection.forEach(
(particleId) => pdgSet.add(particleId.PDG)
);
pdgSet.forEach((pdg) => {
const checkbox = new CheckboxComponent("PDG", pdg, pdg, true);
checkboxes.pdg.push(checkbox);
pdgCheckboxesContainer.appendChild(checkbox.render());
});
pdgContainer.appendChild(pdgCheckboxesContainer);

const algorithmTypeContainer = createSubContainer();
const algorithmTypeTitle = createCollectionSubtitle("Algorithm Type");
algorithmTypeContainer.appendChild(algorithmTypeTitle);
const algorithmTypeCheckboxesContainer = createCheckboxContainer();
const algorithmTypeSet = new Set();
viewObjects.datatypes["edm4hep::ParticleID"].collection.forEach(
(particleId) => algorithmTypeSet.add(particleId.algorithmType)
);
algorithmTypeSet.forEach((algorithmType) => {
const checkbox = new CheckboxComponent(
"algorithmType",
algorithmType,
algorithmType,
true
);
checkboxes.algorithmType.push(checkbox);
algorithmTypeCheckboxesContainer.appendChild(checkbox.render());
});
algorithmTypeContainer.appendChild(algorithmTypeCheckboxesContainer);

container.appendChild(typeContainer);
container.appendChild(pdgContainer);
container.appendChild(algorithmTypeContainer);

return {
container,
filters: {
checkboxes,
},
};
}

export function initParticleIdFilters(parentContainer, viewObjects) {
const { container, filters } = renderParticleIdFilters(viewObjects);
const { checkboxes } = filters;

parentContainer.appendChild(container);

const criteriaFunction = (particleId) => {
let satisfies = true;

Object.values(checkboxes).forEach((checkboxes) => {
const res = objectSatisfiesCheckbox(
particleId,
checkboxes,
checkboxes[0].propertyName,
checkboxLogic
);
satisfies = satisfies && res;
});

return satisfies;
};

return criteriaFunction;
}
2 changes: 2 additions & 0 deletions js/filters/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { setScroll, setScrollBarsPosition } from "../draw/scroll.js";
import { copyObject } from "../lib/copy.js";
import { initClusterFilters } from "./collections/cluster.js";
import { initMCParticleFilters } from "./collections/mcparticle.js";
import { initParticleIdFilters } from "./collections/particleid.js";
import { initRecoParticleFilters } from "./collections/recoparticle.js";
import { initTrackFilters } from "./collections/track.js";
import { initVertexFilters } from "./collections/vertex.js";
Expand All @@ -14,6 +15,7 @@ const map = {
"edm4hep::Cluster": initClusterFilters,
"edm4hep::Track": initTrackFilters,
"edm4hep::Vertex": initVertexFilters,
"edm4hep::ParticleID": initParticleIdFilters,
};

const openFiltersButton = document.getElementById("open-filter");
Expand Down

0 comments on commit 3e4e4d2

Please sign in to comment.