Warning, /firebird/firebird-ng/src/app/model/box-hit.group.ts is written in an unsupported language. File is not indexed.
0001 // box-hit.group.ts
0002
0003 import { EventGroup, EventGroupFactory, registerEventGroupFactory } from './event-group';
0004
0005 /**
0006 * Represents an individual tracker hit with position, dimensions, time, and energy deposit.
0007 */
0008 export class BoxHit {
0009
0010 /** The position of the hit [mm] as [x, y, z]. */
0011 position: [number, number, number];
0012
0013 /** The dimensions of the hit box [mm] as [dx, dy, dz]. */
0014 dimensions: [number, number, number];
0015
0016 /** The time information [ns] as [time, err_time]. */
0017 time: [number, number];
0018
0019 /** The energy deposit with error [GeV] as [edep, err_edep]. */
0020 energyDeposit: [number, number];
0021
0022 /**
0023 * Constructs a new BoxHit instance.
0024 *
0025 * @param position - The position of the hit as [x, y, z].
0026 * @param dimensions - The dimensions of the hit box as [dx, dy, dz].
0027 * @param time - The time information as [time, err_time].
0028 * @param energyDeposit - The energy deposit with error as [edep, err_edep].
0029 */
0030 constructor(
0031 position: [number, number, number],
0032 dimensions: [number, number, number],
0033 time: [number, number],
0034 energyDeposit: [number, number]
0035 ) {
0036 this.position = position;
0037 this.dimensions = dimensions;
0038 this.time = time;
0039 this.energyDeposit = energyDeposit;
0040 }
0041
0042 /**
0043 * Serializes the BoxHit instance into a JSON-compatible object.
0044 *
0045 * @returns A JSON-compatible object representing the serialized BoxHit.
0046 */
0047 toDexObject(): any {
0048 return {
0049 pos: this.position,
0050 dim: this.dimensions,
0051 t: this.time,
0052 ed: this.energyDeposit,
0053 };
0054 }
0055
0056 /**
0057 * Creates a BoxHit instance from a deserialized object.
0058 *
0059 * @param obj - The deserialized object representing a BoxHit.
0060 * @returns A new instance of BoxHit populated with data from the object.
0061 */
0062 static fromDexObject(obj: any): BoxHit {
0063 return new BoxHit(
0064 obj["pos"],
0065 obj["dim"],
0066 obj["t"],
0067 obj["ed"]
0068 );
0069 }
0070 }
0071
0072 /**
0073 * Represents a component that contains multiple BoxHits.
0074 */
0075 export class BoxHitGroup extends EventGroup {
0076
0077 /** calculate time range */
0078 override get timeRange(): [number, number] | null {
0079 if(this.hits.length == 0) return null;
0080 let minTime = this.hits[0].time[0];
0081 let maxTime = this.hits[0].time[0];
0082
0083 for(const hit of this.hits)
0084 {
0085 if (hit.time[0] != null && hit.time[0] < minTime) {
0086 minTime = hit.time[0];
0087 }
0088
0089 if (hit.time[0] != null && hit.time[0] > maxTime) {
0090 maxTime = hit.time[0];
0091 }
0092 }
0093
0094 // Do we have both times?
0095 if(minTime != null && maxTime!=null) {
0096 return [minTime, maxTime];
0097 }
0098
0099 return null;
0100 }
0101
0102 /** The static type identifier for the BoxHitGroup. */
0103 static type = 'BoxHit';
0104
0105 /** An array of BoxHits contained in this component. */
0106 hits: BoxHit[] = [];
0107
0108 /**
0109 * Constructs a new BoxHitGroup instance.
0110 *
0111 * @param name - The name of the component.
0112 * @param origin - Optional origin type of the component.
0113 */
0114 constructor(name: string, origin?: string) {
0115 super(name, BoxHitGroup.type, origin);
0116 }
0117
0118 /**
0119 * Serializes the BoxHitGroup instance into a JSON-compatible object.
0120 *
0121 * @returns A JSON-compatible object representing the serialized BoxHitGroup.
0122 */
0123 toDexObject(): any {
0124 const objHits = [];
0125 for (const hit of this.hits) {
0126 objHits.push(hit.toDexObject());
0127 }
0128
0129 return {
0130 name: this.name,
0131 type: this.type,
0132 origin: this.origin,
0133 hits: objHits,
0134 };
0135 }
0136 }
0137
0138 /**
0139 * Factory for creating instances of BoxHitGroup from deserialized data.
0140 */
0141 export class BoxHitGroupFactory implements EventGroupFactory {
0142 /** The type of the component that this factory creates. */
0143 type: string = BoxHitGroup.type;
0144
0145 /**
0146 * Creates an instance of BoxHitGroup from a deserialized object.
0147 *
0148 * @param obj - The deserialized object representing a BoxHitGroup.
0149 * @returns An instance of BoxHitGroup.
0150 */
0151 fromDexObject(obj: any): EventGroup {
0152 const result = new BoxHitGroup(obj["name"]);
0153
0154 if (obj["origin"]) {
0155 result.origin = obj["origin"];
0156 }
0157
0158 for (const objHit of obj["hits"]) {
0159 result.hits.push(BoxHit.fromDexObject(objHit));
0160 }
0161
0162 return result;
0163 }
0164 }
0165
0166 // Register the component factory
0167 registerEventGroupFactory(new BoxHitGroupFactory());