Skip to content

Commit

Permalink
reconnect mcparticle tree, go to level where objects aren't filtered
Browse files Browse the repository at this point in the history
  • Loading branch information
brauliorivas committed Aug 15, 2024
1 parent 6a7bcdb commit dd28210
Showing 1 changed file with 55 additions and 66 deletions.
121 changes: 55 additions & 66 deletions js/filters/reconnect/mcparticletree.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,78 @@
import { linkTypes } from "../../types/links.js";

const findParentRow = (object, uniqueRows, rowToIndex) => {
const thisRowIndex = rowToIndex[object.row];
if (thisRowIndex > 0 && thisRowIndex < uniqueRows.length) {
return uniqueRows[thisRowIndex - 1];
const findParticles = (otherObject, relationName, ids) => {
let oneToManyRelations;
if (otherObject.relations) {
oneToManyRelations = otherObject.relations.oneToManyRelations;
} else {
oneToManyRelations = otherObject.oneToManyRelations;
}
return NaN;
};

const findDaughterRow = (object, uniqueRows, rowToIndex) => {
const thisRowIndex = rowToIndex[object.row];
if (thisRowIndex >= 0 && thisRowIndex < uniqueRows.length - 1) {
return uniqueRows[thisRowIndex + 1];
}
return NaN;
};

export function reconnectMCParticleTree(viewCurrentObjects, ids) {
const { collection, oneToMany } =
viewCurrentObjects.datatypes["edm4hep::MCParticle"];
const relations = oneToManyRelations[relationName];

const sortedCollection = collection.sort((a, b) => a.row - b.row);
if (relations.length === 0) return [];

// const beginRowsIndex = {};
// sortedCollection.forEach((object, index) => {
// if (beginRowsIndex[object.row] === undefined) {
// beginRowsIndex[object.row] = index;
// }
// });
let hasAny = 0;

// const rows = sortedCollection.map((object) => object.row);
// const uniqueRows = [...new Set(rows)];
relations.forEach((object) =>
ids.has(`${object.index}-${object.collectionId}`) ? (hasAny += 1) : null
);

// const rowToIndex = {};
// for (const [index, row] of uniqueRows.entries()) {
// rowToIndex[row] = index;
// }

// const rowToObjectsCount = {};
return hasAny > 0
? relations
: relations
.map((parentLink) => findParticles(parentLink.to, relationName, ids))
.flat();
};

// sortedCollection.forEach((object) => {
// if (rowToObjectsCount[object.row] === undefined) {
// rowToObjectsCount[object.row] = 1;
// return;
// }
// rowToObjectsCount[object.row] += 1;
// });
export function reconnectMCParticleTree(viewCurrentObjects, ids) {
const { collection, oneToMany } =
viewCurrentObjects.datatypes["edm4hep::MCParticle"];

for (const object of sortedCollection) {
for (const object of collection) {
const { oneToManyRelations } = object;
object.saveRelations();

const parentRelations = oneToManyRelations["parents"];
const daughterRelations = oneToManyRelations["daughters"];

object.oneToManyRelations = {
"parents": [],
"daughters": [],
};

// const parentRow = findParentRow(object, uniqueRows, rowToIndex);
// if (parentRow !== NaN) {
// const beginIndex = beginRowsIndex[parentRow];
// const endIndex = beginIndex + rowToObjectsCount[parentRow];
for (const parentRelation of parentRelations) {
const parent = parentRelation.to;
const parentIndex = `${parent.index}-${parent.collectionId}`;

// for (let i = beginIndex; i < endIndex; i++) {
// const newParentLink = new linkTypes["parents"](
// object,
// sortedCollection[i]
// );
// object.oneToManyRelations["parents"].push(newParentLink);
// oneToMany["parents"].push(newParentLink);
// }
// }
if (ids.has(parentIndex)) {
object.oneToManyRelations["parents"].push(parentRelation);
oneToMany["parents"].push(parentRelation);
} else {
const newParents = findParticles(parent, "parents", ids);
for (const newParent of newParents) {
const link = new linkTypes["parents"](object, newParent);
object.oneToManyRelations["parents"].push(link);
oneToMany["parents"].push(link);
}
}
}

// const daughterRow = findDaughterRow(object, uniqueRows, rowToIndex);
// if (daughterRow !== NaN) {
// const beginIndex = beginRowsIndex[daughterRow];
// const endIndex = beginIndex + rowToObjectsCount[daughterRow];
for (const daughterRelation of daughterRelations) {
const daughter = daughterRelation.to;
const daughterIndex = `${daughter.index}-${daughter.collectionId}`;

// for (let i = beginIndex; i < endIndex; i++) {
// const newDaughterLink = new linkTypes["daughters"](
// object,
// sortedCollection[i]
// );
// object.oneToManyRelations["daughters"].push(newDaughterLink);
// oneToMany["daughters"].push(newDaughterLink);
// }
// }
if (ids.has(daughterIndex)) {
object.oneToManyRelations["daughters"].push(daughterRelation);
oneToMany["daughters"].push(daughterRelation);
} else {
const newDaughters = findParticles(daughter, "daughters", ids);
for (const newDaughter of newDaughters) {
const link = new linkTypes["daughters"](object, newDaughter);
object.oneToManyRelations["daughters"].push(link);
oneToMany["daughters"].push(link);
}
}
}
}
}

0 comments on commit dd28210

Please sign in to comment.