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";
0003 import {LineGeometry} from "three/examples/jsm/lines/LineGeometry";
0004 import {Line2} from "three/examples/jsm/lines/Line2";
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 electronMaterial: LineMaterial;
0066 piPlusMaterial: LineMaterial;
0067 piMinusMaterial: LineMaterial;
0068 piZeroMaterial: LineMaterial;
0069 protonMaterial: LineMaterial;
0070 neutronMaterial: LineMaterial;
0071 posChargeMaterial: LineMaterial;
0072 negChargeMaterial: LineMaterial;
0073 zeroChargeMaterial: LineMaterial;
0074 scatteredElectronMaterial: LineMaterial;
0075
0076 constructor() {
0077 this.gammaMaterial = this.dashedLineMaterial.clone();
0078 this.gammaMaterial.color = new Color(NeonTrackColors.Yellow);
0079 this.gammaMaterial.dashSize = 50;
0080 this.gammaMaterial.gapSize = 50;
0081
0082 this.electronMaterial = this.solidLineMaterial.clone();
0083 this.electronMaterial.color = new Color(NeonTrackColors.Blue);
0084
0085 this.scatteredElectronMaterial = this.electronMaterial.clone();
0086 this.scatteredElectronMaterial.linewidth = 30;
0087
0088 this.piPlusMaterial = this.solidLineMaterial.clone();
0089 this.piPlusMaterial.color = new Color(NeonTrackColors.Pink);
0090
0091 this.piMinusMaterial = this.solidLineMaterial.clone();
0092 this.piMinusMaterial.color = new Color(NeonTrackColors.Teal);
0093
0094 this.piZeroMaterial = this.dashedLineMaterial.clone();
0095 this.piZeroMaterial.color = new Color(NeonTrackColors.Salad);
0096
0097 this.protonMaterial = this.solidLineMaterial.clone();
0098 this.protonMaterial.color = new Color(NeonTrackColors.Violet);
0099
0100 this.neutronMaterial = this.dashedLineMaterial.clone();
0101 this.neutronMaterial.color = new Color(NeonTrackColors.Green);
0102
0103 this.posChargeMaterial = this.solidLineMaterial.clone();
0104 this.posChargeMaterial.color = new Color(NeonTrackColors.Red);
0105
0106 this.negChargeMaterial = this.solidLineMaterial.clone();
0107 this.negChargeMaterial.color = new Color(NeonTrackColors.DeepBlue);
0108
0109 this.zeroChargeMaterial = this.dashedLineMaterial.clone();
0110 this.zeroChargeMaterial.color = new Color(NeonTrackColors.Gray);
0111
0112 }
0113
0114 getMaterial(pdgName: string, charge: number): LineMaterial {
0115 switch (pdgName) {
0116 case "gamma":
0117 return this.gammaMaterial;
0118 case "e-":
0119 return this.electronMaterial;
0120 case "pi+":
0121 return this.piPlusMaterial;
0122 case "pi-":
0123 return this.piMinusMaterial;
0124 case "pi0":
0125 return this.piZeroMaterial;
0126 case "proton":
0127 return this.protonMaterial;
0128 case "neutron":
0129 return this.neutronMaterial;
0130 default:
0131 return charge < 0 ? this.negChargeMaterial: (charge > 0? this.posChargeMaterial: this.neutronMaterial); // Fallback function if material is not predefined
0132 }
0133 }
0134
0135
0136 processMcTracks(mcTracksGroup: Object3D) {
0137
0138 let isFoundScatteredElectron = false;
0139 let processedTrackGroups: ProcessTrackInfo[] = [];
0140 for(let trackGroup of mcTracksGroup.children) {
0141
0142 let trackData = trackGroup.userData;
0143 if(!('pdg_name' in trackData)) continue;
0144 if(!('charge' in trackData)) continue;
0145 if(!('pos' in trackData)) continue;
0146 const pdgName = trackData["pdg_name"] as string;
0147 const charge = trackData["charge"] as number;
0148 const id = trackData["id"]
0149 let positions = trackData["pos"];
0150
0151 // If we are here this is
0152 let trackNode: Object3D = trackGroup;
0153 let oldLine: Object3D|null = null;
0154 let newLine: Line2|null = null;
0155 let trackMesh: Object3D|null = null;
0156 let timeStart = 0;
0157 let timeEnd = 0;
0158 let startPoint = new Vector3();
0159 let endPoint = new Vector3();
0160
0161 for(let obj of trackGroup.children) {
0162
0163 if(obj.type == "Line") {
0164
0165 // Do we have time info?
0166 if(positions.length > 0 && positions[0].length > 3) {
0167 let position = positions[0]
0168 timeStart = timeEnd = position[3];
0169 startPoint = endPoint = new Vector3(position[0], position[1], position[2]);
0170 }
0171 // Set end time if there is more than 1 point
0172 if(positions.length > 1 && positions[0].length > 3) {
0173 let position = positions[positions.length-1];
0174 timeEnd = position[3];
0175 endPoint = new Vector3(position[0], position[1], position[2]);
0176 }
0177
0178 // Build our flat points array and set geometry
0179 let flat = [];
0180 for(let position of positions) {
0181 flat.push(position[0], position[1], position[2]);
0182 }
0183 const geometry = new LineGeometry();
0184 geometry.setPositions( flat );
0185 // geometry.setColors( colors );
0186
0187 let material = this.getMaterial(pdgName, charge);
0188 if(!isFoundScatteredElectron && pdgName=="e-") {
0189 isFoundScatteredElectron = true;
0190 material = this.scatteredElectronMaterial;
0191 }
0192
0193 let line = new Line2( geometry, material );
0194
0195 // line.scale.set( 1, 1, 1 );
0196 line.name = "TrackLine2";
0197 line.computeLineDistances();
0198 line.visible = true;
0199 trackGroup.add( line );
0200 obj.visible = false;
0201 oldLine = obj;
0202 newLine = line;
0203 let ic = (line.geometry as any)?.attributes?.instanceStart;
0204 let geomCount = (line.geometry as any).count;
0205
0206 let posLen = positions.length;
0207 //oldLine.removeFromParent();
0208
0209 // 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)}`);
0210 // console.log(ic);
0211 }
0212
0213 if(obj.type == "Mesh") {
0214 obj.visible = false;
0215 trackMesh = obj;
0216 // obj.removeFromParent();
0217 }
0218 }
0219
0220 // We found everything
0221 if(oldLine && newLine && trackMesh) {
0222 processedTrackGroups.push({
0223 positions: positions,
0224 trackNode: trackNode,
0225 oldLine: oldLine,
0226 newLine: newLine,
0227 trackMesh: trackMesh,
0228 startTime: timeStart,
0229 endTime: timeEnd,
0230 })
0231 }
0232 }
0233
0234 console.log(`Total processed tracks: ${processedTrackGroups.length}`);
0235 return processedTrackGroups;
0236 }
0237 }