Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/packages/root2dex/src/mc-particles.spec.ts is written in an unsupported language. File is not indexed.

0001 /**
0002  * Unit tests for the MCParticles straight-line interpolation. The full
0003  * conversion (and its pyrobird parity) is covered by parity.spec.ts; these pin
0004  * the grid arithmetic on its own.
0005  */
0006 
0007 import { describe, expect, it } from 'vitest';
0008 import { C_LIGHT, interpolateLinePoints } from './mc-particles';
0009 
0010 describe('interpolateLinePoints', () => {
0011   it('places interior points on the fixed time grid', () => {
0012     // beta=1 over 3 x c_light mm takes 3 ns; step 1 ns => vertex + 2 interior + endpoint
0013     const points = interpolateLinePoints(0, 0, 0, 3 * C_LIGHT, 0, 0, 10.0, 1.0, 1.0);
0014     expect(points).toHaveLength(4);
0015     expect(points[0]).toEqual([0, 0, 0, 10.0]);
0016     expect(points[3][0]).toBe(3 * C_LIGHT);
0017     expect(points[3][3]).toBeCloseTo(13.0, 12);
0018     expect(points[1][3]).toBeCloseTo(11.0, 12);
0019     expect(points[2][3]).toBeCloseTo(12.0, 12);
0020     expect(points[1][0]).toBeCloseTo(C_LIGHT, 9);
0021   });
0022 
0023   it('coarsens the grid instead of truncating when maxPoints is hit', () => {
0024     const points = interpolateLinePoints(0, 0, 0, 100000, 0, 0, 0.0, 1.0, 0.001, 16);
0025     expect(points).toHaveLength(16);
0026     expect(points[15][0]).toBe(100000);
0027     const steps = points.slice(1).map((point, i) => point[3] - points[i][3]);
0028     for (const step of steps) expect(step).toBeCloseTo(steps[0], 12);
0029   });
0030 
0031   it('yields two equal-time end points for a particle at rest', () => {
0032     expect(interpolateLinePoints(1, 2, 3, 1, 2, 3, 5.0, 0.0)).toEqual([
0033       [1, 2, 3, 5.0],
0034       [1, 2, 3, 5.0],
0035     ]);
0036   });
0037 });