Back to home page

EIC code displayed by LXR

 
 

    


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 ## Configuration Options
0076 
0077 ### FirebirdTrajectoryWriterEventAction Configuration Options
0078 
0079 The `FirebirdTrajectoryWriterEventAction` provides extensive configuration options for filtering and controlling trajectory output:
0080 
0081 | Parameter | Type | Default | Description |
0082 |-----------|------|---------|-------------|
0083 | `OutputFile` | string | "trajectories.firebird.json" | Output file name for the JSON trajectory data |
0084 | `ComponentName` | string | "Geant4Trajectories" | Component name that will appear in the Firebird display |
0085 | `SaveOptical` | bool | false | When true, optical photons are saved regardless of other filter settings |
0086 | `OnlyPrimary` | bool | false | When true, only primary tracks (ParentID=0) are saved |
0087 | `VertexCut` | bool | false | Enable vertex position filtering |
0088 | `VertexZMin` | double | -5000 | Minimum Z position (mm) for track vertex (start point) |
0089 | `VertexZMax` | double | 5000 | Maximum Z position (mm) for track vertex (start point) |
0090 | `StepCut` | bool | false | Enable step-by-step position filtering |
0091 | `StepZMin` | double | -5000 | Minimum Z position (mm) for any track step to be recorded |
0092 | `StepZMax` | double | 5000 | Maximum Z position (mm) for any track step to be recorded |
0093 | `StepRMax` | double | 5000 | Maximum radial distance from Z axis (mm) for any track step to be recorded |
0094 | `MomentumMin` | double | 150 | Minimum momentum (MeV/c) for tracks to be saved |
0095 | `MomentumMax` | double | 1e6 | Maximum momentum (MeV/c) for tracks to be saved |
0096 | `TrackLengthMin` | double | 0 | Minimum track length (mm) for tracks to be saved |
0097 | `SaveParticles` | vector<int> | [] | List of PDG codes to save. If empty, save all particle types |
0098 | `RequireRichTrajectory` | bool | true | When true, only use trajectories that provide proper time information |
0099 | `VerboseTimeExtraction` | bool | false | Enable detailed logging of time extraction from trajectory points |
0100 
0101 #### Filtering Explanation
0102 
0103 The `FirebirdTrajectoryWriterEventAction` applies filters in the following order:
0104 
0105 1. **Particle Type Filtering**:
0106    - If `SaveOptical` is true, optical photons are always saved regardless of other filters
0107    - If `SaveParticles` is not empty, only particles with matching PDG codes are saved
0108 
0109 2. **Track Source Filtering**:
0110    - If `OnlyPrimary` is true, only tracks with ParentID=0 (primary particles) are saved
0111 
0112 3. **Momentum Filtering**:
0113    - Tracks with momentum outside the range [`MomentumMin`, `MomentumMax`] are filtered out
0114 
0115 4. **Vertex Position Filtering**:
0116    - If `VertexCut` is true, tracks with vertex Z position outside the range [`VertexZMin`, `VertexZMax`] are filtered out
0117 
0118 5. **Step Position Filtering**:
0119    - If `StepCut` is true, individual track points with Z position outside [`StepZMin`, `StepZMax`] or radial distance greater than `StepRMax` are filtered out
0120    - Tracks that have all points filtered out are not saved
0121 
0122 6. **Track Length Filtering**:
0123    - If `TrackLengthMin` > 0, tracks shorter than this length are filtered out
0124 
0125 7. **Rich Trajectory Requirement**:
0126    - If `RequireRichTrajectory` is true, only trajectories that properly support time extraction are saved
0127 
0128 ### Example Usage in Steering File
0129 
0130 Here's how to configure the event action in your steering file:
0131 
0132 ```python
0133 # Instantiate the event action
0134 event_action = DDG4.EventAction(kernel, 'FirebirdTrajectoryWriterEventAction/TrajectoryWriter')
0135 event_action.ComponentName = "Geant4Trajectories"   # Tracks group name in firebird
0136 event_action.OutputFile = "mytrajectories.firebird.json"
0137 event_action.OnlyPrimary = True                    # Only keep primary tracks
0138 event_action.MomentumMin = 350                     # Minimum momentum (MeV/c)
0139 event_action.StepCut = True                        # Enable step position filtering
0140 event_action.StepZMin = -3000                      # Minimum Z (mm) for track steps
0141 event_action.StepZMax = 3000                       # Maximum Z (mm) for track steps
0142 event_action.StepRMax = 2000                       # Maximum R (mm) for track steps
0143 
0144 # Add the event action to the kernel
0145 kernel.eventAction().add(event_action)
0146 ```
0147 
0148 ### FirebirdTrajectoryWriterSteppingAction Configuration
0149 
0150 Similar configuration options are available for the stepping action version of the firebird writer.
0151 See the source code for detailed documentation of these parameters.
0152 
0153 ## EIC specific example
0154 
0155 EIC openly provides docker images as well as sample data. Docker/singularity images aka eic_shell
0156 ships all standard HENP stack, such as ROOT, Geant4, DD4Hep, Acts etc.
0157 
0158 One can start this example simply by [eic_shell](https://eic.github.io/tutorial-setting-up-environment/index.html) or
0159 [eicweb/eic_xl](https://hub.docker.com/r/eicweb/eic_xl/tags) docker image:
0160 
0161 ```bash
0162 docker pull eicweb/eic_xl:nightly
0163 docker run --rm -it -v /host/where/phoenix-dd4hep:/mnt/phoenix-dd4hep -v /host/place/with/data:/mnt/data eicweb/eic_xl:nightly
0164 ```
0165 
0166 ```bash
0167 # Build dd4hep plugin and install to system root
0168 cd /mnt/phoenix-dd4hep
0169 mkdir build && cd build && cmake ..
0170 make && make install 
0171 cd ..
0172 
0173 # Make sure the library and .components file are discoverable:
0174 export LD_LIBRARY_PATH="/mnt/phoenix-dd4hep/prefix/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
0175     
0176 # Use the default ePIC detector for DD4HEP
0177 source /opt/detector/epic-main/bin/thisepic.sh
0178 
0179 # Copy example steering file
0180 cp /mnt/phoenix-dd4hep/steering.py /mnt/data/
0181 # edit parameters of /mnt/data/steering.py
0182 
0183 # Copy example hepmc3 input file
0184 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
0185 
0186 # Run DDSIM 10 events
0187 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
0188 
0189 # Convert to phoenix
0190 python3 dd4hep_txt_to_phoenix.py -o /mnt/data/result.phoenix.json /mnt/data/sim_output.evt.txt
0191 ```
0192 
0193 ## Text Stepping Dump Format
0194 
0195 The dump format is dumb: 
0196 
0197 ```
0198 #Format description
0199 #  E - event: run_num event_num
0200 #  T - track: id, status, pdg, pdg_name, eta, phi, qOverP, px, py, pz, vx, vy, vz
0201 #  P - point: x, y, z, t
0202 E 0 0 
0203 T 8 2212 proton 1 3.5709294573447994 2.261549546104013 6.396484757681894e-05 -559.9251499726829 677.3808238429499 15608.865329424996 0.03897413220097487 0.05261577347068468 18.657590231736023
0204 P 0.03897413220097487 0.05261577347068468 18.657590231736023 -0.07918188652875727
0205 P -17.623005842295107 21.759339731997773 515.6859422023264 1.5843399605023456
0206 P -17.941631710801495 22.14470031506324 524.5667632485647 1.6140634959863716
0207 ... 
0208 ```
0209 
0210 - Lines beginning with E mark the start of a new event
0211 - Lines beginning with T contain information about a particle track
0212 - Lines beginning with P contain step point information
0213 
0214 The file is organized in a hierarchical manner:
0215 
0216 - Event record (E)
0217 - Track record (T)
0218 - Multiple point records (P) for that track
0219 - Next track record
0220 - And so on...
0221 
0222 For each track, there's always at least two points:
0223 
0224 - The first point (P) after a track record is the PreStepPoint (beginning of step)
0225 - Subsequent points are PostStepPoints (end of steps)