Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/packages/firebird-core/src/model/point-trajectory.piece.spec.ts is written in an unsupported language. File is not indexed.

0001 // point-trajectory.piece.spec.ts
0002 
0003 import { PointTrajectoryPiece, PointTrajectoryPieceFactory } from './point-trajectory.piece';
0004 
0005 const DEX_PIECE = {
0006   name: 'CentralTracks',
0007   type: 'PointTrajectory',
0008   version: '1.0',
0009   origin: { by: 'spec' },
0010   count: 2,
0011   columns: {
0012     theta: [0.5, 1.5],
0013     pdg: [11, -211],
0014   },
0015   pointColumns: ['x', 'y', 'z', 't'],
0016   points: [
0017     [[0, 0, 0, 0], [10, 10, 10, 1]],
0018     [[0, 0, 0, 2], [20, 20, 20, 5], [30, 30, 30, 9]],
0019   ],
0020   refs: { particle: 'McParticles' },
0021 };
0022 
0023 describe('PointTrajectoryPieceFactory', () => {
0024   it('adopts param columns and ragged points, id == index', () => {
0025     const piece = new PointTrajectoryPieceFactory().fromDexObject(DEX_PIECE);
0026 
0027     expect(piece.count).toBe(2);
0028     expect(piece.columns['theta']).toEqual([0.5, 1.5]);
0029     expect(piece.param('pdg', 1)).toBe(-211);
0030     expect(piece.param('missing', 0)).toBeNull();
0031     expect(piece.pointColumns).toEqual(['x', 'y', 'z', 't']);
0032     expect(piece.points[1].length).toBe(3);
0033     expect(piece.refs['particle']).toBe('McParticles');
0034   });
0035 
0036   it('sorts each trajectory by time', () => {
0037     const shuffled = {
0038       ...DEX_PIECE,
0039       count: 1,
0040       columns: {},
0041       refs: undefined,
0042       points: [[[5, 5, 5, 9], [1, 1, 1, 2], [3, 3, 3, 4]]],
0043     };
0044     const piece = new PointTrajectoryPieceFactory().fromDexObject(shuffled);
0045     expect(piece.points[0].map(p => p[3])).toEqual([2, 4, 9]);
0046   });
0047 
0048   it('throws loudly when points or columns do not match count', () => {
0049     const factory = new PointTrajectoryPieceFactory();
0050     expect(() => factory.fromDexObject({ ...DEX_PIECE, points: [[[0, 0, 0, 0]]] })).toThrow(/points/);
0051     expect(() => factory.fromDexObject({ ...DEX_PIECE, columns: { theta: [0.5] } })).toThrow(/theta/);
0052   });
0053 });
0054 
0055 describe('PointTrajectoryPiece', () => {
0056   it('computes timeRange over all trajectories', () => {
0057     const piece = new PointTrajectoryPieceFactory().fromDexObject(DEX_PIECE);
0058     expect(piece.timeRange).toEqual([0, 9]);
0059   });
0060 
0061   it('has null timeRange without a time point column', () => {
0062     const noTime = {
0063       ...DEX_PIECE,
0064       pointColumns: ['x', 'y', 'z'],
0065       points: [[[0, 0, 0]], [[1, 1, 1]]],
0066     };
0067     const piece = new PointTrajectoryPieceFactory().fromDexObject(noTime);
0068     expect(piece.timeRange).toBeNull();
0069   });
0070 
0071   it('round-trips through toDexObject', () => {
0072     const factory = new PointTrajectoryPieceFactory();
0073     const piece = factory.fromDexObject(DEX_PIECE);
0074     const dexObject = piece.toDexObject();
0075 
0076     expect(dexObject.type).toBe(PointTrajectoryPiece.type);
0077     expect(dexObject.count).toBe(2);
0078     expect(dexObject.columns.pdg).toEqual([11, -211]);
0079     expect(dexObject.refs).toEqual({ particle: 'McParticles' });
0080 
0081     const reparsed = factory.fromDexObject(dexObject);
0082     expect(reparsed.points).toEqual(piece.points);
0083     expect(reparsed.columns).toEqual(piece.columns);
0084   });
0085 });