Skip to content

Commit

Permalink
Remove superfluous seeding code for GeneratorPythia8 generators
Browse files Browse the repository at this point in the history
This commit harmonizes the seeding procedure of generators based
on o2::eventgen::GeneratorPythia8, following a development done in O2
(AliceO2Group/AliceO2#13281)

In principle, o2::eventgen::GeneratorPythia8 now performs it's own
seeding within the Init function. This seeding makes sure
to integrate with the `--seed` command line option of our event generation
executable.

The commit:
* Removes seeding code in O2DPG when it would override the default
  behaviour from O2.

* Uses a new dedicated function `setInitialSeed` instead of manipulating
  Pythia8 with config strings (in situations in which the user
  targets seeding based on ALIEN_PROC_ID for instance).

* Ensures that event generation becomes more repeatable in situations
  when the same `--seed` is given to the event generation executable.
  This may help to debug crashes on the GRID etc.
  • Loading branch information
sawenzel committed Jul 11, 2024
1 parent 121572c commit f82b452
Show file tree
Hide file tree
Showing 22 changed files with 24 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBJpsiDiElectron);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));


// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -70,13 +62,6 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBJpsiDiMuon);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ GeneratorBeautyToMu_EvtGenFwdY(double rapidityMin = -4.3, double rapidityMax = -
}
if(forcedecay) gen->SetForceDecay(kEvtSemiMuonic);
else gen->SetForceDecay(kEvtAll);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBPsiAndJpsiDiElectron);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -70,13 +61,6 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBPsiAndJpsiDiMuon);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
14 changes: 0 additions & 14 deletions MC/config/PWGDQ/external/generator/GeneratorBeautyToPsi_EvtGen.C
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBPsiDiElectron);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -68,13 +61,6 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBPsiDiMuon);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ FairGenerator*
gen->SetDecayTable(Form("%s/BPLUSTOKAONJPSITOELE.DEC", pathO2.Data()));
// print debug
// gen->PrintDebug();
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));


return gen;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ GeneratorCharmToMu_EvtGenFwdY(double rapidityMin = -4.3, double rapidityMax = -2
printf("PDG %d \n",std::stoi(spdg));
}
gen->SetForceDecay(kEvtSemiMuonic);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public:

protected:

Bool_t generateEvent() override
Bool_t generateEvent() override
{
// reset event
bool genOk = false;
Expand All @@ -90,13 +90,15 @@ Bool_t generateEvent() override
return true;
}

Bool_t Init() override
Bool_t Init() override
{
if(mConfigMBdecays.Contains("cfg")) pythiaMBgen.readFile(mConfigMBdecays.Data());
GeneratorPythia8::Init();
pythiaMBgen.init();
return true;
}
if(mConfigMBdecays.Contains("cfg")) {
pythiaMBgen.readFile(mConfigMBdecays.Data());
}
GeneratorPythia8::Init();
pythiaMBgen.init();
return true;
}

// search for q-qbar mother with at least one q in a selected rapidity window
bool findHeavyQuarkPair(Pythia8::Event& event)
Expand Down Expand Up @@ -181,14 +183,6 @@ FairGenerator*
}
gen->SetForceDecay(kEvtBJpsiDiElectron);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -219,14 +213,6 @@ FairGenerator*
}
gen->SetForceDecay(kEvtBPsiAndJpsiDiElectron);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -261,15 +247,7 @@ FairGenerator*
//gen->SetDecayTable(Form("%s/BPLUSTOKAONJPSITOELE.DEC", pathO2.Data()));
gen->SetDecayTable(Form("%s/BPLUSTOKAONJPSITOELEALLMODES.DEC", pathO2.Data())); // decay table including decay modes for correlated background
// print debug
// gen->PrintDebug();
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// gen->PrintDebug();
return gen;
}

Expand Down Expand Up @@ -298,14 +276,6 @@ FairGenerator*
}
gen->SetForceDecay(kEvtBJpsiDiMuon);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -337,17 +307,8 @@ FairGenerator*
}
gen->SetForceDecay(kEvtBPsiAndJpsiDiMuon);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// print debug
// gen->PrintDebug();

return gen;
}

Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ GeneratorBeautyToEle_EvtGen(double rapidityMin = -2., double rapidityMax = 2., b
if(forcedecay) gen->SetForceDecay(kEvtSemiElectronic);
else gen->SetForceDecay(kEvtAll);
//}
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ GeneratorCharmToEle_EvtGen(double rapidityMin = -2., double rapidityMax = 2., bo
printf("PDG %d \n",std::stoi(spdg));
}
gen->SetForceDecay(kEvtSemiElectronic);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ GeneratorHFToEleFull_EvtGen(bool forcedecay = true, bool allHF = true)
}
if(forcedecay) gen->SetForceDecay(kEvtSemiElectronic);
else gen->SetForceDecay(kEvtAll);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,5 @@ class GeneratorPythia8GapTriggeredLFee : public GeneratorPythia8 {
// Predefined generators: // this function should be called in ini file.
FairGenerator *GeneratorPythia8GapTriggeredLFee_ForEM(int inputTriggerRatio = 5, float yMin=-1.2, float yMax=1.2, int nPart = 1, int mode = -1) {
auto myGen = new GeneratorPythia8GapTriggeredLFee(inputTriggerRatio, yMin, yMax, nPart, mode);
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
myGen->readString("Random:setSeed on");
myGen->readString("Random:seed " + std::to_string(seed));
return myGen;
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,5 @@ class GeneratorPythia8GapTriggeredLFgamma : public GeneratorPythia8 {
// Predefined generators: // this function should be called in ini file.
FairGenerator *GeneratorPythia8GapTriggeredLFgamma_ForEM(int inputTriggerRatio = 5, float yMin=-1.2, float yMax=1.2, int nPart = 1) {
auto myGen = new GeneratorPythia8GapTriggeredLFgamma(inputTriggerRatio, yMin, yMax, nPart);
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
myGen->readString("Random:setSeed on");
myGen->readString("Random:seed " + std::to_string(seed));
return myGen;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ namespace eventgen {
class DecayerPythia8ForceDecays : public DecayerPythia8 {
public:
DecayerPythia8ForceDecays(){
mPythia.readString("Random:setSeed = on");
char* alien_proc_id = getenv("ALIEN_PROC_ID");
int seed;
long seed;
if (alien_proc_id != NULL) {
seed = atoi(alien_proc_id);
LOG(info) << "Seed for DecayerPythia8 set to ALIEN_PROC_ID: " << seed;
Expand All @@ -21,7 +20,7 @@ public:
LOG(info) << "Setting seed for DecayerPyhtia8 to 0 (random)";
seed = 0;
}
mPythia.readString("Random:seed = "+std::to_string(seed));
setInitialSeed(seed);
}
~DecayerPythia8ForceDecays() = default;

Expand Down Expand Up @@ -109,18 +108,17 @@ class GeneratorPythia8ForcedDecays : public GeneratorPythia8 {

public:
GeneratorPythia8ForcedDecays(){
mPythia.readString("Random:setSeed = on");
char* alien_proc_id = getenv("ALIEN_PROC_ID");
int seed;
long seed;
if (alien_proc_id != NULL) {
seed = atoi(alien_proc_id);
LOG(info) << "Seed for GeneratorPythia8 set to ALIEN_PROC_ID: " << seed;
LOG(info) << "Seed for DecayerPythia8 set to ALIEN_PROC_ID: " << seed;
} else {
LOG(info) << "Unable to retrieve ALIEN_PROC_ID";
LOG(info) << "Setting seed for GeneratorPyhtia8 to 0 (random)";
LOG(info) << "Setting seed for DecayerPyhtia8 to 0 (random)";
seed = 0;
}
mPythia.readString("Random:seed = "+std::to_string(seed));
setInitialSeed(seed);
}
~GeneratorPythia8ForcedDecays() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ FairGenerator *GeneratorPythia8GapTriggeredCharm(int inputTriggerRatio, float yQ
auto myGen = new GeneratorPythia8GapTriggeredHF(inputTriggerRatio, std::vector<int>{4}, hadronPdgList);
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
myGen->setUsedSeed(seed);
myGen->readString("Random:setSeed on");
myGen->readString("Random:seed " + std::to_string(seed));
myGen->setInitialSeed(seed);
myGen->setQuarkRapidity(yQuarkMin, yQuarkMax);
if (hadronPdgList.size() != 0)
{
Expand All @@ -244,8 +243,7 @@ FairGenerator *GeneratorPythia8GapTriggeredBeauty(int inputTriggerRatio, float y
auto myGen = new GeneratorPythia8GapTriggeredHF(inputTriggerRatio, std::vector<int>{5}, hadronPdgList);
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
myGen->setUsedSeed(seed);
myGen->readString("Random:setSeed on");
myGen->readString("Random:seed " + std::to_string(seed));
myGen->setInitialSeed(seed);
myGen->setQuarkRapidity(yQuarkMin, yQuarkMax);
if (hadronPdgList.size() != 0)
{
Expand All @@ -260,8 +258,7 @@ FairGenerator *GeneratorPythia8GapTriggeredCharmAndBeauty(int inputTriggerRatio,
auto myGen = new GeneratorPythia8GapTriggeredHF(inputTriggerRatio, std::vector<int>{4, 5}, hadronPdgList);
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
myGen->setUsedSeed(seed);
myGen->readString("Random:setSeed on");
myGen->readString("Random:seed " + std::to_string(seed));
myGen->setInitialSeed(seed);
myGen->setQuarkRapidity(yQuarkMin, yQuarkMax);
if (hadronPdgList.size() != 0)
{
Expand All @@ -279,10 +276,9 @@ FairGenerator *GeneratorPythia8GapHF(int inputTriggerRatio, float yQuarkMin = -1
auto myGen = new GeneratorPythia8GapTriggeredHF(inputTriggerRatio, quarkPdgList, hadronPdgList);
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
myGen->setUsedSeed(seed);
myGen->readString("Random:setSeed on");
myGen->readString("Random:seed " + std::to_string(seed));
myGen->setInitialSeed(seed);
myGen->setQuarkRapidity(yQuarkMin, yQuarkMax);
myGen->setHadronRapidity(yHadronMin, yHadronMax);

return myGen;
}
}
3 changes: 0 additions & 3 deletions MC/config/PWGLF/pythia8/generator/pythia8_inel_136tev.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ ParticleDecays:tau0Max = 10.
### phase space cuts
PhaseSpace:pTHatMin = 0.000000
PhaseSpace:pTHatMax = -1.000000

Random:setSeed = on
Random:seed = 0
Loading

0 comments on commit f82b452

Please sign in to comment.