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   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   processMcTracks(mcTracksGroup: Object3D) {
0136 
0137     let isFoundScatteredElectron = false;
0138     let processedTrackGroups: ProcessTrackInfo[] = [];
0139     for(let trackGroup of mcTracksGroup.children) {
0140 
0141       let trackData = trackGroup.userData;
0142       if(!('pdg_name' in trackData)) continue;
0143       if(!('charge' in trackData)) continue;
0144       if(!('pos' in trackData)) continue;
0145       const pdgName = trackData["pdg_name"] as string;
0146       const charge = trackData["charge"] as number;
0147       const id = trackData["id"]
0148       let positions = trackData["pos"];
0149 
0150       // If we are here this is
0151       let trackNode: Object3D = trackGroup;
0152       let oldLine: Object3D|null = null;
0153       let newLine: Line2|null = null;
0154       let trackMesh: Object3D|null = null;
0155       let timeStart = 0;
0156       let timeEnd = 0;
0157       let startPoint = new Vector3();
0158       let endPoint = new Vector3();
0159 
0160       for(let obj of trackGroup.children) {
0161 
0162         if(obj.type == "Line") {
0163 
0164           // Do we have time info?
0165           if(positions.length > 0 && positions[0].length > 3) {
0166             let position = positions[0]
0167             timeStart = timeEnd = position[3];
0168             startPoint = endPoint = new Vector3(position[0], position[1], position[2]);
0169           }
0170           // Set end time if there is more than 1 point
0171           if(positions.length > 1 && positions[0].length > 3) {
0172             let position = positions[positions.length-1];
0173             timeEnd = position[3];
0174             endPoint = new Vector3(position[0], position[1], position[2]);
0175           }
0176 
0177           // Build our flat points array and set geometry
0178           let flat = [];
0179           for(let position of positions) {
0180             flat.push(position[0], position[1], position[2]);
0181           }
0182           const geometry = new LineGeometry();
0183           geometry.setPositions( flat );
0184           // geometry.setColors( colors );
0185 
0186           let material = this.getMaterial(pdgName, charge);
0187           if(!isFoundScatteredElectron && pdgName=="e-") {
0188             isFoundScatteredElectron = true;
0189             material = this.scatteredElectronMaterial;
0190           }
0191 
0192           let line = new Line2( geometry, material );
0193 
0194           // line.scale.set( 1, 1, 1 );
0195           line.name = "TrackLine2";
0196           line.computeLineDistances();
0197           line.visible = true;
0198           trackGroup.add( line );
0199           obj.visible = false;
0200           oldLine = obj;
0201           newLine = line;
0202           let ic = (line.geometry as any)?.attributes?.instanceStart;
0203           let geomCount = (line.geometry as any).count;
0204 
0205           let posLen = positions.length;
0206           //oldLine.removeFromParent();
0207 
0208           // 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)}`);
0209           // console.log(ic);
0210         }
0211 
0212         if(obj.type == "Mesh") {
0213           obj.visible = false;
0214           trackMesh = obj;
0215           // obj.removeFromParent();
0216         }
0217       }
0218 
0219       // We found everything
0220       if(oldLine && newLine && trackMesh) {
0221         processedTrackGroups.push({
0222           positions: positions,
0223           trackNode: trackNode,
0224           oldLine: oldLine,
0225           newLine: newLine,
0226           trackMesh: trackMesh,
0227           startTime: timeStart,
0228           endTime: timeEnd,
0229         })
0230       }
0231     }
0232 
0233     console.log(`Total processed tracks: ${processedTrackGroups.length}`);
0234     return processedTrackGroups;
0235   }
0236 }