-
Notifications
You must be signed in to change notification settings - Fork 4
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
Create new types of collections #25
Closed
Closed
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3cfbb4c
create initial types of collections defined in gsoc
brauliorivas 186024e
loading function to check if types are correctly working
brauliorivas fbfb0ea
test suite for loadParticles and buildLoader
brauliorivas c7b270c
change example data for RecoParticle test
brauliorivas 170de18
Merge branch 'main' into new-types
brauliorivas 27d03ec
check if previews work
brauliorivas 0a52737
small change
brauliorivas 02392eb
another small change
brauliorivas 13978a4
remove unnecessary exclamation mark
brauliorivas 5f48b1d
eliminate try catch
brauliorivas 00bb203
add version check + dynamic load of object
brauliorivas 83a9bbd
update tests
brauliorivas 3e64c41
types for RecoParticle relations including 1:1 and 1:many
brauliorivas f7a14c5
add links for types
brauliorivas 904cd51
test for loading functions
brauliorivas ba9630c
test reconstruction
brauliorivas 69f3fd6
remove a few things
brauliorivas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
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", | ||
]; | ||
|
||
export function buildLoader(config) { | ||
let newLoader = { | ||
types: {}, | ||
getLoader: (name) => { | ||
if (newLoader.types.hasOwnProperty(name)) { | ||
return newLoader.types[name]; | ||
} | ||
return false; | ||
}, | ||
getAllLoaders: () => { | ||
return newLoader.types; | ||
}, | ||
}; | ||
|
||
for (const particle of config) { | ||
if (loaders.hasOwnProperty(particle)) { | ||
newLoader.types[particle] = loaders[particle]; | ||
} | ||
} | ||
|
||
return newLoader; | ||
} | ||
|
||
export function loadParticles(jsonData, event, loadersConfig) { | ||
const eventData = Object.values(jsonData["Event " + event]); | ||
|
||
const particles = {}; | ||
|
||
if (typeof loadersConfig === "string") loadersConfig = [loadersConfig]; | ||
const loader = buildLoader(loadersConfig); | ||
|
||
Object.keys(loader.getAllLoaders()).forEach((key) => (particles[key] = [])); | ||
|
||
for (const [type, loadFunction] of Object.entries(loader.getAllLoaders())) { | ||
const particlesType = eventData.filter( | ||
(element) => element.collType === `edm4hep::${type}Collection` | ||
); | ||
|
||
particlesType.forEach((collection) => { | ||
const loadedParticles = loadFunction(collection.collection); | ||
particles[type] = loadedParticles; | ||
}); | ||
} | ||
try { | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
return particles; | ||
} | ||
|
||
loadParticles(jsonData, 4, loadersConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { buildLoader, loadParticles } from "../js/types/load"; | ||
|
||
const data = { | ||
"Event 0": { | ||
"AllMuon": { | ||
"collID": 12, | ||
"collType": "edm4hep::ReconstructedParticleCollection", | ||
"collection": [], | ||
}, | ||
"EFlowPhoton": { | ||
"collID": 7, | ||
"collType": "edm4hep::ClusterCollection", | ||
"collection": [ | ||
{ | ||
"clusters": [], | ||
"directionError": { | ||
"x": 0.0, | ||
"y": 0.0, | ||
"z": 0.0, | ||
}, | ||
"energy": 6.2020978927612305, | ||
"energyError": 0.0, | ||
"hits": [], | ||
"iTheta": 0.0, | ||
"particleIDs": [], | ||
"phi": 0.0, | ||
"position": { | ||
"x": 0.0, | ||
"y": 0.0, | ||
"z": 0.0, | ||
}, | ||
"positionError": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], | ||
"shapeParameters": [], | ||
"subdetectorEnergies": [], | ||
"type": 0, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
describe("build loader", () => { | ||
it("should create a loader with a set of types", () => { | ||
const loadersConfig = ["ReconstructedParticle", "ParticleID"]; | ||
const loader = buildLoader(loadersConfig); | ||
const loaderFunctions = loadersConfig.map((type) => loader.getLoader(type)); | ||
|
||
expect(loaderFunctions.every((f) => typeof f === "function")).toBe(true); | ||
}); | ||
|
||
it("should fail when requesting a loader that doesn't exist", () => { | ||
const loadersConfig = ["ReconstructedParticle", "ParticleID"]; | ||
const loader = buildLoader(loadersConfig); | ||
|
||
expect(loader.getLoader("Vertex")).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("load different types of particles", () => { | ||
it("should only load particles of one type", () => { | ||
const loadersConfig = "ReconstructedParticle"; | ||
|
||
const particles = loadParticles(data, "0", loadersConfig); | ||
|
||
expect(particles.hasOwnProperty(loadersConfig)).toBe(true); | ||
}); | ||
|
||
it("should load particles of multiple types", () => { | ||
const loadersConfig = ["ReconstructedParticle", "Cluster"]; | ||
|
||
const particles = loadParticles(data, "0", loadersConfig); | ||
|
||
expect(loadersConfig.every((type) => particles.hasOwnProperty(type))).toBe( | ||
true | ||
); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as an FYI: this seems to be a subset collection, i.e. the actual data live in another collection and this just has "pointers" into that collection. Looking at this bit of JSON here, I think
edm4hep2json
does not yet handle this case properly (unless you have cut quite a bit of the original JSON).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh thanks. I didn't know that.
Yeah, I think it is about
edm4hep2json
. I took the first collection without cutting. I will change it.