Skip to content

Commit

Permalink
Adding names and color
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvbrt committed Aug 10, 2023
1 parent 696484f commit c46119f
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 43 deletions.
56 changes: 50 additions & 6 deletions packages/phoenix-event-display/src/loaders/edm4hep-json-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,12 @@ export class Edm4hepJsonLoader extends PhoenixLoader {
momentum.push(rawParticle.momentum.y);
momentum.push(rawParticle.momentum.z);

console.log('------------ Particle -----------');
console.log(' - origin:', origin);
console.log(' - momentum:', momentum);
console.log(' - status:', rawParticle.generatorStatus);

const particle = {
origin: origin,
momentum: momentum,
color: '#ffff00',
pdgid: rawParticle.PDG,
status: rawParticle.generatorStatus,
color: this.mcParticleColor(rawParticle.PDG),
};
particles.push(particle);
});
Expand All @@ -691,6 +688,53 @@ export class Edm4hepJsonLoader extends PhoenixLoader {
.toUpperCase();
}

/** Return a random colour */
private mcParticleColor(mcParticlePDGid) {
switch (Math.abs(mcParticlePDGid)) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
return '#aa0000';
case 11:
return '#00aa00';
case 12:
return '#00aa00';
case 13:
return '#00aa00';
case 14:
return '#00aa00';
case 15:
return '#00aa00';
case 16:
return '#00aa00';
case 21:
return '#0000aa';
case 22:
return '#0000aa';
case 23:
return '#0000aa';
case 24:
return '#0000aa';
case 25:
return '#00aaaa';
case 111:
return '#aa00aa';
case 211:
return '#aa00aa';
case 221:
return '#aa00aa';
case 311:
return '#aa00aa';
case 321:
return '#aa00aa';
default:
return '#aaaa00';
}
}

/** Helper conversion of HSL to hexadecimal */
private convHSLtoHEX(h: number, s: number, l: number): string {
l /= 100;
Expand Down
144 changes: 120 additions & 24 deletions packages/phoenix-event-display/src/loaders/objects/phoenix-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import {
LineSegments,
LineDashedMaterial,
CanvasTexture,
ArrowHelper,
} from 'three';
import { ConvexGeometry } from 'three/examples/jsm/geometries/ConvexGeometry.js';
import { TextGeometry } from 'three/examples/jsm/geometries/TextGeometry.js';
import { Font } from 'three/examples/jsm/loaders/FontLoader.js';
import HelvetikerFont from '../../managers/three-manager/fonts/helvetiker_regular.typeface.json';
import { EVENT_DATA_TYPE_COLORS } from '../../helpers/constants';
import { RKHelper } from '../../helpers/rk-helper';
import { CoordinateHelper } from '../../helpers/coordinate-helper';
Expand Down Expand Up @@ -912,12 +914,12 @@ export class PhoenixObjects {
public static getMCParticle(mcParticleParams: {
origin: number[];
momentum: number[];
pdgid: number;
status?: number;
color?: string;
uuid: string;
}): Object3D {
const defaultColor: string = '#ffff00';
const defaultStatus = 0;

const origin = new Vector3(
mcParticleParams.origin[0],
Expand All @@ -934,18 +936,16 @@ export class PhoenixObjects {
direction.normalize();

const lineLength = 0.85 * length;
let lineWidth = Math.log(length * 100) / 10;
console.log(lineWidth);
let lineWidth = Math.log(length * 1000) / 100;
if (lineWidth < 0) {
lineWidth = 0.00001;
}
if (lineWidth > 0.4) {
lineWidth = 0.4;
if (lineWidth > 0.1) {
lineWidth = 0.1;
}
const coneLength = 0.15 * length;
const coneWidth = 2.5 * lineWidth;

// const lineGeometry = new CylinderGeometry(2, 2, lineLength, 16, 2);
const lineGeometry = new CylinderGeometry(
lineWidth,
lineWidth,
Expand All @@ -955,7 +955,6 @@ export class PhoenixObjects {
lineGeometry.rotateZ(Math.PI / 2);
lineGeometry.translate(lineLength / 2, 0, 0);

// const coneGeometry = new ConeGeometry(2, coneLength, 16, 2);
const coneGeometry = new ConeGeometry(coneWidth, coneLength, 16);
coneGeometry.rotateZ(-Math.PI / 2);
coneGeometry.translate(length - coneLength / 2, 0, 0);
Expand All @@ -969,32 +968,129 @@ export class PhoenixObjects {
quaternion.setFromUnitVectors(buildDirection, direction);
mergedGeometry.applyQuaternion(quaternion);

mergedGeometry.translate(origin.x, origin.y, origin.z);
mergedGeometry.computeBoundingBox();

const material = new MeshPhongMaterial({
color: mcParticleParams.color ?? defaultColor,
});

const arrowObject = new Mesh(mergedGeometry, material);

// const arrowHelper = new ArrowHelper(direction, origin, length);
// arrowHelper.position.copy(origin);
// arrowHelper.setDirection(direction);
const font = new Font(HelvetikerFont);
const labelGeometry = new TextGeometry(
PhoenixObjects.getMCParticleName(mcParticleParams.pdgid),
{
font: font,
size: 80,
height: 2,
curveSegments: 12,
bevelEnabled: true,
bevelThickness: 4,
bevelSize: 4,
bevelOffset: 0,
bevelSegments: 5,
}
);
labelGeometry.scale(0.01, 0.01, 0.01);

labelGeometry.rotateX(Math.PI / 2);
labelGeometry.translate(length, 0, 0);

labelGeometry.applyQuaternion(quaternion);

const labelObject = new Mesh(labelGeometry, material);

// const arrowObject = new Group();
// arrowObject.add(arrowHelper.line);
// arrowObject.add(arrowHelper.cone);
const arrowContainer = new Group();
arrowContainer.position.x = origin.x;
arrowContainer.position.y = origin.y;
arrowContainer.position.z = origin.z;

// console.log(arrowHelper.line);
// console.log(arrowHelper.cone);
arrowContainer.add(arrowObject);
arrowContainer.add(labelObject);

mcParticleParams.uuid = arrowObject.uuid;
// mcParticleParams.uuid = arrowHelper.uuid;
mcParticleParams.uuid = arrowContainer.uuid;
arrowContainer.userData = Object.assign({}, mcParticleParams);

arrowObject.name = 'MCParticle';
// arrowHelper.name = 'MCParticle';
arrowContainer.name = 'MCParticle';

return arrowObject;
return arrowContainer;
}

/**
* Return a Monte Carlo particle name from PDG ID.
* @param mcParticlePDGid PDG ID.
* @returns MCParticle name.
*/
public static getMCParticleName(mcParticlePDGid: number): string {
switch (mcParticlePDGid) {
case 1:
return 'd';
case -1:
return '!d';
case 2:
return 'u';
case -2:
return '!u';
case 3:
return 's';
case -3:
return '!s';
case 4:
return 'c';
case -4:
return '!c';
case 5:
return 'b';
case -5:
return '!b';
case 6:
return 't';
case -6:
return '!t';
case 11:
return 'e-';
case -11:
return 'e+';
case 12:
return 'νe';
case 13:
return 'μ-';
case -13:
return 'μ+';
case 14:
return 'νμ';
case 15:
return 'τ';
case -15:
return 'τ-';
case 16:
return 'ντ';
case 21:
return 'g';
case 22:
return 'γ';
case 23:
return 'Z';
case 24:
return 'W+';
case -24:
return 'W-';
case 25:
return 'H';
case 111:
return 'π0';
case 211:
return 'π+';
case -211:
return 'π-';
case 221:
return 'η';
case 311:
return 'K0';
case 321:
return 'K+';
case -321:
return 'K-';
default:
return mcParticlePDGid.toString();
}
}
}
41 changes: 28 additions & 13 deletions packages/phoenix-event-display/src/loaders/phoenix-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,28 +435,43 @@ export class PhoenixLoader implements EventDataLoader {
}

if (eventData.MCParticles) {
const cuts = [
// new Cut('status', 0, 200, 20, 29),
];
const cuts = [new Cut('status', 21, 29, 200)];

const scaleMCParticles = (value: number) => {
this.graphicsLibrary
.getSceneManager()
.scaleChildObjects('MCParticles', value);
const addMCParticlesSizeOption = (
typeFolder: GUI,
typeFolderPM: PhoenixMenuNode
) => {
const scaleMCParticles = (value: number) => {
this.graphicsLibrary
.getSceneManager()
.scaleChildObjects('MCParticles', value / 100);
};
if (typeFolder) {
const sizeMenu = typeFolder
.add({ particleScale: 100 }, 'particleScale', 1, 400)
.name('Size (%)');
sizeMenu.onChange(scaleMCParticles);
}
// Phoenix menu
if (typeFolderPM) {
typeFolderPM.addConfig('slider', {
label: 'Size (%)',
value: 100,
min: 1,
max: 400,
allowCustomValue: true,
onChange: scaleMCParticles,
});
}
};
const addMCParticlesOptions = this.addScaleOptions(
'mcParticlesScale',
'MCParticles Scale',
scaleMCParticles
);

this.addObjectType(
eventData.MCParticles,
PhoenixObjects.getMCParticle,
'MCParticles',
false,
cuts,
addMCParticlesOptions
addMCParticlesSizeOption
);
}
}
Expand Down

0 comments on commit c46119f

Please sign in to comment.