Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/assets/docs/dex.md is written in an unsupported language. File is not indexed.

0001 
0002 # Firebird Data Exchange format
0003 
0004 Data exchange is both JSON and Javascript object compatible.
0005 
0006 It starts with (in this order) `"type":"firebird-dex-json"`.  
0007 Then goes `version` and `origin` - any custom origin info and a list of entries. They are described below.
0008 
0009 Here `event` may correspond to `event` in HENP data, while has more technical definition: 
0010 data container for a time labeled data for particular time interval to be displayed.  
0011 
0012 ```json
0013 {
0014   "type":"firebird-dex-json",
0015   "version": "0.04",
0016   "origin": {"any custom origin info": "here"},
0017   "events": [
0018     event0, event1, ...
0019   ]
0020 }
0021 ```
0022 
0023 - **version** - is JSON schema version
0024 - **origin** - designed for any general custom info such as original file name,
0025   timestamp, simulation software version, etc.
0026 - **events** - list of entries/events. The format is below.
0027 
0028 ## Event format
0029 
0030 
0031 ```
0032 +------------------------------------------------+
0033 | Event                                          |
0034 |                                                |
0035 |   +--------------------+                       |
0036 |   |   Group            |                       |
0037 |   |    ~name type~     |                       |
0038 |   +--------------------+                       |
0039 |                                                |
0040 |   +-------------------+                        |
0041 |   |      hits a       |        +----------+    |
0042 |   +-------------------+        |  hits b  |    |
0043 |                                +----------+    |
0044 |   +----------------------------------+         |
0045 |   |      tracks                      |         |
0046 |   +----------------------------------+         |
0047 |                                                |
0048 +------------------------------------------------+
0049 
0050 0------------------------------------------------> time
0051 
0052 
0053 ```
0054 
0055 Event is an object with `id` and `groups` properties.
0056 By design groups represent different hits, tracks, vertices, collections, etc.
0057 While can be any arbitary data, that will be further rendered by the frontend.
0058 
0059 ```json
0060 {
0061   "id": "Event number or string - unique name",
0062   "groups": [
0063     
0064    ...
0065     
0066   ]
0067 }
0068 ```
0069 
0070 Requrired fields are `id` and `groups`. `id` must be unique across events in FDEX file. 
0071 
0072 
0073 ## Group format
0074 
0075 - `name`: unique string id
0076 - `type`: string with type (depends on what group will be used in the frontend to render it)
0077 - `origin`: optional dictionary with origin data info such as type of origin, 
0078    e.g. "edm4eic::TrackerHitData", EDM collection name and so on
0079 
0080 - all other fields defined by "type"
0081 
0082 So far example of exchange format looks like (only required fields are used here):
0083 
0084 ```json
0085 {
0086   "version": "0.04",
0087   "events": [
0088     {
0089       "id": "event 0",
0090       "groups": [
0091         {
0092           "name": "BarrelVertexHits",
0093           "type": "BoxHit",
0094           "origin": {"type": "edm4eic::TrackerHitData", "name": "MPGDBarrelRecHits"},
0095            ...,
0096         },
0097         ...
0098       ]
0099     },
0100     ...
0101   ]
0102 }
0103 ```
0104 
0105 ## BoxHit group
0106 
0107 ```json
0108 {
0109   "pos": [1, 2, 3],
0110   "dim": [10, 10, 1],
0111   "t": [4, 1],
0112   "ed": [0.001, 0.0001]
0113 }
0114 ```
0115 Hit has
0116 
0117 - "pos": position [mm]  (x, y, z),
0118 - "dim": box dimensions [mm] (dx, dy, dz),
0119 - "t": time information [ns] (time, err_time),
0120 - "ed": energy deposit with error [GeV] (edep, err_edep)
0121 
0122 Example
0123 
0124 ```json
0125 "groups": [
0126 {
0127   "name": "MPGDBarrelRecHits",
0128   "type": "BoxHit",
0129   "origin": {"type": "edm4eic::TrackerHitData", "name": "MPGDBarrelRecHits"}
0130   "hits": [
0131     {
0132       "pos": [-567, -84.1, -908],
0133       "dim": [0.05,  0.04,  0.0],
0134       "t":   [-10.6, 10.0],
0135       "ed":  [2e-06,  0.0]
0136     },
0137     {
0138       "pos": [368, -424, 406],
0139       "dim": [0.05, 0.045, 0.0],
0140       "t":   [33, 10],
0141       "ed":  [9e-06, 0.0]
0142     },
0143 ...]
0144 }]
0145 ```
0146 
0147 ## Trajectory group
0148 
0149 Trajectories that are built based on lines connecting points.
0150 
0151 ```json
0152       "groups": [
0153         {
0154           "name": "CentralTrackSegments",
0155           "type": "PointTrajectory",
0156           "origin": { "type": ["edm4eic::TrackPoint","edm4eic::TrackSegment"]}
0157           "paramColumns": [".."], // Param columns should correspond to what is written in line/track params
0158           "pointColumns": ["x", "y", "z", "t", "dx", "dy", "dz", "dt"] 
0159               
0160           "trajectories": [
0161               {
0162                   points: [
0163                   [x, y, z, t, dx, dy, dz, dt],
0164                   [x, y, z, t, dx, dy, dz, dt],
0165                   ... // all points go here
0166                   ],
0167                   params: [...]   // values to parameter columns here
0168               },
0169               ...  // other lines
0170           ]
0171         ...
0172       ]
0173 ```
0174 
0175 ## HomoHisto2D group
0176 
0177 Square 2D histogram where elements are of the same size and arranged over cols and plots.
0178 The value of each histogram bin can change in time
0179 
0180 ** - 
0181 
0182 
0183 
0184 
0185 
0186 ## TypeScript Event Model
0187 
0188 
0189 The Firebird Data Exchange model provides a structured way to serialize and deserialize
0190 event data. The model is implemented in TypeScript and designed to be extensible by users, 
0191 so they could add their own custom groups without modifying the core parsing logic.
0192 
0193 The implementation TypeScript classes mirror the data exchange format 
0194 and provide methods for serialization and deserialization.
0195 
0196 - **DataExchange** class - Represents the entire data exchange object.
0197 - **Event** class - Represents an individual event.
0198 - **EventGroup** abstract class - A base class representing a generic group. Described below.
0199 
0200 It Typescript Firebird Data Exchange often referenced as Dex (Data EXchange) or FDEX. E.g.
0201 `toDexObject`, `fromDexObject`. `DexObject` is a JS object, that if serialized to JSON
0202 would correspond a part of DataExchangeFormat. E.g. Dex BoxHit will have `pos`, `dim` etc.
0203 
0204 What is JSON DEX and Typescript data model difference? 
0205 
0206 In general JSON format is very close to object definition in JS => TS.
0207 But despite that, Firebird JSON format is just a data exchange layer and when deserialized from
0208 JSON is not designed to be a 100% a convenient to work with JS data structure.
0209 More over, it lacks some methods and abstractions, that our domain data-model should have,
0210 such as links between event model and three.js rendering tree objects.
0211 
0212 Summarizing:
0213 
0214 - Firebird Data Exchange - is JSON schema shaping data exchange between backend and frontend
0215 - DexObject - JSON parsed to JS object
0216 - TypeScript event model - Frontend set of classes mimicking DexObject structure but designed
0217   to be convenient in terms of the frontend API
0218 
0219 
0220 ### EventGroups machinery
0221 
0222 Different collection of objects such as hits, tracks, vertexes, etc.
0223 that firebird can work with are represented as various **group-s**.
0224 Each type derive from `EventGroup` and registered in a system.
0225 Then corresponding `Painter`-s classes know how to render/paint them, there are rules how
0226 to display them in tables, etc. Corresponding `Component`class can show GUI configuring configs, etc. 
0227 
0228 - **EventGroup**  An abstract class representing a generic group.
0229 - Contains common properties:
0230   - `name`: Unique identifier.
0231   - `type`: group type (used for determining the appropriate factory).
0232   - `origin`: Optional string indicating the origin type.
0233 - Declares an abstract method `toDexObject()` that must be implemented by subclasses.
0234 
0235 - **EventGroupFactory Interface**: Defines a factory for creating `EventGroup`
0236   instances from Dex objects - deserialized data.
0237 - **group Registry**: A mapping of group types to their corresponding factories.
0238 - Functions:
0239   - `registergroupFactory(factory: EventGroupFactory)`: Registers a new factory.
0240   - `getgroupFactory(type: string)`: Retrieves a factory based on the group type.
0241 
0242 
0243 ## Extending the Model
0244 
0245 ### Adding a New group Type
0246 
0247 To add a new group type, follow these steps:
0248 
0249 1. **Create a New group Class**: Extend `EventGroup` and implement the `toDexObject()` method.
0250 
0251    ```typescript
0252    export class Customgroup extends EventGroup {
0253      static type = 'CustomType';
0254      // Define additional properties
0255 
0256      constructor(name: string, /* additional parameters */, origin?: string) {
0257        super(name, Customgroup.type, origin);
0258        // Initialize additional properties
0259      }
0260 
0261      toDexObject(): any {
0262        return {
0263          name: this.name,
0264          type: this.type,
0265          origin: {type: this.origin},
0266          // Serialize additional properties
0267        };
0268      }
0269    }
0270    ```
0271 
0272 2. **Create a Factory for the group**: Implement `EventGroupFactory` for your group.
0273 
0274    ```typescript
0275    export class CustomgroupFactory implements EventGroupFactory {
0276      type: string = Customgroup.type;
0277 
0278      fromDexObject(obj: any): EventGroup {
0279        const name = obj["name"];
0280        // Extract additional properties
0281        const origin = obj["origin"];
0282 
0283        // Validate required fields
0284        if (!name /* || missing other required fields */) {
0285          throw new Error("Missing required fields in Customgroup");
0286        }
0287 
0288        return new Customgroup(name, /* additional parameters */, origin);
0289      }
0290    }
0291    ```
0292 
0293 3. **Register the Factory**: Use the `registerGroupFactory()` function to register your group factory.
0294 
0295    ```typescript
0296    // Register the custom group factory
0297    registergroupFactory(new CustomgroupFactory());
0298    ```
0299 
0300 4. **Update JSON Parsing Logic**: No need to modify existing parsing logic. The registry will dynamically resolve the new group type.
0301