Skip to content

Commit

Permalink
loading function to check if types are correctly working
Browse files Browse the repository at this point in the history
  • Loading branch information
brauliorivas committed May 31, 2024
1 parent 3cfbb4c commit 186024e
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 72 deletions.
17 changes: 0 additions & 17 deletions js/types/Cluster.js

This file was deleted.

10 changes: 0 additions & 10 deletions js/types/ParticleID.js

This file was deleted.

17 changes: 0 additions & 17 deletions js/types/RecoParticle.js

This file was deleted.

15 changes: 0 additions & 15 deletions js/types/Track.js

This file was deleted.

13 changes: 0 additions & 13 deletions js/types/Vertex.js

This file was deleted.

62 changes: 62 additions & 0 deletions js/types/load.js
Original file line number Diff line number Diff line change
@@ -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);
175 changes: 175 additions & 0 deletions js/types/reconstruction.js
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 186024e

Please sign in to comment.