Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/app/painters/step-track.painter.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 StepTrackComponentPainter {
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.dashedLineMaterial.clone();
0084     this.opticalMaterial.color = new Color(NeonTrackColors.Salad);
0085     this.opticalMaterial.linewidth = 1;
0086 
0087     this.electronMaterial = this.solidLineMaterial.clone();
0088     this.electronMaterial.color = new Color(NeonTrackColors.Blue);
0089 
0090     this.scatteredElectronMaterial = this.electronMaterial.clone();
0091     this.scatteredElectronMaterial.linewidth = 30;
0092 
0093     this.piPlusMaterial = this.solidLineMaterial.clone();
0094     this.piPlusMaterial.color = new Color(NeonTrackColors.Pink);
0095 
0096     this.piMinusMaterial = this.solidLineMaterial.clone();
0097     this.piMinusMaterial.color = new Color(NeonTrackColors.Teal);
0098 
0099     this.piZeroMaterial = this.dashedLineMaterial.clone();
0100     this.piZeroMaterial.color = new Color(NeonTrackColors.Salad);
0101 
0102     this.protonMaterial = this.solidLineMaterial.clone();
0103     this.protonMaterial.color = new Color(NeonTrackColors.Violet);
0104 
0105     this.neutronMaterial = this.dashedLineMaterial.clone();
0106     this.neutronMaterial.color = new Color(NeonTrackColors.Green);
0107 
0108     this.posChargeMaterial = this.solidLineMaterial.clone();
0109     this.posChargeMaterial.color = new Color(NeonTrackColors.Red);
0110 
0111     this.negChargeMaterial = this.solidLineMaterial.clone();
0112     this.negChargeMaterial.color = new Color(NeonTrackColors.DeepBlue);
0113 
0114     this.zeroChargeMaterial = this.dashedLineMaterial.clone();
0115     this.zeroChargeMaterial.color = new Color(NeonTrackColors.Gray);
0116 
0117   }
0118 
0119   getMaterial(pdgName: string, charge: number): LineMaterial {
0120     switch (pdgName) {
0121       case "gamma":
0122         return this.gammaMaterial;
0123       case "opticalphoton":
0124         return this.opticalMaterial;
0125       case "e-":
0126         return this.electronMaterial;
0127       case "pi+":
0128         return this.piPlusMaterial;
0129       case "pi-":
0130         return this.piMinusMaterial;
0131       case "pi0":
0132         return this.piZeroMaterial;
0133       case "proton":
0134         return this.protonMaterial;
0135       case "neutron":
0136         return this.neutronMaterial;
0137       default:
0138         return charge < 0 ? this.negChargeMaterial: (charge > 0? this.posChargeMaterial: this.neutronMaterial); // Fallback function if material is not predefined
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 }