Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to filter by collection name of the object #76

Merged
merged 10 commits into from
Aug 19, 2024
17 changes: 17 additions & 0 deletions css/filter.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,20 @@
.filter-checkbox {
margin: 2px;
}

.collection-checkboxes-handler {
display: flex;
flex-direction: row;
justify-content: space-between;
}

.checkbox-button {
padding: 4px;
margin: 0 5px;
border: 1px solid #000;
border-radius: 5px;
}

.checkbox-button:hover {
background-color: #c5c5c5;
}
31 changes: 27 additions & 4 deletions js/filters/collections/cluster.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import {
checkboxLogic,
objectSatisfiesCheckbox,
} from "../components/checkbox.js";
import { buildCollectionCheckboxes } from "../components/common.js";
import {
addCollectionTitle,
collectionFilterContainer,
} from "../components/lib.js";
import { magnitudeRangeLogic, RangeComponent } from "../components/range.js";
import { rangeLogic } from "../components/range.js";

function renderClusterFilters() {
function renderClusterFilters(viewObjects) {
const container = collectionFilterContainer();
const title = addCollectionTitle("Cluster");
container.appendChild(title);

const position = new RangeComponent("position", "position", "mm");
const energy = new RangeComponent("energy", "energy", "GeV");

const [collectionNamesContainer, collectionCheckboxes] =
buildCollectionCheckboxes(
viewObjects.datatypes["edm4hep::Cluster"].collection
);

container.appendChild(collectionNamesContainer);
container.appendChild(position.render());
container.appendChild(energy.render());

Expand All @@ -21,13 +32,14 @@ function renderClusterFilters() {
filters: {
position,
energy,
collectionCheckboxes,
},
};
}

export function initClusterFilters(parentContainer) {
const { container, filters } = renderClusterFilters();
const { position, energy } = filters;
export function initClusterFilters(parentContainer, viewObjects) {
const { container, filters } = renderClusterFilters(viewObjects);
const { position, energy, collectionCheckboxes } = filters;

parentContainer.appendChild(container);

Expand All @@ -43,6 +55,17 @@ export function initClusterFilters(parentContainer) {
return false;
}

if (
!objectSatisfiesCheckbox(
object,
collectionCheckboxes,
"collectionName",
checkboxLogic
)
) {
return false;
}

return true;
};

Expand Down
55 changes: 41 additions & 14 deletions js/filters/collections/mcparticle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
CheckboxComponent,
checkboxLogic,
bitfieldCheckboxLogic,
objectSatisfiesCheckbox,
} from "../components/checkbox.js";
Expand All @@ -13,6 +12,10 @@ import {
createCollectionSubtitle,
createSubContainer,
} from "../components/lib.js";
import {
buildCollectionCheckboxes,
filterOutByNormalCheckboxes,
} from "../components/common.js";

function renderMCParticleFilters(viewObjects) {
const container = collectionFilterContainer();
Expand Down Expand Up @@ -42,14 +45,18 @@ function renderMCParticleFilters(viewObjects) {
simStatusContainer.appendChild(simStatusTitle);
const simStatusCheckboxesContainer = createCheckboxContainer();

Object.keys(SimStatusBitFieldDisplayValues).forEach((status) => {
const checkbox = new CheckboxComponent(
"simulatorStatus",
status,
SimStatusBitFieldDisplayValues[status]
);
Object.entries(SimStatusBitFieldDisplayValues).forEach(([status, value]) => {
const checkbox = new CheckboxComponent("simulatorStatus", status, value);
checkboxes.simStatus.push(checkbox);
simStatusCheckboxesContainer.appendChild(checkbox.render());

viewObjects.datatypes["edm4hep::MCParticle"].collection.forEach(
(mcparticle) => {
if (bitfieldCheckboxLogic(value, mcparticle, "simulatorStatus")) {
checkbox.checked(true);
}
}
);
});
simStatusContainer.appendChild(simStatusCheckboxesContainer);

Expand All @@ -72,11 +79,19 @@ function renderMCParticleFilters(viewObjects) {
);
checkboxes.generatorStatus.push(checkbox);
genStatusCheckboxesContainer.appendChild(checkbox.render());
checkbox.checked(true);
});
generatorStatusContainer.appendChild(genStatusCheckboxesContainer);

const [collectionNamesContainer, collectionCheckboxes] =
buildCollectionCheckboxes(
viewObjects.datatypes["edm4hep::MCParticle"].collection
);
checkboxes.collectionNames = collectionCheckboxes;

container.appendChild(simStatusContainer);
container.appendChild(generatorStatusContainer);
container.appendChild(collectionNamesContainer);

return {
container,
Expand All @@ -101,22 +116,34 @@ export function initMCParticleFilters(parentContainer, viewObjects) {
}
}

const { simStatus, generatorStatus } = checkboxes;
const { simStatus, generatorStatus, collectionNames } = checkboxes;

let areSimStatusChecked = false;

simStatus.forEach((checkbox) => {
const { checked } = checkbox.getValues();

if (checked) {
areSimStatusChecked = true;
}
});

const someSimStatusCheckbox = objectSatisfiesCheckbox(
object,
simStatus,
"simulatorStatus",
bitfieldCheckboxLogic
);
const someGenStatusCheckbox = objectSatisfiesCheckbox(
object,
const normalCheckboxes = filterOutByNormalCheckboxes(object, [
generatorStatus,
"generatorStatus",
checkboxLogic
);
collectionNames,
]);

return someSimStatusCheckbox && someGenStatusCheckbox;
if (areSimStatusChecked) {
return someSimStatusCheckbox && normalCheckboxes;
} else {
return normalCheckboxes;
}
};

return criteriaFunction;
Expand Down
25 changes: 12 additions & 13 deletions js/filters/collections/particleid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {
checkboxLogic,
objectSatisfiesCheckbox,
} from "../components/checkbox.js";
import {
buildCollectionCheckboxes,
filterOutByNormalCheckboxes,
} from "../components/common.js";
import {
addCollectionTitle,
collectionFilterContainer,
Expand Down Expand Up @@ -72,9 +76,16 @@ function renderParticleIdFilters(viewObjects) {
});
algorithmTypeContainer.appendChild(algorithmTypeCheckboxesContainer);

const [collectionNamesContainer, collectionCheckboxes] =
buildCollectionCheckboxes(
viewObjects.datatypes["edm4hep::ParticleID"].collection
);
checkboxes.collectionNames = collectionCheckboxes;

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

return {
container,
Expand All @@ -91,19 +102,7 @@ export function initParticleIdFilters(parentContainer, viewObjects) {
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 filterOutByNormalCheckboxes(particleId, Object.values(checkboxes));
};

return criteriaFunction;
Expand Down
44 changes: 38 additions & 6 deletions js/filters/collections/recoparticle.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import {
checkboxLogic,
objectSatisfiesCheckbox,
} from "../components/checkbox.js";
import { buildCollectionCheckboxes } from "../components/common.js";
import {
addCollectionTitle,
collectionFilterContainer,
} from "../components/lib.js";
import { RangeComponent } from "../components/range.js";
import { magnitudeRangeLogic, RangeComponent } from "../components/range.js";
import { rangeLogic } from "../components/range.js";

function renderRecoParticleFilters() {
function renderRecoParticleFilters(viewObjects) {
const container = collectionFilterContainer();
const title = addCollectionTitle("Reconstructed Particle");
container.appendChild(title);
Expand All @@ -14,23 +19,34 @@ function renderRecoParticleFilters() {
const charge = new RangeComponent("charge", "charge", "e");
const momentum = new RangeComponent("momentum", "momentum", "GeV");

const range = [energy, charge, momentum];
const range = [energy, charge];

range.forEach((rangeFilter) => {
container.appendChild(rangeFilter.render());
});

container.appendChild(momentum.render());

const [collectionNamesContainer, collectionCheckboxes] =
buildCollectionCheckboxes(
viewObjects.datatypes["edm4hep::ReconstructedParticle"].collection
);

container.appendChild(collectionNamesContainer);

return {
container,
filters: {
range,
collectionCheckboxes,
momentum,
},
};
}

export function initRecoParticleFilters(parentContainer) {
const { container, filters } = renderRecoParticleFilters();
const { range } = filters;
export function initRecoParticleFilters(parentContainer, viewObjects) {
const { container, filters } = renderRecoParticleFilters(viewObjects);
const { range, collectionCheckboxes, momentum } = filters;

parentContainer.appendChild(container);

Expand All @@ -43,6 +59,22 @@ export function initRecoParticleFilters(parentContainer) {
}
}

const { min, max } = momentum.getValues();
if (!magnitudeRangeLogic(min, max, object, "momentum")) {
return false;
}

if (
!objectSatisfiesCheckbox(
object,
collectionCheckboxes,
"collectionName",
checkboxLogic
)
) {
return false;
}

return true;
};

Expand Down
31 changes: 27 additions & 4 deletions js/filters/collections/track.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import {
checkboxLogic,
objectSatisfiesCheckbox,
} from "../components/checkbox.js";
import { buildCollectionCheckboxes } from "../components/common.js";
import {
addCollectionTitle,
collectionFilterContainer,
} from "../components/lib.js";
import { RangeComponent, rangeLogic } from "../components/range.js";

function renderTrackFilters() {
function renderTrackFilters(viewObjects) {
const container = collectionFilterContainer();
const title = addCollectionTitle("Track");
container.appendChild(title);
Expand All @@ -13,17 +18,24 @@ function renderTrackFilters() {

container.appendChild(chiNdf.render());

const [collectionNamesContainer, collectionCheckboxes] =
buildCollectionCheckboxes(
viewObjects.datatypes["edm4hep::Track"].collection
);
container.appendChild(collectionNamesContainer);

return {
container,
filters: {
chiNdf,
collectionCheckboxes,
},
};
}

export function initTrackFilters(parentContainer) {
const { container, filters } = renderTrackFilters();
const { chiNdf } = filters;
export function initTrackFilters(parentContainer, viewObjects) {
const { container, filters } = renderTrackFilters(viewObjects);
const { chiNdf, collectionCheckboxes } = filters;

parentContainer.appendChild(container);

Expand All @@ -34,6 +46,17 @@ export function initTrackFilters(parentContainer) {
return false;
}

if (
!objectSatisfiesCheckbox(
object,
collectionCheckboxes,
"collectionName",
checkboxLogic
)
) {
return false;
}

return true;
};

Expand Down
Loading
Loading