|
| 1 | +<!-- doxy |
| 2 | +\page refrunSimExamplesHepMC Example reading HepMC events |
| 3 | +/doxy --> |
| 4 | + |
| 5 | +Here are pointers on how to use `GeneratorHepMC` selected by the |
| 6 | +option `-g hepmc` for `o2-sim`. |
| 7 | + |
| 8 | +## Reading HepMC files |
| 9 | + |
| 10 | +The generator `GeneratorHepMC` can read events from a |
| 11 | +[HepMC(3)](http://hepmc.web.cern.ch/hepmc/) formatted file. These files |
| 12 | +can be produced by a standalone event generator program (EG). |
| 13 | +Examples of such programs are |
| 14 | + |
| 15 | +- [Pythia8](https://pythia.org) |
| 16 | +- The [CRMC](https://gitlab.iap.kit.edu/AirShowerPhysics/crmc) suite |
| 17 | +- [Herwig](https://herwig.hepforge.org/) |
| 18 | +- [SMASH](https://smash-transport.github.io/) |
| 19 | +- ... and many others |
| 20 | + |
| 21 | +Please refer to the documentation of these for more on how to make |
| 22 | +event files in the HepMC format. |
| 23 | + |
| 24 | +To make a simulation reading from the file `events.hepmc`, do |
| 25 | + |
| 26 | + o2-sim -g hepmc --configKeyValues "HepMC.fileName=events.hepmc" ... |
| 27 | + |
| 28 | +See also [`read.sh`](read.sh) |
| 29 | + |
| 30 | +## Reading HepMC events from child process |
| 31 | + |
| 32 | +`GeneratorHepMC` can not only read HepMC events from a file, but can |
| 33 | +also spawn an child EG to produce events. Suppose we have a program |
| 34 | +named `eg` which is some EG that writes HepMC event records to the |
| 35 | +standard output. Then we can execute a simulation using this external |
| 36 | +EG by |
| 37 | + |
| 38 | + o2-sim -g hepmc --configKeyValues "HepMC.progCmd=eg" |
| 39 | + |
| 40 | +See also [`child.sh`](child.sh) |
| 41 | + |
| 42 | +There are some requirements on the program `eg`: |
| 43 | + |
| 44 | +- It _must_ write the HepMC event structures to standard output |
| 45 | + (`/dev/stdout`). |
| 46 | +- It may _not_ write other information to standard output. |
| 47 | +- It _must_ accept the option `-n n-events` to set the number of |
| 48 | + events to produce to `n-events`. |
| 49 | + |
| 50 | +If a program does not adhere to these requirements, it will often be |
| 51 | +simple enough to make a small wrapper script that enforce this. For |
| 52 | +example, `crmc` will write a lot of information to standard output. |
| 53 | +We can filter that out via a shell script ([`crmc.sh`](crmc.sh)) like |
| 54 | + |
| 55 | + #!/bin/sh |
| 56 | + |
| 57 | + crmc $@ -o hepmc3 -f /dev/stdout | sed -n 's/^\(HepMC::\|[EAUWVP] \)/\1/p' |
| 58 | + |
| 59 | +The `sed` command selects lines that begin with `HepMC::`, or one |
| 60 | +of single characters `E` (event), `A` (attribute), `U` (units), `W` |
| 61 | +(weight), `V` (vertex), or `P` (particle) followed by a space. This |
| 62 | +should in most cases be enough to filter out extra stuff written on |
| 63 | +standard output. |
| 64 | + |
| 65 | +The script above also passes any additional command line options on to |
| 66 | +`crmc` via `$@`. We can utilise this with `o2-sim` to set options to |
| 67 | +the CRMC suite. For example, if we want to simulate p-Pb collisions |
| 68 | +using DpmJET, we can do |
| 69 | + |
| 70 | + o2-sim -g hepmc --configKeyValues "HepMC.progCmd=crmc.sh -m 12 -i2212 -I 1002080820" |
| 71 | + |
| 72 | + |
| 73 | +### Implementation details |
| 74 | + |
| 75 | +Internally `GeneratorHepMC` |
| 76 | + |
| 77 | +1. creates a unique temporary file name in the working directory, |
| 78 | +2. then creates a FIFO (or named pipe, see |
| 79 | + [Wikipedia](https://en.wikipedia.org/wiki/Named_pipe)), |
| 80 | +3. builds a command line, e.g., |
| 81 | + |
| 82 | + eg options > fifo-name & |
| 83 | + |
| 84 | +4. and executes that command line |
| 85 | + |
| 86 | +## The future |
| 87 | + |
| 88 | +The `GeneratorHepMC` (and sister generator `GeneratorTParticle`) will |
| 89 | +in the not so distant future be upgraded with new functionality to |
| 90 | +more easily customise reading files and executing a child process. In |
| 91 | +particular |
| 92 | + |
| 93 | +- HepMC event structures can be read from any file format supported by |
| 94 | + HepMC it self (see |
| 95 | + [here](http://hepmc.web.cern.ch/hepmc/group__IO.html) and |
| 96 | + [here](http://hepmc.web.cern.ch/hepmc/group__factory.html). |
| 97 | + |
| 98 | +- New options that can be specified in `--configKeyValues` |
| 99 | + |
| 100 | + - `HepMC.eventsToSkip=number` a number events to skip at the |
| 101 | + beginning of each file read. |
| 102 | + |
| 103 | + - `FileOrCmd.fileNames=list` a comma separated list of HepMC files |
| 104 | + to read |
| 105 | + |
| 106 | + - `FileOrCmd.cmd=command line` a command line to execute as a |
| 107 | + background child process. If this is set (not the empty string), |
| 108 | + then `FileOrCmd.fileNames` is ignored. |
| 109 | + |
| 110 | + - A number of keys that specifies the command line option switch |
| 111 | + that the child program accepts for certain things. If any of |
| 112 | + these are set to the empty string, then that switch and |
| 113 | + corresponding option value is not passed to the child program. |
| 114 | + |
| 115 | + - `FileOrCmd.outputSwitch=switch` (default `>`) to specify output |
| 116 | + file. The default of `>` assumes that the program write HepMC |
| 117 | + events, and _only_ those, to standard output. |
| 118 | + |
| 119 | + - `FileOrCmd.seedSwitch=switch` (default `-s`) to specify the |
| 120 | + random number generator seed. The value passed is selected by |
| 121 | + the `o2-sim` option `--seed` |
| 122 | + |
| 123 | + - `FileOrCmd.bMaxSwitch=switch` (default `-b`) to specify the |
| 124 | + upper limit on the impact parameters sampled. The value passed |
| 125 | + is selected by the `o2-sim` option `--bMax` |
| 126 | + |
| 127 | + - `FileOrCmd.nEventsSwitch=switch` (default `-n`) to specify the |
| 128 | + number of events to generate. The value passed is selected by |
| 129 | + the `o2-sim` option `--nEvents` or (`-n`) |
| 130 | + |
| 131 | + - `FileOrCmd.backgroundSwitch=switch` (default `&`) to specify how |
| 132 | + the program is put in the background. Typically this should be |
| 133 | + `&`, but a program may itself fork to the background. |
| 134 | + |
| 135 | +- Some options are no longer available |
| 136 | + |
| 137 | + - `HepMC.fileName` - use `FileOrCmd.fileNames` |
| 138 | + - `HepMC.progCmd` - use `FileOrCmd.cmd` |
| 139 | + |
| 140 | +The command line build will now be |
| 141 | + |
| 142 | +> _commandLine_ _nEventsSwitch_ _nEvents_ _seedSwitch_ _seed_ |
| 143 | +> _bMaxSwitch_ _bMax_ _outputSwitch_ _output_ _backgroundSwitch_ |
| 144 | +
|
| 145 | +If any of the `Switch` keys are empty, then the corresponding option |
| 146 | +is not propagated to the command line. For example, if _bMaxSwitch_ |
| 147 | +is empty, then the build command line will be |
| 148 | + |
| 149 | +> _commandLine_ _nEventsSwitch_ _nEvents_ _seedSwitch_ _seed_ |
| 150 | +> _outputSwitch_ _output_ _backgroundSwitch_ |
| 151 | +
|
0 commit comments