Skip to content

Commit dbe3a8d

Browse files
authored
Improved seed and option files handling (#2032)
Each instance of GeneratorEPOS4 will now have a different seed, based on the call order to the gRandom function, and the options files will be separated for each instance. This should fix some issues when calling the generator in parallel or simply in sequence.
1 parent 1489f25 commit dbe3a8d

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

MC/config/examples/epos4/generator_EPOS4.C

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,26 @@ FairGenerator* generateEPOS4(const std::string &name, const int& nEvents)
4343
buffer << line << "\n";
4444
}
4545
file.close();
46+
auto gen = new GeneratorEPOS4();
47+
auto &param0 = o2::eventgen::GeneratorFileOrCmdParam::Instance();
48+
auto &param = o2::eventgen::GeneratorHepMCParam::Instance();
49+
auto &conf = o2::conf::SimConfig::Instance();
50+
// Randomise seed (useful for multiple instances of the generator)
51+
int randomSeed = gRandom->Integer(conf.getStartSeed());
4652
// Write the updated content back to a file in the current directory
47-
std::ofstream outFile("cfg.optns");
53+
std::string optnsFileName(Form("cfg%d.optns", randomSeed));
54+
std::ofstream outFile(optnsFileName);
4855
outFile << buffer.str();
4956
if (!found)
5057
{
5158
outFile << "set nfull " + std::to_string(nEvents);
5259
}
5360
outFile.close();
54-
auto gen = new GeneratorEPOS4();
55-
auto& param0 = o2::eventgen::GeneratorFileOrCmdParam::Instance();
56-
auto& param = o2::eventgen::GeneratorHepMCParam::Instance();
57-
auto& conf = o2::conf::SimConfig::Instance();
61+
optnsFileName = optnsFileName.substr(0, optnsFileName.find_last_of('.')); // remove the .optns extension
5862
// setup the HepMC generator to run with automatic FIFOs
5963
gen->setup(param0, param, conf);
64+
// Replace seed and optns file
65+
gen->setCmd(param0.cmd + " -i " + optnsFileName);
66+
gen->setSeed(randomSeed);
6067
return gen;
6168
}

MC/config/examples/ini/GeneratorEPOS4.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fileName=${O2DPG_MC_CONFIG_ROOT}/MC/config/examples/epos4/generator_EPOS4.C
33
funcName=generateEPOS4("${O2DPG_MC_CONFIG_ROOT}/MC/config/examples/epos4/generator/example.optns", 2147483647)
44

55
[GeneratorFileOrCmd]
6-
cmd=${O2DPG_MC_CONFIG_ROOT}/MC/config/examples/epos4/epos.sh -i cfg
6+
cmd=${O2DPG_MC_CONFIG_ROOT}/MC/config/examples/epos4/epos.sh
77
bMaxSwitch=none
88

99
# Set to version 2 if EPOS4.0.0 is used

MC/config/examples/ini/GeneratorEPOS4HQ.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fileName=${O2DPG_MC_CONFIG_ROOT}/MC/config/examples/epos4/generator_EPOS4.C
44
funcName=generateEPOS4("${O2DPG_MC_CONFIG_ROOT}/MC/config/examples/epos4/generator/examplehq.optns", 2147483647)
55

66
[GeneratorFileOrCmd]
7-
cmd=${O2DPG_MC_CONFIG_ROOT}/MC/config/examples/epos4/epos.sh -i cfg
7+
cmd=${O2DPG_MC_CONFIG_ROOT}/MC/config/examples/epos4/epos.sh
88
bMaxSwitch=none
99

1010
[HepMC]

0 commit comments

Comments
 (0)