Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/packages/root2dex/README.md is written in an unsupported language. File is not indexed.

0001 # @dexvis/root2dex
0002 
0003 Converts EDM4eic / EDM4hep podio ROOT files to Firebird DEX, in the browser or
0004 in node, through the JSROOT API.
0005 
0006 This is the TypeScript twin of `pyrobird convert`. For the same input file,
0007 entries and options the two produce the same DEX document, value for value -
0008 `src/parity.spec.ts` pins that against reference documents written by pyrobird.
0009 One default differs: pyrobird keeps its own list of Cherenkov collections out
0010 of the EDM4hep MC-truth trajectories, and this package keeps none out until
0011 you name them in `trajectoryExcludedCollections`.
0012 
0013 ```ts
0014 import { Root2DexConverter } from '@dexvis/root2dex';
0015 
0016 const converter = await Root2DexConverter.open(file);   // File, URL, path, or byte-range source
0017 console.log(converter.model, converter.entryCount);      // 'edm4eic' | 'edm4hep', number of events
0018 const dex = await converter.convert(eventNumber);        // a DEX 1.0 document
0019 ```
0020 
0021 One-shot form, equivalent to the CLI:
0022 
0023 ```ts
0024 const dex = await convertRootToDex('https://host/reco.edm4eic.root', '0-4');
0025 ```
0026 
0027 ## Entry selections
0028 
0029 Entries are written as `3`, `1-5` or `1,2-5,8`. Entries the file does not
0030 hold are dropped with one warning (through `options.onWarning`, or
0031 `console.warn` without it): `0-99` on a 10-entry file converts entries 0-9.
0032 A selection with no entry in the file throws `EntrySelectionError`, and the
0033 message names the file's entry count. pyrobird applies the same rules with
0034 the same messages.
0035 
0036 The `@dexvis/root2dex/entries` subpath holds the selection helpers
0037 (`parseEntryRanges`, `selectEntries`, `DEFAULT_MAX_ENTRIES`) without the
0038 converter and its jsroot import.
0039 
0040 ## Only the requested event is read
0041 
0042 Event files are routinely many GB, so nothing ever loads the whole file.
0043 JSROOT reads the key directory, the streamer info and the TTree metadata when
0044 the file is opened, and after that only the baskets covering the requested
0045 entry. Measured on the repository's test files:
0046 
0047 | file | size | open | per event |
0048 |---|---|---|---|
0049 | `reco_2024-09_craterlake_2evt.edm4eic.root` | 0.94 MB | 0.26 MB | 22 kB |
0050 | `k_lambda_10x100_2evt.edm4hep.root` | 1.22 MB | 0.05 MB | 29 kB |
0051 
0052 The open cost is paid once per file, not once per event, which is why
0053 `Root2DexConverter` keeps the file open. All the branches an event needs are
0054 read in ONE `treeProcess` pass so their baskets go out as few requests — a pass
0055 per column would multiply the round trips by the number of columns.
0056 
0057 Sources `Root2DexConverter.open` accepts:
0058 
0059 - a browser `File` (file picker or drag-and-drop) — read with `Blob.slice`
0060 - an `http(s)` URL — HTTP Range requests
0061 - a path or `file://` URL under node
0062 - anything built with `createByteRangeSource()` — you supply
0063   `readRange(pos, len)`, and optionally `readRanges([...])` when the transport
0064   can answer several ranges in one round trip. This is where a remote XRootD
0065   byte-range proxy plugs in; nothing else in the package changes.
0066 
0067 ## What is converted
0068 
0069 Matching pyrobird's `edm4eic.py` and `edm4hep.py`:
0070 
0071 **edm4eic** (`tracker_hits`, `tracks`)
0072 - every `vector<edm4eic::TrackerHitData>` collection → a `BoxHit` piece, box
0073   dimensions from `positionError` (±1σ). Empty collections are kept as count-0
0074   pieces.
0075 - `CentralTrackSegments` + its `TrackPoint`s → one `PointTrajectory` piece,
0076   parameters taken positionally from `CentralCKFTrackParameters` (the one-to-one
0077   relation to Track cannot be followed — EICrecon issue #1730).
0078 
0079 **edm4hep** (`tracker_hits`, `mc_trajectories`)
0080 - every `vector<edm4hep::SimTrackerHitData>` collection → a `BoxHit` piece with
0081   a fixed box size (sim hits carry no errors). Collections empty in this event
0082   are dropped.
0083 - MC-truth trajectories: hits pooled across collections, grouped by their
0084   `MCParticle`, sorted by time, one `PointTrajectory` piece. Collections named
0085   in the `trajectoryExcludedCollections` option (default: none) stay out of
0086   trajectory building and still appear as `BoxHit` pieces. Name the
0087   Cherenkov/PID collections there: their photon hits are attributed to the
0088   emitting charged particle and draw zigzags.
0089 
0090 The data model is detected from the branch types — files carrying both win as
0091 `edm4eic` — and can be overridden with the `model` option.
0092 
0093 ## Tests
0094 
0095 ```bash
0096 npm test -w @dexvis/root2dex
0097 ```
0098 
0099 The specs read pyrobird's test ROOT files from `pyrobird/tests/unit_tests/data`
0100 and the reference DEX documents in `test-data/`; they skip themselves when
0101 those files are absent.