Warning, /firebird/dd4hep-plugin/README.md is written in an unsupported language. File is not indexed.
0001 # DD4Hep Plugin
0002
0003 Plugin for DD4Hep that allows to dump stepping action and then convert to Phoenix json format.
0004
0005 ## Usage
0006
0007 1. First one has to build DD4Hep plugin and ensure it is discoverable (e.g. `LD_LIBRARY_PATH` is pointing on it
0008 or it is installed in system libraries)
0009
0010 ```bash
0011 git clone https://github.com/eic/firebird.git
0012 cd firebird/dd4hep-plugin
0013 mkdir build && cd build
0014
0015 # This will create prefix/lib folder after the install
0016 cmake ..
0017 make && make install
0018
0019 # By default the library will be installed into firebird/dd4hep-plugin/prefix/lib
0020 cd .. # go back to firebird repo root
0021 ls prefix/lib # <= Ensure libfirebird-dd4hep.so is there
0022
0023 # Make library and .components file are discoverable:
0024 export LD_LIBRARY_PATH="$(pwd)/prefix/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
0025 ```
0026
0027 2. Now you run dd4hep as usual adding special steering file through `--steeringFile` flag.
0028 This plugin comes with several predefined steering files.
0029 You can copy them, configure and add your own configs!
0030
0031 ```bash
0032 # assuming you are in:
0033 # firebird/dd4hep-plugin
0034 pwd # <= ensure you are in firebird/dd4hep-plugin
0035
0036 ddsim --steeringFile=my_steering.py --compactFile=geometry -N=5 --outputFile=sim_output.edm4hep.root --inputFiles sim_input.hepmc
0037 ```
0038
0039 This will produce `sim_output.firebird.json` Firebird format JSON file containing steps info
0040
0041 > (!) for large events or e.g. if optical photons are saved, such file could easily be gigabytes in size
0042
0043 ## How it works
0044
0045 Under the hood **Firebird dd4hep-plugin** comes with several Geant4 "actions" that can injected
0046 into DD4Hep processing using steering file or python configuration.
0047
0048 - `FirebirdTrajectoryWriterEventAction` this is the main intended to use event-action. Use it with
0049 `firebird_steering.py`. It enables Geant4 to save trajectories in the end of event. These
0050 trajectories are the same, that are used in Geant4 event display. Then event-action saves
0051 the trajectories into the firebird format. Saving one full event with all showers can easily take
0052 tenths of gygabytes, so users can customize cuts in steering file to save only required data.
0053
0054 - `FirebirdTrajectoryWriterSteppingAction` - this class uses Geant4 stepping action and writes
0055 data as Geant4 generates it. As is it doesn't provide benefits compared to event-action,
0056 (moreover event-action trajectories are designed to be displayed so geant4 may add points to smooth them).
0057 But **users can modify C++ code of this file** if they need any custom internal Geant4 data.
0058 Stepping action has access to simulation data as steps occur, detailed physics information,
0059 complete access to physics processes at each step and can potentially modify the simulation while it runs
0060
0061 - `TextDumpingSteppingAction` - is a Geant4 stepping action for DD4hep that records detailed
0062 trajectory information during simulation. It writes track and step data to a simple text file format
0063 that can be easily parsed for custom analysis or visualization (NOT Firebird). This file is also
0064 easy to use as C++ plugin example.
0065
0066 ### Pre-made steering files:
0067
0068 - firebird_steering.py - intended for the first or regular use. Saves everything > 350 MeV (no optical photons)
0069 - cuts_example_steering.py - shows all possible cuts
0070 - optical steering.py - saves only generator particles and optical photons. Good to introspects detectors like DIRC
0071 - save_all_steering.py - saves all including optical photons and particles > 1MeV.
0072 Use it carefully with particular detectors or space cuts. Easily can make Gigabytes long files.
0073 -
0074
0075
0076
0077
0078
0079 ## Configuration Options
0080
0081 ### FirebirdTrajectoryWriterEventAction Configuration Options
0082
0083 The `FirebirdTrajectoryWriterEventAction` provides extensive configuration options for filtering and controlling trajectory output:
0084
0085 | Parameter | Type | Default | Description |
0086 |-----------|------|---------|-------------|
0087 | `OutputFile` | string | "trajectories.firebird.json" | Output file name for the JSON trajectory data |
0088 | `ComponentName` | string | "Geant4Trajectories" | Component name that will appear in the Firebird display |
0089 | `SaveOptical` | bool | false | When true, optical photons are saved regardless of other filter settings |
0090 | `OnlyPrimary` | bool | false | When true, only primary tracks (ParentID=0) are saved |
0091 | `VertexCut` | bool | false | Enable vertex position filtering |
0092 | `VertexZMin` | double | -5000 | Minimum Z position (mm) for track vertex (start point) |
0093 | `VertexZMax` | double | 5000 | Maximum Z position (mm) for track vertex (start point) |
0094 | `StepCut` | bool | false | Enable step-by-step position filtering |
0095 | `StepZMin` | double | -5000 | Minimum Z position (mm) for any track step to be recorded |
0096 | `StepZMax` | double | 5000 | Maximum Z position (mm) for any track step to be recorded |
0097 | `StepRMax` | double | 5000 | Maximum radial distance from Z axis (mm) for any track step to be recorded |
0098 | `MomentumMin` | double | 150 | Minimum momentum (MeV/c) for tracks to be saved |
0099 | `MomentumMax` | double | 1e6 | Maximum momentum (MeV/c) for tracks to be saved |
0100 | `TrackLengthMin` | double | 0 | Minimum track length (mm) for tracks to be saved |
0101 | `SaveParticles` | vector<int> | [] | List of PDG codes to save. If empty, save all particle types |
0102 | `RequireRichTrajectory` | bool | true | When true, only use trajectories that provide proper time information |
0103 | `VerboseTimeExtraction` | bool | false | Enable detailed logging of time extraction from trajectory points |
0104
0105 #### Filtering Explanation
0106
0107 The `FirebirdTrajectoryWriterEventAction` applies filters in the following order:
0108
0109 1. **Particle Type Filtering**:
0110 - If `SaveOptical` is true, optical photons are always saved regardless of other filters
0111 - If `SaveParticles` is not empty, only particles with matching PDG codes are saved
0112
0113 2. **Track Source Filtering**:
0114 - If `OnlyPrimary` is true, only tracks with ParentID=0 (primary particles) are saved
0115
0116 3. **Momentum Filtering**:
0117 - Tracks with momentum outside the range [`MomentumMin`, `MomentumMax`] are filtered out
0118
0119 4. **Vertex Position Filtering**:
0120 - If `VertexCut` is true, tracks with vertex Z position outside the range [`VertexZMin`, `VertexZMax`] are filtered out
0121
0122 5. **Step Position Filtering**:
0123 - If `StepCut` is true, individual track points with Z position outside [`StepZMin`, `StepZMax`] or radial distance greater than `StepRMax` are filtered out
0124 - Tracks that have all points filtered out are not saved
0125
0126 6. **Track Length Filtering**:
0127 - If `TrackLengthMin` > 0, tracks shorter than this length are filtered out
0128
0129 7. **Rich Trajectory Requirement**:
0130 - If `RequireRichTrajectory` is true, only trajectories that properly support time extraction are saved
0131
0132 ### Example Usage in Steering File
0133
0134 Here's how to configure the event action in your steering file:
0135
0136 ```python
0137 # Instantiate the event action
0138 event_action = DDG4.EventAction(kernel, 'FirebirdTrajectoryWriterEventAction/TrajectoryWriter')
0139 event_action.ComponentName = "Geant4Trajectories" # Tracks group name in firebird
0140 event_action.OutputFile = "mytrajectories.firebird.json"
0141 event_action.OnlyPrimary = True # Only keep primary tracks
0142 event_action.MomentumMin = 350 # Minimum momentum (MeV/c)
0143 event_action.StepCut = True # Enable step position filtering
0144 event_action.StepZMin = -3000 # Minimum Z (mm) for track steps
0145 event_action.StepZMax = 3000 # Maximum Z (mm) for track steps
0146 event_action.StepRMax = 2000 # Maximum R (mm) for track steps
0147
0148 # Add the event action to the kernel
0149 kernel.eventAction().add(event_action)
0150 ```
0151
0152 ### FirebirdTrajectoryWriterSteppingAction Configuration
0153
0154 Similar configuration options are available for the stepping action version of the firebird writer.
0155 See the source code for detailed documentation of these parameters.
0156
0157 ## EIC specific example
0158
0159 EIC openly provides docker images as well as sample data. Docker/singularity images aka eic_shell
0160 ships all standard HENP stack, such as ROOT, Geant4, DD4Hep, Acts etc.
0161
0162 One can start this example simply by [eic_shell](https://eic.github.io/tutorial-setting-up-environment/index.html) or
0163 [eicweb/eic_xl](https://hub.docker.com/r/eicweb/eic_xl/tags) docker image:
0164
0165 ```bash
0166 docker pull eicweb/eic_xl:nightly
0167 docker run --rm -it -v /host/where/phoenix-dd4hep:/mnt/phoenix-dd4hep -v /host/place/with/data:/mnt/data eicweb/eic_xl:nightly
0168 ```
0169
0170 ```bash
0171 # Build dd4hep plugin and install to system root
0172 cd /mnt/phoenix-dd4hep
0173 mkdir build && cd build && cmake ..
0174 make && make install
0175 cd ..
0176
0177 # Make sure the library and .components file are discoverable:
0178 export LD_LIBRARY_PATH="/mnt/phoenix-dd4hep/prefix/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
0179
0180 # Use the default ePIC detector for DD4HEP
0181 source /opt/detector/epic-main/bin/thisepic.sh
0182
0183 # Copy example steering file
0184 cp /mnt/phoenix-dd4hep/steering.py /mnt/data/
0185 # edit parameters of /mnt/data/steering.py
0186
0187 # Copy example hepmc3 input file
0188 xrdcp root://dtn2001.jlab.org:1094//work/eic2/EPIC/EVGEN/CI/pythia8NCDIS_5x41_minQ2=1_beamEffects_xAngle=-0.025_hiDiv_1_20ev.hepmc3.tree.root /mnt/data/test.hepmc3.tree.root
0189
0190 # Run DDSIM 10 events
0191 ddsim --steeringFile=/mnt/data/steering.py --compactFile=$DETECTOR_PATH/epic.xml -N=10 --outputFile=/mnt/data/sim_output.edm4hep.root --inputFiles /mnt/data/test.hepmc3.tree.root
0192
0193 # Convert to phoenix
0194 python3 dd4hep_txt_to_phoenix.py -o /mnt/data/result.phoenix.json /mnt/data/sim_output.evt.txt
0195 ```
0196
0197 ## Text Stepping Dump Format
0198
0199 The dump format is dumb:
0200
0201 ```
0202 #Format description
0203 # E - event: run_num event_num
0204 # T - track: id, status, pdg, pdg_name, eta, phi, qOverP, px, py, pz, vx, vy, vz
0205 # P - point: x, y, z, t
0206 E 0 0
0207 T 8 2212 proton 1 3.5709294573447994 2.261549546104013 6.396484757681894e-05 -559.9251499726829 677.3808238429499 15608.865329424996 0.03897413220097487 0.05261577347068468 18.657590231736023
0208 P 0.03897413220097487 0.05261577347068468 18.657590231736023 -0.07918188652875727
0209 P -17.623005842295107 21.759339731997773 515.6859422023264 1.5843399605023456
0210 P -17.941631710801495 22.14470031506324 524.5667632485647 1.6140634959863716
0211 ...
0212 ```
0213
0214 - Lines beginning with E mark the start of a new event
0215 - Lines beginning with T contain information about a particle track
0216 - Lines beginning with P contain step point information
0217
0218 The file is organized in a hierarchical manner:
0219
0220 - Event record (E)
0221 - Track record (T)
0222 - Multiple point records (P) for that track
0223 - Next track record
0224 - And so on...
0225
0226 For each track, there's always at least two points:
0227
0228 - The first point (P) after a track record is the PreStepPoint (beginning of step)
0229 - Subsequent points are PostStepPoints (end of steps)