diff --git a/js/types/Cluster.js b/js/types/Cluster.js deleted file mode 100644 index a1d842aa..00000000 --- a/js/types/Cluster.js +++ /dev/null @@ -1,17 +0,0 @@ -export class Cluster { - constructor() { - // Physics properties - this.type = 0; - this.energy = 0; // GeV - this.energyError = 0; // GeV - this.position = []; // mm - this.positionError = []; - this.iTheta = 0; - this.phi = 0; - this.directionError; // mm^2 - this.shapeParameters = []; - this.subdetectorEnergies = []; - this.clusters = []; - this.hits = []; - } -} diff --git a/js/types/ParticleID.js b/js/types/ParticleID.js deleted file mode 100644 index 69f5e890..00000000 --- a/js/types/ParticleID.js +++ /dev/null @@ -1,10 +0,0 @@ -export class ParticleID { - constructor() { - // Physics properties - this.type = 0; - this.pdg = 0; - this.algorithmType = 0; - this.likelihood = 0; - this.parameters = []; - } -} diff --git a/js/types/RecoParticle.js b/js/types/RecoParticle.js deleted file mode 100644 index 4f68b320..00000000 --- a/js/types/RecoParticle.js +++ /dev/null @@ -1,17 +0,0 @@ -export class ReconstructedParticle { - constructor() { - // Physics properties - this.pdg = 0; - this.energy = 0; // GeV - this.momentum = 0; // GeV - this.referencePoint = 0; // mm - this.charge = 0; - this.mass = 0; // GeV - this.goodnessOfPID = 0; - this.covMatrix = []; - this.startVertex = []; - this.clusters = []; - this.tracks = []; - this.particles = []; - } -} diff --git a/js/types/Track.js b/js/types/Track.js deleted file mode 100644 index 5a910826..00000000 --- a/js/types/Track.js +++ /dev/null @@ -1,15 +0,0 @@ -export class Track { - constructor() { - // Physics properties - this.type = 0; - this.chi2 = 0; - this.ndf = 0; - this.dEdx = 0; - this.dEdxError = 0; - this.radiusOfInnermostHit = 0; - this.subdetectorHitNumbers = []; - this.dxQuantities = []; - this.trackerHits = []; - this.tracks = []; - } -} diff --git a/js/types/Vertex.js b/js/types/Vertex.js deleted file mode 100644 index d954723c..00000000 --- a/js/types/Vertex.js +++ /dev/null @@ -1,13 +0,0 @@ -export class Vertex { - constructor() { - // Physics properties - this.primary = 0; - this.chi2 = 0; - this.probability = 0; - this.position = 0; // mm - this.covMatrix = []; - this.algorithmType = 0; - this.parameters = 0; - this.associatedParticles = []; - } -} diff --git a/js/types/load.js b/js/types/load.js new file mode 100644 index 00000000..7c88b530 --- /dev/null +++ b/js/types/load.js @@ -0,0 +1,62 @@ +import jsonData from "../../input/p8_ee_ZH_ecm240_edm4hep.edm4hep.json" assert { type: "json" }; // node 20 +import { + Cluster, + ParticleID, + ReconstructedParticle, + Vertex, + Track, +} from "./reconstruction.js"; + +const loaders = { + ReconstructedParticle: ReconstructedParticle.load, + ParticleID: ParticleID.load, + Vertex: Vertex.load, + Track: Track.load, + Cluster: Cluster.load, +}; + +const loadersConfig = [ + "ReconstructedParticle", + "ParticleID", + "Vertex", + "Track", + "Cluster", +]; + +function selectedParticles(loaders, particles) { + let newLoader = {}; + + for (const particle of particles) { + if (loaders.hasOwnProperty(particle)) { + newLoader[particle] = loaders[particle]; + } + } + + return newLoader; +} + +export function loadParticles(event, loadersConfig) { + const eventData = Object.values(jsonData["Event " + event]); + + const particles = []; + + const loader = selectedParticles(loaders, loadersConfig); + + for (const [type, loadFunction] of Object.entries(loader)) { + const particlesType = eventData.filter( + (element) => element.collType === `edm4hep::${type}Collection` + ); + + particlesType.forEach((collection) => { + const loadedParticles = loadFunction(collection.collection); + }); + } + try { + } catch (error) { + console.error(error); + } + + return particles; +} + +loadParticles(4, loadersConfig); diff --git a/js/types/reconstruction.js b/js/types/reconstruction.js new file mode 100644 index 00000000..f072440f --- /dev/null +++ b/js/types/reconstruction.js @@ -0,0 +1,175 @@ +export class Cluster { + constructor() { + // Physics properties + this.type = 0; + this.energy = 0; // GeV + this.energyError = 0; // GeV + this.position = []; // mm + this.positionError = []; + this.iTheta = 0; + this.phi = 0; + this.directionError = {}; // mm^2 + this.shapeParameters = []; + this.subdetectorEnergies = []; + this.clusters = []; + this.hits = []; + } + + static load(collection) { + const particles = []; + + for (const [index, particle] of collection.entries()) { + const cluster = new Cluster(); + cluster.index = index; + + cluster.type = particle.type; + cluster.energy = particle.energy; + cluster.energyError = particle.energyError; + cluster.position = particle.position; + cluster.positionError = particle.positionError; + cluster.iTheta = particle.iTheta; + cluster.phi = particle.phi; + cluster.directionError = particle.directionError; + cluster.shapeParameters = particle.shapeParameters; + cluster.subdetectorEnergies = particle.subdetectorEnergies; + cluster.clusters = particle.clusters; + cluster.hits = particle.hits; + + particles.push(cluster); + } + + return particles; + } +} + +export class ParticleID { + constructor() { + // Physics properties + this.type = 0; + this.pdg = 0; + this.algorithmType = 0; + this.likelihood = 0; + this.parameters = []; + this.particle = []; + } + + static load(collection) { + const particles = []; + + for (const [index, particle] of collection.entries()) { + const particleID = new ParticleID(); + particleID.index = index; + + particleID.type = particle.type; + particleID.pdg = particle.pdg; + particleID.algorithmType = particle.algorithmType; + particleID.likelihood = particle.likelihood; + particleID.parameters = particle.parameters; + + particles.push(particleID); + } + + return particles; + } +} + +export class ReconstructedParticle { + constructor() { + // Physics properties + this.pdg = 0; + this.energy = 0; // GeV + this.momentum = {}; // GeV + this.referencePoint = {}; // mm + this.charge = 0; + this.mass = 0; // GeV + this.goodnessOfPID = 0; + this.covMatrix = []; + this.startVertex = {}; + this.clusters = []; + this.tracks = []; + this.particles = []; + } + + static load(collection) { + const particles = []; + + for (const [index, particle] of collection.entries()) { + const reconstructedParticle = new ReconstructedParticle(); + reconstructedParticle.index = index; + + reconstructedParticle.energy = particle.energy; + reconstructedParticle.momentum = particle.momentum; + reconstructedParticle.referencePoint = particle.referencePoint; + reconstructedParticle.charge = particle.charge; + reconstructedParticle.mass = particle.mass; + reconstructedParticle.goodnessOfPID = particle.goodnessOfPID; + reconstructedParticle.covMatrix = particle.covMatrix; + reconstructedParticle.startVertex = particle.startVertex; + reconstructedParticle.clusters = particle.clusters; + reconstructedParticle.tracks = particle.tracks; + reconstructedParticle.particles = particle.particles; + + particles.push(reconstructedParticle); + } + + return particles; + } +} + +export class Vertex { + constructor() { + // Physics properties + this.primary = 0; + this.chi2 = 0; + this.probability = 0; + this.position = 0; // mm + this.covMatrix = []; + this.algorithmType = 0; + this.parameters = 0; + this.associatedParticles = []; + } + + static load() {} +} + +export class Track { + constructor() { + // Physics properties + this.type = 0; + this.chi2 = 0; + this.ndf = 0; + this.dEdx = 0; + this.dEdxError = 0; + this.radiusOfInnermostHit = 0; + this.subdetectorHitNumbers = []; + this.trackStates = []; + this.dxQuantities = []; + this.trackerHits = []; + this.tracks = []; + } + + static load(collection) { + const particles = []; + + for (const [index, particle] of collection.entries()) { + const track = new Track(); + track.index = index; + + track.type = particle.type; + track.chi2 = particle.chi2; + track.ndf = particle.ndf; + track.dEdx = particle.dEdx; + track.dEdxError = particle.dEdxError; + track.radiusOfInnermostHit = particle.radiusOfInnermostHit; + track.subdetectorHitNumbers = particle.subdetectorHitNumbers; + track.trackStates = particle.trackStates; + track.dxQuantities = particle.dxQuantities; + track.trackerHits = particle.trackerHits; + track.tracks = particle.tracks; + + particles.push(track); + } + + return particles; + } +}