Skip to content

Commit bc1e09d

Browse files
committed
Switch option from external to hybrid
1 parent c21d7d7 commit bc1e09d

File tree

8 files changed

+199
-3
lines changed

8 files changed

+199
-3
lines changed

Generators/include/Generators/GeneratorHybridParam.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ namespace eventgen
2929
**/
3030

3131
struct GeneratorHybridParam : public o2::conf::ConfigurableParamHelper<GeneratorHybridParam> {
32-
std::string configFile = ""; // JSON configuration file for the generators
33-
bool randomize = false; // randomize the order of the generators, if not generator using fractions
34-
int num_workers = 1; // number of threads available for asyn/parallel event generation
32+
std::string configFile = ""; // JSON configuration file for the generators
33+
bool randomize = false; // randomize the order of the generators, if not generator using fractions
34+
int num_workers = 1; // number of threads available for asyn/parallel event generation
35+
bool switchExtToHybrid = false; // force external generator to be executed as hybrid mode, useful for Hyperloop MCGEN
3536
O2ParamDef(GeneratorHybridParam, "GeneratorHybrid");
3637
};
3738

Generators/src/GeneratorFactory.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
9393

9494
o2::O2DatabasePDG::addALICEParticles(TDatabasePDG::Instance());
9595
auto genconfig = conf.getGenerator();
96+
#if defined(GENERATORS_WITH_PYTHIA8) && defined(GENERATORS_WITH_HEPMC3)
97+
if (GeneratorHybridParam::Instance().switchExtToHybrid && (genconfig.compare("external") == 0 || genconfig.compare("extgen") == 0)) {
98+
LOG(info) << "Switching external generator to hybrid mode";
99+
genconfig = "hybrid";
100+
}
101+
#endif
96102
LOG(info) << "** Generator to use: '" << genconfig << "'";
97103
if (genconfig.compare("boxgen") == 0) {
98104
// a simple "box" generator configurable via BoxGunparam
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[GeneratorHybrid]
2+
configFile = ${O2_ROOT}/examples/ExternalToHybrid/sequential.json
3+
switchExtToHybrid = true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[GeneratorHybrid]
2+
configFile = ${O2_ROOT}/examples/ExternalToHybrid/cocktail.json
3+
switchExtToHybrid = true
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!-- doxy
2+
\page refrunSimExamplesExternalToHybrid Example ExternalToHybrid
3+
/doxy -->
4+
5+
This example demonstrates how to bypass the Hyperloop limitations when using external generators by switching the configuration to hybrid mode, using the new `GeneratorHybrid.switchExtToHybrid` parameter (set to false by default).
6+
7+
This solution works only with updated O2sim versions containing the `switchExtToHybrid` option.
8+
9+
# Configuration Files
10+
11+
Two example configuration files are provided, each pointing to different hybrid JSON files:
12+
13+
- **GeneratorHyperloopHybridCocktail.ini** → Creates a cocktail mixing two Pythia8 based generators and a boxgen instance
14+
- **GeneratorHyperloopHybrid.ini** → Defines sequential generation of boxgen and EPOS4 events called with an external generator
15+
16+
# Script Description
17+
18+
## rundpl.sh
19+
20+
This script demonstrates event generation using the DPL framework, launching it with the external generator in hybrid mode.
21+
22+
### Available Flags
23+
24+
- **-i, --ini CONFIG** → Specifies the configuration ini file (default: `GeneratorHyperloopHybridCocktail.ini`)
25+
- **-n, --nevents EVENTS** → Sets the number of events to generate (default: 5)
26+
- **-h, --help** → Prints usage instructions and o2-sim-dpl-eventgen help
27+
- **--** → Passes remaining command line arguments to o2-sim-dpl-eventgen
28+
29+
### Usage Examples
30+
31+
Run with default settings (5 events using cocktail configuration):
32+
```bash
33+
./rundpl.sh
34+
```
35+
36+
Generate 10 events using the sequential configuration:
37+
```bash
38+
./rundpl.sh -n 10 -i ${O2_ROOT}/examples/ExternalToHybrid/GeneratorHyperloopHybrid.ini
39+
```
40+
41+
# Requirements
42+
43+
- O2sim version with `switchExtToHybrid` support
44+
- O2_ROOT and O2DPG_MC_CONFIG_ROOT environment variable must be loaded (possibly via O2sim directly)
45+
- Appropriate external generator configurations (e.g., EPOS4) must be available
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"generators": [
3+
{
4+
"cocktail": [
5+
{
6+
"name": "pythia8",
7+
"config": {
8+
"config": "${O2_ROOT}/share/Generators/egconfig/pythia8_inel.cfg",
9+
"hooksFileName": "",
10+
"hooksFuncName": "",
11+
"includePartonEvent": false,
12+
"particleFilter": "",
13+
"verbose": 0
14+
}
15+
},
16+
{
17+
"name": "external",
18+
"config": {
19+
"fileName": "",
20+
"funcName": "",
21+
"iniFile": "${O2DPG_MC_CONFIG_ROOT}/MC/config/ALICE3/ini/pythia8_pp_13tev.ini"
22+
}
23+
},
24+
{
25+
"name": "boxgen",
26+
"config": {
27+
"pdg": 443,
28+
"number": 10,
29+
"eta": [
30+
-0.8,
31+
0.8
32+
],
33+
"prange": [
34+
0.1,
35+
5
36+
],
37+
"phirange": [
38+
0,
39+
360
40+
]
41+
}
42+
}
43+
]
44+
}
45+
],
46+
"fractions": [
47+
1
48+
]
49+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This is a simple example script to bypass the Hyperloop limitations in using
4+
# external generators only, by switching the generator to the hybrid mode
5+
6+
# This script works only with updated O2sim version containing the switchExtToHybrid option
7+
8+
[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 2
9+
[ ! "${O2DPG_MC_CONFIG_ROOT}" ] && echo "Error: This needs O2DPG loaded" && exit 2
10+
11+
NEV=5
12+
# Two example ini configurations are provided pointing to different hybrid JSON files
13+
# One creates a cocktail based on Pythia8, while the other generates sequentially EPOS4 and boxgen events
14+
ini="${O2_ROOT}/examples/ExternalToHybrid/GeneratorHyperloopHybridCocktail.ini"
15+
16+
usage()
17+
{
18+
cat <<EOF
19+
Usage: $0 [OPTIONS]
20+
21+
Options:
22+
23+
-i,--ini INI Configuration ini file ($ini)
24+
-n,--nevents EVENTS Number of events ($nev)
25+
-h,--help Print these instructions
26+
-- Rest of command line sent to o2-sim
27+
28+
COMMAND must be quoted if it contains spaces or other special
29+
characters
30+
31+
Below follows the help output of o2-sim-dpl-eventgen
32+
33+
EOF
34+
}
35+
36+
if [ "$#" -lt 2 ]; then
37+
echo "Running with default values"
38+
fi
39+
40+
while test $# -gt 0 ; do
41+
case $1 in
42+
-i|--ini) ini="$2" ; shift ;;
43+
-n|--nevents) NEV=$2 ; shift ;;
44+
-h|--help) usage; o2-sim-dpl-eventgen --help full ; exit 0 ;;
45+
--) shift ; break ;;
46+
*) echo "Unknown option '$1', did you forget '--'?" >/dev/stderr
47+
exit 3
48+
;;
49+
esac
50+
shift
51+
done
52+
53+
# Starting the dpl-eventgen simulation
54+
o2-sim-dpl-eventgen -b --generator external --nEvents $NEV --configFile $ini
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"generators": [
3+
{
4+
"name": "boxgen",
5+
"config": {
6+
"pdg": 443,
7+
"number": 10,
8+
"eta": [
9+
-0.8,
10+
0.8
11+
],
12+
"prange": [
13+
0.1,
14+
5
15+
],
16+
"phirange": [
17+
0,
18+
360
19+
]
20+
}
21+
},
22+
{
23+
"name": "external",
24+
"config": {
25+
"fileName": "",
26+
"funcName": "",
27+
"iniFile": "${O2DPG_MC_CONFIG_ROOT}/MC/config/examples/ini/GeneratorEPOS4_pp13TeV.ini"
28+
}
29+
}
30+
],
31+
"fractions": [
32+
1,
33+
1
34+
]
35+
}

0 commit comments

Comments
 (0)