Warning, /firebird/firebird-ng/src/app/data-pipelines/three-event.processor.ts is written in an unsupported language. File is not indexed.
0001 import {Color, Line, Object3D, Vector3} from "three";
0002 import {LineMaterial} from "three/examples/jsm/lines/LineMaterial.js";
0003 import {LineGeometry} from "three/examples/jsm/lines/LineGeometry.js";
0004 import {Line2} from "three/examples/jsm/lines/Line2.js";
0005
0006
0007 export interface ProcessTrackInfo {
0008 positions: [[number]];
0009 trackNode: Object3D;
0010 oldLine: Object3D;
0011 newLine: Line2;
0012 trackMesh: Object3D;
0013 startTime: number;
0014 endTime: number;
0015 }
0016
0017 export enum NeonTrackColors {
0018
0019 Red = 0xFF0007,
0020 Pink= 0xCF00FF,
0021 Violet = 0x5400FF,
0022 Blue = 0x0097FF,
0023 DeepBlue = 0x003BFF,
0024 Teal = 0x00FFD1,
0025 Green = 0x13FF00,
0026 Salad = 0x8CFF00,
0027 Yellow = 0xFFEE00,
0028 Orange = 0xFF3500,
0029 Gray = 0xAAAAAA,
0030 }
0031
0032 /**
0033 * "gamma": "yellow",
0034 * "e-": "blue",
0035 * "pi+": "pink",
0036 * "pi-": "salad",
0037 * "proton": "violet",
0038 * "neutron": "green"
0039 */
0040 export class ThreeEventProcessor {
0041
0042 /** This is primer, all other DASHED line materials take this and clone and change color */
0043 dashedLineMaterial = new LineMaterial( {
0044 color: 0xffff00,
0045 linewidth: 20, // in world units with size attenuation, pixels otherwise
0046 worldUnits: true,
0047 dashed: true,
0048 //dashScale: 100, // ???? Need this? What is it?
0049 dashSize: 100,
0050 gapSize: 100,
0051 alphaToCoverage: true,
0052 } );
0053
0054 /** This is primer, all other SOLID line materials take this and clone and change color */
0055 solidLineMaterial = new LineMaterial( {
0056 color: 0xffff00,
0057 linewidth: 20, // in world units with size attenuation, pixels otherwise
0058 worldUnits: true,
0059 dashed: false,
0060 //dashScale: 100, // ???? Need this? What is it?
0061 alphaToCoverage: true,
0062 } );
0063
0064 gammaMaterial: LineMaterial;
0065 opticalMaterial: LineMaterial;
0066 electronMaterial: LineMaterial;
0067 piPlusMaterial: LineMaterial;
0068 piMinusMaterial: LineMaterial;
0069 piZeroMaterial: LineMaterial;
0070 protonMaterial: LineMaterial;
0071 neutronMaterial: LineMaterial;
0072 posChargeMaterial: LineMaterial;
0073 negChargeMaterial: LineMaterial;
0074 zeroChargeMaterial: LineMaterial;
0075 scatteredElectronMaterial: LineMaterial;
0076
0077 constructor() {
0078 this.gammaMaterial = this.dashedLineMaterial.clone();
0079 this.gammaMaterial.color = new Color(NeonTrackColors.Yellow);
0080 this.gammaMaterial.dashSize = 50;
0081 this.gammaMaterial.gapSize = 50;
0082
0083 this.opticalMaterial = this.solidLineMaterial.clone();
0084 this.opticalMaterial.color = new Color(NeonTrackColors.Yellow);
0085
0086 this.electronMaterial = this.solidLineMaterial.clone();
0087 this.electronMaterial.color = new Color(NeonTrackColors.Blue);
0088
0089 this.scatteredElectronMaterial = this.electronMaterial.clone();
0090 this.scatteredElectronMaterial.linewidth = 30;
0091
0092 this.piPlusMaterial = this.solidLineMaterial.clone();
0093 this.piPlusMaterial.color = new Color(NeonTrackColors.Pink);
0094
0095 this.piMinusMaterial = this.solidLineMaterial.clone();
0096 this.piMinusMaterial.color = new Color(NeonTrackColors.Teal);
0097
0098 this.piZeroMaterial = this.dashedLineMaterial.clone();
0099 this.piZeroMaterial.color = new Color(NeonTrackColors.Salad);
0100
0101 this.protonMaterial = this.solidLineMaterial.clone();
0102 this.protonMaterial.color = new Color(NeonTrackColors.Violet);
0103
0104 this.neutronMaterial = this.dashedLineMaterial.clone();
0105 this.neutronMaterial.color = new Color(NeonTrackColors.Green);
0106
0107 this.posChargeMaterial = this.solidLineMaterial.clone();
0108 this.posChargeMaterial.color = new Color(NeonTrackColors.Red);
0109
0110 this.negChargeMaterial = this.solidLineMaterial.clone();
0111 this.negChargeMaterial.color = new Color(NeonTrackColors.DeepBlue);
0112
0113 this.zeroChargeMaterial = this.dashedLineMaterial.clone();
0114 this.zeroChargeMaterial.color = new Color(NeonTrackColors.Gray);
0115
0116 }
0117
0118 getMaterial(pdgName: string, charge: number): LineMaterial {
0119 switch (pdgName) {
0120 case "gamma":
0121 return this.gammaMaterial;
0122 case "opticalphoton":
0123 return this.opticalMaterial;
0124 case "e-":
0125 return this.electronMaterial;
0126 case "pi+":
0127 return this.piPlusMaterial;
0128 case "pi-":
0129 return this.piMinusMaterial;
0130 case "pi0":
0131 return this.piZeroMaterial;
0132 case "proton":
0133 return this.protonMaterial;
0134 case "neutron":
0135 return this.neutronMaterial;
0136 default:
0137 return charge < 0 ? this.negChargeMaterial: (charge > 0? this.posChargeMaterial: this.neutronMaterial); // Fallback function if material is not predefined
0138 }
0139 }
0140
0141
0142 processMcTracks(mcTracksGroup: Object3D) {
0143
0144 let isFoundScatteredElectron = false;
0145 let processedTrackGroups: ProcessTrackInfo[] = [];
0146 for(let trackGroup of mcTracksGroup.children) {
0147
0148 let trackData = trackGroup.userData;
0149 if(!('pdg_name' in trackData)) continue;
0150 if(!('charge' in trackData)) continue;
0151 if(!('pos' in trackData)) continue;
0152 const pdgName = trackData["pdg_name"] as string;
0153 const charge = trackData["charge"] as number;
0154 const id = trackData["id"]
0155 let positions = trackData["pos"];
0156
0157 // If we are here this is
0158 let trackNode: Object3D = trackGroup;
0159 let oldLine: Object3D|null = null;
0160 let newLine: Line2|null = null;
0161 let trackMesh: Object3D|null = null;
0162 let timeStart = 0;
0163 let timeEnd = 0;
0164 let startPoint = new Vector3();
0165 let endPoint = new Vector3();
0166
0167 for(let obj of trackGroup.children) {
0168
0169 if(obj.type == "Line") {
0170
0171 // Do we have time info?
0172 if(positions.length > 0 && positions[0].length > 3) {
0173 let position = positions[0]
0174 timeStart = timeEnd = position[3];
0175 startPoint = endPoint = new Vector3(position[0], position[1], position[2]);
0176 }
0177 // Set end time if there is more than 1 point
0178 if(positions.length > 1 && positions[0].length > 3) {
0179 let position = positions[positions.length-1];
0180 timeEnd = position[3];
0181 endPoint = new Vector3(position[0], position[1], position[2]);
0182 }
0183
0184 // Build our flat points array and set geometry
0185 let flat = [];
0186 for(let position of positions) {
0187 flat.push(position[0], position[1], position[2]);
0188 }
0189 const geometry = new LineGeometry();
0190 geometry.setPositions( flat );
0191 // geometry.setColors( colors );
0192
0193 let material = this.getMaterial(pdgName, charge);
0194 if(!isFoundScatteredElectron && pdgName=="e-") {
0195 isFoundScatteredElectron = true;
0196 material = this.scatteredElectronMaterial;
0197 }
0198
0199 let line = new Line2( geometry, material );
0200
0201 // line.scale.set( 1, 1, 1 );
0202 line.name = "TrackLine2";
0203 line.computeLineDistances();
0204 line.visible = true;
0205 trackGroup.add( line );
0206 obj.visible = false;
0207 oldLine = obj;
0208 newLine = line;
0209 let ic = (line.geometry as any)?.attributes?.instanceStart;
0210 let geomCount = (line.geometry as any).count;
0211
0212 let posLen = positions.length;
0213 //oldLine.removeFromParent();
0214
0215 // console.log(`id: ${id} pdg: ${pdgName} tstart: ${timeStart.toFixed(2)} tend: ${timeEnd.toFixed(2)} instCount: ${ic?.data?.array?.length} count: ${geomCount} posLen: ${posLen} length: ${endPoint.distanceTo(startPoint)}`);
0216 // console.log(ic);
0217 }
0218
0219 if(obj.type == "Mesh") {
0220 obj.visible = false;
0221 trackMesh = obj;
0222 // obj.removeFromParent();
0223 }
0224 }
0225
0226 // We found everything
0227 if(oldLine && newLine && trackMesh) {
0228 processedTrackGroups.push({
0229 positions: positions,
0230 trackNode: trackNode,
0231 oldLine: oldLine,
0232 newLine: newLine,
0233 trackMesh: trackMesh,
0234 startTime: timeStart,
0235 endTime: timeEnd,
0236 })
0237 }
0238 }
0239
0240 console.log(`Total processed tracks: ${processedTrackGroups.length}`);
0241 return processedTrackGroups;
0242 }
0243 }